source: main/trunk/greenstone3/web/interfaces/oran/js/documentmaker_scripts_util.js@ 25368

Last change on this file since 25368 was 25368, checked in by sjm84, 12 years ago

Made hasClass a global function and fixed a text fragment error

  • Property svn:executable set to *
File size: 25.6 KB
Line 
1//Some "constants" to match the server constants
2var SUCCESS = 1;
3var ACCEPTED = 2;
4var ERROR = 3;
5var CONTINUING = 10;
6var COMPLETED = 11;
7var HALTED = 12;
8
9function 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
32function 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
52function 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
72function saveTransaction(transaction)
73{
74 console.log(transaction);
75 _transactions.push(transaction);
76}
77
78function 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
166function 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
178function 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
233 if(changedElem.originalValue)
234 {
235 gs.functions.setArchivesMetadata(collection, gs.xsltParams.site_name, docID, name, null, changedElem.innerHTML, changedElem.originalValue, "override", function(){console.log("SAVED ARCHIVES");});
236 }
237 else
238 {
239 gs.functions.setArchivesMetadata(collection, gs.xsltParams.site_name, docID, name, null, changedElem.innerHTML, null, "accumulate", function(){console.log("SAVED ARCHIVES");});
240 }
241 changedElem.originalValue = changedElem.innerHTML;
242 addCollectionToBuild(collection);
243 }
244 //Save content
245 else if(gs.functions.hasClass(changedElem, "renderedText"))
246 {
247 var section = changedElem.parentDiv.parentItem;
248 saveTransaction('{"operation":"setText", "text":"' + changedElem.innerHTML.replace(/"/g, "\\\"").replace(/&/g, "%26") + '", "collection":"' + section.collection + '", "oid":"' + section.nodeID + '"}');
249 addCollectionToBuild(section.collection);
250 }
251 else if(gs.functions.hasClass(changedElem, "sectionText"))
252 {
253 var id = changedElem.getAttribute("id");
254 var sectionID = id.substring(4);
255 saveTransaction('{"operation":"setText", "text":"' + changedElem.innerHTML.replace(/"/g, "\\\"").replace(/&/g, "%26") + '", "collection":"' + gs.cgiParams.c + '", "oid":"' + sectionID + '"}');
256 addCollectionToBuild(gs.cgiParams.c);
257 }
258 }
259
260 var request = "[";
261 for(var i = 0; i < _transactions.length; i++)
262 {
263 request += _transactions[i];
264 if(i != _transactions.length - 1)
265 {
266 request += ",";
267 }
268 }
269 request += "]";
270
271 var statusID;
272 var ajax = new gs.functions.ajaxRequest();
273 ajax.open("POST", _baseURL, true);
274 ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
275 ajax.onreadystatechange = function()
276 {
277 if(ajax.readyState == 4 && ajax.status == 200)
278 {
279 var text = ajax.responseText;
280 var xml = validateXML(text);
281
282 var errorElems;
283 if(!xml || checkForErrors(xml))
284 {
285 alert(gs.text.dse.error_saving);
286
287 var saveButton = document.getElementById("saveButton");
288 saveButton.innerHTML = gs.text.dse.save_changes;
289 saveButton.disabled = false;
290
291 _statusBar.removeStatus(statusID);
292 return;
293 }
294
295 _statusBar.removeStatus(statusID);
296 buildCollections(_collectionsToBuild);
297 }
298 }
299
300 if(_collectionsToBuild.length > 0)
301 {
302 var saveButton = document.getElementById("saveButton");
303 saveButton.innerHTML = gs.text.dse.saving + "...";
304 saveButton.disabled = true;
305
306 statusID = _statusBar.addStatus(gs.text.dse.modifying_archives + "...");
307 ajax.send("a=g&rt=r&s=DocumentExecuteTransaction&s1.transactions=" + request);
308 }
309}
310
311function buildCollections(collections)
312{
313 var saveButton = document.getElementById("saveButton");
314 if(!collections || collections.length == 0)
315 {
316 console.log(gs.text.dse.empty_collection_list);
317 saveButton.innerHTML = gs.text.save_changes;
318 saveButton.disabled = false;
319 return;
320 }
321
322 var counter = 0;
323 var statusID = 0;
324 var buildFunction = function()
325 {
326 var ajax = new gs.functions.ajaxRequest();
327 ajax.open("GET", _baseURL + "?a=g&rt=r&ro=1&s=BuildCollection&s1.collection=" + collections[counter]);
328 ajax.onreadystatechange = function()
329 {
330 if(ajax.readyState == 4 && ajax.status == 200)
331 {
332 var text = ajax.responseText;
333 var xml = validateXML(text);
334
335 if(!xml || checkForErrors(xml))
336 {
337 alert(gs.text.dse.could_not_build_p1 + " " + collections[counter] + gs.text.dse.could_not_build_p2);
338
339 _statusBar.removeStatus(statusID);
340 saveButton.innerHTML = gs.text.dse.save_changes;
341 saveButton.disabled = false;
342
343 return;
344 }
345
346 var status = xml.getElementsByTagName("status")[0];
347 var pid = status.getAttribute("pid");
348
349 startCheckLoop(pid, "BuildCollection", statusID, function()
350 {
351 var localAjax = new gs.functions.ajaxRequest();
352 localAjax.open("GET", _baseURL + "?a=g&rt=r&ro=1&s=ActivateCollection&s1.collection=" + collections[counter], true);
353 localAjax.onreadystatechange = function()
354 {
355 if(localAjax.readyState == 4 && localAjax.status == 200)
356 {
357 var localText = localAjax.responseText;
358 var localXML = validateXML(localText);
359
360 if(!xml || checkForErrors(xml))
361 {
362 alert(gs.text.dse.could_not_activate_p1 + " " + collections[counter] + gs.text.dse.could_not_activate_p2);
363
364 _statusBar.removeStatus(statusID);
365 saveButton.innerHTML = gs.text.dse.save_changes;
366 saveButton.disabled = false;
367
368 return;
369 }
370
371 var localStatus = localXML.getElementsByTagName("status")[0];
372 if(localStatus)
373 {
374 var localPID = localStatus.getAttribute("pid");
375 startCheckLoop(localPID, "ActivateCollection", statusID, function()
376 {
377 if(counter == collections.length - 1)
378 {
379 removeCollectionsFromBuildList(collections);
380 }
381 else
382 {
383 counter++;
384 buildFunction();
385 }
386
387 _transactions = new Array();
388
389 _statusBar.removeStatus(statusID);
390 saveButton.innerHTML = gs.text.dse.save_changes;
391 saveButton.disabled = false;
392 });
393 }
394 }
395 }
396 _statusBar.changeStatus(statusID, gs.text.dse.activating + " " + collections[counter] + "...");
397 localAjax.send();
398 });
399 }
400 }
401 statusID = _statusBar.addStatus(gs.text.dse.building + " " + collections[counter] + "...");
402 ajax.send();
403 }
404 buildFunction();
405}
406
407function startCheckLoop(pid, serverFunction, statusID, callbackFunction)
408{
409 var ajaxFunction = function()
410 {
411 var saveButton = document.getElementById("saveButton");
412
413 var ajax = new gs.functions.ajaxRequest();
414 ajax.open("GET", _baseURL + "?a=g&rt=s&ro=1&s=" + serverFunction + "&s1.pid=" + pid, true);
415 ajax.onreadystatechange = function()
416 {
417 if(ajax.readyState == 4 && ajax.status == 200)
418 {
419 var text = ajax.responseText;
420 var xml = validateXML(text);
421
422 if(!xml || checkForErrors(xml))
423 {
424 alert(gs.text.dse.could_not_check_status_p1 + " " + serverFunction + gs.text.dse.could_not_check_status_p2a);
425
426 _statusBar.removeStatus(statusID);
427 saveButton.innerHTML = gs.text.dse.save_changes;
428 saveButton.disabled = false;
429
430 return;
431 }
432
433 var status = xml.getElementsByTagName("status")[0];
434 var code = status.getAttribute("code");
435
436 if (code == COMPLETED || code == SUCCESS)
437 {
438 callbackFunction();
439 }
440 else if (code == HALTED || code == ERROR)
441 {
442 alert(gs.text.dse.could_not_check_status_p1 + " " + serverFunction + gs.text.dse.could_not_check_status_p2b);
443
444 _statusBar.removeStatus(statusID);
445 saveButton.innerHTML = gs.text.dse.save_changes;
446 saveButton.disabled = false;
447 }
448 else
449 {
450 setTimeout(ajaxFunction, 1000);
451 }
452 }
453 }
454 ajax.send();
455 }
456 ajaxFunction();
457}
458
459function removeCollectionsFromBuildList(collections)
460{
461 var tempArray = new Array();
462 for(var i = 0; i < _collectionsToBuild.length; i++)
463 {
464 var found = false;
465 for(var j = 0; j < collections.length; j++)
466 {
467 if(collections[j] == _collectionsToBuild[i])
468 {
469 found = true;
470 break;
471 }
472 }
473
474 if(!found)
475 {
476 tempArray.push(_collectionsToBuild[i]);
477 }
478 }
479 _collectionsToBuild = tempArray;
480}
481
482function checkForErrors(xml)
483{
484 var errorElems = xml.getElementsByTagName("error");
485
486 if(errorElems && errorElems.length > 0)
487 {
488 var errorString = gs.text.dse.error_saving_changes + ": ";
489 for(var i = 0; i < errorElems.length; i++)
490 {
491 errorString += " " + errorElems.item(i).firstChild.nodeValue;
492 }
493 alert(errorString);
494 return true;
495 }
496 return false; //No errors
497}
498
499function validateXML(txt)
500{
501 // code for IE
502 if (window.ActiveXObject)
503 {
504 var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
505 xmlDoc.async = "false";
506 xmlDoc.loadXML(document.all(txt).value);
507
508 if(xmlDoc.parseError.errorCode!=0)
509 {
510 txt = dse.error_code + ": " + xmlDoc.parseError.errorCode + "\n";
511 txt = txt + dse.error_reason + ": " + xmlDoc.parseError.reason;
512 txt = txt + dse.error_line + ": " + xmlDoc.parseError.line;
513 console.log(txt);
514 return null;
515 }
516
517 return xmlDoc;
518 }
519 // code for Mozilla, Firefox, Opera, etc.
520 else if (document.implementation.createDocument)
521 {
522 var parser = new DOMParser();
523 var xmlDoc = parser.parseFromString(txt,"text/xml");
524
525 if (xmlDoc.getElementsByTagName("parsererror").length > 0)
526 {
527 console.log(gs.text.dse.xml_error);
528 return null;
529 }
530
531 return xmlDoc;
532 }
533 else
534 {
535 console.log(gs.text.dse.browse_cannot_validate_xml);
536 }
537 return null;
538}
539
540function onVisibleMetadataSetChange()
541{
542 var metadataList = document.getElementById("metadataSetList");
543 var index = metadataList.selectedIndex;
544 var options = metadataList.getElementsByTagName("OPTION");
545 var selectedOption = options[index];
546
547 var selectedSet = selectedOption.innerHTML;
548 changeVisibleMetadata(selectedSet);
549}
550
551function changeVisibleMetadata(metadataSetName)
552{
553 var tables = document.getElementsByTagName("TABLE");
554 for(var i = 0; i < tables.length; i++)
555 {
556 var id = tables[i].getAttribute("id");
557 if(id && id.search(/^meta/) != -1)
558 {
559 var rows = tables[i].getElementsByTagName("TR");
560 for(var j = 0; j < rows.length; j++)
561 {
562 if(metadataSetName == "All")
563 {
564 rows[j].style.display = "table-row";
565 }
566 else
567 {
568 var cells = rows[j].getElementsByTagName("TD");
569 var cellName = cells[0].innerHTML;
570
571 if(cellName.indexOf(".") == -1)
572 {
573 rows[j].style.display = "none";
574 }
575 else
576 {
577 var setName = cellName.substring(0, cellName.lastIndexOf("."));
578 if(setName == metadataSetName)
579 {
580 rows[j].style.display = "table-row";
581 }
582 else
583 {
584 rows[j].style.display = "none";
585 }
586 }
587 }
588 }
589 }
590 }
591}
592
593function asyncRegisterEditSection(cell)
594{
595 //This registering can cause a sizeable delay so we'll thread it (effectively) so the browser is not paused
596 cell.originalValue = cell.innerHTML;
597 setTimeout(function(){de.doc.registerEditSection(cell)}, 0);
598}
599
600function addFunctionalityToTable(table)
601{
602 var rows = table.getElementsByTagName("TR");
603 for(var i = 0; i < rows.length; i++)
604 {
605 var cells = rows[i].getElementsByTagName("TD");
606 var metadataName = cells[0].innerHTML;
607
608 if(metadataName.indexOf(".") != -1)
609 {
610 var metadataSetName = metadataName.substring(0, metadataName.lastIndexOf("."));
611
612 var found = false;
613 for(var j = 0; j < _metadataSetList.length; j++)
614 {
615 if(metadataSetName == _metadataSetList[j])
616 {
617 found = true;
618 break;
619 }
620 }
621
622 if(!found)
623 {
624 _metadataSetList.push(metadataSetName);
625
626 var metadataSetList = document.getElementById("metadataSetList");
627 var newOption = document.createElement("OPTION");
628 newOption.innerHTML = metadataSetName;
629 metadataSetList.appendChild(newOption);
630 }
631 }
632
633 asyncRegisterEditSection(cells[1]);
634
635 addRemoveLinkToRow(rows[i]);
636 }
637
638 var metaNameField = document.createElement("INPUT");
639 metaNameField.setAttribute("type", "text");
640 insertAfter(metaNameField, table);
641 table.metaNameField = metaNameField;
642
643 var addRowButton = document.createElement("BUTTON");
644 addRowButton.innerHTML = gs.text.dse.add_new_metadata;
645 addRowButton.onclick = function()
646 {
647 var name = metaNameField.value;
648 if(!name || name == "")
649 {
650 console.log(gs.text.dse.no_value_given);
651 return;
652 }
653
654 var newRow = document.createElement("TR");
655 var nameCell = document.createElement("TD");
656 var valueCell = document.createElement("TD");
657 nameCell.setAttribute("class", "metaTableCellName");
658 nameCell.innerHTML = name;
659 valueCell.setAttribute("class", "metaTableCell");
660
661 newRow.appendChild(nameCell);
662 newRow.appendChild(valueCell);
663 addRemoveLinkToRow(newRow);
664 table.appendChild(newRow);
665
666 var undo = new Array();
667 undo.op = "delMeta";
668 undo.srcElem = newRow;
669 undo.removeTransaction = false;
670 _undoOperations.push(undo);
671
672 //Threading this function here probably isn't necessary like the other times it is called
673 de.doc.registerEditSection(valueCell);
674 };
675 table.addRowButton = addRowButton;
676 insertAfter(addRowButton, metaNameField);
677}
678
679function addRemoveLinkToRow(row)
680{
681 var newCell = document.createElement("TD");
682 var removeLink = document.createElement("A");
683 removeLink.innerHTML = "remove";
684 removeLink.setAttribute("href", "javascript:;");
685 removeLink.onclick = function()
686 {
687 var undo = new Array();
688 undo.srcElem = row;
689 undo.op = "display";
690 undo.subOp = "table-row";
691 undo.removeDeletedMetadata = true;
692 _undoOperations.push(undo);
693 _deletedMetadata.push(row);
694 row.style.display = "none";
695 }
696 newCell.appendChild(removeLink);
697 newCell.setAttribute("class", "metaTableCell");
698 newCell.setAttribute("style", "font-size:0.6em; padding-left: 3px; padding-right: 3px;");
699 row.appendChild(newCell);
700}
701
702function createTopMenuBar()
703{
704 //Create the top menu bar
705 var headerTable = document.createElement("TABLE");
706 var tableBody = document.createElement("TBODY");
707 var row = document.createElement("TR");
708 var newDocCell = document.createElement("TD");
709 var newSecCell = document.createElement("TD");
710 var saveCell = document.createElement("TD");
711 var undoCell = document.createElement("TD");
712 var metadataListCell = document.createElement("TD");
713
714 var metadataListLabel = document.createElement("SPAN");
715 metadataListLabel.innerHTML = "Visible metadata: ";
716 var metadataList = document.createElement("SELECT");
717 metadataList.setAttribute("id", "metadataSetList");
718 metadataList.onchange = onVisibleMetadataSetChange;
719 var allMetadataOption = document.createElement("OPTION");
720 metadataList.appendChild(allMetadataOption);
721 allMetadataOption.innerHTML = "All";
722 metadataListCell.appendChild(metadataListLabel);
723 metadataListCell.appendChild(metadataList);
724
725 metadataListCell.setAttribute("class", "headerTableTD");
726 newDocCell.setAttribute("class", "headerTableTD");
727 newSecCell.setAttribute("class", "headerTableTD");
728 undoCell.setAttribute("class", "headerTableTD");
729 saveCell.setAttribute("class", "headerTableTD");
730
731 headerTable.appendChild(tableBody);
732 tableBody.appendChild(row);
733 row.appendChild(saveCell);
734 row.appendChild(undoCell);
735 row.appendChild(newDocCell);
736 row.appendChild(newSecCell);
737 row.appendChild(metadataListCell);
738
739 //The "Save changes" button
740 var saveButton = document.createElement("BUTTON");
741 saveButton.innerHTML = gs.text.dse.save_changes;
742 saveButton.setAttribute("onclick", "save();");
743 saveButton.setAttribute("id", "saveButton");
744 saveCell.appendChild(saveButton);
745
746 //The "Undo" button
747 var undoButton = document.createElement("BUTTON");
748 undoButton.innerHTML = "Undo";
749 undoButton.setAttribute("onclick", "undo();");
750 undoCell.appendChild(undoButton);
751
752 //The "Create new document" button
753 var newDocButton = document.createElement("BUTTON");
754 newDocButton.innerHTML = gs.text.dse.create_new_document;
755 newDocButton.setAttribute("onclick", "createNewDocumentArea();");
756 newDocCell.appendChild(newDocButton);
757
758 //The "Insert new section" LI
759 var newSecLI = createDraggableNewSection(newSecCell);
760
761 return headerTable;
762}
763
764function getMetadataFromNode(node, name)
765{
766 var currentNode = node.firstChild;
767 while(currentNode != null)
768 {
769 if(currentNode.nodeName == "metadataList")
770 {
771 currentNode = currentNode.firstChild;
772 break;
773 }
774
775 currentNode = currentNode.nextSibling;
776 }
777
778 while(currentNode != null)
779 {
780 if(currentNode.nodeName == "metadata" && currentNode.getAttribute("name") == name)
781 {
782 return currentNode.firstChild.nodeValue;
783 }
784
785 currentNode = currentNode.nextSibling;
786 }
787 return "";
788}
789
790function storeMetadata(node, listItem)
791{
792 listItem.metadata = new Array();
793
794 var currentNode = node.firstChild;
795 while(currentNode != null)
796 {
797 if(currentNode.nodeName == "metadataList")
798 {
799 currentNode = currentNode.firstChild;
800 break;
801 }
802
803 currentNode = currentNode.nextSibling;
804 }
805
806 while(currentNode != null)
807 {
808 if(currentNode.nodeName == "metadata")
809 {
810 listItem.metadata[currentNode.getAttribute("name")] = currentNode.firstChild.nodeValue;
811 }
812
813 currentNode = currentNode.nextSibling;
814 }
815}
816
817function getNodeContent(node)
818{
819 var currentNode = node.firstChild;
820 while(currentNode != null)
821 {
822 if(currentNode.nodeName == "nodeContent")
823 {
824 return currentNode.firstChild;
825 }
826
827 currentNode = currentNode.nextSibling;
828 }
829 return null;
830}
831
832function containsDocumentNode(node)
833{
834 var currentNode = node.firstChild;
835 while(currentNode != null)
836 {
837 if(currentNode.nodeName == "documentNode")
838 {
839 return true;
840 }
841
842 currentNode = currentNode.nextSibling;
843 }
844 return false;
845}
846
847function isExpanded(textDiv)
848{
849 if(!textDiv.style.display || textDiv.style.display == "block")
850 {
851 return true;
852 }
853 return false;
854}
855
856function toggleTextDiv(section)
857{
858 var textDiv = section.textDiv;
859 if(textDiv)
860 {
861 if(isExpanded(textDiv))
862 {
863 textDiv.style.display = "none";
864 section.menu.editTextLink.innerHTML = gs.text.dse.edit;
865 }
866 else
867 {
868 textDiv.style.display = "block";
869 section.menu.editTextLink.innerHTML = gs.text.dse.hide;
870 }
871 }
872}
873
874function updateFromTop()
875{
876 updateRecursive(document.getElementById("dbDiv"), null, null, 0);
877}
878
879function insertAfter(elem, refElem)
880{
881 if(refElem.nextSibling)
882 {
883 refElem.parentNode.insertBefore(elem, refElem.nextSibling);
884 }
885 else
886 {
887 refElem.parentNode.appendChild(elem);
888 }
889}
890
891function removeFromParent(elem)
892{
893 elem.parentNode.removeChild(elem);
894}
895
896function createSectionTitle(text)
897{
898 var textSpan = document.createElement("SPAN");
899 if(text)
900 {
901 textSpan.appendChild(document.createTextNode(" " + text + " "));
902 }
903 else
904 {
905 textSpan.appendChild(document.createTextNode(" [" + gs.text.dse.untitled_section + "] "));
906 }
907 return textSpan;
908}
909
910function setMouseOverAndOutFunctions(section)
911{
912 //Colour the list item and display the menu on mouse over
913 section.onmouseover = function(e)
914 {
915 if(this.menu){this.menu.style.display = "inline";}
916 this.style.background = "rgb(255, 200, 0)";
917 };
918 //Uncolour the list item and hide the menu on mouse out
919 section.onmouseout = function(e)
920 {
921 if(this.menu){this.menu.style.display = "none";}
922 this.style.background = "none";
923 };
924}
925
926function createDraggableNewSection(parent)
927{
928 var newSecLI = document.createElement("LI");
929 var newSpan = document.createElement("SPAN");
930 newSpan.innerHTML = gs.text.dse.insert_new_section + " ";
931
932 newSecLI.sectionTitle = newSpan;
933 newSecLI.appendChild(newSpan);
934 newSecLI.setAttribute("class", "dragItem newSection");
935 newSecLI.newSection = true;
936 newSecLI.parent = parent;
937 newSecLI.index = -1;
938 new YAHOO.example.DDList(newSecLI);
939 parent.appendChild(newSecLI);
940}
941
942function closeAllOpenContents()
943{
944 for(var i = 0; i < _allContents.length; i++)
945 {
946 if(isExpanded(_allContents[i].textDiv))
947 {
948 toggleTextDiv(_allContents[i]);
949 }
950 }
951 DDM.refreshCache();
952}
953
954//Status Bar class (initialised with new StatusBar(elem);)
955function StatusBar(mainElem)
956{
957 var _statusMap = new Array();
958 var _statusIDCounter = 0;
959 var _mainElem = mainElem;
960 var _activeMessages = 0;
961
962 _mainElem.style.display = "none";
963
964 this.addStatus = function(newStatus)
965 {
966 _mainElem.style.display = "block";
967 var newStatusDiv = document.createElement("DIV");
968 var newStatusSpan = document.createElement("SPAN");
969
970 var workingImage = document.createElement("IMG");
971 workingImage.setAttribute("src", gs.imageURLs.loading);
972 workingImage.setAttribute("height", "16px");
973 workingImage.setAttribute("width", "16px");
974 newStatusDiv.appendChild(workingImage);
975
976 newStatusDiv.appendChild(newStatusSpan);
977 newStatusSpan.innerHTML = " " + newStatus;
978 newStatusDiv.setAttribute("class", "statusMessage");
979 newStatusDiv.span = newStatusSpan;
980
981 _mainElem.appendChild(newStatusDiv);
982 _statusMap["status" + _statusIDCounter] = newStatusDiv;
983 _activeMessages++;
984 return _statusIDCounter++;
985 }
986
987 this.changeStatus = function(id, newStatus)
988 {
989 if(_statusMap["status" + id])
990 {
991 _statusMap["status" + id].span.innerHTML = " " + newStatus;
992 }
993 }
994
995 this.removeStatus = function(id)
996 {
997 if(_statusMap["status" + id])
998 {
999 removeFromParent(_statusMap["status" + id]);
1000
1001 if(--_activeMessages == 0)
1002 {
1003 _mainElem.style.display = "none";
1004 }
1005 }
1006 }
1007}
1008
1009/*
1010function toggleEdit(e)
1011{
1012 var mousePos = de.events.getXYInWindowFromEvent(e);
1013 var cDesc = de.cursor.getCursorDescAtXY(mousePos.x, mousePos.y, de.events.getEventTarget(e));
1014 de.cursor.setCursor(cDesc);
1015}
1016*/
Note: See TracBrowser for help on using the repository browser.