Subversion Repositories oidplus

Rev

Rev 410 | 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
 
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];
64
                                        if (toCheck == candidate) {
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:{
320 daniel-mar 82
                        plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0",
256 daniel-mar 83
                        action:"Insert",
84
                        id:document.getElementById('id').value,
85
                        ra_email:document.getElementById('ra_email').value,
86
                        comment:document.getElementById('comment').value,
87
                        asn1ids:(document.getElementById('asn1ids') ? document.getElementById('asn1ids').value : null),
88
                        iris:(document.getElementById('iris') ? document.getElementById('iris').value : null),
89
                        confidential:(document.getElementById('hide') ? document.getElementById('hide').checked : null),
90
                        weid:(document.getElementById('weid') ? document.getElementById('weid').checked : null),
91
                        parent:parent
92
                },
93
                error:function(jqXHR, textStatus, errorThrown) {
360 daniel-mar 94
                        alert(_L("Error: %1",errorThrown));
256 daniel-mar 95
                },
96
                success:function(data) {
97
                        if ("error" in data) {
360 daniel-mar 98
                                alert(_L("Error: %1",data.error));
381 daniel-mar 99
                        } else if (data.status >= 0) {
100
                                if (data.status == 0/*OK*/) {
395 daniel-mar 101
                                        alert(_L("Insert OK"));
102
                                }
103
 
104
                                if ((data.status & 1) == 1/*RaNotExisting*/) {
105
                                        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))) {
106
                                                crudActionSendInvitation(parent, document.getElementById('ra_email_'+id).value);
107
                                                return;
381 daniel-mar 108
                                        }
256 daniel-mar 109
                                }
395 daniel-mar 110
 
111
                                if ((data.status & 2) == 2/*RaNotExistingNoInvitation*/) {
112
                                        alert(_L("Insert OK"));
113
                                }
114
 
115
                                if ((data.status & 4) == 4/*IsWellKnownOID*/) {
116
                                        alert(_L("Insert OK. However, the RA and the ASN.1 and IRI identifiers were overwritten, because this OID is a well-known OID."));
117
                                }
118
 
119
                                // TODO: auf reloadContent() verzichten. stattdessen nur tree links aktualisieren, und rechts eine neue zeile zur tabelle hinzufĂĽgen
120
                                reloadContent();
256 daniel-mar 121
                        } else {
360 daniel-mar 122
                                alert(_L("Error: %1",data));
256 daniel-mar 123
                        }
124
                }
125
        });
126
}
127
 
128
function crudActionUpdate(id, parent) {
393 daniel-mar 129
        if (id.startsWith('oid:') && !checkMissingOrDoubleASN1(id)) return;
130
 
256 daniel-mar 131
        $.ajax({
132
                url:"ajax.php",
133
                method:"POST",
134
                data: {
320 daniel-mar 135
                        plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0",
256 daniel-mar 136
                        action:"Update",
137
                        id:id,
138
                        ra_email:document.getElementById('ra_email_'+id).value,
139
                        comment:document.getElementById('comment_'+id).value,
140
                        asn1ids:(document.getElementById('asn1ids_'+id) ? document.getElementById('asn1ids_'+id).value : null),
141
                        iris:(document.getElementById('iris_'+id) ? document.getElementById('iris_'+id).value : null),
142
                        confidential:(document.getElementById('hide_'+id) ? document.getElementById('hide_'+id).checked : null),
143
                        parent:parent
144
                },
145
                error:function(jqXHR, textStatus, errorThrown) {
360 daniel-mar 146
                        alert(_L("Error: %1",errorThrown));
256 daniel-mar 147
                },
148
                success:function(data) {
149
                        if ("error" in data) {
360 daniel-mar 150
                                alert(_L("Error: %1",data.error));
381 daniel-mar 151
                        } else if (data.status >= 0) {
152
                                if (data.status == 0/*OK*/) {
153
                                        alert(_L("Update OK"));
395 daniel-mar 154
                                }
155
 
156
                                if ((data.status & 1) == 1/*RaNotExisting*/) {
381 daniel-mar 157
                                        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))) {
158
                                                crudActionSendInvitation(parent, document.getElementById('ra_email_'+id).value);
395 daniel-mar 159
                                                return;
381 daniel-mar 160
                                        }
395 daniel-mar 161
                                }
162
 
163
                                if ((data.status & 2) == 2/*RaNotExistingNoInvitation*/) {
381 daniel-mar 164
                                        alert(_L("Update OK"));
256 daniel-mar 165
                                }
395 daniel-mar 166
 
167
                                if ((data.status & 4) == 4/*IsWellKnownOID*/) {
168
                                        alert(_L("Update OK. However, the RA and the ASN.1 and IRI identifiers were overwritten, because this OID is a well-known OID."));
169
                                }
170
 
171
                                // reloadContent();
172
                                $('#oidtree').jstree("refresh");
256 daniel-mar 173
                        } else {
360 daniel-mar 174
                                alert(_L("Error: %1",data));
256 daniel-mar 175
                        }
176
                }
177
        });
178
}
179
 
180
function crudActionDelete(id, parent) {
360 daniel-mar 181
        if(!window.confirm(_L("Are you sure that you want to delete %1?",id))) return false;
256 daniel-mar 182
 
183
        $.ajax({
184
                url:"ajax.php",
185
                method:"POST",
186
                data: {
320 daniel-mar 187
                        plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0",
256 daniel-mar 188
                        action:"Delete",
189
                        id:id,
190
                        parent:parent
191
                },
192
                error:function(jqXHR, textStatus, errorThrown) {
360 daniel-mar 193
                        alert(_L("Error: %1",errorThrown));
256 daniel-mar 194
                },
195
                success:function(data) {
196
                        if ("error" in data) {
360 daniel-mar 197
                                alert(_L("Error: %1",data.error));
381 daniel-mar 198
                        } else if (data.status >= 0) {
256 daniel-mar 199
                                reloadContent();
393 daniel-mar 200
                                // TODO: auf reloadContent() verzichten. stattdessen nur tree links aktualisieren, und rechts die zeile aus der tabelle löschen
256 daniel-mar 201
                        } else {
360 daniel-mar 202
                                alert(_L("Error: %1",data.error));
256 daniel-mar 203
                        }
204
                }
205
        });
206
}
207
 
208
function updateDesc() {
209
        $.ajax({
210
                url:"ajax.php",
211
                method:"POST",
212
                data: {
320 daniel-mar 213
                        plugin:"1.3.6.1.4.1.37476.2.5.2.4.1.0",
256 daniel-mar 214
                        action:"Update2",
215
                        id:current_node,
216
                        title:(document.getElementById('titleedit') ? document.getElementById('titleedit').value : null),
217
                        //description:(document.getElementById('description') ? document.getElementById('description').value : null)
218
                        description:tinyMCE.get('description').getContent()
219
                },
220
                error:function(jqXHR, textStatus, errorThrown) {
360 daniel-mar 221
                        alert(_L("Error: %1",errorThrown));
256 daniel-mar 222
                },
223
                success:function(data) {
224
                        if ("error" in data) {
360 daniel-mar 225
                                alert(_L("Error: %1",data.error));
381 daniel-mar 226
                        } else if (data.status >= 0) {
360 daniel-mar 227
                                alert(_L("Update OK"));
256 daniel-mar 228
                                //reloadContent();
229
                                $('#oidtree').jstree("refresh");
230
                                var h1s = document.getElementsByTagName("h1");
231
                                for (var i = 0; i < h1s.length; i++) {
232
                                        var h1 = h1s[i];
233
                                        h1.innerHTML = document.getElementById('titleedit').value.htmlentities();
234
                                }
235
                                document.title = combine_systemtitle_and_pagetitle(getOidPlusSystemTitle(), document.getElementById('titleedit').value);
236
 
237
                                var mce = tinymce.get('description');
414 daniel-mar 238
                                if (mce != null) mce.setDirty(false);
256 daniel-mar 239
                        } else {
360 daniel-mar 240
                                alert(_L("Error: %1",data.error));
256 daniel-mar 241
                        }
242
                }
243
        });
244
}
245
 
246
function crudActionSendInvitation(origin, email) {
247
        // window.location.href = "?goto=oidplus:invite_ra$"+encodeURIComponent(email)+"$"+encodeURIComponent(origin);
248
        openOidInPanel('oidplus:invite_ra$'+email+'$'+origin, false);
249
}
250
 
251
function frdl_weid_change() {
252
        var from_base = 36;
253
        var from_control = "#weid";
254
        var to_base = 10;
255
        var to_control = "#id";
256
 
257
        var inp = $(from_control).val().trim();
258
        if (inp == "") {
259
                $(to_control).val("");
260
        } else {
261
                var x = BigNumber(inp, from_base);
262
                if (isNaN(x)) {
263
                        $(to_control).val("");
264
                } else {
265
                        $(to_control).val(x.toString(to_base));
266
                }
267
        }
268
}
269
 
270
function frdl_oidid_change() {
271
        var from_base = 10;
272
        var from_control = "#id";
273
        var to_base = 36;
274
        var to_control = "#weid";
275
 
276
        var inp = $(from_control).val().trim();
277
        if (inp == "") {
278
                $(to_control).val("");
279
        } else {
280
                var x = BigNumber(inp, from_base);
281
                if (isNaN(x)) {
282
                        $(to_control).val("");
283
                } else {
284
                        $(to_control).val(x.toString(to_base));
285
                }
286
        }
395 daniel-mar 287
}