Subversion Repositories oidplus

Rev

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

  1. /*
  2.  * OIDplus 2.0
  3.  * Copyright 2019 - 2021 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 != "") && (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.                         csrf_token:csrf_token,
  83.                         plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0",
  84.                         action:"Insert",
  85.                         id:document.getElementById('id').value,
  86.                         ra_email:document.getElementById('ra_email').value,
  87.                         comment:document.getElementById('comment').value,
  88.                         asn1ids:(document.getElementById('asn1ids') ? document.getElementById('asn1ids').value : null),
  89.                         iris:(document.getElementById('iris') ? document.getElementById('iris').value : null),
  90.                         confidential:(document.getElementById('hide') ? document.getElementById('hide').checked : null),
  91.                         weid:(document.getElementById('weid') ? document.getElementById('weid').checked : null),
  92.                         parent:parent
  93.                 },
  94.                 error:function(jqXHR, textStatus, errorThrown) {
  95.                         alert(_L("Error: %1",errorThrown));
  96.                 },
  97.                 success:function(data) {
  98.                         if ("error" in data) {
  99.                                 alert(_L("Error: %1",data.error));
  100.                         } else if (data.status >= 0) {
  101.                                 if (data.status == 0/*OK*/) {
  102.                                         if (confirm(_L("Insert OK")+".\n\n"+_L("Do you want to open the newly created object now?"))) {
  103.                                                 openAndSelectNode(data.inserted_id, parent);
  104.                                                 return;
  105.                                         }
  106.                                 }
  107.  
  108.                                 if ((data.status & 1) == 1/*RaNotExisting*/) {
  109.                                         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').value))) {
  110.                                                 crudActionSendInvitation(parent, document.getElementById('ra_email_'+id).value);
  111.                                                 return;
  112.                                         } else {
  113.                                                 if (confirm(_L("Do you want to open the newly created object now?"))) {
  114.                                                         openAndSelectNode(data.inserted_id, parent);
  115.                                                         return;
  116.                                                 }
  117.                                         }
  118.                                 }
  119.  
  120.                                 if ((data.status & 2) == 2/*RaNotExistingNoInvitation*/) {
  121.                                         if (confirm(_L("Insert OK.")+"\n\n"+_L("Do you want to open the newly created object now?"))) {
  122.                                                 openAndSelectNode(data.inserted_id, parent);
  123.                                                 return;
  124.                                         }
  125.                                 }
  126.  
  127.                                 if ((data.status & 4) == 4/*IsWellKnownOID*/) {
  128.                                         if (confirm(_L("Insert OK. However, the RA and the ASN.1 and IRI identifiers were overwritten, because this OID is a well-known OID.")+"\n\n"+L("Do you want to open the newly created object now?"))) {
  129.                                                 openAndSelectNode(data.inserted_id, parent);
  130.                                                 return;
  131.                                         }
  132.                                 }
  133.  
  134.                                 // TODO: Don't use reloadContent(); instead add a node at the tree at the left add at the right add a new row to the table
  135.                                 reloadContent();
  136.                         } else {
  137.                                 alert(_L("Error: %1",data));
  138.                         }
  139.                 }
  140.         });
  141. }
  142.  
  143. function crudActionUpdate(id, parent) {
  144.         if (id.startsWith('oid:') && !checkMissingOrDoubleASN1(id)) return;
  145.  
  146.         $.ajax({
  147.                 url:"ajax.php",
  148.                 method:"POST",
  149.                 data: {
  150.                         csrf_token:csrf_token,
  151.                         plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0",
  152.                         action:"Update",
  153.                         id:id,
  154.                         ra_email:document.getElementById('ra_email_'+id).value,
  155.                         comment:document.getElementById('comment_'+id).value,
  156.                         asn1ids:(document.getElementById('asn1ids_'+id) ? document.getElementById('asn1ids_'+id).value : null),
  157.                         iris:(document.getElementById('iris_'+id) ? document.getElementById('iris_'+id).value : null),
  158.                         confidential:(document.getElementById('hide_'+id) ? document.getElementById('hide_'+id).checked : null),
  159.                         parent:parent
  160.                 },
  161.                 error:function(jqXHR, textStatus, errorThrown) {
  162.                         alert(_L("Error: %1",errorThrown));
  163.                 },
  164.                 success:function(data) {
  165.                         if ("error" in data) {
  166.                                 alert(_L("Error: %1",data.error));
  167.                         } else if (data.status >= 0) {
  168.                                 if (data.status == 0/*OK*/) {
  169.                                         alert(_L("Update OK"));
  170.                                 }
  171.  
  172.                                 if ((data.status & 1) == 1/*RaNotExisting*/) {
  173.                                         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))) {
  174.                                                 crudActionSendInvitation(parent, document.getElementById('ra_email_'+id).value);
  175.                                                 return;
  176.                                         }
  177.                                 }
  178.  
  179.                                 if ((data.status & 2) == 2/*RaNotExistingNoInvitation*/) {
  180.                                         alert(_L("Update OK"));
  181.                                 }
  182.  
  183.                                 if ((data.status & 4) == 4/*IsWellKnownOID*/) {
  184.                                         alert(_L("Update OK. However, the RA and the ASN.1 and IRI identifiers were overwritten, because this OID is a well-known OID."));
  185.                                 }
  186.  
  187.                                 // reloadContent();
  188.                                 $('#oidtree').jstree("refresh");
  189.                         } else {
  190.                                 alert(_L("Error: %1",data));
  191.                         }
  192.                 }
  193.         });
  194. }
  195.  
  196. function crudActionDelete(id, parent) {
  197.         if(!window.confirm(_L("Are you sure that you want to delete %1?",id))) return false;
  198.  
  199.         $.ajax({
  200.                 url:"ajax.php",
  201.                 method:"POST",
  202.                 data: {
  203.                         csrf_token:csrf_token,
  204.                         plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0",
  205.                         action:"Delete",
  206.                         id:id,
  207.                         parent:parent
  208.                 },
  209.                 error:function(jqXHR, textStatus, errorThrown) {
  210.                         alert(_L("Error: %1",errorThrown));
  211.                 },
  212.                 success:function(data) {
  213.                         if ("error" in data) {
  214.                                 alert(_L("Error: %1",data.error));
  215.                         } else if (data.status >= 0) {
  216.                                 reloadContent();
  217.                                 // TODO: Don't use reloadContent(); instead delete node at the left tree and remove the row at the right table
  218.                         } else {
  219.                                 alert(_L("Error: %1",data.error));
  220.                         }
  221.                 }
  222.         });
  223. }
  224.  
  225. function updateDesc() {
  226.         $.ajax({
  227.                 url:"ajax.php",
  228.                 method:"POST",
  229.                 data: {
  230.                         csrf_token:csrf_token,
  231.                         plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0",
  232.                         action:"Update2",
  233.                         id:current_node,
  234.                         title:(document.getElementById('titleedit') ? document.getElementById('titleedit').value : null),
  235.                         //description:(document.getElementById('description') ? document.getElementById('description').value : null)
  236.                         description:tinyMCE.get('description').getContent()
  237.                 },
  238.                 error:function(jqXHR, textStatus, errorThrown) {
  239.                         alert(_L("Error: %1",errorThrown));
  240.                 },
  241.                 success:function(data) {
  242.                         if ("error" in data) {
  243.                                 alert(_L("Error: %1",data.error));
  244.                         } else if (data.status >= 0) {
  245.                                 alert(_L("Update OK"));
  246.                                 //reloadContent();
  247.                                 $('#oidtree').jstree("refresh");
  248.                                 var h1s = document.getElementsByTagName("h1");
  249.                                 for (var i = 0; i < h1s.length; i++) {
  250.                                         var h1 = h1s[i];
  251.                                         h1.innerHTML = document.getElementById('titleedit').value.htmlentities();
  252.                                 }
  253.                                 document.title = combine_systemtitle_and_pagetitle(getOidPlusSystemTitle(), document.getElementById('titleedit').value);
  254.  
  255.                                 var mce = tinymce.get('description');
  256.                                 if (mce != null) mce.setDirty(false);
  257.                         } else {
  258.                                 alert(_L("Error: %1",data.error));
  259.                         }
  260.                 }
  261.         });
  262. }
  263.  
  264. function crudActionSendInvitation(origin, email) {
  265.         // window.location.href = "?goto=oidplus:invite_ra$"+encodeURIComponent(email)+"$"+encodeURIComponent(origin);
  266.         openOidInPanel('oidplus:invite_ra$'+email+'$'+origin, false);
  267. }
  268.  
  269. function frdl_weid_change() {
  270.         var from_base = 36;
  271.         var from_control = "#weid";
  272.         var to_base = 10;
  273.         var to_control = "#id";
  274.  
  275.         var inp = $(from_control).val().trim();
  276.         if (inp == "") {
  277.                 $(to_control).val("");
  278.         } else {
  279.                 var x = BigNumber(inp, from_base);
  280.                 if (isNaN(x)) {
  281.                         $(to_control).val("");
  282.                 } else {
  283.                         $(to_control).val(x.toString(to_base));
  284.                 }
  285.         }
  286. }
  287.  
  288. function frdl_oidid_change() {
  289.         var from_base = 10;
  290.         var from_control = "#id";
  291.         var to_base = 36;
  292.         var to_control = "#weid";
  293.  
  294.         var inp = $(from_control).val().trim();
  295.         if (inp == "") {
  296.                 $(to_control).val("");
  297.         } else {
  298.                 var x = BigNumber(inp, from_base);
  299.                 if (isNaN(x)) {
  300.                         $(to_control).val("");
  301.                 } else {
  302.                         $(to_control).val(x.toString(to_base).toUpperCase());
  303.                 }
  304.         }
  305. }
  306.