Changeset 1441


Ignore:
Timestamp:
2010-02-19 16:14:07 (2 years ago)
Author:
freya
Message:

put jquery wrappers in elementindex / no more need to wrap layout templates in a unnecessary span-element
for stable version, please stick to revision 1433

Location:
trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/collection.js

    r1438 r1441  
    6262    } 
    6363    $.extend(CollectionControl.prototype.templates, { 
    64         layout: "<tr><td ><span kauri-role='label'/><span kauri-role='input'/><span kauri-role='messages'/></td></tr>", 
     64        layout: "<tr><td ><span kauri-role='label'/><span kauri-role='input'/><span kauri-role='messages'/><span kauri-role='delete'/></td></tr>", 
    6565        container: "<table kauri-role='container'></table>" 
    6666    }); 
     
    220220 
    221221        // Make sure the item role is associated with the control 
    222         var $newItem = kf.ControlElements.lookup(childControl, "item", false); 
     222        var $newItem = kf.ControlElements.lookup(childControl, kf.ControlElements.REV_ITEM, false); 
    223223 
    224224        // If the new item contains an element with delete role, add event handler to it 
     
    254254 
    255255        // remove it from the page 
    256         child.getElement("item").remove(); 
     256        child.getElement(kf.ControlElements.REV_ITEM).remove(); 
    257257 
    258258        // clear the index 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/control.js

    r1438 r1441  
    146146        forceReIndexing = forceReIndexing || false; 
    147147         
    148         var indexor = function(i){ 
     148        var indexor = function(index){ 
    149149         
    150150            var $this = $(this); 
     
    164164            var rev = $this.attr(ControlElements.ATTR_REV); 
    165165             
    166             store.addElementIndex(index, rev, this); 
     166            store.addElementIndex(index, rev, $this); 
    167167             
    168168            //add type property if known 
     
    171171            $this.attr(ControlElements.ATTR_INDEX, index); 
    172172        }; 
     173 
     174        var wrapIndexor = function($wrap){ 
     175            //var $first = $($eltArray[0]); 
     176            index = "";  
     177            var idref = $wrap.attr(ControlElements.ATTR_IDREF) || ""; 
     178            if (idref.length == 0 || idref.charAt(0) != '/')  
     179                index = $wrap.parents("[" + ControlElements.ATTR_INDEX + "]:first").attr(ControlElements.ATTR_INDEX); 
     180            if (idref) { 
     181                index = $.concatPath(index, idref); 
     182                 
     183            } 
     184             
     185            var rev = $wrap.attr(ControlElements.ATTR_REV); 
     186             
     187            store.addElementIndex(index, rev, $wrap.children()); 
     188             
     189            //add type property if known 
     190          //  store.addTypeAndControl(index, $elt.attr(ControlElements.ATTR_TYPE), $this.attr(ControlElements.ATTR_CONTROL)); 
     191 
     192            $wrap.attr(ControlElements.ATTR_INDEX, index); 
     193        }; 
    173194         
    174195        // find all kauri-idref and kauri-role marked elements and index them 
     
    180201        if (space.is(kauriSelector))  
    181202            space.each(indexor); 
    182         // then go through matching children, but only once (even if they match multiple times) 
     203            // then go through matching children, but only once (even if they match multiple times) 
    183204        var matching = $($.unique($(kauriSelector, space))).filter(function(){ 
    184205            // TODO should we do this this way or should be traverse the tree ourselves (performance?) 
     
    187208 
    188209            return ($this.attr(ControlElements.ATTR_IDREF)!=undefined || revParents == null || revParents.length==0); 
    189         });         
     210        });    
     211     
    190212        matching.each(indexor); 
    191213    } 
     214     
    192215     
    193216     
     
    259282        var index = control.getAbsoluteId(); 
    260283         
    261         var elm = form.getElementIndex(index, relation); // if marked with kauri- attributes we should find it in the indexes 
    262         var $elm = null; 
    263          
    264         if (!elm) {  
     284        var $elm = form.getElementIndex(index, relation); // if marked with kauri- attributes we should find it in the indexes 
     285         
     286         
     287        if (!$elm) {  
    265288            if(relation == ControlElements.REV_INPUT &&  form.getElementIndex(index).length == 1){ 
    266                 elm = form.getElementIndex(index)[0]; 
     289                $elm = form.getElementIndex(index)[0]; 
    267290             
    268                 $elm = $(elm); 
     291             
    269292                 
    270293                if ($elm) { 
    271294                    $elm.attr(ControlElements.ATTR_INDEX, index); 
    272295                    $elm.attr(ControlElements.ATTR_REV, relation); 
    273                     elm = $elm.get(0); 
    274                     form.addElementIndex(index, relation, elm); 
     296                    form.addElementIndex(index, relation, $elm); 
    275297                }  
    276298            } 
    277299        } 
    278         else { 
    279             $elm = $(elm); 
    280         } 
    281          
    282         if (elm)  
     300        
     301        if ($elm)  
    283302            control.setElement(relation, $elm); 
    284303        return $elm; 
     
    447466        } 
    448467         
     468        var $elm = $(elm); 
     469 
     470         
    449471        return this._operateIndex(index, relation, function(i){ 
    450472         
     
    454476            this.elementIndex[i] = elms; 
    455477        }, function(i, r){ 
    456          
    457478            var elms = this.elementIndex[i] = this.elementIndex[i] || ControlElements.newElements(); 
    458479            if (elms.meta[r])  
    459480                throw "[ControlElements#addElementIndex] index already in use: " + i + "#" + r; 
     481             
    460482            elms.meta[r] = elm; 
    461483            if (r == ControlElements.REV_ITEM) {// special case: items double as lookup-spaces! 
     
    480502            return this.elementIndex; 
    481503         
     504        var $elm; 
    482505        return this._operateIndex(index, relation, function(i){ 
    483          
    484             return this.elementIndex[i]; 
     506            $elm = this.elementIndex[i]; 
     507            return $elm; 
    485508        }, function(i, r){ 
    486509         
    487510            this.elementIndex[i] = this.elementIndex[i] || ControlElements.newElements(); 
    488             return this.elementIndex[i].meta[r]; 
     511            $elm = this.elementIndex[i].meta[r]; 
     512            return $elm; 
    489513        }); 
    490514    } 
     
    692716        // If no label is found then the control id will be used instead.   
    693717        // In that case no default creation will happen! (additional requirement for element creation) 
    694         // But if a label is specifief in the template, then that takes precendence over what is in the fconf 
     718        // But if a label is specified in the template, then that takes precendence over what is in the fconf 
    695719        var $lbl = ControlElements.lookup(this, ControlElements.REV_LABEL); 
    696720         
     
    17681792        } 
    17691793 
    1770         if (layout) { 
     1794       /* if (layout) { 
    17711795            layout.hide(); 
    1772         } 
     1796        }*/ 
    17731797    } 
    17741798     
     
    18121836            } 
    18131837            var $layout = layout.clone(); 
    1814             if($layout.length>1){ 
    1815                 var $wrap = $("<span/>"); 
    1816                 $wrap.append($layout); 
    1817                 $layout = $wrap; 
    1818             } 
    18191838 
    18201839            if (childAtPosition != null && childAtPosition.length == 1) { 
     
    18241843            } 
    18251844             
    1826             newElements.attr(ControlElements.ATTR_REV, ControlElements.REV_ITEM); 
     1845             
     1846            //newElements.attr(ControlElements.ATTR_REV, ControlElements.REV_ITEM); 
     1847 
     1848            if(true){ 
     1849                // hier item index berekenen en in elementindex steken 
     1850                // daarna gewoon de elemennten indexeren 
     1851                 
     1852                var idref = id; 
     1853                if (idref.length == 0 || idref.charAt(0) != '/')  
     1854                    index = newElements.parents("[" + ControlElements.ATTR_INDEX + "]:first").attr(ControlElements.ATTR_INDEX); 
     1855                if (idref) { 
     1856                    index = $.concatPath(index, idref); 
     1857                } 
     1858                 
     1859                this.getForm().addElementIndex(index, ControlElements.REV_ITEM, newElements); 
     1860                 
     1861/*                 
     1862                var $wrap = $("<kauri-layout/>"); 
     1863                $wrap.append(newElements.clone()); 
     1864 
     1865                $wrap.attr(ControlElements.ATTR_REV, ControlElements.REV_ITEM); 
     1866                $wrap.attr(ControlElements.ATTR_IDREF, id); 
     1867                //newElements = $wrap; 
     1868                var form = this.getForm(); 
     1869                ControlElements.index($wrap, form, true); 
     1870                return newElements;*/ 
     1871            } 
     1872 
    18271873        } 
    18281874         
    18291875        newElements.attr(ControlElements.ATTR_IDREF, id); 
    1830          
    1831          
    1832          
    18331876        var form = this.getForm(); 
    18341877        ControlElements.index(newElements, form, true); // we force re-indexing cause layout-template elements will already be 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/form.js

    r1414 r1441  
    154154            throw "[Form#setRootElement] Root element already set."; 
    155155        this.rootElement = elm; 
    156         this.addElementIndex("/", elm); 
     156        this.addElementIndex("/", $(elm)); 
    157157    } 
    158158 
Note: See TracChangeset for help on using the changeset viewer.