source: main/trunk/greenstone3/web/interfaces/default/js/documentmaker_scripts_util.js@ 26284

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

Some more fixes to document creation

  • Property svn:executable set to *
File size: 26.2 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 var value = changedElem.innerHTML;
233 value = value.replace(/&nbsp;/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
314function 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
438function 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
490function 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
513function 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
530function 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
571function 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
582function 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
624function 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
631function addFunctionalityToTable(table)
632{
633 var rows = table.getElementsByTagName("TR");
634 for(var i = 0; i < rows.length; i++)
635 {
636 var cells = rows[i].getElementsByTagName("TD");
637 var metadataName = cells[0].innerHTML;
638
639 if(metadataName.indexOf(".") != -1)
640 {
641 var metadataSetName = metadataName.substring(0, metadataName.lastIndexOf("."));
642
643 var found = false;
644 for(var j = 0; j < _metadataSetList.length; j++)
645 {
646 if(metadataSetName == _metadataSetList[j])
647 {
648 found = true;
649 break;
650 }
651 }
652
653 if(!found)
654 {
655 _metadataSetList.push(metadataSetName);
656
657 var metadataSetList = document.getElementById("metadataSetList");
658 var newOption = document.createElement("OPTION");
659 newOption.innerHTML = metadataSetName;
660 metadataSetList.appendChild(newOption);
661 }
662 }
663
664 asyncRegisterEditSection(cells[1]);
665
666 addRemoveLinkToRow(rows[i]);
667 }
668
669 var metaNameField = document.createElement("INPUT");
670 metaNameField.setAttribute("type", "text");
671 insertAfter(metaNameField, table);
672 table.metaNameField = metaNameField;
673
674 var addRowButton = document.createElement("BUTTON");
675 addRowButton.innerHTML = gs.text.dse.add_new_metadata;
676 addRowButton.onclick = function()
677 {
678 var name = metaNameField.value;
679 if(!name || name == "")
680 {
681 console.log(gs.text.dse.no_value_given);
682 return;
683 }
684
685 var newRow = document.createElement("TR");
686 var nameCell = document.createElement("TD");
687 var valueCell = document.createElement("TD");
688 nameCell.setAttribute("class", "metaTableCellName");
689 nameCell.innerHTML = name;
690 valueCell.setAttribute("class", "metaTableCell");
691
692 newRow.appendChild(nameCell);
693 newRow.appendChild(valueCell);
694 addRemoveLinkToRow(newRow);
695 table.appendChild(newRow);
696
697 var undo = new Array();
698 undo.op = "delMeta";
699 undo.srcElem = newRow;
700 undo.removeTransaction = false;
701 _undoOperations.push(undo);
702
703 //Threading this function here probably isn't necessary like the other times it is called
704 de.doc.registerEditSection(valueCell);
705 };
706 table.addRowButton = addRowButton;
707 insertAfter(addRowButton, metaNameField);
708}
709
710function addRemoveLinkToRow(row)
711{
712 var newCell = document.createElement("TD");
713 var removeLink = document.createElement("A");
714 removeLink.innerHTML = "remove";
715 removeLink.setAttribute("href", "javascript:;");
716 removeLink.onclick = function()
717 {
718 var undo = new Array();
719 undo.srcElem = row;
720 undo.op = "display";
721 undo.subOp = "table-row";
722 undo.removeDeletedMetadata = true;
723 _undoOperations.push(undo);
724 _deletedMetadata.push(row);
725 row.style.display = "none";
726 }
727 newCell.appendChild(removeLink);
728 newCell.setAttribute("class", "metaTableCell");
729 newCell.setAttribute("style", "font-size:0.6em; padding-left: 3px; padding-right: 3px;");
730 row.appendChild(newCell);
731}
732
733function createTopMenuBar()
734{
735 //Create the top menu bar
736 var headerTable = document.createElement("TABLE");
737 var tableBody = document.createElement("TBODY");
738 var row = document.createElement("TR");
739 var newDocCell = document.createElement("TD");
740 var newSecCell = document.createElement("TD");
741 var saveCell = document.createElement("TD");
742 var undoCell = document.createElement("TD");
743 var metadataListCell = document.createElement("TD");
744
745 var metadataListLabel = document.createElement("SPAN");
746 metadataListLabel.innerHTML = "Visible metadata: ";
747 var metadataList = document.createElement("SELECT");
748 metadataList.setAttribute("id", "metadataSetList");
749 metadataList.onchange = onVisibleMetadataSetChange;
750 var allMetadataOption = document.createElement("OPTION");
751 metadataList.appendChild(allMetadataOption);
752 allMetadataOption.innerHTML = "All";
753 metadataListCell.appendChild(metadataListLabel);
754 metadataListCell.appendChild(metadataList);
755
756 metadataListCell.setAttribute("class", "headerTableTD");
757 newDocCell.setAttribute("class", "headerTableTD");
758 newSecCell.setAttribute("class", "headerTableTD");
759 undoCell.setAttribute("class", "headerTableTD");
760 saveCell.setAttribute("class", "headerTableTD");
761
762 headerTable.appendChild(tableBody);
763 tableBody.appendChild(row);
764 row.appendChild(saveCell);
765 row.appendChild(undoCell);
766 row.appendChild(newDocCell);
767 row.appendChild(newSecCell);
768 row.appendChild(metadataListCell);
769
770 //The "Save changes" button
771 var saveButton = document.createElement("BUTTON");
772 saveButton.innerHTML = gs.text.dse.save_changes;
773 saveButton.setAttribute("onclick", "save();");
774 saveButton.setAttribute("id", "saveButton");
775 saveCell.appendChild(saveButton);
776
777 //The "Undo" button
778 var undoButton = document.createElement("BUTTON");
779 undoButton.innerHTML = "Undo";
780 undoButton.setAttribute("onclick", "undo();");
781 undoCell.appendChild(undoButton);
782
783 //The "Create new document" button
784 var newDocButton = document.createElement("BUTTON");
785 newDocButton.innerHTML = gs.text.dse.create_new_document;
786 newDocButton.setAttribute("onclick", "createNewDocumentArea();");
787 newDocButton.setAttribute("id", "createNewDocumentButton");
788 newDocCell.appendChild(newDocButton);
789
790 //The "Insert new section" LI
791 var newSecLI = createDraggableNewSection(newSecCell);
792
793 return headerTable;
794}
795
796function getMetadataFromNode(node, name)
797{
798 var currentNode = node.firstChild;
799 while(currentNode != null)
800 {
801 if(currentNode.nodeName == "metadataList")
802 {
803 currentNode = currentNode.firstChild;
804 break;
805 }
806
807 currentNode = currentNode.nextSibling;
808 }
809
810 while(currentNode != null)
811 {
812 if(currentNode.nodeName == "metadata" && currentNode.getAttribute("name") == name)
813 {
814 return currentNode.firstChild.nodeValue;
815 }
816
817 currentNode = currentNode.nextSibling;
818 }
819 return "";
820}
821
822function storeMetadata(node, listItem)
823{
824 listItem.metadata = new Array();
825
826 var currentNode = node.firstChild;
827 while(currentNode != null)
828 {
829 if(currentNode.nodeName == "metadataList")
830 {
831 currentNode = currentNode.firstChild;
832 break;
833 }
834
835 currentNode = currentNode.nextSibling;
836 }
837
838 while(currentNode != null)
839 {
840 if(currentNode.nodeName == "metadata")
841 {
842 listItem.metadata[currentNode.getAttribute("name")] = currentNode.firstChild.nodeValue;
843 }
844
845 currentNode = currentNode.nextSibling;
846 }
847}
848
849function getNodeContent(node)
850{
851 var currentNode = node.firstChild;
852 while(currentNode != null)
853 {
854 if(currentNode.nodeName == "nodeContent")
855 {
856 return currentNode.firstChild;
857 }
858
859 currentNode = currentNode.nextSibling;
860 }
861 return null;
862}
863
864function containsDocumentNode(node)
865{
866 var currentNode = node.firstChild;
867 while(currentNode != null)
868 {
869 if(currentNode.nodeName == "documentNode")
870 {
871 return true;
872 }
873
874 currentNode = currentNode.nextSibling;
875 }
876 return false;
877}
878
879function isExpanded(textDiv)
880{
881 if(!textDiv.style.display || textDiv.style.display == "block")
882 {
883 return true;
884 }
885 return false;
886}
887
888function toggleTextDiv(section)
889{
890 var textDiv = section.textDiv;
891 if(textDiv)
892 {
893 if(isExpanded(textDiv))
894 {
895 textDiv.style.display = "none";
896 section.menu.editTextLink.innerHTML = gs.text.dse.edit;
897 }
898 else
899 {
900 textDiv.style.display = "block";
901 section.menu.editTextLink.innerHTML = gs.text.dse.hide;
902 }
903 }
904}
905
906function updateFromTop()
907{
908 updateRecursive(document.getElementById("dbDiv"), null, null, 0);
909}
910
911function insertAfter(elem, refElem)
912{
913 if(refElem.nextSibling)
914 {
915 refElem.parentNode.insertBefore(elem, refElem.nextSibling);
916 }
917 else
918 {
919 refElem.parentNode.appendChild(elem);
920 }
921}
922
923function removeFromParent(elem)
924{
925 elem.parentNode.removeChild(elem);
926}
927
928function createSectionTitle(text)
929{
930 var textSpan = document.createElement("SPAN");
931 if(text)
932 {
933 textSpan.appendChild(document.createTextNode(" " + text + " "));
934 }
935 else
936 {
937 textSpan.appendChild(document.createTextNode(" [" + gs.text.dse.untitled_section + "] "));
938 }
939 return textSpan;
940}
941
942function setMouseOverAndOutFunctions(section)
943{
944 //Colour the list item and display the menu on mouse over
945 section.onmouseover = function(e)
946 {
947 if(this.menu){this.menu.style.display = "inline";}
948 this.style.background = "rgb(255, 200, 0)";
949 };
950 //Uncolour the list item and hide the menu on mouse out
951 section.onmouseout = function(e)
952 {
953 if(this.menu){this.menu.style.display = "none";}
954 this.style.background = "none";
955 };
956}
957
958function createDraggableNewSection(parent)
959{
960 var newSecLI = document.createElement("LI");
961 var newSpan = document.createElement("SPAN");
962 newSpan.innerHTML = gs.text.dse.insert_new_section + " ";
963
964 newSecLI.sectionTitle = newSpan;
965 newSecLI.appendChild(newSpan);
966 newSecLI.setAttribute("class", "dragItem newSection");
967 newSecLI.newSection = true;
968 newSecLI.parent = parent;
969 newSecLI.index = -1;
970 new YAHOO.example.DDList(newSecLI);
971 parent.appendChild(newSecLI);
972}
973
974function closeAllOpenContents()
975{
976 for(var i = 0; i < _allContents.length; i++)
977 {
978 if(isExpanded(_allContents[i].textDiv))
979 {
980 toggleTextDiv(_allContents[i]);
981 }
982 }
983 DDM.refreshCache();
984}
985
986//Status Bar class (initialised with new StatusBar(elem);)
987function StatusBar(mainElem)
988{
989 var _statusMap = new Array();
990 var _statusIDCounter = 0;
991 var _mainElem = mainElem;
992 var _activeMessages = 0;
993
994 _mainElem.style.display = "none";
995
996 this.addStatus = function(newStatus)
997 {
998 _mainElem.style.display = "block";
999 var newStatusDiv = document.createElement("DIV");
1000 var newStatusSpan = document.createElement("SPAN");
1001
1002 var workingImage = document.createElement("IMG");
1003 workingImage.setAttribute("src", gs.imageURLs.loading);
1004 workingImage.setAttribute("height", "16px");
1005 workingImage.setAttribute("width", "16px");
1006 newStatusDiv.appendChild(workingImage);
1007
1008 newStatusDiv.appendChild(newStatusSpan);
1009 newStatusSpan.innerHTML = " " + newStatus;
1010 newStatusDiv.setAttribute("class", "statusMessage");
1011 newStatusDiv.span = newStatusSpan;
1012
1013 _mainElem.appendChild(newStatusDiv);
1014 _statusMap["status" + _statusIDCounter] = newStatusDiv;
1015 _activeMessages++;
1016 return _statusIDCounter++;
1017 }
1018
1019 this.changeStatus = function(id, newStatus)
1020 {
1021 if(_statusMap["status" + id])
1022 {
1023 _statusMap["status" + id].span.innerHTML = " " + newStatus;
1024 }
1025 }
1026
1027 this.removeStatus = function(id)
1028 {
1029 if(_statusMap["status" + id])
1030 {
1031 removeFromParent(_statusMap["status" + id]);
1032
1033 if(--_activeMessages == 0)
1034 {
1035 _mainElem.style.display = "none";
1036 }
1037 }
1038 }
1039}
1040
1041/*
1042function toggleEdit(e)
1043{
1044 var mousePos = de.events.getXYInWindowFromEvent(e);
1045 var cDesc = de.cursor.getCursorDescAtXY(mousePos.x, mousePos.y, de.events.getEventTarget(e));
1046 de.cursor.setCursor(cDesc);
1047}
1048*/
Note: See TracBrowser for help on using the repository browser.