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

Last change on this file since 27163 was 26704, checked in by davidb, 11 years ago

Changed display of save button and add metadata controls to be more consistent with display of other controls.

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