Rev 393 | 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 |
||
3 | * Copyright 2019 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 | |||
393 | daniel-mar | 18 | function checkMissingOrDoubleASN1(oid) { |
19 | var suffix = (oid == '') ? '' : '_'+oid; |
||
20 | |||
21 | //var curinput = $('#asn1ids'+suffix').value; |
||
22 | var curinput = $('input[id="asn1ids'+suffix+'"]')[0]; |
||
23 | |||
24 | if (curinput.value == '') { |
||
25 | // TODO: maybe we should only warn if ASN.1, IRI and Comment are all null, not just ASN.1? |
||
26 | if (!confirm(_L("Attention: You did not enter an ASN.1 identifier. Are you sure that you want to continue?"))) return false; |
||
27 | } |
||
28 | |||
29 | var ary = curinput.value.split(','); |
||
30 | |||
31 | for (var i=0; i<ary.length; i++) { |
||
32 | var toCheck = ary[i]; |
||
33 | var bry = $('input[id^="asn1ids_"]'); |
||
34 | for (var j=0; j<bry.length; j++) { |
||
35 | if (bry[j].id != 'asn1ids'+suffix) { |
||
36 | var cry = bry[j].value.split(','); |
||
37 | for (var k=0; k<cry.length; k++) { |
||
38 | var candidate = cry[k]; |
||
39 | if (toCheck == candidate) { |
||
40 | if (!confirm(_L("Warning! ASN.1 ID %1 is already used in another OID. Continue?", candidate))) return false; |
||
41 | } |
||
42 | } |
||
43 | } |
||
44 | } |
||
45 | } |
||
46 | |||
47 | return true; |
||
48 | } |
||
49 | |||
256 | daniel-mar | 50 | function crudActionInsert(parent) { |
393 | daniel-mar | 51 | if (parent.startsWith('oid:') && !checkMissingOrDoubleASN1('')) return; |
52 | |||
256 | daniel-mar | 53 | $.ajax({ |
54 | url:"ajax.php", |
||
55 | method:"POST", |
||
56 | data:{ |
||
320 | daniel-mar | 57 | plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0", |
256 | daniel-mar | 58 | action:"Insert", |
59 | id:document.getElementById('id').value, |
||
60 | ra_email:document.getElementById('ra_email').value, |
||
61 | comment:document.getElementById('comment').value, |
||
62 | asn1ids:(document.getElementById('asn1ids') ? document.getElementById('asn1ids').value : null), |
||
63 | iris:(document.getElementById('iris') ? document.getElementById('iris').value : null), |
||
64 | confidential:(document.getElementById('hide') ? document.getElementById('hide').checked : null), |
||
65 | weid:(document.getElementById('weid') ? document.getElementById('weid').checked : null), |
||
66 | parent:parent |
||
67 | }, |
||
68 | error:function(jqXHR, textStatus, errorThrown) { |
||
360 | daniel-mar | 69 | alert(_L("Error: %1",errorThrown)); |
256 | daniel-mar | 70 | }, |
71 | success:function(data) { |
||
72 | if ("error" in data) { |
||
360 | daniel-mar | 73 | alert(_L("Error: %1",data.error)); |
381 | daniel-mar | 74 | } else if (data.status >= 0) { |
395 | daniel-mar | 75 | alert(data.status); |
76 | |||
381 | daniel-mar | 77 | if (data.status == 0/*OK*/) { |
395 | daniel-mar | 78 | alert(_L("Insert OK")); |
79 | } |
||
80 | |||
81 | if ((data.status & 1) == 1/*RaNotExisting*/) { |
||
82 | 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_'+id).value))) { |
||
83 | crudActionSendInvitation(parent, document.getElementById('ra_email_'+id).value); |
||
84 | return; |
||
381 | daniel-mar | 85 | } |
256 | daniel-mar | 86 | } |
395 | daniel-mar | 87 | |
88 | if ((data.status & 2) == 2/*RaNotExistingNoInvitation*/) { |
||
89 | alert(_L("Insert OK")); |
||
90 | } |
||
91 | |||
92 | if ((data.status & 4) == 4/*IsWellKnownOID*/) { |
||
93 | alert(_L("Insert OK. However, the RA and the ASN.1 and IRI identifiers were overwritten, because this OID is a well-known OID.")); |
||
94 | } |
||
95 | |||
96 | // TODO: auf reloadContent() verzichten. stattdessen nur tree links aktualisieren, und rechts eine neue zeile zur tabelle hinzufügen |
||
97 | reloadContent(); |
||
256 | daniel-mar | 98 | } else { |
360 | daniel-mar | 99 | alert(_L("Error: %1",data)); |
256 | daniel-mar | 100 | } |
101 | } |
||
102 | }); |
||
103 | } |
||
104 | |||
105 | function crudActionUpdate(id, parent) { |
||
393 | daniel-mar | 106 | if (id.startsWith('oid:') && !checkMissingOrDoubleASN1(id)) return; |
107 | |||
256 | daniel-mar | 108 | $.ajax({ |
109 | url:"ajax.php", |
||
110 | method:"POST", |
||
111 | data: { |
||
320 | daniel-mar | 112 | plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0", |
256 | daniel-mar | 113 | action:"Update", |
114 | id:id, |
||
115 | ra_email:document.getElementById('ra_email_'+id).value, |
||
116 | comment:document.getElementById('comment_'+id).value, |
||
117 | asn1ids:(document.getElementById('asn1ids_'+id) ? document.getElementById('asn1ids_'+id).value : null), |
||
118 | iris:(document.getElementById('iris_'+id) ? document.getElementById('iris_'+id).value : null), |
||
119 | confidential:(document.getElementById('hide_'+id) ? document.getElementById('hide_'+id).checked : null), |
||
120 | parent:parent |
||
121 | }, |
||
122 | error:function(jqXHR, textStatus, errorThrown) { |
||
360 | daniel-mar | 123 | alert(_L("Error: %1",errorThrown)); |
256 | daniel-mar | 124 | }, |
125 | success:function(data) { |
||
126 | if ("error" in data) { |
||
360 | daniel-mar | 127 | alert(_L("Error: %1",data.error)); |
381 | daniel-mar | 128 | } else if (data.status >= 0) { |
129 | if (data.status == 0/*OK*/) { |
||
130 | alert(_L("Update OK")); |
||
395 | daniel-mar | 131 | } |
132 | |||
133 | if ((data.status & 1) == 1/*RaNotExisting*/) { |
||
381 | daniel-mar | 134 | 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))) { |
135 | crudActionSendInvitation(parent, document.getElementById('ra_email_'+id).value); |
||
395 | daniel-mar | 136 | return; |
381 | daniel-mar | 137 | } |
395 | daniel-mar | 138 | } |
139 | |||
140 | if ((data.status & 2) == 2/*RaNotExistingNoInvitation*/) { |
||
381 | daniel-mar | 141 | alert(_L("Update OK")); |
256 | daniel-mar | 142 | } |
395 | daniel-mar | 143 | |
144 | if ((data.status & 4) == 4/*IsWellKnownOID*/) { |
||
145 | alert(_L("Update OK. However, the RA and the ASN.1 and IRI identifiers were overwritten, because this OID is a well-known OID.")); |
||
146 | } |
||
147 | |||
148 | // reloadContent(); |
||
149 | $('#oidtree').jstree("refresh"); |
||
256 | daniel-mar | 150 | } else { |
360 | daniel-mar | 151 | alert(_L("Error: %1",data)); |
256 | daniel-mar | 152 | } |
153 | } |
||
154 | }); |
||
155 | } |
||
156 | |||
157 | function crudActionDelete(id, parent) { |
||
360 | daniel-mar | 158 | if(!window.confirm(_L("Are you sure that you want to delete %1?",id))) return false; |
256 | daniel-mar | 159 | |
160 | $.ajax({ |
||
161 | url:"ajax.php", |
||
162 | method:"POST", |
||
163 | data: { |
||
320 | daniel-mar | 164 | plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0", |
256 | daniel-mar | 165 | action:"Delete", |
166 | id:id, |
||
167 | parent:parent |
||
168 | }, |
||
169 | error:function(jqXHR, textStatus, errorThrown) { |
||
360 | daniel-mar | 170 | alert(_L("Error: %1",errorThrown)); |
256 | daniel-mar | 171 | }, |
172 | success:function(data) { |
||
173 | if ("error" in data) { |
||
360 | daniel-mar | 174 | alert(_L("Error: %1",data.error)); |
381 | daniel-mar | 175 | } else if (data.status >= 0) { |
256 | daniel-mar | 176 | reloadContent(); |
393 | daniel-mar | 177 | // TODO: auf reloadContent() verzichten. stattdessen nur tree links aktualisieren, und rechts die zeile aus der tabelle löschen |
256 | daniel-mar | 178 | } else { |
360 | daniel-mar | 179 | alert(_L("Error: %1",data.error)); |
256 | daniel-mar | 180 | } |
181 | } |
||
182 | }); |
||
183 | } |
||
184 | |||
185 | function updateDesc() { |
||
186 | $.ajax({ |
||
187 | url:"ajax.php", |
||
188 | method:"POST", |
||
189 | data: { |
||
320 | daniel-mar | 190 | plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0", |
256 | daniel-mar | 191 | action:"Update2", |
192 | id:current_node, |
||
193 | title:(document.getElementById('titleedit') ? document.getElementById('titleedit').value : null), |
||
194 | //description:(document.getElementById('description') ? document.getElementById('description').value : null) |
||
195 | description:tinyMCE.get('description').getContent() |
||
196 | }, |
||
197 | error:function(jqXHR, textStatus, errorThrown) { |
||
360 | daniel-mar | 198 | alert(_L("Error: %1",errorThrown)); |
256 | daniel-mar | 199 | }, |
200 | success:function(data) { |
||
201 | if ("error" in data) { |
||
360 | daniel-mar | 202 | alert(_L("Error: %1",data.error)); |
381 | daniel-mar | 203 | } else if (data.status >= 0) { |
360 | daniel-mar | 204 | alert(_L("Update OK")); |
256 | daniel-mar | 205 | //reloadContent(); |
206 | $('#oidtree').jstree("refresh"); |
||
207 | var h1s = document.getElementsByTagName("h1"); |
||
208 | for (var i = 0; i < h1s.length; i++) { |
||
209 | var h1 = h1s[i]; |
||
210 | h1.innerHTML = document.getElementById('titleedit').value.htmlentities(); |
||
211 | } |
||
212 | document.title = combine_systemtitle_and_pagetitle(getOidPlusSystemTitle(), document.getElementById('titleedit').value); |
||
213 | |||
214 | var mce = tinymce.get('description'); |
||
215 | if (mce != null) mce.isNotDirty = 1; |
||
216 | } else { |
||
360 | daniel-mar | 217 | alert(_L("Error: %1",data.error)); |
256 | daniel-mar | 218 | } |
219 | } |
||
220 | }); |
||
221 | } |
||
222 | |||
223 | function crudActionSendInvitation(origin, email) { |
||
224 | // window.location.href = "?goto=oidplus:invite_ra$"+encodeURIComponent(email)+"$"+encodeURIComponent(origin); |
||
225 | openOidInPanel('oidplus:invite_ra$'+email+'$'+origin, false); |
||
226 | } |
||
227 | |||
228 | function frdl_weid_change() { |
||
229 | var from_base = 36; |
||
230 | var from_control = "#weid"; |
||
231 | var to_base = 10; |
||
232 | var to_control = "#id"; |
||
233 | |||
234 | var inp = $(from_control).val().trim(); |
||
235 | if (inp == "") { |
||
236 | $(to_control).val(""); |
||
237 | } else { |
||
238 | var x = BigNumber(inp, from_base); |
||
239 | if (isNaN(x)) { |
||
240 | $(to_control).val(""); |
||
241 | } else { |
||
242 | $(to_control).val(x.toString(to_base)); |
||
243 | } |
||
244 | } |
||
245 | } |
||
246 | |||
247 | function frdl_oidid_change() { |
||
248 | var from_base = 10; |
||
249 | var from_control = "#id"; |
||
250 | var to_base = 36; |
||
251 | var to_control = "#weid"; |
||
252 | |||
253 | var inp = $(from_control).val().trim(); |
||
254 | if (inp == "") { |
||
255 | $(to_control).val(""); |
||
256 | } else { |
||
257 | var x = BigNumber(inp, from_base); |
||
258 | if (isNaN(x)) { |
||
259 | $(to_control).val(""); |
||
260 | } else { |
||
261 | $(to_control).val(x.toString(to_base)); |
||
262 | } |
||
263 | } |
||
395 | daniel-mar | 264 | } |