Changeset 27218
- Timestamp:
- 2013-04-18T13:15:34+12:00 (11 years ago)
- Location:
- main/trunk/greenstone3/web/interfaces/default/js
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/js/debug_scripts.js
r27166 r27218 7 7 //The this variable 8 8 var _greenbug = this; 9 10 //Template tracker class 11 var TemplateTracker = function() 12 { 13 var templates = new Array(); 14 var currentIndex = -1; 15 16 this.push = function(object) 17 { 18 if(currentIndex < templates.length - 1 && templates.length > 0) 19 { 20 templates.splice(currentIndex + 1, templates.length - 1 - currentIndex); 21 } 22 templates[++currentIndex] = object; 23 24 _forwardButton.button("option", "disabled", true); 25 if(templates.length > 1) 26 { 27 _backButton.button("option", "disabled", false); 28 } 29 } 30 31 this.next = function() 32 { 33 if(currentIndex == templates.length - 1) 34 { 35 return; 36 } 37 38 if(currentIndex + 1 == templates.length - 1) 39 { 40 _forwardButton.button("option", "disabled", true); 41 } 42 _backButton.button("option", "disabled", false); 43 44 return templates[++currentIndex]; 45 } 46 47 this.previous = function() 48 { 49 if(currentIndex == 0) 50 { 51 return; 52 } 53 54 if(currentIndex - 1 == 0) 55 { 56 _backButton.button("option", "disabled", true); 57 } 58 _forwardButton.button("option", "disabled", false); 59 60 return templates[--currentIndex]; 61 } 62 63 this.peekPrevious = function() 64 { 65 if(currentIndex == 0) 66 { 67 return; 68 } 69 70 return templates[currentIndex - 1]; 71 } 72 73 this.peekNext = function() 74 { 75 if(currentIndex == templates.length - 1) 76 { 77 return; 78 } 79 80 return templates[currentIndex + 1]; 81 } 82 } 83 84 var _templateTracker = new TemplateTracker(); 9 85 10 86 //Debugger state-keeping variables … … 15 91 var _editModeText = false; 16 92 var _fromSelection = false; 17 var _selectedTemplate;18 93 var _selectedInfoContainers = new Array(); 19 94 … … 29 104 var _editor; 30 105 var _editingDiv; 106 var _xmlStatusBar; 107 108 //Buttons 109 var _backButton; 110 var _forwardButton; 111 var _currentSelectionButton; 31 112 var _enableSelectorButton; 32 113 var _closeEditorButton; 33 var _xmlStatusBar;34 114 var _saveButton; 35 115 var _swapEditorButton; … … 95 175 } 96 176 } 177 178 var changeToSelectedElement = function(templateIndex, templateList) 179 { 180 _templateSelector.children("select").empty(); 181 182 for(var i = 0; i < templateList.length; i++) 183 { 184 _templateSelector.children("select").append($(templateList[i]).clone(true)); 185 } 186 187 if(templateIndex === undefined) 188 { 189 _templateSelector.find("option").first().trigger("change", [true]); 190 } 191 else 192 { 193 _templateSelector.find("option").filter(function(){return $(this).data("index") == templateIndex}).first().trigger("change", [true]); 194 } 195 return; 196 } 197 198 var createNavButtons = function(buttonDiv) 199 { 200 var navButtonHolder = $("<div>").css("float", "left"); 201 202 var backForwardFunction = function(e) 203 { 204 var template; 205 if($(e.target).attr("id") == "veBack") 206 { 207 template = _templateTracker.previous(); 208 } 209 else 210 { 211 template = _templateTracker.next(); 212 } 213 214 if(!template) 215 { 216 return; 217 } 218 219 _fileSelector.find("option").filter(function(){return $(this).data("index") == template.fileIndex}).prop("selected", true); 220 221 changeToSelectedElement(template.templateIndex, template.list); 222 } 223 224 _backButton = $("<button>Back button</button>").attr("id", "veBack"); 225 _backButton.click(backForwardFunction); 226 _styleFunctions.push(function(){_backButton.button({icons:{primary:"ui-icon-triangle-1-w"}, text:false, disabled:true})}); 227 228 _forwardButton = $("<button>Forward button</button>").attr("id", "veForwards"); 229 _forwardButton.click(backForwardFunction); 230 _styleFunctions.push(function(){_forwardButton.button({icons:{primary:"ui-icon-triangle-1-e"}, text:false, disabled:true})}); 231 232 //Changes the template list to what is currently selected 233 _currentSelectionButton = $("<button>Current selection button</button>"); 234 _currentSelectionButton.click(function() 235 { 236 _fileSelector.find("option").eq(0).prop("selected", true); 237 changeToSelectedElement(undefined, _selectedInfoContainers); 238 239 var selectedCopy = new Array(); 240 for(var i = 0; i < _selectedInfoContainers.length; i++) 241 { 242 selectedCopy[i] = _selectedInfoContainers[i]; 243 } 244 245 _templateTracker.push({fileIndex:-1, templateIndex:0, list:selectedCopy}); 246 }); 247 _styleFunctions.push(function(){_currentSelectionButton.button({icons:{primary:"ui-icon-pencil"}, text:false, disabled:true})}); 248 249 navButtonHolder.append(_backButton); 250 navButtonHolder.append(_forwardButton); 251 navButtonHolder.append(_currentSelectionButton); 252 buttonDiv.append(navButtonHolder); 253 } 97 254 98 255 //Create the area where the buttons are stored 99 var create ButtonDiv= function(buttonDiv)256 var createControlButtons = function(buttonDiv) 100 257 { 101 258 //Used to enable the selector to get the templates of a particular area of the page … … 112 269 _enableSelectorButton.button("option", "disabled", true); 113 270 }); 114 _styleFunctions.push(function(){_enableSelectorButton.button({icons:{primary:"ui-icon-p ower"}})});271 _styleFunctions.push(function(){_enableSelectorButton.button({icons:{primary:"ui-icon-pencil"}})}); 115 272 116 273 //Used to minimise/restore the editor … … 316 473 _templateSelector.append($("<span>Templates: <span>")); 317 474 var templateSelectBox = $("<select>").append("<option>-- No templates --</option>"); 318 templateSelectBox.change(function( )475 templateSelectBox.change(function(e, triggered) 319 476 { 320 477 var selected = templateSelectBox.find(":selected"); … … 323 480 { 324 481 changeFunction(); 482 } 483 484 if(!triggered) 485 { 486 _templateTracker.push({fileIndex:_fileSelector.find(":selected").data("index"), templateIndex:selected.data("index"), list:templateSelectBox.children("option").clone(true)}); 325 487 } 326 488 }); … … 341 503 var list = eval(listString); 342 504 343 var selectBox = $("<select>");344 selectBox.append($("<option>-- Select a file --</option>", {value:"none"}));505 var fileSelectBox = $("<select>"); 506 fileSelectBox.append($("<option>-- Select a file --</option>").data("index", -1)); 345 507 _fileSelector.addClass("ui-state-default"); 346 508 _fileSelector.addClass("ui-corner-all"); 347 509 _fileSelector.append("<span>Files: </span>"); 348 _fileSelector.append(selectBox); 349 350 var currentSelectionOption = $("<option>[Current selection]</option>"); 351 currentSelectionOption.val("currentSelection"); 352 selectBox.append(currentSelectionOption); 510 _fileSelector.append(fileSelectBox); 353 511 354 512 for(var i = 0; i < list.length; i++) 355 513 { 356 514 var item = list[i]; 357 var option = $("<option>" + item.path + " (" + item.location + ")</option>" , {value:item.path});515 var option = $("<option>" + item.path + " (" + item.location + ")</option>").data("index", i); 358 516 option.data("fileItem", item); 359 selectBox.append(option); 360 } 361 362 selectBox.change(function() 363 { 364 var selectedItem = selectBox.find(":selected"); 365 366 if(selectedItem.val() == "currentSelection") 367 { 368 _templateSelector.children("select").empty(); 369 for(var i = 0; i < _selectedInfoContainers.length; i++) 370 { 371 var currentContainer = _selectedInfoContainers[i]; 372 _templateSelector.children("select").append(currentContainer); 373 } 374 _templateSelector.children("select").children().first().trigger("change"); 375 return; 376 } 517 fileSelectBox.append(option); 518 } 519 520 fileSelectBox.change(function() 521 { 522 var selectedItem = fileSelectBox.find(":selected"); 377 523 378 524 if(!selectedItem.data("fileItem")) … … 393 539 if(templateList.length == 0) 394 540 { 395 _templateSelector.children("select").append( "<option>-- No templates --</option>");541 _templateSelector.children("select").append($("<option>-- No templates --</option>").data("index", -1)); 396 542 } 397 543 398 544 for(var i = 0; i < templateList.length; i++) 399 545 { 400 var file Name = selectedItem.data("fileItem").path;546 var filename = selectedItem.data("fileItem").path; 401 547 var location = selectedItem.data("fileItem").location; 402 548 var namespace = templateList[i].namespace; … … 418 564 _elements.push(infoContainer); 419 565 420 addChangeEventToInfoContainer(infoContainer, file Name, location, nodename, namespace, name, match);566 addChangeEventToInfoContainer(infoContainer, filename, location, nodename, namespace, name, match); 421 567 422 568 if(name && name.length > 0) … … 429 575 } 430 576 577 infoContainer.data("index", i); 431 578 _templateSelector.children("select").append(infoContainer); 432 579 } … … 465 612 var buttonDiv = $("<div>"); 466 613 toolBarDiv.append(buttonDiv); 467 createButtonDiv(buttonDiv); 614 createNavButtons(buttonDiv); 615 createControlButtons(buttonDiv); 468 616 createFileAndTemplateSelectors(buttonDiv); 469 617 createXMLStatusBar(buttonDiv); … … 508 656 509 657 //Change the current template in the XML and Visual editor 510 this.changeCurrentTemplate = function(location, fileName, nodename, namespace, name, match) 511 { 658 this.changeCurrentTemplate = function(location, filename, nodename, namespace, name, match) 659 { 660 _currentFileName = filename; 661 _currentLocation = location; 662 _currentNodename = nodename; 663 _currentNamespace = namespace; 664 _currentName = name; 665 _currentMatch = match; 666 512 667 var responseName = "requestedNameTemplate"; 513 668 514 var url = gs.xsltParams.library_name + "?a=g&rt=r&s=GetXMLTemplateFromFile&s1.fileName=" + file Name + "&s1.interfaceName=" + gs.xsltParams.interface_name + "&s1.siteName=" + gs.xsltParams.site_name + "&s1.collectionName=" + gs.cgiParams.c + "&s1.locationName=" + location + "&s1.namespace=" + namespace + "&s1.nodename=" + nodename;669 var url = gs.xsltParams.library_name + "?a=g&rt=r&s=GetXMLTemplateFromFile&s1.fileName=" + filename + "&s1.interfaceName=" + gs.xsltParams.interface_name + "&s1.siteName=" + gs.xsltParams.site_name + "&s1.collectionName=" + gs.cgiParams.c + "&s1.locationName=" + location + "&s1.namespace=" + namespace + "&s1.nodename=" + nodename; 515 670 if(match && match.length > 0){url += "&s1.match=" + match; responseName = "requestedMatchTemplate";} 516 671 if(name && name.length > 0){url += "&s1.name=" + name;} … … 541 696 542 697 _editingDiv.empty(); 543 _editingDiv.append($("<p>Location: " + location + " <br/>Filename: " + file Name + "</p>"));698 _editingDiv.append($("<p>Location: " + location + " <br/>Filename: " + filename + "</p>")); 544 699 _editingDiv.append(_textEditor); 545 700 … … 551 706 552 707 _vEditor.setFileLocation(location); 553 _vEditor.setFileName(file Name);708 _vEditor.setFileName(filename); 554 709 555 710 if(!_isVisualEditor) … … 587 742 588 743 //Store the function that is called when this template is selected from the list 589 var addChangeEventToInfoContainer = function(infoContainer, file Name, location, nodename, namespace, name, match)744 var addChangeEventToInfoContainer = function(infoContainer, filename, location, nodename, namespace, name, match) 590 745 { 591 746 infoContainer.data("changeFunction", function() 592 747 { 593 if(_selectedTemplate) 594 { 595 _selectedTemplate.css("border", _selectedTemplate.prevBorder); 596 } 597 _selectedTemplate = infoContainer; 598 _selectedTemplate.prevBorder = _selectedTemplate.css("border"); 599 _selectedTemplate.css("border", "red 1px solid"); 600 601 _currentFileName = fileName; 602 _currentLocation = location; 603 _currentNodename = nodename; 604 _currentNamespace = namespace; 605 _currentName = name; 606 _currentMatch = match; 607 608 _greenbug.changeCurrentTemplate(location, fileName, nodename, namespace, name, match); 748 _greenbug.changeCurrentTemplate(location, filename, nodename, namespace, name, match); 609 749 }); 610 750 } … … 614 754 { 615 755 var location; 616 var file Name;756 var filename; 617 757 //Use the filepath to work out where this file is from 618 758 if(filepath.search(/[\/\\]interfaces[\/\\]/) != -1) 619 759 { 620 760 location = "interface"; 621 file Name = filepath.replace(/.*[\/\\]transform[\/\\]/, "");761 filename = filepath.replace(/.*[\/\\]transform[\/\\]/, ""); 622 762 } 623 763 else if(filepath.search(/[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]etc[\/\\]/) != -1) 624 764 { 625 765 location = "collectionConfig"; 626 file Name = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]etc[\/\\]/, "");766 filename = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]etc[\/\\]/, ""); 627 767 } 628 768 else if(filepath.search(/[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]transform[\/\\]/) != -1) 629 769 { 630 770 location = "collection"; 631 file Name = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]transform[\/\\]/, "");771 filename = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]transform[\/\\]/, ""); 632 772 } 633 773 else if(filepath.search(/[\/\\]sites[\/\\].*[\/\\]transform[\/\\]/) != -1) 634 774 { 635 775 location = "site"; 636 file Name = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]transform[\/\\]/, "");776 filename = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]transform[\/\\]/, ""); 637 777 } 638 778 639 return {location:location, filename:file Name};779 return {location:location, filename:filename}; 640 780 } 641 781 … … 647 787 if(_debugOn) 648 788 { 789 e.stopPropagation(); 649 790 $("a").off("click"); 650 791 _debugOn = false; 651 792 _pauseSelector = true; 652 793 _enableSelectorButton.button("option", "disabled", false); 653 _templateSelector.children("select").trigger("change"); 654 _fileSelector.children("select").val("currentSelection"); 655 e.stopPropagation(); 794 _templateSelector.children("select").trigger("change", [true]); 795 _fileSelector.children("select").val("none"); 796 797 var selectedCopy = new Array(); 798 for(var i = 0; i < _selectedInfoContainers.length; i++) 799 { 800 selectedCopy[i] = _selectedInfoContainers[i]; 801 } 802 803 _currentSelectionButton.button("option", "disabled", false); 804 805 _templateTracker.push({fileIndex:-1, list:selectedCopy, templateIndex:0}); 656 806 } 657 807 }); … … 718 868 infoContainer.text(match); 719 869 } 720 870 871 _templateSelector.children("select").append(infoContainer); 872 infoContainer.data("index", infoContainer.index()); 721 873 _selectedInfoContainers.push(infoContainer.clone(true)); 722 723 _templateSelector.children("select").append(infoContainer);724 874 }); 725 875 -
main/trunk/greenstone3/web/interfaces/default/js/visual-xml-editor.js
r27163 r27218 277 277 var retrieveGSLIBTemplates = function(callback) 278 278 { 279 var url = gs.xsltParams.library_name + "?a=g&rt=r&s=GetTemplateListFromFile&s1.locationName=interface&s1.interfaceName=" + gs.xsltParams.interface_name + "&s1.fileName=gslib.xsl"; 280 281 $.ajax(url) 282 .success(function(response) 283 { 284 startIndex = response.search("<templateList>") + "<templateList>".length; 285 endIndex = response.search("</templateList>"); 286 287 if(startIndex == "<templateList>".length - 1) 279 if($(document).data("gslibList")) 280 { 281 _elemList["gslib"] = $(document).data("gslibList"); 282 283 if(callback) 284 { 285 callback(); 286 } 287 } 288 else 289 { 290 var url = gs.xsltParams.library_name + "?a=g&rt=r&s=GetTemplateListFromFile&s1.locationName=interface&s1.interfaceName=" + gs.xsltParams.interface_name + "&s1.fileName=gslib.xsl"; 291 292 $.ajax(url) 293 .success(function(response) 294 { 295 startIndex = response.search("<templateList>") + "<templateList>".length; 296 endIndex = response.search("</templateList>"); 297 298 if(startIndex == "<templateList>".length - 1) 299 { 300 console.log("Error retrieving GSLIB templates"); 301 return; 302 } 303 304 var listString = response.substring(startIndex, endIndex); 305 var list = eval(listString.replace(/"/g, "\"")); 306 var modifiedList = new Array(); 307 308 for(var i = 0; i < list.length; i++) 309 { 310 var current = list[i]; 311 if(current.name) 312 { 313 modifiedList.push(current.name); 314 } 315 } 316 317 _elemList["gslib"] = modifiedList; 318 $(document).data("gslibList", modifiedList); 319 320 if(callback) 321 { 322 callback(); 323 } 324 }) 325 .error(function() 288 326 { 289 327 console.log("Error retrieving GSLIB templates"); 290 return; 291 } 292 293 var listString = response.substring(startIndex, endIndex); 294 var list = eval(listString.replace(/"/g, "\"")); 295 var modifiedList = new Array(); 296 297 for(var i = 0; i < list.length; i++) 298 { 299 var current = list[i]; 300 if(current.name) 301 { 302 modifiedList.push(current.name); 303 } 304 } 305 306 _elemList["gslib"] = modifiedList; 307 308 if(callback) 309 { 310 callback(); 311 } 312 }) 313 .error(function() 314 { 315 console.log("Error retrieving GSLIB templates"); 316 }); 328 }); 329 } 317 330 } 318 331 … … 328 341 329 342 var tab = $("<li>"); 330 var tabLink = $("<a>", {"href": "#ve" + key});343 var tabLink = $("<a>", {"href":document.URL + "#ve" + key}); 331 344 tabLink.css({"font-size":"0.9em", "padding":"5px"}); 332 345 tabLink.text(key); … … 353 366 354 367 var otherTab = $("<li>"); 355 var otherTabLink = $("<a>", {"href": "#veother"});368 var otherTabLink = $("<a>", {"href":document.URL + "#veother"}); 356 369 otherTabLink.css({"font-size":"0.9em", "padding":"5px"}); 357 370 otherTabLink.text("other");
Note:
See TracChangeset
for help on using the changeset viewer.