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

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

Added the ability to remove metadata

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