Subversion Repositories oidplus

Rev

Rev 399 | Go to most recent revision | View as "text/javascript" | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * OIDplus 2.0
  3.  * Copyright 2019 Daniel Marschall, ViaThinkSoft
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17.  
  18. function cbRemoveTinyMCE(selector) {
  19.         if ((typeof tinymce == "undefined") || (tinymce == null)) {
  20.                 // This should not happen
  21.                 console.error("cbRemoveTinyMCE(): TinyMCE is missing?!");
  22.                 return;
  23.         }
  24.         tinymce.remove(selector); // here, we need a "#" (selector contains "#")
  25. }
  26.  
  27. function cbQueryTinyMCE(selector) {
  28.         // tinymce.get() does NOT allow a "#" prefix (but selector contains "#"). So we remove it
  29.         selector = selector.replace('#', '');
  30.  
  31.         if ((typeof tinymce == "undefined") || (tinymce == null) || (tinymce.get(selector) == null)) {
  32.                 // This should not happen
  33.                 console.error("cbQueryTinyMCE(): TinyMCE is missing?!");
  34.                 return true;
  35.         }
  36.         if (tinymce.get(selector).isDirty()) {
  37.                 return confirm(_L("Attention: Do you want to continue without saving?"));
  38.         } else {
  39.                 return true;
  40.         }
  41. }
  42.  
  43. function checkMissingOrDoubleASN1(oid) {
  44.         var suffix = (oid == '') ? '' : '_'+oid;
  45.  
  46.         //var curinput = $('#asn1ids'+suffix').value;
  47.         var curinput = $('input[id="asn1ids'+suffix+'"]')[0];
  48.  
  49.         if (curinput.value == '') {
  50.                 // TODO: maybe we should only warn if ASN.1, IRI and Comment are all null, not just ASN.1?
  51.                 if (!confirm(_L("Attention: You did not enter an ASN.1 identifier. Are you sure that you want to continue?"))) return false;
  52.         }
  53.  
  54.         var ary = curinput.value.split(',');
  55.  
  56.         for (var i=0; i<ary.length; i++) {
  57.                 var toCheck = ary[i];
  58.                 var bry = $('input[id^="asn1ids_"]');
  59.                 for (var j=0; j<bry.length; j++) {
  60.                         if (bry[j].id != 'asn1ids'+suffix) {
  61.                                 var cry = bry[j].value.split(',');
  62.                                 for (var k=0; k<cry.length; k++) {
  63.                                         var candidate = cry[k];
  64.                                         if (toCheck == candidate) {
  65.                                                 if (!confirm(_L("Warning! ASN.1 ID %1 is already used in another OID. Continue?", candidate))) return false;
  66.                                         }
  67.                                 }
  68.                         }
  69.                 }
  70.         }
  71.  
  72.         return true;
  73. }
  74.  
  75. function crudActionInsert(parent) {
  76.         if (parent.startsWith('oid:') && !checkMissingOrDoubleASN1('')) return;
  77.  
  78.         $.ajax({
  79.                 url:"ajax.php",
  80.                 method:"POST",
  81.                 data:{
  82.                         plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0",
  83.                         action:"Insert",
  84.                         id:document.getElementById('id').value,
  85.                         ra_email:document.getElementById('ra_email').value,
  86.                         comment:document.getElementById('comment').value,
  87.                         asn1ids:(document.getElementById('asn1ids') ? document.getElementById('asn1ids').value : null),
  88.                         iris:(document.getElementById('iris') ? document.getElementById('iris').value : null),
  89.                         confidential:(document.getElementById('hide') ? document.getElementById('hide').checked : null),
  90.                         weid:(document.getElementById('weid') ? document.getElementById('weid').checked : null),
  91.                         parent:parent
  92.                 },
  93.                 error:function(jqXHR, textStatus, errorThrown) {
  94.                         alert(_L("Error: %1",errorThrown));
  95.                 },
  96.                 success:function(data) {
  97.                         if ("error" in data) {
  98.                                 alert(_L("Error: %1",data.error));
  99.                         } else if (data.status >= 0) {
  100.                                 if (data.status == 0/*OK*/) {
  101.                                         alert(_L("Insert OK"));
  102.                                 }
  103.  
  104.                                 if ((data.status & 1) == 1/*RaNotExisting*/) {
  105.                                         if (confirm(_L("Insert OK. However, the email address you have entered (%1) is not in our system. Do you want to send an invitation, so that the RA can register an account to manage their OIDs?",document.getElementById('ra_email_'+id).value))) {
  106.                                                 crudActionSendInvitation(parent, document.getElementById('ra_email_'+id).value);
  107.                                                 return;
  108.                                         }
  109.                                 }
  110.  
  111.                                 if ((data.status & 2) == 2/*RaNotExistingNoInvitation*/) {
  112.                                         alert(_L("Insert OK"));
  113.                                 }
  114.  
  115.                                 if ((data.status & 4) == 4/*IsWellKnownOID*/) {
  116.                                         alert(_L("Insert OK. However, the RA and the ASN.1 and IRI identifiers were overwritten, because this OID is a well-known OID."));
  117.                                 }
  118.  
  119.                                 // TODO: auf reloadContent() verzichten. stattdessen nur tree links aktualisieren, und rechts eine neue zeile zur tabelle hinzufügen
  120.                                 reloadContent();
  121.                         } else {
  122.                                 alert(_L("Error: %1",data));
  123.                         }
  124.                 }
  125.         });
  126. }
  127.  
  128. function crudActionUpdate(id, parent) {
  129.         if (id.startsWith('oid:') && !checkMissingOrDoubleASN1(id)) return;
  130.  
  131.         $.ajax({
  132.                 url:"ajax.php",
  133.                 method:"POST",
  134.                 data: {
  135.                         plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0",
  136.                         action:"Update",
  137.                         id:id,
  138.                         ra_email:document.getElementById('ra_email_'+id).value,
  139.                         comment:document.getElementById('comment_'+id).value,
  140.                         asn1ids:(document.getElementById('asn1ids_'+id) ? document.getElementById('asn1ids_'+id).value : null),
  141.                         iris:(document.getElementById('iris_'+id) ? document.getElementById('iris_'+id).value : null),
  142.                         confidential:(document.getElementById('hide_'+id) ? document.getElementById('hide_'+id).checked : null),
  143.                         parent:parent
  144.                 },
  145.                 error:function(jqXHR, textStatus, errorThrown) {
  146.                         alert(_L("Error: %1",errorThrown));
  147.                 },
  148.                 success:function(data) {
  149.                         if ("error" in data) {
  150.                                 alert(_L("Error: %1",data.error));
  151.                         } else if (data.status >= 0) {
  152.                                 if (data.status == 0/*OK*/) {
  153.                                         alert(_L("Update OK"));
  154.                                 }
  155.  
  156.                                 if ((data.status & 1) == 1/*RaNotExisting*/) {
  157.                                         if (confirm(_L("Update OK. However, the email address you have entered (%1) is not in our system. Do you want to send an invitation, so that the RA can register an account to manage their OIDs?",document.getElementById('ra_email_'+id).value))) {
  158.                                                 crudActionSendInvitation(parent, document.getElementById('ra_email_'+id).value);
  159.                                                 return;
  160.                                         }
  161.                                 }
  162.  
  163.                                 if ((data.status & 2) == 2/*RaNotExistingNoInvitation*/) {
  164.                                         alert(_L("Update OK"));
  165.                                 }
  166.  
  167.                                 if ((data.status & 4) == 4/*IsWellKnownOID*/) {
  168.                                         alert(_L("Update OK. However, the RA and the ASN.1 and IRI identifiers were overwritten, because this OID is a well-known OID."));
  169.                                 }
  170.  
  171.                                 // reloadContent();
  172.                                 $('#oidtree').jstree("refresh");
  173.                         } else {
  174.                                 alert(_L("Error: %1",data));
  175.                         }
  176.                 }
  177.         });
  178. }
  179.  
  180. function crudActionDelete(id, parent) {
  181.         if(!window.confirm(_L("Are you sure that you want to delete %1?",id))) return false;
  182.  
  183.         $.ajax({
  184.                 url:"ajax.php",
  185.                 method:"POST",
  186.                 data: {
  187.                         plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0",
  188.                         action:"Delete",
  189.                         id:id,
  190.                         parent:parent
  191.                 },
  192.                 error:function(jqXHR, textStatus, errorThrown) {
  193.                         alert(_L("Error: %1",errorThrown));
  194.                 },
  195.                 success:function(data) {
  196.                         if ("error" in data) {
  197.                                 alert(_L("Error: %1",data.error));
  198.                         } else if (data.status >= 0) {
  199.                                 reloadContent();
  200.                                 // TODO: auf reloadContent() verzichten. stattdessen nur tree links aktualisieren, und rechts die zeile aus der tabelle löschen
  201.                         } else {
  202.                                 alert(_L("Error: %1",data.error));
  203.                         }
  204.                 }
  205.         });
  206. }
  207.  
  208. function updateDesc() {
  209.         $.ajax({
  210.                 url:"ajax.php",
  211.                 method:"POST",
  212.                 data: {
  213.                         plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0",
  214.                         action:"Update2",
  215.                         id:current_node,
  216.                         title:(document.getElementById('titleedit') ? document.getElementById('titleedit').value : null),
  217.                         //description:(document.getElementById('description') ? document.getElementById('description').value : null)
  218.                         description:tinyMCE.get('description').getContent()
  219.                 },
  220.                 error:function(jqXHR, textStatus, errorThrown) {
  221.                         alert(_L("Error: %1",errorThrown));
  222.                 },
  223.                 success:function(data) {
  224.                         if ("error" in data) {
  225.                                 alert(_L("Error: %1",data.error));
  226.                         } else if (data.status >= 0) {
  227.                                 alert(_L("Update OK"));
  228.                                 //reloadContent();
  229.                                 $('#oidtree').jstree("refresh");
  230.                                 var h1s = document.getElementsByTagName("h1");
  231.                                 for (var i = 0; i < h1s.length; i++) {
  232.                                         var h1 = h1s[i];
  233.                                         h1.innerHTML = document.getElementById('titleedit').value.htmlentities();
  234.                                 }
  235.                                 document.title = combine_systemtitle_and_pagetitle(getOidPlusSystemTitle(), document.getElementById('titleedit').value);
  236.  
  237.                                 var mce = tinymce.get('description');
  238.                                 if (mce != null) mce.isNotDirty = 1;
  239.                         } else {
  240.                                 alert(_L("Error: %1",data.error));
  241.                         }
  242.                 }
  243.         });
  244. }
  245.  
  246. function crudActionSendInvitation(origin, email) {
  247.         // window.location.href = "?goto=oidplus:invite_ra$"+encodeURIComponent(email)+"$"+encodeURIComponent(origin);
  248.         openOidInPanel('oidplus:invite_ra$'+email+'$'+origin, false);
  249. }
  250.  
  251. function frdl_weid_change() {
  252.         var from_base = 36;
  253.         var from_control = "#weid";
  254.         var to_base = 10;
  255.         var to_control = "#id";
  256.  
  257.         var inp = $(from_control).val().trim();
  258.         if (inp == "") {
  259.                 $(to_control).val("");
  260.         } else {
  261.                 var x = BigNumber(inp, from_base);
  262.                 if (isNaN(x)) {
  263.                         $(to_control).val("");
  264.                 } else {
  265.                         $(to_control).val(x.toString(to_base));
  266.                 }
  267.         }
  268. }
  269.  
  270. function frdl_oidid_change() {
  271.         var from_base = 10;
  272.         var from_control = "#id";
  273.         var to_base = 36;
  274.         var to_control = "#weid";
  275.  
  276.         var inp = $(from_control).val().trim();
  277.         if (inp == "") {
  278.                 $(to_control).val("");
  279.         } else {
  280.                 var x = BigNumber(inp, from_base);
  281.                 if (isNaN(x)) {
  282.                         $(to_control).val("");
  283.                 } else {
  284.                         $(to_control).val(x.toString(to_base));
  285.                 }
  286.         }
  287. }
  288.