Subversion Repositories oidplus

Rev

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