Rev 507 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
256 | daniel-mar | 1 | /* |
2 | * OIDplus 2.0 |
||
511 | daniel-mar | 3 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
256 | daniel-mar | 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 | |||
399 | daniel-mar | 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 | } |
||
404 | daniel-mar | 24 | tinymce.remove(selector); // here, we need a "#" (selector contains "#") |
399 | daniel-mar | 25 | } |
26 | |||
27 | function cbQueryTinyMCE(selector) { |
||
404 | daniel-mar | 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)) { |
||
399 | daniel-mar | 32 | // This should not happen |
33 | console.error("cbQueryTinyMCE(): TinyMCE is missing?!"); |
||
34 | return true; |
||
35 | } |
||
404 | daniel-mar | 36 | if (tinymce.get(selector).isDirty()) { |
399 | daniel-mar | 37 | return confirm(_L("Attention: Do you want to continue without saving?")); |
38 | } else { |
||
39 | return true; |
||
40 | } |
||
41 | } |
||
42 | |||
393 | daniel-mar | 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]; |
||
424 | daniel-mar | 64 | if ((toCheck != "") && (candidate != "") && (toCheck == candidate)) { |
393 | daniel-mar | 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 | |||
256 | daniel-mar | 75 | function crudActionInsert(parent) { |
393 | daniel-mar | 76 | if (parent.startsWith('oid:') && !checkMissingOrDoubleASN1('')) return; |
77 | |||
256 | daniel-mar | 78 | $.ajax({ |
79 | url:"ajax.php", |
||
80 | method:"POST", |
||
81 | data:{ |
||
424 | daniel-mar | 82 | csrf_token:csrf_token, |
320 | daniel-mar | 83 | plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0", |
256 | daniel-mar | 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) { |
||
360 | daniel-mar | 95 | alert(_L("Error: %1",errorThrown)); |
256 | daniel-mar | 96 | }, |
97 | success:function(data) { |
||
98 | if ("error" in data) { |
||
360 | daniel-mar | 99 | alert(_L("Error: %1",data.error)); |
381 | daniel-mar | 100 | } else if (data.status >= 0) { |
101 | if (data.status == 0/*OK*/) { |
||
507 | daniel-mar | 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 | } |
||
395 | daniel-mar | 106 | } |
107 | |||
108 | if ((data.status & 1) == 1/*RaNotExisting*/) { |
||
422 | daniel-mar | 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))) { |
395 | daniel-mar | 110 | crudActionSendInvitation(parent, document.getElementById('ra_email_'+id).value); |
111 | return; |
||
507 | daniel-mar | 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 | } |
||
381 | daniel-mar | 117 | } |
256 | daniel-mar | 118 | } |
395 | daniel-mar | 119 | |
120 | if ((data.status & 2) == 2/*RaNotExistingNoInvitation*/) { |
||
507 | daniel-mar | 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 | } |
||
395 | daniel-mar | 125 | } |
126 | |||
127 | if ((data.status & 4) == 4/*IsWellKnownOID*/) { |
||
507 | daniel-mar | 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 | } |
||
395 | daniel-mar | 132 | } |
133 | |||
499 | daniel-mar | 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 |
395 | daniel-mar | 135 | reloadContent(); |
256 | daniel-mar | 136 | } else { |
360 | daniel-mar | 137 | alert(_L("Error: %1",data)); |
256 | daniel-mar | 138 | } |
139 | } |
||
140 | }); |
||
141 | } |
||
142 | |||
143 | function crudActionUpdate(id, parent) { |
||
393 | daniel-mar | 144 | if (id.startsWith('oid:') && !checkMissingOrDoubleASN1(id)) return; |
145 | |||
256 | daniel-mar | 146 | $.ajax({ |
147 | url:"ajax.php", |
||
148 | method:"POST", |
||
149 | data: { |
||
424 | daniel-mar | 150 | csrf_token:csrf_token, |
320 | daniel-mar | 151 | plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0", |
256 | daniel-mar | 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) { |
||
360 | daniel-mar | 162 | alert(_L("Error: %1",errorThrown)); |
256 | daniel-mar | 163 | }, |
164 | success:function(data) { |
||
165 | if ("error" in data) { |
||
360 | daniel-mar | 166 | alert(_L("Error: %1",data.error)); |
381 | daniel-mar | 167 | } else if (data.status >= 0) { |
168 | if (data.status == 0/*OK*/) { |
||
169 | alert(_L("Update OK")); |
||
395 | daniel-mar | 170 | } |
171 | |||
172 | if ((data.status & 1) == 1/*RaNotExisting*/) { |
||
381 | daniel-mar | 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); |
||
395 | daniel-mar | 175 | return; |
381 | daniel-mar | 176 | } |
395 | daniel-mar | 177 | } |
178 | |||
179 | if ((data.status & 2) == 2/*RaNotExistingNoInvitation*/) { |
||
381 | daniel-mar | 180 | alert(_L("Update OK")); |
256 | daniel-mar | 181 | } |
395 | daniel-mar | 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"); |
||
256 | daniel-mar | 189 | } else { |
360 | daniel-mar | 190 | alert(_L("Error: %1",data)); |
256 | daniel-mar | 191 | } |
192 | } |
||
193 | }); |
||
194 | } |
||
195 | |||
196 | function crudActionDelete(id, parent) { |
||
360 | daniel-mar | 197 | if(!window.confirm(_L("Are you sure that you want to delete %1?",id))) return false; |
256 | daniel-mar | 198 | |
199 | $.ajax({ |
||
200 | url:"ajax.php", |
||
201 | method:"POST", |
||
202 | data: { |
||
424 | daniel-mar | 203 | csrf_token:csrf_token, |
320 | daniel-mar | 204 | plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0", |
256 | daniel-mar | 205 | action:"Delete", |
206 | id:id, |
||
207 | parent:parent |
||
208 | }, |
||
209 | error:function(jqXHR, textStatus, errorThrown) { |
||
360 | daniel-mar | 210 | alert(_L("Error: %1",errorThrown)); |
256 | daniel-mar | 211 | }, |
212 | success:function(data) { |
||
213 | if ("error" in data) { |
||
360 | daniel-mar | 214 | alert(_L("Error: %1",data.error)); |
381 | daniel-mar | 215 | } else if (data.status >= 0) { |
256 | daniel-mar | 216 | reloadContent(); |
499 | daniel-mar | 217 | // TODO: Don't use reloadContent(); instead delete node at the left tree and remove the row at the right table |
256 | daniel-mar | 218 | } else { |
360 | daniel-mar | 219 | alert(_L("Error: %1",data.error)); |
256 | daniel-mar | 220 | } |
221 | } |
||
222 | }); |
||
223 | } |
||
224 | |||
225 | function updateDesc() { |
||
226 | $.ajax({ |
||
227 | url:"ajax.php", |
||
228 | method:"POST", |
||
229 | data: { |
||
424 | daniel-mar | 230 | csrf_token:csrf_token, |
320 | daniel-mar | 231 | plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0", |
256 | daniel-mar | 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) { |
||
360 | daniel-mar | 239 | alert(_L("Error: %1",errorThrown)); |
256 | daniel-mar | 240 | }, |
241 | success:function(data) { |
||
242 | if ("error" in data) { |
||
360 | daniel-mar | 243 | alert(_L("Error: %1",data.error)); |
381 | daniel-mar | 244 | } else if (data.status >= 0) { |
360 | daniel-mar | 245 | alert(_L("Update OK")); |
256 | daniel-mar | 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'); |
||
414 | daniel-mar | 256 | if (mce != null) mce.setDirty(false); |
256 | daniel-mar | 257 | } else { |
360 | daniel-mar | 258 | alert(_L("Error: %1",data.error)); |
256 | daniel-mar | 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 { |
||
507 | daniel-mar | 302 | $(to_control).val(x.toString(to_base).toUpperCase()); |
256 | daniel-mar | 303 | } |
304 | } |
||
395 | daniel-mar | 305 | } |