Changeset 1948


Ignore:
Timestamp:
2011-09-09 14:41:24 (8 months ago)
Author:
mpo
Message:

cleanup of code, mostly directed by jslint

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

Legend:

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

    r1920 r1948  
     1/*jslint eqeq: true */ 
    12/** 
    23 * @fileOverview This file holds some basic controltypes for standard forms. 
     
    56( function( $) { 
    67 
    7     if (!$) 
     8    if (!$) { 
    89        throw "Kauri Forms Basic-Controls requires jQuery"; 
    9     if (!$.org.kauriproject.forms) 
     10    } 
     11    if (!$.org.kauriproject.forms) { 
    1012        throw "Kauri Forms Basic-Controls requires the kauri-form namespace"; 
     13    } 
    1114 
    1215    var kp = $.org.kauriproject; 
     
    1720    // - textarea, choice, group-checkbox, images... 
    1821 
    19     $.inherit(InputControl, kf.Control); 
    2022    /** 
    2123     * @class Specific ControlType for simple character input-boxes. 
     
    3032        kf.Control.init(this, id, form, conf); 
    3133    } 
     34    $.inherit(InputControl, kf.Control); 
    3235 
    3336    /**  
     
    5154         
    5255        //default  
    53         if (!this.password)  
    54             this.password = false;  
     56        if (!this.password) { 
     57            this.password = false; 
     58        } 
    5559         
    5660        if ($input.attr('type') == 'password') {  
     
    6973            this.setElement( kf.ControlElements.REV_INPUT, $input);  
    7074        }  
    71     } 
     75    }; 
    7276     
    7377    /** 
     
    7983        var $input = this.getElement(); 
    8084        return $input.val(); 
    81     } 
     85    }; 
    8286    /** 
    8387     * Reads the value that was entered by the user. 
     
    8993        var $input = this.getElement(); 
    9094        $input.val(value); 
    91     } 
    92  
    93  
    94     // OutputControl - displays the value as text. 
    95     $.inherit(OutputControl, kf.Control); 
    96     /** 
     95    }; 
     96 
     97 
     98    /** 
     99     * OutputControl - displays the value as text. 
    97100     * @class Specific ControlType for simple output (wrapped in a <span/>) 
    98101     * @param {String} id  
     
    106109        kf.Control.init(this, id, form, conf); 
    107110    } 
     111    $.inherit(OutputControl, kf.Control); 
    108112 
    109113    /**  
     
    125129         
    126130        //default  
    127         if (!this.html)  
     131        if (!this.html) {  
    128132            this.html = false;  
    129          
    130     } 
     133        } 
     134         
     135    }; 
    131136     
    132137    /** 
     
    137142 
    138143        var $input = this.getElement(); 
    139         return $input[this.html?'html':'text'](value); 
    140     } 
     144        return $input[this.html?'html':'text'](); 
     145    }; 
    141146    /** 
    142147     * Reads the value that was entered by the user. 
     
    148153        var $input = this.getElement(); 
    149154        $input[this.html?'html':'text'](value); 
    150     } 
    151  
    152  
    153     $.inherit(CheckBoxControl, kf.Control); 
     155    }; 
     156 
    154157 
    155158    /** 
     
    163166        kf.Control.init(this, id, form, type); 
    164167    } 
     168    $.inherit(CheckBoxControl, kf.Control); 
    165169 
    166170 
     
    179183        this._input = $input; 
    180184        this.value = false;  
    181     } 
     185    }; 
    182186     
    183187 
     
    198202        } 
    199203 
    200     } 
     204    }; 
    201205     
    202206     
     
    207211     */ 
    208212    CheckBoxControl.prototype.normaliseValue = function (value) { 
    209         if (value && value.constructor == Boolean && typeof value === 'object') return value; // note Boolean object holding false would become true with !! operation 
     213        if (value && value.constructor == Boolean && typeof value === 'object') { return value; }// note Boolean object holding false would become true with !! operation 
    210214        return new Boolean(!!value); //anything becomes true, nothing or false becomes false 
    211     } 
     215    }; 
    212216 
    213217    CheckBoxControl.prototype.readUserValue = function() { 
    214218 
    215         if (this._input.attr("checked")) 
     219        if (this._input.attr("checked")) { 
    216220            return true; 
    217         else 
     221        } else{  
    218222            return false; 
    219     } 
     223        } 
     224    }; 
    220225 
    221226    CheckBoxControl.prototype.writeUserValue = function( value) { 
    222227 
    223         if (value == true || value == "true") 
     228        if (value == true || value == "true") { 
    224229            this._input.attr("checked", "checked"); 
    225         else 
     230        } else { 
    226231            this._input.removeAttr("checked"); 
    227     } 
    228  
    229  
    230     $.inherit(SelectionControl, kf.Control); 
    231  
    232     // TODO maybe look for wrapping a combobox control (combining selection with new entries) 
     232        } 
     233    }; 
     234 
     235 
     236 
    233237    /** 
    234238     * Specific ControlType for select-boxes with multiple options in a <select> 
     
    241245        kf.Control.init(this, id, form, type); 
    242246    } 
     247    $.inherit(SelectionControl, kf.Control); 
    243248 
    244249    SelectionControl.prototype.templates = {}; 
     
    301306            } 
    302307        } 
    303     } 
     308    }; 
    304309 
    305310 
     
    320325        // loop options from type and construct the inner HTML 
    321326        var last = userValues.length; 
    322         for ( var i = 0; i < last; i++) { 
     327        var i; 
     328        for ( i = 0; i < last; i++) { 
    323329            $("<option value='" + userValues[i] + "'>" + labels[i] + "</option>").appendTo($select); 
    324330        } 
     
    333339        // on IE we need to trigger repaint by 
    334340        $select.blur(); // calling blur 
    335     } 
     341    }; 
    336342 
    337343    /**  
     
    355361            // first fall-back: take the initial value if that is available in the options-list 
    356362            value = this.options.trimValues(this.initial.value);  
    357             if (value == undefined) 
     363            if (value == undefined) { 
    358364              value = values[0]; //final fall-back: pick the first value, since that is what the control will show anyway 
     365            } 
    359366        } 
    360367         
    361368        return value; 
    362     } 
     369    }; 
    363370     
    364371    SelectionControl.prototype.readUserValue = function() { 
     
    367374         
    368375        return $select.val(); 
    369     } 
     376    }; 
    370377 
    371378    SelectionControl.prototype.writeUserValue = function( value) { 
     
    374381         
    375382        if(value.constructor == Array){ 
    376             for(var v in value) 
     383            var v; 
     384            for(v in value) { 
    377385                value[v] = value[v].toString(); 
     386            } 
    378387            $select.val(value); 
    379388        }else 
    380389            $select.val(value.toString()); 
    381     } 
    382      
    383     $.inherit(TextareaControl, kf.Control); 
     390    }; 
     391     
    384392 
    385393    /** 
     
    393401        kf.Control.init(this, id, form, type); 
    394402    } 
     403    $.inherit(TextareaControl, kf.Control); 
    395404 
    396405    TextareaControl.prototype.templates = {}; 
     
    406415 
    407416        // defaults 
    408         if (!this.cols) 
     417        if (!this.cols) { 
    409418            this.cols = 22; 
    410         if (!this.rows) 
     419        } 
     420        if (!this.rows) { 
    411421            this.rows = 3; 
     422        } 
    412423        if (!this.readonly){ 
    413424            this.readonly = false; 
     
    422433        // the only way to check this, is by using an attribute selector 
    423434        ($('textarea[readonly]' ,$unselectableElement).size() == 1)? (this.readonly = $textarea.attr('readonly')) : $textarea.attr('readonly', this.readonly);            
    424     } 
     435    }; 
    425436     
    426437    TextareaControl.prototype.readUserValue = function() { 
    427438 
    428439        return this.getElement().val(); 
    429     } 
     440    }; 
    430441 
    431442    TextareaControl.prototype.writeUserValue = function( value) { 
     
    433444        value = value || ""; 
    434445        this.getElement().val(value); 
    435     } 
     446    }; 
    436447 
    437448    // adding the new types to the registry... 
     
    443454        "textarea-control" :TextareaControl 
    444455    }); 
    445  
    446 })(jQuery); 
     456}(jQuery)); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/basic-fields.js

    r1825 r1948  
     1/*jslint eqeq: true */ 
    12/** 
    23 * @fileOverview This file holds the basic structure of the fields composing the forms 
     
    56( function( $) { 
    67 
    7     if (!$) 
     8    if (!$) { 
    89        throw "Kauri Forms Fields requires jQuery"; 
    9     if (!$.org.kauriproject.forms) 
     10    } 
     11    if (!$.org.kauriproject.forms) { 
    1012        throw "Kauri Forms Fields requires the kauri-form namespace"; 
     13    } 
    1114 
    1215    var kf = $.org.kauriproject.forms; 
     
    4649            '+validators': { 'isUrl': {} } 
    4750        } 
    48  
    49  
    5051    }); 
    51  
    52 })(jQuery); 
     52}(jQuery)); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/basic-formatters.js

    r1917 r1948  
     1/*jslint eqeq: true */ 
    12/** 
    23 * @fileOverview This file holds the basic structure of the validation system 
     
    56( function( $) { 
    67 
    7     if (!$) 
     8    if (!$) { 
    89        throw "[basic-formatters.js] requires jQuery"; 
    9     if (!$.org.kauriproject.forms) 
     10    } 
     11    if (!$.org.kauriproject.forms) { 
    1012        throw "[basic-formatters.js] requires the kauri-form namespace"; 
     13    } 
    1114 
    1215    var kf = $.org.kauriproject.forms; 
     
    2225            format : function( val) { 
    2326 
    24                 if (val == undefined) 
     27                if (val == undefined) { 
    2528                    return ""; 
     29                } 
    2630                if (val.constructor != Boolean) { 
    2731                    this.fail("Not a valid boolean: {0}.", [ val ]); 
    2832                } 
    2933                 
    30                 if (this.asIs) return val; 
     34                if (this.asIs) { return val;}  
    3135 
    3236                return val.toString(); 
     
    3741                if (typeof valstr == 'string') { 
    3842                    valstr = $.trim(valstr); 
    39                     if (valstr.length == 0) 
     43                    if (valstr.length == 0) { 
    4044                        return undefined; 
     45                    } 
    4146                    var FALSE_REGEX = new RegExp("^false$", "ig"); 
    4247                    var match = FALSE_REGEX.test(valstr); 
    43                     if (match) 
     48                    if (match) { 
    4449                        return new Boolean(false); 
     50                    } 
    4551                } 
    4652                return new Boolean(valstr); 
     
    5662            format : function( val) { 
    5763 
    58                 if (val == undefined || val == null) 
     64                if (val == undefined || val == null) { 
    5965                    return ""; 
    60                 if (val.constructor != Number) 
     66                } 
     67                if (val.constructor != Number) { 
    6168                    this.fail("Not a valid number: {0}.", [ val ]); 
     69                } 
    6270 
    63                 if (this.asIs) return val; 
    64                 if (this.rawFormat) return "" + val.valueOf(); 
     71                if (this.asIs) { return val; } 
     72                if (this.rawFormat) { return "" + val.valueOf();} 
    6573                 
    6674                if(this.decimal){ 
     
    6977                    // no decimals wanted, skip the trailing zeros 
    7078                    var parts = val.toLocaleString().split($.getDecimalSeparator()); 
    71                     if(parts.length>1 && new Number(parts[1]) == 0) 
     79                    if(parts.length>1 && new Number(parts[1]) == 0) { 
    7280                        return parts[0]; 
    73                     else 
     81                    } else {  
    7482                        return val.toLocaleString(); 
     83                    } 
    7584                } 
    7685            }, 
     
    97106                    // replace decimal-separator with '.' 
    98107                    valstr = valstr.replace(decimalSep, "."); 
    99                     if (valstr.length == 0) 
     108                    if (valstr.length == 0) { 
    100109                        return undefined; 
     110                    } 
    101111                         
    102112                    valstr = valstr.replace(/\s/g,""); 
     
    105115                var val = (valstr == null) ? null : new Number(valstr); 
    106116                 
    107                 if (isNaN(val)) 
     117                if (isNaN(val)) { 
    108118                    this.fail("Not a valid number: {0}.", [ valstr ]); 
     119                } 
    109120 
    110121                return val; 
     
    116127            format : function( val) { 
    117128 
    118                 if (val == undefined) 
     129                if (val == undefined) { 
    119130                    return ""; 
     131                } 
    120132                val = val.toString(); 
    121133 
    122134                var last = this.pattern.length; 
    123135                var valstr = ""; 
    124                 var j = 0; 
    125                 for ( var i = 0; i < last; i++) { 
     136                var i = 0, j = 0; 
     137                for ( i = 0; i < last; i++) { 
    126138                    var c = this.pattern.charAt(i); 
    127139                    var k = c; 
    128140                    if (c == '$') { 
    129141                        k = val.charAt(j++); 
    130                         if (k == undefined || !k.match(/[a-z0-9]/i)) 
     142                        if (k == undefined || !k.match(/[a-z0-9]/i)) { 
    131143                            this.fail("Input {0} doesn't match pattern {1}. Expected alfanumeric (a-z0-9) at position {2}.", [ 
    132144                                    val, this.pattern, i ]); 
     145                        } 
    133146                    } else if (c == '#') { 
    134147                        k = val.charAt(j++); 
    135                         if (k == undefined || !k.match(/[0-9]/i)) 
     148                        if (k == undefined || !k.match(/[0-9]/i)) { 
    136149                            this.fail("Input {0} doesn't match pattern {1}. Expected digit (0-9) at position {2}.", [ val, 
    137150                                    this.pattern, i ]); 
     151                        } 
    138152                    } else if (c == "*") { 
    139153                        k = val.substr(j); 
     
    143157                } 
    144158 
    145                 if (j != val.length) 
     159                if (j != val.length) { 
    146160                    this.fail("Input {0} doesn't match pattern {1}. More characters then pattern can hold.", 
    147161                            [ val, this.pattern ]); 
     162                } 
    148163 
    149164                return valstr; 
     
    153168 
    154169                valstr = $.trim(valstr); 
    155                 if (valstr.length == 0) 
     170                if (valstr.length == 0) { 
    156171                    return undefined; 
     172                } 
    157173                valstr = valstr.replace(STRIP_REGEX, ""); 
    158174                return valstr; 
     
    162178    }); 
    163179 
    164 })(jQuery); 
     180}(jQuery)); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/basic-validators.js

    r1920 r1948  
     1/*jslint eqeq: true */ 
    12/** 
    23 * @fileOverview This file holds the basic structure of the validation system 
     
    56( function( $) { 
    67 
    7     if (!$) 
     8    if (!$) { 
    89        throw "[basic-validators.js] requires jQuery"; 
    9     if (!$.org.kauriproject.forms) 
     10    } 
     11    if (!$.org.kauriproject.forms) { 
    1012        throw "[basic-validators.js] requires the kauri-form namespace"; 
     13    } 
    1114 
    1215    var kp = $.org.kauriproject; 
     
    1821    // define re-useable regexes once 
    1922    // email regex from - http://www.regular-expressions.info/email.html 
    20     var EMAIL_REGEX = /^[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_\`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i; 
     23    var EMAIL_REGEX = /^[a-z0-9!#$%&\'*+\/=?\^_`{|}~\-]+(?:\.[a-z0-9!#$%&\'*+\/=?\^_\`{|}~\-]+)*@(?:[a-z0-9](?:[a-z0-9\-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9\-]*[a-z0-9])?$/i; 
    2124 
    2225    // uri regex from http://www.osix.net/modules/article/?id=586, 
    2326    // fixed to allow portnumbers of up to 5 digits 
    2427    // fixed to remove space after : between user:password. 
    25     var URI_REGEX = /^(https?|ftp):\/\/(([0-9a-z_!~*\'().&=+$%-]+:)?[0-9a-z_!~*\'().&=+$%-]+@)?(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z_!~*\'()-]+\.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.[a-z]{2,6})(:[0-9]{1,5})?((\/?)|(\/[0-9a-z_!~*\'().;?:@&=+$,%#-]+)+\/?)$/; 
     28    var URI_REGEX = /^(https?|ftp):\/\/(([0-9a-z_!~*\'().&=+$%\-]+:)?[0-9a-z_!~*\'().&=+$%\-]+@)?(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z_!~*\'()\-]+\.)*([0-9a-z][0-9a-z\-]{0,61})?[0-9a-z]\.[a-z]{2,6})(:[0-9]{1,5})?((\/?)|(\/[0-9a-z_!~*\'().;?:@&=+$,%#\-]+)+\/?)$/; 
    2629    // | scheme | :// | user:password @ | ip adrress | 3rd level domain 2nd level domain top level domain | :portnumber | path | 
    2730 
    2831    kf.Validator.validateInt = function(me, value) { 
    29         if (value == undefined) 
     32        if (value == undefined) { 
    3033            return me.notifySuccess(); 
    31  
    32         if (typeof value == 'number') 
     34        } 
     35 
     36        if (typeof value == 'number') { 
    3337            value = new Number(value); 
    34  
    35         if (value.constructor != Number || isNaN(value)) 
     38        } 
     39 
     40        if (value.constructor != Number || isNaN(value)) { 
    3641            return me.notifyFail("i18n:Not a number."); 
     42        } 
    3743 
    3844        var intValueStr = value.toFixed(0); 
    3945        var valueStr = value.toString(); 
    4046 
    41         if (intValueStr != valueStr) 
     47        if (intValueStr != valueStr) { 
    4248            return me.notifyFail("i18n:Not a valid integer!"); 
     49        } 
    4350 
    4451        return me.notifySuccess(); 
    45     } 
     52    }; 
    4653 
    4754    validators.putAll( { 
     
    6875            validate : function( value) { 
    6976 
    70                 if ($.isEmpty(value)) 
    71                     return this.notifySuccess(); 
     77                if ($.isEmpty(value)) { 
     78                    return this.notifySuccess(); 
     79                } 
    7280 
    7381                if (((this.min != undefined) && value < this.min) || ((this.max != undefined) && value > this.max) 
    74                         || ((this.step != undefined) && ((value - ((this.min != undefined) ? this.min : 0)) % this.step != 0))) 
     82                        || ((this.step != undefined) && ((value - ((this.min != undefined) ? this.min : 0)) % this.step != 0))) { 
    7583                    return this.notifyFail("i18n:Should be at least {0}, at most {1}, and in steps of {2}!", [ this.min, this.max, 
    7684                            this.step ]); 
     85                } 
    7786 
    7887                return this.notifySuccess(); 
     
    8493            validate : function( value) { 
    8594 
    86                 if (value == undefined || value.length == undefined) // only for arrays and strings 
    87                     return this.notifySuccess(); 
     95                if (value == undefined || value.length == undefined) { // only for arrays and strings 
     96                    return this.notifySuccess(); 
     97                } 
    8898     
    89                 if (((this.min != undefined) && value.length < this.min) || (this.max && value.length > this.max)) 
     99                if (((this.min != undefined) && value.length < this.min) || (this.max && value.length > this.max)) { 
    90100                    return this.notifyFail("i18n:Should be at least {0} and at most {1} characters!", [ this.min, this.max ]); 
     101                } 
    91102     
    92103                return this.notifySuccess(); 
     
    97108            validate : function( value) { 
    98109 
    99                 if ($.isEmpty(value)) 
    100                     return this.notifySuccess(); 
     110                if ($.isEmpty(value)) { 
     111                    return this.notifySuccess(); 
     112                } 
    101113 
    102114                this.assertRegexInitialization(); 
    103115 
    104                 if (this.regex.test(value) != true) 
     116                if (this.regex.test(value) != true) { 
    105117                    return this.notifyFail("i18n:Not a valid value according to the regex ({0}).", [ this.regex ]); 
     118                } 
    106119             
    107120                return this.notifySuccess(); 
     
    109122             
    110123            assertRegexInitialization : function() { 
    111                 if (typeof this.regex === "string")  
     124                if (typeof this.regex === "string") {  
    112125                    this.regex = new RegExp(this.regex); 
    113                  
    114                 if (this.regex == undefined || !$.isFunction(this.regex.test)) 
     126                } 
     127                 
     128                if (this.regex == undefined || !$.isFunction(this.regex.test)) { 
    115129                    throw "Regex validation badly configured."; // TODO or should we silently switch to an accept all regex? 
     130                } 
    116131            } 
    117132        },   
     
    120135            validate : function( value) { 
    121136             
    122                 if ($.isEmpty(value)) 
    123                     return this.notifySuccess(); 
    124              
    125                 if (EMAIL_REGEX.test(value) != true) 
     137                if ($.isEmpty(value)) { 
     138                    return this.notifySuccess(); 
     139                } 
     140             
     141                if (EMAIL_REGEX.test(value) != true) { 
    126142                    return this.notifyFail("i18n:Not a valid email adress"); 
     143                } 
    127144             
    128145                return this.notifySuccess(); 
     
    133150            validate : function( value) { 
    134151             
    135                 if ($.isEmpty(value)) 
    136                     return this.notifySuccess(); 
    137              
    138                 if (URI_REGEX.test(value) != true) 
     152                if ($.isEmpty(value)) { 
     153                    return this.notifySuccess(); 
     154                } 
     155             
     156                if (URI_REGEX.test(value) != true) { 
    139157                    return this.notifyFail("i18n:Not a valid url"); 
     158                } 
    140159             
    141160                return this.notifySuccess(); 
     
    146165            validate : function( value, data) { 
    147166             
    148                 if ($.isEmpty(value)) 
    149                     return this.notifySuccess(); 
     167                if ($.isEmpty(value)) { 
     168                    return this.notifySuccess(); 
     169                } 
    150170             
    151171                var options = data.options || [];  
    152                 if ($.valueInArray(value, options) < 0) 
     172                if ($.valueInArray(value, options) < 0) { 
    153173                    return this.notifyFail("i18n:Value[{0}](@pos {1}) not in list of available options.", [ value, data.index ]); 
     174                } 
    154175             
    155176                return this.notifySuccess(); 
     
    160181            validate : function( value, validationData) { 
    161182             
    162                 if ($.isEmpty(value)) 
    163                     return this.notifySuccess(); 
     183                if ($.isEmpty(value)) { 
     184                    return this.notifySuccess(); 
     185                } 
    164186                 
    165187                //take the wireValue in stead 
     
    167189                value = kp.JSON.stringify(value); 
    168190                 
    169                 if (!this.location) 
     191                if (!this.location) { 
    170192                    throw "A location-path for remote validation should be given!"; 
     193                } 
    171194                 
    172195                var me = this; 
     196                var errorHandler = function() { 
     197                    return me.notifyFail("i18n:Error while connecting to remote validation."); 
     198                }; 
    173199                var successHandler = function( response, txtstatus, xhr) { 
    174200                 
     
    187213                    return me.notifyFail("i18n:Remote validation returned incompatible response!"); 
    188214                }; 
    189                 var errorHandler = function() { 
    190                     return me.notifyFail("i18n:Error while connecting to remote validation."); 
    191                 }; 
    192215                try { 
    193216                    $.ajax( { 
     
    210233    }); 
    211234 
    212 })(jQuery); 
     235}(jQuery)); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/builder.js

    r948 r1948  
     1/*jslint eqeq: true */ 
    12/** 
    23 * @fileOverview This script initializes the Kauri Forms 'System' 
     
    67( function( $) { 
    78 
    8     if (!$) 
     9    if (!$) { 
    910        throw "[builder.js] requires jQuery"; 
    10     if (!$.org.kauriproject.forms) 
     11    } 
     12    if (!$.org.kauriproject.forms) { 
    1113        throw "[builder.js] requires the kauri-form namespace"; 
     14    } 
    1215 
    1316    var kf = $.org.kauriproject.forms; 
    1417    var kp = $.org.kauriproject; 
    1518 
    16     $.extend(kf, { 
    17         Builder :Builder 
    18     }); 
    1919 
    2020    /** 
     
    3232        // create the registries 
    3333        var last = this.registryNames.length; 
    34         for ( var i = 0; i < last; i++) { 
     34        var i = 0; 
     35        for ( i = 0; i < last; i++) { 
    3536            var name = this.registryNames[i]; 
    3637            this[name] = new kf.ConstructorRegistry("Registry of [" + level + "] " + name, parent[name]); 
     
    4445        this.controlTypes.setBaseConstructor(kf.Control); 
    4546    } 
     47    $.extend(kf, { Builder :Builder}); 
    4648 
    4749    /** 
     
    5961             
    6062        var last = this.registryNames.length; 
    61         for ( var i = 0; i < last; i++) { 
     63        var i = 0; 
     64        for ( i = 0; i < last; i++) { 
    6265            var name = this.registryNames[i]; 
    6366             
    6467            if (name == "fieldTypes") { 
    65                 for (var prop in conf[name]) { 
     68                var prop; 
     69                for (prop in conf[name]) { 
    6670                    // no base defined, but members are: default to composite 
    67                     if (conf[name][prop].base == undefined && conf[name][prop].members != undefined) 
     71                    if (conf[name][prop].base == undefined && conf[name][prop].members != undefined) { 
    6872                        conf[name][prop].base = 'composite'; 
     73                    } 
    6974                } 
    7075            } 
     
    7580        // TODO think about a good path location for dynamic loaded components (fieldtypes, validators, ..) 
    7681        // and a way to describe that in the conf, maybe conf.locations = { validators: .., ...}; 
    77     } 
     82    }; 
    7883 
    7984    /** 
     
    9196    Builder.prototype.getInstance = function( /* String */registry, /* String */name, /* Object */extender, /* array */args) { 
    9297 
    93         if (this[registry] == undefined || this[registry].constructor != kf.ConstructorRegistry) 
     98        if (this[registry] == undefined || this[registry].constructor != kf.ConstructorRegistry) { 
    9499            return; 
     100        } 
    95101        return this[registry].getInstance(name, extender, args); 
    96     } 
     102    }; 
    97103 
    98104    // initialize the 'basic' builder level. 
    99105    $.extend(kf, new Builder("Basic")); 
    100106 
    101 })(jQuery); 
     107}(jQuery)); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/case.js

    r1920 r1948  
     1/*jslint eqeq: true */ 
    12/** 
    23 * @fileOverview This file holds the fieldtype and controltype for handling case-data-structures. 
     
    56( function( $) { 
    67 
    7     if (!$) 
     8    if (!$) { 
    89        throw "[case.js] requires jQuery"; 
    9     if (!$.org.kauriproject.forms) 
     10    } 
     11    if (!$.org.kauriproject.forms) { 
    1012        throw "[case.js] requires the kauri-form namespace"; 
     13    } 
    1114 
    1215    var kp = $.org.kauriproject; 
     
    1619    var validators = kf.validators; 
    1720     
    18     /** 
    19      
    20     */ 
    21     $.inherit(CaseFieldType, kf.FieldType); 
    2221     
    2322    /** 
     
    2928        kf.FieldType.init(this); 
    3029    } 
     30    $.inherit(CaseFieldType, kf.FieldType); 
    3131     
    3232    /** 
     
    6262    CaseFieldType.configBuild = function( builder, protype) { 
    6363        kf.FieldType.configBuild(builder, protype); // keep handling the basic stuff. 
    64         if (protype.cases) 
     64        if (protype.cases) { 
    6565            kf.FieldType.createTypes(builder, protype.cases); 
     66        } 
    6667        if (protype.selector) { 
    6768            var selectorType = {selector : protype.selector}; 
     
    6970            protype.selector = selectorType.selector; 
    7071        } 
    71     } 
     72    }; 
    7273 
    7374    /** 
     
    7879    CaseFieldType.prototype.getCaseTypes = function() { 
    7980        return this.cases; 
    80     } 
     81    }; 
    8182 
    8283    /** 
     
    8889    CaseFieldType.prototype.getCaseType = function(name) { 
    8990        return this.cases[name]; 
    90     } 
     91    }; 
    9192     
    9293    /** 
     
    9899    CaseFieldType.prototype.getCaseControlType = function(name) { 
    99100        return this.getCaseType(name).control; 
    100     } 
     101    }; 
    101102     
    102103    /** 
     
    107108    CaseFieldType.prototype.getSelectorType = function () { 
    108109        return this.selector; 
    109     } 
     110    }; 
    110111     
    111112    /* CASE CONTROL */ 
    112      
    113     $.inherit(CaseControl, kf.AbstractContainerControl); 
    114113     
    115114    /** 
     
    129128        kf.Control.init(this, id, form, conf); 
    130129    } 
    131      
     130    $.inherit(CaseControl, kf.AbstractContainerControl); 
     131         
    132132    CaseControl.prototype.templates = {}; 
    133133     
     
    139139     
    140140     
    141      
    142141    var CASE_PFX = "case-"; 
    143142     
     
    167166        } 
    168167 
    169          
    170         for ( var caseName in caseTypes) { 
     168        var caseName; 
     169        for ( caseName in caseTypes) { 
    171170            var caseType = caseTypes[caseName];         
    172171            var valueControl = this.createChildControl(CASE_PFX + caseName, caseType); 
     
    188187        // typically for selection-controls we set the options from the collected cases. 
    189188        var options = caseControl.options; 
    190         if (options) 
     189        if (options) { 
    191190            options.set(optionValues, optionLabels); 
     191        } 
    192192         
    193193        caseControl.setWireValue(optionValues[0], true); //noValidation on init of elements 
     
    195195        this.putChild("case", caseControl);       
    196196 
    197     } 
     197    }; 
    198198     
    199199    /** 
     
    205205    CaseControl.prototype.getChildren = function(includeAll) { 
    206206        includeAll = includeAll || false; 
    207         if (includeAll) 
     207        if (includeAll) { 
    208208            return this._valueControls; 
     209        } 
    209210        return kf.AbstractContainerControl.getChildren(this); 
    210211         
    211     } 
     212    }; 
    212213     
    213214    /** 
     
    230231        //else default to 
    231232        return null; 
    232     } 
     233    }; 
    233234    CaseControl.prototype.getChildByPathSegment = function(pathSegment){ 
    234235        return this.getChild(pathSegment); 
    235     } 
     236    }; 
    236237     
    237238    /** 
     
    250251            var value = me.getChild("value"); 
    251252             
    252             if(value) 
     253            if(value) { 
    253254                me.getChild("value").hide(); 
     255            } 
    254256             
    255257            // find  the new value control             
     
    260262                valueControl.resetShowState(); // don't just show, restore initial view state 
    261263            }else{ 
    262                 if(me.nullable) 
     264                if(me.nullable) { 
    263265                    me.deleteChild("value"); 
    264                 else 
     266                } else { 
    265267                    me.setMessage("Sorry but " + selectedCase + " is not a valid value"); 
     268                } 
    266269            } 
    267270            var noValidation = (this.valueState == kf.Control.STATE_INIT);  
    268             if(!noValidation) 
     271            if(!noValidation) { 
    269272                me.newValidation(this.getValue(), this.getWireValue()); 
     273            } 
    270274        }); 
    271     } 
     275    }; 
    272276     
    273277 
     
    276280    }; 
    277281    CaseControl.reset = function(me) { 
     282        var i; 
     283         
    278284        // reset children: first elements in me._valueControls, then me.caseControl 
    279285        for (i in me._valueControls) { 
     
    298304          } else { 
    299305            me._valueControls[i].hide(); 
    300           }; 
     306          } 
    301307        } 
    302308 
    303309        me.valueState = me.STATE_INIT; 
    304310        me.updateValidationClasses(); 
    305     } 
     311    }; 
    306312     
    307313    /** 
     
    326332         
    327333        this.getChild("value").resetShowState(); 
    328     } 
     334    }; 
    329335     
    330336     
     
    332338    controlTypes.put("case-control", CaseControl); 
    333339     
    334 })(jQuery); 
     340}(jQuery)); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/collection.js

    r1920 r1948  
     1/*jslint eqeq: true */ 
    12/** 
    23 * @fileOverview This file describes the field-type and controltype for collections 
     
    67( function( $) { 
    78 
    8     if (!$) 
     9    if (!$) { 
    910        throw "[collection.js] requires jQuery"; 
    10     if (!$.org.kauriproject.forms) 
     11    } 
     12    if (!$.org.kauriproject.forms){ 
    1113        throw "[collection.js] requires the kauri-form namespace"; 
     14    } 
    1215 
    1316    var kf = $.org.kauriproject.forms; 
     
    1619 
    1720 
    18     $.inherit(CollectionFieldType, kf.FieldType); 
    1921    /** 
    2022     * Specific FieldType that takes care of creating the field-type used to model the children (= the "rows" 
     
    2830        kf.FieldType.init(this); 
    2931    } 
     32    $.inherit(CollectionFieldType, kf.FieldType); 
    3033 
    3134    CollectionFieldType.prototype.control = 'collection-control'; 
    3235    CollectionFieldType.prototype.validators = []; 
    3336 
    34     CollectionFieldType.prototype.child; 
    35  
    3637    CollectionFieldType.configBuild = function( builder, protype) { 
    3738 
    3839        kf.FieldType.configBuild(builder, protype); // keep handling the basic stuff. 
    39         if (protype.child) 
     40        if (protype.child) { 
    4041            protype.child = kf.FieldType.buildType(builder, protype.child); 
    41     } 
     42        } 
     43    }; 
    4244 
    4345    CollectionFieldType.prototype.getChildType = function() { 
    4446        return this.child; 
    45     } 
     47    }; 
    4648 
    4749    CollectionFieldType.prototype.getChildControlType = function() { 
    4850        return this.child.control; 
    49     } 
    50  
    51  
    52     $.inherit(CollectionControl, kf.AbstractContainerControl); 
     51    }; 
     52 
     53 
    5354    /** 
    5455     * Specific ControlType for collections of elements. 
     
    6061        kf.Control.init(this, id, form, conf); 
    6162    } 
     63    $.inherit(CollectionControl, kf.AbstractContainerControl); 
    6264     
    6365    CollectionControl.idCount = 0; 
     
    126128         
    127129        this._childrenContainer = container; 
    128     } 
     130    }; 
    129131 
    130132    CollectionControl.prototype.initial = $.extend(true, $.extend({}, kf.AbstractContainerControl.prototype.initial), {"value": []}); 
     
    138140 
    139141        this.removeChildren(); 
    140     } 
     142    }; 
    141143     
    142144    /**  
     
    149151         
    150152        // loop trough all values, create child(rows) if needed and pass the child-value 
    151         for (var i in value) { 
     153        var i; 
     154        for (i in value) { 
    152155            var child = this.getChildByIndex(i); // NOTE: must use getChild(since it might need to create it still.) 
    153             if (child != undefined) // and if it hasn't been created, then just ignore this value. 
     156            if (child != undefined) {// and if it hasn't been created, then just ignore this value. 
    154157                cfn(i, child); 
    155         } 
    156     } 
     158            } 
     159        } 
     160    }; 
    157161 
    158162    /** 
     
    167171        } 
    168172        return children[index]; 
    169     } 
     173    }; 
    170174 
    171175    /** 
     
    175179     */ 
    176180    CollectionControl.prototype.getChild = function(id) { 
    177         var children = this.getChildren(); 
    178         for (var i = 0; i < children.length; i++) { 
     181        var children = this.getChildren(), i=0; 
     182        for (i = 0; i < children.length; i++) { 
    179183            if (children[i].getId() === id) { 
    180184                return children[i]; 
     
    182186        } 
    183187        return null; 
    184     } 
     188    }; 
    185189 
    186190    /** 
     
    190194     */ 
    191195    CollectionControl.prototype.getChildIndex = function(id) {         
    192         var children = this.getChildren(); 
    193         for (var i = 0; i < children.length; i++) { 
     196        var children = this.getChildren(), i=0; 
     197        for (i = 0; i < children.length; i++) { 
    194198            if (children[i].getId() == id) { 
    195199                return i; 
     
    197201        } 
    198202        return null; 
    199     } 
     203    }; 
    200204 
    201205    CollectionControl.prototype.getChildByPathSegment = function(pathSegment){ 
    202206        return this.getChildren()[pathSegment]; 
    203     } 
     207    }; 
    204208     
    205209    CollectionControl.prototype.newChildId = function() { 
    206210        return "rid-" + CollectionControl.idCount++; 
    207     } 
     211    }; 
    208212 
    209213    /** 
     
    253257 
    254258        return childControl; 
    255     } 
     259    }; 
    256260 
    257261    CollectionControl.prototype.removeChild = function(childId) { 
    258262        var childIndex = this.getChildIndex(childId); 
    259         if (childIndex == null) 
     263        if (childIndex == null) { 
    260264            throw "No child in collection with id " + childId; 
     265        } 
    261266         
    262267        var child = this.getChild(childId); 
    263         if (child == null) 
     268        if (child == null) { 
    264269            throw "No child in collection with index " + childIndex; 
     270        } 
    265271 
    266272        child.close(); 
     
    268274        // remove it from array 
    269275        this.getChildren().splice(childIndex, 1); 
    270     } 
     276    }; 
    271277 
    272278    // adding the new types to the registries... 
     
    274280    controlTypes.put("collection-control", CollectionControl); 
    275281 
    276 })(jQuery); 
     282}(jQuery)); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/composite.js

    r1920 r1948  
    55( function( $) { 
    66 
    7     if (!$) 
     7    if (!$) { 
    88        throw "[composite.js] requires jQuery"; 
    9     if (!$.org.kauriproject.forms) 
     9    } 
     10    if (!$.org.kauriproject.forms){ 
    1011        throw "[composite.js] requires the kauri-form namespace"; 
     12    } 
    1113 
    1214    var kp = $.org.kauriproject; 
     
    1719 
    1820 
    19     $.inherit(CompositeFieldType, kf.FieldType); 
    2021    /** 
    2122     * Specific FieldType that takes care of creating the field-type used to model the members. 
     
    2829        kf.FieldType.init(this); 
    2930    } 
     31    $.inherit(CompositeFieldType, kf.FieldType); 
    3032 
    3133    CompositeFieldType.prototype.control = 'composite-control'; 
     
    3739 
    3840        kf.FieldType.configBuild(builder, protype); // keep handling the basic stuff. 
    39         if (protype.members) 
     41        if (protype.members) { 
    4042            kf.FieldType.createTypes(builder, protype.members); 
    41     } 
     43        } 
     44    }; 
    4245 
    4346    CompositeFieldType.prototype.getMemberTypes = function() { 
    4447 
    4548        return this.members; 
    46     } 
     49    }; 
    4750 
    4851    CompositeFieldType.prototype.getMemberType = function( name) { 
    4952 
    5053        return this.members[name]; 
    51     } 
     54    }; 
    5255 
    5356    CompositeFieldType.prototype.getMemberControlType = function( name) { 
    5457 
    5558        return this.members[name].control; 
    56     } 
     59    }; 
    5760 
    5861     
    59     $.inherit(CompositeControl, kf.AbstractContainerControl); 
    6062    /** 
    6163     * CompositeControlType groups and contains the various member-control-types it is composed off. 
     
    7375     */ 
    7476    function CompositeControl( id, form, conf) { 
    75  
    7677        kf.Control.init(this, id, form, conf); 
    7778    } 
     79    $.inherit(CompositeControl, kf.AbstractContainerControl); 
    7880     
    7981    CompositeControl.prototype.templates = {}; 
     
    9496         
    9597        var orderArray = type.order || []; 
     98        var memberName; 
    9699         
    97         for (var memberName in memberTypes){ 
    98             var position = $.inArray(memberName, orderArray) 
     100        for (memberName in memberTypes){ 
     101            var position = $.inArray(memberName, orderArray); 
     102            var orderObj = {}; 
    99103            if(position == -1){ 
    100104                // not found in array, push it 
    101                 var orderObj = {}; 
    102                 orderObj["memberType"] = memberTypes[memberName]; 
    103                 orderObj["memberName"] = memberName; 
     105                orderObj.memberType = memberTypes[memberName]; 
     106                orderObj.memberName = memberName; 
    104107                orderArray.push(orderObj ); 
    105             }else{ 
    106                 var orderObj = {}; 
    107                 orderObj["memberType"] = memberTypes[memberName]; 
    108                 orderObj["memberName"] = memberName; 
     108            } else { 
     109                orderObj.memberType = memberTypes[memberName]; 
     110                orderObj.memberName = memberName; 
    109111                orderArray[position] = orderObj;     
    110112            } 
    111113             
    112114        } 
    113         orderArray.sort( function (a,b) { return b.order < a.order } ); 
     115        orderArray.sort( function (a,b) { return b.order < a.order; } ); 
    114116 
    115         for (var sKey in orderArray) { 
     117        var sKey; 
     118        for (sKey in orderArray) { 
    116119            var childControl = this.createChildControl(orderArray[sKey].memberName, orderArray[sKey].memberType); 
    117120            this.putChild(orderArray[sKey].memberName, childControl); 
    118121        } 
    119          
    120          
    121     } 
     122    }; 
     123     
    122124     
    123125    CompositeControl.prototype.createChildElements = function (id, container, layout) { 
     
    128130        //var item = $(this.getTemplate('layout')).appendTo(container); 
    129131        //return item; 
    130     } 
     132    }; 
    131133 
    132134    // adding the new types to the registries... 
     
    142144                var a = $.trim(this.fieldA); 
    143145                var b = $.trim(this.fieldB);                 
    144                 if (a.indexOf('{') < 0) 
     146                if (a.indexOf('{') < 0) { 
    145147                    a = "{" + a + "}"; 
    146                 if (b.indexOf('{') < 0) 
     148                } 
     149                if (b.indexOf('{') < 0) { 
    147150                    b = "{" + b + "}"; 
     151                } 
    148152                 
    149153                this.templA = new kp.UriTemplate(a); 
     
    151155            }, 
    152156            validate : function (value) { 
    153                 if ($.isEmpty(value))  
     157                if ($.isEmpty(value)) {  
    154158                    return this.notifySuccess(); 
     159                } 
    155160                     
    156161                var valA = this.templA.expand(value); 
    157162                var valB = this.templB.expand(value); 
    158163 
    159                 if (this._operations[this.operation](valA, valB)) 
     164                if (this._operations[this.operation](valA, valB)) { 
    160165                    return this.notifySuccess(); 
    161                 else  
     166                } else {  
    162167                    return this.notifyFail(valA + " is not " + this.operation + " than " + valB); 
    163                  
     168                } 
    164169            }, 
    165170            _operations : { 
     
    187192    }); 
    188193 
    189 })(jQuery); 
     194}(jQuery)); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/control.js

    r1927 r1948  
     1/*jslint eqeq: true, maxerr: 500 */ 
    12/** 
    23 * @fileOverview This file holds the basic structure of the control system 
     
    56(function($){ 
    67 
    7     if (!$)  
     8    if (!$) {  
    89        throw "[control.js] requires jQuery"; 
    9     if (!$.org.kauriproject.forms)  
     10    } 
     11    if (!$.org.kauriproject.forms) {  
    1012        throw "[control.js] requires kauri-form namespace"; 
     13    } 
    1114     
    1215    var kf = $.org.kauriproject.forms; 
    1316    var locale = kf.locale; 
    14      
    15     $.extend(kf, { 
    16         ControlElements: ControlElements, 
    17         Control: Control, 
    18         AbstractContainerControl: AbstractContainerControl 
    19     }); 
    2017     
    2118     
     
    182179            var layout = $this.attr(ControlElements.ATTR_LAYOUT);  
    183180 
    184             if (idref.length == 0 || idref.charAt(0) != '/')  
     181            if (idref.length === 0 || idref.charAt(0) !== '/') {  
    185182                index = parentindex; 
     183            } 
    186184            if (idref) { 
    187185                index = $.concatPath(index, idref); 
     
    197195 
    198196            store.addTypeAndControl(index, type, control); 
    199             if(childtype) 
     197            if(childtype) { 
    200198                store.addChildType(index, childtype); 
     199            } 
    201200             
    202             if((value != undefined && value != "")  || disabled == true  || (type != undefined && type == 'hidden') ){ 
     201            if((value != undefined && value !== "")  || disabled === true  || (type != undefined && type === 'hidden') ){ 
    203202                var initial = {}; 
    204203                initial.value = value; 
    205                 initial.enable = (disabled == true) ? false : true; 
    206                 initial.show = (type != undefined && type == 'hidden') ? false : true; 
     204                initial.enable = (disabled === true) ? false : true; 
     205                initial.show = (type != undefined && type === 'hidden') ? false : true; 
    207206                store.addInitialProperties(index, initial); 
    208207            } 
     
    211210            if(layout){ 
    212211                var layoutindex; 
    213                 if (layout.length == 0 || layout.charAt(0) != '/')  
     212                if (layout.length === 0 || layout.charAt(0) !== '/') {  
    214213                    layoutindex = parentindex; 
     214                } 
    215215                if (layout) { 
    216216                    layoutindex = $.concatPath(layoutindex, layout); 
     
    222222            $this.children().each(function(){ 
    223223                var $child = $(this); 
    224                 ControlElements.initialIndex($child, store, index) 
     224                ControlElements.initialIndex($child, store, index); 
    225225            }); 
    226226        }); 
    227     } 
     227    }; 
    228228     
    229229   /** 
     
    236236    * @static 
    237237    */ 
    238   ControlElements.index = function(space, store, parentindex){ 
    239       space.each(function(){ 
    240           var $this = $(this); 
    241  
    242           var index = $this.attr(ControlElements.ATTR_INDEX) || ""; 
    243           var idref = $this.attr(ControlElements.ATTR_IDREF) || "";  
    244           var layout = $this.attr(ControlElements.ATTR_LAYOUT);  
     238    ControlElements.index = function(space, store, parentindex){ 
     239        space.each(function(){ 
     240            var $this = $(this); 
     241 
     242            var index = $this.attr(ControlElements.ATTR_INDEX) || ""; 
     243            var idref = $this.attr(ControlElements.ATTR_IDREF) || "";  
     244            var layout = $this.attr(ControlElements.ATTR_LAYOUT);  
    245245           
    246           if (index.length == 0) { //no explicit index is set - build it from the idref 
    247               if (idref.length == 0 || idref.charAt(0) != '/') {  
    248                   index = parentindex; 
    249               } 
    250               if (idref) { 
    251                   index = $.concatPath(index, idref); 
    252               } 
    253           } 
     246            if (index.length === 0) { //no explicit index is set - build it from the idref 
     247                if (idref.length === 0 || idref.charAt(0) !== '/') {  
     248                    index = parentindex; 
     249                } 
     250                if (idref) { 
     251                    index = $.concatPath(index, idref); 
     252                } 
     253            } 
    254254           
    255           // do elementIndexing + cursorIndexing 
    256           // get relevant attributes kauri-idref, kauri-role, kauri-layout, kauri-cursor 
    257           var role = $this.attr(ControlElements.ATTR_ROLE); 
    258           var cursor = $this.attr(ControlElements.ATTR_LAYOUT_CURSOR);  
    259           var group = $this.attr(ControlElements.ATTR_LAYOUT_GROUP);  
     255            // do elementIndexing + cursorIndexing 
     256            // get relevant attributes kauri-idref, kauri-role, kauri-layout, kauri-cursor 
     257            var role = $this.attr(ControlElements.ATTR_ROLE); 
     258            var cursor = $this.attr(ControlElements.ATTR_LAYOUT_CURSOR);  
     259            var group = $this.attr(ControlElements.ATTR_LAYOUT_GROUP);  
    260260           
    261           if(idref || role){ 
    262               $this.attr(ControlElements.ATTR_INDEX, index); 
    263               store.addElementIndex(index, role, $this); 
    264            } 
    265  
    266           if(cursor) { 
    267               // to do with cursor: replace the '#' with the appropriate ID of the element if needed in case of nested elements 
    268               // e.g. kauri-cursor="/people/#/children" for the cursor of "/people/r1/children" or "/people/r2/children" 
    269               var cursorindex; 
    270               if (cursor.length == 0 || cursor.charAt(0) != '/')  
    271                   cursorindex = parentindex; 
    272               if (cursor) { 
    273                   cursorindex = $.concatPath(cursorindex, cursor); 
    274               } 
    275               store.addCursorIndex(cursorindex, $this, group); 
    276           } 
     261            if(idref || role){ 
     262                $this.attr(ControlElements.ATTR_INDEX, index); 
     263                store.addElementIndex(index, role, $this); 
     264            } 
     265         
     266            if(cursor) { 
     267                // to do with cursor: replace the '#' with the appropriate ID of the element if needed in case of nested elements 
     268                // e.g. kauri-cursor="/people/#/children" for the cursor of "/people/r1/children" or "/people/r2/children" 
     269                var cursorindex; 
     270                if (cursor.length === 0 || cursor.charAt(0) !== '/') {   
     271                    cursorindex = parentindex; 
     272                } 
     273                if (cursor) { 
     274                    cursorindex = $.concatPath(cursorindex, cursor); 
     275                } 
     276                store.addCursorIndex(cursorindex, $this, group); 
     277            } 
    277278                   
    278           if(!layout){ 
    279               // now index each child of $this 
    280               $this.children().each(function(){ 
    281                  var $child = $(this); 
    282                  ControlElements.index($child, store, index) 
    283               }); 
    284           }else{ 
    285               // it's a layout element : check if there is a cursor, otherwise insert a cursor before the element before removing it 
    286               if( ! store.getCursorIndex(index, group) ){ 
    287                   var cursor = $this.clone(); 
    288                   cursor.empty(); 
    289                   cursor.hide(); // explicit cursors are hidden already, these implicit ones need that too. 
    290                   cursor.insertBefore($this); 
    291                   store.addCursorIndex(index, cursor, group); 
    292               } 
    293  
    294               $this.remove(); 
    295           } 
    296       }); 
    297   } 
     279            if(!layout){ 
     280                // now index each child of $this 
     281                $this.children().each(function(){ 
     282                    var $child = $(this); 
     283                    ControlElements.index($child, store, index); 
     284                }); 
     285            } else { 
     286                // it's a layout element : check if there is a cursor, otherwise insert a cursor before the element before removing it 
     287                if( ! store.getCursorIndex(index, group) ){ 
     288                    cursor = $this.clone(); 
     289                    cursor.empty(); 
     290                    cursor.hide(); // explicit cursors are hidden already, these implicit ones need that too. 
     291                    cursor.insertBefore($this); 
     292                    store.addCursorIndex(index, cursor, group); 
     293                } 
     294     
     295                $this.remove(); 
     296            } 
     297        }); 
     298    }; 
    298299     
    299300     
     
    308309            this.elementIndex[index].control = control; 
    309310        } 
    310     } 
     311    }; 
    311312 
    312313    ControlElements.prototype.addChildType = function(index, childtype){ 
    313          
    314314        if (childtype != undefined) { 
    315315            this.elementIndex[index] = this.elementIndex[index] || ControlElements.newElements(); 
    316316            this.elementIndex[index].childtype = childtype; 
    317317        } 
    318     } 
     318    }; 
    319319 
    320320     
     
    323323            this.elementIndex[index] = this.elementIndex[index] || ControlElements.newElements(); 
    324324            this.elementIndex[index].initial = initialProperties; 
    325              
    326         } 
    327     } 
    328  
    329      
     325        } 
     326    }; 
     327 
    330328     
    331329    ControlElements.prototype.getImplicitConfig = function() { 
     
    335333        var field = {}; 
    336334 
    337         for ( var index in this.elementIndex) { 
     335        var index; 
     336        for ( index in this.elementIndex) { 
    338337            if (((this.elementIndex[index].type != undefined) 
    339338                    || (this.elementIndex[index].control != undefined) || (this.elementIndex[index].initial != undefined)) 
    340                     && index != "/") { 
     339                    && index !== "/") { 
    341340                var segments = index.split('/'); 
    342341                var control = implicitFconf; 
    343342 
    344343                // search in fconf which control to edit 
     344                var i; 
    345345                for (i = 0; i < segments.length; i++) { 
    346                     if (segments[i] == "") { 
     346                    if (segments[i] === "") { 
    347347                        continue; 
    348348                    } else { 
    349                         if (control.base == 'collection') { 
    350                             if (control['child'] == undefined) 
    351                                 control['child'] = {}; 
    352                             control = control['child']; 
     349                        if (control.base === 'collection') { 
     350                            if (control.child == undefined) { 
     351                                control.child = {}; 
     352                            } 
     353                            control = control.child; 
    353354                        } 
    354                         if (control.base == 'case') { 
    355                             if (control['cases'] == undefined) 
    356                                 control['cases'] = {}; 
    357                             if (segments[i].indexOf('case-') == 0) { 
    358                                 control = control['cases']; 
    359                                 control[segments[i].substr(5)] = control[segments[i] 
    360                                         .substr(5)] 
    361                                         || {}; 
     355                        if (control.base === 'case') { 
     356                            if (control.cases == undefined){ 
     357                                control.cases = {}; 
     358                            } 
     359                            if (segments[i].indexOf('case-') === 0) { 
     360                                control = control.cases; 
     361                                control[segments[i].substr(5)] = control[segments[i].substr(5)] || {}; 
    362362                                control = control[segments[i].substr(5)]; 
    363                             } else if (segments[i] == 'case') { 
     363                            } else if (segments[i] === 'case') { 
    364364                                control.selector = control.selector || {}; 
    365365                                control = control.selector; 
    366366                            } else { 
    367                                 throw segments[i] 
    368                                         + " is a valid name within 'case' controls"; 
     367                                throw segments[i] + " is a valid name within 'case' controls"; 
    369368                            } 
    370                         } else if (control['members'] != undefined 
    371                                 && control['members'][segments[i]] != undefined) { 
    372                             if (control['members'][segments[i]].constructor == String) { 
    373                                 var controlType = control['members'][segments[i]]; 
    374                                 control['members'][segments[i]] = {}; 
    375                                 control['members'][segments[i]]["base"] = controlType; 
     369                        } else if (control.members != undefined 
     370                                && control.members[segments[i]] != undefined) { 
     371                            if (control.members[segments[i]].constructor === String) { 
     372                                var controlType = control.members[segments[i]]; 
     373                                control.members[segments[i]] = {}; 
     374                                control.members[segments[i]].base = controlType; 
    376375                            } 
    377                             control = control['members'][segments[i]]; 
     376                            control = control.members[segments[i]]; 
    378377                        } else { 
    379                             if (control['members'] == undefined) { 
    380                                 control['members'] = {}; 
     378                            if (control.members == undefined) { 
     379                                control.members = {}; 
    381380                            } 
    382                             control = control['members']; 
     381                            control = control.members; 
    383382                            control[segments[i]] = control[segments[i]] || {}; 
    384383                            control = control[segments[i]]; 
     
    389388 
    390389                var type = {}; 
    391                 if (this.elementIndex[index].type) 
    392                     type['base'] = this.elementIndex[index].type; 
     390                if (this.elementIndex[index].type) { 
     391                    type.base = this.elementIndex[index].type; 
     392                } 
    393393 
    394394                if (this.elementIndex[index].control) { 
    395                     if (this.elementIndex[index].control.constructor == 'Object') { 
    396                         type['control'] = this.elementIndex[index].control; 
     395                    if (this.elementIndex[index].control.constructor === 'Object') { 
     396                        type.control = this.elementIndex[index].control; 
    397397                    } else { 
    398                         type['control'] = {}; 
    399                         type['control']['base'] = this.elementIndex[index].control; 
     398                        type.control = {}; 
     399                        type.control.base = this.elementIndex[index].control; 
    400400                    } 
    401401                } 
    402402 
    403403                if (this.elementIndex[index].initial) { 
    404                     type['control'] = type['control'] || {}; 
    405                     type['control']['initial'] = this.elementIndex[index].initial; 
     404                    type.control = type.control || {}; 
     405                    type.control.initial = this.elementIndex[index].initial; 
    406406                } 
    407407                var childtype = this.getElementIndex(index).childtype; 
    408408                if (childtype) { 
    409                     controlToEdit['child'] = controlToEdit['child'] || {}; 
    410                     controlToEdit['child']['base'] = childtype; 
     409                    controlToEdit.child = controlToEdit.child || {}; 
     410                    controlToEdit.child.base = childtype; 
    411411                } 
    412412 
     
    415415        } 
    416416        return implicitFconf; 
    417     } 
     417    }; 
    418418     
    419419    /** 
     
    428428    ControlElements.lookup = function(control, relation){ 
    429429        return control.getElement(relation); 
    430     } 
     430    }; 
    431431 
    432432     /** 
     
    441441     ControlElements.removeRelationElement = function(control, relation){ 
    442442      
    443          if (!relation)  
     443         if (!relation) { 
    444444             throw "[ControlElements#lookup] no relation specified."; 
     445         } 
    445446         var form = control.getForm(); 
    446447         var index = control.getAbsoluteId(); 
    447448          
    448449         form.removeElementIndex(index, relation); 
    449      } 
     450     }; 
    450451 
    451452      
     
    461462        } 
    462463        return $elm; 
    463     } 
     464    }; 
    464465 
    465466    ControlElements.lookupLayoutCursor = function(control) { 
     
    473474        } 
    474475        return $elm; 
    475     } 
     476    }; 
    476477      
    477478      
     
    483484        var index = control.getAbsoluteId(); 
    484485         
    485         var allElms = new Array();  
     486        var allElms = [];  
    486487        var size = 0; 
    487488        var elmIndex = form.getElementIndex(index); 
    488489         
    489490        var last = elmIndex.length; 
    490         for (var i = 0; i< last; i++) { 
     491        var i; 
     492        for (i = 0; i< last; i++) { 
    491493            var elm = elmIndex[i]; 
    492             if(elm) 
     494            if(elm) { 
    493495                allElms[size++] = elm; 
     496            } 
    494497        } 
    495498        var relElms = elmIndex.meta; 
    496         for (var r in relElms) { 
    497             if(relElms[r]) 
     499        var r; 
     500        for (r in relElms) { 
     501            if(relElms[r]) { 
    498502                allElms[size++] = relElms[r]; 
     503            } 
    499504        } 
    500505         
    501506        return allElms; 
    502     } 
     507    }; 
    503508     
    504509    /** 
     
    508513     * @final 
    509514     */ 
    510     ControlElements.INDEX_REGEX = /^([^#]+)(#(\w+))?$/; 
     515    ControlElements.INDEX_REGEX = /^([\/\d\w\-_.]+)(#(\w+))?$/; 
    511516     
    512517    /** 
     
    528533            relation: match[3] 
    529534        }; 
    530     } 
     535    }; 
    531536     
    532537    /** 
     
    542547        empty.meta = {}; 
    543548        return empty; 
    544     } 
    545  
    546      ControlElements.newLayoutElements = function() { 
     549    }; 
     550 
     551    ControlElements.newLayoutElements = function() { 
    547552        var empty = []; 
    548553        empty.layout = {}; 
    549554        return empty; 
    550     } 
     555    }; 
    551556 
    552557     
     
    562567     
    563568        return '[' + ControlElements.ATTR_ROLE + '="' + relation + '"]'; 
    564     } 
     569    }; 
    565570     
    566571    /** 
     
    603608            return idfn.apply(this, [index]); 
    604609        } 
    605     } 
     610    }; 
    606611     
    607612     
     
    616621     */ 
    617622    ControlElements.prototype.clearElementIndex = function(index, relation){ 
    618         if (index == undefined)  
    619             return this.elementIndex = {}; 
     623        if (index == undefined) { 
     624            return this.elementIndex; 
     625        } 
    620626         
    621627        return this._operateIndex(index, relation, function(i){ 
     
    626632            delete this.elementIndex[i].meta[r]; 
    627633        }); 
    628     } 
    629  
    630      /** 
    631       * Removes the specified element and relation from the html 
    632       * 
    633       * @param {string} 
    634       *            [index] index to clear. <code>undefined</code> will clear all entries in the whole store. 
    635       * @param {string} 
    636       *            [relation] relation-part to clear. <code>undefined</code> will force extra parsing of the index looking for a 
    637       *            relation part. <code>false</code> will skip index-parsing and clear the array. 
    638       */ 
    639      ControlElements.prototype.removeAndClearElementIndex = function(index, relation){ 
    640          if (index == undefined)  
    641              return; 
     634    }; 
     635 
     636    /** 
     637     * Removes the specified element and relation from the html 
     638     * 
     639     * @param {string} 
     640     *            [index] index to clear. <code>undefined</code> will clear all entries in the whole store. 
     641     * @param {string} 
     642     *            [relation] relation-part to clear. <code>undefined</code> will force extra parsing of the index looking for a 
     643     *            relation part. <code>false</code> will skip index-parsing and clear the array. 
     644     */ 
     645    ControlElements.prototype.removeAndClearElementIndex = function(index, relation){ 
     646        if (index == undefined) {  
     647            return; 
     648        } 
    642649          
    643          if(relation == undefined){ 
    644              if (this.elementIndex[index].meta) { 
    645                  for(var relation in this.elementIndex[index].meta) { 
    646                      this.elementIndex[index].meta[relation].remove(); 
    647                      delete this.elementIndex[index].meta[relation]; 
    648                  } 
    649              } 
    650              delete this.elementIndex[index]; 
    651          } else { 
    652              this.elementIndex[index].meta[relation].remove(); 
    653              delete this.elementIndex[index].meta[relation]; 
    654          } 
    655      } 
     650        if(relation == undefined){ 
     651            if (this.elementIndex[index].meta) { 
     652                var rel; 
     653                for(rel in this.elementIndex[index].meta) { 
     654                    this.elementIndex[index].meta[rel].remove(); 
     655                    delete this.elementIndex[index].meta[rel]; 
     656                } 
     657            } 
     658            delete this.elementIndex[index]; 
     659        } else { 
     660            this.elementIndex[index].meta[relation].remove(); 
     661            delete this.elementIndex[index].meta[relation]; 
     662        } 
     663    }; 
    656664      
    657665      
     
    668676     */ 
    669677    ControlElements.prototype.addElementIndex = function(index, relation, elm){ 
    670         if (arguments.length == 2) { 
     678        if (arguments.length === 2) { 
    671679            elm = relation; 
    672680            relation = undefined; 
     
    677685         
    678686        return this._operateIndex(index, relation, function(i){ 
    679          
    680          
    681687            var elms = this.elementIndex[i] || ControlElements.newElements(); 
    682688            elms[elms.length] = elm; 
     
    684690        }, function(i, r){ 
    685691            var elms = this.elementIndex[i] = this.elementIndex[i] || ControlElements.newElements(); 
    686            //TODO if (elms.meta[r])  
     692            //TODO if (elms.meta[r])  
    687693            //    throw "[ControlElements#addElementIndex] index already in use: " + i + "#" + r; 
    688694             
    689695            elms.meta[r] = elm; 
    690             if (r == ControlElements.REV_ITEM) {// special case: items double as lookup-spaces! 
     696            if (r === ControlElements.REV_ITEM) {// special case: items double as lookup-spaces! 
    691697                elms[elms.length] = elm; 
    692698                this.elementIndex[i] = elms; 
    693699            } 
    694700        }); 
    695     } 
     701    }; 
    696702     
    697703    /** 
     
    705711     */ 
    706712    ControlElements.prototype.getElementIndex = function(index, relation){ 
    707         if (index == undefined)  
     713        if (index == undefined) {  
    708714            return this.elementIndex; 
     715        } 
    709716         
    710717        return this._operateIndex(index, relation, function(i){ 
     
    714721            return this.elementIndex[i].meta[r]; 
    715722        }); 
    716     } 
    717  
    718      /** 
    719       * Removes the specified element from the index. 
    720       * 
    721       * @param {string} 
    722       *            [index] index to remove 
    723       * @param {string} 
    724       *            [relation] relation-part to remove 
    725       * @param (boolean) 
    726       *            [deleteChildren] set to true if you want all children to be deleted as well 
    727       */ 
     723    }; 
     724 
     725    /** 
     726     * Removes the specified element from the index. 
     727     * 
     728     * @param {string} 
     729     *            [index] index to remove 
     730     * @param {string} 
     731     *            [relation] relation-part to remove 
     732     * @param (boolean) 
     733     *            [deleteChildren] set to true if you want all children to be deleted as well 
     734     */ 
    728735    ControlElements.prototype.removeElementIndex = function(index, relation, deleteChildren){ 
    729          deleteChildren = deleteChildren || false; 
     736        deleteChildren = deleteChildren || false; 
    730737          
    731          if (index == undefined)  
    732              return; 
    733  
    734          if(deleteChildren) { 
    735              for(var i in this.elementIndex){ 
    736                  if(i.match("^"+index)==index){ 
    737                      this.removeElementIndex(i, relation, false); 
    738                  } 
    739              } 
    740          }else{ 
    741              if(! relation){ 
    742                  delete this.elementIndex[index]; 
    743              } 
    744              if(this.elementIndex[index] && this.elementIndex[index].meta[relation]){ 
    745                  delete this.elementIndex[index].meta[relation]; 
    746              } 
    747          } 
    748      } 
     738        if (index == undefined) {  
     739            return; 
     740        } 
     741 
     742        if(deleteChildren) { 
     743            var i; 
     744            for(i in this.elementIndex){ 
     745                if(i.match("^"+index)==index){ 
     746                    this.removeElementIndex(i, relation, false); 
     747                } 
     748            } 
     749        } else { 
     750            if(!relation){ 
     751                delete this.elementIndex[index]; 
     752            } 
     753            if(this.elementIndex[index] && this.elementIndex[index].meta[relation]){ 
     754                delete this.elementIndex[index].meta[relation]; 
     755            } 
     756        } 
     757    }; 
    749758 
    750759      
    751      /** 
    752       * Adds the specified element to the index. 
    753       * 
    754       * @param {string} 
    755       *            index index position to add to. 
    756       * @param {string} 
    757       *            [group] the group part we're adding a layout element to 
    758       * @param {$jquery} 
    759       *            elm element to add 
    760       */ 
    761      ControlElements.prototype.addLayoutIndex = function(index, $element){ 
    762          var elms = this.layoutIndex[index] = this.layoutIndex[index] || ControlElements.newLayoutElements(); 
    763          var group = $element.attr(ControlElements.ATTR_LAYOUT_GROUP); 
    764          if(!group){ 
    765              // find available index 
    766              var idx = 0; 
    767              while(elms.group && elms.group[idx]){ 
    768                  idx++; 
    769              } 
    770              group=idx; 
    771          } 
    772  
    773          var layoutgroup = elms.layout[group] = elms.layout[group] || []; 
     760    /** 
     761     * Adds the specified element to the index. 
     762     * 
     763     * @param {string} 
     764     *            index index position to add to. 
     765     * @param {string} 
     766     *            [group] the group part we're adding a layout element to 
     767     * @param {$jquery} 
     768     *            elm element to add 
     769     */ 
     770    ControlElements.prototype.addLayoutIndex = function(index, $element){ 
     771        var elms = this.layoutIndex[index] = this.layoutIndex[index] || ControlElements.newLayoutElements(); 
     772        var group = $element.attr(ControlElements.ATTR_LAYOUT_GROUP); 
     773        if(!group){ 
     774            // find available index 
     775            var idx = 0; 
     776            while(elms.group && elms.group[idx]){ 
     777                idx++; 
     778            } 
     779            group=idx; 
     780        } 
     781 
     782        var layoutgroup = elms.layout[group] = elms.layout[group] || []; 
    774783          
    775          layoutgroup.push($element.clone()); 
     784        layoutgroup.push($element.clone()); 
     785    }; 
     786 
     787    ControlElements.prototype.clearLayoutIndex = function(index){ 
     788        if(this.layoutIndex[index] && this.layoutIndex[index].layout) { 
     789            this.layoutIndex[index].layout = {}; 
     790        } 
     791        if(this.layoutIndex[index] && this.layoutIndex[index].cursor) { 
     792            this.layoutIndex[index].cursor = {};  
     793        } 
     794    }; 
     795 
     796 
     797    ControlElements.prototype.clearCursorIndex = function(index){ 
     798        if(this.layoutIndex[index] && this.layoutIndex[index].cursor) { 
     799            this.layoutIndex[index].cursor = {}; 
     800        } 
     801    }; 
     802 
     803       
     804    /** 
     805     * Gets the specified layout JQuery wrapper element from the index. 
     806     * 
     807     * @param {string} 
     808     *            [index] index to get. <code>undefined</code> will return the whole store. 
     809     * @param {group} 
     810     *            [group] the group layout part to get from the index 
     811     */ 
     812    ControlElements.prototype.getLayoutIndex = function(index, group){ 
     813      
     814        if (index == undefined) { 
     815            return this.layoutIndex; 
     816        } 
    776817          
    777      } 
    778  
    779       ControlElements.prototype.clearLayoutIndex = function(index){ 
    780           if(this.layoutIndex[index] && this.layoutIndex[index].layout) 
    781               this.layoutIndex[index].layout = {}; 
    782           if(this.layoutIndex[index] && this.layoutIndex[index].cursor) 
    783               this.layoutIndex[index].cursor = {};  
    784       } 
    785  
    786  
    787       ControlElements.prototype.clearCursorIndex = function(index){ 
    788           if(this.layoutIndex[index] && this.layoutIndex[index].cursor) 
    789               this.layoutIndex[index].cursor = {}; 
    790       } 
    791  
     818        var $elm; 
     819        //this.layoutIndex[index] = this.layoutIndex[index] || ControlElements.newLayoutElements(); 
     820 
     821        if(this.layoutIndex[index]) { 
     822            if(group == undefined) { 
     823                return this.layoutIndex[index].layout; 
     824            } else {          
     825                return this.layoutIndex[index].layout[group]; 
     826            } 
     827        } else { 
     828            return null; 
     829        } 
     830     }; 
     831 
     832    /** 
     833     * Adds the specified element to the cursor index. 
     834     * 
     835     * @param {string} 
     836     *            index index position to add to. 
     837     * @param {$jquery} 
     838     *            elm element to add 
     839     */ 
     840    ControlElements.prototype.addCursorIndex = function(index, $element, group){ 
     841        var elms = this.cursorIndex[index] = this.cursorIndex[index] || []; 
     842           
     843        if( group === undefined || group === null ){ 
     844            // find available index 
     845            var idx = 0; 
     846            while(elms[idx]){ 
     847                idx++; 
     848            } 
     849            group=idx; 
     850        } 
     851        elms[group] = $element; 
     852    }; 
    792853       
    793      /** 
    794       * Gets the specified layout JQuery wrapper element from the index. 
    795       * 
    796       * @param {string} 
    797       *            [index] index to get. <code>undefined</code> will return the whole store. 
    798       * @param {group} 
    799       *            [group] the group layout part to get from the index 
    800       */ 
    801      ControlElements.prototype.getLayoutIndex = function(index, group){ 
    802       
    803          if (index == undefined)  
    804              return this.layoutIndex; 
    805           
     854    /** 
     855     * Gets the specified layout JQuery wrapper element from the cursor index. 
     856     * 
     857     * @param {string} 
     858     *            [index] index to get. <code>undefined</code> will return the whole store. 
     859     */ 
     860    ControlElements.prototype.getCursorIndex = function(index, group){ 
     861       
    806862         var $elm; 
    807863         //this.layoutIndex[index] = this.layoutIndex[index] || ControlElements.newLayoutElements(); 
    808864 
    809          if(this.layoutIndex[index]) { 
    810               
    811              if(group == undefined) 
    812                  return this.layoutIndex[index].layout; 
    813              else          
    814                  return this.layoutIndex[index].layout[group]; 
    815          }else 
     865         if(this.cursorIndex[index]) { 
     866                
     867             if(group == undefined) { 
     868                 return this.cursorIndex[index][0]; 
     869             } else {          
     870                 return this.cursorIndex[index][group]; 
     871             } 
     872         } else { 
    816873             return null; 
    817       } 
    818  
    819       /** 
    820        * Adds the specified element to the cursor index. 
    821        * 
    822        * @param {string} 
    823        *            index index position to add to. 
    824        * @param {$jquery} 
    825        *            elm element to add 
    826        */ 
    827       ControlElements.prototype.addCursorIndex = function(index, $element, group){ 
    828           var elms = this.cursorIndex[index] = this.cursorIndex[index] || []; 
    829            
    830           if( group == undefined || group == null ){ 
    831               // find available index 
    832               var idx = 0; 
    833               while(elms[idx]){ 
    834                   idx++; 
    835               } 
    836               group=idx; 
    837           } 
    838           elms[group] = $element; 
    839       } 
    840        
    841       /** 
    842        * Gets the specified layout JQuery wrapper element from the cursor index. 
    843        * 
    844        * @param {string} 
    845        *            [index] index to get. <code>undefined</code> will return the whole store. 
    846        */ 
    847       ControlElements.prototype.getCursorIndex = function(index, group){ 
    848        
    849            var $elm; 
    850            //this.layoutIndex[index] = this.layoutIndex[index] || ControlElements.newLayoutElements(); 
    851  
    852            if(this.cursorIndex[index]) { 
    853                 
    854                if(group == undefined) 
    855                    return this.cursorIndex[index][0]; 
    856                else          
    857                    return this.cursorIndex[index][group]; 
    858            }else 
    859                return null; 
    860        } 
     874         } 
     875     }; 
    861876 
    862877 
     
    883898        me._form = form; 
    884899         
    885         if (conf != undefined) 
     900        if (conf != undefined) { 
    886901            me.initialize(conf); 
    887     } 
     902        } 
     903    }; 
    888904     
    889905    /**  
     
    924940        if (conf.isReady) { 
    925941            type = conf; // if a ready type is passed to us, we can just use it 
    926         } 
    927         else { 
     942        } else { 
    928943            type = this.createType(conf); 
    929944        } 
    930945        this.setType(type); 
    931946        this.initType(); 
    932     } 
     947    }; 
    933948     
    934949    Control.prototype.initType = function(conf){ 
    935     } 
     950    }; 
    936951     
    937952    /** 
     
    945960        var types = [conf]; 
    946961         
    947          
    948962        kf.FieldType.createTypes(form, types); 
    949963         
     
    957971     * @private 
    958972     */ 
    959     Control.prototype._templates; 
     973    Control.prototype._templates = null; 
    960974     
    961975    /**  
     
    979993     */ 
    980994    Control.prototype.initElementConfigs = function(){ 
    981      
    982     } 
     995    }; 
    983996     
    984997    /** 
     
    9941007     
    9951008        var elmConfig = this.elements[relation]; 
    996         if (!elmConfig)  
     1009        if (!elmConfig) { 
    9971010            return; 
     1011        } 
    9981012        return elmConfig[attribute]; 
    999     } 
     1013    }; 
    10001014     
    10011015    /** 
     
    10071021    Control.prototype.getTemplate = function(relation){ 
    10081022        var templates = this.templates; 
    1009         if (!templates)  
     1023        if (!templates) {  
    10101024            return; 
     1025        } 
    10111026        return templates[relation]; 
    1012     } 
     1027    }; 
    10131028      
    10141029    /** 
     
    10201035 
    10211036        this.getForm().addElementIndex(this.getAbsoluteId(), relation, $elm); 
    1022     } 
     1037    }; 
    10231038     
    10241039    /** 
     
    10341049        var $elm = form.getElementIndex(index, relation); 
    10351050        if (!$elm) {  
    1036             if(relation == ControlElements.REV_INPUT &&  form.getElementIndex(index).length == 1){ 
     1051            if(relation === ControlElements.REV_INPUT &&  form.getElementIndex(index).length === 1){ 
    10371052                $elm = form.getElementIndex(index)[0]; 
    10381053             
     
    10451060        } 
    10461061        return $elm; 
    1047     } 
     1062    }; 
    10481063     
    10491064     
     
    11191134        this._makeEventHandler("valueChanged"); 
    11201135         
    1121         if ($lbl && $lbl[0].childNodes.length == 0) { 
     1136        if ($lbl && $lbl[0].childNodes.length === 0) { 
    11221137            var label = this.label != null ? this.label : this.getId(); 
    11231138            $lbl.text(locale.getMessage(label)); 
     
    11351150        this.initial = $.extend({enable : true, show : true}, this.initial); 
    11361151 
    1137     } 
     1152    }; 
    11381153     
    11391154    /** 
     
    11411156     */ 
    11421157    Control.prototype._makeEventHandler = function(name, data){ 
    1143         if (name == undefined) return; 
     1158        if (name == undefined) {return; } 
    11441159        name = "" + name; //stringify 
    11451160         
    1146         if (this[name] != undefined) 
     1161        if (this[name] != undefined) { 
    11471162            throw "Can't make eventhandler system for event " + name + ". Property already exists."; 
     1163        } 
    11481164         
    11491165        data = data || {}; 
     
    11541170            return fn ? $this.bind(name, data, fn) : $this.triggerHandler(name); 
    11551171        } 
    1156     } 
     1172    }; 
    11571173     
    11581174    /** 
     
    11641180        } 
    11651181        this.initProperties(); 
    1166     } 
     1182    }; 
    11671183     
    11681184    Control.prototype.initProperties = function(){ 
    1169     } 
     1185    }; 
    11701186 
    11711187     
     
    11761192     */ 
    11771193    Control.prototype.initContainerElements = function(container, create){ 
    1178      
    1179     } 
     1194    }; 
    11801195     
    11811196    /** 
     
    11891204        if (opts) { 
    11901205            var options = kf.Options.create(opts, this.getType()); 
    1191             if (options.toShare())  
     1206            if (options.toShare()) {  
    11921207                options = this.getType().share("options", options); 
     1208            } 
    11931209            this.options = options; 
    11941210             
    11951211            // register for update-callback on the type options 
    11961212            options.update(function(){ 
    1197                 me.updateOptions(options.getValues(), options.readUserValues(), options.getLabels()) 
     1213                me.updateOptions(options.getValues(), options.readUserValues(), options.getLabels()); 
    11981214            }); 
    11991215             
    12001216            // trigger loading the options 
    1201             if (options.getValues() == undefined)  
     1217            if (options.getValues() == undefined) {  
    12021218                options.refresh(); 
    1203             else  
     1219            } else {  
    12041220                this.updateOptions(options.getValues(), options.readUserValues(), options.getLabels()); 
    1205         } 
    1206     } 
     1221            } 
     1222        } 
     1223    }; 
    12071224     
    12081225     
     
    12181235         value = value || this.getValue();  
    12191236        
    1220          var noValidation = (this.valueState == kf.Control.STATE_INIT);  
     1237         var noValidation = (this.valueState === kf.Control.STATE_INIT);  
    12211238         this.setValue(value, noValidation);      
    1222     } 
    1223      
    1224      
     1239    }; 
    12251240     
    12261241     
     
    12311246     */ 
    12321247    Control.prototype.initElements = function(){ 
    1233      
    1234     } 
     1248    }; 
    12351249     
    12361250    /** 
     
    12841298            // register for value-changes by the end-user (change event on main input element) 
    12851299            var notification = function(){ 
    1286              
    1287                 me.update() 
     1300                me.update(); 
    12881301            }; 
    12891302             
     
    12991312            me._initEventWiring(); 
    13001313        }); 
    1301     } 
     1314    }; 
    13021315     
    13031316    /** 
     
    13071320     */ 
    13081321    Control.prototype.initEvents = function(){ 
    1309      
    1310     } 
     1322    }; 
    13111323     
    13121324    Control.prototype._initEventWiring = function(){ 
    13131325        var options = this.options; 
    13141326        if(options){ 
    1315             if (options.toShare() && options.initEventWiringDone) 
     1327            if (options.toShare() && options.initEventWiringDone) { 
    13161328                return; // no need to re-init shared options, avoiding multiple updates when one suffices 
     1329            } 
    13171330             
    13181331            // in all other cases we should loop over dependency-controls 
     
    13201333            var depends = this.depends; 
    13211334            var context = {}; 
    1322             for ( var name in depends) { 
     1335            var name; 
     1336            for ( name in depends) { 
    13231337                var path = depends[name]; 
    13241338                var control = this.findControl(path); 
     
    13341348         
    13351349        this.initEventWiring(); 
    1336     } 
     1350    }; 
    13371351     
    13381352    /** 
     
    13421356     */ 
    13431357    Control.prototype.initEventWiring = function(){ 
    1344          
    1345     } 
     1358    }; 
    13461359     
    13471360    /** 
     
    13521365        var userVal = this.readUserValue(); 
    13531366        this.updateUserValue(userVal); 
    1354     } 
     1367    }; 
    13551368     
    13561369    /** 
     
    13581371     */ 
    13591372    Control.prototype.readUserValue = function(){ 
    1360      
    1361     } // without actual input element to control there is no real value to get. 
     1373    }; // without actual input element to control there is no real value to get. 
    13621374     
    13631375    /** 
     
    13651377     */ 
    13661378    Control.prototype.writeUserValue = function(userValue){ 
    1367      
    1368     } 
     1379    }; 
    13691380     
    13701381    Control.prototype.isEnabled = function(){ 
    13711382        return this.initial.enable; 
    1372     } 
     1383    }; 
    13731384     
    13741385    /** 
     
    14571468    Control.prototype.reset = function() { 
    14581469        Control.reset(this); 
    1459     } 
     1470    }; 
    14601471 
    14611472    Control.reset = function(me) { 
    1462         if( ! (me.value === me.initial.value && me.valueState == Control.STATE_INIT)) {         
     1473        if( ! (me.value === me.initial.value && me.valueState === Control.STATE_INIT)) {         
    14631474            me.setWireValue(me.initial.value, true); 
    14641475        } 
     
    14671478         
    14681479        me.resetShowState();         
    1469     } 
     1480    }; 
    14701481     
    14711482    Control.prototype.resetShowState = function() { 
    14721483        Control.resetShowState(this); 
    1473     } 
     1484    }; 
    14741485 
    14751486    Control.resetShowState = function(me) { 
     
    14851496            me.hide(); 
    14861497        } 
    1487     } 
    1488  
    1489     /** 
    1490     * closes a control 
    1491     */ 
    1492    Control.prototype.close = function() { 
    1493        Control.close(this); 
    1494    } 
    1495  
    1496    Control.close = function(me) { 
    1497        me.getForm().removeAndClearElementIndex(me.getAbsoluteId()); 
    1498    } 
     1498    }; 
     1499 
     1500    /** 
     1501     * closes a control 
     1502     */ 
     1503    Control.prototype.close = function() { 
     1504        Control.close(this); 
     1505    }; 
     1506 
     1507    Control.close = function(me) { 
     1508        me.getForm().removeAndClearElementIndex(me.getAbsoluteId()); 
     1509    }; 
    14991510    
    15001511    /** 
     
    15091520            var value = this.getType().parseUserValue(userValue); 
    15101521            this.setValue(value, noValidation); 
    1511         }  
    1512         catch (e) { 
     1522        } catch (e) { 
    15131523            this.value = undefined; 
    15141524            this.handleValueError(e); 
    15151525            this.valueChanged(); 
    15161526        } 
    1517     } 
     1527    }; 
    15181528     
    15191529    /** 
     
    15261536        this.valueState = Control.STATE_INVALID; 
    15271537        this.setMessage(text); 
    1528     } 
     1538    }; 
    15291539     
    15301540    /** 
     
    15361546    Control.prototype.isValid = function(forceValidation){ 
    15371547        return (Control.isValid(this, forceValidation)); 
    1538     } 
     1548    }; 
    15391549 
    15401550    Control.isValid = function(me, forceValidation){ 
     
    15421552         
    15431553        // force validation if it didn't happen yet 
    1544         if (forceValidation && me.valueState != Control.STATE_INVALID)  
     1554        if (forceValidation && me.valueState !== Control.STATE_INVALID) {  
    15451555            me.newValidation(me.getValue(), me.getWireValue()); 
    1546  
    1547         return (me.valueState == Control.STATE_VALID); 
    1548     } 
     1556        } 
     1557 
     1558        return (me.valueState === Control.STATE_VALID); 
     1559    }; 
    15491560 
    15501561      
     
    15731584            me.setNormalisedValue(value, noValidation); 
    15741585             
    1575         }  
    1576         catch (e) { 
     1586        } catch (e) { 
    15771587            me.handleValueError(e); 
    15781588        } finally { 
     
    15881598        noValidation = noValidation || false; 
    15891599         
    1590         if (this.valueState == Control.STATE_INIT || !this.valueEquals(value) || ( this.valueState == Control.STATE_INVALID && this.value == undefined && value == undefined)) { // in case of change 
     1600        if (this.valueState === Control.STATE_INIT || !this.valueEquals(value) || ( this.valueState === Control.STATE_INVALID && this.value == undefined && value == undefined)) { // in case of change 
    15911601            this.value = value; 
    15921602            try { 
     
    16241634     */ 
    16251635    Control.prototype.normaliseValue = function (value) { 
    1626         return value 
    1627     } 
     1636        return value; 
     1637    }; 
    16281638     
    16291639     
     
    16561666        try { 
    16571667            wireValue = this.getType().toWireValue(value); 
    1658         }  
    1659         catch (e) { 
     1668        } catch (e) { 
    16601669            // keeping it at undefined return 
    16611670        } 
    16621671        return wireValue; 
    1663     } 
     1672    }; 
    16641673     
    16651674    /** 
     
    16711680            var value = this.getType().parseWireValue(wireValue); 
    16721681            this.setOriginalValue(value, noValidation); 
    1673         }  
    1674         catch (e) { 
     1682        } catch (e) { 
    16751683            this.handleValueError(e); 
    16761684        } 
    1677     } 
     1685    }; 
    16781686     
    16791687    /** 
     
    16871695        this.setValue(value, noValidation); 
    16881696        this.originalValueSuppressedByNormalization = this.hasChanges(); // normalization changed the original value! 
    1689     } 
     1697    }; 
    16901698     
    16911699    /** 
     
    16971705     
    16981706        return (!this.valueEquals(this.originalValue)); 
    1699     } 
     1707    }; 
    17001708     
    17011709    /** 
     
    17081716     
    17091717        var thisValue = this.value; 
    1710         if (this.getType().multivalue)  
    1711             return $.valueCompare(thisValue, thatValue) 
     1718        if (this.getType().multivalue) {  
     1719            return $.valueCompare(thisValue, thatValue); 
     1720        } 
    17121721        return (thisValue === thatValue); // will not work for container-controls (array or object values) 
    1713     } 
     1722    }; 
    17141723 
    17151724    /** 
     
    17181727     */ 
    17191728    Control.prototype.newValidation = function(value, wireValue){ 
    1720         if (this.operationalState == Control.STATE_DISABLED) { 
     1729        if (this.operationalState === Control.STATE_DISABLED) { 
    17211730            this.valueState = Control.STATE_VALID; 
    17221731            return; 
    17231732        } 
    1724         if (this.getType().validators.length == 0 ) { 
     1733        if (this.getType().validators.length === 0 ) { 
    17251734            // if there are no validators then we must assume that the control is valid 
    17261735            this.valueState = Control.STATE_VALID; 
     
    17331742        } 
    17341743        this.updateValidationClasses(); 
    1735     } 
     1744    }; 
    17361745     
    17371746    /** 
     
    17451754            options: this.getOptionValues() 
    17461755        }, baseData); 
    1747     } 
     1756    }; 
    17481757     
    17491758    /** 
     
    17531762     */ 
    17541763    Control.prototype.getOptionValues = function(){ 
    1755         if (this.options == undefined || this.options.getValues == undefined)  
     1764        if (this.options == undefined || this.options.getValues == undefined)  
    17561765            return undefined; 
     1766        } 
    17571767        return this.options.getValues(); 
    1758     } 
     1768    }; 
    17591769     
    17601770    /** 
     
    17621772     */ 
    17631773    Control.prototype.validationSuccess = function(){ 
    1764      
    1765     } 
     1774    }; 
    17661775     
    17671776    /** 
     
    17721781        this.validationMessages = []; 
    17731782        this.clearMessage(); 
    1774     } 
     1783    }; 
    17751784     
    17761785    /** 
     
    17821791        var sep = ""; 
    17831792        var last = this.validationMessages.length; 
    1784         if (last == 0) { 
     1793        if (last === 0) { 
    17851794            this.valueState = Control.STATE_VALID; 
    17861795        } 
    17871796        else { 
    1788             for (var i = 0; i < last; i++) { 
     1797            var i; 
     1798            for ( i = 0; i < last; i++) { 
    17891799                var msg = this.validationMessages[i]; 
    17901800                aggr += sep + msg; 
     
    17961806         
    17971807        this.validationFinished(); 
    1798     } 
     1808    }; 
    17991809     
    18001810    /** 
     
    18041814    Control.prototype.validationFail = function(message){ 
    18051815        this.validationMessages[this.validationMessages.length] = message.getText(); 
    1806     } 
     1816    }; 
    18071817     
    18081818    /** 
     
    18181828         
    18191829        this.updateValidationClasses(); 
    1820     } 
     1830    }; 
    18211831     
    18221832    /** 
     
    18251835    Control.prototype.clearMessage = function(){ 
    18261836        this.setMessage(""); 
    1827     } 
     1837    }; 
    18281838 
    18291839    /** 
    18301840     * updates the validation classes to match the outcome of isValid() 
    18311841     */ 
    1832      Control.prototype.updateValidationClasses = function(){ 
    1833           var mrkElm = this.getElement(ControlElements.REV_MARK); 
     1842    Control.prototype.updateValidationClasses = function(){ 
     1843        var mrkElm = this.getElement(ControlElements.REV_MARK); 
    18341844           
    1835           if(mrkElm){ 
    1836               if (this.valueState == Control.STATE_INVALID) { 
    1837                   mrkElm.removeClass("valid").addClass("invalid"); 
    1838               } else if (this.valueState == Control.STATE_VALID) { 
    1839                   mrkElm.removeClass("invalid").addClass("valid"); 
    1840               } else { 
    1841                   mrkElm.removeClass("invalid").removeClass("valid"); 
    1842               } 
    1843           } 
    1844       } 
     1845        if(mrkElm){ 
     1846            if (this.valueState === Control.STATE_INVALID) { 
     1847                mrkElm.removeClass("valid").addClass("invalid"); 
     1848            } else if (this.valueState === Control.STATE_VALID) { 
     1849                mrkElm.removeClass("invalid").addClass("valid"); 
     1850            } else { 
     1851                mrkElm.removeClass("invalid").removeClass("valid"); 
     1852            } 
     1853        } 
     1854    }; 
    18451855      
    18461856    /** 
     
    18631873            var parent = this.getParent(); 
    18641874            var parentId = ""; 
    1865             if (parent)  
     1875            if (parent) { 
    18661876                parentId = parent.getAbsoluteId(); 
     1877            } 
    18671878            var id = this.getId(); 
    18681879            this._absoluteId = $.concatPath(parentId, id); 
    18691880        } 
    18701881        return this._absoluteId; 
    1871     } 
    1872  
    1873     /** 
    1874     * Gets this controls absolute id. This means including all the ids of possible parent controls 
    1875     * @return absolute id or id-path 
    1876     * @type String 
    1877     */ 
    1878    Control.prototype.getGroupId = function(){ 
    1879        if( ! this._groupId ) { 
    1880            var parent = this.getParent(); 
    1881            var parentId = ""; 
    1882            var id = ""; 
     1882    }; 
     1883 
     1884    /** 
     1885     * Gets this controls absolute id. This means including all the ids of possible parent controls 
     1886     * @return absolute id or id-path 
     1887     * @type String 
     1888     */ 
     1889    Control.prototype.getGroupId = function(){ 
     1890        if( ! this._groupId ) { 
     1891            var parent = this.getParent(); 
     1892            var parentId = ""; 
     1893            var id = ""; 
    18831894            
    1884            if (parent)  
    1885                parentId = parent.getGroupId(); 
     1895            if (parent) {  
     1896                parentId = parent.getGroupId(); 
     1897            } 
    18861898                
    1887            if(parent == undefined || !parent.groupChildrenInLayoutIndex) 
    1888                id = $.concatPath(parentId, this.getId()); 
    1889            else  
    1890                id = $.concatPath(parentId, "#"); 
     1899            if(parent == undefined || !parent.groupChildrenInLayoutIndex) { 
     1900                id = $.concatPath(parentId, this.getId()); 
     1901            } else {  
     1902                id = $.concatPath(parentId, "#"); 
     1903            } 
    18911904        
    1892            this._groupId = id; 
    1893        } 
    1894        return this._groupId; 
    1895    } 
     1905            this._groupId = id; 
     1906        } 
     1907        return this._groupId; 
     1908    }; 
    18961909 
    18971910     
     
    19051918    Control.prototype.findControl = function(){ 
    19061919     
    1907         if (arguments.length == 0)  
     1920        if (arguments.length === 0) { 
    19081921            return; 
    1909          
    1910         if (typeof arguments[0] == 'string') { 
     1922        } 
     1923         
     1924        if (typeof arguments[0] === 'string') { 
    19111925            return this._findControlByPath(arguments[0]); 
    1912         } 
    1913         else  
     1926        } else {  
    19141927            if (arguments[0].constructor == Array) { 
    19151928                return this._findControlBySegments(arguments[0]); 
    1916             } 
    1917             else  
     1929            } else {  
    19181930                return; 
    1919     } 
     1931            } 
     1932        } 
     1933    }; 
    19201934     
    19211935    /** 
     
    19271941    Control.prototype._findControlByPath = function(path){ 
    19281942     
    1929         var target = (path.charAt(0) == '/') ? this.getForm() : this; 
     1943        var target = (path.charAt(0) === '/') ? this.getForm() : this; 
    19301944        var segments = path.split('/'); 
    19311945        return target._findControlBySegments(segments); 
    1932     } 
     1946    }; 
    19331947     
    19341948    /** 
     
    19411955     
    19421956        var next = segments.shift(); 
    1943         while (segments.length > 0 && (next == undefined || next.length == 0))  
     1957        while (segments.length > 0 && (next == undefined || next.length === 0)) {  
    19441958            next = segments.shift(); // ignore empty path segments 
     1959        } 
    19451960        var target; 
    1946         if (next == '.' || next == undefined || next.length == 0) // me 
     1961        if (next === '.' || next == undefined || next.length === 0) { // me 
    19471962            target = this; 
    1948         else  
    1949             if (next == '..') // parent 
     1963        } else {  
     1964            if (next === '..') { // parent 
    19501965                target = this.getParent(); 
    1951             else  
     1966            } else {  
    19521967                target = this.getChildByPathSegment(next); // child 
    1953         if (segments.length != 0)  
     1968            } 
     1969        } 
     1970        if (segments.length !== 0) {  
    19541971            return target._findControlBySegments(segments); 
    1955         else  
     1972        } else {  
    19561973            return target; 
    1957     } 
     1974        } 
     1975    }; 
    19581976     
    19591977    Control.prototype.eachElement = function(fn){ 
    1960         if (this._allElements == undefined) 
     1978        if (this._allElements == undefined) { 
    19611979            this._allElements = $(ControlElements.all(this)); 
     1980        } 
    19621981        this._allElements.each(fn); 
    1963     } 
     1982    }; 
    19641983     
    19651984    /** 
     
    19681987    Control.prototype.hide = function(){ 
    19691988        Control.hide(this); 
    1970     } 
     1989    }; 
    19711990     
    19721991    Control.hide = function(me) { 
    19731992        me.eachElement(function() { 
    1974             $(this).hide() 
     1993            $(this).hide(); 
    19751994        }); 
    19761995        me.viewState = Control.STATE_HIDDEN; 
    1977     } 
     1996    }; 
    19781997     
    19791998    /** 
     
    19822001    Control.prototype.show = function(){ 
    19832002        Control.show(this); 
    1984     } 
     2003    }; 
    19852004     
    19862005    Control.show = function (me) { 
    19872006        me.eachElement(function() { 
    1988             $(this).show() 
     2007            $(this).show(); 
    19892008        }); 
    19902009        me.viewState = Control.STATE_VISIBLE; 
    1991     } 
     2010    }; 
    19922011     
    19932012    /** 
     
    19962015    Control.prototype.enable = function(){ 
    19972016        Control.enable(this); 
    1998     } 
     2017    }; 
     2018     
    19992019    Control.enable = function(me) { 
    20002020        me.eachElement(function(){ 
     
    20082028        me.operationalState = Control.STATE_ENABLED; 
    20092029        // If the control isn't in STATE_INIT, we should re-validate to restore validation messages that may have been present when disable() was called 
    2010         if (me.valueState != Control.STATE_INIT) { 
     2030        if (me.valueState !== Control.STATE_INIT) { 
    20112031          me.newValidation(me.getValue(), me.getWireValue()); 
    20122032        } 
    2013     } 
     2033    }; 
    20142034     
    20152035    /** 
     
    20182038    Control.prototype.disable = function(){ 
    20192039        Control.disable(this); 
    2020     } 
     2040    }; 
     2041     
    20212042    Control.disable = function(me) { 
    20222043        me.eachElement(function(){ 
     
    20312052        me.updateValidationClasses(); 
    20322053        me.operationalState = Control.STATE_DISABLED; 
    2033     } 
     2054    }; 
    20342055     
    20352056    /* 
     
    20442065     
    20452066        return this._id; 
    2046     } 
     2067    }; 
    20472068     
    20482069    /** 
     
    20542075     
    20552076        return this._form; 
    2056     } 
     2077    }; 
    20572078     
    20582079    /** 
     
    20732094     
    20742095        return this._type; 
    2075     } 
     2096    }; 
    20762097     
    20772098    /**  
     
    20822103     * @type Control 
    20832104     */ 
    2084     Control.prototype.getParent = function(){ } 
     2105    Control.prototype.getParent = function(){  
     2106    }; 
    20852107     
    20862108    /**  
     
    20952117            this[meth].apply(this, args); 
    20962118        } 
    2097     } 
    2098      
    2099      
    2100     $.inherit(AbstractContainerControl, Control); 
     2119    }; 
     2120     
     2121     
    21012122     
    21022123    /** 
     
    21122133        Control.init(this, id, form, conf); 
    21132134    } 
    2114  
     2135    $.inherit(AbstractContainerControl, Control); 
     2136 
     2137 
     2138    $.extend(kf, { 
     2139        ControlElements: ControlElements, 
     2140        Control: Control, 
     2141        AbstractContainerControl: AbstractContainerControl 
     2142    }); 
     2143     
    21152144    /** 
    21162145     * Creates a blank value 
     
    21542183        //else 
    21552184        var children = this.getChildren(includeAll); 
     2185        var i, child; 
    21562186        if (!stopable) { 
    2157             for (var i in children) { 
    2158                 var child = children[i]; 
     2187            for (i in children) { 
     2188                child = children[i]; 
    21592189                if (child) { 
    21602190                    fn(i, child); 
     
    21622192            } 
    21632193        } else { 
    2164             for (var i in children) { 
    2165                 var child = children[i];  
     2194            for (i in children) { 
     2195                child = children[i];  
    21662196                if (child) { 
    21672197                    var stop = fn(i, child); 
    2168                     if (stop) return stop; 
     2198                    if (stop) { return stop;} 
    21692199                } 
    21702200            } 
     
    21762206        this.eachChild(function(i, child){ child.hide();}); 
    21772207        Control.hide(this); 
    2178     } 
     2208    }; 
    21792209     
    21802210    AbstractContainerControl.prototype.show = function(){ 
    21812211        this.eachChild(function(i, child){ child.show();}); 
    21822212        Control.show(this); 
    2183     } 
     2213    }; 
    21842214 
    21852215    AbstractContainerControl.prototype.disable = function() { 
     
    22132243                isBlank = false; 
    22142244            }             
    2215         }  
     2245        };  
    22162246        this.eachChild(cfn); 
    22172247         
    2218         if (isBlank) value = undefined; 
     2248        if (isBlank) {  
     2249            value = undefined;  
     2250        } 
    22192251         
    22202252        return value; 
     
    22882320     */ 
    22892321    AbstractContainerControl.prototype.getValue = function(){ 
    2290         if (this.value == CLEAR){ 
     2322        if (this.value === CLEAR) { 
    22912323            this.value = this.getLoop(AbstractContainerControl.childGetter); 
    22922324        } 
     
    23072339    AbstractContainerControl.childSetter = function(i, child, value, noValidation) { 
    23082340        return child.setValue(value, noValidation); 
    2309     } 
     2341    }; 
    23102342     
    23112343    /** 
     
    23152347     */ 
    23162348    AbstractContainerControl.prototype.getWireValue = function(){ 
    2317         if (this.cachedWireValue == CLEAR) { 
     2349        if (this.cachedWireValue === CLEAR) { 
    23182350            var w = this.getLoop(AbstractContainerControl.childWireGetter);   
    23192351            this.cachedWireValue = this.getType().toWireValue(w); // allow composite-type specific formatting (merge) 
     
    23792411        this.getChild(childId).close(); 
    23802412        delete this.getChildren()[childId]; 
    2381     } 
     2413    }; 
    23822414     
    23832415    AbstractContainerControl.prototype.removeChildren = function() { 
    23842416        var children = this.getChildren(); 
    23852417        var toRemove = []; 
    2386          
    2387         for (var i in children) { 
     2418        var i; 
     2419        for (i in children) { 
    23882420            var child = children[i]; 
    23892421            toRemove.push(children[i]); 
    23902422        } 
    23912423         
    2392         for (var i in toRemove) { 
     2424        for (i in toRemove) { 
    23932425            this.removeChild(toRemove[i].getId()); 
    23942426        } 
    23952427         
    2396     } 
     2428    }; 
    23972429 
    23982430      
    2399      /** 
     2431    /** 
    24002432     * Sets the original value of the control (This doesn't do anything) 
    24012433     * @param {Object} value 
    24022434     */ 
    24032435    AbstractContainerControl.prototype.setOriginalValue = function(value){ 
    2404     } 
     2436    }; 
    24052437     
    24062438    /** 
     
    24152447    AbstractContainerControl.childHasChanges = function(i, child) { 
    24162448        return child.hasChanges(); 
    2417     } 
     2449    }; 
    24182450     
    24192451     
     
    24252457     
    24262458        return; // undefined, which is always seen as 'false' which will silence value-changed events 
    2427     } 
     2459    }; 
    24282460     
    24292461    /** 
     
    24352467    AbstractContainerControl.prototype.getChildren = function(){ 
    24362468        return AbstractContainerControl.getChildren(this); 
    2437     } 
     2469    }; 
    24382470    AbstractContainerControl.getChildren = function(me) { 
    24392471        return me._children; 
    2440     } 
     2472    }; 
    24412473     
    24422474    /** 
     
    24482480    AbstractContainerControl.prototype.getChild = function(id){ 
    24492481        return AbstractContainerControl.getChild(this, id); 
    2450     } 
     2482    }; 
    24512483    AbstractContainerControl.getChild = function (me, id) { 
    24522484        return me._children[id]; 
    2453     } 
     2485    }; 
    24542486    AbstractContainerControl.prototype.getChildByPathSegment = function(pathSegment){ 
    24552487        return this._children[pathSegment]; 
    2456     } 
     2488    }; 
    24572489     
    24582490    /** 
     
    24862518         } 
    24872519          
    2488     } 
     2520    }; 
    24892521     
    24902522 
     
    25122544        var form = this.getForm(); 
    25132545        var elements = form.getElementIndex(newIndex); 
    2514         if (elements && (elements.length > 0 || elements.meta[ControlElements.REV_INPUT] || elements.meta[ControlElements.REV_CONTROL]))  
     2546        if (elements && (elements.length > 0 || elements.meta[ControlElements.REV_INPUT] || elements.meta[ControlElements.REV_CONTROL])) {  
    25152547            return elements; // no need to create new elements 
     2548        } 
    25162549         
    25172550        var newElements; 
    25182551        var newElementsArray = []; 
    25192552 
    2520         var form = this.getForm(); 
    25212553        var parentGroupId = this.getGroupId(); 
    25222554        var groupId = ""; 
    2523         if ( this.groupChildrenInLayoutIndex )  
     2555        if ( this.groupChildrenInLayoutIndex ) {  
    25242556            groupId = $.concatPath(parentGroupId, "#"); 
    2525         else 
     2557        } else { 
    25262558            groupId = $.concatPath(parentGroupId, id); 
     2559        } 
    25272560        var containerId = this.getId(); 
    25282561        var cloneId = absoluteId + "(" + groupId + ")"; 
     
    25302563 
    25312564        var kauriSelector = "[kauri-role],[kauri-id]"; 
    2532         var setIdRef = function($elt, id){ 
     2565        var setIdRef; 
     2566        setIdRef = function($elt, id){ 
    25332567            if($elt.is(kauriSelector)){ 
    25342568                $elt.attr(ControlElements.ATTR_IDREF, id); 
    25352569            } else { 
    25362570                $elt.children().each(function(a,b) { 
    2537                     setIdRef($(b),id) 
     2571                    setIdRef($(b),id); 
    25382572                }); 
    25392573            } 
    2540         } 
     2574        }; 
    25412575         
    25422576        // determine position to insert layout clone 
     
    25502584        if(position) { 
    25512585            var clones = $("[kauri-layout-clone='" + cloneId + "']", container); 
    2552             if( clones.length > 0 && position <= clones.length) 
     2586            if( clones.length > 0 && position <= clones.length) { 
    25532587                cursor = clones[position]; 
     2588            } 
    25542589        } 
    25552590         
     
    25612596            }); 
    25622597             
    2563             if(cursor) 
     2598            if(cursor) { 
    25642599                newElements = $layoutClone.insertBefore(cursor); 
    2565             else { 
     2600            } else { 
    25662601                container.append($layoutClone); 
    25672602                newElements = $layoutClone; 
     
    25692604            ControlElements.index($layoutClone, form, absoluteId); 
    25702605            newElementsArray.push(newElements); 
    2571         }else{ 
     2606        } else { 
    25722607            // clone each element in layout group 
    25732608            $.each($layoutGroups, function(layoutGroupId, eltArray){ 
     
    25892624 
    25902625        return newElementsArray; 
    2591     } 
    2592      
     2626    }; 
    25932627    AbstractContainerControl.prototype.createChildElements = function(id, container, layout){ 
    25942628        throw "[AbstractContainerControl#createChildElements] No container or layout to work with."; 
    2595     } 
     2629    }; 
     2630     
    25962631    /** 
    25972632     * Creates a new control based on type but doesn't add it to the list of children 
     
    26052640     */ 
    26062641    AbstractContainerControl.prototype.createChildControl = function(id, type, position){ 
    2607          if (type == undefined)  
    2608              throw "[AbstractContainerControl.createChildControl] Unknown type for member: " + id + " of control " + 
    2609              this.getAbsoluteId(); 
     2642         if (type == undefined) { 
     2643             throw "[AbstractContainerControl.createChildControl] Unknown type for member: " + id + " of control " + this.getAbsoluteId(); 
     2644         } 
    26102645 
    26112646         var controlType = type.control; 
     
    26132648         
    26142649         if (!(type.control && type.control.isReady)) { 
    2615             if (typeof type.control == 'string') { 
     2650            if (typeof type.control === 'string') { 
    26162651                controlType = type.control; 
    2617             } else if (type.control.constructor == Array) { 
     2652            } else if (type.control.constructor === Array) { 
    26182653                controlType = type.control[0]; 
    26192654                extender = type.control[1]; 
    26202655            } else { // item = {base:'string', ...extensions.. } 
    26212656                controlType = type.control.base; 
    2622                 if(controlType==undefined) 
     2657                if(controlType==undefined) { 
    26232658                    controlType='composite-control'; 
     2659                } 
    26242660                extender = type.control; 
    26252661            } 
    26262662        } 
    26272663         
    2628         if (controlType == undefined)  
    2629             throw "[AbstractContainerControl.createChildControl] Unknown controlType for member: " + id + " of control " + 
    2630             this.getAbsoluteId(); 
     2664        if (controlType == undefined) {  
     2665            throw "[AbstractContainerControl.createChildControl] Unknown controlType for member: " + id + " of control " + this.getAbsoluteId(); 
     2666        } 
    26312667             
    26322668        this._createChildElements(id, position); // ensure the needed html elements for this new child are available. 
     
    26452681         
    26462682        var childChanged = function(){ 
    2647          
    26482683            me.updateValue(); 
    2649              
    2650         } 
     2684        }; 
    26512685         
    26522686        childControl.valueChanged(childChanged); 
    26532687 
    26542688        return childControl; 
    2655     } 
     2689    }; 
    26562690     
    26572691    /** 
     
    26642698        this._children[id] = childControl; 
    26652699        this.updateValue(true, true); // be sure to handle change in value structure 
    2666     } 
     2700    }; 
    26672701 
    26682702    /** 
     
    26742708        delete this._children[id]; 
    26752709        this.updateValue(true, true); // be sure to handle change in value structure 
    2676     } 
     2710    }; 
    26772711 
    26782712      
     
    26992733        } 
    27002734        this.valueChanged();         // and notify parent 
    2701      } 
     2735    }; 
    27022736      
    27032737    /** 
     
    27112745         
    27122746        this.updateValue = restoreUpdateFn; 
    2713     }   
     2747    };  
    27142748     
    27152749    /** 
     
    27192753    AbstractContainerControl.prototype.isValid = function(forceValidation){ 
    27202754        return AbstractContainerControl.isValid(this, forceValidation); 
    2721     } 
     2755    }; 
    27222756 
    27232757    /** 
     
    27292763        // if we're not valid at this level then it's no use checking the children 
    27302764        if (valid) { 
    2731             for (var i in me._children) { 
     2765            var i; 
     2766            for (i in me._children) { 
    27322767                valid = (me._children[i] != undefined) && me._children[i].isValid(forceValidation) && valid; 
    27332768            } 
     
    27352770         
    27362771        return valid; 
    2737     } 
     2772    }; 
    27382773 
    27392774    AbstractContainerControl.prototype.delegates = true; 
     
    27412776        var args = arguments; 
    27422777        this.eachChild(function(i, child) { 
    2743             if (child.delegates) 
    2744                 child.delegate.apply(child, args);  
     2778            if (child.delegates) { 
     2779                child.delegate.apply(child, args); 
     2780            } 
    27452781        }, false, true); 
    2746     } 
     2782    }; 
    27472783      
    27482784       
     
    27512787    };      
    27522788 
    2753 })(jQuery); 
     2789     
     2790}(jQuery)); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/date.js

    r1920 r1948  
     1/* jslint eqeq: true */ 
    12/** 
    23 * @fileOverview This file holds the fieldtype and controltype for handling composition-data-structures. 
     
    56( function( $) { 
    67 
    7     if (!$) 
     8    if (!$) { 
    89        throw "[date.js] requires jQuery"; 
    9     if (!$.org.kauriproject.forms) 
     10    } 
     11    if (!$.org.kauriproject.forms) { 
    1012        throw "[date.js] requires the kauri-form namespace"; 
    11     if (!$.datepicker) 
     13    } 
     14    if (!$.datepicker) { 
    1215        throw "[date.js] requires jQuery UI datepicker"; 
     16    } 
    1317 
    1418    var kf = $.org.kauriproject.forms; 
     
    2226    function padZero (val) { 
    2327        var s = "" + val; 
    24         return ( (s.length == 1)  ?  ("0" + s) : s ); 
     28        return ( (s.length === 1)  ?  ("0" + s) : s ); 
    2529    } 
    2630     
    2731    function asTimeNumber(numStr, max) { 
    28         if (numStr === undefined)  
     32        if (numStr === undefined) {  
    2933            return 0; 
     34        } 
    3035         
    3136        max = max || 60; // default 
    3237        var num = new Number(numStr); 
    33         if (isNaN(num) || num > max || num < 0) 
     38        if (isNaN(num) || num > max || num < 0) { 
    3439            return undefined;     
    35         return num  
     40        } 
     41        return num;  
    3642    } 
    3743 
     
    6268             
    6369            format : function( val) { 
    64                 if (val == undefined) 
     70                if (val == undefined) { 
    6571                    return ""; 
    66                 if (val.constructor != Date) 
     72                } 
     73                if (val.constructor !== Date) { 
    6774                    this.fail("Not a Date: {0}.", [val]); 
     75                } 
    6876     
    6977                return $.datepicker.formatDate(this.pattern, val);                 
     
    7179             
    7280            parse : function(valstr) {       
    73                 if (typeof valstr == 'string') {  
     81                if (typeof valstr === 'string') {  
    7482                    valstr = $.trim(valstr);  
    75                     if (valstr.length == 0)  
     83                    if (valstr.length === 0) {  
    7684                        return undefined;  
     85                    } 
    7786                         
    7887                    try { 
     
    94103            format : function (val) { 
    95104 
    96                 if (val == undefined )  
     105                if (val == undefined ) {  
    97106                    return undefined; 
    98                  
    99                 if (val.date == undefined) 
     107                } 
     108                 
     109                if (val.date == undefined) { 
    100110                    this.fail("Not a valid date-time structure. Missing date part." ); 
     111                } 
    101112                 
    102113                var datePart = val.date; 
     
    109120            parse : function(valstr) {      
    110121                var parts;  
    111                 if (typeof valstr == 'string') {  
     122                if (typeof valstr === 'string') {  
    112123                    valstr = $.trim(valstr);  
    113                     if (valstr.length == 0)  
     124                    if (valstr.length === 0) {  
    114125                        return undefined; 
     126                    } 
    115127                          
    116128                    parts = valstr.split(this.timeSeparator); 
    117                 } else if (valstr.constructor == Array) { 
     129                } else if (valstr.constructor === Array) { 
    118130                    parts = valstr; 
    119131                }     
    120132                  
    121                 if (parts === undefined || parts.length != 2) { 
     133                if (parts === undefined || parts.length !== 2) { 
    122134                    this.fail( "Could not parse the date-range: " + valstr );          
    123135                } 
    124136                 
    125137                var result = {}; 
    126                 if (parts[0] !== undefined) { result.date = parts[0] }; 
    127                 if (parts[1] !== undefined) { result.time = parts[1] }; 
     138                if (parts[0] !== undefined) { result.date = parts[0]; } 
     139                if (parts[1] !== undefined) { result.time = parts[1]; } 
    128140                 
    129141                return  result; 
     
    135147            rangeSeparator : "/", 
    136148            format : function (val) { 
    137                 if (val === undefined || (val.start === undefined && val.end === undefined))  
     149                if (val === undefined || (val.start === undefined && val.end === undefined)) {  
    138150                    return undefined; 
     151                } 
    139152                 
    140153                return "" + val.start + this.rangeSeparator + val.end; 
     
    142155            parse : function(valstr) {      
    143156                var parts;  
    144                 if (typeof valstr == 'string') {  
     157                if (typeof valstr === 'string') {  
    145158                    valstr = $.trim(valstr);  
    146                     if (valstr.length == 0)  
     159                    if (valstr.length === 0) { 
    147160                        return undefined; 
     161                    } 
    148162                          
    149163                    parts = valstr.split(this.rangeSeparator); 
    150                  } else if (valstr.constructor == Array) { 
     164                 } else if (valstr.constructor === Array) { 
    151165                    parts = valstr; 
    152166                 }     
    153167                  
    154                  if (parts === undefined || parts.length != 2) { 
     168                 if (parts === undefined || parts.length !== 2) { 
    155169                     this.fail( "Could not parse the date-range: " + valstr );          
    156170                 }    
    157171                 var result = {}; 
    158                  if (parts[0] !== undefined) { result.start = parts[0] }; 
    159                  if (parts[1] !== undefined) { result.end = parts[1] }; 
     172                 if (parts[0] !== undefined) { result.start = parts[0]; } 
     173                 if (parts[1] !== undefined) { result.end   = parts[1]; } 
    160174                  
    161175                 return  result; 
     
    167181 
    168182            format : function (val) { 
    169                 if (val == undefined) 
     183                if (val == undefined) { 
    170184                    return ""; 
    171                 if (val.constructor != Date) 
     185                } 
     186                if (val.constructor !== Date) { 
    172187                    this.fail("Not a Date: {0}.", [val]); 
     188                } 
    173189                     
    174190                return formatTime(val); 
    175191            }, 
    176192            parse : function (valstr) { 
    177                 if (typeof valstr == 'string') {  
     193                if (typeof valstr === 'string') {  
    178194                    valstr = $.trim(valstr);  
    179                     if (valstr.length == 0)  
     195                    if (valstr.length === 0) {  
    180196                        return undefined;  
     197                    } 
    181198                     
    182199                    var parsedTime = parseTime(valstr); 
     
    203220            patterns : [$.datepicker.ISO_8601,"dd/mm/yy"], 
    204221            validate : function(value) { 
    205                 if ($.isEmpty(value)) 
    206                         return this.notifySuccess(); 
     222                if ($.isEmpty(value)) { 
     223                    return this.notifySuccess(); 
     224                } 
    207225     
    208226                // any date object is considered A OK 
    209                 if (value.constructor == Date) 
    210                     return this.notifySuccess(); 
     227                if (value.constructor === Date) { 
     228                    return this.notifySuccess(); 
     229                } 
    211230                     
    212231                // if we are dealing with strings then lets give 'em a good 'ol parsin' to see if all 's well 
    213                 if (typeof value == "string") { 
     232                if (typeof value === "string") { 
    214233                    var ok = false; 
    215                     for (var i = 0; i < this.patterns.length && !ok; i++) { 
     234                    var i; 
     235                    for (i = 0; i < this.patterns.length && !ok; i++) { 
    216236                        try { 
    217237                            $.datepicker.parseDate(this.patterns[i], value); 
     
    222242                    } 
    223243                     
    224                     if (ok) 
     244                    if (ok) { 
    225245                        return this.notifySuccess(); 
     246                    } 
    226247                }    
    227248         
     
    234255            strict : false, 
    235256            validate : function (value) { 
    236                 if ($.isEmpty(value)) 
    237                     return this.notifySuccess(); 
    238                 if ($.isEmpty(value.start)) 
    239                     return this.notifySuccess(); 
    240                 if ($.isEmpty(value.end)) 
    241                     return this.notifySuccess(); 
     257                if ($.isEmpty(value)) { 
     258                    return this.notifySuccess(); 
     259                } 
     260                if ($.isEmpty(value.start)) { 
     261                    return this.notifySuccess(); 
     262                } 
     263                if ($.isEmpty(value.end)) { 
     264                    return this.notifySuccess(); 
     265                } 
    242266             
    243267                // the child controls should have ensured that value holds two actual dates. 
    244268 
    245                 if (this.order == "asc" && this.strict) { 
     269                if (this.order === "asc" && this.strict) { 
    246270                    if (value.start >= value.end) { 
    247271                        this.notifyFail("The first date must be strictly before the second one"); 
    248272                    } 
    249                 } else if (this.order == "asc" && !this.strict) { 
     273                } else if (this.order === "asc" && !this.strict) { 
    250274                    if (value.start > value.end) { 
    251275                        this.notifyFail("The first date must be before the second one"); 
    252276                    } 
    253                 } else if (this.order == "desc" && this.strict) { 
     277                } else if (this.order === "desc" && this.strict) { 
    254278                    if (value.start <= value.end) { 
    255279                        this.notifyFail("The first date must be strictly after the second one"); 
    256280                    } 
    257                 } else if (this.order == "desc" && !this.strict) { 
     281                } else if (this.order === "desc" && !this.strict) { 
    258282                    if (value.start < value.end) { 
    259283                        this.notifyFail("The first date must be after the second one"); 
     
    269293            maxDate : undefined, // maximum date 
    270294            validate : function (value) { 
    271                 if ($.isEmpty(value)) 
    272                     return this.notifySuccess(); 
     295                if ($.isEmpty(value)) { 
     296                    return this.notifySuccess(); 
     297                } 
    273298             
    274                 if (value.constructor != Date) 
     299                if (value.constructor != Date) { 
    275300                    return this.notifyFail(value + " is not a Date Object"); 
    276                  
    277                 if (((this.minDate != undefined) && value < this.minDate) || ((this.maxDate != undefined) && value > this.maxDate) ) 
     301                } 
     302                 
     303                if (((this.minDate != undefined) && value < this.minDate) || ((this.maxDate != undefined) && value > this.maxDate) ) { 
    278304                    return this.notifyFail("i18n:Should be between {0} and {1}", [ this.minDate, this.maxDate ]); 
     305                } 
    279306 
    280307                return this.notifySuccess();                 
     
    286313            _days : ["sunday","monday","tuesday","wednesday","thursday","friday","saturday"], 
    287314            validate : function (value) { 
    288                 if (this.dayOfWeek < 0 && this.dayOfWeek > 6) 
     315                if (this.dayOfWeek < 0 && this.dayOfWeek > 6) { 
    289316                    return this.notifyFail("The parameter 'dayOfWeek' must be a number between 0 and 6"); 
    290                      
    291                 if ($.isEmpty(value)) 
    292                     return this.notifySuccess(); 
     317                } 
     318                     
     319                if ($.isEmpty(value)) { 
     320                    return this.notifySuccess(); 
     321                } 
    293322             
    294                 if (value.constructor != Date) 
     323                if (value.constructor !== Date) { 
    295324                    return this.notifyFail(value + " is not a Date Object"); 
    296                      
    297                 if (value.getDay() == this.dayOfWeek) 
    298                     return this.notifySuccess(); 
     325                } 
     326                     
     327                if (value.getDay() === this.dayOfWeek) { 
     328                    return this.notifySuccess(); 
     329                } 
    299330                 
    300331                return this.notifyFail(value + " is not a " + this._days[this.dayOfWeek] ); 
     
    340371    }); 
    341372 
    342     $.inherit(DateControl, kf.Control); 
    343373    function DateControl( id, form, conf) { 
    344374        kf.Control.init(this, id, form, conf); 
    345375    } 
     376    $.inherit(DateControl, kf.Control); 
    346377     
    347378    DateControl.prototype.staticResourceUri = "../../main/kauri/static/"; //default for source based testing - injected dynamically through headerlinks.xml 
     
    369400        var type = this.getType(); 
    370401         
    371         type.readonly && $input.attr("readonly", type.readonly); 
     402        if (type.readonly) { 
     403            $input.attr("readonly", type.readonly); 
     404        } 
    372405         
    373406        if (this.useDatePicker) { 
     
    407440            this.useDatePicker = this.getType().useDatePicker; 
    408441        } 
    409              
    410     } 
     442    }; 
     443     
    411444    DateControl.prototype.readUserValue = function() { 
    412445 
    413446        return this._input.val(); 
    414     } 
     447    }; 
    415448 
    416449    DateControl.prototype.writeUserValue = function( value) { 
     
    418451        value = value || ""; 
    419452        this._input.val(value); 
    420     } 
     453    }; 
    421454     
    422455    DateControl.prototype.enable = function(){ 
    423         kf.Control.enable(this); 
    424         if(this.useDatePicker) { 
    425             this.getElement().datepicker("enable"); 
    426         } 
    427     } 
     456        kf.Control.enable(this); 
     457        if(this.useDatePicker) { 
     458            this.getElement().datepicker("enable"); 
     459        } 
     460    }; 
    428461     
    429462    DateControl.prototype.disable = function(){ 
    430         kf.Control.disable(this); 
    431         if(this.useDatePicker) { 
    432             this.getElement().datepicker("disable"); 
    433         } 
    434     } 
     463        kf.Control.disable(this); 
     464        if(this.useDatePicker) { 
     465            this.getElement().datepicker("disable"); 
     466        } 
     467    }; 
    435468     
    436469    controlTypes.put( "date-control", DateControl); 
    437470 
    438     $.inherit(DateRangeControl, kf.CompositeControl); 
    439471    function DateRangeControl( id, container, form, conf) { 
    440472        kf.Control.init(this, id, container, form, conf); 
     
    443475            this.forceOrder = "asc"; 
    444476        } 
    445     }; 
     477    } 
     478    $.inherit(DateRangeControl, kf.CompositeControl); 
     479 
     480     
    446481    DateRangeControl.prototype.initProperties = function() { 
    447     } 
     482    }; 
     483     
    448484    DateRangeControl.prototype.normaliseValue = function(value) { 
    449485      if (value && value.start && value.end) { 
    450         if (this.forceOrder == "asc") { 
     486        if (this.forceOrder === "asc") { 
    451487          if (value.start > value.end) { 
    452488            value = { start: value.end, end: value.start }; 
    453489          } 
    454         } else if (this.forceOrder == "desc") { 
     490        } else if (this.forceOrder === "desc") { 
    455491          if (value.start < value.end) { 
    456492            value = { start: value.end, end: value.start }; 
     
    462498    }; 
    463499    controlTypes.put( "date-range-control", DateRangeControl); 
    464 })(jQuery); 
     500}(jQuery)); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/field.js

    r1922 r1948  
     1/* jslint eqeq: true */ 
    12/** 
    23 * @fileOverview This file holds the basic structure of the fields composing the forms 
     
    56( function( $) { 
    67 
    7     if (!$) 
     8    if (!$) { 
    89        throw "[fields.js] requires jQuery"; 
    9     if (!$.org.kauriproject.forms) 
     10    } 
     11    if (!$.org.kauriproject.forms) { 
    1012        throw "[fields.js] requires the kauri-form namespace"; 
     13    } 
    1114 
    1215    var kp = $.org.kauriproject; 
    1316    var kf = $.org.kauriproject.forms; 
    14  
    15     $.extend(kf, { 
    16         Options: Options,  
    17         FieldType :FieldType 
    18     }); 
    1917 
    2018 
     
    5654        Options.createTemplate(opts, "labelTemplate"); 
    5755         
    58         if (type !== undefined) 
     56        if (type !== undefined) { 
    5957            opts.type = type; 
     58        } 
    6059         
    6160        if (opts.data) { 
     
    7372    */ 
    7473    Options.createTemplate = function(opts, name) { 
    75         if (opts[name] == undefined) return; 
     74        if (opts[name] == undefined) { return; } 
    7675        opts[name] = new kp.UriTemplate(opts[name], {skipEscape: true}); 
    77     } 
     76    }; 
    7877     
    7978    /**  
     
    8483    Options.prototype.refreshable = function() { 
    8584        return (this.uri != undefined); 
    86     } 
     85    }; 
    8786      
    8887    /**  
     
    9392    Options.prototype.updateable = function() { 
    9493        return this.refreshable() || (!this.fixed); 
    95     } 
     94    }; 
    9695       
    9796    /**  
     
    103102 
    104103        return (this.shared); 
    105     } 
     104    }; 
    106105     
    107106    /**  
     
    113112 
    114113        return this.values; 
    115     } 
     114    }; 
    116115 
    117116    Options.prototype.trimValues = function(values) { 
    118         if (values == undefined || this.values == undefined) return undefined; 
    119         if (values.constructor != Array) { 
     117        if (values == undefined || this.values == undefined) { return undefined; } 
     118        if (values.constructor !== Array) { 
    120119            var wrapped = this.trimValues([values]); //wrap 
    121120            return (wrapped != undefined) ? wrapped[0] : undefined; // unwrap 
     
    123122         
    124123        var result = [];  
    125         for (var i = 0; i< values.length; i++) { 
     124        var i; 
     125        for (i = 0; i< values.length; i++) { 
    126126            var testvalue = values[i]; 
    127127            if ($.valueInArray(testvalue, this.values) >= 0) { 
     
    129129            } 
    130130        } 
    131         return (result.length == 0 ) ? undefined : result; 
    132     } 
     131        return (result.length === 0 ) ? undefined : result; 
     132    }; 
    133133     
    134134     
     
    141141 
    142142        return this.userValues; 
    143     } 
     143    }; 
    144144     
    145145    /**  
     
    151151 
    152152        return this.labels; 
    153     } 
     153    }; 
    154154     
    155155    /** 
     
    159159    */ 
    160160    Options.prototype.set = function( values, labels) { 
    161         values = $.extend([], values); //clone to avoid issue #464 
    162         labels = labels ? $.extend([], labels) : null; 
    163          
     161        values = $.extend([], values); //clone to avoid issue #464 
     162        labels = labels ? $.extend([], labels) : null; 
     163 
     164        var i; 
     165         
    164166        if (this.type) { 
    165             this.userValues = new Array(); 
     167            this.userValues = []; 
    166168            var last = values ? values.length : 0; 
    167             for(var i = 0; i< last; i++) 
    168                 if (typeof values[i] == 'string' ) 
     169            for(i = 0; i< last; i++) 
     170                if (typeof values[i] === 'string' ) { 
    169171                    this.userValues[i] = values[i]; 
    170                 else 
     172                } else { 
    171173                    this.userValues[i] = this.type.toUserValue(values[i]); 
    172         }else{ 
     174                } 
     175        } else { 
    173176            this.userValues = values; // values in user-format if no type defined default to values 
    174177        } 
    175178         
    176179        // set the labels , use userValues for this 
    177         if(this.userValues != undefined) 
     180        if(this.userValues != undefined) { 
    178181            labels = labels || this.userValues.slice(); 
     182        } 
    179183 
    180184        if (this.nullable) { 
    181             for (var i = values.length; i>0; i--) { 
     185            for (i = values.length; i>0; i--) { 
    182186                values[i] = values[i-1]; 
    183187                labels[i] = labels[i-1]; 
     
    189193        } 
    190194 
    191         this.values = values; 
     195        this.values = values; 
    192196        this.labels = labels;         
    193197         
    194198        this.update(); 
    195     } 
     199    }; 
    196200 
    197201    /**  
     
    208212    Options.prototype.update = function( fn) { 
    209213 
    210         if (!this.updateable()) return; 
     214        if (!this.updateable()) { return; } 
    211215         
    212216        return (fn) ? $(this).bind("update", {options :this.values}, fn) : $(this).triggerHandler("update"); 
    213     } 
     217    }; 
    214218     
    215219    /** 
     
    223227            var me = this; 
    224228            var onSuccess = function( data, status, xhr) { 
    225                 if (xhr && me.lastXhr == xhr) { //ignore responses that are not linked to the last request  
     229                if (xhr && me.lastXhr === xhr) { //ignore responses that are not linked to the last request  
    226230                    me.parseOptions(data); 
    227231                    me.lastXhr = null; 
     
    229233            }; 
    230234            var onError = function( xhr, status, err) { 
    231                 if (xhr && me.lastXhr == xhr) {  
     235                if (xhr && me.lastXhr === xhr) {  
    232236                    me.clearOptions(); 
    233237                    me.lastXhr = null; 
     
    256260            }); 
    257261        } 
    258     } 
     262    }; 
    259263 
    260264 
     
    272276        var changedContext = false; 
    273277        if (value != undefined) { 
    274             changedContext = (this.uriContext[key] != value) ; 
     278            changedContext = (this.uriContext[key] !== value) ; 
    275279            this.uriContext[key] = value; 
    276280        } else { 
     
    282286        } 
    283287             
    284         if (changedContext && !noRefresh)  
     288        if (changedContext && !noRefresh) {  
    285289            this.refresh(); 
     290        } 
    286291         
    287292        return changedContext; // return if there was any change 
    288     } 
     293    }; 
    289294 
    290295    /** 
     
    305310 
    306311        var offset = 0; 
    307         for ( var i = 0; i < last; i++) { 
     312        var i; 
     313        for (i = 0; i < last; i++) { 
    308314            var option = data[i]; 
    309315            var j = i + offset; 
    310316            if (this.valueTemplate) { 
    311317                values[j] = this.valueTemplate.expand(option, false); 
    312                 if (this.labelTemplate) 
     318                if (this.labelTemplate) { 
    313319                    labels[j] = this.labelTemplate.expand(option, false); 
     320                } 
    314321            } else { 
    315322                values[j] = option;     
    316323            } 
    317             if (this.type) 
     324            if (this.type) { 
    318325                values[j] = this.type.parseWireValue(values[j]); 
     326            } 
    319327        } 
    320328        // set those arrays 
    321329        this.set(values, labels); 
    322     } 
    323      
    324      /** 
    325       * clear the options list 
    326       * <p> 
    327       * Note: Updating the HTML should not happen until "update" event triggers the various listeners (e.g. 
    328       * selection-control#updateOptions) 
    329       * </p> 
    330       * @param {Array} data 
    331       */ 
    332      Options.prototype.clearOptions = function( ) { 
    333  
    334          this.set([], []); 
    335      } 
     330    }; 
     331     
     332    /** 
     333     * clear the options list 
     334     * <p> 
     335     * Note: Updating the HTML should not happen until "update" event triggers the various listeners (e.g. 
     336     * selection-control#updateOptions) 
     337     * </p> 
     338     * @param {Array} data 
     339     */ 
     340    Options.prototype.clearOptions = function( ) { 
     341 
     342        this.set([], []); 
     343    }; 
    336344     
    337345         
     
    346354        FieldType.init(this); 
    347355    } 
     356     
    348357    FieldType.init = function(me) { 
    349     } 
     358    }; 
    350359 
    351360 
     
    358367     */ 
    359368    FieldType.createValidators = function( builder, validators) { 
    360  
    361         for ( var i in validators) { 
     369        var i; 
     370        for ( i in validators) { 
    362371            var v = validators[i]; 
    363372            var base = v.base; 
     
    367376            } 
    368377        } 
    369     } 
     378    }; 
    370379 
    371380    /** 
     
    377386    FieldType.createTypes = function( builder, subtypes) { 
    378387 
    379         for ( var ref in subtypes) { 
     388        var ref; 
     389        for ( ref in subtypes) { 
    380390            // only build field types if they haven't been built already 
    381391            if (subtypes[ref].format == null) { 
    382392                var type = subtypes[ref].type; 
    383                 if(type==undefined){ 
     393                if(type == undefined){ 
    384394                  type=subtypes[ref];  
    385395                } 
    386                 if(type.base==undefined) 
     396                if(type.base == undefined) { 
    387397                    type.base='composite'; 
     398                } 
    388399                subtypes[ref] = FieldType.buildType(builder, type); 
    389400            } 
    390401        } 
    391     } 
     402    }; 
    392403 
    393404    /** 
     
    402413 
    403414        return FieldType.buildProperty(builder, type, 'fieldTypes'); 
    404     } 
     415    }; 
    405416 
    406417    /** 
     
    415426 
    416427        return FieldType.buildProperty(builder, formatter, 'formatters'); 
    417     } 
     428    }; 
    418429     
    419430    /** 
     
    430441        var base; 
    431442        var extender; 
    432         if (typeof item == 'string') { 
     443        if (typeof item === 'string') { 
    433444            base = item; 
    434         } else if (item.constructor == Array) { 
    435  
     445        } else if (item.constructor === Array) { 
    436446            base = item[0]; 
    437447            extender = item[1]; 
    438448        } else { // item = {base:'string', ...extensions.. } 
    439           // 1. itereer alle properties uit control 
    440           // if item[property]!=undefined 
     449            // 1. itereer alle properties uit control 
     450            // if item[property]!=undefined 
    441451            if (item.base != undefined) { 
    442452                base = item.base; 
    443453                delete item.base; 
    444             }else 
    445                 if(itemType=="fieldTypes") 
     454            } else { 
     455                if(itemType === "fieldTypes") { 
    446456                    base="composite"; // this should be the default 
    447           extender = item; 
     457                } 
     458            } 
     459            extender = item; 
    448460        } 
    449461 
     
    453465 
    454466        return item; 
    455     } 
     467    }; 
    456468 
    457469    /** 
     
    464476    FieldType.configBuild = function( builder, protype) { 
    465477 
    466  
    467         if(protype.control.constructor == Object && protype.control.base == undefined){ 
    468             var fieldtype = builder.fieldTypes.get(protype["org.kauriproject.registry-name"]); 
    469             var controlType = (new fieldtype).control; 
    470             if(controlType) protype.control.base = controlType; 
    471         } 
    472  
    473         if (protype.validators) 
     478        if(protype.control.constructor === Object && protype.control.base == undefined){ 
     479            var FType = builder.fieldTypes.get(protype["org.kauriproject.registry-name"]); 
     480            var controlType = (new FType()).control; 
     481            if(controlType) { protype.control.base = controlType; } 
     482        } 
     483 
     484        if (protype.validators) { 
    474485            FieldType.createValidators(builder, protype.validators); 
    475         if (protype['user-format']) 
     486        } 
     487        if (protype['user-format']) { 
    476488            protype['user-format'] = FieldType.buildFormatter(builder, protype['user-format']); 
    477         if (protype['wire-format']) 
     489        } 
     490        if (protype['wire-format']) { 
    478491            protype['wire-format'] = FieldType.buildFormatter(builder, protype['wire-format']); 
     492        } 
    479493    }; 
    480494 
     
    506520    */ 
    507521    FieldType.prototype.share = function(key, value) { 
    508         if (this._share == undefined) 
     522        if (this._share == undefined) { 
    509523            this._share = {}; 
     524        } 
    510525        var share = this._share; 
    511526 
    512         if (key == undefined) // asking the share itself 
     527        if (key == undefined) { // asking the share itself 
    513528            return share;  
     529        } 
    514530         
    515531        var sharedValue = share[key]; 
    516         if (value == undefined) // polling the shared property 
     532        if (value == undefined) {// polling the shared property 
    517533            return sharedValue;  
     534        } 
    518535         
    519536        if (!sharedValue) {  // registring a value to be shared 
     
    523540         
    524541        return sharedValue; 
    525     } 
     542   }; 
    526543 
    527544    /** 
     
    539556        var num = 1; 
    540557        if (this.multivalue) { 
    541             if (value && value.constructor == Array) { 
     558            if (value && value.constructor === Array) { 
    542559                values = value; 
    543560                num = values.length; 
     
    549566 
    550567        var seqId = listener.expect(all); 
    551         for ( var i = 0; i < num; i++) { 
     568        var i, j; 
     569        for ( i = 0; i < num; i++) { 
    552570            var validationData = {index: i, type: this, multivalue: this.multivalue};  
    553571            $.extend(validationData, data); 
    554572 
    555             for ( var j = 0; j < last; j++) { 
     573            for ( j = 0; j < last; j++) { 
    556574                 
    557575                var v = myValidators[j]; 
     
    563581            } 
    564582        } 
    565     } 
     583    }; 
    566584 
    567585    /** 
     
    573591 
    574592        return this.validators; 
    575     } 
     593    }; 
    576594 
    577595    /** 
     
    599617 
    600618        return this.parse('user-format', value); 
    601     } 
     619    }; 
    602620 
    603621    /** 
     
    608626     */ 
    609627    FieldType.prototype.toUserValue = function( value) { 
    610         if (value == undefined)  
     628        if (value == undefined) { 
    611629            return this.multivalue ? [] : ""; // this is forced behaviour for user-formatting, while wire-formatting reuse would pas undefined in this case 
    612  
     630        } 
    613631        return this.format('user-format', value); 
    614     } 
     632    }; 
    615633 
    616634    /** 
     
    622640    FieldType.prototype.parseWireValue = function( value) { 
    623641 
    624         if (value === undefined) return undefined;  // ensure wire-format parsing doesn't fail on undefined 
     642        if (value === undefined) { 
     643            return undefined;  // ensure wire-format parsing doesn't fail on undefined 
     644        } 
    625645        return this.parse('wire-format', value); 
    626     } 
     646    }; 
    627647 
    628648    /** 
     
    634654    FieldType.prototype.toWireValue = function( value) { 
    635655         
    636         if (value === undefined)  
     656        if (value === undefined) {  
    637657            return undefined; // this is forced behaviour for wire-formatting, while user-formatting reuse would yield "" here 
     658        } 
    638659        var wireValue = this.format('wire-format', value); 
    639         if (wireValue !== undefined && $.isFunction(wireValue.valueOf)) 
     660        if (wireValue !== undefined && $.isFunction(wireValue.valueOf)) { 
    640661            wireValue = wireValue.valueOf(); // unwrap standard objects like Number and Boolean 
     662        } 
    641663        return wireValue; 
    642     } 
     664    }; 
    643665 
    644666    /** 
     
    652674 
    653675        return this.convert(format, "parse", value); 
    654     } 
     676    }; 
    655677 
    656678    /** 
     
    664686 
    665687        return this.convert(format, "format", value); 
    666     } 
     688    }; 
    667689 
    668690    /** 
     
    677699 
    678700        format = this.getFormat(format); 
    679         if (!format || !$.isFunction(format[method])) 
     701        if (!format || !$.isFunction(format[method])) { 
    680702            return value; 
     703        } 
    681704 
    682705        var values = [ value ]; 
    683706        var num = 1; 
    684707        var wrap = true; 
    685         if (this.multivalue && value && value.constructor == Array) { 
     708        if (this.multivalue && value && value.constructor === Array) { 
    686709            values = value; 
    687710            num = values.length; 
     
    690713        var result = new Array(num); 
    691714 
    692         for ( var i = 0; i < num; i++) { 
     715        var i; 
     716        for ( i = 0; i < num; i++) { 
    693717            result[i] = format[method](values[i]); 
    694718        } 
    695719 
    696         if (wrap) 
     720        if (wrap) { 
    697721            return result[0]; 
     722        } 
    698723 
    699724        return result; 
    700     } 
     725    }; 
    701726 
    702727    /** 
     
    708733    FieldType.prototype.getFormat = function( format) { 
    709734 
    710         if (typeof format == 'string') 
     735        if (typeof format === 'string') { 
    711736            return this[format]; 
     737        } 
    712738        return format; 
    713     } 
    714  
    715 })(jQuery); 
     739    }; 
     740 
     741     
     742    $.extend(kf, { 
     743        Options: Options,  
     744        FieldType :FieldType 
     745    }); 
     746 
     747}(jQuery)); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/form.js

    r1920 r1948  
     1/* jslint eqeq: true */ 
    12/** 
    2 * @fileOverview This file holds the classes composing the actual Form structure. 
    3 */ 
     3 * @fileOverview This file holds the classes composing the actual Form structure. 
     4 */ 
    45; 
    56( function( $) { 
    67 
    7   if (!$) 
     8  if (!$) { 
    89      throw "[form.js] requires jQuery"; 
    9   if (!$.org.kauriproject.forms) 
     10  } 
     11  if (!$.org.kauriproject.forms) { 
    1012      throw "[form.js] requires the kauri-form namespace"; 
     13  } 
    1114 
    1215  var kf = $.org.kauriproject.forms; 
    1316  var kp = $.org.kauriproject; 
    1417 
    15   $.inherit(Form, kf.CompositeControl); 
    1618  /** 
    1719   * Form holds and controls a set of controls getting build up from a descriptive configuration object. It matches the HTML 
     
    3234      id = (elmOrId && elmOrId.jquery) ? "" : elmOrId; 
    3335       
    34       if (space.size() != 1) 
     36      if (space.size() !== 1) { 
    3537          throw "[Form.initElementIndex] No matching <form> element found for id #" + elmOrId; 
     38      } 
    3639 
    3740      this.initRegistries(conf); 
     
    5558      var complete = false; // keeping this local so it can't be tampered with, 
    5659      this.isComplete = function() { 
    57  
    5860          return complete; 
    5961      }; // only read 
    6062      this.initComplete( function() { 
    61  
    6263          complete = true; 
    6364      }); // first trigger to execute. 
     
    7172          $submitBtn = $submitBtn.length > 0 ? $submitBtn : $("<input type='submit' value='submit'/>").appendTo(this); 
    7273          // register submission-handler 
    73               $submitBtn.each(function() { 
    74                   var $btn = $(this); 
    75  
    76                   var submitAttr = $(this).attr("kauri-submit") || ""; 
    77                   var submitParams = submitAttr.split(/\s*,\s*/); 
    78                   var saveMode = true; 
    79                   var allowInvalid = false; 
     74          $submitBtn.each(function() { 
     75              var $btn = $(this); 
     76 
     77              var submitAttr = $(this).attr("kauri-submit") || ""; 
     78              var submitParams = submitAttr.split(/\s*,\s*/); 
     79              var saveMode = true; 
     80              var allowInvalid = false; 
     81               
     82              var i; 
     83              for (i = 0; i< submitParams.length; i++) { 
     84                  var param = submitParams[i]; 
     85                  if (param === "create")    {    saveMode = false;    } 
     86                  if (param === "invalid")   {    allowInvalid = true; } 
     87              } 
     88               
     89              $btn.click(function(evt) { 
     90                  evt.preventDefault(); 
     91                  evt.stopPropagation(); 
    8092                   
    81                   for (var i = 0; i< submitParams.length; i++) { 
    82                       var param = submitParams[i]; 
    83                       if (param == "create")        saveMode = false; 
    84                       if (param == "invalid")       allowInvalid = true; 
    85                   } 
    86                    
    87                   $btn.click(function(evt) { 
    88                       evt.preventDefault(); 
    89                       evt.stopPropagation(); 
    90                        
    91                       form.submit($(this), saveMode, allowInvalid); 
    92                   }); 
     93                  form.submit($(this), saveMode, allowInvalid); 
    9394              }); 
    94           }); // last trigger to execute 
     95          }); 
     96      }); // last trigger to execute 
    9597 
    9698      this.initComplete(); // trigger event to execute callbacks. 
     
    100102      // TODO check if there is not a nicer way to do this 
    101103      this.getType().toWireValue = function( value) { 
    102           if (value === undefined)  
    103               return {}; // for forms, return empty object instead of undefined  
     104          if (value === undefined) { 
     105              return {}; // for forms, return empty object instead of undefined 
     106          } 
    104107          var wireValue = this.format('wire-format', value); 
    105           if (wireValue !== undefined && $.isFunction(wireValue.valueOf)) 
     108          if (wireValue !== undefined && $.isFunction(wireValue.valueOf)) {  
    106109              wireValue = wireValue.valueOf(); // unwrap standard objects like Number and Boolean 
     110          } 
    107111          return wireValue; 
    108112      }; 
    109113  } 
     114  $.inherit(Form, kf.CompositeControl); 
    110115 
    111116  Form.prototype.initEvents = function() { 
     
    114119      this._makeEventHandler("submitsuccess"); 
    115120      this._makeEventHandler("submiterror"); 
    116   } 
     121  }; 
    117122 
    118123  Form.prototype.initComplete = function( fn) { 
     
    123128      }; 
    124129 
    125       if (this.isComplete && this.isComplete() && fn) 
     130      if (this.isComplete && this.isComplete() && fn) {  
    126131          return fn.apply(root, [data]); // execute immediately, no need to register any more 
     132      } 
    127133 
    128134      var $root = $(root); 
    129135      return fn ? $root.one("initComplete", data, fn) : $root.trigger("initComplete"); 
    130   } 
     136  }; 
    131137 
    132138 
     
    138144      // load conf-registries 
    139145      this.buildTypes(conf); 
    140   } 
     146  }; 
    141147 
    142148  Form.prototype.initDataURIs = function( conf) { 
    143149 
    144       if (conf.dataURI != undefined) 
     150      if (conf.dataURI != undefined) { 
    145151          this._dataURITemplate = new kp.UriTemplate(conf.dataURI); 
     152      } 
    146153      delete conf.dataURI; 
    147       if (conf.createURI != undefined) 
     154      if (conf.createURI != undefined) { 
    148155          this._createURITemplate = new kp.UriTemplate(conf.createURI); 
     156      } 
    149157      delete conf.createURI; 
    150  
    151   } 
     158  }; 
    152159 
    153160  Form.prototype.initElementIndex = function( space ) { 
     
    159166      var $layoutElts = $("[" + kf.ControlElements.ATTR_LAYOUT_CURSOR + "]", space); 
    160167      $.each($layoutElts, function(index, element){ 
    161           $(element).hide(); 
    162         } 
     168              $(element).hide(); 
     169          } 
    163170      ); 
    164171 
    165        
    166172       
    167173      space.attr(kf.ControlElements.ATTR_INDEX, '/'); 
     
    171177 
    172178      this.setRootElement(space); 
    173   } 
     179  }; 
    174180 
    175181 
    176182  Form.prototype.setRootElement = function( elm) { 
    177183 
    178       if (this.rootElement) 
     184      if (this.rootElement) {  
    179185          throw "[Form#setRootElement] Root element already set."; 
     186      } 
    180187      this.rootElement = elm; 
    181188      this.addElementIndex("/", $(elm)); 
    182   } 
     189  }; 
    183190 
    184191  Form.prototype.getRootElement = function() { 
    185192 
    186193      return this.rootElement; 
    187   } 
     194  }; 
    188195 
    189196  Form.prototype.getAbsoluteId = function() { 
     
    201208 
    202209      this.allowInvalid = allow; 
    203   } 
     210  }; 
    204211   
    205212  Form.prototype.preSubmitValidationCheck = function(allowInvalid) { 
    206213 
    207       if (allowInvalid || this.allowInvalid) return true; 
     214      if (allowInvalid || this.allowInvalid) { return true; } 
    208215       
    209216      var previousAsync = $.ajaxSettings.async; // clone current async settings 
     
    213220          formValid = this.isValid(true); // force validation if it didn't happen yet 
    214221      } finally { 
    215           if (previousAsync) $.ajaxSetup({async: true}); // reset async settings 
     222          if (previousAsync) { $.ajaxSetup({async: true}); } // reset async settings 
    216223      } 
    217224       
     
    222229       
    223230      return true; 
    224   } 
     231  }; 
    225232   
    226233  Form.prototype.submit = function($trigger, saveMode, allowInvalid) { 
    227234      var me = this; 
    228235       
    229       if (saveMode == undefined) saveMode = true; 
    230       if (allowInvalid == undefined) allowInvalid = false; 
     236      if (saveMode == undefined)     { saveMode = true; } 
     237      if (allowInvalid == undefined) { allowInvalid = false; } 
    231238       
    232239      $(this).triggerHandler("prevalidation"); 
    233240       
    234241      var proceed = this.preSubmitValidationCheck(allowInvalid); 
    235       if (!proceed) return; 
     242      if (!proceed) { return; } 
    236243 
    237244      // update data object 
     
    256263         
    257264        $(this).triggerHandler("presubmit", formSubmissionData); 
    258         if (formSubmissionData.cancelsubmit) return; 
    259  
     265        if (formSubmissionData.cancelsubmit) { return; } 
    260266 
    261267        var json = kp.JSON.stringify(data);  
     
    268274        var modeMsg; 
    269275 
    270         if(this._createMode || !saveMode){ 
     276        if(this._createMode || !saveMode) { 
    271277            uriTemplate = this.getCreateURITemplate(); 
    272             modeMsg = "createURI" 
    273         }else{ 
     278            modeMsg = "createURI"; 
     279        } else { 
    274280            // put 
    275281            uriTemplate = this.getDataURITemplate(); 
     
    287293        var params = $.param(uriSuffix); 
    288294        if (params.length > 0) { 
    289           uri += (uri.match(/\?/) ? "&" : "?") + params; 
     295            uri += (uri.match(/\?/) ? "&" : "?") + params; 
    290296        } 
    291297         
     
    298304            dataType :"json", 
    299305            success : function(data, type) { 
    300               $(me).triggerHandler('submitsuccess', data, type); 
    301               if (me.submitSuccess || me.submitsuccess.length == 0) { 
    302                 // a handler was registered (via f.submitSuccess=function() OR via the jQuery-style event handler) 
    303                 var fn = me.submitSuccess || me._submitSuccess; 
    304                 fn(data, type); 
    305               } 
     306                $(me).triggerHandler('submitsuccess', data, type); 
     307                if (me.submitSuccess || me.submitsuccess.length === 0) { 
     308                    // a handler was registered (via f.submitSuccess=function() OR via the jQuery-style event handler) 
     309                    var fn = me.submitSuccess || me._submitSuccess; 
     310                    fn(data, type); 
     311                } 
    306312            }, 
    307313            error : function(request, status, error) { 
    308               $(me).triggerHandler('submiterror', request, status, error); 
    309               if (me.submitError || me.submiterror.length == 0) { 
    310                 // a handler was registered (via f.submitError=function() OR via the jQuery-style event handler) 
    311                 var fn = me.submitError || me._submitError; 
    312                 fn(request, status, error); 
     314                $(me).triggerHandler('submiterror', request, status, error); 
     315                if (me.submitError || me.submiterror.length === 0) { 
     316                    // a handler was registered (via f.submitError=function() OR via the jQuery-style event handler) 
     317                    var fn = me.submitError || me._submitError; 
     318                    fn(request, status, error); 
    313319              } 
    314320            }, 
     
    316322            dataFilter : me.dataFilter 
    317323        }); 
    318     } 
     324    }; 
    319325 
    320326    /** 
     
    325331    */ 
    326332    Form.prototype.dataFilter = function (data, type) { 
    327         if (!data  && type=="json") { 
     333        if (!data  && type === "json") { 
    328334            return "{}"; 
    329         } else 
     335        } else { 
    330336            return data; 
     337        } 
    331338    }; 
    332339     
    333340    Form.prototype.setCreateMode = function (isCreate) { 
    334341        this._createMode = isCreate; 
    335     } 
     342    }; 
    336343     
    337344    Form.prototype.isCreateMode = function () { 
    338345        return this._createMode; 
    339     } 
     346    }; 
    340347     
    341348    Form.prototype.getDataURITemplate = function () { 
    342349        return this._dataURITemplate; 
    343     } 
     350    }; 
    344351     
    345352    Form.prototype.getCreateURITemplate = function () { 
    346353        // fallback if createURITemplate is null 
    347         if(this._createURITemplate) 
     354        if(this._createURITemplate) { 
    348355            return this._createURITemplate; 
    349         else 
     356        } else { 
    350357            return this._dataURITemplate; 
    351     } 
     358        } 
     359    }; 
    352360     
    353361    /** 
     
    358366    Form.prototype._submitSuccess = function (data, status) { 
    359367        alert("Server responded: " + status + " \n" + kp.JSON.stringify(data)); 
    360             if (data.redirect) 
    361                 window.location = data.redirect; 
     368        if (data.redirect) { 
     369            window.location = data.redirect; 
     370        } 
    362371    }; 
    363372     
     
    370379    Form.prototype._submitError = function (request, status, error) { 
    371380        alert("Error submitting form:\n" + request.status + ": " + request.statusText); 
    372     } 
     381    }; 
    373382     
    374383    /** 
     
    378387    Form.prototype.beforeSubmit = function (request) { 
    379388        // by default do nothing here 
    380     } 
     389    }; 
    381390     
    382391     
     
    403412    $.define("kauriform", Form);  
    404413 
    405 })(jQuery); 
     414}(jQuery)); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/formatter.js

    r560 r1948  
     1/* jslint eqeq: true */ 
    12/** 
    23 * @fileOverview This file holds the basic structure of the formatter system 
     
    56( function( $) { 
    67 
    7     if (!$) 
     8    if (!$) { 
    89        throw "[formatter.js] requires jQuery"; 
    9     if (!$.org.kauriproject.forms) 
     10    } 
     11    if (!$.org.kauriproject.forms) {  
    1012        throw "[formatter.js] requires the kauri-form namespace"; 
     13    } 
    1114 
    1215    var kf = $.org.kauriproject.forms; 
    1316    var locale = kf.locale; 
    14  
    15     $.extend(kf, { 
    16         Formatter :Formatter 
    17     }); 
    1817 
    1918 
     
    2524     */ 
    2625    function Formatter() { 
    27  
    2826    } 
    2927 
     
    3634    Formatter.prototype.format = function( val) { 
    3735 
    38         if (val == undefined) 
     36        if (val == undefined) {  
    3937            return ""; 
     38        } 
    4039        return val.toString(); 
    41     } 
     40    }; 
    4241 
    4342    /** 
     
    5251 
    5352        valstr = $.trim(valstr); 
    54         if (valstr == "") 
     53        if (valstr === "") {  
    5554            return undefined; 
     55        } 
    5656        return valstr; 
    57     } 
     57    }; 
    5858 
    5959    Formatter.prototype.toString = function() { 
    6060 
    6161        return "Formatter('" + this['org.kauriproject.registry-name'] + "')"; 
    62     } 
     62    }; 
    6363 
    6464    Formatter.prototype.fail = function( msg, args) { 
     
    6666        msg = this.message || msg; 
    6767        throw new kf.Message.build(msg, args, "Formatter.fail"); 
    68     } 
     68    }; 
    6969 
    7070 
    71 })(jQuery); 
     71    $.extend(kf, { 
     72        Formatter :Formatter 
     73    }); 
     74 
     75     
     76}(jQuery)); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/location.js

    r1920 r1948  
     1/* jslint eqeq: true */ 
    12/** 
    23 * @fileOverview This file holds some advanced controltypes for standard forms. 
     
    56( function( $) { 
    67 
    7     if (!$) 
     8    if (!$) {  
    89        throw "Kauri Forms Location module requires jQuery"; 
    9     if (!$.org.kauriproject.forms) 
     10    } 
     11    if (!$.org.kauriproject.forms) {  
    1012        throw "Kauri Forms Location module requires the kauri-form namespace"; 
     13    } 
    1114     
    1215    var kp = $.org.kauriproject; 
     
    2427     
    2528     
    26     $.inherit(GMapControl, kf.AbstractContainerControl); 
    27      
    2829    /** 
    2930    * @class Uses a google map as a control for choosing a location 
     
    3940        kf.Control.init(this, id, form, conf); 
    4041    } 
     42    $.inherit(GMapControl, kf.AbstractContainerControl); 
     43     
    4144     
    4245    /** 
     
    5861        var type = this.getType(); 
    5962        var memberTypes = type.getMemberTypes(); 
    60  
    61         for ( var memberName in memberTypes) { 
     63        var memberName; 
     64        for ( memberName in memberTypes) { 
    6265            var memberType = memberTypes[memberName]; 
    6366            var childControl = this.createChildControl(memberName, memberType); 
     
    9699    }; 
    97100     
    98      GMapControl.prototype.initEvents = function(){ 
    99          var me = this; 
     101    GMapControl.prototype.initEvents = function(){ 
     102        var me = this; 
    100103         
    101104        // we are now setting the valueChanged handler 
    102105        this.valueChanged(function (evt) { 
    103                 var val = me.getWireValue(); 
    104                 if (val && val.latitude != null && val.longitude != null && val.zoom != null) { 
    105                     var mapVal = {latitude : new Number(val.latitude).valueOf(), longitude : new Number(val.longitude).valueOf(), zoom : new Number(val.zoom).valueOf()}; 
    106                     me.setMapValue(mapVal);                     
    107                 }                             
     106            var val = me.getWireValue(); 
     107            if (val && val.latitude != null && val.longitude != null && val.zoom != null) { 
     108                var mapVal = {latitude : new Number(val.latitude).valueOf(), longitude : new Number(val.longitude).valueOf(), zoom : new Number(val.zoom).valueOf()}; 
     109                me.setMapValue(mapVal);                     
     110            }                             
    108111                     
    109112        }); 
    110      } 
     113    }; 
    111114     
    112115    GMapControl.prototype.setMapValue = function (value) { 
     
    121124            this.gmap.panTo(point); 
    122125        } 
    123     } 
     126    }; 
     127     
    124128    kf.controlTypes.put("gmap-control", GMapControl); 
    125129     
    126 })(jQuery); 
     130}(jQuery)); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/numeric-range.js

    r1920 r1948  
     1/* jslint eqeq: true */ 
    12/** 
    23 * @fileOverview This file holds some advanced controltypes for standard forms. 
     
    56( function( $) { 
    67 
    7     if (!$) 
     8    if (!$) {  
    89        throw "Kauri Forms Advanced-Controls requires jQuery"; 
    9     if (!$.org.kauriproject.forms) 
     10    } 
     11    if (!$.org.kauriproject.forms) {  
    1012        throw "Kauri Forms Advanced-Controls requires the kauri-form namespace"; 
     13    } 
    1114     
    1215    var kp = $.org.kauriproject; 
     
    1720     
    1821        format : function( val) { 
    19             if (val == undefined) 
     22            if (val == undefined) {  
    2023                return ""; 
    21             if (val.start == undefined || val.end == undefined)  
     24            } 
     25            if (val.start == undefined || val.end == undefined) {  
    2226                this.fail("The range doesn't have a start or end"); 
    23             if (val.start.constructor != Number) 
     27            } 
     28            if (val.start.constructor !== Number) {  
    2429                this.fail("Not a valid number: {0}.", [ val.start ]); 
    25             if (val.end.constructor != Number) 
     30            } 
     31            if (val.end.constructor !== Number) {  
    2632                this.fail("Not a valid number: {0}.", [ val.ends ]); 
    27      
    28             if (this.rawFormat) return {start : "" + val.start.valueOf(), end : "" + val.end.valueOf()}; 
     33            } 
     34            if (this.rawFormat) {  
     35                return {start : "" + val.start.valueOf(), end : "" + val.end.valueOf()}; 
     36            } 
    2937            return val.start.toLocaleString() + " - " + val.end.toLocaleString(); 
    3038        }, 
     
    3341            var start, end; 
    3442     
    35             if (typeof valstr == 'string') { 
     43            if (typeof valstr === 'string') { 
    3644                valstr = $.trim(valstr); 
    37                 if (valstr.length == 0) 
     45                if (valstr.length === 0) {  
    3846                    return undefined; 
     47                } 
    3948                     
    4049                var valArr = valstr.split(" - "); 
    41                 if (valArr.length != 2) 
     50                if (valArr.length !== 2) {  
    4251                    this.fail("Not a valid number range : {0}.", [ valstr ]); 
     52                } 
    4353                     
    4454                start = new Number(valArr[0]); 
    4555                end = new Number(valArr[1]); 
    4656                 
    47                 if (isNaN(start) || isNaN(end)) 
     57                if (isNaN(start) || isNaN(end)) {  
    4858                    this.fail("Not a valid number range : {0}.", [ valstr ]); 
    49  
    50                 if (start > end) 
     59                } 
     60 
     61                if (start > end) {  
    5162                    this.fail("First value should be smaller than second value in a number range: {0}.", [ valstr ]); 
    52  
    53             } else if (typeof valstr == "object" && valstr.start != null && valstr.end != null)  { 
     63                } 
     64 
     65            } else if (typeof valstr === "object" && valstr.start != null && valstr.end != null)  { 
    5466                start = valstr.start; 
    5567                end = valstr.end; 
     
    6375        validate : function( value) { 
    6476     
    65             if (value == undefined) 
     77            if (value == undefined) {  
    6678                return this.notifySuccess(); 
     79            } 
    6780                 
    68             if (!value.start || !value.end) 
    69                  return this.notifyFail("Not a range."); 
     81            if (!value.start || !value.end) {  
     82                return this.notifyFail("Not a range."); 
     83            } 
    7084                  
    7185            var response = kf.Validator.validateInt(this, value.start); 
    72             if(response == true) 
     86            if(response === true) { 
    7387                response = kf.Validator.validateInt(this, value.end); 
     88            } 
    7489                 
    7590            return response; 
     
    87102    }); 
    88103 
    89     $.inherit(SliderControl, kf.Control); 
    90104         
    91105    function SliderControl ( id, form, conf) { 
    92106        kf.Control.init(this, id, form, conf); 
    93107    } 
     108    $.inherit(SliderControl, kf.Control); 
     109 
    94110    SliderControl.prototype.elements = {}; 
    95111    $.extend(SliderControl.prototype.elements, kf.Control.prototype.elements); 
     
    120136            range :me.isRange, 
    121137            change : function( e, ui) { 
    122  
    123138                me.syncInputValue(ui.value); 
    124139            } 
     
    131146         
    132147        this.$slider.slider(sliderConf); 
    133     } 
     148    }; 
    134149     
    135150    /** 
     
    141156        var $input = this.getElement(); 
    142157        return $input.val(); 
    143     } 
     158    }; 
    144159     
    145160    /** 
     
    155170        var val = this.getType().parseUserValue(value); 
    156171        this.syncSlider( val); 
    157     } 
     172    }; 
    158173 
    159174 
     
    161176 
    162177        // escape from event loops between the two sources of change 
    163         if (this.inChangeEventHandler) 
    164             return; 
    165          
    166         if(!value) 
    167             return; 
     178        if (this.inChangeEventHandler) { return;} 
     179        if(!value) {   return; } 
    168180 
    169181        // set event-handler-flag and be sure to unset it 
     
    180192            this.inChangeEventHandler = false; 
    181193        } 
    182     } 
     194    }; 
    183195 
    184196    SliderControl.prototype.syncInputValue = function( value) { 
     
    186198 
    187199        // escape from event loops between the two sources of change 
    188         if (this.inChangeEventHandler) 
    189             return; 
     200        if (this.inChangeEventHandler) { return; } 
    190201 
    191202        // set event-handler-flag and be sure to unset it 
     
    206217            this.inChangeEventHandler = false; 
    207218        } 
    208     } 
     219    }; 
    209220 
    210221 
    211222    kf.controlTypes.put("slider-control", SliderControl); 
    212223     
    213 })(jQuery); 
     224}(jQuery)); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/registry.js

    r1920 r1948  
     1/* jslint eqeq: true */ 
    12/** 
    23 * @fileOverview This script creates the Registry system based for managing the various types of types and objects in the forms 
     
    78( function( $) { 
    89 
    9     if (!$) 
     10    if (!$) { 
    1011        throw "[registry.js] requires jQuery"; 
    11     if (!$.org.kauriproject.forms) 
     12    } 
     13    if (!$.org.kauriproject.forms) { 
    1214        throw "[registry.js] requires the kauri-form namespace"; 
     15    } 
    1316 
    1417    var kf = $.org.kauriproject.forms; 
     
    4750 
    4851        this.toString = function() { 
    49  
    5052            return 'ConstructorRegistry: ' + description; 
    5153        }; 
     
    7274    ConstructorRegistry.prototype.setBaseConstructor = function( /* constructor */baseConstructor, /* string */baseName) { 
    7375 
    74         if (this._baseConstructor != undefined) 
     76        if (this._baseConstructor != undefined) { 
    7577            throw "[ConstructorRegistry.setBaseConstructor] can only be set once"; 
     78        } 
    7679        this._baseConstructor = baseConstructor; 
    77         if (baseName != undefined) 
     80        if (baseName != undefined) { 
    7881            this.put(baseName, baseConstructor); 
     82        } 
    7983    }; 
    8084 
     
    8286 
    8387        var found = this._baseConstructor; 
    84         if (found == undefined && this._parent != undefined) 
     88        if (found == undefined && this._parent != undefined) { 
    8589            found = this._parent.getBaseConstructor(); 
     90        } 
    8691        return found; 
    87     } 
     92    }; 
    8893 
    8994    ConstructorRegistry.prototype.setConfigBuilder = function( builder) { 
    9095 
    9196        this._configBuilder = builder; 
    92     } 
     97    }; 
    9398 
    9499    /** 
     
    101106 
    102107        if (loadPath != undefined) { 
    103             if (typeof loadPath == "string") 
     108            if (typeof loadPath === "string") { 
    104109                loadPath = new kp.UriTemplate(loadPath); 
    105             else if (loadPath.constructor != kp.UriTemplate) 
     110            } else if (loadPath.constructor !== kp.UriTemplate) {  
    106111                throw "[ConstructorRegistry.setLoadPath] loadPath constructor argument should be either string or UriTemplate."; 
     112            } 
    107113            this._loadPath = loadPath; 
    108114        } 
     
    117123    ConstructorRegistry.prototype.load = function( /* string */name) { 
    118124 
    119         if (!this._loadPath) 
    120             return; 
     125        if (!this._loadPath) { return; } 
    121126 
    122127        var uri = this._loadPath.expand( { 
     
    148153        }); 
    149154 
    150         if (constr && this._autoAdd) 
     155        if (constr && this._autoAdd) {  
    151156            this.put(name, constr); 
     157        } 
    152158 
    153159        return constr; 
     
    172178 
    173179        var constr = classSpec; 
    174         if (name == undefined) 
     180        if (name == undefined) {  
    175181            throw "[ConstructorRegistry.put] Can't register without a proper name."; 
    176         if (this._reg[name] != undefined) 
     182        } 
     183        if (this._reg[name] != undefined) {  
    177184            throw "[ConstructorRegistry.put] can't register constructor (" + constr + ") in registry (" + this 
    178185                    + "). Reason: Name (" + name + ") already exists."; 
     186        } 
    179187 
    180188        classSpec = classSpec || {}; 
     
    183191            var baseConstructor = extender.base; 
    184192            delete extender.base; 
    185             if (!$.isFunction(baseConstructor) && baseConstructor != undefined) 
     193            if (!$.isFunction(baseConstructor) && baseConstructor != undefined) {  
    186194                baseConstructor = this.get(baseConstructor); 
     195            } 
    187196            baseConstructor = baseConstructor || this.getBaseConstructor(); 
    188197            constr = this.extendConstructor(baseConstructor, extender); 
    189198        } 
    190199 
    191         if (!$.isFunction(constr)) 
     200        if (!$.isFunction(constr)) {  
    192201            throw "[ConstructorRegistry.put] can only register functions/constructors."; 
     202        } 
    193203 
    194204        addNameProperty = addNameProperty || true; 
    195         if (addNameProperty) 
     205        if (addNameProperty) {  
    196206            constr.prototype['org.kauriproject.registry-name'] = name; 
     207        } 
    197208 
    198209        this._reg[name] = constr; 
     
    215226        addNameProperty = addNameProperty || true; 
    216227 
    217         for ( var name in classSpecs) { 
     228        var name; 
     229        for ( name in classSpecs) { 
    218230            this.put(name, classSpecs[name], addNameProperty); 
    219231        } 
     
    227239    ConstructorRegistry.isObject = function( val) { 
    228240 
    229         return (val != undefined && val.constructor != Array) 
    230     } 
     241        return (val != undefined && val.constructor !== Array); 
     242    }; 
    231243 
    232244    /** 
     
    239251    ConstructorRegistry.prototype.extendProperties = function( protype, extender) { 
    240252 
    241         for ( var atProp in extender) { 
    242             if (atProp.charAt(0) == '+') { 
     253        var atProp; 
     254        for ( atProp in extender) { 
     255            if (atProp.charAt(0) === '+') { 
    243256                var prop = atProp.substring(1); 
    244257                var oldPropVal = protype[prop]; 
     
    247260                var newPropVal = isObjectProperty ? {} : []; // we need to make a new instance, otherwise the parent prototype 
    248261                                                                // gets extended. 
    249  
    250                 for ( var knownRef in oldPropVal) { 
     262                var knownRef; 
     263                for ( knownRef in oldPropVal) { 
    251264                    newPropVal[knownRef] = oldPropVal[knownRef]; 
    252265                } 
    253266 
    254                 for ( var fresh in freshPropVal) { 
     267                var fresh; 
     268                for ( fresh in freshPropVal) { 
    255269                    var ref = isObjectProperty ? fresh : newPropVal.length; 
    256270                    var freshVal = freshPropVal[fresh]; 
    257                     if (ConstructorRegistry.isObject(freshPropVal)) 
     271                    if (ConstructorRegistry.isObject(freshPropVal)) {  
    258272                        freshVal.base = fresh; 
     273                    } 
    259274 
    260275                    newPropVal[ref] = freshVal; 
     
    265280            } 
    266281        } 
    267     } 
     282    }; 
    268283 
    269284 
     
    276291    ConstructorRegistry.prototype.configureProperties = function( constr) { 
    277292 
    278         if (this._configBuilder == undefined || constr.configBuild == undefined || !$.isFunction(constr.configBuild)) 
     293        if (this._configBuilder == undefined || constr.configBuild == undefined || !$.isFunction(constr.configBuild)) {  
    279294            return; 
     295        } 
    280296 
    281297        constr.configBuild(this._configBuilder, constr.prototype); 
    282     } 
     298    }; 
    283299 
    284300 
     
    294310    ConstructorRegistry.prototype.extendConstructor = function( /* function */baseConstructor, /* object */extender) { 
    295311 
    296         if (!$.hasProperties(extender)) 
     312        if (!$.hasProperties(extender)) {  
    297313            return baseConstructor; 
     314        } 
    298315 
    299316        //clone extender making sure it can be reused. 
     
    303320        delete extender["<init>"]; 
    304321 
    305         $.inherit(newConstructor, baseConstructor); 
    306322        function newConstructor() { 
    307323 
     
    313329            } 
    314330        } 
     331        $.inherit(newConstructor, baseConstructor); 
    315332 
    316333        this.extendProperties(newConstructor.prototype, extender); 
     
    326343        // deep-clone these properties 
    327344        var deepClonePropertyNames = ["initial", "templates"]; //room for more in the future 
    328         for (var i=0; i<deepClonePropertyNames.length; i++) { 
     345        var i; 
     346        for ( i=0; i<deepClonePropertyNames.length; i++) { 
    329347            var name = deepClonePropertyNames[i]; 
    330348            if (extender[name] != null) { 
     
    345363 
    346364        var found = this._reg[name]; 
    347         if (!found && this._parent) 
     365        if (!found && this._parent) { 
    348366            found = this._parent.getWithoutLoad(name); 
     367        } 
    349368        return found; 
    350     } 
     369    }; 
    351370 
    352371    /** 
     
    365384    ConstructorRegistry.prototype.get = function( /* string */name, /* object */extender) { 
    366385 
    367         if (!name) 
     386        if (!name) {  
    368387            throw "[ConstructorRegistry.get] Need the name to get the registered constructor in registry " + this.toString(); 
     388        } 
    369389 
    370390        var found = this.getWithoutLoad(name); 
    371         if (!found) 
     391        if (!found) {  
    372392            found = this.load(name); 
    373         if (!found) 
     393        } 
     394        if (!found) {  
    374395            throw "[ConstructorRegistry.get] No registered constructor found: " + name + " in registry " + this.toString(); 
    375  
    376         if ($.hasProperties(extender)) 
     396        } 
     397        if ($.hasProperties(extender)) {  
    377398            found = this.extendConstructor(found, extender); 
     399        } 
    378400 
    379401        return found; 
     
    394416    ConstructorRegistry.prototype.getInstance = function( /* string */name, /* object */extender, /* array */args) { 
    395417 
    396         if (!name) 
     418        if (!name) { 
    397419            throw "[ConstructorRegistry.getInstance] Need the name to get the registered constructor."; 
    398  
    399         var foundConstructor = this.get(name, extender); 
    400         if (!$.isFunction(foundConstructor)) 
     420        } 
     421 
     422        var FoundConstructor = this.get(name, extender); 
     423        if (!$.isFunction(FoundConstructor)) { 
    401424            return undefined; 
     425        } 
    402426 
    403427        // ie -jscript doesn't like args == undefined in tha call to fn.apply(this, args); 
    404428        args = args || []; 
    405         function instance() { 
    406  
    407             foundConstructor.apply(this, args); 
    408         } 
    409         instance.prototype = new foundConstructor(); 
    410  
    411         return new instance(); 
     429        function Instance() { 
     430 
     431            FoundConstructor.apply(this, args); 
     432        } 
     433        Instance.prototype = new FoundConstructor(); 
     434 
     435        return new Instance(); 
    412436    }; 
    413437 
     
    416440    }); 
    417441 
    418 })(jQuery); 
     442}(jQuery)); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/upload.js

    r1920 r1948  
     1/* jslint eqeq: true */ 
    12/** 
    23 * @fileOverview This file holds some advanced controltypes for standard forms. 
     
    56(function($){ 
    67 
    7     if (!$)  
     8    if (!$) { 
    89        throw "Kauri Forms Upload module requires jQuery"; 
    9     if (!$.org.kauriproject.forms)  
     10    } 
     11    if (!$.org.kauriproject.forms) {  
    1012        throw "Kauri Forms Upload module requires the kauri-form namespace"; 
     13    } 
    1114     
    1215    var kp = $.org.kauriproject; 
     
    1821    }); 
    1922     
    20     $.inherit(UploadControl, kf.Control); 
    2123     
    2224    /** 
     
    3133        kf.Control.init(this, id, form, conf); 
    3234    } 
     35    $.inherit(UploadControl, kf.Control); 
    3336     
    3437    /** 
     
    5659         
    5760        // by default show the remove link 
    58         if (this.showRemove == undefined) 
     61        if (this.showRemove == undefined) { 
    5962            this.showRemove = true; 
     63        } 
    6064         
    6165        var $container = this.getElement("input"); 
     
    111115        $container = $container || this.getElement("input"); 
    112116         
    113         if (this.uploadInput) 
     117        if (this.uploadInput) { 
    114118            this.uploadInput.remove(); 
     119        } 
    115120             
    116121        // the visual input control the end user will see 
     
    119124            me.performUpload(); 
    120125        }); 
    121     } 
     126    }; 
    122127     
    123128    UploadControl.prototype.performUpload = function() { 
     
    142147        // start upload by submitting the upload-form 
    143148        this.uploadForm.submit(); 
    144     } 
     149    }; 
    145150     
    146151    UploadControl.prototype.handleUploadResponse = function(idoc) { 
    147         if (!idoc || INIT_FRAME_URL == idoc.URL) 
     152        if (!idoc || INIT_FRAME_URL === idoc.URL) { 
    148153            return; // no data to be read, this is just starting up 
     154        } 
    149155             
    150156        try { 
     
    167173            this.updateView(); 
    168174        } 
    169     } 
     175    }; 
    170176     
    171177    UploadControl.prototype.dataRef = function(id){ 
     
    175181         
    176182        return base + id; 
    177     } 
     183    }; 
    178184 
    179185    UploadControl.prototype.leaseRef = function(id){ 
     
    183189         
    184190        return base + id + "/lease.json"; 
    185     } 
    186  
     191    }; 
    187192     
    188193     
     
    191196        level = level || 0; 
    192197        var nextOrder = Number(new Number(size) / 1024).toFixed(); 
    193         if (nextOrder != "0" && ORDER_SIZES.length > level +1) 
     198        if (nextOrder !== "0" && ORDER_SIZES.length > level +1) { 
    194199            return this.humanSize(nextOrder, level+1); 
     200        } 
    195201        //else  
    196202        return size + ORDER_SIZES[level]; 
    197     } 
     203    }; 
    198204     
    199205    var FILE_PART_REGEXP = /^.*?([^\/\\]+)$/; 
    200206    UploadControl.prototype.fileNameOnly = function(path) { 
    201207        var m = FILE_PART_REGEXP.exec(path); 
    202         if (m == null) 
     208        if (m == null) { 
    203209            return path; 
     210        } 
    204211        return m[1]; 
    205     } 
     212    }; 
    206213     
    207214    UploadControl.prototype.updateView = function () { 
     
    213220 
    214221            // remove the input if still there and replace with file information 
    215             if (this.uploadInput)  
     222            if (this.uploadInput) { 
    216223                this.uploadInput.remove(); 
     224            } 
    217225             
    218226            // display file information 
     
    236244                }); 
    237245            } 
    238             if (isTemporary) 
     246            if (isTemporary) { 
    239247                this.startHeartBeat(value.id); 
    240              
     248            } 
    241249        } else { 
    242250            //no value set, so allow end-user to enter one 
     
    244252            this.newUploadInput(me); 
    245253        } 
    246     } 
     254    }; 
    247255     
    248256    UploadControl.prototype.clearUploadedFile = function (key, isTemporary) { 
     
    256264            url :uri 
    257265        }); 
    258     } 
     266    }; 
    259267     
    260268    UploadControl.prototype.heartbeatTimer = null;  
     
    265273 
    266274        var interval = (refreshTime) ? refreshTime/2 : 150000;  
    267         heartbeatTimer = setInterval(this.getLeaseInfo, interval, this.leaseRef(key), "HEAD");         
    268  
    269     } 
     275        this.heartbeatTimer = setInterval(this.getLeaseInfo, interval, this.leaseRef(key), "HEAD");         
     276 
     277    }; 
    270278     
    271279    UploadControl.prototype.getLeaseInfo = function (leaseRef, method) { 
     
    275283            url :leaseRef, 
    276284            success: function(data) { 
    277                 if(data)  refreshTime = data.refreshTime; 
     285                if(data)  { refreshTime = data.refreshTime; } 
    278286            } 
    279287        }); 
    280288        return refreshTime; 
    281     } 
     289    }; 
    282290     
    283291    UploadControl.prototype.endHeartBeat = function (key) { 
    284         clearInterval(heartbeatTimer); 
    285     } 
     292        clearInterval(this.heartbeatTimer); 
     293    }; 
    286294         
    287295    UploadControl.prototype.writeUserValue = function (value) { 
    288296        // no such thing, we just use the event to update the visual 
    289297        this.updateView(); 
    290     } 
     298    }; 
    291299     
    292300    UploadControl.prototype.readUserValue = function () { 
    293301        // no such thing 
    294     } 
    295  
    296    UploadControl.prototype.getUpdateElement = function(){ 
    297        return undefined; 
    298    }; 
    299      
    300    UploadControl.prototype.close = function(){ 
    301        var $container = this.getElement("input"); 
    302        $container.empty(); 
    303        var value = this.getValue(); 
    304        if(value != undefined) { 
    305          var isTemporary = value.ref ? false : true;  
    306          if (isTemporary) { 
    307              this.clearUploadedFile(value.id); 
    308          } 
    309        } 
    310    }; 
     302    }; 
     303 
     304    UploadControl.prototype.getUpdateElement = function(){ 
     305        return undefined; 
     306    }; 
     307     
     308    UploadControl.prototype.close = function(){ 
     309        var $container = this.getElement("input"); 
     310        $container.empty(); 
     311        var value = this.getValue(); 
     312        if(value != undefined) { 
     313            var isTemporary = value.ref ? false : true;  
     314            if (isTemporary) { 
     315                this.clearUploadedFile(value.id); 
     316            } 
     317        } 
     318    }; 
    311319     
    312320    kf.controlTypes.put("upload-control", UploadControl); 
    313321     
    314 })(jQuery); 
     322}(jQuery)); 
  • trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/validator.js

    r1920 r1948  
     1/* jslint eqeq: true */ 
    12/** 
    23 * @fileOverview This file holds the basic structure of the validation system 
     
    56( function( $) { 
    67 
    7     if (!$) 
     8    if (!$) {  
    89        throw "[validator.js] requires jQuery"; 
    9     if (!$.org.kauriproject.forms) 
     10    } 
     11    if (!$.org.kauriproject.forms) {  
    1012        throw "[validator.js] requires the kauri-form namespace"; 
     13    } 
    1114 
    1215    var kf = $.org.kauriproject.forms; 
    1316    var locale = kf.locale; 
    14  
    15     $.extend(kf, { 
    16         Validator :Validator, 
    17         ValidationListener :ValidationListener 
    18     }); 
    1917 
    2018    /** 
     
    3432     */ 
    3533    function Validator() { 
    36  
    3734    } 
    3835 
     
    5350 
    5451        return this.notifySuccess(); 
    55     } 
     52    }; 
    5653 
    5754    Validator.prototype.inSequence = function( listener, seqId) { 
     
    5956        this.listener = listener; 
    6057        this.seqId = seqId; 
    61     } 
     58    }; 
    6259 
    6360    Validator.prototype.clearSequence = function() { 
    6461 
    6562        this.inSequence(); 
    66     } 
     63    }; 
    6764 
    6865    Validator.prototype.toString = function() { 
    6966 
    7067        return "Validator('" + this['org.kauriproject.registry-name'] + "')"; 
    71     } 
     68    }; 
    7269 
    7370    Validator.prototype.notify = function( result, msg) { 
    7471        Validator.notify(this, result, msg); 
    75     } 
     72    }; 
    7673     
    7774    Validator.notify = function(me, result, msg) { 
    7875 
    79         if (!me.listener || !me.seqId) 
     76        if (!me.listener || !me.seqId) {  
    8077            return result; 
     78        } 
    8179 
    8280        me.listener.report(me.seqId, result, msg); 
     
    8482 
    8583        return result; 
    86     } 
     84    }; 
    8785 
    8886    Validator.prototype.notifyFail = function( msg, args) { 
    8987        Validator.notifyFail(this, msg, args); 
    90     } 
     88    }; 
    9189     
    9290    Validator.notifyFail = function(me, msg, args) { 
     
    9997    Validator.prototype.notifySuccess = function() { 
    10098        Validator.notifySuccess(this);  
    101     } 
     99    }; 
    102100    Validator.notifySuccess = function(me) { 
    103101        return Validator.notify(me, true); 
    104     } 
     102    }; 
    105103     
    106104    /** 
     
    108106    * @return true by default 
    109107    */ 
    110     Validator.prototype.isEnabled = function( ) { 
    111        return true; 
    112    } 
     108    Validator.prototype.isEnabled = function() { 
     109        return true; 
     110    }; 
    113111 
    114112    /** 
     
    118116    function ValidationListener( delegate) { 
    119117 
    120         this.currentSequenceId; 
    121         this.expects; 
     118        this.currentSequenceId = undefined; 
     119        this.expects = undefined; 
    122120        this.delegate = delegate || this; 
    123121    } 
     
    126124 
    127125        return new Number(Math.random() * 10000).toFixed(); 
    128     } 
     126    }; 
    129127 
    130128    ValidationListener.prototype.newSequenceId = function() { 
    131129 
    132130        return ValidationListener.newSequenceId(); 
    133     } 
     131    }; 
    134132 
    135133    ValidationListener.prototype.expect = function( n) { 
     
    139137        this.delegate.validationStart(); 
    140138        return this.sequenceId; 
    141     } 
     139    }; 
    142140 
    143141    ValidationListener.prototype.report = function( seqId, result, message) { 
    144142 
    145         if (this.sequenceId == seqId) { 
    146             if (result) 
     143        if (this.sequenceId === seqId) { 
     144            if (result) {  
    147145                this.delegate.validationSuccess(); 
    148             else 
     146            } else { 
    149147                this.delegate.validationFail(message); 
    150             if (--this.expects == 0) 
     148            } 
     149            if (--this.expects === 0) { 
    151150                this.delegate.validationComplete(); 
    152         } else 
     151            } 
     152        } else { 
    153153            this.delegate.validationIgnored(seqId, result, message); 
    154     } 
     154        } 
     155    }; 
    155156 
    156157    ValidationListener.prototype.validationSuccess = function() { 
    157  
    158     } 
     158    }; 
    159159 
    160160    ValidationListener.prototype.validationFail = function( message) { 
    161  
    162     } 
     161    }; 
    163162 
    164163    ValidationListener.prototype.validationStart = function() { 
    165  
    166     } 
     164    }; 
    167165 
    168166    ValidationListener.prototype.validationComplete = function() { 
    169  
    170     } 
     167    }; 
    171168 
    172169    ValidationListener.prototype.validationIgnored = function( seqId, result, message) { 
     170    }; 
    173171 
    174     } 
     172     
     173    $.extend(kf, { 
     174        Validator :Validator, 
     175        ValidationListener :ValidationListener 
     176    }); 
    175177 
    176 })(jQuery); 
     178 
     179}(jQuery)); 
Note: See TracChangeset for help on using the changeset viewer.