Changeset 1438


Ignore:
Timestamp:
2010-02-18 16:02:44 (3 years ago)
Author:
freya
Message:

first form builder changes: simplify lookup mechanism and use htmltemplates per role in controls

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

Legend:

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

    r1374 r1438  
    3535    * @type Object  
    3636    */ 
    37     InputControl.prototype.elements = {}; 
    38     $.extend(InputControl.prototype.elements, kf.Control.prototype.elements); 
    39     $.extend(InputControl.prototype.elements, { 
    40         input : { 
    41             create :"<input type='text'>", 
    42             select :":text,:password"  
    43         } 
     37    InputControl.prototype.templates = {}; 
     38    $.extend(InputControl.prototype.templates, kf.Control.prototype.templates); 
     39    $.extend(InputControl.prototype.templates, { 
     40           input:"<input type='text'/>" 
    4441    }); 
    4542 
     
    4845    * @param {Boolean} create Creates the elements if they don't exist yet 
    4946    */  
    50     InputControl.prototype.initElements = function( create) {  
     47    InputControl.prototype.initElements = function() {  
    5148    
    5249        var $input = this.getElement(); 
     50         
     51        var selector = "input"; 
     52        if(! $input){ 
     53            // does not contain an input element TODO check if this is OK 
     54            this.setElement("input", $(this.getTemplate('input'))); 
     55            $input = this.getElement(); 
     56        } 
     57        if(! $input.is(selector)){ 
     58            $input.html(this.getTemplate('input')); 
     59        } 
    5360         
    5461        //default  
     
    5663            this.password = false;  
    5764         
    58         if (!create && $input.attr('type') == 'password') {  
     65        if ($input.attr('type') == 'password') {  
    5966            this.password = true;  
    60         } else if ( (!create && !!this.password && ($input.attr('type') == 'text')) || (create && !!this.password) ){  
     67        } else if ( (!!this.password && ($input.attr('type') == 'text')) || (!!this.password) ){  
    6168            // change type to 'password' if it's set via config  
    6269            // type cannot be changed for newly created element, so it's cloned   
     
    110117    * @type Object  
    111118    */ 
    112     OutputControl.prototype.elements = {}; 
    113     $.extend(OutputControl.prototype.elements, kf.Control.prototype.elements); 
    114     $.extend(OutputControl.prototype.elements, { 
    115         input : { 
    116             create :"<span/>", 
    117             select :"span" 
    118         } 
     119    OutputControl.prototype.templates = {}; 
     120    $.extend(OutputControl.prototype.templates, kf.Control.prototype.templates); 
     121    $.extend(OutputControl.prototype.templates, { 
     122           input : "<span/>" 
    119123    }); 
    120124 
     
    123127    * @param {Boolean} create Creates the elements if they don't exist yet 
    124128    */  
    125     OutputControl.prototype.initElements = function( create) {  
     129    OutputControl.prototype.initElements = function( ) {  
    126130    
    127131        var $output = this.getElement(); 
     132        var selector = "span"; 
     133        if(! $output){ 
     134            // does not contain an input element TODO check if this is OK 
     135            this.setElement("input", $(this.getTemplate('input'))); 
     136            $output = this.getElement(); 
     137        } 
     138        if(! $output.is(selector)){ 
     139            $output.html(this.getTemplate('input')); 
     140        } 
    128141         
    129142        //default  
     
    168181 
    169182 
    170     CheckBoxControl.prototype.elements = {}; 
    171     $.extend(CheckBoxControl.prototype.elements, kf.Control.prototype.elements); 
    172     $.extend(CheckBoxControl.prototype.elements, { 
    173         input : { 
    174             create :"<input type='checkbox'>", 
    175             select :"input[type='checkbox']" 
    176         } 
     183    CheckBoxControl.prototype.templates = {}; 
     184    $.extend(CheckBoxControl.prototype.templates, kf.Control.prototype.templates); 
     185    $.extend(CheckBoxControl.prototype.templates, { 
     186           input : "<input type='checkbox'>" 
    177187    }); 
    178188 
    179189 
    180190    /** Specific control element initialisation */ 
    181     CheckBoxControl.prototype.initElements = function( create) { 
    182  
    183         var $input = this.getElement(); 
     191    CheckBoxControl.prototype.initElements = function( ) { 
     192 
     193        var $input = this.getElement(); 
     194         
     195        var selector = "input[type='checkbox']"; 
     196        if(! $input){ 
     197            // does not contain an input element TODO check if this is OK 
     198            this.setElement("input", $(this.getTemplate('input'))); 
     199            $input = this.getElement(); 
     200        } 
     201        if(! $input.is(selector)) 
     202            $input.html(this.getTemplate('input')); 
     203         
    184204        this._input = $input; 
    185205    } 
     
    226246    } 
    227247 
    228     SelectionControl.prototype.elements = {}; 
    229     $.extend(SelectionControl.prototype.elements, kf.Control.prototype.elements); 
    230     $.extend(SelectionControl.prototype.elements, { 
    231         input : { 
    232             create :"<select>", 
    233             select :"select" 
    234         }, 
    235         refresh : { 
    236             create :"<button class='refresh'>", 
    237             select :"button.refresh" 
    238         } 
     248    SelectionControl.prototype.templates = {}; 
     249    $.extend(SelectionControl.prototype.templates, kf.Control.prototype.templates); 
     250    $.extend(SelectionControl.prototype.templates, { 
     251           input : "<select kauri-role='input'>", 
     252           refresh: "<button class='refresh' kauri-role='refresh'>" 
    239253    }); 
    240254 
     
    243257     */ 
    244258    SelectionControl.prototype.options = {}; 
     259     
     260    SelectionControl.prototype.showRefresh = false; 
    245261 
    246262    /** Specific control element initialisation */ 
    247     SelectionControl.prototype.initElements = function( create) { 
     263    SelectionControl.prototype.initElements = function( ) { 
    248264        
    249265        var type = this.getType(); 
    250266        var $select = this.getElement(); 
    251  
    252         if (!create) { 
    253             // TODO read the options from the HTML - set them on the ready options object 
    254  
    255             // check multi-select and size: template setting overrides control-conf 
    256             type.multivalue = type.multivalue || !!$select.attr('multiple'); 
    257             this.size = this.size != undefined && this.size != 0 ? this.size : $select.attr('size'); 
    258         } 
     267         
     268        var selector = "select[kauri-role='input']"; 
     269        if(! $select){ 
     270            // does not contain an input element TODO check if this is OK 
     271            $select = $(this.getTemplate('input')) 
     272            this.setElement("input", $select); 
     273        } 
     274        if(! $select.is(selector)){ 
     275            $select.html(this.getTemplate('input')); 
     276            $select = $(selector,$select); 
     277            this.setElement("input", $select); 
     278        } 
     279        // TODO read the options from the HTML - set them on the ready options object 
     280        // check multi-select and size: template setting overrides control-conf 
     281        type.multivalue = type.multivalue || !!$select.attr('multiple'); 
     282        this.size = this.size != undefined && this.size != 0 ? this.size : $select.attr('size'); 
    259283 
    260284        // check multi-select and size 
     
    265289        if (options.refreshable()) { 
    266290            // find/create the refresh button 
    267             var $refresh = kf.ControlElements.lookup(this, kf.ControlElements.REV_REFRESH, create); 
     291            var $refresh = kf.ControlElements.lookup(this, kf.ControlElements.REV_REFRESH); 
     292             
     293            if(!$refresh && this.showRefresh){ 
     294                $(this.getTemplate("refresh")).insertAfter($select); 
     295                $refresh = $(":last-child",$refresh); 
     296            } 
    268297            if ($refresh) { 
    269298                $refresh.click( function(evt) { 
     
    282311    SelectionControl.prototype.initEventWiring = function() { 
    283312 
    284         var options = this.options; 
     313       var options = this.options; 
    285314        if (options.toShare() && options.initEventWiringDone) 
    286315            return; // no need to re-init shared options, avoiding multiple updates when one suffices 
     
    309338     */ 
    310339    SelectionControl.prototype.updateOptions = function( userValues, labels) { 
    311  
    312340        userValues = userValues || []; 
    313341        labels = labels || userValues; 
     
    323351        var last = userValues.length; 
    324352        for ( var i = 0; i < last; i++) { 
    325             $option = $("<option value='" + userValues[i] + "'>" + labels[i] + "</option>").appendTo($select); 
     353            $("<option value='" + userValues[i] + "'>" + labels[i] + "</option>").appendTo($select); 
    326354        } 
    327355 
     
    403431    } 
    404432 
    405     TextareaControl.prototype.elements = {}; 
    406     $.extend(TextareaControl.prototype.elements, kf.Control.prototype.elements); 
    407     $.extend(TextareaControl.prototype.elements, { 
    408         input : { 
    409             create :"<textarea/>", 
    410             select :"textarea" 
    411         } 
     433    TextareaControl.prototype.templates = {}; 
     434    $.extend(TextareaControl.prototype.templates, kf.Control.prototype.templates); 
     435    $.extend(TextareaControl.prototype.templates, { 
     436           input: "<textarea/>" 
    412437    }); 
    413438     
    414439    /** Specific control element initialisation */ 
    415     TextareaControl.prototype.initElements = function( create) { 
     440    TextareaControl.prototype.initElements = function( ) { 
    416441        var $textarea = this.getElement(); 
    417442 
     443        var selector = "textarea"; 
     444        if(! $textarea){ 
     445            // does not contain an input element TODO check if this is OK 
     446            this.setElement("input", $(this.getTemplate('input'))); 
     447            $textarea = this.getElement(); 
     448        } 
     449        if(! $textarea.is(selector)) 
     450            $textarea.html(this.getTemplate('input')); 
     451         
    418452        // defaults 
    419453        if (!this.cols) 
     
    425459        } 
    426460 
    427         if (!create) { 
     461 
    428462            ($textarea.attr('cols') != -1)? (this.cols = $textarea.attr('cols')) : $textarea.attr('cols', this.cols); 
    429463            ($textarea.attr('rows') != -1)? (this.rows = $textarea.attr('rows')) : $textarea.attr('rows', this.rows); 
     
    431465            // the only way to check this, is by using an attribute selector 
    432466            ($('textarea[readonly]' ,$('<div />').append($textarea.clone())).size() == 1)? (this.readonly = $textarea.attr('readonly')) : $textarea.attr('readonly', this.readonly);            
    433         } else { 
    434             this.cols && $textarea.attr('cols', this.cols); 
    435             this.rows && $textarea.attr('rows', this.rows); 
    436             this.readonly && $textarea.attr('readonly', this.readonly); 
    437         } 
    438467    } 
    439468     
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/case.js

    r1273 r1438  
    130130    } 
    131131     
    132     CaseControl.prototype.elements = {}; 
    133     $.extend(CaseControl.prototype.elements, kf.CompositeControl.prototype.elements); 
    134     $.extend(CaseControl.prototype.elements, {         
    135         layout : { 
    136             create : "<span/>" 
    137         } 
     132    CaseControl.prototype.templates = {}; 
     133    $.extend(CaseControl.prototype.templates, kf.CompositeControl.prototype.templates); 
     134    $.extend(CaseControl.prototype.templates, {         
     135        layout : "<span/>" 
    138136    }); 
    139137     
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/collection.js

    r1267 r1438  
    6161        this['<super.init>'](id, form, conf); 
    6262    } 
    63  
    64     CollectionControl.prototype.initElements = function( create) { 
     63    $.extend(CollectionControl.prototype.templates, { 
     64        layout: "<tr><td ><span kauri-role='label'/><span kauri-role='input'/><span kauri-role='messages'/></td></tr>", 
     65        container: "<table kauri-role='container'></table>" 
     66    }); 
     67     
     68    CollectionControl.prototype.initElements = function( ) { 
    6569        var me = this; 
    6670        var children = this._children = []; 
    6771 
    68         var addblock = kf.ControlElements.lookup(this, "add", create); 
     72        var addblock = kf.ControlElements.lookup(this, "add"); 
    6973        if (addblock) { 
    7074            addblock.click( function(evt) { 
     
    7882 
    7983        // sortable needs a class to identify the handle, so add one 
    80         var handleblock = kf.ControlElements.lookup(this, "handle", create); 
     84        var handleblock = kf.ControlElements.lookup(this, "handle"); 
    8185        if (handleblock) { 
    8286            handleblock.addClass("handleblock"); 
     
    215219 
    216220 
    217         // Make sure the item role is assoicated with the control 
     221        // Make sure the item role is associated with the control 
    218222        var $newItem = kf.ControlElements.lookup(childControl, "item", false); 
    219223 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/composite.js

    r804 r1438  
    7777    } 
    7878     
    79     CompositeControl.prototype.elements = {}; 
    80     $.extend(CompositeControl.prototype.elements, kf.AbstractContainerControl.prototype.elements); 
    81     $.extend(CompositeControl.prototype.elements, { 
    82         container : null, 
    83         layout : null 
     79    CompositeControl.prototype.templates = {}; 
     80    $.extend(CompositeControl.prototype.templates, kf.AbstractContainerControl.prototype.templates); 
     81    $.extend(CompositeControl.prototype.templates, { 
     82           container: "<dl kauri-role='container'></dl>", 
     83           layout: "<dt kauri-role='label'/><dd><span kauri-role='input'/><span kauri-role='messages'/></dd>"     
    8484    }); 
    8585 
    86     CompositeControl.prototype.initElements = function( create) { 
     86    CompositeControl.prototype.initElements = function( ) { 
    8787 
    8888        this._children = {}; 
     
    101101        if (!container) { 
    102102             throw "[CompositeControl#createChildElements] No container to work with.";            
    103         } else if (!container.is("dl")) { 
    104             container = $("<dl/>").appendTo(container); 
    105             this.setElement(kf.ControlElements.REV_CONTAINER, container); 
    106         } 
    107          
    108         // since there is no layout we will use our own default layout 
    109         var item = $("<dt kauri-role='label'/><dd kauri-role='item'/>").appendTo(container); 
     103        }  
     104        var item = $(this.getTemplate('layout')).appendTo(container); 
    110105        return item; 
    111106    } 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/control.js

    r1430 r1438  
    174174        // find all kauri-idref and kauri-role marked elements and index them 
    175175        var kauriSelector = "[" + ControlElements.ATTR_IDREF + "],[" + ControlElements.ATTR_REV + "]"; 
     176 
     177         
     178         
    176179        // begin by index space itself, 
    177180        if (space.is(kauriSelector))  
     
    184187 
    185188            return ($this.attr(ControlElements.ATTR_IDREF)!=undefined || revParents == null || revParents.length==0); 
    186         }); 
     189        });         
    187190        matching.each(indexor); 
    188191    } 
     
    242245    /** 
    243246     * Finds the element assigned to the identified control for a specific kauri-form-relation (functional role), and creates it if 
    244      * not found. 
     247     * not found. + Sets the element in the control 
    245248     * @param {Control} control 
    246249     * @param {String} relation What relation the element has with the control (input, message, ...) 
     
    249252     * @static 
    250253     */ 
    251     ControlElements.lookup = function(control, relation, create){ 
    252      
    253         create = create || false; 
    254          
     254    ControlElements.lookup = function(control, relation){ 
     255     
    255256        if (!relation)  
    256257            throw "[ControlElements#lookup] no relation specified."; 
     
    259260         
    260261        var elm = form.getElementIndex(index, relation); // if marked with kauri- attributes we should find it in the indexes 
    261         var $elm; 
    262          
    263         if (!elm) { // look it up in some parent using a specific selector 
    264             var lookupSpaces = form.getElementIndex(index) || []; 
    265             var lastSpace = lookupSpaces.length; 
     262        var $elm = null; 
     263         
     264        if (!elm) {  
     265            if(relation == ControlElements.REV_INPUT &&  form.getElementIndex(index).length == 1){ 
     266                elm = form.getElementIndex(index)[0]; 
    266267             
    267             var selector = control.getElementSelector(relation); 
    268             if (selector) { 
    269              
    270                 for (var i = 0; i < lastSpace; i++) { 
    271                     var space = lookupSpaces[i]; 
    272                     var $space = $(space); 
    273                     if ($space.is(selector)) { 
    274                         $elm = $space; 
    275                     } 
    276                     else { 
    277                         var found = $(selector, $space); 
    278                         if (found.size() > 0)  
    279                             // arbitrarily take first hit 
    280                             $elm = found.eq(0); 
    281                     } 
    282                 } 
    283             } 
    284              
    285             if (!$elm && lastSpace > 0 && create) { // still not found and a valid parent available, then consider creating: 
    286                 var creator = control.getCreateElement(relation); 
    287                 if (creator) { 
    288                     $elm = $(creator).appendTo($(lookupSpaces[0])); 
    289                     // TODO consider allowing pointers to "where" (relative to other elements) this new element should be added. 
    290                 } 
    291             } 
    292              
    293             if ($elm) { 
    294                 $elm.attr(ControlElements.ATTR_INDEX, index); 
    295                 $elm.attr(ControlElements.ATTR_REV, relation); 
    296                 elm = $elm.get(0); 
    297                 form.addElementIndex(index, relation, elm); 
     268                $elm = $(elm); 
     269                 
     270                if ($elm) { 
     271                    $elm.attr(ControlElements.ATTR_INDEX, index); 
     272                    $elm.attr(ControlElements.ATTR_REV, relation); 
     273                    elm = $elm.get(0); 
     274                    form.addElementIndex(index, relation, elm); 
     275                }  
    298276            } 
    299277        } 
     
    590568     
    591569    /** 
    592      * Holds the control-bound HTML elements per relation 
     570     * Holds the control-bound HTML templates per relation 
    593571     * @private 
    594572     */ 
    595     Control.prototype._elements; 
     573    Control.prototype._templates; 
    596574     
    597575    /**  
     
    599577     * @type Object 
    600578     */ 
    601     Control.prototype.elements = { 
    602         messages: { 
    603             create: "<span></span>" 
    604         } 
     579    Control.prototype.templates = { 
     580        messages: "<span></span>" 
    605581    }; 
    606582     
     
    630606     
    631607    /** 
    632      * Gets the element selector for an element with the specified relationship 
    633      * @param {String} relation The elements relationship with the control 
    634      * @return The element selector 
    635      * @type String 
    636      */ 
    637     Control.prototype.getElementSelector = function(relation){ 
    638      
    639         return this._getElementConfig(relation, 'select'); 
    640     } 
    641      
    642     /** 
    643      * Gets the create statement for an element with the specified relationship 
     608     * Gets the template for an element with the specified relationship 
    644609     * @param {String} relation The elements relationship with the control 
    645610     * @return The create statement 
    646611     * @type String 
    647612     */ 
    648     Control.prototype.getCreateElement = function(relation){ 
    649      
    650         return this._getElementConfig(relation, 'create'); 
    651     } 
    652      
     613    Control.prototype.getTemplate = function(relation){ 
     614        var templates = this.templates; 
     615        if (!templates)  
     616            return; 
     617        return templates[relation]; 
     618    } 
     619      
    653620    /** 
    654621     * Sets a html element (jQuery wrapped) for a specific relationship 
     
    674641            return; 
    675642        relation = relation || "input"; 
    676         return this._elements[relation]; 
     643         
     644        var $elements = this._elements[relation]; 
     645        return $elements; 
    677646    } 
    678647     
     
    716685     * @final To extend this behaviour for specific controls: override the initElements(create) method (no underscore). 
    717686     */ 
    718     Control.prototype._initElements = function(create){ 
    719      
    720         create = create || false; 
    721          
    722         var $input = ControlElements.lookup(this, ControlElements.REV_INPUT, create); 
    723         if (!create && !$input) { // 2nd attempt after switching to create mode. 
    724             create = true; 
    725             $input = ControlElements.lookup(this, ControlElements.REV_INPUT, create); 
    726         } 
    727          
    728         if (!$input)  
    729             throw "[Control#_initElements] Cannot continue without a proper input element for this control. (" + 
    730             this.getAbsoluteId() + 
    731             ")"; 
    732          
    733          
    734         // add events to the control: valueChanged, validationFinished 
    735         this._makeEventHandler("validationFinished"); 
    736         this._makeEventHandler("valueChanged"); 
     687    Control.prototype._initElements = function(){ 
     688    
     689        var $input = ControlElements.lookup(this, ControlElements.REV_INPUT); 
    737690         
    738691        // Sets a label in the label element. 
     
    740693        // In that case no default creation will happen! (additional requirement for element creation) 
    741694        // But if a label is specifief in the template, then that takes precendence over what is in the fconf 
    742         var labelCreate = create && (this.label != undefined);         
    743         var $lbl = ControlElements.lookup(this, ControlElements.REV_LABEL, labelCreate); 
     695        var $lbl = ControlElements.lookup(this, ControlElements.REV_LABEL); 
     696         
     697        var $mark = ControlElements.lookup(this, ControlElements.REV_MARK); 
     698        if (!$mark)  
     699            this.setElement(ControlElements.REV_MARK, $input); // by default the input element doubles as marking 
     700        var $msg = ControlElements.lookup(this, ControlElements.REV_MESSAGES); 
     701 
     702        // add events to the control: valueChanged, validationFinished 
     703        this._makeEventHandler("validationFinished"); 
     704        this._makeEventHandler("valueChanged"); 
     705         
    744706        if ($lbl && $lbl[0].childNodes.length == 0) { 
    745707            var label = this.label != null ? this.label : this.getId(); 
     
    747709        } 
    748710         
    749         var $mark = ControlElements.lookup(this, ControlElements.REV_MARK, create); 
    750         if (!$mark)  
    751             this.setElement(ControlElements.REV_MARK, $input); // by default the input element doubles as marking 
    752         var $msg = ControlElements.lookup(this, ControlElements.REV_MESSAGES, create); 
    753          
    754711        // allow control-specific initialization of containment elements 
    755         this.initContainerElements(create); 
     712        this.initContainerElements(); 
    756713         
    757714        //initialize options 
    758         this.initOptions(create); 
     715        this.initOptions(); 
    759716         
    760717        // allow control-specific initialization of specific functional elements 
    761         this.initElements(create); 
     718        this.initElements(); 
    762719    } 
    763720     
     
    849806     * @see #_initElements(create) 
    850807     */ 
    851     Control.prototype.initElements = function(create){ 
     808    Control.prototype.initElements = function(){ 
    852809     
    853810    } 
     
    15831540     * @type object 
    15841541     */ 
    1585     AbstractContainerControl.prototype.elements = {}; 
    1586     $.extend(AbstractContainerControl.prototype.elements, Control.prototype.elements); 
    1587     $.extend(AbstractContainerControl.prototype.elements, { 
    1588         input: { 
    1589             select: "div", 
    1590             create: "<div></div>" 
    1591         }, 
    1592         layout: { 
    1593             create: "<div><span kauri-role='label'/></div>" 
    1594         } 
     1542    AbstractContainerControl.prototype.templates = {}; 
     1543    $.extend(AbstractContainerControl.prototype.templates, Control.prototype.templates); 
     1544    $.extend(AbstractContainerControl.prototype.templates, { 
     1545        input: "<div><span kauri-role='label'/><span kauri-role='input'/><span kauri-role='messages'/></div>", 
     1546        layout: "<div><span kauri-role='label'/><span kauri-role='input'/><span kauri-role='messages'/></div>", 
     1547        container: "<div kauri-role='container'></div>" 
    15951548    }); 
    15961549     
     
    17921745    AbstractContainerControl.prototype.initContainerElements = function(create){ 
    17931746     
    1794         var container = ControlElements.lookup(this, ControlElements.REV_CONTAINER, create); 
    1795         if (!container) { // default to complete input space 
     1747        var container = ControlElements.lookup(this, ControlElements.REV_CONTAINER); 
     1748        var $container = $(container); 
     1749        if (!container) {  
     1750            var creator = this.getTemplate(ControlElements.REV_CONTAINER); 
     1751            if (creator) { 
     1752                $container = $(creator).appendTo($(this.getElement("input"))); 
     1753                this.setElement(ControlElements.REV_CONTAINER, $container); 
     1754            } 
     1755        } 
     1756 
     1757        if (!$container) { // default to complete input space  
    17961758            this.setElement(ControlElements.REV_CONTAINER, this.getElement("input")); 
    17971759        } 
    1798         var layout = ControlElements.lookup(this, ControlElements.REV_LAYOUT, create); 
     1760         
     1761        var layout = ControlElements.lookup(this, ControlElements.REV_LAYOUT); 
     1762        if (!layout) {  
     1763            var creator = this.getTemplate(ControlElements.REV_LAYOUT); 
     1764            if (creator) { 
     1765                $layout = $(creator).appendTo($container); 
     1766                this.setElement(ControlElements.REV_LAYOUT, $layout); 
     1767            } 
     1768        } 
     1769 
    17991770        if (layout) { 
    18001771            layout.hide(); 
     
    18291800        var container = this.getElement(ControlElements.REV_CONTAINER); 
    18301801        var layout = this.getElement(ControlElements.REV_LAYOUT); 
     1802         
    18311803        var newElements 
    18321804        if (!(container && layout)) { 
     
    18341806        } 
    18351807        else { 
     1808            // there is a container and there is a layout 
    18361809            var childAtPosition = null; 
    18371810            if (position != undefined && (typeof position == "number")) { 
    18381811                childAtPosition = container.children(":nth-child(" + (position + 1) + ")"); 
    18391812            } 
     1813            var $layout = layout.clone(); 
     1814            if($layout.length>1){ 
     1815                var $wrap = $("<span/>"); 
     1816                $wrap.append($layout); 
     1817                $layout = $wrap; 
     1818            } 
     1819 
    18401820            if (childAtPosition != null && childAtPosition.length == 1) { 
    1841                 newElements = layout.clone().insertBefore(childAtPosition[0]).show(); 
     1821                newElements = $layout.insertBefore(childAtPosition[0]).show(); 
    18421822            } else { 
    1843                 newElements = layout.clone().appendTo(container).show(); 
     1823                newElements = $layout.appendTo(container).show(); 
    18441824            } 
     1825             
    18451826            newElements.attr(ControlElements.ATTR_REV, ControlElements.REV_ITEM); 
    18461827        } 
    18471828         
    18481829        newElements.attr(ControlElements.ATTR_IDREF, id); 
     1830         
     1831         
    18491832         
    18501833        var form = this.getForm(); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/date.js

    r1299 r1438  
    189189            base :"wire-date", 
    190190            pattern :"dd/mm/yy" 
    191         } 
     191        }, 
     192         
     193        "short-date-range" : { 
     194            base :"wire-date-range", 
     195            pattern :"dd/mm/yy - dd/mm/yy" 
     196        } 
     197 
    192198    }); 
    193199     
     
    288294        "date-range" : { 
    289295            'base': "composite", 
     296            'user-format' :"short-date-range", 
    290297            'members' : { 
    291298                "start" : { base : "date"}, 
     
    317324    * @type Object  
    318325    */ 
    319     DateControl.prototype.elements = {}; 
    320     $.extend(DateControl.prototype.elements, kf.Control.prototype.elements); 
    321     $.extend(DateControl.prototype.elements, { 
    322         input : { 
    323             create :"<input type='text'>", 
    324             select :":text"  
    325         } 
     326    DateControl.prototype.templates = {}; 
     327    $.extend(DateControl.prototype.templates, kf.Control.prototype.templates); 
     328    $.extend(DateControl.prototype.templates, { 
     329           input :"<div><input type='text' kauri-role='input'/></div>" 
    326330    }); 
    327     DateControl.prototype.initElements = function (create) { 
     331    DateControl.prototype.initElements = function ( ) { 
    328332        var $input = this.getElement(); 
     333         
     334        var selector = "div > input"; 
     335        if(! $input){ 
     336            // does not contain an input element TODO check if this is OK 
     337            $input = $(this.getTemplate('input')) 
     338            this.setElement("input", $input); 
     339        } 
     340        if(! $input.is(selector)){ 
     341            $input.html(this.getTemplate('input')); 
     342            $input = $("div > input",$input); 
     343        } 
     344         
    329345        var type = this.getType(); 
    330346         
    331         if (!create) { 
    332             type.readonly = $input.attr("readonly"); 
    333         } else {             
    334             type.readonly && $input.attr("readonly", type.readonly); 
    335         } 
    336          
     347        type.readonly && $input.attr("readonly", type.readonly); 
    337348         
    338349        if (this.useDatePicker) { 
     
    342353                buttonImage: "javascript:void(0);", // the image will actually be set with css so just pass a dummy img src 
    343354                buttonImageOnly: true, 
    344                 buttonText: "choose a date", 
    345355                showOn: "button", 
    346356                yearRange: this.yearRange, 
    347357                rangeSelect: this.isRange 
     358                // the buttonText option is removed because is always shown (image is set by css and so the alt is always shown) 
    348359            }; 
    349360         
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/location.js

    r1221 r1438  
    4545    GMapControl.prototype.apiKey = "ABQIAAAAOLLfFZQRGe8Hwl8R-4_7ABTb-vLQlFZmc2N8bgWI8YDPp5FEVBRSxdJTJfWoHiTs2nyCjV6ZpIuHvA";  
    4646     
    47     GMapControl.prototype.elements = {}; 
    48     $.extend(GMapControl.prototype.elements, kf.AbstractContainerControl.prototype.elements); 
    49     $.extend(GMapControl.prototype.elements, { 
     47    GMapControl.prototype.templates = {}; 
     48    $.extend(GMapControl.prototype.templates, kf.AbstractContainerControl.prototype.templates); 
     49    $.extend(GMapControl.prototype.templates, { 
    5050        container : "<div/>"         
    5151    }); 
    5252     
    53     GMapControl.prototype.initElements = function( create) { 
     53    GMapControl.prototype.initElements = function( ) { 
    5454        var me = this; 
    5555        var container = this.getElement(kf.ControlElements.REV_CONTAINER); 
     
    8282                 
    8383                var val = me.getWireValue(); 
    84                 if (val.latitude != null && val.longitude != null && val.zoom != null) { 
     84                if (val && val.latitude != null && val.longitude != null && val.zoom != null) { 
    8585                    var mapVal = {latitude : new Number(val.latitude).valueOf(), longitude : new Number(val.longitude).valueOf(), zoom : new Number(val.zoom).valueOf()}; 
    8686                    me.setMapValue(mapVal);                     
     
    102102        this.valueChanged(function (evt) { 
    103103                var val = me.getWireValue(); 
    104                 if (val.latitude != null && val.longitude != null && val.zoom != null) { 
     104                if (val && val.latitude != null && val.longitude != null && val.zoom != null) { 
    105105                    var mapVal = {latitude : new Number(val.latitude).valueOf(), longitude : new Number(val.longitude).valueOf(), zoom : new Number(val.zoom).valueOf()}; 
    106106                    me.setMapValue(mapVal);                     
Note: See TracChangeset for help on using the changeset viewer.