Subversion Repositories oidplus

Rev

Rev 1410 | 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.  
  112.                                         if (typeof data !== "object" || !("status" in data) || data.status < 0) {
  113.                                                 console.error(data);
  114.                                                 alert("Error: " + data);
  115.                                         }
  116.  
  117.                                         var message = _L("Insert OK.");
  118.                                         var isWarning = false;
  119.  
  120.                                         if ((data.status & 4) == 4/*IsWellKnownOID*/) {
  121.                                                 isWarning = true;
  122.                                                 message = message + ' ' + _L("However, the RA and the ASN.1 and IRI identifiers were overwritten, because this OID is a well-known OID.");
  123.                                         }
  124.  
  125.                                         if (message.trim() != "") {
  126.                                                 if (isWarning) {
  127.                                                         alertWarning(message.trim())
  128.                                                 } else {
  129.                                                         alertSuccess(message.trim());
  130.                                                 }
  131.                                         }
  132.  
  133.                                         openAndSelectNode(data.inserted_id, parent);
  134.                                 });
  135.                         }
  136.                 });
  137.         },
  138.  
  139.         crudActionUpdate: function(id, parent) {
  140.                 if (id.startsWith('oid:') && !OIDplusPagePublicObjects.checkMissingOrDoubleASN1(id)) return;
  141.  
  142.                 $.ajax({
  143.                         url:"ajax.php",
  144.                         method:"POST",
  145.                         beforeSend: function(jqXHR, settings) {
  146.                                 $.xhrPool.abortAll();
  147.                                 $.xhrPool.add(jqXHR);
  148.                         },
  149.                         complete: function(jqXHR, text) {
  150.                                 $.xhrPool.remove(jqXHR);
  151.                         },
  152.                         data: {
  153.                                 csrf_token:csrf_token,
  154.                                 plugin:OIDplusPagePublicObjects.oid,
  155.                                 action:"Update",
  156.                                 id:id,
  157.                                 ra_email:$("#ra_email_"+$.escapeSelector(id))[0].value,
  158.                                 comment:$("#comment_"+$.escapeSelector(id))[0].value,
  159.                                 asn1ids:($("#asn1ids_"+$.escapeSelector(id))[0] ? $("#asn1ids_"+$.escapeSelector(id))[0].value : null),
  160.                                 iris:($("#iris_"+$.escapeSelector(id))[0] ? $("#iris_"+$.escapeSelector(id))[0].value : null),
  161.                                 confidential:($("#hide_"+$.escapeSelector(id))[0] ? $("#hide_"+$.escapeSelector(id))[0].checked : null),
  162.                                 parent:parent
  163.                         },
  164.                         error: oidplus_ajax_error,
  165.                         success: function (data) {
  166.                                 oidplus_ajax_success(data, function (data) {
  167.  
  168.                                         if (typeof data !== "object" || !("status" in data) || data.status < 0) {
  169.                                                 console.error(data);
  170.                                                 alert("Error: " + data);
  171.                                         }
  172.  
  173.                                         var message = _L("Update OK");
  174.                                         var isWarning = false;
  175.  
  176.                                         if ((data.status & 4) == 4/*IsWellKnownOID*/) {
  177.                                                 isWarning = true;
  178.                                                 message = message + ' ' + _L("However, the RA and the ASN.1 and IRI identifiers were overwritten, because this OID is a well-known OID.");
  179.                                         }
  180.  
  181.                                         if ((data.status & 2) == 2/*RaNotExistingNoInvitation*/) {
  182.                                                 // message = _L("Update OK");
  183.                                         }
  184.  
  185.                                         message = message + "\n\n";
  186.  
  187.                                         if (message.trim() != "") {
  188.                                                 if (isWarning) {
  189.                                                         alertWarning(message.trim())
  190.                                                 } else {
  191.                                                         alertSuccess(message.trim());
  192.                                                 }
  193.                                         }
  194.  
  195.                                         // reloadContent();
  196.                                         $('#oidtree').jstree("refresh");
  197.                                 });
  198.                         }
  199.                 });
  200.         },
  201.  
  202.         crudActionDelete: function(id, parent) {
  203.                 if(!window.confirm(_L("Are you sure that you want to delete %1?",id))) return false;
  204.  
  205.                 $.ajax({
  206.                         url:"ajax.php",
  207.                         method:"POST",
  208.                         beforeSend: function(jqXHR, settings) {
  209.                                 $.xhrPool.abortAll();
  210.                                 $.xhrPool.add(jqXHR);
  211.                         },
  212.                         complete: function(jqXHR, text) {
  213.                                 $.xhrPool.remove(jqXHR);
  214.                         },
  215.                         data: {
  216.                                 csrf_token:csrf_token,
  217.                                 plugin:OIDplusPagePublicObjects.oid,
  218.                                 action:"Delete",
  219.                                 id:id,
  220.                                 parent:parent
  221.                         },
  222.                         error: oidplus_ajax_error,
  223.                         success: function (data) {
  224.                                 oidplus_ajax_success(data, function (data) {
  225.  
  226.                                         if (typeof data !== "object" || !("status" in data) || data.status < 0) {
  227.                                                 console.error(data);
  228.                                                 alert("Error: " + data);
  229.                                         }
  230.  
  231.                                         reloadContent();
  232.                                         // TODO: Don't use reloadContent(); instead delete node at the left tree and remove the row at the right table
  233.                                 });
  234.                         }
  235.                 });
  236.         },
  237.  
  238.         updateDesc: function(id) {
  239.                 $.ajax({
  240.                         url:"ajax.php",
  241.                         method:"POST",
  242.                         beforeSend: function(jqXHR, settings) {
  243.                                 $.xhrPool.abortAll();
  244.                                 $.xhrPool.add(jqXHR);
  245.                         },
  246.                         complete: function(jqXHR, text) {
  247.                                 $.xhrPool.remove(jqXHR);
  248.                         },
  249.                         data: {
  250.                                 csrf_token:csrf_token,
  251.                                 plugin:OIDplusPagePublicObjects.oid,
  252.                                 action:"Update",
  253.                                 id:id,
  254.                                 title:($("#titleedit")[0] ? $("#titleedit")[0].value : null),
  255.                                 //description:($("#description")[0] ? $("#description")[0].value : null)
  256.                                 description:tinyMCE.get('description').getContent()
  257.                         },
  258.                         error: oidplus_ajax_error,
  259.                         success: function (data) {
  260.                                 oidplus_ajax_success(data, function (data) {
  261.                                         alertSuccess(_L("Update OK"));
  262.                                         //reloadContent();
  263.                                         $('#oidtree').jstree("refresh");
  264.                                         var h1s = $("h1");
  265.                                         for (var i = 0; i < h1s.length; i++) {
  266.                                                 var h1 = h1s[i];
  267.                                                 h1.innerHTML = $("#titleedit")[0].value.htmlentities();
  268.                                         }
  269.                                         document.title = combine_systemtitle_and_pagetitle(getOidPlusSystemTitle(), $("#titleedit")[0].value);
  270.  
  271.                                         var mce = tinymce.get('description');
  272.                                         if (mce != null) mce.setDirty(false);
  273.                                 });
  274.                         }
  275.                 });
  276.         },
  277.  
  278.         frdl_weid_change: function() {
  279.                 var from_base = 36;
  280.                 var from_control = "#weid";
  281.                 var to_base = 10;
  282.                 var to_control = "#id";
  283.  
  284.                 var inp = $(from_control).val().toUpperCase().trim();
  285.                 if (inp == "") {
  286.                         $(to_control).val("");
  287.                 } else {
  288.                         var x = WeidOidConverter.base_convert_bigint(inp, from_base, to_base);
  289.                         if (x === false) {
  290.                                 $(to_control).val("");
  291.                         } else {
  292.                                 $(to_control).val(x);
  293.                         }
  294.                 }
  295.         },
  296.  
  297.         frdl_oidid_change: function() {
  298.                 var from_base = 10;
  299.                 var from_control = "#id";
  300.                 var to_base = 36;
  301.                 var to_control = "#weid";
  302.  
  303.                 var inp = $(from_control).val().trim();
  304.                 if (inp == "") {
  305.                         $(to_control).val("");
  306.                 } else {
  307.                         var x = WeidOidConverter.base_convert_bigint(inp, from_base, to_base);
  308.                         if (x === false) {
  309.                                 $(to_control).val("");
  310.                         } else {
  311.                                 $(to_control).val(x.toUpperCase());
  312.                         }
  313.                 }
  314.         }
  315.  
  316. };
  317.