Changeset 27256 for main


Ignore:
Timestamp:
2013-04-23T16:56:08+12:00 (11 years ago)
Author:
sjm84
Message:

Allow visiting called templates as well as other improvements

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

    r27218 r27256  
    527527                }
    528528
    529                 var getURL = gs.xsltParams.library_name + "?a=g&rt=r&s=GetTemplateListFromFile&s1.fileName=" + selectedItem.data("fileItem").path + "&s1.locationName=" + selectedItem.data("fileItem").location + "&s1.interfaceName=" + gs.xsltParams.interface_name + "&s1.siteName=" + gs.xsltParams.site_name + "&s1.collectionName=" + gs.cgiParams.c;
    530                 $.ajax(getURL)
    531                 .success(function(templateResponse)
    532                 {
    533                     var templateListStart = templateResponse.indexOf("<templateList>") + "<templateList>".length;
    534                     var templateListEnd = templateResponse.indexOf("</templateList>");
    535                     var templateListString = templateResponse.substring(templateListStart, templateListEnd).replace(/&quot;/g, "\"");
    536                     var templateList = eval(templateListString);
    537 
    538                     _templateSelector.children("select").empty();
    539                     if(templateList.length == 0)
    540                     {
    541                         _templateSelector.children("select").append($("<option>-- No templates --</option>").data("index", -1));
    542                     }
    543 
    544                     for(var i = 0; i < templateList.length; i++)
    545                     {
    546                         var filename = selectedItem.data("fileItem").path;
    547                         var location = selectedItem.data("fileItem").location;
    548                         var namespace = templateList[i].namespace;
    549                         var nodename = "template";
    550                         var name = templateList[i].name;
    551                         var match = templateList[i].match;
    552 
    553                         if(name)
    554                         {
    555                             name = templateList[i].name.replace(/&apos;/g, "'").replace(/&quot;/g, "\"").replace(/&amp;/g, "&");
    556                         }
    557                         if(match)
    558                         {
    559                             match = templateList[i].match.replace(/&apos;/g, "'").replace(/&quot;/g, "\"").replace(/&amp;/g, "&");
    560                         }
    561 
    562                         var infoContainer = $("<option>");
    563 
    564                         _elements.push(infoContainer);
    565 
    566                         addChangeEventToInfoContainer(infoContainer, filename, location, nodename, namespace, name, match);
    567 
    568                         if(name && name.length > 0)
    569                         {
    570                             infoContainer.text(name);
    571                         }
    572                         if(match && match.length > 0)
    573                         {
    574                             infoContainer.text(match);
    575                         }
    576 
    577                         infoContainer.data("index", i);
    578                         _templateSelector.children("select").append(infoContainer);
    579                     }
    580 
    581                     _templateSelector.children("select").trigger("change");
    582                 });
     529                _greenbug.populateTemplateSelectorFromFile(selectedItem.data("fileItem").path, selectedItem.data("fileItem").location, function(){_templateSelector.children("select").trigger("change")});
    583530            });
    584531        })
     
    654601        _elements.push(rightBorderDiv);
    655602    }
     603   
     604    this.populateTemplateSelectorFromFile = function(filename, location, callback)
     605    {
     606        var getURL = gs.xsltParams.library_name + "?a=g&rt=r&s=GetTemplateListFromFile&s1.fileName=" + filename + "&s1.locationName=" + location + "&s1.interfaceName=" + gs.xsltParams.interface_name + "&s1.siteName=" + gs.xsltParams.site_name + "&s1.collectionName=" + gs.cgiParams.c;
     607        $.ajax(getURL)
     608        .success(function(templateResponse)
     609        {
     610            var templateListStart = templateResponse.indexOf("<templateList>") + "<templateList>".length;
     611            var templateListEnd = templateResponse.indexOf("</templateList>");
     612            var templateListString = templateResponse.substring(templateListStart, templateListEnd).replace(/&quot;/g, "\"");
     613            var templateList = eval(templateListString);
     614
     615            _templateSelector.children("select").empty();
     616            if(templateList.length == 0)
     617            {
     618                _templateSelector.children("select").append($("<option>-- No templates --</option>").data("index", -1));
     619            }
     620
     621            for(var i = 0; i < templateList.length; i++)
     622            {
     623                var namespace = templateList[i].namespace;
     624                var nodename = "template";
     625                var name = templateList[i].name;
     626                var match = templateList[i].match;
     627
     628                if(name)
     629                {
     630                    name = templateList[i].name.replace(/&apos;/g, "'").replace(/&quot;/g, "\"").replace(/&amp;/g, "&");
     631                }
     632                if(match)
     633                {
     634                    match = templateList[i].match.replace(/&apos;/g, "'").replace(/&quot;/g, "\"").replace(/&amp;/g, "&");
     635                }
     636
     637                var infoContainer = $("<option>");
     638
     639                _elements.push(infoContainer);
     640
     641                addChangeEventToInfoContainer(infoContainer, filename, location, nodename, namespace, name, match);
     642
     643                if(name && name.length > 0)
     644                {
     645                    infoContainer.text(name);
     646                }
     647                if(match && match.length > 0)
     648                {
     649                    infoContainer.text(match);
     650                }
     651
     652                infoContainer.data("index", i);
     653                _templateSelector.children("select").append(infoContainer);
     654            }
     655           
     656            if(callback)
     657            {
     658                callback();
     659            }
     660        });
     661    }
    656662
    657663    //Change the current template in the XML and Visual editor
     
    750756    }
    751757   
     758    this.getTemplateTracker = function()
     759    {
     760        return _templateTracker;
     761    }
     762   
    752763    //Turns a filename into it's location (i.e. interface/site/collection) and name
    753764    this.fileNameToLocationAndName = function(filepath)
     
    776787            filename = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]transform[\/\\]/, "");
    777788        }
     789       
     790        filename = filename.replace(/\\/g, "/");
    778791       
    779792        return {location:location, filename:filename};
  • main/trunk/greenstone3/web/interfaces/default/js/visual-xml-editor.js

    r27218 r27256  
    11461146        {
    11471147            return _id;
     1148        }
     1149       
     1150        var visitCalledTemplate = function()
     1151        {
     1152            var url = gs.xsltParams.library_name + "?a=g&rt=r&s=ResolveCallTemplate&s1.interfaceName=" + gs.xsltParams.interface_name + "&s1.siteName=" + gs.xsltParams.site_name + "&s1.collectionName=" + gs.cgiParams.c + "&s1.fileName=" + _fileName + "&s1.templateName=" + _xmlNode.getAttribute("name");
     1153            $.ajax(url)
     1154            .success(function(response)
     1155            {
     1156                var startIndex = response.indexOf("<requestedTemplate>") + ("<requestedTemplate>").length;
     1157                var endIndex = response.indexOf("</requestedTemplate>");
     1158               
     1159                if(endIndex != -1)
     1160                {
     1161                    var templateFileName = response.substring(startIndex, endIndex);
     1162                    var file = _greenbug.fileNameToLocationAndName(templateFileName);
     1163                   
     1164                    var fileTemplateName = file.filename.replace(/\\/g, "/") + " (" + file.location + ")";
     1165                    $("#veFileSelector").find("option").filter(function(){return $(this).text() == fileTemplateName}).prop("selected", true);
     1166                    _greenbug.populateTemplateSelectorFromFile(file.filename, file.location);
     1167                    _greenbug.changeCurrentTemplate(file.location, file.filename, "template", "xsl", _xmlNode.getAttribute("name"), null);
     1168                }
     1169                else
     1170                {
     1171                    _greenbug.changeCurrentTemplate("interface", "gslib.xsl", "template", "xsl", _xmlNode.getAttribute("name"), null);
     1172                }
     1173            });
    11481174        }
    11491175
     
    12491275                   
    12501276                    visitTemplateOption.button();
    1251                     visitTemplateOption.click(function()
    1252                     {
    1253                         var url = gs.xsltParams.library_name + "?a=g&rt=r&s=ResolveCallTemplate&s1.interfaceName=" + gs.xsltParams.interface_name + "&s1.siteName=" + gs.xsltParams.site_name + "&s1.collectionName=" + gs.cgiParams.c + "&s1.fileName=" + _fileName + "&s1.templateName=" + _xmlNode.getAttribute("name");
    1254                         $.ajax(url)
    1255                         .success(function(response)
    1256                         {
    1257                             var startIndex = response.indexOf("<requestedTemplate>") + ("<requestedTemplate>").length;
    1258                             var endIndex = response.indexOf("</requestedTemplate>");
    1259                            
    1260                             if(endIndex != -1)
    1261                             {
    1262                                 var templateFileName = response.substring(startIndex, endIndex);
    1263                                 var file = _greenbug.fileNameToLocationAndName(templateFileName);
    1264                                 _greenbug.changeCurrentTemplate(file.location, file.filename, "template", "xsl", _xmlNode.getAttribute("name"), null);
    1265                             }
    1266                             else
    1267                             {
    1268                                 _greenbug.changeCurrentTemplate("interface", "gslib.xsl", "template", "xsl", _xmlNode.getAttribute("name"), null);
    1269                             }
    1270                         });
    1271                     });
     1277                    visitTemplateOption.click(visitCalledTemplate);
    12721278                }
    12731279            }
     
    12861292            {
    12871293                event.stopPropagation();
    1288                 _div.css("border", "1px solid orange");
     1294                if(!_selectedElement || _id != _selectedElement.data("parentVEElement").getID())
     1295                {
     1296                    _div.css("border", "1px solid orange");
     1297                }
     1298
    12891299                var titleString = " ";
    12901300                if(_xmlNode.nodeType == 1)
     
    13071317            _div.mouseout(function(event)
    13081318            {
    1309                 _div.css("border", "1px solid black");
     1319                if(!_selectedElement || _id != _selectedElement.data("parentVEElement").getID())
     1320                {
     1321                    _div.css("border", "1px solid black");
     1322                }
    13101323                event.stopPropagation();
    13111324            });
    13121325            _div.click(function(event)
    13131326            {
     1327                event.stopPropagation();
    13141328                if(_selectedElement)
    13151329                {
    13161330                    _selectedElement.css("border", _selectedElement.prevBorder);
     1331                    if(_selectedElement.children("a").length)
     1332                    {
     1333                        _selectedElement.children("a").replaceWith(_selectedElement.children("a").children(".veTitleElement"));
     1334                    }
    13171335                }
    13181336                _selectedElement = _div;
     
    13221340                _div.data("parentVEElement").focus();
    13231341                _div.data("parentVEElement").populateInformationDiv();
    1324 
    1325                 event.stopPropagation();
     1342               
     1343                if(_xmlNode.tagName == "xsl:call-template" && _xmlNode.getAttribute("name").length > 0)
     1344                {
     1345                    var link = $("<a>");
     1346                    link.attr("href", "javascript:;");
     1347                    link.click(visitCalledTemplate);
     1348                    link.append(_div.children(".veTitleElement"));
     1349                    _div.append(link);
     1350                }
    13261351            });
    13271352        }
Note: See TracChangeset for help on using the changeset viewer.