Subversion Repositories oidplus

Rev

Rev 105 | Rev 108 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 105 Rev 107
Line 50... Line 50...
50
}
50
}
51
 
51
 
52
function getTreeLoadURL() {
52
function getTreeLoadURL() {
53
        var url = new URL(window.location.href);
53
        var url = new URL(window.location.href);
54
        var goto = url.searchParams.get("goto");
54
        var goto = url.searchParams.get("goto");
55
        return (goto != null) ? "treeload.php?goto="+encodeURIComponent(goto) : "treeload.php";
55
        return (goto != null) ? "ajax.php?action=tree_load&goto="+encodeURIComponent(goto)
-
 
56
                              : "ajax.php?action=tree_load";
56
}
57
}
57
 
58
 
58
function reloadContent() {
59
function reloadContent() {
59
        // document.location = '?goto='+encodeURIComponent(current_node);
60
        // document.location = '?goto='+encodeURIComponent(current_node);
60
        openOidInPanel(current_node);
61
        openOidInPanel(current_node, false);
61
        $('#oidtree').jstree("refresh");
62
        $('#oidtree').jstree("refresh");
62
}
63
}
63
 
64
 
64
function openOidInPanel(id, unselect=false) {
65
function x_rec(x_data, i) {
65
        console.log("openOidInPanel("+id+", "+unselect+")");
66
        $('#oidtree').jstree('open_node', x_data[i], function(e, data) {
-
 
67
                if (i+1 < x_data.length) {
-
 
68
                        x_rec(x_data, i+1);
-
 
69
                } else {
-
 
70
                        $('#oidtree').jstree('select_node', x_data[i]);
-
 
71
                }
-
 
72
        });
-
 
73
}
66
 
74
 
-
 
75
function openOidInPanel(id, reselect=false) {
67
        if (unselect) {
76
        if (reselect) {
68
                $('#oidtree').jstree('deselect_all');
77
                $('#oidtree').jstree('deselect_all');
-
 
78
 
-
 
79
                // If the node is already loaded in the tree, select it.
-
 
80
                // The select-event will load the content page, so we can return from this function.
69
                $('#oidtree').jstree('select_node', id);
81
                if ($('#oidtree').jstree('select_node', id)) return;
-
 
82
 
-
 
83
                // If the node is not loaded, then we try to search it.
-
 
84
                // If it can be found, then open all parent nodes and select the node
-
 
85
                $.ajax({
-
 
86
                        url:"ajax.php",
-
 
87
                        method:"POST",
-
 
88
                        data:{
-
 
89
                                action:"tree_search",
-
 
90
                                search:id
-
 
91
                        },
-
 
92
                        error:function(jqXHR, textStatus, errorThrown) {
-
 
93
                                openOidInPanel(id, false);
-
 
94
                        },
-
 
95
                        success:function(data) {
-
 
96
                                if ((data instanceof Array) && (data.length > 0) && ("error" in data)) {
-
 
97
                                        x_rec(data, 0);
-
 
98
                                } else {
-
 
99
                                        openOidInPanel(id, false);
-
 
100
                                }
-
 
101
                        }
-
 
102
                });
-
 
103
 
-
 
104
                // If something fails (e.g. if ajax.php=action=tree_search cannot find the node,
-
 
105
                // then openOidInPanel will be called again, without the reselect argument.
-
 
106
                // So we can now exit
-
 
107
                return;
70
        }
108
        }
71
 
109
 
72
        // $('#content_window').hide();
-
 
73
        document.title = "";
110
        document.title = "";
74
        $('#real_title').html("&nbsp;");
111
        $('#real_title').html("&nbsp;");
75
        $('#real_content').html("Loading...");
112
        $('#real_content').html("Loading...");
76
        $('#static_link').attr("href", "?goto="+encodeURIComponent(id));
113
        $('#static_link').attr("href", "?goto="+encodeURIComponent(id));
77
        $('#static_link_desktop').attr("href", "index_desktop.php?goto="+encodeURIComponent(id));
114
        $('#static_link_desktop').attr("href", "index_desktop.php?goto="+encodeURIComponent(id));
78
        $('#static_link_mobile').attr("href", "index_mobile.php?goto="+encodeURIComponent(id));
115
        $('#static_link_mobile').attr("href", "index_mobile.php?goto="+encodeURIComponent(id));
79
 
116
 
80
        if (popstate_running) return; // To avoid that the jstree selection during popstate() won't trigger another page load
117
        if (popstate_running) return; // To avoid that the jstree selection during popstate() won't trigger another page load
81
 
118
 
82
        // Normal opening of a description
119
        // Normal opening of a description
83
        fetch('get_description.php?id='+encodeURIComponent(id))
120
        fetch('ajax.php?action=get_description&id='+encodeURIComponent(id))
84
        .then(function(response) {
121
        .then(function(response) {
85
                response.json()
122
                response.json()
86
                .then(function(data) {
123
                .then(function(data) {
-
 
124
                        if ("error" in data) {
-
 
125
                                alert("Failed to load content: " + data.error);
-
 
126
                                console.error(data.error);
-
 
127
                                return;
-
 
128
                        }
-
 
129
 
87
                        data.id = id;
130
                        data.id = id;
88
 
131
 
89
                        document.title = combine_systemtitle_and_pagetitle(system_title, data.title);
132
                        document.title = combine_systemtitle_and_pagetitle(system_title, data.title);
90
                        var state = {
133
                        var state = {
91
                                "node_id":encodeURIComponent(id),
134
                                "node_id":id,
92
                                "titleHTML":(data.icon ? '<img src="'+data.icon+'" width="48" height="48" alt="'+data.title.htmlentities()+'"> ' : '') +data.title.htmlentities(),
135
                                "titleHTML":(data.icon ? '<img src="'+data.icon+'" width="48" height="48" alt="'+data.title.htmlentities()+'"> ' : '') +data.title.htmlentities(),
93
                                "textHTML":data.text,
136
                                "textHTML":data.text,
94
                                "staticlinkHREF":"?goto="+encodeURIComponent(id),
137
                                "staticlinkHREF":"?goto="+encodeURIComponent(id),
95
                                "staticlinkHREF_Desktop":"index_desktop.php?goto="+encodeURIComponent(id),
138
                                "staticlinkHREF_Desktop":"index_desktop.php?goto="+encodeURIComponent(id),
96
                                "staticlinkHREF_Mobile":"index_mobile.php?goto="+encodeURIComponent(id)
139
                                "staticlinkHREF_Mobile":"index_mobile.php?goto="+encodeURIComponent(id)
Line 109... Line 152...
109
                        $('#real_content').html(data.text);
152
                        $('#real_content').html(data.text);
110
                        document.title = combine_systemtitle_and_pagetitle(system_title, data.title);
153
                        document.title = combine_systemtitle_and_pagetitle(system_title, data.title);
111
                        current_node = id;
154
                        current_node = id;
112
                })
155
                })
113
                .catch(function(error) {
156
                .catch(function(error) {
-
 
157
                        alert("Failed to load content: " + error);
114
                        console.error(error);
158
                        console.error(error);
115
                });
159
                });
116
        })
160
        })
117
        .catch(function(error) {
161
        .catch(function(error) {
-
 
162
                alert("Failed to load content: " + error);
118
                console.error(error);
163
                console.error(error);
119
        });
164
        });
120
 
-
 
121
        // $('#content_window').show();
-
 
122
}
165
}
123
 
166
 
124
function updateDesc() {
167
function updateDesc() {
125
        $.ajax({
168
        $.ajax({
126
                url:"action.php",
169
                url:"ajax.php",
127
                method:"POST",
170
                method:"POST",
128
                data: {
171
                data: {
129
                        action:"Update2",
172
                        action:"Update2",
130
                        id:current_node,
173
                        id:current_node,
131
                        title:(document.getElementById('titleedit') ? document.getElementById('titleedit').value : null),
174
                        title:(document.getElementById('titleedit') ? document.getElementById('titleedit').value : null),
132
                        //description:(document.getElementById('description') ? document.getElementById('description').value : null)
175
                        //description:(document.getElementById('description') ? document.getElementById('description').value : null)
133
                        description:tinyMCE.get('description').getContent()
176
                        description:tinyMCE.get('description').getContent()
134
                },
177
                },
-
 
178
                error:function(jqXHR, textStatus, errorThrown) {
-
 
179
                        alert("Error: " + errorThrown);
-
 
180
                },
135
                success:function(data) {
181
                success:function(data) {
136
                        if (data != "OK") {
182
                        if ("error" in data) {
137
                                alert("Error: " + data);
183
                                alert("Error: " + data.error);
138
                        } else {
184
                        } else if (data.status == 0) {
139
                                alert("Update OK");
185
                                alert("Update OK");
140
                                //reloadContent();
186
                                //reloadContent();
141
                                $('#oidtree').jstree("refresh");
187
                                $('#oidtree').jstree("refresh");
142
                                var h1s = document.getElementsByTagName("h1");
188
                                var h1s = document.getElementsByTagName("h1");
143
                                for (var i = 0; i < h1s.length; i++) {
189
                                for (var i = 0; i < h1s.length; i++) {
Line 146... Line 192...
146
                                }
192
                                }
147
                                document.title = combine_systemtitle_and_pagetitle(system_title, document.getElementById('titleedit').value);
193
                                document.title = combine_systemtitle_and_pagetitle(system_title, document.getElementById('titleedit').value);
148
 
194
 
149
                                var mce = tinymce.get('description');
195
                                var mce = tinymce.get('description');
150
                                if (mce != null) mce.isNotDirty = 1;
196
                                if (mce != null) mce.isNotDirty = 1;
-
 
197
                        } else {
-
 
198
                                alert("Error: " + data.error);
151
                        }
199
                        }
152
                }
200
                }
153
        });
201
        });
154
}
202
}
155
 
203
 
156
function crudActionSendInvitation(origin, email) {
204
function crudActionSendInvitation(origin, email) {
157
        // document.location = '?goto=oidplus:invite_ra$'+email+'$'+origin;
205
        // document.location = '?goto=oidplus:invite_ra$'+email+'$'+origin;
158
 
206
 
159
        openOidInPanel('oidplus:invite_ra$'+email+'$'+origin);
207
        openOidInPanel('oidplus:invite_ra$'+email+'$'+origin, false);
160
 
208
 
161
}
209
}
162
 
210
 
163
function crudActionInsert(parent) {
211
function crudActionInsert(parent) {
164
        $.ajax({
212
        $.ajax({
165
                url:"action.php",
213
                url:"ajax.php",
166
                method:"POST",
214
                method:"POST",
167
                data:{
215
                data:{
168
                        action:"Insert",
216
                        action:"Insert",
169
                        id:document.getElementById('id').value,
217
                        id:document.getElementById('id').value,
170
                        ra_email:document.getElementById('ra_email').value,
218
                        ra_email:document.getElementById('ra_email').value,
171
                        asn1ids:(document.getElementById('asn1ids') ? document.getElementById('asn1ids').value : null),
219
                        asn1ids:(document.getElementById('asn1ids') ? document.getElementById('asn1ids').value : null),
172
                        iris:(document.getElementById('iris') ? document.getElementById('iris').value : null),
220
                        iris:(document.getElementById('iris') ? document.getElementById('iris').value : null),
173
                        confidential:(document.getElementById('hide') ? document.getElementById('hide').checked : null),
221
                        confidential:(document.getElementById('hide') ? document.getElementById('hide').checked : null),
174
                        parent:parent
222
                        parent:parent
175
                },
223
                },
-
 
224
                error:function(jqXHR, textStatus, errorThrown) {
-
 
225
                        alert("Error: " + errorThrown);
-
 
226
                },
176
                success:function(data) {
227
                success:function(data) {
177
                        if (data == "OK") {
228
                        if ("error" in data) {
-
 
229
                                alert("Error: " + data.error);
-
 
230
                        } else if (data.status == 0) {
178
                                //alert("Insert OK");
231
                                //alert("Insert OK");
179
                                reloadContent();
232
                                reloadContent();
180
                                // TODO: auf reloadContent() verzichten. stattdessen nur tree links aktualisieren, und rechts eine neue zeile zur tabelle hinzufügen
233
                                // TODO: auf reloadContent() verzichten. stattdessen nur tree links aktualisieren, und rechts eine neue zeile zur tabelle hinzufügen
181
                        } else if (data == "OK (RaNotInDatabase)") {
234
                        } else if (data.status == 1) {
182
                                if (confirm("Update OK. However, the email address you have entered ("+document.getElementById('ra_email').value+") is not in our system. Do you want to send an invitation, so that the RA can register an account to manage their OIDs?")) {
235
                                if (confirm("Update OK. However, the email address you have entered ("+document.getElementById('ra_email').value+") is not in our system. Do you want to send an invitation, so that the RA can register an account to manage their OIDs?")) {
183
                                        crudActionSendInvitation(parent, document.getElementById('ra_email').value);
236
                                        crudActionSendInvitation(parent, document.getElementById('ra_email').value);
184
                                } else {
237
                                } else {
185
                                        reloadContent();
238
                                        reloadContent();
186
                                        // TODO: auf reloadContent() verzichten. stattdessen nur tree links aktualisieren, und rechts eine neue zeile zur tabelle hinzufügen
239
                                        // TODO: auf reloadContent() verzichten. stattdessen nur tree links aktualisieren, und rechts eine neue zeile zur tabelle hinzufügen
Line 192... Line 245...
192
        });
245
        });
193
}
246
}
194
 
247
 
195
function crudActionUpdate(id, parent) {
248
function crudActionUpdate(id, parent) {
196
        $.ajax({
249
        $.ajax({
197
                url:"action.php",
250
                url:"ajax.php",
198
                method:"POST",
251
                method:"POST",
199
                data: {
252
                data: {
200
                        action:"Update",
253
                        action:"Update",
201
                        id:encodeURIComponent(id),
254
                        id:id,
202
                        ra_email:document.getElementById('ra_email_'+id).value,
255
                        ra_email:document.getElementById('ra_email_'+id).value,
203
                        asn1ids:(document.getElementById('asn1ids_'+id) ? document.getElementById('asn1ids_'+id).value : null),
256
                        asn1ids:(document.getElementById('asn1ids_'+id) ? document.getElementById('asn1ids_'+id).value : null),
204
                        iris:(document.getElementById('iris_'+id) ? document.getElementById('iris_'+id).value : null),
257
                        iris:(document.getElementById('iris_'+id) ? document.getElementById('iris_'+id).value : null),
205
                        confidential:(document.getElementById('hide_'+id) ? document.getElementById('hide_'+id).checked : null),
258
                        confidential:(document.getElementById('hide_'+id) ? document.getElementById('hide_'+id).checked : null),
206
                        parent:parent
259
                        parent:parent
207
                },
260
                },
-
 
261
                error:function(jqXHR, textStatus, errorThrown) {
-
 
262
                        alert("Error: " + errorThrown);
-
 
263
                },
208
                success:function(data) {
264
                success:function(data) {
209
                        if (data == "OK") {
265
                        if ("error" in data) {
-
 
266
                                alert("Error: " + data.error);
-
 
267
                        } else if (data.status == 0) {
210
                                alert("Update OK");
268
                                alert("Update OK");
211
                                // reloadContent();
269
                                // reloadContent();
212
                                $('#oidtree').jstree("refresh");
270
                                $('#oidtree').jstree("refresh");
213
                        } else if (data == "OK (RaNotInDatabase)") {
271
                        } else if (data.status == 1) {
214
                                if (confirm("Update OK. However, the email address you have entered ("+document.getElementById('ra_email_'+id).value+") is not in our system. Do you want to send an invitation, so that the RA can register an account to manage their OIDs?")) {
272
                                if (confirm("Update OK. However, the email address you have entered ("+document.getElementById('ra_email_'+id).value+") is not in our system. Do you want to send an invitation, so that the RA can register an account to manage their OIDs?")) {
215
                                        crudActionSendInvitation(parent, document.getElementById('ra_email_'+id).value);
273
                                        crudActionSendInvitation(parent, document.getElementById('ra_email_'+id).value);
216
                                } else {
274
                                } else {
217
                                        // reloadContent();
275
                                        // reloadContent();
218
                                        $('#oidtree').jstree("refresh");
276
                                        $('#oidtree').jstree("refresh");
Line 226... Line 284...
226
 
284
 
227
function crudActionDelete(id, parent) {
285
function crudActionDelete(id, parent) {
228
        if(!window.confirm("Are you sure that you want to delete "+id+"?")) return false;
286
        if(!window.confirm("Are you sure that you want to delete "+id+"?")) return false;
229
 
287
 
230
        $.ajax({
288
        $.ajax({
231
                url:"action.php",
289
                url:"ajax.php",
232
                method:"POST",
290
                method:"POST",
233
                data: {
291
                data: {
234
                        action:"Delete",
292
                        action:"Delete",
235
                        id:encodeURIComponent(id),
293
                        id:id,
236
                        parent:parent
294
                        parent:parent
237
                },
295
                },
-
 
296
                error:function(jqXHR, textStatus, errorThrown) {
-
 
297
                        alert("Error: " + errorThrown);
-
 
298
                },
238
                success:function(data) {
299
                success:function(data) {
239
                        if (data != "OK") {
300
                        if ("error" in data) {
240
                                alert("Error: " + data);
301
                                alert("Error: " + data.error);
241
                        } else {
302
                        } else if (data.status == 0) {
242
                                reloadContent();
303
                                reloadContent();
243
                                // TODO: auf reloadContent() verzichten. stattdessen nur tree links aktualisieren, und rechts die zeile aus der tabelle löschen
304
                                // TODO: auf reloadContent() verzichten. stattdessen nur tree links aktualisieren, und rechts die zeile aus der tabelle löschen
-
 
305
                        } else {
-
 
306
                                alert("Error: " + data.error);
244
                        }
307
                        }
245
                }
308
                }
246
        });
309
        });
247
}
310
}
248
 
311
 
249
function deleteRa(email, goto) {
312
function deleteRa(email, goto) {
250
        if(!window.confirm("Are you really sure that you want to delete "+email+"? (The OIDs stay active)")) return false;
313
        if(!window.confirm("Are you really sure that you want to delete "+email+"? (The OIDs stay active)")) return false;
251
 
314
 
252
        $.ajax({
315
        $.ajax({
253
                url:"action.php",
316
                url:"ajax.php",
254
                method:"POST",
317
                method:"POST",
255
                data: {
318
                data: {
256
                        action:"delete_ra",
319
                        action:"delete_ra",
257
                        email:email,
320
                        email:email,
258
                },
321
                },
-
 
322
                error:function(jqXHR, textStatus, errorThrown) {
-
 
323
                        alert("Error: " + errorThrown);
-
 
324
                },
259
                success:function(data) {
325
                success:function(data) {
260
                        if (data != "OK") {
326
                        if ("error" in data) {
261
                                alert("Error: " + data);
327
                                alert("Error: " + data.error);
262
                        } else {
328
                        } else if (data.status == 0) {
263
                                alert("Done.");
329
                                alert("Done.");
264
                                if (goto != null) document.location = '?goto=' + goto;
330
                                if (goto != null) document.location = '?goto=' + goto;
265
                                // reloadContent();
331
                                // reloadContent();
-
 
332
                        } else {
-
 
333
                                alert("Error: " + data.error);
266
                        }
334
                        }
267
                }
335
                }
268
        });
336
        });
269
}
337
}
270
 
338
 
-
 
339
// This function opens the "parentID" node, and then selects the "childID" node (which should be beneath the parent node)
271
function openAndSelectNode(childID, parentID) {
340
function openAndSelectNode(childID, parentID) {
272
        if ($('#oidtree').jstree(true).get_node(parentID)) {
341
        if ($('#oidtree').jstree(true).get_node(parentID)) {
273
                $('#oidtree').jstree('open_node', '#'+parentID, function(e, data) { // open parent node
342
                $('#oidtree').jstree('open_node', parentID, function(e, data) { // open parent node
274
                        if ($('#oidtree').jstree(true).get_node(childID)) { // is the child there?
343
                        if ($('#oidtree').jstree(true).get_node(childID)) { // is the child there?
275
                                $('#oidtree').jstree('deselect_all').jstree('select_node', '#'+childID); // select it
344
                                $('#oidtree').jstree('deselect_all').jstree('select_node', childID); // select it
276
                        } else {
345
                        } else {
277
                                // This can happen if the content page contains brand new items which are not in the treeview yet
346
                                // This can happen if the content page contains brand new items which are not in the treeview yet
278
                                document.location = "?goto="+encodeURIComponent(childID);
347
                                document.location = "?goto="+encodeURIComponent(childID);
279
                        }
348
                        }
280
                }, true);
349
                }, true);
Line 288... Line 357...
288
        popstate_running = true;
357
        popstate_running = true;
289
        try {
358
        try {
290
                var data = e.originalEvent.state;
359
                var data = e.originalEvent.state;
291
 
360
 
292
                current_node = data.node_id;
361
                current_node = data.node_id;
293
                $('#oidtree').jstree('deselect_all').jstree('select_node', data.node_id); // TODO: search and open the nodes
362
                $('#oidtree').jstree('deselect_all').jstree('select_node', data.node_id);
294
                $('#real_title').html(data.titleHTML);
363
                $('#real_title').html(data.titleHTML);
295
                $('#real_content').html(data.textHTML);
364
                $('#real_content').html(data.textHTML);
296
                $('#static_link').attr("href", data.staticlinkHREF);
365
                $('#static_link').attr("href", data.staticlinkHREF);
297
                $('#static_link_desktop').attr("href", data.staticlinkHREF_Desktop);
366
                $('#static_link_desktop').attr("href", data.staticlinkHREF_Desktop);
298
                $('#static_link_mobile').attr("href", data.staticlinkHREF_Mobile);
367
                $('#static_link_mobile').attr("href", data.staticlinkHREF_Mobile);
Line 330... Line 399...
330
        .on('ready.jstree', function (e, data) {
399
        .on('ready.jstree', function (e, data) {
331
                var url = new URL(window.location.href);
400
                var url = new URL(window.location.href);
332
                var goto = url.searchParams.get("goto");
401
                var goto = url.searchParams.get("goto");
333
                if (goto == null) goto = "oidplus:system"; // the page was not called with ?goto=...
402
                if (goto == null) goto = "oidplus:system"; // the page was not called with ?goto=...
334
 
403
 
335
                // By setting current_node, select_node() will not cause get_description.php to load (since we already loaded the first static content via PHP, for search engines mainly)
404
                // By setting current_node, select_node() will not cause ajax.php?action=get_description to load (since we already loaded the first static content via PHP, for search engines mainly)
336
                // But then we need to set the history state manually
405
                // But then we need to set the history state manually
337
                current_node = goto;
406
                current_node = goto;
338
                window.history.replaceState({
407
                window.history.replaceState({
339
                        "node_id":encodeURIComponent(goto),
408
                        "node_id":goto,
340
                        "titleHTML":$('#real_title').html(),
409
                        "titleHTML":$('#real_title').html(),
341
                        "textHTML":$('#real_content').html(),
410
                        "textHTML":$('#real_content').html(),
342
                        "staticlinkHREF":"?goto="+encodeURIComponent(goto),
411
                        "staticlinkHREF":"?goto="+encodeURIComponent(goto),
343
                        "staticlinkHREF_Desktop":"index_desktop.php?goto="+encodeURIComponent(goto),
412
                        "staticlinkHREF_Desktop":"index_desktop.php?goto="+encodeURIComponent(goto),
344
                        "staticlinkHREF_Mobile":"index_mobile.php?goto="+encodeURIComponent(goto)
413
                        "staticlinkHREF_Mobile":"index_mobile.php?goto="+encodeURIComponent(goto)
Line 352... Line 421...
352
                        $("#system_title_menu").removeClass("active");
421
                        $("#system_title_menu").removeClass("active");
353
                }
422
                }
354
 
423
 
355
                var id = selected.node.id;
424
                var id = selected.node.id;
356
                if (current_node != id) {
425
                if (current_node != id) {
357
                        openOidInPanel(id);
426
                        openOidInPanel(id, false);
358
                }
427
                }
359
        });
428
        });
360
 
429
 
361
        // --- Layout
430
        // --- Layout
362
 
431