Ignore:
Timestamp:
2013-03-21T16:52:48+13:00 (11 years ago)
Author:
sjm84
Message:

Some major improvements including the functionality to select arbitrary files to modify

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/js/visual-xml-editor.js

    r27072 r27110  
    66function visualXMLEditor(xmlString)
    77{
    8     var thisEditor = this;
     8    var _thisEditor = this;
     9    var _greenbug;
    910
    1011    var _globalID = 0;
     
    8990    };
    9091   
     92    this.setGreenbug = function(gb)
     93    {
     94        _greenbug = gb;
     95    }
     96   
    9197    this.getXML = function()
    9298    {
     
    243249    var retrieveGSLIBTemplates = function(callback)
    244250    {
    245         var url = gs.xsltParams.library_name + "?a=g&rt=r&s=GetGSLIBElementsFromFile&s1.interfaceName=" + gs.xsltParams.interface_name;
     251        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";
    246252
    247253        $.ajax(url)
     
    253259            var listString = response.substring(startIndex, endIndex);
    254260            var list = eval(listString.replace(/"/g, "\""));
    255            
    256             _elemList["gslib"] = list;
     261            var modifiedList = new Array();
     262           
     263            for(var i = 0; i < list.length; i++)
     264            {
     265                var current = list[i];
     266                if(current.name)
     267                {
     268                    modifiedList.push(current.name);
     269                }
     270            }
     271           
     272            _elemList["gslib"] = modifiedList;
    257273           
    258274            if(callback)
     
    569585   
    570586        var _textEditor = $("<div>");
    571         var _textTitle = $("<div>Text:</div>");
    572587        var _nodeText = $("<div>");
    573588        _nodeText.text(_xmlNode.nodeValue);
    574589
    575         _textEditor.append(_textTitle);
    576590        _textEditor.append(_nodeText);
    577591       
     
    10681082        this.populateInformationDiv = function()
    10691083        {
    1070             thisEditor.savePendingEdits();
     1084            _thisEditor.savePendingEdits();
    10711085            _infoDiv.empty();
    10721086
    1073             var nameElement = $("<p>");
    10741087            if(_xmlNode.nodeType == 1)
    10751088            {
    1076                 nameElement.text("Name: " + _xmlNode.nodeName);
     1089                var nameElementTitle = $("<div>", {"class":"ui-state-default ui-corner-all veInfoDivTitle"}).text("Element name:");
     1090                _infoDiv.append(nameElementTitle);
     1091                _infoDiv.append($("<p>").text(_xmlNode.nodeName));
    10771092            }
    10781093            else
    10791094            {
    1080                 nameElement.text("[text node]");
    1081             }
    1082             _infoDiv.append(nameElement);
     1095                var textElementTitle = $("<div>", {"class":"ui-state-default ui-corner-all veInfoDivTitle"}).text("Text node:");
     1096                _infoDiv.append(textElementTitle);
     1097            }
    10831098
    10841099            if(_xmlNode.nodeType == 1)
    10851100            {
    1086                 var attributeTableTitle = $("<p>Attributes:<p/>");
     1101                var attributeTableTitle = $("<div>", {"class":"ui-state-default ui-corner-all veInfoDivTitle"});
     1102                attributeTableTitle.text("Attributes:");
    10871103                var attributeTable = $("<table>");
    10881104                attributeTable.addClass("veAttributeTableContainer");
     
    10991115                _infoDiv.append(attributeTable);
    11001116               
     1117                var addDiv = $("<div>", {"class":"veInfoDivTitle"});
    11011118                var addSelect = $("<select>");
    11021119                addSelect.append("<option>[blank]</option>", {value:"[blank]"});
     
    11491166                    _transactions.push({type:"addAttr", row:row})
    11501167                });
    1151                 _infoDiv.append(addSelect);
    1152                 _infoDiv.append(addButton);
     1168                addDiv.append(addSelect);
     1169                addDiv.append(addButton);
     1170                _infoDiv.append(addDiv);
    11531171                addButton.button();
     1172               
     1173                /*
     1174                if(_xmlNode.tagName == "xsl:call-template" && _xmlNode.getAttribute("name").length > 0)
     1175                {
     1176                    var extraOptionsTitle = $("<div>", {"class":"ui-state-default ui-corner-all veInfoDivTitle"}).text("Additional options:");
     1177                    var visitTemplateOption = $("<button>View called template</button>");
     1178                   
     1179                    _infoDiv.append(extraOptionsTitle);
     1180                    _infoDiv.append(visitTemplateOption);
     1181                   
     1182                    visitTemplateOption.button();
     1183                    visitTemplateOption.click(function()
     1184                    {
     1185                        var template = "";
     1186                        template += '<xsl:template match="/">';
     1187                        template +=   '<calledTemplate>';
     1188                        var params = $(_xmlNode).children("xsl\\:with-param");
     1189                        if(!params.length)
     1190                        {
     1191                            template += '<xsl:call-template name="' + _xmlNode.getAttribute("name") + '"/>';
     1192                        }
     1193                        else
     1194                        {
     1195                            template += '<xsl:call-template name="' + _xmlNode.getAttribute("name") + '">';
     1196                            for(var i = 0; i < params.length; i++)
     1197                            {
     1198                                var param = params.eq(i);
     1199                                template += "<xsl:with-param";
     1200                                for(var j = 0; j < param[0].attributes.length; j++)
     1201                                {
     1202                                    var attr = param[0].attributes[j];
     1203                                    template += " " + attr.name + "=\"" + attr.value + "\"";
     1204                                }
     1205                                template += "/>";
     1206                            }
     1207                            template += '</xsl:call-template>';
     1208                        }
     1209                        template +=   '</calledTemplate>';
     1210                        template += '</xsl:template>';
     1211                        template = template.replace(" ", "%20");
     1212                       
     1213                        var url = document.URL;
     1214                        if(url.indexOf("?") == url.length - 1)
     1215                        {
     1216                            url += "ilt=" + template;
     1217                        }
     1218                        else if(url.indexOf("?") != -1)
     1219                        {
     1220                            url += "&ilt=" + template;
     1221                        }
     1222                        else
     1223                        {
     1224                            url += "?ilt=" + template;
     1225                        }
     1226                       
     1227                        $.ajax(url)
     1228                        .success(function(response)
     1229                        {
     1230                            var xml = $.parseXML(response);
     1231                            var debug = $(xml).find("calledTemplate debug");
     1232
     1233                            _greenbug.changeCurrentTemplate(debug[0].getAttribute("filename"), "template", "xsl", debug[0].getAttribute("name"), null);
     1234                            $(".gbTemplateContainer").css("border", "1px dashed #AAAAAA");
     1235                        });
     1236                    });
     1237                }
     1238                */
    11541239            }
    11551240
     
    11591244                _infoDiv.append(textNode.getDiv());
    11601245            }
    1161         }
    1162        
    1163         this.remove = function()
    1164         {
    1165             var divParent = _div.parents(".veElement");
    1166             _transactions.push({type:"remMvElem", vElemParent:_div.parent(), vElemPos:_div.index(), vElem:_div});
    1167             _div.data("expanded", "normal");
    1168             $(_xmlNode).remove();
    1169             _div.detach();
    1170             _infoDiv.empty();
    1171            
    1172             if(divParent.length)
    1173             {
    1174                 divParent.first().trigger("click");
    1175             }
    1176            
    1177             $("#veTrash").children("img").attr("src", gs.imageURLs.trashFull);
    11781246        }
    11791247
     
    12471315            return false;
    12481316        }
     1317       
     1318        this.remove = function()
     1319        {
     1320            var divParent = _div.parents(".veElement");
     1321            _transactions.push({type:"remMvElem", vElemParent:_div.parent(), vElemPos:_div.index(), vElem:_div});
     1322            _div.data("expanded", "normal");
     1323            $(_xmlNode).remove();
     1324            _div.detach();
     1325            _infoDiv.empty();
     1326           
     1327            if(divParent.length)
     1328            {
     1329                divParent.first().trigger("click");
     1330            }
     1331           
     1332            $("#veTrash").children("img").attr("src", gs.imageURLs.trashFull);
     1333        }
    12491334
    12501335        this.expand = function()
Note: See TracChangeset for help on using the changeset viewer.