1 | //Some "constants" to match the server constants
|
---|
2 | var SUCCESS = 1;
|
---|
3 | var ACCEPTED = 2;
|
---|
4 | var ERROR = 3;
|
---|
5 | var CONTINUING = 10;
|
---|
6 | var COMPLETED = 11;
|
---|
7 | var HALTED = 12;
|
---|
8 |
|
---|
9 | function getElementsByClassName(cl, parent)
|
---|
10 | {
|
---|
11 | var elemArray = [];
|
---|
12 | var classRegEx = new RegExp("\\b" + cl + "\\b");
|
---|
13 | var elems;
|
---|
14 | if(parent)
|
---|
15 | {
|
---|
16 | elems = parent.getElementsByTagName("*");
|
---|
17 | }
|
---|
18 | else
|
---|
19 | {
|
---|
20 | elems = document.getElementsByTagName("*");
|
---|
21 | }
|
---|
22 |
|
---|
23 | for (var i = 0; i < elems.length; i++)
|
---|
24 | {
|
---|
25 | var classeName = elems[i].className;
|
---|
26 | if (classRegEx.test(classeName)) elemArray.push(elems[i]);
|
---|
27 | }
|
---|
28 |
|
---|
29 | return elemArray;
|
---|
30 | };
|
---|
31 |
|
---|
32 | function getNextSiblingOfType(elem, type)
|
---|
33 | {
|
---|
34 | if(elem == null)
|
---|
35 | {
|
---|
36 | return null;
|
---|
37 | }
|
---|
38 |
|
---|
39 | var current = elem.nextSibling;
|
---|
40 | while(current != null)
|
---|
41 | {
|
---|
42 | if(current.nodeName.toLowerCase() == type)
|
---|
43 | {
|
---|
44 | return current;
|
---|
45 | }
|
---|
46 |
|
---|
47 | current = current.nextSibling;
|
---|
48 | }
|
---|
49 | return null;
|
---|
50 | }
|
---|
51 |
|
---|
52 | function getPrevSiblingOfType(elem, type)
|
---|
53 | {
|
---|
54 | if(elem == null)
|
---|
55 | {
|
---|
56 | return null;
|
---|
57 | }
|
---|
58 |
|
---|
59 | var current = elem.previousSibling;
|
---|
60 | while(current != null)
|
---|
61 | {
|
---|
62 | if(current.nodeName.toLowerCase() == type)
|
---|
63 | {
|
---|
64 | return current;
|
---|
65 | }
|
---|
66 |
|
---|
67 | current = current.previousSibling;
|
---|
68 | }
|
---|
69 | return null;
|
---|
70 | }
|
---|
71 |
|
---|
72 | function saveTransaction(transaction)
|
---|
73 | {
|
---|
74 | console.log(transaction);
|
---|
75 | _transactions.push(transaction);
|
---|
76 | }
|
---|
77 |
|
---|
78 | function undo()
|
---|
79 | {
|
---|
80 | if(_undoOperations.length == 0)
|
---|
81 | {
|
---|
82 | return;
|
---|
83 | }
|
---|
84 |
|
---|
85 | var undoOp = _undoOperations.pop();
|
---|
86 |
|
---|
87 | //Create/Duplicate undo
|
---|
88 | if(undoOp.op == "del")
|
---|
89 | {
|
---|
90 | if(undoOp.srcElem.childList)
|
---|
91 | {
|
---|
92 | removeFromParent(undoOp.srcElem.childList);
|
---|
93 | }
|
---|
94 | if(undoOp.srcElem.parentItem)
|
---|
95 | {
|
---|
96 | undoOp.srcElem.parentItem.menu.newSectionLink.style.display = "inline";
|
---|
97 | undoOp.srcElem.parentItem.childList = null;
|
---|
98 | }
|
---|
99 | removeFromParent(undoOp.srcElem);
|
---|
100 | }
|
---|
101 |
|
---|
102 | if(undoOp.op == "delMeta")
|
---|
103 | {
|
---|
104 | if(undoOp.srcElem.childList)
|
---|
105 | {
|
---|
106 | removeFromParent(undoOp.srcElem.childList);
|
---|
107 | }
|
---|
108 | if(undoOp.srcElem.parentItem)
|
---|
109 | {
|
---|
110 | undoOp.srcElem.parentItem.menu.newSectionLink.style.display = "inline";
|
---|
111 | undoOp.srcElem.parentItem.childList = null;
|
---|
112 | }
|
---|
113 | de.doc.unregisterEditSection(undoOp.srcElem);
|
---|
114 | removeFromParent(undoOp.srcElem);
|
---|
115 | }
|
---|
116 |
|
---|
117 | //Move undo (mva is move after, mvb is move before, mvi is move into)
|
---|
118 | else if(undoOp.op == "mva" || undoOp.op == "mvb" || undoOp.op == "mvi")
|
---|
119 | {
|
---|
120 | if(undoOp.op == "mvb")
|
---|
121 | {
|
---|
122 | undoOp.refElem.parentNode.insertBefore(undoOp.srcElem, undoOp.refElem);
|
---|
123 | }
|
---|
124 | else if(undoOp.op == "mva")
|
---|
125 | {
|
---|
126 | insertAfter(undoOp.srcElem, undoOp.refElem);
|
---|
127 | }
|
---|
128 | else
|
---|
129 | {
|
---|
130 | undoOp.refElem.removeChild(undoOp.refElem.firstChild);
|
---|
131 | undoOp.refElem.appendChild(undoOp.srcElem);
|
---|
132 | }
|
---|
133 |
|
---|
134 | if(undoOp.srcElem.textDiv)
|
---|
135 | {
|
---|
136 | insertAfter(undoOp.srcElem.textDiv, undoOp.srcElem);
|
---|
137 | }
|
---|
138 | if(undoOp.srcElem.childList)
|
---|
139 | {
|
---|
140 | insertAfter(undoOp.srcElem.childList, undoOp.srcElem.textDiv);
|
---|
141 | }
|
---|
142 |
|
---|
143 | if(undoOp.srcElem.onmouseout)
|
---|
144 | {
|
---|
145 | //Uncolour the section if it coloured
|
---|
146 | undoOp.srcElem.onmouseout();
|
---|
147 | }
|
---|
148 | updateFromTop();
|
---|
149 | }
|
---|
150 | else if(undoOp.op == "display")
|
---|
151 | {
|
---|
152 | undoOp.srcElem.style.display = undoOp.subOp;
|
---|
153 | }
|
---|
154 |
|
---|
155 | if(undoOp.removeDeletedMetadata)
|
---|
156 | {
|
---|
157 | _deletedMetadata.pop();
|
---|
158 | }
|
---|
159 |
|
---|
160 | if(undoOp.removeTransaction)
|
---|
161 | {
|
---|
162 | _transactions.pop();
|
---|
163 | }
|
---|
164 | }
|
---|
165 |
|
---|
166 | function addCollectionToBuild(collection)
|
---|
167 | {
|
---|
168 | for(var i = 0; i < _collectionsToBuild.length; i++)
|
---|
169 | {
|
---|
170 | if(collection == _collectionsToBuild[i])
|
---|
171 | {
|
---|
172 | return;
|
---|
173 | }
|
---|
174 | }
|
---|
175 | _collectionsToBuild.push(collection);
|
---|
176 | }
|
---|
177 |
|
---|
178 | function save()
|
---|
179 | {
|
---|
180 | //This works in most cases but will not work when taking a doc from one collection to another, will need to be fixed at some point
|
---|
181 | var collection;
|
---|
182 | if(gs.cgiParams.c && gs.cgiParams.c != "")
|
---|
183 | {
|
---|
184 | collection = gs.cgiParams.c
|
---|
185 | }
|
---|
186 | else
|
---|
187 | {
|
---|
188 | collection = gs.cgiParams.p_c
|
---|
189 | }
|
---|
190 |
|
---|
191 | for(var i = 0; i < _deletedMetadata.length; i++)
|
---|
192 | {
|
---|
193 | var currentRow = _deletedMetadata[i];
|
---|
194 |
|
---|
195 | //Get document ID
|
---|
196 | var currentElem = currentRow;
|
---|
197 | while((currentElem = currentElem.parentNode).tagName != "TABLE");
|
---|
198 | var docID = currentElem.getAttribute("id").substring(4);
|
---|
199 |
|
---|
200 | //Get metadata name
|
---|
201 | var cells = currentRow.getElementsByTagName("TD");
|
---|
202 | var nameCell = cells[0];
|
---|
203 | var name = nameCell.innerHTML;
|
---|
204 | var valueCell = cells[1];
|
---|
205 | var value = valueCell.innerHTML;
|
---|
206 |
|
---|
207 | gs.functions.removeArchivesMetadata(collection, gs.xsltParams.site_name, docID, name, null, value, function(){console.log("REMOVED ARCHIVES");});
|
---|
208 | addCollectionToBuild(collection);
|
---|
209 |
|
---|
210 | removeFromParent(currentRow);
|
---|
211 | }
|
---|
212 |
|
---|
213 | var changes = de.Changes.getChangedEditableSections();
|
---|
214 |
|
---|
215 | for(var i = 0; i < changes.length; i++)
|
---|
216 | {
|
---|
217 | var changedElem = changes[i];
|
---|
218 |
|
---|
219 | //Save metadata
|
---|
220 | if(gs.functions.hasClass(changedElem, "metaTableCell"))
|
---|
221 | {
|
---|
222 | //Get document ID
|
---|
223 | var currentElem = changedElem;
|
---|
224 | while((currentElem = currentElem.parentNode).tagName != "TABLE");
|
---|
225 | var docID = currentElem.getAttribute("id").substring(4);
|
---|
226 |
|
---|
227 | //Get metadata name
|
---|
228 | var row = changedElem.parentNode;
|
---|
229 | var cells = row.getElementsByTagName("TD");
|
---|
230 | var nameCell = cells[0];
|
---|
231 | var name = nameCell.innerHTML;
|
---|
232 | var value = changedElem.innerHTML;
|
---|
233 | value = value.replace(/ /g, " ");
|
---|
234 | value = escape(value);
|
---|
235 |
|
---|
236 | if(changedElem.originalValue)
|
---|
237 | {
|
---|
238 | gs.functions.setArchivesMetadata(collection, gs.xsltParams.site_name, docID, name, null, value, changedElem.originalValue, "override", function(){console.log("SAVED ARCHIVES");});
|
---|
239 | }
|
---|
240 | else
|
---|
241 | {
|
---|
242 | gs.functions.setArchivesMetadata(collection, gs.xsltParams.site_name, docID, name, null, value, null, "accumulate", function(){console.log("SAVED ARCHIVES");});
|
---|
243 | }
|
---|
244 | changedElem.originalValue = changedElem.innerHTML;
|
---|
245 | addCollectionToBuild(collection);
|
---|
246 | }
|
---|
247 | //Save content
|
---|
248 | else if(gs.functions.hasClass(changedElem, "renderedText"))
|
---|
249 | {
|
---|
250 | var section = changedElem.parentDiv.parentItem;
|
---|
251 | saveTransaction('{"operation":"setText", "text":"' + changedElem.innerHTML.replace(/"/g, "\\\"").replace(/&/g, "%26") + '", "collection":"' + section.collection + '", "oid":"' + section.nodeID + '"}');
|
---|
252 | addCollectionToBuild(section.collection);
|
---|
253 | }
|
---|
254 | else if(gs.functions.hasClass(changedElem, "sectionText"))
|
---|
255 | {
|
---|
256 | var id = changedElem.getAttribute("id");
|
---|
257 | var sectionID = id.substring(4);
|
---|
258 | saveTransaction('{"operation":"setText", "text":"' + changedElem.innerHTML.replace(/"/g, "\\\"").replace(/&/g, "%26") + '", "collection":"' + gs.cgiParams.c + '", "oid":"' + sectionID + '"}');
|
---|
259 | addCollectionToBuild(gs.cgiParams.c);
|
---|
260 | }
|
---|
261 | }
|
---|
262 |
|
---|
263 | var request = "[";
|
---|
264 | for(var i = 0; i < _transactions.length; i++)
|
---|
265 | {
|
---|
266 | request += _transactions[i];
|
---|
267 | if(i != _transactions.length - 1)
|
---|
268 | {
|
---|
269 | request += ",";
|
---|
270 | }
|
---|
271 | }
|
---|
272 | request += "]";
|
---|
273 |
|
---|
274 | var statusID;
|
---|
275 | var ajax = new gs.functions.ajaxRequest();
|
---|
276 | ajax.open("POST", gs.xsltParams.library_name, true);
|
---|
277 | ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
---|
278 | ajax.onreadystatechange = function()
|
---|
279 | {
|
---|
280 | if(ajax.readyState == 4 && ajax.status == 200)
|
---|
281 | {
|
---|
282 | var text = ajax.responseText;
|
---|
283 | var xml = validateXML(text);
|
---|
284 |
|
---|
285 | var errorElems;
|
---|
286 | if(!xml || checkForErrors(xml))
|
---|
287 | {
|
---|
288 | alert(gs.text.dse.error_saving);
|
---|
289 |
|
---|
290 | var saveButton = document.getElementById("saveButton");
|
---|
291 | saveButton.innerHTML = gs.text.dse.save_changes;
|
---|
292 | saveButton.disabled = false;
|
---|
293 |
|
---|
294 | _statusBar.removeStatus(statusID);
|
---|
295 | return;
|
---|
296 | }
|
---|
297 |
|
---|
298 | _statusBar.removeStatus(statusID);
|
---|
299 | buildCollections(_collectionsToBuild);
|
---|
300 | }
|
---|
301 | }
|
---|
302 |
|
---|
303 | if(_collectionsToBuild.length > 0)
|
---|
304 | {
|
---|
305 | var saveButton = document.getElementById("saveButton");
|
---|
306 | saveButton.innerHTML = gs.text.dse.saving + "...";
|
---|
307 | saveButton.disabled = true;
|
---|
308 |
|
---|
309 | statusID = _statusBar.addStatus(gs.text.dse.modifying_archives + "...");
|
---|
310 | ajax.send("a=g&rt=r&s=DocumentExecuteTransaction&s1.transactions=" + request);
|
---|
311 | }
|
---|
312 | }
|
---|
313 |
|
---|
314 | function buildCollections(collections, documents, callback)
|
---|
315 | {
|
---|
316 | var saveButton = document.getElementById("saveButton");
|
---|
317 | if(!collections || collections.length == 0)
|
---|
318 | {
|
---|
319 | console.log(gs.text.dse.empty_collection_list);
|
---|
320 | saveButton.innerHTML = gs.text.save_changes;
|
---|
321 | saveButton.disabled = false;
|
---|
322 | return;
|
---|
323 | }
|
---|
324 |
|
---|
325 | var docs = "";
|
---|
326 | var buildOperation = "";
|
---|
327 | if(documents)
|
---|
328 | {
|
---|
329 | buildOperation = "ImportCollection";
|
---|
330 | docs += "&s1.documents=";
|
---|
331 | for(var i = 0; i < documents.length; i++)
|
---|
332 | {
|
---|
333 | docs += documents[i];
|
---|
334 | if(i < documents.length - 1)
|
---|
335 | {
|
---|
336 | docs += ",";
|
---|
337 | }
|
---|
338 | }
|
---|
339 | }
|
---|
340 | else
|
---|
341 | {
|
---|
342 | buildOperation = "BuildAndActivateCollection";
|
---|
343 | }
|
---|
344 |
|
---|
345 | var counter = 0;
|
---|
346 | var statusID = 0;
|
---|
347 | var buildFunction = function()
|
---|
348 | {
|
---|
349 | var ajax = new gs.functions.ajaxRequest();
|
---|
350 | ajax.open("GET", _baseURL + "?a=g&rt=r&ro=1&s=" + buildOperation + "&s1.collection=" + collections[counter] + docs);
|
---|
351 | ajax.onreadystatechange = function()
|
---|
352 | {
|
---|
353 | if(ajax.readyState == 4 && ajax.status == 200)
|
---|
354 | {
|
---|
355 | var text = ajax.responseText;
|
---|
356 | var xml = validateXML(text);
|
---|
357 |
|
---|
358 | if(!xml || checkForErrors(xml))
|
---|
359 | {
|
---|
360 | alert(gs.text.dse.could_not_build_p1 + " " + collections[counter] + gs.text.dse.could_not_build_p2);
|
---|
361 |
|
---|
362 | _statusBar.removeStatus(statusID);
|
---|
363 | saveButton.innerHTML = gs.text.dse.save_changes;
|
---|
364 | saveButton.disabled = false;
|
---|
365 |
|
---|
366 | return;
|
---|
367 | }
|
---|
368 |
|
---|
369 | var status = xml.getElementsByTagName("status")[0];
|
---|
370 | var pid = status.getAttribute("pid");
|
---|
371 |
|
---|
372 | startCheckLoop(pid, buildOperation, statusID, function()
|
---|
373 | {
|
---|
374 | /*
|
---|
375 | var localAjax = new gs.functions.ajaxRequest();
|
---|
376 | localAjax.open("GET", _baseURL + "?a=g&rt=r&ro=1&s=ActivateCollection&s1.collection=" + collections[counter], true);
|
---|
377 | localAjax.onreadystatechange = function()
|
---|
378 | {
|
---|
379 | if(localAjax.readyState == 4 && localAjax.status == 200)
|
---|
380 | {
|
---|
381 | var localText = localAjax.responseText;
|
---|
382 | var localXML = validateXML(localText);
|
---|
383 |
|
---|
384 | if(!xml || checkForErrors(xml))
|
---|
385 | {
|
---|
386 | alert(gs.text.dse.could_not_activate_p1 + " " + collections[counter] + gs.text.dse.could_not_activate_p2);
|
---|
387 |
|
---|
388 | _statusBar.removeStatus(statusID);
|
---|
389 | saveButton.innerHTML = gs.text.dse.save_changes;
|
---|
390 | saveButton.disabled = false;
|
---|
391 |
|
---|
392 | return;
|
---|
393 | }
|
---|
394 |
|
---|
395 | var localStatus = localXML.getElementsByTagName("status")[0];
|
---|
396 | if(localStatus)
|
---|
397 | {
|
---|
398 | var localPID = localStatus.getAttribute("pid");
|
---|
399 | startCheckLoop(localPID, "ActivateCollection", statusID, function()
|
---|
400 | {
|
---|
401 | */
|
---|
402 | if(counter == collections.length - 1)
|
---|
403 | {
|
---|
404 | removeCollectionsFromBuildList(collections);
|
---|
405 | if(callback)
|
---|
406 | {
|
---|
407 | callback();
|
---|
408 | }
|
---|
409 | }
|
---|
410 | else
|
---|
411 | {
|
---|
412 | counter++;
|
---|
413 | buildFunction();
|
---|
414 | }
|
---|
415 |
|
---|
416 | _transactions = new Array();
|
---|
417 |
|
---|
418 | _statusBar.removeStatus(statusID);
|
---|
419 | saveButton.innerHTML = gs.text.dse.save_changes;
|
---|
420 | saveButton.disabled = false;
|
---|
421 | /*
|
---|
422 | });
|
---|
423 | }
|
---|
424 | }
|
---|
425 | }
|
---|
426 | _statusBar.changeStatus(statusID, gs.text.dse.activating + " " + collections[counter] + "...");
|
---|
427 | localAjax.send();
|
---|
428 | */
|
---|
429 | });
|
---|
430 | }
|
---|
431 | }
|
---|
432 | statusID = _statusBar.addStatus(gs.text.dse.building + " " + collections[counter] + "...");
|
---|
433 | ajax.send();
|
---|
434 | }
|
---|
435 | buildFunction();
|
---|
436 | }
|
---|
437 |
|
---|
438 | function startCheckLoop(pid, serverFunction, statusID, callbackFunction)
|
---|
439 | {
|
---|
440 | var ajaxFunction = function()
|
---|
441 | {
|
---|
442 | var saveButton = document.getElementById("saveButton");
|
---|
443 |
|
---|
444 | var ajax = new gs.functions.ajaxRequest();
|
---|
445 | ajax.open("GET", _baseURL + "?a=g&rt=s&ro=1&s=" + serverFunction + "&s1.pid=" + pid, true);
|
---|
446 | ajax.onreadystatechange = function()
|
---|
447 | {
|
---|
448 | if(ajax.readyState == 4 && ajax.status == 200)
|
---|
449 | {
|
---|
450 | var text = ajax.responseText;
|
---|
451 | var xml = validateXML(text);
|
---|
452 |
|
---|
453 | if(!xml || checkForErrors(xml))
|
---|
454 | {
|
---|
455 | alert(gs.text.dse.could_not_check_status_p1 + " " + serverFunction + gs.text.dse.could_not_check_status_p2a);
|
---|
456 |
|
---|
457 | _statusBar.removeStatus(statusID);
|
---|
458 | saveButton.innerHTML = gs.text.dse.save_changes;
|
---|
459 | saveButton.disabled = false;
|
---|
460 |
|
---|
461 | return;
|
---|
462 | }
|
---|
463 |
|
---|
464 | var status = xml.getElementsByTagName("status")[0];
|
---|
465 | var code = status.getAttribute("code");
|
---|
466 |
|
---|
467 | if (code == COMPLETED || code == SUCCESS)
|
---|
468 | {
|
---|
469 | callbackFunction();
|
---|
470 | }
|
---|
471 | else if (code == HALTED || code == ERROR)
|
---|
472 | {
|
---|
473 | alert(gs.text.dse.could_not_check_status_p1 + " " + serverFunction + gs.text.dse.could_not_check_status_p2b);
|
---|
474 |
|
---|
475 | _statusBar.removeStatus(statusID);
|
---|
476 | saveButton.innerHTML = gs.text.dse.save_changes;
|
---|
477 | saveButton.disabled = false;
|
---|
478 | }
|
---|
479 | else
|
---|
480 | {
|
---|
481 | setTimeout(ajaxFunction, 1000);
|
---|
482 | }
|
---|
483 | }
|
---|
484 | }
|
---|
485 | ajax.send();
|
---|
486 | }
|
---|
487 | ajaxFunction();
|
---|
488 | }
|
---|
489 |
|
---|
490 | function removeCollectionsFromBuildList(collections)
|
---|
491 | {
|
---|
492 | var tempArray = new Array();
|
---|
493 | for(var i = 0; i < _collectionsToBuild.length; i++)
|
---|
494 | {
|
---|
495 | var found = false;
|
---|
496 | for(var j = 0; j < collections.length; j++)
|
---|
497 | {
|
---|
498 | if(collections[j] == _collectionsToBuild[i])
|
---|
499 | {
|
---|
500 | found = true;
|
---|
501 | break;
|
---|
502 | }
|
---|
503 | }
|
---|
504 |
|
---|
505 | if(!found)
|
---|
506 | {
|
---|
507 | tempArray.push(_collectionsToBuild[i]);
|
---|
508 | }
|
---|
509 | }
|
---|
510 | _collectionsToBuild = tempArray;
|
---|
511 | }
|
---|
512 |
|
---|
513 | function checkForErrors(xml)
|
---|
514 | {
|
---|
515 | var errorElems = xml.getElementsByTagName("error");
|
---|
516 |
|
---|
517 | if(errorElems && errorElems.length > 0)
|
---|
518 | {
|
---|
519 | var errorString = gs.text.dse.error_saving_changes + ": ";
|
---|
520 | for(var i = 0; i < errorElems.length; i++)
|
---|
521 | {
|
---|
522 | errorString += " " + errorElems.item(i).firstChild.nodeValue;
|
---|
523 | }
|
---|
524 | alert(errorString);
|
---|
525 | return true;
|
---|
526 | }
|
---|
527 | return false; //No errors
|
---|
528 | }
|
---|
529 |
|
---|
530 | function validateXML(txt)
|
---|
531 | {
|
---|
532 | // code for IE
|
---|
533 | if (window.ActiveXObject)
|
---|
534 | {
|
---|
535 | var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
|
---|
536 | xmlDoc.async = "false";
|
---|
537 | xmlDoc.loadXML(document.all(txt).value);
|
---|
538 |
|
---|
539 | if(xmlDoc.parseError.errorCode!=0)
|
---|
540 | {
|
---|
541 | txt = dse.error_code + ": " + xmlDoc.parseError.errorCode + "\n";
|
---|
542 | txt = txt + dse.error_reason + ": " + xmlDoc.parseError.reason;
|
---|
543 | txt = txt + dse.error_line + ": " + xmlDoc.parseError.line;
|
---|
544 | console.log(txt);
|
---|
545 | return null;
|
---|
546 | }
|
---|
547 |
|
---|
548 | return xmlDoc;
|
---|
549 | }
|
---|
550 | // code for Mozilla, Firefox, Opera, etc.
|
---|
551 | else if (document.implementation.createDocument)
|
---|
552 | {
|
---|
553 | var parser = new DOMParser();
|
---|
554 | var xmlDoc = parser.parseFromString(txt,"text/xml");
|
---|
555 |
|
---|
556 | if (xmlDoc.getElementsByTagName("parsererror").length > 0)
|
---|
557 | {
|
---|
558 | console.log(gs.text.dse.xml_error);
|
---|
559 | return null;
|
---|
560 | }
|
---|
561 |
|
---|
562 | return xmlDoc;
|
---|
563 | }
|
---|
564 | else
|
---|
565 | {
|
---|
566 | console.log(gs.text.dse.browse_cannot_validate_xml);
|
---|
567 | }
|
---|
568 | return null;
|
---|
569 | }
|
---|
570 |
|
---|
571 | function onVisibleMetadataSetChange()
|
---|
572 | {
|
---|
573 | var metadataList = document.getElementById("metadataSetList");
|
---|
574 | var index = metadataList.selectedIndex;
|
---|
575 | var options = metadataList.getElementsByTagName("OPTION");
|
---|
576 | var selectedOption = options[index];
|
---|
577 |
|
---|
578 | var selectedSet = selectedOption.innerHTML;
|
---|
579 | changeVisibleMetadata(selectedSet);
|
---|
580 | }
|
---|
581 |
|
---|
582 | function changeVisibleMetadata(metadataSetName)
|
---|
583 | {
|
---|
584 | var tables = document.getElementsByTagName("TABLE");
|
---|
585 | for(var i = 0; i < tables.length; i++)
|
---|
586 | {
|
---|
587 | var id = tables[i].getAttribute("id");
|
---|
588 | if(id && id.search(/^meta/) != -1)
|
---|
589 | {
|
---|
590 | var rows = tables[i].getElementsByTagName("TR");
|
---|
591 | for(var j = 0; j < rows.length; j++)
|
---|
592 | {
|
---|
593 | if(metadataSetName == "All")
|
---|
594 | {
|
---|
595 | rows[j].style.display = "table-row";
|
---|
596 | }
|
---|
597 | else
|
---|
598 | {
|
---|
599 | var cells = rows[j].getElementsByTagName("TD");
|
---|
600 | var cellName = cells[0].innerHTML;
|
---|
601 |
|
---|
602 | if(cellName.indexOf(".") == -1)
|
---|
603 | {
|
---|
604 | rows[j].style.display = "none";
|
---|
605 | }
|
---|
606 | else
|
---|
607 | {
|
---|
608 | var setName = cellName.substring(0, cellName.lastIndexOf("."));
|
---|
609 | if(setName == metadataSetName)
|
---|
610 | {
|
---|
611 | rows[j].style.display = "table-row";
|
---|
612 | }
|
---|
613 | else
|
---|
614 | {
|
---|
615 | rows[j].style.display = "none";
|
---|
616 | }
|
---|
617 | }
|
---|
618 | }
|
---|
619 | }
|
---|
620 | }
|
---|
621 | }
|
---|
622 | }
|
---|
623 |
|
---|
624 | function asyncRegisterEditSection(cell)
|
---|
625 | {
|
---|
626 | //This registering can cause a sizeable delay so we'll thread it (effectively) so the browser is not paused
|
---|
627 | cell.originalValue = cell.innerHTML;
|
---|
628 | setTimeout(function(){de.doc.registerEditSection(cell)}, 0);
|
---|
629 | }
|
---|
630 |
|
---|
631 | function addFunctionalityToTable(table)
|
---|
632 | {
|
---|
633 | table.find("tr").each(function()
|
---|
634 | {
|
---|
635 | var cells = $(this).find("td");
|
---|
636 | var metadataName = $(cells[0]).html();
|
---|
637 |
|
---|
638 | if(metadataName.indexOf(".") != -1)
|
---|
639 | {
|
---|
640 | var metadataSetName = metadataName.substring(0, metadataName.lastIndexOf("."));
|
---|
641 |
|
---|
642 | var found = false;
|
---|
643 | for(var j = 0; j < _metadataSetList.length; j++)
|
---|
644 | {
|
---|
645 | if(metadataSetName == _metadataSetList[j])
|
---|
646 | {
|
---|
647 | found = true;
|
---|
648 | break;
|
---|
649 | }
|
---|
650 | }
|
---|
651 |
|
---|
652 | if(!found)
|
---|
653 | {
|
---|
654 | _metadataSetList.push(metadataSetName);
|
---|
655 |
|
---|
656 | var metadataSetList = $("#metadataSetList");
|
---|
657 | var newOption = $("<option>");
|
---|
658 | newOption.html(metadataSetName);
|
---|
659 | metadataSetList.append(newOption);
|
---|
660 | }
|
---|
661 | }
|
---|
662 |
|
---|
663 | asyncRegisterEditSection(cells[1]);
|
---|
664 | addRemoveLinkToRow(this);
|
---|
665 | });
|
---|
666 |
|
---|
667 | var metaNameField = $("<input>", {"type": "text"});
|
---|
668 | table.after(metaNameField);
|
---|
669 | table.metaNameField = metaNameField;
|
---|
670 |
|
---|
671 | var addRowButton = $("<button>");
|
---|
672 | addRowButton.html(gs.text.dse.add_new_metadata);
|
---|
673 | addRowButton.click(function()
|
---|
674 | {
|
---|
675 | var name = metaNameField.val();
|
---|
676 | if(!name || name == "")
|
---|
677 | {
|
---|
678 | console.log(gs.text.dse.no_value_given);
|
---|
679 | return;
|
---|
680 | }
|
---|
681 |
|
---|
682 | var newRow = $("<tr>");
|
---|
683 | var nameCell = $("<td>" + name + "</td>");
|
---|
684 | nameCell.attr("class", "metaTableCellName");
|
---|
685 | var valueCell = $("<td>", {"class": "metaTableCell"});
|
---|
686 |
|
---|
687 | newRow.append(nameCell);
|
---|
688 | newRow.append(valueCell);
|
---|
689 | addRemoveLinkToRow(newRow);
|
---|
690 | table.append(newRow);
|
---|
691 |
|
---|
692 | var undo = new Array();
|
---|
693 | undo.op = "delMeta";
|
---|
694 | undo.srcElem = newRow;
|
---|
695 | undo.removeTransaction = false;
|
---|
696 | _undoOperations.push(undo);
|
---|
697 |
|
---|
698 | //Threading this function here probably isn't necessary like the other times it is called
|
---|
699 | de.doc.registerEditSection(valueCell[0]);
|
---|
700 | });
|
---|
701 | table.addRowButton = addRowButton;
|
---|
702 | metaNameField.after(addRowButton);
|
---|
703 | }
|
---|
704 |
|
---|
705 | function addRemoveLinkToRow(row)
|
---|
706 | {
|
---|
707 | var newCell = $("<td>");
|
---|
708 | var removeLink = $("<a>remove</a>", {"href": "javascript:;"});
|
---|
709 | removeLink.click(function()
|
---|
710 | {
|
---|
711 | var undo = new Array();
|
---|
712 | undo.srcElem = row;
|
---|
713 | undo.op = "display";
|
---|
714 | undo.subOp = "table-row";
|
---|
715 | undo.removeDeletedMetadata = true;
|
---|
716 | _undoOperations.push(undo);
|
---|
717 | _deletedMetadata.push(row);
|
---|
718 | row.css("display", "none");
|
---|
719 | });
|
---|
720 | newCell.append(removeLink);
|
---|
721 | newCell.attr({"class": "metaTableCell", "style": "font-size:0.6em; padding-left: 3px; padding-right: 3px;"});
|
---|
722 | $(row).append(newCell);
|
---|
723 | }
|
---|
724 |
|
---|
725 | function createTopMenuBar()
|
---|
726 | {
|
---|
727 | //Create the top menu bar
|
---|
728 | var headerTable = document.createElement("TABLE");
|
---|
729 | var tableBody = document.createElement("TBODY");
|
---|
730 | var row = document.createElement("TR");
|
---|
731 | var newDocCell = document.createElement("TD");
|
---|
732 | var newSecCell = document.createElement("TD");
|
---|
733 | var saveCell = document.createElement("TD");
|
---|
734 | var undoCell = document.createElement("TD");
|
---|
735 | var metadataListCell = document.createElement("TD");
|
---|
736 |
|
---|
737 | var metadataListLabel = document.createElement("SPAN");
|
---|
738 | metadataListLabel.innerHTML = "Visible metadata: ";
|
---|
739 | var metadataList = document.createElement("SELECT");
|
---|
740 | metadataList.setAttribute("id", "metadataSetList");
|
---|
741 | metadataList.onchange = onVisibleMetadataSetChange;
|
---|
742 | var allMetadataOption = document.createElement("OPTION");
|
---|
743 | metadataList.appendChild(allMetadataOption);
|
---|
744 | allMetadataOption.innerHTML = "All";
|
---|
745 | metadataListCell.appendChild(metadataListLabel);
|
---|
746 | metadataListCell.appendChild(metadataList);
|
---|
747 |
|
---|
748 | metadataListCell.setAttribute("class", "headerTableTD");
|
---|
749 | newDocCell.setAttribute("class", "headerTableTD");
|
---|
750 | newSecCell.setAttribute("class", "headerTableTD");
|
---|
751 | undoCell.setAttribute("class", "headerTableTD");
|
---|
752 | saveCell.setAttribute("class", "headerTableTD");
|
---|
753 |
|
---|
754 | headerTable.appendChild(tableBody);
|
---|
755 | tableBody.appendChild(row);
|
---|
756 | row.appendChild(saveCell);
|
---|
757 | row.appendChild(undoCell);
|
---|
758 | row.appendChild(newDocCell);
|
---|
759 | row.appendChild(newSecCell);
|
---|
760 | row.appendChild(metadataListCell);
|
---|
761 |
|
---|
762 | //The "Save changes" button
|
---|
763 | var saveButton = document.createElement("BUTTON");
|
---|
764 | saveButton.innerHTML = gs.text.dse.save_changes;
|
---|
765 | saveButton.setAttribute("onclick", "save();");
|
---|
766 | saveButton.setAttribute("id", "saveButton");
|
---|
767 | saveCell.appendChild(saveButton);
|
---|
768 |
|
---|
769 | //The "Undo" button
|
---|
770 | var undoButton = document.createElement("BUTTON");
|
---|
771 | undoButton.innerHTML = "Undo";
|
---|
772 | undoButton.setAttribute("onclick", "undo();");
|
---|
773 | undoCell.appendChild(undoButton);
|
---|
774 |
|
---|
775 | //The "Create new document" button
|
---|
776 | var newDocButton = document.createElement("BUTTON");
|
---|
777 | newDocButton.innerHTML = gs.text.dse.create_new_document;
|
---|
778 | newDocButton.setAttribute("onclick", "createNewDocumentArea();");
|
---|
779 | newDocButton.setAttribute("id", "createNewDocumentButton");
|
---|
780 | newDocCell.appendChild(newDocButton);
|
---|
781 |
|
---|
782 | //The "Insert new section" LI
|
---|
783 | var newSecLI = createDraggableNewSection(newSecCell);
|
---|
784 |
|
---|
785 | return headerTable;
|
---|
786 | }
|
---|
787 |
|
---|
788 | function getMetadataFromNode(node, name)
|
---|
789 | {
|
---|
790 | var currentNode = node.firstChild;
|
---|
791 | while(currentNode != null)
|
---|
792 | {
|
---|
793 | if(currentNode.nodeName == "metadataList")
|
---|
794 | {
|
---|
795 | currentNode = currentNode.firstChild;
|
---|
796 | break;
|
---|
797 | }
|
---|
798 |
|
---|
799 | currentNode = currentNode.nextSibling;
|
---|
800 | }
|
---|
801 |
|
---|
802 | while(currentNode != null)
|
---|
803 | {
|
---|
804 | if(currentNode.nodeName == "metadata" && currentNode.getAttribute("name") == name)
|
---|
805 | {
|
---|
806 | return currentNode.firstChild.nodeValue;
|
---|
807 | }
|
---|
808 |
|
---|
809 | currentNode = currentNode.nextSibling;
|
---|
810 | }
|
---|
811 | return "";
|
---|
812 | }
|
---|
813 |
|
---|
814 | function storeMetadata(node, listItem)
|
---|
815 | {
|
---|
816 | listItem.metadata = new Array();
|
---|
817 |
|
---|
818 | var currentNode = node.firstChild;
|
---|
819 | while(currentNode != null)
|
---|
820 | {
|
---|
821 | if(currentNode.nodeName == "metadataList")
|
---|
822 | {
|
---|
823 | currentNode = currentNode.firstChild;
|
---|
824 | break;
|
---|
825 | }
|
---|
826 |
|
---|
827 | currentNode = currentNode.nextSibling;
|
---|
828 | }
|
---|
829 |
|
---|
830 | while(currentNode != null)
|
---|
831 | {
|
---|
832 | if(currentNode.nodeName == "metadata")
|
---|
833 | {
|
---|
834 | listItem.metadata[currentNode.getAttribute("name")] = currentNode.firstChild.nodeValue;
|
---|
835 | }
|
---|
836 |
|
---|
837 | currentNode = currentNode.nextSibling;
|
---|
838 | }
|
---|
839 | }
|
---|
840 |
|
---|
841 | function getNodeContent(node)
|
---|
842 | {
|
---|
843 | var currentNode = node.firstChild;
|
---|
844 | while(currentNode != null)
|
---|
845 | {
|
---|
846 | if(currentNode.nodeName == "nodeContent")
|
---|
847 | {
|
---|
848 | return currentNode.firstChild;
|
---|
849 | }
|
---|
850 |
|
---|
851 | currentNode = currentNode.nextSibling;
|
---|
852 | }
|
---|
853 | return null;
|
---|
854 | }
|
---|
855 |
|
---|
856 | function containsDocumentNode(node)
|
---|
857 | {
|
---|
858 | var currentNode = node.firstChild;
|
---|
859 | while(currentNode != null)
|
---|
860 | {
|
---|
861 | if(currentNode.nodeName == "documentNode")
|
---|
862 | {
|
---|
863 | return true;
|
---|
864 | }
|
---|
865 |
|
---|
866 | currentNode = currentNode.nextSibling;
|
---|
867 | }
|
---|
868 | return false;
|
---|
869 | }
|
---|
870 |
|
---|
871 | function isExpanded(textDiv)
|
---|
872 | {
|
---|
873 | if(!textDiv.style.display || textDiv.style.display == "block")
|
---|
874 | {
|
---|
875 | return true;
|
---|
876 | }
|
---|
877 | return false;
|
---|
878 | }
|
---|
879 |
|
---|
880 | function toggleTextDiv(section)
|
---|
881 | {
|
---|
882 | var textDiv = section.textDiv;
|
---|
883 | if(textDiv)
|
---|
884 | {
|
---|
885 | if(isExpanded(textDiv))
|
---|
886 | {
|
---|
887 | textDiv.style.display = "none";
|
---|
888 | section.menu.editTextLink.innerHTML = gs.text.dse.edit;
|
---|
889 | }
|
---|
890 | else
|
---|
891 | {
|
---|
892 | textDiv.style.display = "block";
|
---|
893 | section.menu.editTextLink.innerHTML = gs.text.dse.hide;
|
---|
894 | }
|
---|
895 | }
|
---|
896 | }
|
---|
897 |
|
---|
898 | function updateFromTop()
|
---|
899 | {
|
---|
900 | updateRecursive(document.getElementById("dbDiv"), null, null, 0);
|
---|
901 | }
|
---|
902 |
|
---|
903 | function insertAfter(elem, refElem)
|
---|
904 | {
|
---|
905 | if(refElem.nextSibling)
|
---|
906 | {
|
---|
907 | refElem.parentNode.insertBefore(elem, refElem.nextSibling);
|
---|
908 | }
|
---|
909 | else
|
---|
910 | {
|
---|
911 | refElem.parentNode.appendChild(elem);
|
---|
912 | }
|
---|
913 | }
|
---|
914 |
|
---|
915 | function removeFromParent(elem)
|
---|
916 | {
|
---|
917 | elem.parentNode.removeChild(elem);
|
---|
918 | }
|
---|
919 |
|
---|
920 | function createSectionTitle(text)
|
---|
921 | {
|
---|
922 | var textSpan = document.createElement("SPAN");
|
---|
923 | if(text)
|
---|
924 | {
|
---|
925 | textSpan.appendChild(document.createTextNode(" " + text + " "));
|
---|
926 | }
|
---|
927 | else
|
---|
928 | {
|
---|
929 | textSpan.appendChild(document.createTextNode(" [" + gs.text.dse.untitled_section + "] "));
|
---|
930 | }
|
---|
931 | return textSpan;
|
---|
932 | }
|
---|
933 |
|
---|
934 | function setMouseOverAndOutFunctions(section)
|
---|
935 | {
|
---|
936 | //Colour the list item and display the menu on mouse over
|
---|
937 | section.onmouseover = function(e)
|
---|
938 | {
|
---|
939 | if(this.menu){this.menu.style.display = "inline";}
|
---|
940 | this.style.background = "rgb(255, 200, 0)";
|
---|
941 | };
|
---|
942 | //Uncolour the list item and hide the menu on mouse out
|
---|
943 | section.onmouseout = function(e)
|
---|
944 | {
|
---|
945 | if(this.menu){this.menu.style.display = "none";}
|
---|
946 | this.style.background = "none";
|
---|
947 | };
|
---|
948 | }
|
---|
949 |
|
---|
950 | function createDraggableNewSection(parent)
|
---|
951 | {
|
---|
952 | var newSecLI = document.createElement("LI");
|
---|
953 | var newSpan = document.createElement("SPAN");
|
---|
954 | newSpan.innerHTML = gs.text.dse.insert_new_section + " ";
|
---|
955 |
|
---|
956 | newSecLI.sectionTitle = newSpan;
|
---|
957 | newSecLI.appendChild(newSpan);
|
---|
958 | newSecLI.setAttribute("class", "dragItem newSection");
|
---|
959 | newSecLI.newSection = true;
|
---|
960 | newSecLI.parent = parent;
|
---|
961 | newSecLI.index = -1;
|
---|
962 | new YAHOO.example.DDList(newSecLI);
|
---|
963 | parent.appendChild(newSecLI);
|
---|
964 | }
|
---|
965 |
|
---|
966 | function closeAllOpenContents()
|
---|
967 | {
|
---|
968 | for(var i = 0; i < _allContents.length; i++)
|
---|
969 | {
|
---|
970 | if(isExpanded(_allContents[i].textDiv))
|
---|
971 | {
|
---|
972 | toggleTextDiv(_allContents[i]);
|
---|
973 | }
|
---|
974 | }
|
---|
975 | DDM.refreshCache();
|
---|
976 | }
|
---|
977 |
|
---|
978 | //Status Bar class (initialised with new StatusBar(elem);)
|
---|
979 | function StatusBar(mainElem)
|
---|
980 | {
|
---|
981 | var _statusMap = new Array();
|
---|
982 | var _statusIDCounter = 0;
|
---|
983 | var _mainElem = mainElem;
|
---|
984 | var _activeMessages = 0;
|
---|
985 |
|
---|
986 | _mainElem.style.display = "none";
|
---|
987 |
|
---|
988 | this.addStatus = function(newStatus)
|
---|
989 | {
|
---|
990 | _mainElem.style.display = "block";
|
---|
991 | var newStatusDiv = document.createElement("DIV");
|
---|
992 | var newStatusSpan = document.createElement("SPAN");
|
---|
993 |
|
---|
994 | var workingImage = document.createElement("IMG");
|
---|
995 | workingImage.setAttribute("src", gs.imageURLs.loading);
|
---|
996 | workingImage.setAttribute("height", "16px");
|
---|
997 | workingImage.setAttribute("width", "16px");
|
---|
998 | newStatusDiv.appendChild(workingImage);
|
---|
999 |
|
---|
1000 | newStatusDiv.appendChild(newStatusSpan);
|
---|
1001 | newStatusSpan.innerHTML = " " + newStatus;
|
---|
1002 | newStatusDiv.setAttribute("class", "statusMessage");
|
---|
1003 | newStatusDiv.span = newStatusSpan;
|
---|
1004 |
|
---|
1005 | _mainElem.appendChild(newStatusDiv);
|
---|
1006 | _statusMap["status" + _statusIDCounter] = newStatusDiv;
|
---|
1007 | _activeMessages++;
|
---|
1008 | return _statusIDCounter++;
|
---|
1009 | }
|
---|
1010 |
|
---|
1011 | this.changeStatus = function(id, newStatus)
|
---|
1012 | {
|
---|
1013 | if(_statusMap["status" + id])
|
---|
1014 | {
|
---|
1015 | _statusMap["status" + id].span.innerHTML = " " + newStatus;
|
---|
1016 | }
|
---|
1017 | }
|
---|
1018 |
|
---|
1019 | this.removeStatus = function(id)
|
---|
1020 | {
|
---|
1021 | if(_statusMap["status" + id])
|
---|
1022 | {
|
---|
1023 | removeFromParent(_statusMap["status" + id]);
|
---|
1024 |
|
---|
1025 | if(--_activeMessages == 0)
|
---|
1026 | {
|
---|
1027 | _mainElem.style.display = "none";
|
---|
1028 | }
|
---|
1029 | }
|
---|
1030 | }
|
---|
1031 | }
|
---|
1032 |
|
---|
1033 | /*
|
---|
1034 | function toggleEdit(e)
|
---|
1035 | {
|
---|
1036 | var mousePos = de.events.getXYInWindowFromEvent(e);
|
---|
1037 | var cDesc = de.cursor.getCursorDescAtXY(mousePos.x, mousePos.y, de.events.getEventTarget(e));
|
---|
1038 | de.cursor.setCursor(cDesc);
|
---|
1039 | }
|
---|
1040 | */ |
---|