Changeset 221


Ignore:
Timestamp:
2008-05-13 15:20:08 (5 years ago)
Author:
idbr
Message:

Fixed forms sample

Location:
trunk/modules/kauri-forms/kauri-forms-framework/src/main/resources/KAURI-INF/js
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/resources/KAURI-INF/js/basics.js

    r220 r221  
    112112    } 
    113113 
    114     BooleanWidgetType.initialize = function(/* WidgetInstance */widgetInstance) 
     114    BooleanWidgetType.prototype.initialize = function(/* WidgetInstance */widgetInstance) 
    115115    { 
    116116        if (widgetInstance.getContainer().attr("type") != "checkbox") 
     
    123123 
    124124    // TODO we can probably just remove this... 
    125     BooleanWidgetType.configure = function(/* WidgetInstance */widgetInstance) 
     125    BooleanWidgetType.prototype.configure = function(/* WidgetInstance */widgetInstance) 
    126126    { 
    127127    } 
    128128 
    129     BooleanWidgetType.getValue = function(/* WidgetInstance */widgetInstance) 
     129    BooleanWidgetType.prototype.getValue = function(/* WidgetInstance */widgetInstance) 
    130130    { 
    131131        if (widgetInstance.getContainer().attr("checked") == true) 
     
    135135    } 
    136136 
    137     BooleanWidgetType.setValue = function(/* WidgetInstance */widgetInstance, value) 
     137    BooleanWidgetType.prototype.setValue = function(/* WidgetInstance */widgetInstance, value) 
    138138    { 
    139139        if (value == true || value == "true") 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/resources/KAURI-INF/js/composite.js

    r220 r221  
    145145    } 
    146146     
    147     CompositeWidgetType.setValue = function(/* WidgetInstance */widgetInstance, value) 
     147    CompositeWidgetType.prototype.setValue = function(/* WidgetInstance */widgetInstance, value) 
    148148    { 
    149149        var members = widgetInstance.getType().getMembers(); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/resources/KAURI-INF/js/field.js

    r220 r221  
    136136            return this; 
    137137        else 
    138         { 
     138        {    
     139             
    139140            // clone Type obj 
    140              var cloneType = $.extend({}, this); 
     141             //var cloneType = {}; 
     142             //$.extend(/*deep*/true, cloneType, this); 
     143            //TODO: check why extend doesn't work correctly 
     144             var cloneType = new cloneObject(this); 
    141145 
    142146            /* _DEV_ */kf.debug("extended type"); 
     
    184188    } 
    185189     
     190    function cloneObject(obj) 
     191    { 
     192        for (i in obj) 
     193        { 
     194            if (obj && obj.constructor == Array) 
     195            { 
     196                // Clone an array 
     197                var clone = []; 
     198                for ( var i = 0; i < obj.length; i++) 
     199                { 
     200                    clone[i] = obj[i]; 
     201                } 
     202                return clone; 
     203            } else if (typeof obj[i] == 'object') 
     204            { 
     205                this[i] = new cloneObject(obj[i]); 
     206            } else 
     207                this[i] = obj[i]; 
     208        } 
     209    } 
     210 
     211     
    186212    /** 
    187213     * FieldInstance controls... 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/resources/KAURI-INF/js/form.js

    r220 r221  
    1 /**   
    2  * @fileOverview This file holds the classes composing the actual Form structure. 
     1/** 
     2 * @fileOverview This file holds the classes composing the actual Form 
     3 *               structure. 
    34 */ 
    4 ;(function($){ 
    5     if (!$) throw "Kauri Form & Model requires jQuery"; 
    6     if (!$.org.kauriproject.forms) throw "Kauri Form & Model requires the kauri-form namespace"; 
    7      
    8     var kf =  $.org.kauriproject.forms; 
     5; 
     6( function($) 
     7{ 
     8    if (!$) 
     9        throw "Kauri Form & Model requires jQuery"; 
     10    if (!$.org.kauriproject.forms) 
     11        throw "Kauri Form & Model requires the kauri-form namespace"; 
     12 
     13    var kf = $.org.kauriproject.forms; 
    914 
    1015    $.extend(kf, { 
    11         Model: Model, 
    12         Form: Form  
    13     } ); 
     16        Model :Model, 
     17        Form :Form 
     18    }); 
    1419 
    1520    // TODO think and discuss about a good path location 
    1621    var REMOTE_WIDGET_PATH = "/kauri/forms/widgets/load_"; 
    1722    /* _DEV_ *//* for local test purpose */REMOTE_WIDGET_PATH = "../public/widgets/load_"; 
    18      
    19     // TODO more thinking for dynamic loaded fieltypes and validators (if needed)  
    20          
     23 
     24    // TODO more thinking for dynamic loaded fieltypes and validators (if 
     25    // needed) 
     26 
    2127    /** 
    2228     * Model holds and controlls ... 
    2329     *  
    2430     * TODO document 
    25      * 
     31     *  
    2632     *  
    2733     * @constructor 
     
    3743        this.validators = new kf.Registry("Registry for Local Validators", kf.validators); 
    3844    } 
    39      
    40     //TODO consider removing these add** methods in favour of direct calls to the registries... 
     45 
     46    // TODO consider removing these add** methods in favour of direct calls to 
     47    // the registries... 
    4148    Model.prototype.addWidgetType = function(/* String */name, /* WidgetDefinition */widgetType) 
    4249    { 
    4350        this.widgetTypes.put(widgetType, name); 
    4451    } 
    45      
     52 
    4653    Model.prototype.addFieldType = function(/* String */name, /* Type */type) 
    4754    { 
    4855        this.fieldTypes.put(type, name); 
    49         // todo check this was here before: needed?  
     56        // todo check this was here before: needed? 
    5057        // type._name = name; 
    5158    } 
    52      
     59 
    5360    Model.prototype.addValidator = function(/* String */name, /* function */validator) 
    5461    { 
    5562        this.validators.put(validator, name); 
    5663    } 
    57      
     64 
    5865    Model.prototype.setDatatype = function(/* Type */type) 
    5966    { 
    6067        this._datatype = type; 
    6168    } 
    62      
     69 
    6370    Model.prototype.getDatatype = function() 
    6471    { 
    6572        return this._datatype; 
    6673    } 
    67      
    68     //TODO consider removing these find** methods in favour of direct calls to the registries... 
     74 
     75    // TODO consider removing these find** methods in favour of direct calls to 
     76    // the registries... 
    6977    Model.prototype.findWidgetType = function(/* String */name) 
    7078    { 
    7179        return this.widgetTypes.get(name); 
    7280    } 
    73      
     81 
    7482    Model.prototype.findFieldType = function(/* String */name) 
    7583    { 
    7684        return this.fieldTypes.get(name); 
    7785    } 
    78      
     86 
    7987    Model.prototype.findValidator = function(/* String */name) 
    8088    { 
     
    8290    } 
    8391 
    84  
    85      
    86      
    8792    /** 
    8893     * Form holds and controlls.... 
     
    102107            alert("No correct container specified for form."); 
    103108        } 
    104      
     109 
    105110        this._widgetInstanceInventory = {}; 
    106      
     111 
    107112        this.formWidgetFQN = "form"; 
    108113    } 
    109      
     114 
    110115    /** 
    111116     * Finds a WidgetType by name. 
     
    117122    { 
    118123        var localType = this._model.findWidgetType(widgetDefinitionName); 
    119         if (localType) 
    120             return localType; 
    121         else 
    122             return kf.widgetTypes.get(widgetDefinitionName); 
    123     } 
    124      
    125     /** 
    126      * Finds a Type by name. 
     124        return localType; 
     125    } 
     126 
     127    /** 
     128     * Finds a FieldType by name. 
    127129     *  
    128130     * First search local reg, if nothing found, search global reg 
     131     *  
     132     * @type FieldType 
    129133     */ 
    130134    Form.prototype.findFieldType = function(/* String */typeName) 
    131135    { 
    132       var localType = this._model.findFieldType(typeName); 
    133       if (localType) 
    134           return localType; 
    135       else 
    136           return kf.fieldTypes.get(typeName); 
    137     } 
    138      
    139     /** 
    140      * Finds a Validation method by name. 
    141      *  
    142      * First search local reg, if nothing found, search global reg 
     136        var localType = this._model.findFieldType(typeName); 
     137        return localType; 
     138    } 
     139 
     140    /** 
     141     * Finds a Validator by name. 
     142     *  
     143     * First search local reg, if nothing found, search global reg * 
     144     *  
     145     * @type Validator 
    143146     */ 
    144147    Form.prototype.findValidator = function(/* String */validationName) 
     
    146149        return this._model.findValidator(validationName); 
    147150    } 
    148      
    149      
    150     //TODO describe/understand what this inventory is? 
    151     /** 
    152      * Finds a WidgetInstancein the widgetInstanceInventory by its fully qualified 
    153      * name. 
    154      *  
     151 
     152    // TODO describe/understand what this inventory is? 
     153    /** 
     154     * Finds a WidgetInstance in the widgetInstanceInventory by its fully 
     155     * qualified name. The purpose for this registry is widgetbinding. 
     156     *  
     157     * @type WidgetInstance 
    155158     */ 
    156159    Form.prototype.findWidgetInstance = function(/* String */widgetFQN) 
     
    158161        return this._widgetInstanceInventory[widgetFQN]; 
    159162    } 
    160      
     163 
    161164    /** 
    162165     * Adds a WidgetInstance to the widgetInstanceInventory 
     
    172175        } 
    173176    } 
    174      
     177 
    175178    /** 
    176179     * Creates a Member from a chunck of data. 
     
    183186        if (!memberdata.type) 
    184187            return kf.reportDesignError("Missing type for member '" + name + "'!"); 
    185      
     188 
    186189        var type = this.findFieldType(memberdata.type); 
    187190        if (!type) 
    188191            return kf.reportDesignError("Unknown type: '" + memberdata.type + "' for member '" + name + "'!"); 
    189      
     192 
    190193        // check if widget gets overridden 
    191194        var widgetType; 
     
    199202                        + widgetType.getName() + "'!"); 
    200203        } 
    201      
     204 
    202205        // parse validation rules 
    203206        var validationRules; 
     
    221224            } 
    222225        } 
    223      
     226 
    224227        // instantiate Member with possible extensions to type 
    225228        var member = new kf.FieldInstance(name, type.extend(widgetType, memberdata.options, undefined, validationRules, 
    226229                memberdata.validationTriggers), ((memberdata.label) ? memberdata.label : ""), 
    227230                ((memberdata.isCollection) ? memberdata.isCollection : false)); 
    228      
     231 
    229232        return member; 
    230233    } 
    231      
     234 
    232235    /** 
    233236     * Creates a Type from a chunck of data. 
     
    252255                return kf.reportDesignError("Type not found: '" + typedata.type + "'!"); 
    253256        } 
    254      
     257 
    255258        var widgetType; 
    256259        if (typedata.widget) 
     
    260263                return kf.reportDesignError("WidgetType not found: '" + typedata.widget + "'!"); 
    261264            if (!widgetType.isTypeCompatible(typedata.type)) 
    262                 return kf.reportDesignError("Type '" + typedata.type + "' is not compatible with widget '" 
    263                         + widgetType.getName() + "'!"); 
    264         } 
    265      
     265                return kf.reportDesignError("Type '" + typedata.type + "' is not compatible with widget '" + widgetType.getName() 
     266                        + "'!"); 
     267        } 
     268 
    266269        return type.extend(widgetType, typedata.options, {}, typedata.validations); 
    267270    } 
    268      
     271 
    269272    /** 
    270273     * Loads the model data and returns a Model 
    271274     *  
    272      * order of filling the regs is important: first custom widgets and validations, 
    273      * than the types 
     275     * order of filling the regs is important: first custom widgets and 
     276     * validations, than the types 
    274277     */ 
    275278    Form.prototype.loadModel = function(/* object */formmodeldata) 
    276279    { 
    277280        var model = this._model; 
    278      
     281 
    279282        // load local widget-definitions 
    280283        if (formmodeldata.widgets) 
     
    283286            { 
    284287                var widgetdata = formmodeldata.widgets[widgetname]; 
    285                 model.widgetTypes.put(  
    286                     new kf.WidgetType( 
    287                         widgetname,  
    288                         widgetdata.compatibleTypes, 
    289                         widgetdata.initFunction,  
    290                         widgetdata.configFunction,  
    291                         widgetdata.getValueFunction,  
    292                         widgetdata.setValueFunction, 
    293                         widgetdata.events 
    294                     ) 
    295                 ); 
    296             } 
    297         } 
    298      
     288                model.widgetTypes.put(new kf.WidgetType(widgetname, widgetdata.compatibleTypes, widgetdata.initFunction, 
     289                        widgetdata.configFunction, widgetdata.getValueFunction, widgetdata.setValueFunction, widgetdata.events)); 
     290            } 
     291        } 
     292 
    299293        // load local type-definitions 
    300294        if (formmodeldata.types) 
     
    303297            { 
    304298                var typedata = formmodeldata.types[typename]; 
    305                 model.fieldTypes.put(this.createType(typedata), typename ); 
    306             } 
    307         } 
    308      
     299                model.fieldTypes.put(this.createType(typedata), typename); 
     300            } 
     301        } 
     302 
    309303        // set base composite 
    310304        model.setDatatype(this.findFieldType(formmodeldata.datatype)); 
    311      
     305 
    312306        if (formmodeldata.getDataUri) 
    313307            model._getDataURI = new kauri.util.Template(formmodeldata.getDataUri); 
    314308        if (formmodeldata.putDataUri) 
    315309            model._putDataURI = new kauri.util.Template(formmodeldata.putDataUri); 
    316      
     310 
    317311        model._postDataURI = formmodeldata.postDataUri; 
    318      
     312 
    319313        return model; 
    320314    } 
    321      
     315 
    322316    /** 
    323317     * Initializes the form by instantiating the widgets and binding the submit 
     
    330324        this.addWidgetInstance(datatype.getWidgetType().createWidgetInstance(this.getContainer(), this, this.formWidgetFQN, 
    331325                datatype)); 
    332      
     326 
    333327        // configure widgets 
    334328        /* _DEV_ */kf.debug("Start config of all widgets"); 
    335329        this.findWidgetInstance(this.formWidgetFQN).configure(); 
    336330        /* _DEV_ */kf.debug("End config"); 
    337      
     331 
    338332        var form = this; 
    339333        $(".submit", this.getContainer()).click( function() 
     
    342336        }); 
    343337    } 
    344      
     338 
    345339    /** 
    346340     * Sets the data of the form by filling in all the widgets 
     
    359353        } 
    360354    } 
    361      
     355 
    362356    Form.prototype.setRemoteJsonData = function() 
    363357    { 
    364358        var form = this; 
    365         if (form._model._getDataURI && !(function(){for (var p in form._resourceIdObject){return false;} return true;}())) 
     359        if (form._model._getDataURI && !( function() 
     360        { 
     361            for ( var p in form._resourceIdObject) 
     362            { 
     363                return false; 
     364            } 
     365            return true; 
     366        }())) 
    366367        { 
    367368            $.getJSON(form._model._getDataURI.expand(this._resourceIdObject), function(data) 
     
    371372        } 
    372373    } 
    373      
     374 
    374375    Form.prototype.validate = function() 
    375376    { 
     
    379380        return valid; 
    380381    } 
    381      
     382 
    382383    Form.prototype.submit = function() 
    383384    { 
     
    387388            return; 
    388389        } 
    389      
     390 
    390391        // update data object 
    391392        var json = {}; 
     
    397398            json[formmembers[i].getName()] = widget.getValue(); 
    398399        } 
    399      
     400 
    400401        // post 
    401402        var postUrl; 
     
    404405        else 
    405406            postUrl = this._model._postDataURI; 
    406      
     407 
    407408        $.ajax( { 
    408409            type :"POST", 
     
    420421        }); 
    421422    } 
    422      
     423 
    423424    Form.prototype.getContainer = function() 
    424425    { 
Note: See TracChangeset for help on using the changeset viewer.