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

Last change on this file since 27810 was 27810, checked in by sjm84, 11 years ago

A fix to a silly mistake that was causing multiple metadata values to not be saved

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