Changeset 1447


Ignore:
Timestamp:
2010-03-12 10:35:16 (2 years ago)
Author:
freya
Message:

Make use of container role for abstract container controls

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

Legend:

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

    r1446 r1447  
    3838    $.extend(InputControl.prototype.templates, kf.Control.prototype.templates); 
    3939    $.extend(InputControl.prototype.templates, { 
    40            input:"<input type='text' kauri-role='input'/>" 
     40           control:"<input type='text' kauri-role='input'/>" 
    4141    }); 
    4242 
     
    4747    InputControl.prototype.initElements = function() {  
    4848    
    49         var $input = this.getElement(); 
     49        var $input = this.getElement("input"); 
    5050         
    5151        var selector = "input"; 
    5252        if(! $input){ 
    5353            // does not contain an input element TODO check if this is OK 
    54             this.setElement("input", $(this.getTemplate('input'))); 
     54            this.setElement("input", $(this.getTemplate('control'))); 
    5555            $input = this.getElement(); 
    5656        } 
    5757        if(! $input.is(selector)){ 
    58             var $element = $(this.getTemplate('input'));  
    59  
    60             $input.each( function() { 
    61                 $.each(this.attributes, function(i, attrib) { 
    62                     var name = attrib.name; 
    63                     var value = attrib.value; 
    64                     if (!$element.attr(name)) { 
    65                         $element.attr(name, value); 
    66                     } 
    67                 }); 
    68             }); 
    69             $input.before($element).remove();  
     58            var $element = $(this.getTemplate('control')); 
     59            $element.attr('kauri-idref', $input.attr('kauri-idref')); 
     60            $input.before($element).remove(); 
     61            kf.ControlElements.index($element, this.getForm(), true); 
     62            this.setElement("input", $input); 
     63            // hier herindexeren 
    7064        } 
    7165         
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/collection.js

    r1446 r1447  
    6262    } 
    6363    $.extend(CollectionControl.prototype.templates, { 
    64         layout: "<tr><td ><span kauri-role='label'/><span kauri-role='input'/><span kauri-role='messages'/><span kauri-role='delete'/></td></tr>", 
    65         container: "<table kauri-role='container'></table>", 
    66         input: "<table kauri-role='input'></table>" 
     64        layout: "<tr><td ><span kauri-role='label'/><span kauri-role='control'/><span kauri-role='messages'/><span kauri-role='delete'/></td></tr>", 
     65        control: "<table kauri-role='container'></table>" 
    6766    }); 
    6867     
     
    9190 
    9291        var container = this.getElement(kf.ControlElements.REV_INPUT); 
    93         var layout = this.getElement(kf.ControlElements.REV_LAYOUT); 
    9492 
    9593        var el, startindex, stopindex; // local variables used in the nested functions 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/composite.js

    r1446 r1447  
    8080    $.extend(CompositeControl.prototype.templates, kf.AbstractContainerControl.prototype.templates); 
    8181    $.extend(CompositeControl.prototype.templates, { 
    82            input: "<dl kauri-role='input'></dl>", 
    83            layout: "<dt kauri-role='label'/><dd><span kauri-role='input'/><span kauri-role='messages'/></dd>", 
    84            "kauri-layout": "<dt kauri-role='label'/><dd><span kauri-role='input'/><span kauri-role='messages'/></dd>" 
     82           control: "<dl kauri-role='container'></dl>", 
     83           layout: "<dt kauri-role='label'/><dd><span kauri-role='control'/><span kauri-role='messages'/></dd>" 
     84            
    8585    }); 
    8686 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/control.js

    r1446 r1447  
    147147     
    148148 
     149    ControlElements.REV_CONTAINER = "container"; 
    149150    /** 
    150151     * TODO this one should be removed, it is remplaces by the kauri-layout attribute 
     
    152153     * @final 
    153154     */ 
    154     ControlElements.REV_CONTAINER = "container"; 
     155    ControlElements.REV_CONTROL = "control"; 
     156     
    155157    ControlElements.REV_LAYOUT = "layout"; 
    156158 
     
    200202             
    201203            var rev = $this.attr(ControlElements.ATTR_REV); 
     204            $this.attr(ControlElements.ATTR_INDEX, index); 
    202205            store.addElementIndex(index, rev, $this); 
    203206             
     
    205208            store.addTypeAndControl(index, $this.attr(ControlElements.ATTR_TYPE), $this.attr(ControlElements.ATTR_CONTROL)); 
    206209 
    207             $this.attr(ControlElements.ATTR_INDEX, index); 
     210             
    208211        }; 
    209212 
    210213        // find all kauri-idref and kauri-role marked elements and index them 
    211         var kauriSelector = "[" + ControlElements.ATTR_IDREF + "]"; 
     214        var kauriSelector = "[" + ControlElements.ATTR_IDREF + "],[" + ControlElements.ATTR_REV + "]"; 
    212215        var layoutSelector = "[kauri-layout]"; 
    213216         
     
    223226            return (revParents == null || revParents.length==0); 
    224227        });       
    225         $.unique($(kauriSelector, space)).each(indexor); 
     228        matching.each(indexor); 
    226229         
    227230         
     
    348351    } 
    349352 
     353     /** 
     354      * Finds the element assigned to the identified control for a specific kauri-form-relation (functional role), and creates it if 
     355      * not found. + Sets the element in the control 
     356      * @param {Control} control 
     357      * @param {String} relation What relation the element has with the control (input, message, ...) 
     358      * @param {Boolean} create Flag that indicates if an element should be created if not found 
     359      * @final 
     360      * @static 
     361      */ 
     362     ControlElements.removeRelationElement = function(control, relation){ 
     363      
     364         if (!relation)  
     365             throw "[ControlElements#lookup] no relation specified."; 
     366         var form = control.getForm(); 
     367         var index = control.getAbsoluteId(); 
     368          
     369         form.removeElementIndex(index, relation); 
     370         delete control._elements[relation]; 
     371     } 
     372 
    350373      
    351374     ControlElements.lookupLayout = function(control) { 
     
    553576        }, function(i, r){ 
    554577            var elms = this.elementIndex[i] = this.elementIndex[i] || ControlElements.newElements(); 
    555             if (elms.meta[r])  
    556                 throw "[ControlElements#addElementIndex] index already in use: " + i + "#" + r; 
     578           //TODO if (elms.meta[r])  
     579            //    throw "[ControlElements#addElementIndex] index already in use: " + i + "#" + r; 
    557580             
    558581            elms.meta[r] = elm; 
     
    590613    } 
    591614 
     615     /** 
     616      * Removes the specified element from the index. 
     617      * 
     618      * @param {string} 
     619      *            [index] index to remove 
     620      * @param {string} 
     621      *            [relation] relation-part to remove 
     622      */ 
     623     ControlElements.prototype.removeElementIndex = function(index, relation){ 
     624         if (index == undefined)  
     625             return; 
     626 
     627         if(! relation){ 
     628             delete this.elementIndex[index]; 
     629         } 
     630         if(this.elementIndex[index] && this.elementIndex[index].meta[relation]){ 
     631             delete this.elementIndex[index].meta[relation]; 
     632         } 
     633     } 
     634 
     635      
    592636     /** 
    593637      * Adds the specified element to the index. 
     
    879923    
    880924        var $input = ControlElements.lookup(this, ControlElements.REV_INPUT); 
    881          
     925        var $control = ControlElements.lookup(this, ControlElements.REV_CONTROL); 
     926 
     927        if($control) { 
     928            var $element = $(this.getTemplate(ControlElements.REV_CONTROL)); 
     929            $element.attr('kauri-idref', $control.attr('kauri-idref')); 
     930            $control.before($element).remove(); 
     931 
     932            this.setElement(ControlElements.REV_INPUT, $element); 
     933            ControlElements.removeRelationElement(this, ControlElements.REV_CONTROL); 
     934             
     935            ControlElements.index($element, this.getForm(), true); 
     936        } 
     937 
    882938        // Sets a label in the label element. 
    883939        // If no label is found then the control id will be used instead.   
     
    901957         
    902958        // allow control-specific initialization of containment elements 
    903         this.initContainerElements(); 
     959        this.initContainerElements(this.getParent() ? this.getParent().getElement() : this.getElement()); 
    904960         
    905961        //initialize options 
     
    9481004     * @see #_initElements(create) 
    9491005     */ 
    950     Control.prototype.initContainerElements = function(create){ 
     1006    Control.prototype.initContainerElements = function(container, create){ 
    9511007     
    9521008    } 
     
    19512007     
    19522008    /** 
    1953      * Initializes typical container elements 
     2009     * Initializes typical container elements: 
     2010     *     - set the container element on the control (so that children know where to attach) 
     2011     *     - check if there is a 'control' element and if so, replace it by the 'input' template 
    19542012     * @param {Boolean} create If true it will create the container elements if the don't already exist 
    19552013     * @private 
    19562014     */ 
    1957     AbstractContainerControl.prototype.initContainerElements = function(create){ 
    1958          var container = ControlElements.lookup(this, ControlElements.REV_INPUT); 
     2015    AbstractContainerControl.prototype.initContainerElements = function(container, create){ 
     2016         var id = this.getAbsoluteId(); 
     2017 
     2018         // check if there is an container-role element 
     2019         // if there is not, create one and append where 
    19592020          
     2021         var $input = ControlElements.lookup(this, ControlElements.REV_INPUT); 
     2022         var $container = ControlElements.lookup(this, ControlElements.REV_CONTAINER); 
    19602023          
    1961          // check if there is a layout attached to this element 
    1962          // if not,  switch the apply the input template from the control and append to the input container 
    1963          var id = this.getAbsoluteId(); 
    1964          if(!this.getForm().getLayoutIndex(id)){ 
    1965              var creator = this.getTemplate(ControlElements.REV_INPUT); 
     2024         if(!$container && !$input) { 
     2025             var $element = $(this.getTemplate(ControlElements.REV_CONTROL)); 
     2026              
     2027             $element.attr('kauri-idref', $input.attr('kauri-idref')); 
     2028             $input.before($element).remove(); 
     2029              
     2030             this.setElement(ControlElements.REV_CONTAINER, $element); 
     2031             ControlElements.index($input, this.getForm(), true); 
     2032         } 
     2033          
     2034         if (!$container) {  
     2035             this.setElement(ControlElements.REV_CONTAINER, $input); 
     2036         } 
     2037          
     2038         /*if(!container) { 
     2039             var creator = this.getTemplate(ControlElements.REV_CONTROL); 
    19662040             if (creator) { 
    19672041                 var form = this.getForm(); 
    1968                  var $input = $(creator); 
    1969                  $container = $input.appendTo(container); 
    1970                  this.setElement(ControlElements.REV_INPUT, $input); 
    1971              }     
    1972          } 
     2042                 var $control = $(creator); 
     2043                 var parentInput = this.getParent() ? this.getParent().getElement(ControlElements.REV_CONTAINER) : this.getElement(ControlElements.REV_INPUT); 
     2044                  
     2045                 var $container = $control.appendTo(parentInput); 
     2046                  
     2047                 if($container.attr(ControlElements.ATTR_IDREF)) 
     2048                     $container.attr(ControlElements.ATTR_IDREF, $container.attr(ControlElements.ATTR_IDREF) + "/" +id); 
     2049                 else 
     2050                     $container.attr(ControlElements.ATTR_IDREF,id); 
     2051                 this.setElement(ControlElements.REV_CONTAINER, $("[kauri-role="+ControlElements.REV_CONTAINER+"]",$control)); 
     2052                 ControlElements.index($control, this.getForm(), true); 
     2053             }   
     2054         }*/ 
    19732055          
    1974          var $container = $(container); 
    1975          if (!container) {  
    1976               
    1977          } 
    1978  
     2056        /* var control = ControlElements.lookup(this, ControlElements.REV_CONTROL); 
     2057         /* 
    19792058         if (!$container) { // default to complete input space  
    1980              this.setElement(ControlElements.REV_INPUT, this.getElement("input")); 
    1981          } 
     2059             this.setElement(ControlElements.REV_CONTROL, this.getElement("input")); 
     2060         }*/ 
    19822061    } 
    19832062     
     
    20032082     * @private 
    20042083     */ 
    2005     AbstractContainerControl.prototype._createChildElements = function(id, position) { 
     2084    AbstractContainerControl.prototype._createChildElements = function(id, position, container) { 
    20062085        var absoluteId = this.getAbsoluteId(); 
    20072086        var newIndex = $.concatPath(absoluteId, id); 
     
    20192098        var $layoutGroups = form.getLayoutIndex(groupId); 
    20202099 
    2021          
    2022         var copyIdRef = function(idx, elt){ 
     2100        var kauriSelector = "[kauri-role],[kauri-id]"; 
     2101        var setIdRef = function(idx, elt){ 
    20232102            var $elt = $(elt); 
    2024             if($elt.attr(ControlElements.ATTR_IDREF)) 
    2025                 $elt.attr(ControlElements.ATTR_IDREF, $elt.attr(ControlElements.ATTR_IDREF) + "/" +id); 
    2026             else 
     2103            if($elt.is(kauriSelector)){ 
    20272104                $elt.attr(ControlElements.ATTR_IDREF, id); 
     2105            } 
    20282106        }; 
    2029          
    20302107         
    20312108        if(!$layoutGroups) { 
     
    20352112            var $layout = $(this.getTemplate("layout")); 
    20362113             
    2037             $layout.each(copyIdRef); 
    2038              
    2039             $.each($("[kauri-role]", $layout), copyIdRef); 
    2040              
     2114            $layout.each(setIdRef); 
     2115            $.each($(kauriSelector, $layout), setIdRef); 
     2116 
    20412117            newElements = container.append($layout); 
    20422118            ControlElements.index($layout, form, true); 
     
    21172193            this.getAbsoluteId(); 
    21182194         
    2119         this._createChildElements(id, position); // ensure the needed html elements for this new child are available. 
     2195        this._createChildElements(id, position, this.getElement()); // ensure the needed html elements for this new child are available. 
    21202196        var me = this; 
    21212197        var form = this.getForm(); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/form.js

    r1446 r1447  
    346346    }); 
    347347 
     348    Form.prototype.templates = {}; 
     349    $.extend(Form.prototype.templates, kf.CompositeControl.prototype.templates); 
     350    $.extend(Form.prototype.templates, { 
     351        control: "<fieldset ><dl kauri-role='container'></dl></fieldset>" 
     352    }); 
    348353 
    349354    $.extend(kf, { 
Note: See TracChangeset for help on using the changeset viewer.