Changeset 27713


Ignore:
Timestamp:
2013-06-27T16:52:08+12:00 (11 years ago)
Author:
sjm84
Message:

Fixing collectionConfig templates being incorrect

Location:
main/trunk/greenstone3/web/interfaces/default/js
Files:
1 added
3 edited
9 moved

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/js/debug_scripts.js

    r27256 r27713  
    122122    var _currentMatch;
    123123    var _currentNamespace;
     124    var _currentXPath;
    124125    var _isVisualEditor = true;
    125126
     
    322323                if(_currentName && _currentName.length > 0){parameters["s1.name"] = _currentName;}
    323324                if(_currentMatch && _currentMatch.length > 0){parameters["s1.match"] = _currentMatch;}
     325                if(_currentXPath && _currentXPath.length > 0){parameters["s1.xpath"] = _currentXPath}
    324326
    325327                _saveButton.button("option", "disabled", true);
     
    610612            var templateListStart = templateResponse.indexOf("<templateList>") + "<templateList>".length;
    611613            var templateListEnd = templateResponse.indexOf("</templateList>");
     614           
     615            if(templateListStart == "<templateList>".length - 1)
     616            {
     617                return;
     618            }
     619           
    612620            var templateListString = templateResponse.substring(templateListStart, templateListEnd).replace(/&quot;/g, "\"");
    613621            var templateList = eval(templateListString);
     
    625633                var name = templateList[i].name;
    626634                var match = templateList[i].match;
     635                var xpath = templateList[i].xpath;
    627636
    628637                if(name)
     
    639648                _elements.push(infoContainer);
    640649
    641                 addChangeEventToInfoContainer(infoContainer, filename, location, nodename, namespace, name, match);
     650                addChangeEventToInfoContainer(infoContainer, filename, location, nodename, namespace, name, match, xpath);
    642651
    643652                if(name && name.length > 0)
    644653                {
    645                     infoContainer.text(name);
     654                    infoContainer.text(name + ((xpath) ? (" (" + xpath + ")") : ""));
    646655                }
    647656                if(match && match.length > 0)
    648657                {
    649                     infoContainer.text(match);
     658                    infoContainer.text(match + ((xpath) ? (" (" + xpath + ")") : ""));
    650659                }
    651660
     
    662671
    663672    //Change the current template in the XML and Visual editor
    664     this.changeCurrentTemplate = function(location, filename, nodename, namespace, name, match)
     673    this.changeCurrentTemplate = function(location, filename, nodename, namespace, name, match, xpath)
    665674    {
    666675        _currentFileName = filename;
     
    670679        _currentName = name;
    671680        _currentMatch = match;
    672    
     681        _currentXPath = xpath;
     682
    673683        var responseName = "requestedNameTemplate";
    674684
    675         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;
    676         if(match && match.length > 0){url += "&s1.match=" + match; responseName = "requestedMatchTemplate";}
    677         if(name && name.length > 0){url += "&s1.name=" + name;}
    678 
    679         $.ajax(url)
     685        var url = gs.xsltParams.library_name;
     686        var params = {"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};
     687
     688        if(match && match.length > 0){params["s1.match"] = match; responseName = "requestedMatchTemplate";}
     689        if(name && name.length > 0){params["s1.name"] = name;}
     690        if(xpath && xpath.length > 0){params["s1.xpath"] = xpath}
     691
     692        $.post(url, params)
    680693        .success(function(response)
    681694        {
     
    748761
    749762    //Store the function that is called when this template is selected from the list
    750     var addChangeEventToInfoContainer = function(infoContainer, filename, location, nodename, namespace, name, match)
     763    var addChangeEventToInfoContainer = function(infoContainer, filename, location, nodename, namespace, name, match, xpath)
    751764    {
    752765        infoContainer.data("changeFunction", function()
    753766        {
    754             _greenbug.changeCurrentTemplate(location, filename, nodename, namespace, name, match);
     767            _greenbug.changeCurrentTemplate(location, filename, nodename, namespace, name, match, xpath);
    755768        });
    756769    }
     
    864877                    var name = $(this).attr("name");
    865878                    var match = $(this).attr("match");
     879                    var xpath = $(this).attr("xpath");
    866880
    867881                    var file = _greenbug.fileNameToLocationAndName(filepath);
     
    871885                    _elements.push(infoContainer);
    872886
    873                     addChangeEventToInfoContainer(infoContainer, file.filename, file.location, nodename, namespace, name, match);
     887                    addChangeEventToInfoContainer(infoContainer, file.filename, file.location, nodename, namespace, name, match, xpath);
    874888
    875889                    if(name && name.length > 0)
    876890                    {
    877                         infoContainer.text(name);
     891                        infoContainer.text(name + ((xpath) ? (" (" + xpath + ")") : ""));
    878892                    }
    879893                    if(match && match.length > 0)
    880894                    {
    881                         infoContainer.text(match);
     895                        infoContainer.text(match + ((xpath) ? (" (" + xpath + ")") : ""));
    882896                    }
    883897
  • main/trunk/greenstone3/web/interfaces/default/js/javascript-global-functions.js

    r26431 r27713  
     1var SUCCESS = 1;
     2var ACCEPTED = 2;
     3var ERROR = 3;
     4var CONTINUING = 10;
     5var COMPLETED = 11;
     6var HALTED = 12;
     7
    18gs.functions = new Array();
    29
     
    93100}
    94101
     102gs.functions.checkForErrors = function(xml)
     103{
     104    var errorElems = xml.getElementsByTagName("error");
     105   
     106    if(errorElems && errorElems.length > 0)
     107    {
     108        var errorString = gs.text.dse.error_saving_changes + ": ";
     109        for(var i = 0; i < errorElems.length; i++)
     110        {
     111            errorString += " " + errorElems.item(i).firstChild.nodeValue;
     112        }
     113        alert(errorString);
     114        return true;
     115    }
     116    return false; //No errors
     117}
     118
     119gs.functions.validateXML = function(txt)
     120{
     121    // code for IE
     122    if (window.ActiveXObject)
     123    {
     124        var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
     125        xmlDoc.async = "false";
     126        xmlDoc.loadXML(document.all(txt).value);
     127
     128        if(xmlDoc.parseError.errorCode!=0)
     129        {
     130            txt = dse.error_code + ": " + xmlDoc.parseError.errorCode + "\n";
     131            txt = txt + dse.error_reason + ": " + xmlDoc.parseError.reason;
     132            txt = txt + dse.error_line + ": " + xmlDoc.parseError.line;
     133            console.log(txt);
     134            return null;
     135        }
     136       
     137        return xmlDoc;
     138    }
     139    // code for Mozilla, Firefox, Opera, etc.
     140    else if (document.implementation.createDocument)
     141    {
     142        var parser = new DOMParser();
     143        var xmlDoc = parser.parseFromString(txt,"text/xml");
     144
     145        if (xmlDoc.getElementsByTagName("parsererror").length > 0)
     146        {
     147            console.log(gs.text.dse.xml_error);
     148            return null;
     149        }
     150       
     151        return xmlDoc;
     152    }
     153    else
     154    {
     155        console.log(gs.text.dse.browse_cannot_validate_xml);
     156    }
     157    return null;
     158}
     159
    95160gs.functions.buildCollections = function(collections, finalFunction)
    96161{
     
    105170    {
    106171        var ajax = new gs.functions.ajaxRequest();
    107         ajax.open("GET", _baseURL + "?a=g&rt=r&ro=1&s=BuildCollection&s1.collection=" + collections[counter]);
     172        ajax.open("GET", gs.xsltParams.library_name + "?a=g&rt=r&ro=1&s=BuildCollection&s1.collection=" + collections[counter]);
    108173        ajax.onreadystatechange = function()
    109174        {
     
    111176            {
    112177                var text = ajax.responseText;
    113                 var xml = validateXML(text);
    114 
    115                 if(!xml || checkForErrors(xml))
     178                var xml = gs.functions.validateXML(text);
     179
     180                if(!xml || gs.functions.checkForErrors(xml))
    116181                {
    117182                    console.log("Could not build collection -> " + collections[counter] + ", aborting");
     
    122187                var pid = status.getAttribute("pid");
    123188
    124                 startCheckLoop(pid, "BuildCollection", function()
     189                gs.functions.startCheckLoop(pid, "BuildCollection", function()
    125190                {
    126191                    var localAjax = new gs.functions.ajaxRequest();
    127                     localAjax.open("GET", _baseURL + "?a=g&rt=r&ro=1&s=ActivateCollection&s1.collection=" + collections[counter], true);
     192                    localAjax.open("GET", gs.xsltParams.library_name + "?a=g&rt=r&ro=1&s=ActivateCollection&s1.collection=" + collections[counter], true);
    128193                    localAjax.onreadystatechange = function()
    129194                    {
     
    131196                        {
    132197                            var localText = localAjax.responseText;
    133                             var localXML = validateXML(localText);
     198                            var localXML = gs.functions.validateXML(localText);
    134199                           
    135                             if(!xml || checkForErrors(xml))
     200                            if(!xml || gs.functions.checkForErrors(xml))
    136201                            {
    137202                                console.log("Could not activate collection -> " + collections[counter] + ", aborting");
     
    143208                            {
    144209                                var localPID = localStatus.getAttribute("pid");
    145                                 startCheckLoop(localPID, "ActivateCollection", function()
     210                                gs.functions.startCheckLoop(localPID, "ActivateCollection", function()
    146211                                {
    147                                     if (++counter == _collections.length)
     212                                    if (++counter == collections.length)
    148213                                    {
    149214                                        //Run this function once we are done building all the collections
     
    167232}
    168233
    169 function startCheckLoop(pid, serverFunction, callbackFunction)
     234gs.functions.startCheckLoop = function(pid, serverFunction, callbackFunction)
    170235{
    171236    var ajaxFunction = function()
    172237    {
    173238        var ajax = new gs.functions.ajaxRequest();
    174         ajax.open("GET", _baseURL + "?a=g&rt=s&ro=1&s=" + serverFunction + "&s1.pid=" + pid, true);
     239        ajax.open("GET", gs.xsltParams.library_name + "?a=g&rt=s&ro=1&s=" + serverFunction + "&s1.pid=" + pid, true);
    175240        ajax.onreadystatechange = function()
    176241        {
     
    178243            {
    179244                var text = ajax.responseText;
    180                 var xml = validateXML(text);
     245                var xml = gs.functions.validateXML(text);
    181246               
    182                 if(!xml || checkForErrors(xml))
     247                if(!xml || gs.functions.checkForErrors(xml))
    183248                {
    184249                    console.log("Could not check status of " + serverFunction + ", there was an error in the XML, aborting");       
  • main/trunk/greenstone3/web/interfaces/default/js/visual-xml-editor.js

    r27256 r27713  
    11511151        {
    11521152            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)
     1153       
     1154            var successFunction = function(response)
    11551155            {
    11561156                var startIndex = response.indexOf("<requestedTemplate>") + ("<requestedTemplate>").length;
     
    11711171                    _greenbug.changeCurrentTemplate("interface", "gslib.xsl", "template", "xsl", _xmlNode.getAttribute("name"), null);
    11721172                }
    1173             });
     1173            }
     1174           
     1175            var errorFunction = function()
     1176            {
     1177                $.ajax(url).success(successFunction).error(errorFunction);
     1178            }
     1179           
     1180            $.ajax(url).success(successFunction).error(errorFunction);
    11741181        }
    11751182
Note: See TracChangeset for help on using the changeset viewer.