Ignore:
Timestamp:
2013-03-07T13:15:30+13:00 (11 years ago)
Author:
sjm84
Message:

Attributes to add can now be selected from a drop down list. Only works for gsf statements at the moment.

File:
1 edited

Legend:

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

    r27015 r27016  
    3636    var _transactions = new Array();
    3737   
     38    var _validAttrList =
     39    {
     40        gsf:
     41        {
     42            "cgi-param":["name"],
     43            "collectionText":["args", "name"],
     44            "displayItem":["name"],
     45            "displayText":["name"],
     46            "equivlinkgs3":["name"],
     47            "foreach-metadata":["name", "separator"],
     48            "icon":["type"],
     49            "if-metadata-exists":["name"],
     50            "image":["type"],
     51            "interfaceText":["name"],
     52            "link":["OID", "OIDmetadata", "name", "nodeID", "target", "title", "titlekey", "type"],
     53            "metadata":["format", "hidden", "name", "pos", "prefix", "separator", "suffix", "type"],
     54            "script":["src"],
     55            "style":["src"],
     56            "switch":["preprocess", "test", "test-value"]
     57        }
     58    }
     59   
     60    var _elemList =
     61    {
     62        html:["a", "br", "div", "li", "link", "p", "script", "span", "table", "td", "tr", "ul"],
     63        xsl:
     64        [
     65            "apply-imports", "apply-templates", "attribute", "attribute-set", "call-template",
     66            "choose", "copy", "copy-of", "decimal-format", "element",
     67            "fallback", "for-each", "if", "import", "include",
     68            "key", "message", "namespace-alias", "number", "otherwise",
     69            "output", "param", "preserve-space", "processing-instruction", "sort",
     70            "strip-space", "stylesheet", "template", "text", "transform",
     71            "value-of", "variable", "when", "with-param"
     72        ],
     73        gsf:
     74        [
     75            "cgi-param", "choose-metadata", "collectionText", "displayItem", "displayText",
     76            "equivlinkgs3", "foreach-metadata", "icon", "if-metadata-exists", "image",
     77            "interfaceText", "link", "meta-value", "metadata", "script",
     78            "style", "switch", "template", "text", "variable"
     79        ]
     80    };
     81   
    3882    var _childRestrictions =
    3983    {
     
    199243    var populateToolbar = function()
    200244    {
    201         var elemList =
    202         {
    203             html:["a", "br", "div", "li", "link", "p", "script", "span", "table", "td", "tr", "ul"],
    204             xsl:
    205             [
    206                 "apply-imports", "apply-templates", "attribute", "attribute-set", "call-template",
    207                 "choose", "copy", "copy-of", "decimal-format", "element",
    208                 "fallback", "for-each", "if", "import", "include",
    209                 "key", "message", "namespace-alias", "number", "otherwise",
    210                 "output", "param", "preserve-space", "processing-instruction", "sort",
    211                 "strip-space", "stylesheet", "template", "text", "transform",
    212                 "value-of", "variable", "when", "with-param"
    213             ],
    214             gsf:
    215             [
    216                 "cgi-param", "choose-metadata", "collectionText", "displayItem", "displayText",
    217                 "equivlinkgs3", "foreach-metadata", "icon", "if-metadata-exists", "image",
    218                 "interfaceText", "link", "meta-value", "metadata", "script",
    219                 "style", "switch", "template", "text", "variable"
    220             ]
    221         };
    222 
    223245        var tabHolder = $("<ul>");
    224246        _toolboxDiv.append(tabHolder);
    225247
    226         for(var key in elemList)
    227         {
    228             var currentList = elemList[key];
     248        for(var key in _elemList)
     249        {
     250            var currentList = _elemList[key];
    229251
    230252            var tab = $("<li>");
     
    675697        }
    676698       
    677         this.editMode = function()
     699        this.editMode = function(editValue)
    678700        {
    679701            _editingNodes.push(_thisAttr);
     
    704726            valueCell.append(valueInput);
    705727
    706             nameInput.focus();
     728            if(editValue)
     729            {
     730                valueInput.focus();
     731            }
     732            else
     733            {
     734                nameInput.focus();
     735            }
    707736        }
    708737       
     
    10221051                _infoDiv.append(attributeTable);
    10231052               
     1053                var addSelect = $("<select>");
     1054                addSelect.append("<option>[blank]</option>", {value:"[blank]"});
     1055                var fullName = _xmlNode.tagName;
     1056                var namespace;
     1057                var nodeName;
     1058                if(fullName.indexOf(":") == -1)
     1059                {
     1060                    namespace = "no namespace";
     1061                    nodeName = fullName;
     1062                }
     1063                else
     1064                {
     1065                    namespace = fullName.substring(0, fullName.indexOf(":"));
     1066                    nodeName = fullName.substring(fullName.indexOf(":") + 1);
     1067                }
     1068                var nameList = _validAttrList[namespace];
     1069                if(nameList)
     1070                {
     1071                    var nameList = _validAttrList[namespace];
     1072                    var attrList = nameList[nodeName];
     1073                    if(attrList)
     1074                    {
     1075                        for(var i = 0; i < attrList.length; i++)
     1076                        {
     1077                            addSelect.append($("<option>" + attrList[i] + "</option>", {value:attrList[i]}));
     1078                        }
     1079                    }
     1080                }
     1081               
    10241082                var addButton = $("<button>Add attribute</button>");
    10251083                addButton.click(function()
    10261084                {
    1027                     var newAtt = new VEAttribute(null, _xmlNode, "", "");
     1085                    var newAtt;
     1086                    var editModeValue;
     1087                    if(addSelect.find(":selected").val() == "[blank]")
     1088                    {
     1089                        newAtt = new VEAttribute(null, _xmlNode, "", "");
     1090                        editModeValue = false;
     1091                    }
     1092                    else
     1093                    {
     1094                        newAtt = new VEAttribute(null, _xmlNode, addSelect.find(":selected").val(), "");
     1095                        editModeValue = true;
     1096                    }
     1097 
    10281098                    var row = newAtt.getAsTableRow();
    10291099                    attributeTable.append(row);
    1030                     newAtt.editMode();
     1100                    newAtt.editMode(editModeValue);
    10311101                    _transactions.push({type:"addAttr", row:row})
    10321102                });
     1103                _infoDiv.append(addSelect);
    10331104                _infoDiv.append(addButton);
    10341105            }
Note: See TracChangeset for help on using the changeset viewer.