Changeset 27218 for main


Ignore:
Timestamp:
2013-04-18T13:15:34+12:00 (11 years ago)
Author:
sjm84
Message:

Added back, forwards and current selection buttons, also various improvements and fixes

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  
    77    //The this variable
    88    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();
    985
    1086    //Debugger state-keeping variables
     
    1591    var _editModeText = false;
    1692    var _fromSelection = false;
    17     var _selectedTemplate;
    1893    var _selectedInfoContainers = new Array();
    1994
     
    29104    var _editor;
    30105    var _editingDiv;
     106    var _xmlStatusBar;
     107   
     108    //Buttons
     109    var _backButton;
     110    var _forwardButton;
     111    var _currentSelectionButton;
    31112    var _enableSelectorButton;
    32113    var _closeEditorButton;
    33     var _xmlStatusBar;
    34114    var _saveButton;
    35115    var _swapEditorButton;
     
    95175        }
    96176    }
     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    }
    97254
    98255    //Create the area where the buttons are stored
    99     var createButtonDiv = function(buttonDiv)
     256    var createControlButtons = function(buttonDiv)
    100257    {
    101258        //Used to enable the selector to get the templates of a particular area of the page
     
    112269            _enableSelectorButton.button("option", "disabled", true);
    113270        });
    114         _styleFunctions.push(function(){_enableSelectorButton.button({icons:{primary:"ui-icon-power"}})});
     271        _styleFunctions.push(function(){_enableSelectorButton.button({icons:{primary:"ui-icon-pencil"}})});
    115272
    116273        //Used to minimise/restore the editor
     
    316473        _templateSelector.append($("<span>Templates: <span>"));
    317474        var templateSelectBox = $("<select>").append("<option>-- No templates --</option>");
    318         templateSelectBox.change(function()
     475        templateSelectBox.change(function(e, triggered)
    319476        {
    320477            var selected = templateSelectBox.find(":selected");
     
    323480            {
    324481                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)});
    325487            }
    326488        });
     
    341503            var list = eval(listString);
    342504
    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));
    345507            _fileSelector.addClass("ui-state-default");
    346508            _fileSelector.addClass("ui-corner-all");
    347509            _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);
    353511           
    354512            for(var i = 0; i < list.length; i++)
    355513            {
    356514                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);
    358516                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");
    377523               
    378524                if(!selectedItem.data("fileItem"))
     
    393539                    if(templateList.length == 0)
    394540                    {
    395                         _templateSelector.children("select").append("<option>-- No templates --</option>");
     541                        _templateSelector.children("select").append($("<option>-- No templates --</option>").data("index", -1));
    396542                    }
    397543
    398544                    for(var i = 0; i < templateList.length; i++)
    399545                    {
    400                         var fileName = selectedItem.data("fileItem").path;
     546                        var filename = selectedItem.data("fileItem").path;
    401547                        var location = selectedItem.data("fileItem").location;
    402548                        var namespace = templateList[i].namespace;
     
    418564                        _elements.push(infoContainer);
    419565
    420                         addChangeEventToInfoContainer(infoContainer, fileName, location, nodename, namespace, name, match);
     566                        addChangeEventToInfoContainer(infoContainer, filename, location, nodename, namespace, name, match);
    421567
    422568                        if(name && name.length > 0)
     
    429575                        }
    430576
     577                        infoContainer.data("index", i);
    431578                        _templateSelector.children("select").append(infoContainer);
    432579                    }
     
    465612        var buttonDiv = $("<div>");
    466613        toolBarDiv.append(buttonDiv);
    467         createButtonDiv(buttonDiv);
     614        createNavButtons(buttonDiv);
     615        createControlButtons(buttonDiv);
    468616        createFileAndTemplateSelectors(buttonDiv);
    469617        createXMLStatusBar(buttonDiv);
     
    508656
    509657    //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   
    512667        var responseName = "requestedNameTemplate";
    513668
    514         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;
     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;
    515670        if(match && match.length > 0){url += "&s1.match=" + match; responseName = "requestedMatchTemplate";}
    516671        if(name && name.length > 0){url += "&s1.name=" + name;}
     
    541696
    542697            _editingDiv.empty();
    543             _editingDiv.append($("<p>Location: " + location + " <br/>Filename: " + fileName + "</p>"));
     698            _editingDiv.append($("<p>Location: " + location + " <br/>Filename: " + filename + "</p>"));
    544699            _editingDiv.append(_textEditor);
    545700
     
    551706
    552707            _vEditor.setFileLocation(location);
    553             _vEditor.setFileName(fileName);
     708            _vEditor.setFileName(filename);
    554709
    555710            if(!_isVisualEditor)
     
    587742
    588743    //Store the function that is called when this template is selected from the list
    589     var addChangeEventToInfoContainer = function(infoContainer, fileName, location, nodename, namespace, name, match)
     744    var addChangeEventToInfoContainer = function(infoContainer, filename, location, nodename, namespace, name, match)
    590745    {
    591746        infoContainer.data("changeFunction", function()
    592747        {
    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);
    609749        });
    610750    }
     
    614754    {
    615755        var location;
    616         var fileName;
     756        var filename;
    617757        //Use the filepath to work out where this file is from
    618758        if(filepath.search(/[\/\\]interfaces[\/\\]/) != -1)
    619759        {
    620760            location = "interface";
    621             fileName = filepath.replace(/.*[\/\\]transform[\/\\]/, "");
     761            filename = filepath.replace(/.*[\/\\]transform[\/\\]/, "");
    622762        }
    623763        else if(filepath.search(/[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]etc[\/\\]/) != -1)
    624764        {
    625765            location = "collectionConfig";
    626             fileName = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]etc[\/\\]/, "");
     766            filename = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]etc[\/\\]/, "");
    627767        }
    628768        else if(filepath.search(/[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]transform[\/\\]/) != -1)
    629769        {
    630770            location = "collection";
    631             fileName = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]transform[\/\\]/, "");
     771            filename = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]transform[\/\\]/, "");
    632772        }
    633773        else if(filepath.search(/[\/\\]sites[\/\\].*[\/\\]transform[\/\\]/) != -1)
    634774        {
    635775            location = "site";
    636             fileName = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]transform[\/\\]/, "");
     776            filename = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]transform[\/\\]/, "");
    637777        }
    638778       
    639         return {location:location, filename:fileName};
     779        return {location:location, filename:filename};
    640780    }
    641781
     
    647787            if(_debugOn)
    648788            {
     789                e.stopPropagation();
    649790                $("a").off("click");
    650791                _debugOn = false;
    651792                _pauseSelector = true;
    652793                _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});
    656806            }
    657807        });
     
    718868                        infoContainer.text(match);
    719869                    }
    720                    
     870
     871                    _templateSelector.children("select").append(infoContainer);
     872                    infoContainer.data("index", infoContainer.index());
    721873                    _selectedInfoContainers.push(infoContainer.clone(true));
    722 
    723                     _templateSelector.children("select").append(infoContainer);
    724874                });
    725875               
  • main/trunk/greenstone3/web/interfaces/default/js/visual-xml-editor.js

    r27163 r27218  
    277277    var retrieveGSLIBTemplates = function(callback)
    278278    {
    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(/&quot;/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()
    288326            {
    289327                console.log("Error retrieving GSLIB templates");
    290                 return;
    291             }
    292 
    293             var listString = response.substring(startIndex, endIndex);
    294             var list = eval(listString.replace(/&quot;/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        }
    317330    }
    318331
     
    328341
    329342            var tab = $("<li>");
    330             var tabLink = $("<a>", {"href":"#ve" + key});
     343            var tabLink = $("<a>", {"href":document.URL + "#ve" + key});
    331344            tabLink.css({"font-size":"0.9em", "padding":"5px"});
    332345            tabLink.text(key);
     
    353366
    354367        var otherTab = $("<li>");
    355         var otherTabLink = $("<a>", {"href":"#veother"});
     368        var otherTabLink = $("<a>", {"href":document.URL + "#veother"});
    356369        otherTabLink.css({"font-size":"0.9em", "padding":"5px"});
    357370        otherTabLink.text("other");
Note: See TracChangeset for help on using the changeset viewer.