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

Allow visiting called templates as well as other improvements

File:
1 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};
Note: See TracChangeset for help on using the changeset viewer.