Subversion Repositories oidplus

Rev

Rev 1269 | Rev 1400 | Go to most recent revision | View as "text/javascript" | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.  * OIDplus 2.0
  3.  * Copyright 2019 - 2022 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. var OIDplusPagePublicObjects = {
  19.  
  20.         oid: "1.3.6.1.4.1.37476.2.5.2.4.1.0",
  21.  
  22.         cbRemoveTinyMCE: function(selector) {
  23.                 if ((typeof tinymce == "undefined") || (tinymce == null)) {
  24.                         // This should not happen
  25.                         console.error("OIDplusPagePublicObjects.cbRemoveTinyMCE(): TinyMCE is missing?!");
  26.                         return;
  27.                 }
  28.                 tinymce.remove(selector); // here, we need a "#" (selector contains "#")
  29.         },
  30.  
  31.         cbQueryTinyMCE: function(selector) {
  32.                 // tinymce.get() does NOT allow a "#" prefix (but selector contains "#"). So we remove it
  33.                 selector = selector.replace('#', '');
  34.  
  35.                 if ((typeof tinymce == "undefined") || (tinymce == null) || (tinymce.get(selector) == null)) {
  36.                         // This should not happen
  37.                         console.error("OIDplusPagePublicObjects.cbQueryTinyMCE(): TinyMCE is missing?!");
  38.                         return true;
  39.                 }
  40.                 if (tinymce.get(selector).isDirty()) {
  41.                         return confirm(_L("Attention: Do you want to continue without saving?"));
  42.                 } else {
  43.                         return true;
  44.                 }
  45.         },
  46.  
  47.         checkMissingOrDoubleASN1: function(oid) {
  48.                 var suffix = (oid == '') ? '' : '_'+oid;
  49.  
  50.                 //var curinput = $('#asn1ids'+suffix').value;
  51.                 var curinput = $('input[id="asn1ids'+suffix+'"]')[0];
  52.  
  53.                 if (typeof curinput == "undefined") return true;
  54.  
  55.                 if (curinput.value == '') {
  56.                         // TODO: maybe we should only warn if ASN.1, IRI and Comment are all null, not just ASN.1?
  57.                         if (!confirm(_L("Attention: You did not enter an ASN.1 identifier. Are you sure that you want to continue?"))) return false;
  58.                 }
  59.  
  60.                 var ary = curinput.value.split(',');
  61.  
  62.                 for (var i=0; i<ary.length; i++) {
  63.                         var toCheck = ary[i];
  64.                         var bry = $('input[id^="asn1ids_"]');
  65.                         for (var j=0; j<bry.length; j++) {
  66.                                 if (bry[j].id != 'asn1ids'+suffix) {
  67.                                         var cry = bry[j].value.split(',');
  68.                                         for (var k=0; k<cry.length; k++) {
  69.                                                 var candidate = cry[k];
  70.                                                 if ((toCheck != "") && (candidate != "") && (toCheck == candidate)) {
  71.                                                         if (!confirm(_L("Warning! ASN.1 ID %1 is already used in another OID. Continue?", candidate))) return false;
  72.                                                 }
  73.                                         }
  74.                                 }
  75.                         }
  76.                 }
  77.  
  78.                 return true;
  79.         },
  80.  
  81.         crudActionInsert: function(parent) {
  82.                 if (parent.startsWith('oid:') && !OIDplusPagePublicObjects.checkMissingOrDoubleASN1('')) return;
  83.  
  84.                 $.ajax({
  85.                         url:"ajax.php",
  86.                         method:"POST",
  87.                         beforeSend: function(jqXHR, settings) {
  88.                                 $.xhrPool.abortAll();
  89.                                 $.xhrPool.add(jqXHR);
  90.                         },
  91.                         complete: function(jqXHR, text) {
  92.                                 $.xhrPool.remove(jqXHR);
  93.                         },
  94.                         data: {
  95.                                 csrf_token:csrf_token,
  96.                                 plugin:OIDplusPagePublicObjects.oid,
  97.                                 action:"Insert",
  98.                                 id:$("#id")[0].value,
  99.                                 id_fully_qualified:false,
  100.                                 ra_email:$("#ra_email")[0].value,
  101.                                 comment:$("#comment")[0].value,
  102.                                 asn1ids:($("#asn1ids")[0] ? $("#asn1ids")[0].value : null),
  103.                                 iris:($("#iris")[0] ? $("#iris")[0].value : null),
  104.                                 confidential:($("#hide")[0] ? $("#hide")[0].checked : null),
  105.                                 weid:($("#weid")[0] ? $("#weid")[0].checked : null),
  106.                                 parent:parent
  107.                         },
  108.                         error: oidplus_ajax_error,
  109.                         success: function (data) {
  110.                                 oidplus_ajax_success(data, function (data) {
  111.                                         var message = _L("Insert OK.");
  112.                                         var isWarning = false;
  113.  
  114.                                         if ((data.status & 4) == 4/*IsWellKnownOID*/) {
  115.                                                 isWarning = true;
  116.                                                 message = message + ' ' + _L("However, the RA and the ASN.1 and IRI identifiers were overwritten, because this OID is a well-known OID.");
  117.                                         }
  118.  
  119.                                         if ((data.status & 2) == 2/*RaNotExistingNoInvitation*/) {
  120.                                                 //message = _L("Insert OK.");
  121.                                         }
  122.  
  123.                                         message = message + "\n\n";
  124.  
  125.                                         if ((data.status & 1) == 1/*RaNotExisting*/) {
  126.                                                 if (confirm(message + _L("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?", $("#ra_email")[0].value))) {
  127.                                                         OIDplusPagePublicObjects.crudActionSendInvitation(parent, $("#ra_email")[0].value);
  128.                                                         return;
  129.                                                 }
  130.                                                 message = ""; // In the further messages, do not show this part of the message a second time
  131.                                         }
  132.  
  133.                                         if ((data.status & 8) == 8/*HasWriteRights*/) {
  134.                                                 if (confirm(message + _L("Do you want to open the newly created object now?"))) {
  135.                                                         openAndSelectNode(data.inserted_id, parent);
  136.                                                         return;
  137.                                                 }
  138.                                                 message = ""; // In the further messages, do not show this part of the message a second time
  139.                                         }
  140.  
  141.                                         if (message.trim() != "") {
  142.                                                 if (isWarning) {
  143.                                                         alertWarning(message.trim())
  144.                                                 } else {
  145.                                                         alertSuccess(message.trim());
  146.                                                 }
  147.                                         }
  148.  
  149.                                         // 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
  150.                                         reloadContent();
  151.                                 });
  152.                         }
  153.                 });
  154.         },
  155.  
  156.         crudActionUpdate: function(id, parent) {
  157.                 if (id.startsWith('oid:') && !OIDplusPagePublicObjects.checkMissingOrDoubleASN1(id)) return;
  158.  
  159.                 $.ajax({
  160.                         url:"ajax.php",
  161.                         method:"POST",
  162.                         beforeSend: function(jqXHR, settings) {
  163.                                 $.xhrPool.abortAll();
  164.                                 $.xhrPool.add(jqXHR);
  165.                         },
  166.                         complete: function(jqXHR, text) {
  167.                                 $.xhrPool.remove(jqXHR);
  168.                         },
  169.                         data: {
  170.                                 csrf_token:csrf_token,
  171.                                 plugin:OIDplusPagePublicObjects.oid,
  172.                                 action:"Update",
  173.                                 id:id,
  174.                                 ra_email:$("#ra_email_"+$.escapeSelector(id))[0].value,
  175.                                 comment:$("#comment_"+$.escapeSelector(id))[0].value,
  176.                                 asn1ids:($("#asn1ids_"+$.escapeSelector(id))[0] ? $("#asn1ids_"+$.escapeSelector(id))[0].value : null),
  177.                                 iris:($("#iris_"+$.escapeSelector(id))[0] ? $("#iris_"+$.escapeSelector(id))[0].value : null),
  178.                                 confidential:($("#hide_"+$.escapeSelector(id))[0] ? $("#hide_"+$.escapeSelector(id))[0].checked : null),
  179.                                 parent:parent
  180.                         },
  181.                         error: oidplus_ajax_error,
  182.                         success: function (data) {
  183.                                 oidplus_ajax_success(data, function (data) {
  184.                                         var message = _L("Update OK");
  185.                                         var isWarning = false;
  186.  
  187.                                         if ((data.status & 4) == 4/*IsWellKnownOID*/) {
  188.                                                 isWarning = true;
  189.                                                 message = message + ' ' + _L("However, the RA and the ASN.1 and IRI identifiers were overwritten, because this OID is a well-known OID.");
  190.                                         }
  191.  
  192.                                         if ((data.status & 2) == 2/*RaNotExistingNoInvitation*/) {
  193.                                                 // message = _L("Update OK");
  194.                                         }
  195.  
  196.                                         message = message + "\n\n";
  197.  
  198.                                         if ((data.status & 1) == 1/*RaNotExisting*/) {
  199.                                                 if (confirm(message + _L("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?", $("#ra_email_" + $.escapeSelector(id))[0].value))) {
  200.                                                         OIDplusPagePublicObjects.crudActionSendInvitation(parent, $("#ra_email_" + $.escapeSelector(id))[0].value);
  201.                                                         return;
  202.                                                 }
  203.                                                 message = ""; // In the further messages, do not show this part of the message a second time
  204.                                         }
  205.  
  206.                                         //if ((data.status & 8) == 8/*HasWriteRights*/) {
  207.                                         //      if (confirm(message + _L("Do you want to open the updated object now?"))) {
  208.                                         //              openAndSelectNode(id, parent);
  209.                                         //              return;
  210.                                         //      }
  211.                                         //      message = ""; // In the further messages, do not show this part of the message a second time
  212.                                         //}
  213.  
  214.                                         if (message.trim() != "") {
  215.                                                 if (isWarning) {
  216.                                                         alertWarning(message.trim())
  217.                                                 } else {
  218.                                                         alertSuccess(message.trim());
  219.                                                 }
  220.                                         }
  221.  
  222.                                         // reloadContent();
  223.                                         $('#oidtree').jstree("refresh");
  224.                                 });
  225.                         }
  226.                 });
  227.         },
  228.  
  229.         crudActionDelete: function(id, parent) {
  230.                 if(!window.confirm(_L("Are you sure that you want to delete %1?",id))) return false;
  231.  
  232.                 $.ajax({
  233.                         url:"ajax.php",
  234.                         method:"POST",
  235.                         beforeSend: function(jqXHR, settings) {
  236.                                 $.xhrPool.abortAll();
  237.                                 $.xhrPool.add(jqXHR);
  238.                         },
  239.                         complete: function(jqXHR, text) {
  240.                                 $.xhrPool.remove(jqXHR);
  241.                         },
  242.                         data: {
  243.                                 csrf_token:csrf_token,
  244.                                 plugin:OIDplusPagePublicObjects.oid,
  245.                                 action:"Delete",
  246.                                 id:id,
  247.                                 parent:parent
  248.                         },
  249.                         error: oidplus_ajax_error,
  250.                         success: function (data) {
  251.                                 oidplus_ajax_success(data, function (data) {
  252.                                         reloadContent();
  253.                                         // TODO: Don't use reloadContent(); instead delete node at the left tree and remove the row at the right table
  254.                                 });
  255.                         }
  256.                 });
  257.         },
  258.  
  259.         updateDesc: function() {
  260.                 $.ajax({
  261.                         url:"ajax.php",
  262.                         method:"POST",
  263.                         beforeSend: function(jqXHR, settings) {
  264.                                 $.xhrPool.abortAll();
  265.                                 $.xhrPool.add(jqXHR);
  266.                         },
  267.                         complete: function(jqXHR, text) {
  268.                                 $.xhrPool.remove(jqXHR);
  269.                         },
  270.                         data: {
  271.                                 csrf_token:csrf_token,
  272.                                 plugin:OIDplusPagePublicObjects.oid,
  273.                                 action:"Update",
  274.                                 id:current_node,
  275.                                 title:($("#titleedit")[0] ? $("#titleedit")[0].value : null),
  276.                                 //description:($("#description")[0] ? $("#description")[0].value : null)
  277.                                 description:tinyMCE.get('description').getContent()
  278.                         },
  279.                         error: oidplus_ajax_error,
  280.                         success: function (data) {
  281.                                 oidplus_ajax_success(data, function (data) {
  282.                                         alertSuccess(_L("Update OK"));
  283.                                         //reloadContent();
  284.                                         $('#oidtree').jstree("refresh");
  285.                                         var h1s = $("h1");
  286.                                         for (var i = 0; i < h1s.length; i++) {
  287.                                                 var h1 = h1s[i];
  288.                                                 h1.innerHTML = $("#titleedit")[0].value.htmlentities();
  289.                                         }
  290.                                         document.title = combine_systemtitle_and_pagetitle(getOidPlusSystemTitle(), $("#titleedit")[0].value);
  291.  
  292.                                         var mce = tinymce.get('description');
  293.                                         if (mce != null) mce.setDirty(false);
  294.                                 });
  295.                         }
  296.                 });
  297.         },
  298.  
  299.         crudActionSendInvitation: function(origin, email) {
  300.                 // window.location.href = "?goto=oidplus%3Ainvite_ra%24"+encodeURIComponent(email)+"%24"+encodeURIComponent(origin);
  301.                 openOidInPanel('oidplus:invite_ra$'+email+'$'+origin, false);
  302.         },
  303.  
  304.         frdl_weid_change: function() {
  305.                 var from_base = 36;
  306.                 var from_control = "#weid";
  307.                 var to_base = 10;
  308.                 var to_control = "#id";
  309.  
  310.                 var inp = $(from_control).val().toUpperCase().trim();
  311.                 if (inp == "") {
  312.                         $(to_control).val("");
  313.                 } else {
  314.                         var x = WeidOidConverter.base_convert_bigint(inp, from_base, to_base);
  315.                         if (x == false) {
  316.                                 $(to_control).val("");
  317.                         } else {
  318.                                 $(to_control).val(x);
  319.                         }
  320.                 }
  321.         },
  322.  
  323.         frdl_oidid_change: function() {
  324.                 var from_base = 10;
  325.                 var from_control = "#id";
  326.                 var to_base = 36;
  327.                 var to_control = "#weid";
  328.  
  329.                 var inp = $(from_control).val().trim();
  330.                 if (inp == "") {
  331.                         $(to_control).val("");
  332.                 } else {
  333.                         var x = WeidOidConverter.base_convert_bigint(inp, from_base, to_base);
  334.                         if (x == false) {
  335.                                 $(to_control).val("");
  336.                         } else {
  337.                                 $(to_control).val(x.toUpperCase());
  338.                         }
  339.                 }
  340.         }
  341.  
  342. };
  343.