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

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

More document maker changes

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