[31748] | 1 | /** Javascript file for the document maker, which is where you can split documents up etc. Not used at the moment until we work out exactly what it does. */
|
---|
| 2 | /** requires documentedit_scripts_util.js and documentmaker_scripts_util.js */
|
---|
| 3 | /** does it also need documentedit_scripts.js?? */
|
---|
| 4 |
|
---|
| 5 |
|
---|
| 6 | //var _transactions = new Array();
|
---|
| 7 | //var _collectionsToBuild = new Array();
|
---|
| 8 | //var _allContents = new Array();
|
---|
[25012] | 9 | var _idCounter = 0;
|
---|
| 10 | var _indexCounter = 0;
|
---|
[31748] | 11 | //var _deletedSections = new Array();
|
---|
| 12 | //var _deletedMetadata = new Array();
|
---|
| 13 | //var _undoOperations = new Array();
|
---|
| 14 | //var _baseURL;
|
---|
| 15 | //var _statusBar;
|
---|
| 16 | //var _metadataSetList = new Array();
|
---|
[25012] | 17 |
|
---|
[25142] | 18 | function initDocumentMaker()
|
---|
[25012] | 19 | {
|
---|
| 20 | //Get all of the links on the page
|
---|
| 21 | var allLinks = document.getElementsByTagName("a");
|
---|
| 22 |
|
---|
| 23 | //Work out which links are the actual document links
|
---|
| 24 | var docLinks = new Array();
|
---|
| 25 | for(var i = 0; i < allLinks.length; i++)
|
---|
| 26 | {
|
---|
[25363] | 27 | if(allLinks[i].getAttribute("class") && (gs.functions.hasClass(allLinks[i], "dbdoc")))
|
---|
[25012] | 28 | {
|
---|
| 29 | docLinks.push(allLinks[i]);
|
---|
| 30 | }
|
---|
| 31 | }
|
---|
| 32 |
|
---|
[25072] | 33 | if(gs.cgiParams.docToEdit)
|
---|
| 34 | {
|
---|
| 35 | var content = document.getElementById("gs_content");
|
---|
| 36 | var newLink = document.createElement("A");
|
---|
| 37 | newLink.setAttribute("href", gs.xsltParams.library_name + "?a=d&c=" + gs.cgiParams.p_c + "&dt=hierarchy&ed=1&d=" + gs.cgiParams.docToEdit);
|
---|
| 38 | content.appendChild(newLink);
|
---|
| 39 | docLinks.push(newLink);
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[25012] | 42 | if(docLinks.length == 0)
|
---|
| 43 | {
|
---|
[25296] | 44 | document.getElementById("gs_content").innerHTML = gs.text.dse.no_docs;
|
---|
[25012] | 45 | return;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | //Create the top menu bar
|
---|
| 49 | var menuBar = createTopMenuBar();
|
---|
| 50 |
|
---|
| 51 | //Add the menu bar to the page
|
---|
| 52 | var mainContentDiv = document.getElementById("gs_content");
|
---|
| 53 | mainContentDiv.appendChild(menuBar);
|
---|
| 54 |
|
---|
| 55 | var dbDiv = document.createElement("DIV");
|
---|
| 56 | dbDiv.setAttribute("id", "dbDiv");
|
---|
| 57 | insertAfter(dbDiv, menuBar);
|
---|
| 58 |
|
---|
| 59 | var statusDiv = document.createElement("DIV");
|
---|
| 60 | statusDiv.setAttribute("class", "statusBar");
|
---|
| 61 | insertAfter(statusDiv, menuBar);
|
---|
| 62 | _statusBar = new StatusBar(statusDiv);
|
---|
| 63 |
|
---|
| 64 | //Request the html for each link's page
|
---|
| 65 | for(var i = 0; i < docLinks.length; i++)
|
---|
| 66 | {
|
---|
[25363] | 67 | var callback =
|
---|
| 68 | {
|
---|
[25012] | 69 | success: addDocumentStructureToPage,
|
---|
| 70 | failure: function(data){/*alert("FAILED");*/}
|
---|
| 71 | }
|
---|
| 72 | callback.currentLink = docLinks[i];
|
---|
[33041] | 73 | YAHOO.util.Connect.asyncRequest("GET", docLinks[i].getAttribute("href").concat('&dmd=true&excerptid=gs-document-text&hhf='+makeURLComponentSafe('[{"name":"Cache-Control", "value":"no-cache"}]')), callback);
|
---|
[25012] | 74 | }
|
---|
| 75 |
|
---|
| 76 | _baseURL = gs.xsltParams.library_name;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | function addDocumentStructureToPage(data)
|
---|
| 80 | {
|
---|
| 81 | //Get the HTML
|
---|
| 82 | var page = data.responseText;
|
---|
| 83 |
|
---|
| 84 | //Add the HTML to the page inside an invisible div
|
---|
| 85 | var tempDiv = document.createElement("DIV");
|
---|
| 86 | tempDiv.innerHTML = page;
|
---|
| 87 | tempDiv.style.display = "none";
|
---|
| 88 | insertAfter(tempDiv, this.currentLink);
|
---|
| 89 |
|
---|
| 90 | //Get the collection that this document belongs to
|
---|
| 91 | var collection = document.getElementById("gs-document-text").getAttribute("collection");
|
---|
| 92 |
|
---|
| 93 | //Get the Document Basket div
|
---|
| 94 | var dbDiv = document.getElementById("dbDiv");
|
---|
| 95 |
|
---|
| 96 | //Create the container list and add it to the Document Basket div
|
---|
| 97 | var containerUL = document.createElement("UL");
|
---|
[25544] | 98 | containerUL.setAttribute("class", "topLevelItem");
|
---|
[25012] | 99 | dbDiv.appendChild(containerUL);
|
---|
| 100 |
|
---|
| 101 | //Get all of the headers in the page
|
---|
| 102 | var headers = getElementsByClassName("sectionTitle", tempDiv);
|
---|
| 103 |
|
---|
| 104 | //Some necessary loop variables
|
---|
| 105 | var prevItem = null;
|
---|
| 106 | var prevDepth = 0;
|
---|
| 107 | var levelContainers = new Array();
|
---|
| 108 | levelContainers[0] = containerUL;
|
---|
| 109 |
|
---|
| 110 | //Loop through all of the headers
|
---|
| 111 | for(var i = 0; i < headers.length; i++)
|
---|
| 112 | {
|
---|
| 113 | var currentHeader = headers[i];
|
---|
| 114 |
|
---|
| 115 | //If the currentHeader is not a <td> element then we are not interested
|
---|
| 116 | if(currentHeader.nodeName.toLowerCase() != "td")
|
---|
| 117 | {
|
---|
| 118 | continue;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | //Split the section ID on . to get its position in the document
|
---|
| 122 | var posArray = currentHeader.getAttribute("id").split(".");
|
---|
| 123 |
|
---|
| 124 | //Save the document ID
|
---|
| 125 | var docID = posArray[0].substring(6);
|
---|
| 126 |
|
---|
| 127 | //Save the depth of the section (top level is 0)
|
---|
| 128 | var depth = posArray.length - 1;
|
---|
| 129 |
|
---|
| 130 | //Turn the position array into a string
|
---|
| 131 | var position = "";
|
---|
| 132 | for(var j = 1; j < posArray.length; j++)
|
---|
| 133 | {
|
---|
| 134 | if(j != 1)
|
---|
| 135 | {
|
---|
| 136 | position += ".";
|
---|
| 137 | }
|
---|
| 138 | position += posArray[j];
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | //Save the section number
|
---|
| 142 | var secID = currentHeader.getAttribute("id").substring("6");
|
---|
| 143 |
|
---|
| 144 | //Get the text of the section
|
---|
| 145 | var currentText = document.getElementById("text" + secID);
|
---|
| 146 | var renderedDiv = createSectionTextDiv(currentText.innerHTML);
|
---|
| 147 |
|
---|
| 148 | var newItem = document.createElement("LI");
|
---|
| 149 | new YAHOO.example.DDList(newItem);
|
---|
| 150 |
|
---|
| 151 | var title = createSectionTitle(currentHeader.innerHTML);
|
---|
| 152 | newItem.sectionTitle = title;
|
---|
| 153 | newItem.appendChild(title);
|
---|
[25544] | 154 | newItem.setAttribute("class", depth == 0 ? "dragItem topLevelItem" : "dragItem");
|
---|
[25012] | 155 | newItem.textDiv = renderedDiv;
|
---|
| 156 | renderedDiv.parentItem = newItem;
|
---|
| 157 |
|
---|
| 158 | var metadataTable = document.getElementById("meta" + secID);
|
---|
| 159 | renderedDiv.insertBefore(metadataTable, renderedDiv.firstChild);
|
---|
| 160 | addFunctionalityToTable(metadataTable);
|
---|
| 161 |
|
---|
| 162 | if(depth > prevDepth)
|
---|
| 163 | {
|
---|
| 164 | var newContainer = document.createElement("UL");
|
---|
| 165 | new YAHOO.util.DDTarget(newContainer);
|
---|
| 166 | newContainer.setAttribute("class", "dragList");
|
---|
| 167 |
|
---|
| 168 | prevItem.childList = newContainer;
|
---|
| 169 | prevItem.menu.newSectionLink.style.display = "none";
|
---|
| 170 | newContainer.parentItem = prevItem;
|
---|
| 171 | levelContainers[depth - 1].appendChild(newContainer);
|
---|
| 172 | levelContainers[depth] = newContainer;
|
---|
| 173 | }
|
---|
| 174 | prevDepth = depth;
|
---|
| 175 |
|
---|
| 176 | levelContainers[depth].appendChild(newItem);
|
---|
| 177 | levelContainers[depth].appendChild(renderedDiv);
|
---|
| 178 |
|
---|
| 179 | createSectionMenu(newItem);
|
---|
| 180 | setMouseOverAndOutFunctions(newItem);
|
---|
| 181 |
|
---|
| 182 | //Set various section properties
|
---|
| 183 | //newItem.collection = collectionName;
|
---|
| 184 | newItem.documentID = docID;
|
---|
| 185 | newItem.position = position;
|
---|
| 186 | newItem.nodeID = secID;
|
---|
| 187 | newItem.dbID = _idCounter++;
|
---|
| 188 | newItem.index = newItem.dbID;
|
---|
| 189 | newItem.collection = collection;
|
---|
| 190 | newItem.parentList = levelContainers[depth];
|
---|
| 191 |
|
---|
| 192 | prevItem = newItem;
|
---|
| 193 |
|
---|
| 194 | //Insert the section into the list of sections
|
---|
| 195 | _allContents.push(newItem);
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | removeFromParent(this.currentLink);
|
---|
| 199 | updateFromTop();
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | function createSectionTextDiv(text)
|
---|
| 203 | {
|
---|
| 204 | var renderedDiv = document.createElement("DIV");
|
---|
| 205 | renderedDiv.setAttribute("style", "display:none;");
|
---|
| 206 |
|
---|
| 207 | var textDiv = document.createElement("DIV");
|
---|
| 208 | if(text && text.length > 0)
|
---|
| 209 | {
|
---|
| 210 | textDiv.innerHTML = text;
|
---|
| 211 | }
|
---|
| 212 | else
|
---|
| 213 | {
|
---|
| 214 | textDiv.innerHTML = " ";
|
---|
| 215 | }
|
---|
| 216 | textDiv.setAttribute("class", "renderedText editable");
|
---|
| 217 |
|
---|
| 218 | //This registering can cause a sizeable delay so we'll thread it (effectively) so the browser is not paused
|
---|
[29861] | 219 | setTimeout(function(){addEditableState(textDiv, editableInitStates)}, 0);
|
---|
[25012] | 220 |
|
---|
| 221 | renderedDiv.appendChild(textDiv);
|
---|
| 222 | textDiv.parentDiv = renderedDiv;
|
---|
| 223 |
|
---|
| 224 | return renderedDiv;
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | function createNewDocumentArea()
|
---|
| 228 | {
|
---|
[25544] | 229 | var createButton = document.getElementById("createNewDocumentButton");
|
---|
| 230 | createButton.disabled = true;
|
---|
[25012] | 231 |
|
---|
[25544] | 232 | var saveButton = document.getElementById("saveButton");
|
---|
| 233 | saveButton.disabled = true;
|
---|
[25012] | 234 |
|
---|
[25544] | 235 | var statusID = _statusBar.addStatus("Creating document...");
|
---|
| 236 |
|
---|
| 237 | var newID = "HASH" + gs.functions.hashString("" + (new Date()).getTime());
|
---|
| 238 |
|
---|
| 239 | var ajax = new gs.functions.ajaxRequest();
|
---|
| 240 | ajax.open("POST", gs.xsltParams.library_name, true);
|
---|
| 241 | ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
---|
| 242 | ajax.onreadystatechange = function()
|
---|
[25012] | 243 | {
|
---|
[25544] | 244 | if(ajax.readyState == 4 && ajax.status == 200)
|
---|
| 245 | {
|
---|
| 246 | buildCollections([gs.cgiParams.p_c], [newID], function()
|
---|
| 247 | {
|
---|
| 248 | //Create the necessary elements
|
---|
| 249 | var topLevelUL = document.createElement("UL");
|
---|
| 250 | var topLevelLI = document.createElement("LI");
|
---|
| 251 | var contentUL = document.createElement("UL");
|
---|
| 252 |
|
---|
| 253 | //Append the top-level list item to the top-level list
|
---|
| 254 | topLevelUL.appendChild(topLevelLI);
|
---|
| 255 | topLevelUL.setAttribute("class", "topLevelItem");
|
---|
| 256 |
|
---|
| 257 | //Set up the top-level item
|
---|
| 258 | topLevelLI.setAttribute("class", "dragItem topLevelItem");
|
---|
| 259 | topLevelLI.childList = contentUL;
|
---|
| 260 | topLevelLI.collection = gs.cgiParams.p_c;
|
---|
| 261 | topLevelLI.nodeID = newID;
|
---|
| 262 | contentUL.parentItem = topLevelLI;
|
---|
| 263 |
|
---|
| 264 | //Add a textDiv to the top-level item
|
---|
| 265 | var textDiv = createSectionTextDiv(null);
|
---|
| 266 | textDiv.parentItem = topLevelLI;
|
---|
| 267 | topLevelLI.textDiv = textDiv;
|
---|
| 268 | topLevelUL.appendChild(textDiv);
|
---|
| 269 |
|
---|
| 270 | //Create a blank metadata table
|
---|
| 271 | var metaTable = document.createElement("TABLE");
|
---|
| 272 | metaTable.setAttribute("id", "meta" + newID);
|
---|
| 273 | textDiv.insertBefore(metaTable, textDiv.firstChild);
|
---|
| 274 | var titleMetaRow = document.createElement("TR");
|
---|
| 275 | var titleMetaNameCell = document.createElement("TD");
|
---|
| 276 | titleMetaNameCell.innerHTML = "dc.Title";
|
---|
| 277 | titleMetaNameCell.setAttribute("class", "metaTableCellName");
|
---|
| 278 | var titleMetaValueCell = document.createElement("TD");
|
---|
| 279 | titleMetaValueCell.setAttribute("class", "metaTableCell editable");
|
---|
| 280 | titleMetaValueCell.innerHTML = "UNTITLED DOCUMENT";
|
---|
| 281 | titleMetaRow.appendChild(titleMetaNameCell);
|
---|
| 282 | titleMetaRow.appendChild(titleMetaValueCell);
|
---|
| 283 | metaTable.appendChild(titleMetaRow);
|
---|
| 284 | addFunctionalityToTable(metaTable);
|
---|
| 285 |
|
---|
| 286 | //Add a title to the top-level item
|
---|
| 287 | var title = createSectionTitle(gs.text.dse.untitled);
|
---|
| 288 | topLevelLI.appendChild(title);
|
---|
| 289 | topLevelLI.sectionTitle = title;
|
---|
| 290 |
|
---|
| 291 | createSectionMenu(topLevelLI);
|
---|
| 292 | setMouseOverAndOutFunctions(topLevelLI);
|
---|
| 293 |
|
---|
| 294 | //Set up the placeholder for the first section
|
---|
| 295 | contentUL.setAttribute("class", "dragList");
|
---|
| 296 | new YAHOO.util.DDTarget(contentUL);
|
---|
| 297 |
|
---|
| 298 | //Create a placeholder and add it to first section
|
---|
| 299 | var placeHolder = createPlaceholder(null, contentUL, false);
|
---|
| 300 | contentUL.appendChild(placeHolder);
|
---|
| 301 |
|
---|
| 302 | //Add elements to the page
|
---|
| 303 | var dbDiv = document.getElementById("dbDiv");
|
---|
| 304 | if(dbDiv.firstChild)
|
---|
| 305 | {
|
---|
| 306 | dbDiv.insertBefore(topLevelUL, dbDiv.firstChild);
|
---|
| 307 | }
|
---|
| 308 | else
|
---|
| 309 | {
|
---|
| 310 | dbDiv.appendChild(topLevelUL);
|
---|
| 311 | }
|
---|
| 312 | insertAfter(contentUL, topLevelLI.textDiv);
|
---|
| 313 |
|
---|
| 314 | //Correct any issues
|
---|
| 315 | updateFromTop();
|
---|
| 316 | });
|
---|
| 317 | createButton.disabled = false;
|
---|
| 318 | saveButton.disabled = false;
|
---|
| 319 | _statusBar.removeStatus(statusID);
|
---|
| 320 | }
|
---|
| 321 | else if (ajax.readyState == 4)
|
---|
| 322 | {
|
---|
| 323 | createButton.disabled = false;
|
---|
| 324 | saveButton.disabled = false;
|
---|
| 325 | _statusBar.removeStatus(statusID);
|
---|
| 326 | }
|
---|
[25012] | 327 | }
|
---|
[25544] | 328 | console.log('[{"operation":"createDocument", "oid":"' + newID + '", "collection":"' + gs.cgiParams.p_c + '"}]');
|
---|
| 329 | ajax.send('a=g&rt=r&s=DocumentExecuteTransaction&s1.transactions=[{"operation":"createDocument", "oid":"' + newID + '", "collection":"' + gs.cgiParams.p_c + '"}]');
|
---|
[25012] | 330 | }
|
---|
| 331 |
|
---|
| 332 | function createPlaceholder(parent, parentList, mouseEvents)
|
---|
| 333 | {
|
---|
| 334 | //Create the place holder and assign its class
|
---|
| 335 | var placeHolder = document.createElement("LI");
|
---|
| 336 | placeHolder.setAttribute("class", "placeHolder");
|
---|
| 337 |
|
---|
| 338 | //If a parent was given then we can assign the collection and nodeID
|
---|
| 339 | if(parent)
|
---|
| 340 | {
|
---|
| 341 | placeHolder.collection = parent.collection;
|
---|
| 342 | placeHolder.nodeID = parent.nodeID;
|
---|
| 343 | }
|
---|
| 344 |
|
---|
| 345 | //If this is to be a plain placeholder then we don't want it to react to mouse events
|
---|
| 346 | if(mouseEvents)
|
---|
| 347 | {
|
---|
| 348 | placeHolder.isEmptyList = true;
|
---|
| 349 |
|
---|
| 350 | //Create the delete section link
|
---|
| 351 | var deleteSectionLink = document.createElement("A");
|
---|
[25296] | 352 | deleteSectionLink.innerHTML = gs.text.dse.delete_section;
|
---|
[25012] | 353 | deleteSectionLink.setAttribute("href", "javascript:;");
|
---|
| 354 | deleteSectionLink.setAttribute("class", "menuLink");
|
---|
| 355 | deleteSectionLink.style.display = "none";
|
---|
| 356 |
|
---|
| 357 | //Set the onclick behaviour of the delete link
|
---|
| 358 | deleteSectionLink.onclick = function()
|
---|
| 359 | {
|
---|
| 360 | //Delete the place holder
|
---|
| 361 | removeFromParent(placeHolder);
|
---|
| 362 |
|
---|
| 363 | //If this is in a list then delete the list (as this will be the only thing in the list)
|
---|
| 364 | if(parentList)
|
---|
| 365 | {
|
---|
| 366 | var undo = new Array();
|
---|
| 367 |
|
---|
| 368 | undo.op = "mva";
|
---|
| 369 | undo.srcElem = parentList;
|
---|
| 370 | undo.refElem = parent;
|
---|
| 371 | undo.removeTransaction = false;
|
---|
| 372 | _undoOperations.push(undo);
|
---|
| 373 |
|
---|
| 374 | removeFromParent(parentList);
|
---|
| 375 | }
|
---|
| 376 |
|
---|
| 377 | //Enable the "add sub-section" menu option in the parent
|
---|
| 378 | if(parent)
|
---|
| 379 | {
|
---|
| 380 | parent.menu.newSectionLink.style.display = "inline";
|
---|
| 381 | parent.childList = null;
|
---|
| 382 | }
|
---|
| 383 | }
|
---|
| 384 | placeHolder.appendChild(deleteSectionLink);
|
---|
| 385 |
|
---|
| 386 | //Colour the list item and display the menu on mouse over
|
---|
| 387 | placeHolder.onmouseover = function(e)
|
---|
| 388 | {
|
---|
| 389 | deleteSectionLink.style.display = "inline";
|
---|
| 390 | this.style.background = "rgb(255, 200, 0)";
|
---|
| 391 | };
|
---|
| 392 | //Uncolour the list item and hide the menu on mouse out
|
---|
| 393 | placeHolder.onmouseout = function(e)
|
---|
| 394 | {
|
---|
| 395 | deleteSectionLink.style.display = "none";
|
---|
| 396 | this.style.background = "none";
|
---|
| 397 | };
|
---|
| 398 | }
|
---|
| 399 |
|
---|
| 400 | var dragItem = new YAHOO.example.DDList(placeHolder);
|
---|
| 401 | dragItem.addInvalidHandleClass("placeHolder");
|
---|
| 402 | return placeHolder;
|
---|
| 403 | }
|
---|
| 404 |
|
---|
| 405 | function duplicateSection(section)
|
---|
| 406 | {
|
---|
| 407 | var newLI = document.createElement("LI");
|
---|
| 408 | newLI.setAttribute("class", "dragItem");
|
---|
| 409 | new YAHOO.example.DDList(newLI);
|
---|
| 410 |
|
---|
| 411 | if(section.textDiv)
|
---|
| 412 | {
|
---|
| 413 | var textDiv = createSectionTextDiv(section.textDiv.innerHTML);
|
---|
| 414 | newLI.textDiv = textDiv;
|
---|
| 415 | }
|
---|
| 416 | newLI.collection = section.collectionName;
|
---|
| 417 |
|
---|
| 418 | if(section.sectionTitle)
|
---|
| 419 | {
|
---|
| 420 | var title = createSectionTitle(section.sectionTitle.innerHTML);
|
---|
| 421 | newLI.sectionTitle = title;
|
---|
| 422 | newLI.appendChild(title);
|
---|
| 423 | }
|
---|
| 424 |
|
---|
| 425 | createSectionMenu(newLI);
|
---|
| 426 | setMouseOverAndOutFunctions(newLI);
|
---|
| 427 | newLI.onmouseout();
|
---|
| 428 |
|
---|
| 429 | if(section.childList)
|
---|
| 430 | {
|
---|
| 431 | insertAfter(newLI, section.childList);
|
---|
| 432 | }
|
---|
| 433 | else if(section.textDiv)
|
---|
| 434 | {
|
---|
| 435 | insertAfter(newLI, section.textDiv);
|
---|
| 436 | }
|
---|
| 437 | else
|
---|
| 438 | {
|
---|
| 439 | insertAfter(newLI, section);
|
---|
| 440 | }
|
---|
| 441 |
|
---|
| 442 | if(newLI.textDiv)
|
---|
| 443 | {
|
---|
| 444 | insertAfter(newLI.textDiv, newLI);
|
---|
| 445 | }
|
---|
| 446 | return newLI;
|
---|
| 447 | }
|
---|
| 448 |
|
---|
| 449 | function duplicateSectionChildrenRecursive(duplicate, original)
|
---|
| 450 | {
|
---|
| 451 | if(!original.childList)
|
---|
| 452 | {
|
---|
| 453 | return;
|
---|
| 454 | }
|
---|
| 455 |
|
---|
| 456 | var newUL = document.createElement("UL");
|
---|
| 457 | newUL.setAttribute("class", "dragList");
|
---|
| 458 | new YAHOO.util.DDTarget(newUL);
|
---|
| 459 | insertAfter(newUL, duplicate.textDiv);
|
---|
| 460 |
|
---|
| 461 | var children = new Array();
|
---|
| 462 | var current = original.childList.firstChild;
|
---|
| 463 | while(current != null)
|
---|
| 464 | {
|
---|
| 465 | children.push(current);
|
---|
| 466 | current = current.nextSibling;
|
---|
| 467 | }
|
---|
| 468 |
|
---|
| 469 | for(var i = 0; i < children.length; i++)
|
---|
| 470 | {
|
---|
| 471 | current = children[i];
|
---|
[25363] | 472 | if(current.nodeName.toLowerCase() == "li" && !gs.functions.hasClass(current, "placeHolder"))
|
---|
[25012] | 473 | {
|
---|
| 474 | var newSection = duplicateSection(current);
|
---|
| 475 | newUL.appendChild(newSection);
|
---|
| 476 | if(current.childList)
|
---|
| 477 | {
|
---|
| 478 | duplicateSectionChildrenRecursive(newSection, current);
|
---|
| 479 | }
|
---|
| 480 | }
|
---|
| 481 | }
|
---|
| 482 |
|
---|
| 483 | duplicate.childList = newUL;
|
---|
| 484 | newUL.parentItem = duplicate.childList;
|
---|
| 485 |
|
---|
| 486 | if(duplicate.menu)
|
---|
| 487 | {
|
---|
| 488 | duplicate.menu.newSectionLink.style.display = "none";
|
---|
| 489 | }
|
---|
| 490 | }
|
---|
| 491 |
|
---|
| 492 | function deleteSection(section)
|
---|
| 493 | {
|
---|
| 494 | var undo = new Array();
|
---|
| 495 | var prev = getPrevSiblingOfType(section, "li");
|
---|
| 496 | var next = getNextSiblingOfType(section, "li");
|
---|
| 497 | var parent = section.parentList;
|
---|
| 498 | if(prev)
|
---|
| 499 | {
|
---|
| 500 | undo.op = "mva";
|
---|
| 501 | undo.refElem = prev;
|
---|
| 502 | }
|
---|
| 503 | else if(next)
|
---|
| 504 | {
|
---|
| 505 | undo.op = "mvb";
|
---|
| 506 | undo.refElem = next;
|
---|
| 507 | }
|
---|
| 508 | else
|
---|
| 509 | {
|
---|
| 510 | undo.op = "mvi";
|
---|
| 511 | undo.refElem = parent;
|
---|
| 512 | }
|
---|
| 513 | undo.srcElem = section;
|
---|
| 514 | undo.removeTransaction = true;
|
---|
| 515 | _undoOperations.push(undo);
|
---|
| 516 |
|
---|
| 517 | saveTransaction('{"operation":"delete", "collection":"' + section.collection + '", "oid":"' + section.nodeID + '"}');
|
---|
| 518 | addCollectionToBuild(section.collection);
|
---|
| 519 |
|
---|
| 520 | _deletedSections.push(section);
|
---|
| 521 | if(section.textDiv)
|
---|
| 522 | {
|
---|
| 523 | removeFromParent(section.textDiv);
|
---|
| 524 | }
|
---|
| 525 | if(section.childList)
|
---|
| 526 | {
|
---|
| 527 | removeFromParent(section.childList);
|
---|
| 528 | }
|
---|
| 529 | removeFromParent(section);
|
---|
| 530 | updateFromTop();
|
---|
| 531 | }
|
---|
| 532 |
|
---|
| 533 | function createBlankSection(parent)
|
---|
| 534 | {
|
---|
| 535 | if(parent.childList)
|
---|
| 536 | {
|
---|
| 537 | return;
|
---|
| 538 | }
|
---|
| 539 |
|
---|
| 540 | var newUL = document.createElement("UL");
|
---|
| 541 |
|
---|
| 542 | newUL.setAttribute("class", "dragList emptyList");
|
---|
| 543 | new YAHOO.util.DDTarget(newUL);
|
---|
| 544 |
|
---|
| 545 | insertAfter(newUL, parent.textDiv);
|
---|
| 546 | parent.childList = newUL;
|
---|
| 547 | newUL.parentItem = parent;
|
---|
| 548 |
|
---|
| 549 | var menu = parent.menu;
|
---|
| 550 | menu.newSectionLink.style.display = "none";
|
---|
| 551 |
|
---|
| 552 | var undo = new Array();
|
---|
| 553 | undo.op = "del";
|
---|
| 554 | undo.srcElem = newUL;
|
---|
| 555 | undo.removeTransaction = false;
|
---|
| 556 | _undoOperations.push(undo);
|
---|
| 557 | }
|
---|
| 558 |
|
---|
| 559 | function createSectionMenu(section)
|
---|
| 560 | {
|
---|
| 561 | var menuBar = document.createElement("SPAN");
|
---|
| 562 |
|
---|
| 563 | //Separator
|
---|
| 564 | menuBar.appendChild(document.createTextNode(" "));
|
---|
| 565 |
|
---|
| 566 | //"Edit" link
|
---|
| 567 | var toggleLink = document.createElement("A");
|
---|
[25296] | 568 | toggleLink.innerHTML = gs.text.dse.edit;
|
---|
[25012] | 569 | toggleLink.setAttribute("class", "menuLink");
|
---|
| 570 | toggleLink.setAttribute("href", "javascript:;");
|
---|
| 571 | toggleLink.onclick = function(){toggleTextDiv(section);};
|
---|
| 572 | menuBar.appendChild(toggleLink);
|
---|
| 573 | menuBar.editTextLink = toggleLink;
|
---|
| 574 |
|
---|
| 575 | //Separator
|
---|
| 576 | menuBar.appendChild(document.createTextNode(" "));
|
---|
| 577 |
|
---|
| 578 | var newSectionLink = document.createElement("A");
|
---|
[25296] | 579 | newSectionLink.innerHTML = gs.text.dse.add_sub_section.replace(/ /g, " ");
|
---|
[25012] | 580 | newSectionLink.setAttribute("class", "menuLink");
|
---|
| 581 | newSectionLink.setAttribute("href", "javascript:;");
|
---|
| 582 | newSectionLink.onclick = function()
|
---|
| 583 | {
|
---|
| 584 | createBlankSection(section);
|
---|
| 585 | updateFromTop();
|
---|
| 586 | };
|
---|
| 587 | menuBar.appendChild(newSectionLink);
|
---|
| 588 | menuBar.newSectionLink = newSectionLink;
|
---|
| 589 |
|
---|
| 590 | //"New Section" link
|
---|
| 591 | if(section.childList)
|
---|
| 592 | {
|
---|
| 593 | newSectionLink.style.display = "none";
|
---|
| 594 | }
|
---|
| 595 |
|
---|
| 596 | //Separator
|
---|
| 597 | menuBar.appendChild(document.createTextNode(" "));
|
---|
| 598 |
|
---|
| 599 | //"Duplicate" link
|
---|
| 600 | var duplicateLink = document.createElement("A");
|
---|
[25296] | 601 | duplicateLink.innerHTML = gs.text.dse.duplicate;
|
---|
[25012] | 602 | duplicateLink.setAttribute("class", "menuLink");
|
---|
| 603 | duplicateLink.setAttribute("href", "javascript:;");
|
---|
| 604 | duplicateLink.onclick = function()
|
---|
| 605 | {
|
---|
| 606 | var newSection = duplicateSection(section);
|
---|
| 607 | if(section.childList)
|
---|
| 608 | {
|
---|
| 609 | duplicateSectionChildrenRecursive(newSection, section);
|
---|
| 610 | }
|
---|
| 611 |
|
---|
| 612 | var newNodeID = section.nodeID;
|
---|
| 613 | var lastDigit = parseInt(newNodeID.substring(newNodeID.lastIndexOf(".") + 1));
|
---|
| 614 | newNodeID = newNodeID.replace(/\.[^\.]*$/, "." + ++lastDigit);
|
---|
| 615 |
|
---|
| 616 | var undo = new Array();
|
---|
| 617 | undo.op = "del";
|
---|
| 618 | undo.srcElem = section;
|
---|
| 619 | undo.removeTransaction = true;
|
---|
| 620 | _undoOperations.push(undo);
|
---|
| 621 |
|
---|
| 622 | saveTransaction('{"operation":"duplicate", "subOperation":"insertBefore", "collection":"' + section.collection + '", "oid":"' + section.nodeID + '", "newCollection":"' + section.collection + '", "newOID":"' + newNodeID + '"}');
|
---|
| 623 | addCollectionToBuild(section.collection);
|
---|
| 624 |
|
---|
| 625 | updateFromTop();
|
---|
| 626 | };
|
---|
| 627 | menuBar.appendChild(duplicateLink);
|
---|
| 628 | menuBar.duplicateLink = duplicateLink;
|
---|
| 629 |
|
---|
| 630 | //Separator
|
---|
| 631 | menuBar.appendChild(document.createTextNode(" "));
|
---|
| 632 |
|
---|
| 633 | //"Delete" link
|
---|
| 634 | var deleteLink = document.createElement("A");
|
---|
| 635 | deleteLink.innerHTML = "[X]";
|
---|
| 636 | deleteLink.setAttribute("class", "menuLink deleteLink");
|
---|
| 637 | deleteLink.setAttribute("href", "javascript:;");
|
---|
| 638 | deleteLink.onclick = function(){deleteSection(section)};
|
---|
| 639 | menuBar.appendChild(deleteLink);
|
---|
| 640 | menuBar.deleteLink = deleteLink;
|
---|
| 641 |
|
---|
| 642 | menuBar.style.display = "none";
|
---|
| 643 | section.appendChild(menuBar);
|
---|
| 644 | section.menu = menuBar;
|
---|
| 645 | }
|
---|
| 646 |
|
---|
| 647 | function updateRecursive(parent, currentDocument, currentPosition, level)
|
---|
| 648 | {
|
---|
| 649 | if(level == 0)
|
---|
| 650 | {
|
---|
| 651 | _indexCounter = 0;
|
---|
| 652 | }
|
---|
| 653 |
|
---|
| 654 | level++;
|
---|
| 655 | var current = parent.firstChild;
|
---|
| 656 | var posCount = 1;
|
---|
| 657 | var lastItem;
|
---|
| 658 | var liCount = 0;
|
---|
| 659 | while(current != null)
|
---|
| 660 | {
|
---|
| 661 | if(current.nodeName.toLowerCase() == "ul")
|
---|
| 662 | {
|
---|
| 663 | var pos = null;
|
---|
| 664 | if(level > 2)
|
---|
| 665 | {
|
---|
| 666 | if(!currentPosition)
|
---|
| 667 | {
|
---|
| 668 | pos = (posCount - 1);
|
---|
| 669 | }
|
---|
| 670 | else
|
---|
| 671 | {
|
---|
| 672 | pos = currentPosition + "." + (posCount - 1);
|
---|
| 673 | }
|
---|
| 674 | }
|
---|
| 675 |
|
---|
| 676 | updateRecursive(current, currentDocument, pos, level);
|
---|
| 677 | }
|
---|
[25363] | 678 | else if (current.nodeName.toLowerCase() == "li" && gs.functions.hasClass(current, "dragItem") && !gs.functions.hasClass(current, "placeHolder"))
|
---|
[25012] | 679 | {
|
---|
| 680 | if(currentDocument == null && current.nodeID)
|
---|
| 681 | {
|
---|
| 682 | currentDocument = current.nodeID;
|
---|
| 683 | }
|
---|
| 684 |
|
---|
| 685 | var pos;
|
---|
| 686 | if(!currentPosition)
|
---|
| 687 | {
|
---|
| 688 | pos = posCount;
|
---|
| 689 | }
|
---|
| 690 | else
|
---|
| 691 | {
|
---|
| 692 | pos = currentPosition + "." + posCount;
|
---|
| 693 | }
|
---|
| 694 |
|
---|
[25544] | 695 | if(!gs.functions.hasClass(current, "topLevelItem"))
|
---|
[25012] | 696 | {
|
---|
| 697 | current.nodeID = currentDocument + "." + pos;
|
---|
| 698 | current.position = pos;
|
---|
| 699 | current.documentID = currentDocument;
|
---|
| 700 | }
|
---|
| 701 | posCount++;
|
---|
| 702 |
|
---|
| 703 | current.index = _indexCounter++;
|
---|
| 704 | }
|
---|
[25363] | 705 | else if (gs.functions.hasClass(current, "placeHolder") && !current.isEmptyList)
|
---|
[25012] | 706 | {
|
---|
| 707 | var pos;
|
---|
| 708 | if(!currentPosition)
|
---|
| 709 | {
|
---|
| 710 | pos = posCount - 1;
|
---|
| 711 | }
|
---|
| 712 | else
|
---|
| 713 | {
|
---|
| 714 | pos = currentPosition + "." + posCount - 1;
|
---|
| 715 | }
|
---|
| 716 | current.nodeID = currentDocument + "." + pos;
|
---|
| 717 | }
|
---|
| 718 |
|
---|
| 719 | if(current.nodeName.toLowerCase() == "li")
|
---|
| 720 | {
|
---|
| 721 | liCount++;
|
---|
| 722 | lastItem = current;
|
---|
| 723 | }
|
---|
| 724 |
|
---|
| 725 | current = current.nextSibling;
|
---|
| 726 | }
|
---|
| 727 |
|
---|
| 728 | if(level > 2)
|
---|
| 729 | {
|
---|
| 730 | //If the last section a this level has a child list then insert a blank placeholder after it so we can insert sections after the list
|
---|
| 731 | if(lastItem && lastItem.childList)
|
---|
| 732 | {
|
---|
| 733 | var placeHolder = createPlaceholder(lastItem, parent, false);
|
---|
| 734 | parent.appendChild(placeHolder);
|
---|
| 735 | }
|
---|
| 736 |
|
---|
| 737 | //If this list is empty or has 1 placeholder child
|
---|
[25363] | 738 | if(liCount == 0 || (liCount == 1 && gs.functions.hasClass(lastItem, "placeHolder")))
|
---|
[25012] | 739 | {
|
---|
| 740 | //Give it the emptyList css class (if it does not already have it)
|
---|
| 741 | if(!parent.getAttribute("class") || parent.getAttribute("class").search("emptyList") == -1)
|
---|
| 742 | {
|
---|
| 743 | var newClass = parent.getAttribute("class") ? parent.getAttribute("class") + " emptyList" : "emptyList";
|
---|
| 744 | parent.setAttribute("class", newClass);
|
---|
| 745 | }
|
---|
| 746 |
|
---|
| 747 | //If the list is empty then add a placeholder
|
---|
| 748 | if(liCount == 0)
|
---|
| 749 | {
|
---|
| 750 | var placeHolder = createPlaceholder(parent.previousSibling.previousSibling, parent, true); //Find a smarter way of doing this
|
---|
| 751 | parent.appendChild(placeHolder);
|
---|
| 752 | }
|
---|
| 753 | }
|
---|
| 754 | //Remove the empty list class if the list is no longer empty
|
---|
[25363] | 755 | else if(gs.functions.hasClass(parent, "emptyList"))
|
---|
[25012] | 756 | {
|
---|
| 757 | parent.setAttribute("class", parent.getAttribute("class").replace(/emptyList/g, ""));
|
---|
| 758 | }
|
---|
| 759 | }
|
---|
[29861] | 760 | }
|
---|