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