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

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

Added in metamode and the ability to add metadata

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