Changeset 1948
- Timestamp:
- 2011-09-09 14:41:24 (8 months ago)
- Location:
- trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms
- Files:
-
- 18 edited
-
basic-controls.js (modified) (28 diffs)
-
basic-fields.js (modified) (3 diffs)
-
basic-formatters.js (modified) (12 diffs)
-
basic-validators.js (modified) (14 diffs)
-
builder.js (modified) (7 diffs)
-
case.js (modified) (23 diffs)
-
collection.js (modified) (16 diffs)
-
composite.js (modified) (10 diffs)
-
control.js (modified) (130 diffs)
-
date.js (modified) (21 diffs)
-
field.js (modified) (45 diffs)
-
form.js (modified) (23 diffs)
-
formatter.js (modified) (6 diffs)
-
location.js (modified) (7 diffs)
-
numeric-range.js (modified) (14 diffs)
-
registry.js (modified) (24 diffs)
-
upload.js (modified) (18 diffs)
-
validator.js (modified) (11 diffs)
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 */ 1 2 /** 2 3 * @fileOverview This file holds some basic controltypes for standard forms. … … 5 6 ( function( $) { 6 7 7 if (!$) 8 if (!$) { 8 9 throw "Kauri Forms Basic-Controls requires jQuery"; 9 if (!$.org.kauriproject.forms) 10 } 11 if (!$.org.kauriproject.forms) { 10 12 throw "Kauri Forms Basic-Controls requires the kauri-form namespace"; 13 } 11 14 12 15 var kp = $.org.kauriproject; … … 17 20 // - textarea, choice, group-checkbox, images... 18 21 19 $.inherit(InputControl, kf.Control);20 22 /** 21 23 * @class Specific ControlType for simple character input-boxes. … … 30 32 kf.Control.init(this, id, form, conf); 31 33 } 34 $.inherit(InputControl, kf.Control); 32 35 33 36 /** … … 51 54 52 55 //default 53 if (!this.password) 54 this.password = false; 56 if (!this.password) { 57 this.password = false; 58 } 55 59 56 60 if ($input.attr('type') == 'password') { … … 69 73 this.setElement( kf.ControlElements.REV_INPUT, $input); 70 74 } 71 } 75 }; 72 76 73 77 /** … … 79 83 var $input = this.getElement(); 80 84 return $input.val(); 81 } 85 }; 82 86 /** 83 87 * Reads the value that was entered by the user. … … 89 93 var $input = this.getElement(); 90 94 $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. 97 100 * @class Specific ControlType for simple output (wrapped in a <span/>) 98 101 * @param {String} id … … 106 109 kf.Control.init(this, id, form, conf); 107 110 } 111 $.inherit(OutputControl, kf.Control); 108 112 109 113 /** … … 125 129 126 130 //default 127 if (!this.html) 131 if (!this.html) { 128 132 this.html = false; 129 130 } 133 } 134 135 }; 131 136 132 137 /** … … 137 142 138 143 var $input = this.getElement(); 139 return $input[this.html?'html':'text']( value);140 } 144 return $input[this.html?'html':'text'](); 145 }; 141 146 /** 142 147 * Reads the value that was entered by the user. … … 148 153 var $input = this.getElement(); 149 154 $input[this.html?'html':'text'](value); 150 } 151 152 153 $.inherit(CheckBoxControl, kf.Control); 155 }; 156 154 157 155 158 /** … … 163 166 kf.Control.init(this, id, form, type); 164 167 } 168 $.inherit(CheckBoxControl, kf.Control); 165 169 166 170 … … 179 183 this._input = $input; 180 184 this.value = false; 181 } 185 }; 182 186 183 187 … … 198 202 } 199 203 200 } 204 }; 201 205 202 206 … … 207 211 */ 208 212 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 !! operation213 if (value && value.constructor == Boolean && typeof value === 'object') { return value; }// note Boolean object holding false would become true with !! operation 210 214 return new Boolean(!!value); //anything becomes true, nothing or false becomes false 211 } 215 }; 212 216 213 217 CheckBoxControl.prototype.readUserValue = function() { 214 218 215 if (this._input.attr("checked")) 219 if (this._input.attr("checked")) { 216 220 return true; 217 else221 } else{ 218 222 return false; 219 } 223 } 224 }; 220 225 221 226 CheckBoxControl.prototype.writeUserValue = function( value) { 222 227 223 if (value == true || value == "true") 228 if (value == true || value == "true") { 224 229 this._input.attr("checked", "checked"); 225 else230 } else { 226 231 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 233 237 /** 234 238 * Specific ControlType for select-boxes with multiple options in a <select> … … 241 245 kf.Control.init(this, id, form, type); 242 246 } 247 $.inherit(SelectionControl, kf.Control); 243 248 244 249 SelectionControl.prototype.templates = {}; … … 301 306 } 302 307 } 303 } 308 }; 304 309 305 310 … … 320 325 // loop options from type and construct the inner HTML 321 326 var last = userValues.length; 322 for ( var i = 0; i < last; i++) { 327 var i; 328 for ( i = 0; i < last; i++) { 323 329 $("<option value='" + userValues[i] + "'>" + labels[i] + "</option>").appendTo($select); 324 330 } … … 333 339 // on IE we need to trigger repaint by 334 340 $select.blur(); // calling blur 335 } 341 }; 336 342 337 343 /** … … 355 361 // first fall-back: take the initial value if that is available in the options-list 356 362 value = this.options.trimValues(this.initial.value); 357 if (value == undefined) 363 if (value == undefined) { 358 364 value = values[0]; //final fall-back: pick the first value, since that is what the control will show anyway 365 } 359 366 } 360 367 361 368 return value; 362 } 369 }; 363 370 364 371 SelectionControl.prototype.readUserValue = function() { … … 367 374 368 375 return $select.val(); 369 } 376 }; 370 377 371 378 SelectionControl.prototype.writeUserValue = function( value) { … … 374 381 375 382 if(value.constructor == Array){ 376 for(var v in value) 383 var v; 384 for(v in value) { 377 385 value[v] = value[v].toString(); 386 } 378 387 $select.val(value); 379 388 }else 380 389 $select.val(value.toString()); 381 } 382 383 $.inherit(TextareaControl, kf.Control); 390 }; 391 384 392 385 393 /** … … 393 401 kf.Control.init(this, id, form, type); 394 402 } 403 $.inherit(TextareaControl, kf.Control); 395 404 396 405 TextareaControl.prototype.templates = {}; … … 406 415 407 416 // defaults 408 if (!this.cols) 417 if (!this.cols) { 409 418 this.cols = 22; 410 if (!this.rows) 419 } 420 if (!this.rows) { 411 421 this.rows = 3; 422 } 412 423 if (!this.readonly){ 413 424 this.readonly = false; … … 422 433 // the only way to check this, is by using an attribute selector 423 434 ($('textarea[readonly]' ,$unselectableElement).size() == 1)? (this.readonly = $textarea.attr('readonly')) : $textarea.attr('readonly', this.readonly); 424 } 435 }; 425 436 426 437 TextareaControl.prototype.readUserValue = function() { 427 438 428 439 return this.getElement().val(); 429 } 440 }; 430 441 431 442 TextareaControl.prototype.writeUserValue = function( value) { … … 433 444 value = value || ""; 434 445 this.getElement().val(value); 435 } 446 }; 436 447 437 448 // adding the new types to the registry... … … 443 454 "textarea-control" :TextareaControl 444 455 }); 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 */ 1 2 /** 2 3 * @fileOverview This file holds the basic structure of the fields composing the forms … … 5 6 ( function( $) { 6 7 7 if (!$) 8 if (!$) { 8 9 throw "Kauri Forms Fields requires jQuery"; 9 if (!$.org.kauriproject.forms) 10 } 11 if (!$.org.kauriproject.forms) { 10 12 throw "Kauri Forms Fields requires the kauri-form namespace"; 13 } 11 14 12 15 var kf = $.org.kauriproject.forms; … … 46 49 '+validators': { 'isUrl': {} } 47 50 } 48 49 50 51 }); 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 */ 1 2 /** 2 3 * @fileOverview This file holds the basic structure of the validation system … … 5 6 ( function( $) { 6 7 7 if (!$) 8 if (!$) { 8 9 throw "[basic-formatters.js] requires jQuery"; 9 if (!$.org.kauriproject.forms) 10 } 11 if (!$.org.kauriproject.forms) { 10 12 throw "[basic-formatters.js] requires the kauri-form namespace"; 13 } 11 14 12 15 var kf = $.org.kauriproject.forms; … … 22 25 format : function( val) { 23 26 24 if (val == undefined) 27 if (val == undefined) { 25 28 return ""; 29 } 26 30 if (val.constructor != Boolean) { 27 31 this.fail("Not a valid boolean: {0}.", [ val ]); 28 32 } 29 33 30 if (this.asIs) return val;34 if (this.asIs) { return val;} 31 35 32 36 return val.toString(); … … 37 41 if (typeof valstr == 'string') { 38 42 valstr = $.trim(valstr); 39 if (valstr.length == 0) 43 if (valstr.length == 0) { 40 44 return undefined; 45 } 41 46 var FALSE_REGEX = new RegExp("^false$", "ig"); 42 47 var match = FALSE_REGEX.test(valstr); 43 if (match) 48 if (match) { 44 49 return new Boolean(false); 50 } 45 51 } 46 52 return new Boolean(valstr); … … 56 62 format : function( val) { 57 63 58 if (val == undefined || val == null) 64 if (val == undefined || val == null) { 59 65 return ""; 60 if (val.constructor != Number) 66 } 67 if (val.constructor != Number) { 61 68 this.fail("Not a valid number: {0}.", [ val ]); 69 } 62 70 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();} 65 73 66 74 if(this.decimal){ … … 69 77 // no decimals wanted, skip the trailing zeros 70 78 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) { 72 80 return parts[0]; 73 else81 } else { 74 82 return val.toLocaleString(); 83 } 75 84 } 76 85 }, … … 97 106 // replace decimal-separator with '.' 98 107 valstr = valstr.replace(decimalSep, "."); 99 if (valstr.length == 0) 108 if (valstr.length == 0) { 100 109 return undefined; 110 } 101 111 102 112 valstr = valstr.replace(/\s/g,""); … … 105 115 var val = (valstr == null) ? null : new Number(valstr); 106 116 107 if (isNaN(val)) 117 if (isNaN(val)) { 108 118 this.fail("Not a valid number: {0}.", [ valstr ]); 119 } 109 120 110 121 return val; … … 116 127 format : function( val) { 117 128 118 if (val == undefined) 129 if (val == undefined) { 119 130 return ""; 131 } 120 132 val = val.toString(); 121 133 122 134 var last = this.pattern.length; 123 135 var valstr = ""; 124 var j = 0;125 for ( vari = 0; i < last; i++) {136 var i = 0, j = 0; 137 for ( i = 0; i < last; i++) { 126 138 var c = this.pattern.charAt(i); 127 139 var k = c; 128 140 if (c == '$') { 129 141 k = val.charAt(j++); 130 if (k == undefined || !k.match(/[a-z0-9]/i)) 142 if (k == undefined || !k.match(/[a-z0-9]/i)) { 131 143 this.fail("Input {0} doesn't match pattern {1}. Expected alfanumeric (a-z0-9) at position {2}.", [ 132 144 val, this.pattern, i ]); 145 } 133 146 } else if (c == '#') { 134 147 k = val.charAt(j++); 135 if (k == undefined || !k.match(/[0-9]/i)) 148 if (k == undefined || !k.match(/[0-9]/i)) { 136 149 this.fail("Input {0} doesn't match pattern {1}. Expected digit (0-9) at position {2}.", [ val, 137 150 this.pattern, i ]); 151 } 138 152 } else if (c == "*") { 139 153 k = val.substr(j); … … 143 157 } 144 158 145 if (j != val.length) 159 if (j != val.length) { 146 160 this.fail("Input {0} doesn't match pattern {1}. More characters then pattern can hold.", 147 161 [ val, this.pattern ]); 162 } 148 163 149 164 return valstr; … … 153 168 154 169 valstr = $.trim(valstr); 155 if (valstr.length == 0) 170 if (valstr.length == 0) { 156 171 return undefined; 172 } 157 173 valstr = valstr.replace(STRIP_REGEX, ""); 158 174 return valstr; … … 162 178 }); 163 179 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 */ 1 2 /** 2 3 * @fileOverview This file holds the basic structure of the validation system … … 5 6 ( function( $) { 6 7 7 if (!$) 8 if (!$) { 8 9 throw "[basic-validators.js] requires jQuery"; 9 if (!$.org.kauriproject.forms) 10 } 11 if (!$.org.kauriproject.forms) { 10 12 throw "[basic-validators.js] requires the kauri-form namespace"; 13 } 11 14 12 15 var kp = $.org.kauriproject; … … 18 21 // define re-useable regexes once 19 22 // 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; 21 24 22 25 // uri regex from http://www.osix.net/modules/article/?id=586, 23 26 // fixed to allow portnumbers of up to 5 digits 24 27 // 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_!~*\'().;?:@&=+$,%#\-]+)+\/?)$/; 26 29 // | scheme | :// | user:password @ | ip adrress | 3rd level domain 2nd level domain top level domain | :portnumber | path | 27 30 28 31 kf.Validator.validateInt = function(me, value) { 29 if (value == undefined) 32 if (value == undefined) { 30 33 return me.notifySuccess(); 31 32 if (typeof value == 'number') 34 } 35 36 if (typeof value == 'number') { 33 37 value = new Number(value); 34 35 if (value.constructor != Number || isNaN(value)) 38 } 39 40 if (value.constructor != Number || isNaN(value)) { 36 41 return me.notifyFail("i18n:Not a number."); 42 } 37 43 38 44 var intValueStr = value.toFixed(0); 39 45 var valueStr = value.toString(); 40 46 41 if (intValueStr != valueStr) 47 if (intValueStr != valueStr) { 42 48 return me.notifyFail("i18n:Not a valid integer!"); 49 } 43 50 44 51 return me.notifySuccess(); 45 } 52 }; 46 53 47 54 validators.putAll( { … … 68 75 validate : function( value) { 69 76 70 if ($.isEmpty(value)) 71 return this.notifySuccess(); 77 if ($.isEmpty(value)) { 78 return this.notifySuccess(); 79 } 72 80 73 81 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))) { 75 83 return this.notifyFail("i18n:Should be at least {0}, at most {1}, and in steps of {2}!", [ this.min, this.max, 76 84 this.step ]); 85 } 77 86 78 87 return this.notifySuccess(); … … 84 93 validate : function( value) { 85 94 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 } 88 98 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)) { 90 100 return this.notifyFail("i18n:Should be at least {0} and at most {1} characters!", [ this.min, this.max ]); 101 } 91 102 92 103 return this.notifySuccess(); … … 97 108 validate : function( value) { 98 109 99 if ($.isEmpty(value)) 100 return this.notifySuccess(); 110 if ($.isEmpty(value)) { 111 return this.notifySuccess(); 112 } 101 113 102 114 this.assertRegexInitialization(); 103 115 104 if (this.regex.test(value) != true) 116 if (this.regex.test(value) != true) { 105 117 return this.notifyFail("i18n:Not a valid value according to the regex ({0}).", [ this.regex ]); 118 } 106 119 107 120 return this.notifySuccess(); … … 109 122 110 123 assertRegexInitialization : function() { 111 if (typeof this.regex === "string") 124 if (typeof this.regex === "string") { 112 125 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)) { 115 129 throw "Regex validation badly configured."; // TODO or should we silently switch to an accept all regex? 130 } 116 131 } 117 132 }, … … 120 135 validate : function( value) { 121 136 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) { 126 142 return this.notifyFail("i18n:Not a valid email adress"); 143 } 127 144 128 145 return this.notifySuccess(); … … 133 150 validate : function( value) { 134 151 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) { 139 157 return this.notifyFail("i18n:Not a valid url"); 158 } 140 159 141 160 return this.notifySuccess(); … … 146 165 validate : function( value, data) { 147 166 148 if ($.isEmpty(value)) 149 return this.notifySuccess(); 167 if ($.isEmpty(value)) { 168 return this.notifySuccess(); 169 } 150 170 151 171 var options = data.options || []; 152 if ($.valueInArray(value, options) < 0) 172 if ($.valueInArray(value, options) < 0) { 153 173 return this.notifyFail("i18n:Value[{0}](@pos {1}) not in list of available options.", [ value, data.index ]); 174 } 154 175 155 176 return this.notifySuccess(); … … 160 181 validate : function( value, validationData) { 161 182 162 if ($.isEmpty(value)) 163 return this.notifySuccess(); 183 if ($.isEmpty(value)) { 184 return this.notifySuccess(); 185 } 164 186 165 187 //take the wireValue in stead … … 167 189 value = kp.JSON.stringify(value); 168 190 169 if (!this.location) 191 if (!this.location) { 170 192 throw "A location-path for remote validation should be given!"; 193 } 171 194 172 195 var me = this; 196 var errorHandler = function() { 197 return me.notifyFail("i18n:Error while connecting to remote validation."); 198 }; 173 199 var successHandler = function( response, txtstatus, xhr) { 174 200 … … 187 213 return me.notifyFail("i18n:Remote validation returned incompatible response!"); 188 214 }; 189 var errorHandler = function() {190 return me.notifyFail("i18n:Error while connecting to remote validation.");191 };192 215 try { 193 216 $.ajax( { … … 210 233 }); 211 234 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 */ 1 2 /** 2 3 * @fileOverview This script initializes the Kauri Forms 'System' … … 6 7 ( function( $) { 7 8 8 if (!$) 9 if (!$) { 9 10 throw "[builder.js] requires jQuery"; 10 if (!$.org.kauriproject.forms) 11 } 12 if (!$.org.kauriproject.forms) { 11 13 throw "[builder.js] requires the kauri-form namespace"; 14 } 12 15 13 16 var kf = $.org.kauriproject.forms; 14 17 var kp = $.org.kauriproject; 15 18 16 $.extend(kf, {17 Builder :Builder18 });19 19 20 20 /** … … 32 32 // create the registries 33 33 var last = this.registryNames.length; 34 for ( var i = 0; i < last; i++) { 34 var i = 0; 35 for ( i = 0; i < last; i++) { 35 36 var name = this.registryNames[i]; 36 37 this[name] = new kf.ConstructorRegistry("Registry of [" + level + "] " + name, parent[name]); … … 44 45 this.controlTypes.setBaseConstructor(kf.Control); 45 46 } 47 $.extend(kf, { Builder :Builder}); 46 48 47 49 /** … … 59 61 60 62 var last = this.registryNames.length; 61 for ( var i = 0; i < last; i++) { 63 var i = 0; 64 for ( i = 0; i < last; i++) { 62 65 var name = this.registryNames[i]; 63 66 64 67 if (name == "fieldTypes") { 65 for (var prop in conf[name]) { 68 var prop; 69 for (prop in conf[name]) { 66 70 // 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) { 68 72 conf[name][prop].base = 'composite'; 73 } 69 74 } 70 75 } … … 75 80 // TODO think about a good path location for dynamic loaded components (fieldtypes, validators, ..) 76 81 // and a way to describe that in the conf, maybe conf.locations = { validators: .., ...}; 77 } 82 }; 78 83 79 84 /** … … 91 96 Builder.prototype.getInstance = function( /* String */registry, /* String */name, /* Object */extender, /* array */args) { 92 97 93 if (this[registry] == undefined || this[registry].constructor != kf.ConstructorRegistry) 98 if (this[registry] == undefined || this[registry].constructor != kf.ConstructorRegistry) { 94 99 return; 100 } 95 101 return this[registry].getInstance(name, extender, args); 96 } 102 }; 97 103 98 104 // initialize the 'basic' builder level. 99 105 $.extend(kf, new Builder("Basic")); 100 106 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 */ 1 2 /** 2 3 * @fileOverview This file holds the fieldtype and controltype for handling case-data-structures. … … 5 6 ( function( $) { 6 7 7 if (!$) 8 if (!$) { 8 9 throw "[case.js] requires jQuery"; 9 if (!$.org.kauriproject.forms) 10 } 11 if (!$.org.kauriproject.forms) { 10 12 throw "[case.js] requires the kauri-form namespace"; 13 } 11 14 12 15 var kp = $.org.kauriproject; … … 16 19 var validators = kf.validators; 17 20 18 /**19 20 */21 $.inherit(CaseFieldType, kf.FieldType);22 21 23 22 /** … … 29 28 kf.FieldType.init(this); 30 29 } 30 $.inherit(CaseFieldType, kf.FieldType); 31 31 32 32 /** … … 62 62 CaseFieldType.configBuild = function( builder, protype) { 63 63 kf.FieldType.configBuild(builder, protype); // keep handling the basic stuff. 64 if (protype.cases) 64 if (protype.cases) { 65 65 kf.FieldType.createTypes(builder, protype.cases); 66 } 66 67 if (protype.selector) { 67 68 var selectorType = {selector : protype.selector}; … … 69 70 protype.selector = selectorType.selector; 70 71 } 71 } 72 }; 72 73 73 74 /** … … 78 79 CaseFieldType.prototype.getCaseTypes = function() { 79 80 return this.cases; 80 } 81 }; 81 82 82 83 /** … … 88 89 CaseFieldType.prototype.getCaseType = function(name) { 89 90 return this.cases[name]; 90 } 91 }; 91 92 92 93 /** … … 98 99 CaseFieldType.prototype.getCaseControlType = function(name) { 99 100 return this.getCaseType(name).control; 100 } 101 }; 101 102 102 103 /** … … 107 108 CaseFieldType.prototype.getSelectorType = function () { 108 109 return this.selector; 109 } 110 }; 110 111 111 112 /* CASE CONTROL */ 112 113 $.inherit(CaseControl, kf.AbstractContainerControl);114 113 115 114 /** … … 129 128 kf.Control.init(this, id, form, conf); 130 129 } 131 130 $.inherit(CaseControl, kf.AbstractContainerControl); 131 132 132 CaseControl.prototype.templates = {}; 133 133 … … 139 139 140 140 141 142 141 var CASE_PFX = "case-"; 143 142 … … 167 166 } 168 167 169 170 for ( varcaseName in caseTypes) {168 var caseName; 169 for ( caseName in caseTypes) { 171 170 var caseType = caseTypes[caseName]; 172 171 var valueControl = this.createChildControl(CASE_PFX + caseName, caseType); … … 188 187 // typically for selection-controls we set the options from the collected cases. 189 188 var options = caseControl.options; 190 if (options) 189 if (options) { 191 190 options.set(optionValues, optionLabels); 191 } 192 192 193 193 caseControl.setWireValue(optionValues[0], true); //noValidation on init of elements … … 195 195 this.putChild("case", caseControl); 196 196 197 } 197 }; 198 198 199 199 /** … … 205 205 CaseControl.prototype.getChildren = function(includeAll) { 206 206 includeAll = includeAll || false; 207 if (includeAll) 207 if (includeAll) { 208 208 return this._valueControls; 209 } 209 210 return kf.AbstractContainerControl.getChildren(this); 210 211 211 } 212 }; 212 213 213 214 /** … … 230 231 //else default to 231 232 return null; 232 } 233 }; 233 234 CaseControl.prototype.getChildByPathSegment = function(pathSegment){ 234 235 return this.getChild(pathSegment); 235 } 236 }; 236 237 237 238 /** … … 250 251 var value = me.getChild("value"); 251 252 252 if(value) 253 if(value) { 253 254 me.getChild("value").hide(); 255 } 254 256 255 257 // find the new value control … … 260 262 valueControl.resetShowState(); // don't just show, restore initial view state 261 263 }else{ 262 if(me.nullable) 264 if(me.nullable) { 263 265 me.deleteChild("value"); 264 else266 } else { 265 267 me.setMessage("Sorry but " + selectedCase + " is not a valid value"); 268 } 266 269 } 267 270 var noValidation = (this.valueState == kf.Control.STATE_INIT); 268 if(!noValidation) 271 if(!noValidation) { 269 272 me.newValidation(this.getValue(), this.getWireValue()); 273 } 270 274 }); 271 } 275 }; 272 276 273 277 … … 276 280 }; 277 281 CaseControl.reset = function(me) { 282 var i; 283 278 284 // reset children: first elements in me._valueControls, then me.caseControl 279 285 for (i in me._valueControls) { … … 298 304 } else { 299 305 me._valueControls[i].hide(); 300 } ;306 } 301 307 } 302 308 303 309 me.valueState = me.STATE_INIT; 304 310 me.updateValidationClasses(); 305 } 311 }; 306 312 307 313 /** … … 326 332 327 333 this.getChild("value").resetShowState(); 328 } 334 }; 329 335 330 336 … … 332 338 controlTypes.put("case-control", CaseControl); 333 339 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 */ 1 2 /** 2 3 * @fileOverview This file describes the field-type and controltype for collections … … 6 7 ( function( $) { 7 8 8 if (!$) 9 if (!$) { 9 10 throw "[collection.js] requires jQuery"; 10 if (!$.org.kauriproject.forms) 11 } 12 if (!$.org.kauriproject.forms){ 11 13 throw "[collection.js] requires the kauri-form namespace"; 14 } 12 15 13 16 var kf = $.org.kauriproject.forms; … … 16 19 17 20 18 $.inherit(CollectionFieldType, kf.FieldType);19 21 /** 20 22 * Specific FieldType that takes care of creating the field-type used to model the children (= the "rows" … … 28 30 kf.FieldType.init(this); 29 31 } 32 $.inherit(CollectionFieldType, kf.FieldType); 30 33 31 34 CollectionFieldType.prototype.control = 'collection-control'; 32 35 CollectionFieldType.prototype.validators = []; 33 36 34 CollectionFieldType.prototype.child;35 36 37 CollectionFieldType.configBuild = function( builder, protype) { 37 38 38 39 kf.FieldType.configBuild(builder, protype); // keep handling the basic stuff. 39 if (protype.child) 40 if (protype.child) { 40 41 protype.child = kf.FieldType.buildType(builder, protype.child); 41 } 42 } 43 }; 42 44 43 45 CollectionFieldType.prototype.getChildType = function() { 44 46 return this.child; 45 } 47 }; 46 48 47 49 CollectionFieldType.prototype.getChildControlType = function() { 48 50 return this.child.control; 49 } 50 51 52 $.inherit(CollectionControl, kf.AbstractContainerControl); 51 }; 52 53 53 54 /** 54 55 * Specific ControlType for collections of elements. … … 60 61 kf.Control.init(this, id, form, conf); 61 62 } 63 $.inherit(CollectionControl, kf.AbstractContainerControl); 62 64 63 65 CollectionControl.idCount = 0; … … 126 128 127 129 this._childrenContainer = container; 128 } 130 }; 129 131 130 132 CollectionControl.prototype.initial = $.extend(true, $.extend({}, kf.AbstractContainerControl.prototype.initial), {"value": []}); … … 138 140 139 141 this.removeChildren(); 140 } 142 }; 141 143 142 144 /** … … 149 151 150 152 // 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) { 152 155 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. 154 157 cfn(i, child); 155 } 156 } 158 } 159 } 160 }; 157 161 158 162 /** … … 167 171 } 168 172 return children[index]; 169 } 173 }; 170 174 171 175 /** … … 175 179 */ 176 180 CollectionControl.prototype.getChild = function(id) { 177 var children = this.getChildren() ;178 for ( vari = 0; i < children.length; i++) {181 var children = this.getChildren(), i=0; 182 for (i = 0; i < children.length; i++) { 179 183 if (children[i].getId() === id) { 180 184 return children[i]; … … 182 186 } 183 187 return null; 184 } 188 }; 185 189 186 190 /** … … 190 194 */ 191 195 CollectionControl.prototype.getChildIndex = function(id) { 192 var children = this.getChildren() ;193 for ( vari = 0; i < children.length; i++) {196 var children = this.getChildren(), i=0; 197 for (i = 0; i < children.length; i++) { 194 198 if (children[i].getId() == id) { 195 199 return i; … … 197 201 } 198 202 return null; 199 } 203 }; 200 204 201 205 CollectionControl.prototype.getChildByPathSegment = function(pathSegment){ 202 206 return this.getChildren()[pathSegment]; 203 } 207 }; 204 208 205 209 CollectionControl.prototype.newChildId = function() { 206 210 return "rid-" + CollectionControl.idCount++; 207 } 211 }; 208 212 209 213 /** … … 253 257 254 258 return childControl; 255 } 259 }; 256 260 257 261 CollectionControl.prototype.removeChild = function(childId) { 258 262 var childIndex = this.getChildIndex(childId); 259 if (childIndex == null) 263 if (childIndex == null) { 260 264 throw "No child in collection with id " + childId; 265 } 261 266 262 267 var child = this.getChild(childId); 263 if (child == null) 268 if (child == null) { 264 269 throw "No child in collection with index " + childIndex; 270 } 265 271 266 272 child.close(); … … 268 274 // remove it from array 269 275 this.getChildren().splice(childIndex, 1); 270 } 276 }; 271 277 272 278 // adding the new types to the registries... … … 274 280 controlTypes.put("collection-control", CollectionControl); 275 281 276 } )(jQuery);282 }(jQuery)); -
trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/composite.js
r1920 r1948 5 5 ( function( $) { 6 6 7 if (!$) 7 if (!$) { 8 8 throw "[composite.js] requires jQuery"; 9 if (!$.org.kauriproject.forms) 9 } 10 if (!$.org.kauriproject.forms){ 10 11 throw "[composite.js] requires the kauri-form namespace"; 12 } 11 13 12 14 var kp = $.org.kauriproject; … … 17 19 18 20 19 $.inherit(CompositeFieldType, kf.FieldType);20 21 /** 21 22 * Specific FieldType that takes care of creating the field-type used to model the members. … … 28 29 kf.FieldType.init(this); 29 30 } 31 $.inherit(CompositeFieldType, kf.FieldType); 30 32 31 33 CompositeFieldType.prototype.control = 'composite-control'; … … 37 39 38 40 kf.FieldType.configBuild(builder, protype); // keep handling the basic stuff. 39 if (protype.members) 41 if (protype.members) { 40 42 kf.FieldType.createTypes(builder, protype.members); 41 } 43 } 44 }; 42 45 43 46 CompositeFieldType.prototype.getMemberTypes = function() { 44 47 45 48 return this.members; 46 } 49 }; 47 50 48 51 CompositeFieldType.prototype.getMemberType = function( name) { 49 52 50 53 return this.members[name]; 51 } 54 }; 52 55 53 56 CompositeFieldType.prototype.getMemberControlType = function( name) { 54 57 55 58 return this.members[name].control; 56 } 59 }; 57 60 58 61 59 $.inherit(CompositeControl, kf.AbstractContainerControl);60 62 /** 61 63 * CompositeControlType groups and contains the various member-control-types it is composed off. … … 73 75 */ 74 76 function CompositeControl( id, form, conf) { 75 76 77 kf.Control.init(this, id, form, conf); 77 78 } 79 $.inherit(CompositeControl, kf.AbstractContainerControl); 78 80 79 81 CompositeControl.prototype.templates = {}; … … 94 96 95 97 var orderArray = type.order || []; 98 var memberName; 96 99 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 = {}; 99 103 if(position == -1){ 100 104 // 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; 104 107 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; 109 111 orderArray[position] = orderObj; 110 112 } 111 113 112 114 } 113 orderArray.sort( function (a,b) { return b.order < a.order } );115 orderArray.sort( function (a,b) { return b.order < a.order; } ); 114 116 115 for (var sKey in orderArray) { 117 var sKey; 118 for (sKey in orderArray) { 116 119 var childControl = this.createChildControl(orderArray[sKey].memberName, orderArray[sKey].memberType); 117 120 this.putChild(orderArray[sKey].memberName, childControl); 118 121 } 119 120 121 } 122 }; 123 122 124 123 125 CompositeControl.prototype.createChildElements = function (id, container, layout) { … … 128 130 //var item = $(this.getTemplate('layout')).appendTo(container); 129 131 //return item; 130 } 132 }; 131 133 132 134 // adding the new types to the registries... … … 142 144 var a = $.trim(this.fieldA); 143 145 var b = $.trim(this.fieldB); 144 if (a.indexOf('{') < 0) 146 if (a.indexOf('{') < 0) { 145 147 a = "{" + a + "}"; 146 if (b.indexOf('{') < 0) 148 } 149 if (b.indexOf('{') < 0) { 147 150 b = "{" + b + "}"; 151 } 148 152 149 153 this.templA = new kp.UriTemplate(a); … … 151 155 }, 152 156 validate : function (value) { 153 if ($.isEmpty(value)) 157 if ($.isEmpty(value)) { 154 158 return this.notifySuccess(); 159 } 155 160 156 161 var valA = this.templA.expand(value); 157 162 var valB = this.templB.expand(value); 158 163 159 if (this._operations[this.operation](valA, valB)) 164 if (this._operations[this.operation](valA, valB)) { 160 165 return this.notifySuccess(); 161 else166 } else { 162 167 return this.notifyFail(valA + " is not " + this.operation + " than " + valB); 163 168 } 164 169 }, 165 170 _operations : { … … 187 192 }); 188 193 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 */ 1 2 /** 2 3 * @fileOverview This file holds the basic structure of the control system … … 5 6 (function($){ 6 7 7 if (!$) 8 if (!$) { 8 9 throw "[control.js] requires jQuery"; 9 if (!$.org.kauriproject.forms) 10 } 11 if (!$.org.kauriproject.forms) { 10 12 throw "[control.js] requires kauri-form namespace"; 13 } 11 14 12 15 var kf = $.org.kauriproject.forms; 13 16 var locale = kf.locale; 14 15 $.extend(kf, {16 ControlElements: ControlElements,17 Control: Control,18 AbstractContainerControl: AbstractContainerControl19 });20 17 21 18 … … 182 179 var layout = $this.attr(ControlElements.ATTR_LAYOUT); 183 180 184 if (idref.length == 0 || idref.charAt(0) != '/')181 if (idref.length === 0 || idref.charAt(0) !== '/') { 185 182 index = parentindex; 183 } 186 184 if (idref) { 187 185 index = $.concatPath(index, idref); … … 197 195 198 196 store.addTypeAndControl(index, type, control); 199 if(childtype) 197 if(childtype) { 200 198 store.addChildType(index, childtype); 199 } 201 200 202 if((value != undefined && value != "") || disabled == true || (type != undefined && type== 'hidden') ){201 if((value != undefined && value !== "") || disabled === true || (type != undefined && type === 'hidden') ){ 203 202 var initial = {}; 204 203 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; 207 206 store.addInitialProperties(index, initial); 208 207 } … … 211 210 if(layout){ 212 211 var layoutindex; 213 if (layout.length == 0 || layout.charAt(0) != '/')212 if (layout.length === 0 || layout.charAt(0) !== '/') { 214 213 layoutindex = parentindex; 214 } 215 215 if (layout) { 216 216 layoutindex = $.concatPath(layoutindex, layout); … … 222 222 $this.children().each(function(){ 223 223 var $child = $(this); 224 ControlElements.initialIndex($child, store, index) 224 ControlElements.initialIndex($child, store, index); 225 225 }); 226 226 }); 227 } 227 }; 228 228 229 229 /** … … 236 236 * @static 237 237 */ 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); 245 245 246 if (index.length== 0) { //no explicit index is set - build it from the idref247 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 } 254 254 255 // do elementIndexing + cursorIndexing256 // get relevant attributes kauri-idref, kauri-role, kauri-layout, kauri-cursor257 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); 260 260 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 } 277 278 278 if(!layout){279 // now index each child of $this280 $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 it286 if( ! store.getCursorIndex(index, group) ){287 varcursor = $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 }; 298 299 299 300 … … 308 309 this.elementIndex[index].control = control; 309 310 } 310 } 311 }; 311 312 312 313 ControlElements.prototype.addChildType = function(index, childtype){ 313 314 314 if (childtype != undefined) { 315 315 this.elementIndex[index] = this.elementIndex[index] || ControlElements.newElements(); 316 316 this.elementIndex[index].childtype = childtype; 317 317 } 318 } 318 }; 319 319 320 320 … … 323 323 this.elementIndex[index] = this.elementIndex[index] || ControlElements.newElements(); 324 324 this.elementIndex[index].initial = initialProperties; 325 326 } 327 } 328 329 325 } 326 }; 327 330 328 331 329 ControlElements.prototype.getImplicitConfig = function() { … … 335 333 var field = {}; 336 334 337 for ( var index in this.elementIndex) { 335 var index; 336 for ( index in this.elementIndex) { 338 337 if (((this.elementIndex[index].type != undefined) 339 338 || (this.elementIndex[index].control != undefined) || (this.elementIndex[index].initial != undefined)) 340 && index != "/") {339 && index !== "/") { 341 340 var segments = index.split('/'); 342 341 var control = implicitFconf; 343 342 344 343 // search in fconf which control to edit 344 var i; 345 345 for (i = 0; i < segments.length; i++) { 346 if (segments[i] == "") {346 if (segments[i] === "") { 347 347 continue; 348 348 } 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; 353 354 } 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)] || {}; 362 362 control = control[segments[i].substr(5)]; 363 } else if (segments[i] == 'case') {363 } else if (segments[i] === 'case') { 364 364 control.selector = control.selector || {}; 365 365 control = control.selector; 366 366 } else { 367 throw segments[i] 368 + " is a valid name within 'case' controls"; 367 throw segments[i] + " is a valid name within 'case' controls"; 369 368 } 370 } else if (control ['members']!= undefined371 && 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; 376 375 } 377 control = control ['members'][segments[i]];376 control = control.members[segments[i]]; 378 377 } else { 379 if (control ['members']== undefined) {380 control ['members']= {};378 if (control.members == undefined) { 379 control.members = {}; 381 380 } 382 control = control ['members'];381 control = control.members; 383 382 control[segments[i]] = control[segments[i]] || {}; 384 383 control = control[segments[i]]; … … 389 388 390 389 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 } 393 393 394 394 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; 397 397 } else { 398 type ['control']= {};399 type ['control']['base']= this.elementIndex[index].control;398 type.control = {}; 399 type.control.base = this.elementIndex[index].control; 400 400 } 401 401 } 402 402 403 403 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; 406 406 } 407 407 var childtype = this.getElementIndex(index).childtype; 408 408 if (childtype) { 409 controlToEdit ['child'] = controlToEdit['child']|| {};410 controlToEdit ['child']['base']= childtype;409 controlToEdit.child = controlToEdit.child || {}; 410 controlToEdit.child.base = childtype; 411 411 } 412 412 … … 415 415 } 416 416 return implicitFconf; 417 } 417 }; 418 418 419 419 /** … … 428 428 ControlElements.lookup = function(control, relation){ 429 429 return control.getElement(relation); 430 } 430 }; 431 431 432 432 /** … … 441 441 ControlElements.removeRelationElement = function(control, relation){ 442 442 443 if (!relation) 443 if (!relation) { 444 444 throw "[ControlElements#lookup] no relation specified."; 445 } 445 446 var form = control.getForm(); 446 447 var index = control.getAbsoluteId(); 447 448 448 449 form.removeElementIndex(index, relation); 449 } 450 }; 450 451 451 452 … … 461 462 } 462 463 return $elm; 463 } 464 }; 464 465 465 466 ControlElements.lookupLayoutCursor = function(control) { … … 473 474 } 474 475 return $elm; 475 } 476 }; 476 477 477 478 … … 483 484 var index = control.getAbsoluteId(); 484 485 485 var allElms = new Array();486 var allElms = []; 486 487 var size = 0; 487 488 var elmIndex = form.getElementIndex(index); 488 489 489 490 var last = elmIndex.length; 490 for (var i = 0; i< last; i++) { 491 var i; 492 for (i = 0; i< last; i++) { 491 493 var elm = elmIndex[i]; 492 if(elm) 494 if(elm) { 493 495 allElms[size++] = elm; 496 } 494 497 } 495 498 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]) { 498 502 allElms[size++] = relElms[r]; 503 } 499 504 } 500 505 501 506 return allElms; 502 } 507 }; 503 508 504 509 /** … … 508 513 * @final 509 514 */ 510 ControlElements.INDEX_REGEX = /^([ ^#]+)(#(\w+))?$/;515 ControlElements.INDEX_REGEX = /^([\/\d\w\-_.]+)(#(\w+))?$/; 511 516 512 517 /** … … 528 533 relation: match[3] 529 534 }; 530 } 535 }; 531 536 532 537 /** … … 542 547 empty.meta = {}; 543 548 return empty; 544 } 545 546 ControlElements.newLayoutElements = function() {549 }; 550 551 ControlElements.newLayoutElements = function() { 547 552 var empty = []; 548 553 empty.layout = {}; 549 554 return empty; 550 } 555 }; 551 556 552 557 … … 562 567 563 568 return '[' + ControlElements.ATTR_ROLE + '="' + relation + '"]'; 564 } 569 }; 565 570 566 571 /** … … 603 608 return idfn.apply(this, [index]); 604 609 } 605 } 610 }; 606 611 607 612 … … 616 621 */ 617 622 ControlElements.prototype.clearElementIndex = function(index, relation){ 618 if (index == undefined) 619 return this.elementIndex = {}; 623 if (index == undefined) { 624 return this.elementIndex; 625 } 620 626 621 627 return this._operateIndex(index, relation, function(i){ … … 626 632 delete this.elementIndex[i].meta[r]; 627 633 }); 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 } 642 649 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 }; 656 664 657 665 … … 668 676 */ 669 677 ControlElements.prototype.addElementIndex = function(index, relation, elm){ 670 if (arguments.length == 2) {678 if (arguments.length === 2) { 671 679 elm = relation; 672 680 relation = undefined; … … 677 685 678 686 return this._operateIndex(index, relation, function(i){ 679 680 681 687 var elms = this.elementIndex[i] || ControlElements.newElements(); 682 688 elms[elms.length] = elm; … … 684 690 }, function(i, r){ 685 691 var elms = this.elementIndex[i] = this.elementIndex[i] || ControlElements.newElements(); 686 //TODO if (elms.meta[r])692 //TODO if (elms.meta[r]) 687 693 // throw "[ControlElements#addElementIndex] index already in use: " + i + "#" + r; 688 694 689 695 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! 691 697 elms[elms.length] = elm; 692 698 this.elementIndex[i] = elms; 693 699 } 694 700 }); 695 } 701 }; 696 702 697 703 /** … … 705 711 */ 706 712 ControlElements.prototype.getElementIndex = function(index, relation){ 707 if (index == undefined) 713 if (index == undefined) { 708 714 return this.elementIndex; 715 } 709 716 710 717 return this._operateIndex(index, relation, function(i){ … … 714 721 return this.elementIndex[i].meta[r]; 715 722 }); 716 } 717 718 /**719 * Removes the specified element from the index.720 *721 * @param {string}722 * [index] index to remove723 * @param {string}724 * [relation] relation-part to remove725 * @param (boolean)726 * [deleteChildren] set to true if you want all children to be deleted as well727 */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 */ 728 735 ControlElements.prototype.removeElementIndex = function(index, relation, deleteChildren){ 729 deleteChildren = deleteChildren || false;736 deleteChildren = deleteChildren || false; 730 737 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 }; 749 758 750 759 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 to758 * @param {$jquery}759 * elm element to add760 */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 index766 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] || []; 774 783 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 } 776 817 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 }; 792 853 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 806 862 var $elm; 807 863 //this.layoutIndex[index] = this.layoutIndex[index] || ControlElements.newLayoutElements(); 808 864 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 { 816 873 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 }; 861 876 862 877 … … 883 898 me._form = form; 884 899 885 if (conf != undefined) 900 if (conf != undefined) { 886 901 me.initialize(conf); 887 } 902 } 903 }; 888 904 889 905 /** … … 924 940 if (conf.isReady) { 925 941 type = conf; // if a ready type is passed to us, we can just use it 926 } 927 else { 942 } else { 928 943 type = this.createType(conf); 929 944 } 930 945 this.setType(type); 931 946 this.initType(); 932 } 947 }; 933 948 934 949 Control.prototype.initType = function(conf){ 935 } 950 }; 936 951 937 952 /** … … 945 960 var types = [conf]; 946 961 947 948 962 kf.FieldType.createTypes(form, types); 949 963 … … 957 971 * @private 958 972 */ 959 Control.prototype._templates ;973 Control.prototype._templates = null; 960 974 961 975 /** … … 979 993 */ 980 994 Control.prototype.initElementConfigs = function(){ 981 982 } 995 }; 983 996 984 997 /** … … 994 1007 995 1008 var elmConfig = this.elements[relation]; 996 if (!elmConfig) 1009 if (!elmConfig) { 997 1010 return; 1011 } 998 1012 return elmConfig[attribute]; 999 } 1013 }; 1000 1014 1001 1015 /** … … 1007 1021 Control.prototype.getTemplate = function(relation){ 1008 1022 var templates = this.templates; 1009 if (!templates) 1023 if (!templates) { 1010 1024 return; 1025 } 1011 1026 return templates[relation]; 1012 } 1027 }; 1013 1028 1014 1029 /** … … 1020 1035 1021 1036 this.getForm().addElementIndex(this.getAbsoluteId(), relation, $elm); 1022 } 1037 }; 1023 1038 1024 1039 /** … … 1034 1049 var $elm = form.getElementIndex(index, relation); 1035 1050 if (!$elm) { 1036 if(relation == ControlElements.REV_INPUT && form.getElementIndex(index).length== 1){1051 if(relation === ControlElements.REV_INPUT && form.getElementIndex(index).length === 1){ 1037 1052 $elm = form.getElementIndex(index)[0]; 1038 1053 … … 1045 1060 } 1046 1061 return $elm; 1047 } 1062 }; 1048 1063 1049 1064 … … 1119 1134 this._makeEventHandler("valueChanged"); 1120 1135 1121 if ($lbl && $lbl[0].childNodes.length == 0) {1136 if ($lbl && $lbl[0].childNodes.length === 0) { 1122 1137 var label = this.label != null ? this.label : this.getId(); 1123 1138 $lbl.text(locale.getMessage(label)); … … 1135 1150 this.initial = $.extend({enable : true, show : true}, this.initial); 1136 1151 1137 } 1152 }; 1138 1153 1139 1154 /** … … 1141 1156 */ 1142 1157 Control.prototype._makeEventHandler = function(name, data){ 1143 if (name == undefined) return;1158 if (name == undefined) {return; } 1144 1159 name = "" + name; //stringify 1145 1160 1146 if (this[name] != undefined) 1161 if (this[name] != undefined) { 1147 1162 throw "Can't make eventhandler system for event " + name + ". Property already exists."; 1163 } 1148 1164 1149 1165 data = data || {}; … … 1154 1170 return fn ? $this.bind(name, data, fn) : $this.triggerHandler(name); 1155 1171 } 1156 } 1172 }; 1157 1173 1158 1174 /** … … 1164 1180 } 1165 1181 this.initProperties(); 1166 } 1182 }; 1167 1183 1168 1184 Control.prototype.initProperties = function(){ 1169 } 1185 }; 1170 1186 1171 1187 … … 1176 1192 */ 1177 1193 Control.prototype.initContainerElements = function(container, create){ 1178 1179 } 1194 }; 1180 1195 1181 1196 /** … … 1189 1204 if (opts) { 1190 1205 var options = kf.Options.create(opts, this.getType()); 1191 if (options.toShare()) 1206 if (options.toShare()) { 1192 1207 options = this.getType().share("options", options); 1208 } 1193 1209 this.options = options; 1194 1210 1195 1211 // register for update-callback on the type options 1196 1212 options.update(function(){ 1197 me.updateOptions(options.getValues(), options.readUserValues(), options.getLabels()) 1213 me.updateOptions(options.getValues(), options.readUserValues(), options.getLabels()); 1198 1214 }); 1199 1215 1200 1216 // trigger loading the options 1201 if (options.getValues() == undefined) 1217 if (options.getValues() == undefined) { 1202 1218 options.refresh(); 1203 else1219 } else { 1204 1220 this.updateOptions(options.getValues(), options.readUserValues(), options.getLabels()); 1205 } 1206 } 1221 } 1222 } 1223 }; 1207 1224 1208 1225 … … 1218 1235 value = value || this.getValue(); 1219 1236 1220 var noValidation = (this.valueState == kf.Control.STATE_INIT);1237 var noValidation = (this.valueState === kf.Control.STATE_INIT); 1221 1238 this.setValue(value, noValidation); 1222 } 1223 1224 1239 }; 1225 1240 1226 1241 … … 1231 1246 */ 1232 1247 Control.prototype.initElements = function(){ 1233 1234 } 1248 }; 1235 1249 1236 1250 /** … … 1284 1298 // register for value-changes by the end-user (change event on main input element) 1285 1299 var notification = function(){ 1286 1287 me.update() 1300 me.update(); 1288 1301 }; 1289 1302 … … 1299 1312 me._initEventWiring(); 1300 1313 }); 1301 } 1314 }; 1302 1315 1303 1316 /** … … 1307 1320 */ 1308 1321 Control.prototype.initEvents = function(){ 1309 1310 } 1322 }; 1311 1323 1312 1324 Control.prototype._initEventWiring = function(){ 1313 1325 var options = this.options; 1314 1326 if(options){ 1315 if (options.toShare() && options.initEventWiringDone) 1327 if (options.toShare() && options.initEventWiringDone) { 1316 1328 return; // no need to re-init shared options, avoiding multiple updates when one suffices 1329 } 1317 1330 1318 1331 // in all other cases we should loop over dependency-controls … … 1320 1333 var depends = this.depends; 1321 1334 var context = {}; 1322 for ( var name in depends) { 1335 var name; 1336 for ( name in depends) { 1323 1337 var path = depends[name]; 1324 1338 var control = this.findControl(path); … … 1334 1348 1335 1349 this.initEventWiring(); 1336 } 1350 }; 1337 1351 1338 1352 /** … … 1342 1356 */ 1343 1357 Control.prototype.initEventWiring = function(){ 1344 1345 } 1358 }; 1346 1359 1347 1360 /** … … 1352 1365 var userVal = this.readUserValue(); 1353 1366 this.updateUserValue(userVal); 1354 } 1367 }; 1355 1368 1356 1369 /** … … 1358 1371 */ 1359 1372 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. 1362 1374 1363 1375 /** … … 1365 1377 */ 1366 1378 Control.prototype.writeUserValue = function(userValue){ 1367 1368 } 1379 }; 1369 1380 1370 1381 Control.prototype.isEnabled = function(){ 1371 1382 return this.initial.enable; 1372 } 1383 }; 1373 1384 1374 1385 /** … … 1457 1468 Control.prototype.reset = function() { 1458 1469 Control.reset(this); 1459 } 1470 }; 1460 1471 1461 1472 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)) { 1463 1474 me.setWireValue(me.initial.value, true); 1464 1475 } … … 1467 1478 1468 1479 me.resetShowState(); 1469 } 1480 }; 1470 1481 1471 1482 Control.prototype.resetShowState = function() { 1472 1483 Control.resetShowState(this); 1473 } 1484 }; 1474 1485 1475 1486 Control.resetShowState = function(me) { … … 1485 1496 me.hide(); 1486 1497 } 1487 } 1488 1489 /** 1490 * closes a control1491 */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 }; 1499 1510 1500 1511 /** … … 1509 1520 var value = this.getType().parseUserValue(userValue); 1510 1521 this.setValue(value, noValidation); 1511 } 1512 catch (e) { 1522 } catch (e) { 1513 1523 this.value = undefined; 1514 1524 this.handleValueError(e); 1515 1525 this.valueChanged(); 1516 1526 } 1517 } 1527 }; 1518 1528 1519 1529 /** … … 1526 1536 this.valueState = Control.STATE_INVALID; 1527 1537 this.setMessage(text); 1528 } 1538 }; 1529 1539 1530 1540 /** … … 1536 1546 Control.prototype.isValid = function(forceValidation){ 1537 1547 return (Control.isValid(this, forceValidation)); 1538 } 1548 }; 1539 1549 1540 1550 Control.isValid = function(me, forceValidation){ … … 1542 1552 1543 1553 // force validation if it didn't happen yet 1544 if (forceValidation && me.valueState != Control.STATE_INVALID)1554 if (forceValidation && me.valueState !== Control.STATE_INVALID) { 1545 1555 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 }; 1549 1560 1550 1561 … … 1573 1584 me.setNormalisedValue(value, noValidation); 1574 1585 1575 } 1576 catch (e) { 1586 } catch (e) { 1577 1587 me.handleValueError(e); 1578 1588 } finally { … … 1588 1598 noValidation = noValidation || false; 1589 1599 1590 if (this.valueState == Control.STATE_INIT || !this.valueEquals(value) || ( this.valueState== Control.STATE_INVALID && this.value == undefined && value == undefined)) { // in case of change1600 if (this.valueState === Control.STATE_INIT || !this.valueEquals(value) || ( this.valueState === Control.STATE_INVALID && this.value == undefined && value == undefined)) { // in case of change 1591 1601 this.value = value; 1592 1602 try { … … 1624 1634 */ 1625 1635 Control.prototype.normaliseValue = function (value) { 1626 return value 1627 } 1636 return value; 1637 }; 1628 1638 1629 1639 … … 1656 1666 try { 1657 1667 wireValue = this.getType().toWireValue(value); 1658 } 1659 catch (e) { 1668 } catch (e) { 1660 1669 // keeping it at undefined return 1661 1670 } 1662 1671 return wireValue; 1663 } 1672 }; 1664 1673 1665 1674 /** … … 1671 1680 var value = this.getType().parseWireValue(wireValue); 1672 1681 this.setOriginalValue(value, noValidation); 1673 } 1674 catch (e) { 1682 } catch (e) { 1675 1683 this.handleValueError(e); 1676 1684 } 1677 } 1685 }; 1678 1686 1679 1687 /** … … 1687 1695 this.setValue(value, noValidation); 1688 1696 this.originalValueSuppressedByNormalization = this.hasChanges(); // normalization changed the original value! 1689 } 1697 }; 1690 1698 1691 1699 /** … … 1697 1705 1698 1706 return (!this.valueEquals(this.originalValue)); 1699 } 1707 }; 1700 1708 1701 1709 /** … … 1708 1716 1709 1717 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 } 1712 1721 return (thisValue === thatValue); // will not work for container-controls (array or object values) 1713 } 1722 }; 1714 1723 1715 1724 /** … … 1718 1727 */ 1719 1728 Control.prototype.newValidation = function(value, wireValue){ 1720 if (this.operationalState == Control.STATE_DISABLED) {1729 if (this.operationalState === Control.STATE_DISABLED) { 1721 1730 this.valueState = Control.STATE_VALID; 1722 1731 return; 1723 1732 } 1724 if (this.getType().validators.length == 0 ) {1733 if (this.getType().validators.length === 0 ) { 1725 1734 // if there are no validators then we must assume that the control is valid 1726 1735 this.valueState = Control.STATE_VALID; … … 1733 1742 } 1734 1743 this.updateValidationClasses(); 1735 } 1744 }; 1736 1745 1737 1746 /** … … 1745 1754 options: this.getOptionValues() 1746 1755 }, baseData); 1747 } 1756 }; 1748 1757 1749 1758 /** … … 1753 1762 */ 1754 1763 Control.prototype.getOptionValues = function(){ 1755 if (this.options == undefined || this.options.getValues == undefined) 1764 if (this.options == undefined || this.options.getValues == undefined) { 1756 1765 return undefined; 1766 } 1757 1767 return this.options.getValues(); 1758 } 1768 }; 1759 1769 1760 1770 /** … … 1762 1772 */ 1763 1773 Control.prototype.validationSuccess = function(){ 1764 1765 } 1774 }; 1766 1775 1767 1776 /** … … 1772 1781 this.validationMessages = []; 1773 1782 this.clearMessage(); 1774 } 1783 }; 1775 1784 1776 1785 /** … … 1782 1791 var sep = ""; 1783 1792 var last = this.validationMessages.length; 1784 if (last == 0) {1793 if (last === 0) { 1785 1794 this.valueState = Control.STATE_VALID; 1786 1795 } 1787 1796 else { 1788 for (var i = 0; i < last; i++) { 1797 var i; 1798 for ( i = 0; i < last; i++) { 1789 1799 var msg = this.validationMessages[i]; 1790 1800 aggr += sep + msg; … … 1796 1806 1797 1807 this.validationFinished(); 1798 } 1808 }; 1799 1809 1800 1810 /** … … 1804 1814 Control.prototype.validationFail = function(message){ 1805 1815 this.validationMessages[this.validationMessages.length] = message.getText(); 1806 } 1816 }; 1807 1817 1808 1818 /** … … 1818 1828 1819 1829 this.updateValidationClasses(); 1820 } 1830 }; 1821 1831 1822 1832 /** … … 1825 1835 Control.prototype.clearMessage = function(){ 1826 1836 this.setMessage(""); 1827 } 1837 }; 1828 1838 1829 1839 /** 1830 1840 * updates the validation classes to match the outcome of isValid() 1831 1841 */ 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); 1834 1844 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 }; 1845 1855 1846 1856 /** … … 1863 1873 var parent = this.getParent(); 1864 1874 var parentId = ""; 1865 if (parent) 1875 if (parent) { 1866 1876 parentId = parent.getAbsoluteId(); 1877 } 1867 1878 var id = this.getId(); 1868 1879 this._absoluteId = $.concatPath(parentId, id); 1869 1880 } 1870 1881 return this._absoluteId; 1871 } 1872 1873 /** 1874 * Gets this controls absolute id. This means including all the ids of possible parent controls1875 * @return absolute id or id-path1876 * @type String1877 */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 = ""; 1883 1894 1884 if (parent) 1885 parentId = parent.getGroupId(); 1895 if (parent) { 1896 parentId = parent.getGroupId(); 1897 } 1886 1898 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 } 1891 1904 1892 this._groupId = id;1893 }1894 return this._groupId;1895 }1905 this._groupId = id; 1906 } 1907 return this._groupId; 1908 }; 1896 1909 1897 1910 … … 1905 1918 Control.prototype.findControl = function(){ 1906 1919 1907 if (arguments.length == 0)1920 if (arguments.length === 0) { 1908 1921 return; 1909 1910 if (typeof arguments[0] == 'string') { 1922 } 1923 1924 if (typeof arguments[0] === 'string') { 1911 1925 return this._findControlByPath(arguments[0]); 1912 } 1913 else 1926 } else { 1914 1927 if (arguments[0].constructor == Array) { 1915 1928 return this._findControlBySegments(arguments[0]); 1916 } 1917 else 1929 } else { 1918 1930 return; 1919 } 1931 } 1932 } 1933 }; 1920 1934 1921 1935 /** … … 1927 1941 Control.prototype._findControlByPath = function(path){ 1928 1942 1929 var target = (path.charAt(0) == '/') ? this.getForm() : this;1943 var target = (path.charAt(0) === '/') ? this.getForm() : this; 1930 1944 var segments = path.split('/'); 1931 1945 return target._findControlBySegments(segments); 1932 } 1946 }; 1933 1947 1934 1948 /** … … 1941 1955 1942 1956 var next = segments.shift(); 1943 while (segments.length > 0 && (next == undefined || next.length == 0))1957 while (segments.length > 0 && (next == undefined || next.length === 0)) { 1944 1958 next = segments.shift(); // ignore empty path segments 1959 } 1945 1960 var target; 1946 if (next == '.' || next == undefined || next.length == 0)// me1961 if (next === '.' || next == undefined || next.length === 0) { // me 1947 1962 target = this; 1948 else1949 if (next == '..')// parent1963 } else { 1964 if (next === '..') { // parent 1950 1965 target = this.getParent(); 1951 else1966 } else { 1952 1967 target = this.getChildByPathSegment(next); // child 1953 if (segments.length != 0) 1968 } 1969 } 1970 if (segments.length !== 0) { 1954 1971 return target._findControlBySegments(segments); 1955 else1972 } else { 1956 1973 return target; 1957 } 1974 } 1975 }; 1958 1976 1959 1977 Control.prototype.eachElement = function(fn){ 1960 if (this._allElements == undefined) 1978 if (this._allElements == undefined) { 1961 1979 this._allElements = $(ControlElements.all(this)); 1980 } 1962 1981 this._allElements.each(fn); 1963 } 1982 }; 1964 1983 1965 1984 /** … … 1968 1987 Control.prototype.hide = function(){ 1969 1988 Control.hide(this); 1970 } 1989 }; 1971 1990 1972 1991 Control.hide = function(me) { 1973 1992 me.eachElement(function() { 1974 $(this).hide() 1993 $(this).hide(); 1975 1994 }); 1976 1995 me.viewState = Control.STATE_HIDDEN; 1977 } 1996 }; 1978 1997 1979 1998 /** … … 1982 2001 Control.prototype.show = function(){ 1983 2002 Control.show(this); 1984 } 2003 }; 1985 2004 1986 2005 Control.show = function (me) { 1987 2006 me.eachElement(function() { 1988 $(this).show() 2007 $(this).show(); 1989 2008 }); 1990 2009 me.viewState = Control.STATE_VISIBLE; 1991 } 2010 }; 1992 2011 1993 2012 /** … … 1996 2015 Control.prototype.enable = function(){ 1997 2016 Control.enable(this); 1998 } 2017 }; 2018 1999 2019 Control.enable = function(me) { 2000 2020 me.eachElement(function(){ … … 2008 2028 me.operationalState = Control.STATE_ENABLED; 2009 2029 // 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) { 2011 2031 me.newValidation(me.getValue(), me.getWireValue()); 2012 2032 } 2013 } 2033 }; 2014 2034 2015 2035 /** … … 2018 2038 Control.prototype.disable = function(){ 2019 2039 Control.disable(this); 2020 } 2040 }; 2041 2021 2042 Control.disable = function(me) { 2022 2043 me.eachElement(function(){ … … 2031 2052 me.updateValidationClasses(); 2032 2053 me.operationalState = Control.STATE_DISABLED; 2033 } 2054 }; 2034 2055 2035 2056 /* … … 2044 2065 2045 2066 return this._id; 2046 } 2067 }; 2047 2068 2048 2069 /** … … 2054 2075 2055 2076 return this._form; 2056 } 2077 }; 2057 2078 2058 2079 /** … … 2073 2094 2074 2095 return this._type; 2075 } 2096 }; 2076 2097 2077 2098 /** … … 2082 2103 * @type Control 2083 2104 */ 2084 Control.prototype.getParent = function(){ } 2105 Control.prototype.getParent = function(){ 2106 }; 2085 2107 2086 2108 /** … … 2095 2117 this[meth].apply(this, args); 2096 2118 } 2097 } 2098 2099 2100 $.inherit(AbstractContainerControl, Control); 2119 }; 2120 2121 2101 2122 2102 2123 /** … … 2112 2133 Control.init(this, id, form, conf); 2113 2134 } 2114 2135 $.inherit(AbstractContainerControl, Control); 2136 2137 2138 $.extend(kf, { 2139 ControlElements: ControlElements, 2140 Control: Control, 2141 AbstractContainerControl: AbstractContainerControl 2142 }); 2143 2115 2144 /** 2116 2145 * Creates a blank value … … 2154 2183 //else 2155 2184 var children = this.getChildren(includeAll); 2185 var i, child; 2156 2186 if (!stopable) { 2157 for ( vari in children) {2158 varchild = children[i];2187 for (i in children) { 2188 child = children[i]; 2159 2189 if (child) { 2160 2190 fn(i, child); … … 2162 2192 } 2163 2193 } else { 2164 for ( vari in children) {2165 varchild = children[i];2194 for (i in children) { 2195 child = children[i]; 2166 2196 if (child) { 2167 2197 var stop = fn(i, child); 2168 if (stop) return stop;2198 if (stop) { return stop;} 2169 2199 } 2170 2200 } … … 2176 2206 this.eachChild(function(i, child){ child.hide();}); 2177 2207 Control.hide(this); 2178 } 2208 }; 2179 2209 2180 2210 AbstractContainerControl.prototype.show = function(){ 2181 2211 this.eachChild(function(i, child){ child.show();}); 2182 2212 Control.show(this); 2183 } 2213 }; 2184 2214 2185 2215 AbstractContainerControl.prototype.disable = function() { … … 2213 2243 isBlank = false; 2214 2244 } 2215 } 2245 }; 2216 2246 this.eachChild(cfn); 2217 2247 2218 if (isBlank) value = undefined; 2248 if (isBlank) { 2249 value = undefined; 2250 } 2219 2251 2220 2252 return value; … … 2288 2320 */ 2289 2321 AbstractContainerControl.prototype.getValue = function(){ 2290 if (this.value == CLEAR){2322 if (this.value === CLEAR) { 2291 2323 this.value = this.getLoop(AbstractContainerControl.childGetter); 2292 2324 } … … 2307 2339 AbstractContainerControl.childSetter = function(i, child, value, noValidation) { 2308 2340 return child.setValue(value, noValidation); 2309 } 2341 }; 2310 2342 2311 2343 /** … … 2315 2347 */ 2316 2348 AbstractContainerControl.prototype.getWireValue = function(){ 2317 if (this.cachedWireValue == CLEAR) {2349 if (this.cachedWireValue === CLEAR) { 2318 2350 var w = this.getLoop(AbstractContainerControl.childWireGetter); 2319 2351 this.cachedWireValue = this.getType().toWireValue(w); // allow composite-type specific formatting (merge) … … 2379 2411 this.getChild(childId).close(); 2380 2412 delete this.getChildren()[childId]; 2381 } 2413 }; 2382 2414 2383 2415 AbstractContainerControl.prototype.removeChildren = function() { 2384 2416 var children = this.getChildren(); 2385 2417 var toRemove = []; 2386 2387 for ( vari in children) {2418 var i; 2419 for (i in children) { 2388 2420 var child = children[i]; 2389 2421 toRemove.push(children[i]); 2390 2422 } 2391 2423 2392 for ( vari in toRemove) {2424 for (i in toRemove) { 2393 2425 this.removeChild(toRemove[i].getId()); 2394 2426 } 2395 2427 2396 } 2428 }; 2397 2429 2398 2430 2399 /**2431 /** 2400 2432 * Sets the original value of the control (This doesn't do anything) 2401 2433 * @param {Object} value 2402 2434 */ 2403 2435 AbstractContainerControl.prototype.setOriginalValue = function(value){ 2404 } 2436 }; 2405 2437 2406 2438 /** … … 2415 2447 AbstractContainerControl.childHasChanges = function(i, child) { 2416 2448 return child.hasChanges(); 2417 } 2449 }; 2418 2450 2419 2451 … … 2425 2457 2426 2458 return; // undefined, which is always seen as 'false' which will silence value-changed events 2427 } 2459 }; 2428 2460 2429 2461 /** … … 2435 2467 AbstractContainerControl.prototype.getChildren = function(){ 2436 2468 return AbstractContainerControl.getChildren(this); 2437 } 2469 }; 2438 2470 AbstractContainerControl.getChildren = function(me) { 2439 2471 return me._children; 2440 } 2472 }; 2441 2473 2442 2474 /** … … 2448 2480 AbstractContainerControl.prototype.getChild = function(id){ 2449 2481 return AbstractContainerControl.getChild(this, id); 2450 } 2482 }; 2451 2483 AbstractContainerControl.getChild = function (me, id) { 2452 2484 return me._children[id]; 2453 } 2485 }; 2454 2486 AbstractContainerControl.prototype.getChildByPathSegment = function(pathSegment){ 2455 2487 return this._children[pathSegment]; 2456 } 2488 }; 2457 2489 2458 2490 /** … … 2486 2518 } 2487 2519 2488 } 2520 }; 2489 2521 2490 2522 … … 2512 2544 var form = this.getForm(); 2513 2545 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])) { 2515 2547 return elements; // no need to create new elements 2548 } 2516 2549 2517 2550 var newElements; 2518 2551 var newElementsArray = []; 2519 2552 2520 var form = this.getForm();2521 2553 var parentGroupId = this.getGroupId(); 2522 2554 var groupId = ""; 2523 if ( this.groupChildrenInLayoutIndex ) 2555 if ( this.groupChildrenInLayoutIndex ) { 2524 2556 groupId = $.concatPath(parentGroupId, "#"); 2525 else2557 } else { 2526 2558 groupId = $.concatPath(parentGroupId, id); 2559 } 2527 2560 var containerId = this.getId(); 2528 2561 var cloneId = absoluteId + "(" + groupId + ")"; … … 2530 2563 2531 2564 var kauriSelector = "[kauri-role],[kauri-id]"; 2532 var setIdRef = function($elt, id){ 2565 var setIdRef; 2566 setIdRef = function($elt, id){ 2533 2567 if($elt.is(kauriSelector)){ 2534 2568 $elt.attr(ControlElements.ATTR_IDREF, id); 2535 2569 } else { 2536 2570 $elt.children().each(function(a,b) { 2537 setIdRef($(b),id) 2571 setIdRef($(b),id); 2538 2572 }); 2539 2573 } 2540 } 2574 }; 2541 2575 2542 2576 // determine position to insert layout clone … … 2550 2584 if(position) { 2551 2585 var clones = $("[kauri-layout-clone='" + cloneId + "']", container); 2552 if( clones.length > 0 && position <= clones.length) 2586 if( clones.length > 0 && position <= clones.length) { 2553 2587 cursor = clones[position]; 2588 } 2554 2589 } 2555 2590 … … 2561 2596 }); 2562 2597 2563 if(cursor) 2598 if(cursor) { 2564 2599 newElements = $layoutClone.insertBefore(cursor); 2565 else {2600 } else { 2566 2601 container.append($layoutClone); 2567 2602 newElements = $layoutClone; … … 2569 2604 ControlElements.index($layoutClone, form, absoluteId); 2570 2605 newElementsArray.push(newElements); 2571 } else{2606 } else { 2572 2607 // clone each element in layout group 2573 2608 $.each($layoutGroups, function(layoutGroupId, eltArray){ … … 2589 2624 2590 2625 return newElementsArray; 2591 } 2592 2626 }; 2593 2627 AbstractContainerControl.prototype.createChildElements = function(id, container, layout){ 2594 2628 throw "[AbstractContainerControl#createChildElements] No container or layout to work with."; 2595 } 2629 }; 2630 2596 2631 /** 2597 2632 * Creates a new control based on type but doesn't add it to the list of children … … 2605 2640 */ 2606 2641 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 } 2610 2645 2611 2646 var controlType = type.control; … … 2613 2648 2614 2649 if (!(type.control && type.control.isReady)) { 2615 if (typeof type.control == 'string') {2650 if (typeof type.control === 'string') { 2616 2651 controlType = type.control; 2617 } else if (type.control.constructor == Array) {2652 } else if (type.control.constructor === Array) { 2618 2653 controlType = type.control[0]; 2619 2654 extender = type.control[1]; 2620 2655 } else { // item = {base:'string', ...extensions.. } 2621 2656 controlType = type.control.base; 2622 if(controlType==undefined) 2657 if(controlType==undefined) { 2623 2658 controlType='composite-control'; 2659 } 2624 2660 extender = type.control; 2625 2661 } 2626 2662 } 2627 2663 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 } 2631 2667 2632 2668 this._createChildElements(id, position); // ensure the needed html elements for this new child are available. … … 2645 2681 2646 2682 var childChanged = function(){ 2647 2648 2683 me.updateValue(); 2649 2650 } 2684 }; 2651 2685 2652 2686 childControl.valueChanged(childChanged); 2653 2687 2654 2688 return childControl; 2655 } 2689 }; 2656 2690 2657 2691 /** … … 2664 2698 this._children[id] = childControl; 2665 2699 this.updateValue(true, true); // be sure to handle change in value structure 2666 } 2700 }; 2667 2701 2668 2702 /** … … 2674 2708 delete this._children[id]; 2675 2709 this.updateValue(true, true); // be sure to handle change in value structure 2676 } 2710 }; 2677 2711 2678 2712 … … 2699 2733 } 2700 2734 this.valueChanged(); // and notify parent 2701 }2735 }; 2702 2736 2703 2737 /** … … 2711 2745 2712 2746 this.updateValue = restoreUpdateFn; 2713 } 2747 }; 2714 2748 2715 2749 /** … … 2719 2753 AbstractContainerControl.prototype.isValid = function(forceValidation){ 2720 2754 return AbstractContainerControl.isValid(this, forceValidation); 2721 } 2755 }; 2722 2756 2723 2757 /** … … 2729 2763 // if we're not valid at this level then it's no use checking the children 2730 2764 if (valid) { 2731 for (var i in me._children) { 2765 var i; 2766 for (i in me._children) { 2732 2767 valid = (me._children[i] != undefined) && me._children[i].isValid(forceValidation) && valid; 2733 2768 } … … 2735 2770 2736 2771 return valid; 2737 } 2772 }; 2738 2773 2739 2774 AbstractContainerControl.prototype.delegates = true; … … 2741 2776 var args = arguments; 2742 2777 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 } 2745 2781 }, false, true); 2746 } 2782 }; 2747 2783 2748 2784 … … 2751 2787 }; 2752 2788 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 */ 1 2 /** 2 3 * @fileOverview This file holds the fieldtype and controltype for handling composition-data-structures. … … 5 6 ( function( $) { 6 7 7 if (!$) 8 if (!$) { 8 9 throw "[date.js] requires jQuery"; 9 if (!$.org.kauriproject.forms) 10 } 11 if (!$.org.kauriproject.forms) { 10 12 throw "[date.js] requires the kauri-form namespace"; 11 if (!$.datepicker) 13 } 14 if (!$.datepicker) { 12 15 throw "[date.js] requires jQuery UI datepicker"; 16 } 13 17 14 18 var kf = $.org.kauriproject.forms; … … 22 26 function padZero (val) { 23 27 var s = "" + val; 24 return ( (s.length == 1) ? ("0" + s) : s );28 return ( (s.length === 1) ? ("0" + s) : s ); 25 29 } 26 30 27 31 function asTimeNumber(numStr, max) { 28 if (numStr === undefined) 32 if (numStr === undefined) { 29 33 return 0; 34 } 30 35 31 36 max = max || 60; // default 32 37 var num = new Number(numStr); 33 if (isNaN(num) || num > max || num < 0) 38 if (isNaN(num) || num > max || num < 0) { 34 39 return undefined; 35 return num 40 } 41 return num; 36 42 } 37 43 … … 62 68 63 69 format : function( val) { 64 if (val == undefined) 70 if (val == undefined) { 65 71 return ""; 66 if (val.constructor != Date) 72 } 73 if (val.constructor !== Date) { 67 74 this.fail("Not a Date: {0}.", [val]); 75 } 68 76 69 77 return $.datepicker.formatDate(this.pattern, val); … … 71 79 72 80 parse : function(valstr) { 73 if (typeof valstr == 'string') {81 if (typeof valstr === 'string') { 74 82 valstr = $.trim(valstr); 75 if (valstr.length == 0)83 if (valstr.length === 0) { 76 84 return undefined; 85 } 77 86 78 87 try { … … 94 103 format : function (val) { 95 104 96 if (val == undefined ) 105 if (val == undefined ) { 97 106 return undefined; 98 99 if (val.date == undefined) 107 } 108 109 if (val.date == undefined) { 100 110 this.fail("Not a valid date-time structure. Missing date part." ); 111 } 101 112 102 113 var datePart = val.date; … … 109 120 parse : function(valstr) { 110 121 var parts; 111 if (typeof valstr == 'string') {122 if (typeof valstr === 'string') { 112 123 valstr = $.trim(valstr); 113 if (valstr.length == 0)124 if (valstr.length === 0) { 114 125 return undefined; 126 } 115 127 116 128 parts = valstr.split(this.timeSeparator); 117 } else if (valstr.constructor == Array) {129 } else if (valstr.constructor === Array) { 118 130 parts = valstr; 119 131 } 120 132 121 if (parts === undefined || parts.length != 2) {133 if (parts === undefined || parts.length !== 2) { 122 134 this.fail( "Could not parse the date-range: " + valstr ); 123 135 } 124 136 125 137 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]; } 128 140 129 141 return result; … … 135 147 rangeSeparator : "/", 136 148 format : function (val) { 137 if (val === undefined || (val.start === undefined && val.end === undefined)) 149 if (val === undefined || (val.start === undefined && val.end === undefined)) { 138 150 return undefined; 151 } 139 152 140 153 return "" + val.start + this.rangeSeparator + val.end; … … 142 155 parse : function(valstr) { 143 156 var parts; 144 if (typeof valstr == 'string') {157 if (typeof valstr === 'string') { 145 158 valstr = $.trim(valstr); 146 if (valstr.length == 0)159 if (valstr.length === 0) { 147 160 return undefined; 161 } 148 162 149 163 parts = valstr.split(this.rangeSeparator); 150 } else if (valstr.constructor == Array) {164 } else if (valstr.constructor === Array) { 151 165 parts = valstr; 152 166 } 153 167 154 if (parts === undefined || parts.length != 2) {168 if (parts === undefined || parts.length !== 2) { 155 169 this.fail( "Could not parse the date-range: " + valstr ); 156 170 } 157 171 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]; } 160 174 161 175 return result; … … 167 181 168 182 format : function (val) { 169 if (val == undefined) 183 if (val == undefined) { 170 184 return ""; 171 if (val.constructor != Date) 185 } 186 if (val.constructor !== Date) { 172 187 this.fail("Not a Date: {0}.", [val]); 188 } 173 189 174 190 return formatTime(val); 175 191 }, 176 192 parse : function (valstr) { 177 if (typeof valstr == 'string') {193 if (typeof valstr === 'string') { 178 194 valstr = $.trim(valstr); 179 if (valstr.length == 0)195 if (valstr.length === 0) { 180 196 return undefined; 197 } 181 198 182 199 var parsedTime = parseTime(valstr); … … 203 220 patterns : [$.datepicker.ISO_8601,"dd/mm/yy"], 204 221 validate : function(value) { 205 if ($.isEmpty(value)) 206 return this.notifySuccess(); 222 if ($.isEmpty(value)) { 223 return this.notifySuccess(); 224 } 207 225 208 226 // 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 } 211 230 212 231 // 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") { 214 233 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++) { 216 236 try { 217 237 $.datepicker.parseDate(this.patterns[i], value); … … 222 242 } 223 243 224 if (ok) 244 if (ok) { 225 245 return this.notifySuccess(); 246 } 226 247 } 227 248 … … 234 255 strict : false, 235 256 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 } 242 266 243 267 // the child controls should have ensured that value holds two actual dates. 244 268 245 if (this.order == "asc" && this.strict) {269 if (this.order === "asc" && this.strict) { 246 270 if (value.start >= value.end) { 247 271 this.notifyFail("The first date must be strictly before the second one"); 248 272 } 249 } else if (this.order == "asc" && !this.strict) {273 } else if (this.order === "asc" && !this.strict) { 250 274 if (value.start > value.end) { 251 275 this.notifyFail("The first date must be before the second one"); 252 276 } 253 } else if (this.order == "desc" && this.strict) {277 } else if (this.order === "desc" && this.strict) { 254 278 if (value.start <= value.end) { 255 279 this.notifyFail("The first date must be strictly after the second one"); 256 280 } 257 } else if (this.order == "desc" && !this.strict) {281 } else if (this.order === "desc" && !this.strict) { 258 282 if (value.start < value.end) { 259 283 this.notifyFail("The first date must be after the second one"); … … 269 293 maxDate : undefined, // maximum date 270 294 validate : function (value) { 271 if ($.isEmpty(value)) 272 return this.notifySuccess(); 295 if ($.isEmpty(value)) { 296 return this.notifySuccess(); 297 } 273 298 274 if (value.constructor != Date) 299 if (value.constructor != Date) { 275 300 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) ) { 278 304 return this.notifyFail("i18n:Should be between {0} and {1}", [ this.minDate, this.maxDate ]); 305 } 279 306 280 307 return this.notifySuccess(); … … 286 313 _days : ["sunday","monday","tuesday","wednesday","thursday","friday","saturday"], 287 314 validate : function (value) { 288 if (this.dayOfWeek < 0 && this.dayOfWeek > 6) 315 if (this.dayOfWeek < 0 && this.dayOfWeek > 6) { 289 316 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 } 293 322 294 if (value.constructor != Date)323 if (value.constructor !== Date) { 295 324 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 } 299 330 300 331 return this.notifyFail(value + " is not a " + this._days[this.dayOfWeek] ); … … 340 371 }); 341 372 342 $.inherit(DateControl, kf.Control);343 373 function DateControl( id, form, conf) { 344 374 kf.Control.init(this, id, form, conf); 345 375 } 376 $.inherit(DateControl, kf.Control); 346 377 347 378 DateControl.prototype.staticResourceUri = "../../main/kauri/static/"; //default for source based testing - injected dynamically through headerlinks.xml … … 369 400 var type = this.getType(); 370 401 371 type.readonly && $input.attr("readonly", type.readonly); 402 if (type.readonly) { 403 $input.attr("readonly", type.readonly); 404 } 372 405 373 406 if (this.useDatePicker) { … … 407 440 this.useDatePicker = this.getType().useDatePicker; 408 441 } 409 410 }442 }; 443 411 444 DateControl.prototype.readUserValue = function() { 412 445 413 446 return this._input.val(); 414 } 447 }; 415 448 416 449 DateControl.prototype.writeUserValue = function( value) { … … 418 451 value = value || ""; 419 452 this._input.val(value); 420 } 453 }; 421 454 422 455 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 }; 428 461 429 462 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 }; 435 468 436 469 controlTypes.put( "date-control", DateControl); 437 470 438 $.inherit(DateRangeControl, kf.CompositeControl);439 471 function DateRangeControl( id, container, form, conf) { 440 472 kf.Control.init(this, id, container, form, conf); … … 443 475 this.forceOrder = "asc"; 444 476 } 445 }; 477 } 478 $.inherit(DateRangeControl, kf.CompositeControl); 479 480 446 481 DateRangeControl.prototype.initProperties = function() { 447 } 482 }; 483 448 484 DateRangeControl.prototype.normaliseValue = function(value) { 449 485 if (value && value.start && value.end) { 450 if (this.forceOrder == "asc") {486 if (this.forceOrder === "asc") { 451 487 if (value.start > value.end) { 452 488 value = { start: value.end, end: value.start }; 453 489 } 454 } else if (this.forceOrder == "desc") {490 } else if (this.forceOrder === "desc") { 455 491 if (value.start < value.end) { 456 492 value = { start: value.end, end: value.start }; … … 462 498 }; 463 499 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 */ 1 2 /** 2 3 * @fileOverview This file holds the basic structure of the fields composing the forms … … 5 6 ( function( $) { 6 7 7 if (!$) 8 if (!$) { 8 9 throw "[fields.js] requires jQuery"; 9 if (!$.org.kauriproject.forms) 10 } 11 if (!$.org.kauriproject.forms) { 10 12 throw "[fields.js] requires the kauri-form namespace"; 13 } 11 14 12 15 var kp = $.org.kauriproject; 13 16 var kf = $.org.kauriproject.forms; 14 15 $.extend(kf, {16 Options: Options,17 FieldType :FieldType18 });19 17 20 18 … … 56 54 Options.createTemplate(opts, "labelTemplate"); 57 55 58 if (type !== undefined) 56 if (type !== undefined) { 59 57 opts.type = type; 58 } 60 59 61 60 if (opts.data) { … … 73 72 */ 74 73 Options.createTemplate = function(opts, name) { 75 if (opts[name] == undefined) return;74 if (opts[name] == undefined) { return; } 76 75 opts[name] = new kp.UriTemplate(opts[name], {skipEscape: true}); 77 } 76 }; 78 77 79 78 /** … … 84 83 Options.prototype.refreshable = function() { 85 84 return (this.uri != undefined); 86 } 85 }; 87 86 88 87 /** … … 93 92 Options.prototype.updateable = function() { 94 93 return this.refreshable() || (!this.fixed); 95 } 94 }; 96 95 97 96 /** … … 103 102 104 103 return (this.shared); 105 } 104 }; 106 105 107 106 /** … … 113 112 114 113 return this.values; 115 } 114 }; 116 115 117 116 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) { 120 119 var wrapped = this.trimValues([values]); //wrap 121 120 return (wrapped != undefined) ? wrapped[0] : undefined; // unwrap … … 123 122 124 123 var result = []; 125 for (var i = 0; i< values.length; i++) { 124 var i; 125 for (i = 0; i< values.length; i++) { 126 126 var testvalue = values[i]; 127 127 if ($.valueInArray(testvalue, this.values) >= 0) { … … 129 129 } 130 130 } 131 return (result.length == 0 ) ? undefined : result;132 } 131 return (result.length === 0 ) ? undefined : result; 132 }; 133 133 134 134 … … 141 141 142 142 return this.userValues; 143 } 143 }; 144 144 145 145 /** … … 151 151 152 152 return this.labels; 153 } 153 }; 154 154 155 155 /** … … 159 159 */ 160 160 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 164 166 if (this.type) { 165 this.userValues = new Array();167 this.userValues = []; 166 168 var last = values ? values.length : 0; 167 for( vari = 0; i< last; i++)168 if (typeof values[i] == 'string' )169 for(i = 0; i< last; i++) 170 if (typeof values[i] === 'string' ) { 169 171 this.userValues[i] = values[i]; 170 else172 } else { 171 173 this.userValues[i] = this.type.toUserValue(values[i]); 172 }else{ 174 } 175 } else { 173 176 this.userValues = values; // values in user-format if no type defined default to values 174 177 } 175 178 176 179 // set the labels , use userValues for this 177 if(this.userValues != undefined) 180 if(this.userValues != undefined) { 178 181 labels = labels || this.userValues.slice(); 182 } 179 183 180 184 if (this.nullable) { 181 for ( vari = values.length; i>0; i--) {185 for (i = values.length; i>0; i--) { 182 186 values[i] = values[i-1]; 183 187 labels[i] = labels[i-1]; … … 189 193 } 190 194 191 this.values = values;195 this.values = values; 192 196 this.labels = labels; 193 197 194 198 this.update(); 195 } 199 }; 196 200 197 201 /** … … 208 212 Options.prototype.update = function( fn) { 209 213 210 if (!this.updateable()) return;214 if (!this.updateable()) { return; } 211 215 212 216 return (fn) ? $(this).bind("update", {options :this.values}, fn) : $(this).triggerHandler("update"); 213 } 217 }; 214 218 215 219 /** … … 223 227 var me = this; 224 228 var onSuccess = function( data, status, xhr) { 225 if (xhr && me.lastXhr == xhr) { //ignore responses that are not linked to the last request229 if (xhr && me.lastXhr === xhr) { //ignore responses that are not linked to the last request 226 230 me.parseOptions(data); 227 231 me.lastXhr = null; … … 229 233 }; 230 234 var onError = function( xhr, status, err) { 231 if (xhr && me.lastXhr == xhr) {235 if (xhr && me.lastXhr === xhr) { 232 236 me.clearOptions(); 233 237 me.lastXhr = null; … … 256 260 }); 257 261 } 258 } 262 }; 259 263 260 264 … … 272 276 var changedContext = false; 273 277 if (value != undefined) { 274 changedContext = (this.uriContext[key] != value) ;278 changedContext = (this.uriContext[key] !== value) ; 275 279 this.uriContext[key] = value; 276 280 } else { … … 282 286 } 283 287 284 if (changedContext && !noRefresh) 288 if (changedContext && !noRefresh) { 285 289 this.refresh(); 290 } 286 291 287 292 return changedContext; // return if there was any change 288 } 293 }; 289 294 290 295 /** … … 305 310 306 311 var offset = 0; 307 for ( var i = 0; i < last; i++) { 312 var i; 313 for (i = 0; i < last; i++) { 308 314 var option = data[i]; 309 315 var j = i + offset; 310 316 if (this.valueTemplate) { 311 317 values[j] = this.valueTemplate.expand(option, false); 312 if (this.labelTemplate) 318 if (this.labelTemplate) { 313 319 labels[j] = this.labelTemplate.expand(option, false); 320 } 314 321 } else { 315 322 values[j] = option; 316 323 } 317 if (this.type) 324 if (this.type) { 318 325 values[j] = this.type.parseWireValue(values[j]); 326 } 319 327 } 320 328 // set those arrays 321 329 this.set(values, labels); 322 } 323 324 /**325 * clear the options list326 * <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} data331 */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 }; 336 344 337 345 … … 346 354 FieldType.init(this); 347 355 } 356 348 357 FieldType.init = function(me) { 349 } 358 }; 350 359 351 360 … … 358 367 */ 359 368 FieldType.createValidators = function( builder, validators) { 360 361 for ( vari in validators) {369 var i; 370 for ( i in validators) { 362 371 var v = validators[i]; 363 372 var base = v.base; … … 367 376 } 368 377 } 369 } 378 }; 370 379 371 380 /** … … 377 386 FieldType.createTypes = function( builder, subtypes) { 378 387 379 for ( var ref in subtypes) { 388 var ref; 389 for ( ref in subtypes) { 380 390 // only build field types if they haven't been built already 381 391 if (subtypes[ref].format == null) { 382 392 var type = subtypes[ref].type; 383 if(type ==undefined){393 if(type == undefined){ 384 394 type=subtypes[ref]; 385 395 } 386 if(type.base ==undefined)396 if(type.base == undefined) { 387 397 type.base='composite'; 398 } 388 399 subtypes[ref] = FieldType.buildType(builder, type); 389 400 } 390 401 } 391 } 402 }; 392 403 393 404 /** … … 402 413 403 414 return FieldType.buildProperty(builder, type, 'fieldTypes'); 404 } 415 }; 405 416 406 417 /** … … 415 426 416 427 return FieldType.buildProperty(builder, formatter, 'formatters'); 417 } 428 }; 418 429 419 430 /** … … 430 441 var base; 431 442 var extender; 432 if (typeof item == 'string') {443 if (typeof item === 'string') { 433 444 base = item; 434 } else if (item.constructor == Array) { 435 445 } else if (item.constructor === Array) { 436 446 base = item[0]; 437 447 extender = item[1]; 438 448 } else { // item = {base:'string', ...extensions.. } 439 // 1. itereer alle properties uit control440 // if item[property]!=undefined449 // 1. itereer alle properties uit control 450 // if item[property]!=undefined 441 451 if (item.base != undefined) { 442 452 base = item.base; 443 453 delete item.base; 444 } else445 if(itemType =="fieldTypes")454 } else { 455 if(itemType === "fieldTypes") { 446 456 base="composite"; // this should be the default 447 extender = item; 457 } 458 } 459 extender = item; 448 460 } 449 461 … … 453 465 454 466 return item; 455 } 467 }; 456 468 457 469 /** … … 464 476 FieldType.configBuild = function( builder, protype) { 465 477 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) { 474 485 FieldType.createValidators(builder, protype.validators); 475 if (protype['user-format']) 486 } 487 if (protype['user-format']) { 476 488 protype['user-format'] = FieldType.buildFormatter(builder, protype['user-format']); 477 if (protype['wire-format']) 489 } 490 if (protype['wire-format']) { 478 491 protype['wire-format'] = FieldType.buildFormatter(builder, protype['wire-format']); 492 } 479 493 }; 480 494 … … 506 520 */ 507 521 FieldType.prototype.share = function(key, value) { 508 if (this._share == undefined) 522 if (this._share == undefined) { 509 523 this._share = {}; 524 } 510 525 var share = this._share; 511 526 512 if (key == undefined) // asking the share itself527 if (key == undefined) { // asking the share itself 513 528 return share; 529 } 514 530 515 531 var sharedValue = share[key]; 516 if (value == undefined) // polling the shared property532 if (value == undefined) {// polling the shared property 517 533 return sharedValue; 534 } 518 535 519 536 if (!sharedValue) { // registring a value to be shared … … 523 540 524 541 return sharedValue; 525 }542 }; 526 543 527 544 /** … … 539 556 var num = 1; 540 557 if (this.multivalue) { 541 if (value && value.constructor == Array) {558 if (value && value.constructor === Array) { 542 559 values = value; 543 560 num = values.length; … … 549 566 550 567 var seqId = listener.expect(all); 551 for ( var i = 0; i < num; i++) { 568 var i, j; 569 for ( i = 0; i < num; i++) { 552 570 var validationData = {index: i, type: this, multivalue: this.multivalue}; 553 571 $.extend(validationData, data); 554 572 555 for ( varj = 0; j < last; j++) {573 for ( j = 0; j < last; j++) { 556 574 557 575 var v = myValidators[j]; … … 563 581 } 564 582 } 565 } 583 }; 566 584 567 585 /** … … 573 591 574 592 return this.validators; 575 } 593 }; 576 594 577 595 /** … … 599 617 600 618 return this.parse('user-format', value); 601 } 619 }; 602 620 603 621 /** … … 608 626 */ 609 627 FieldType.prototype.toUserValue = function( value) { 610 if (value == undefined) 628 if (value == undefined) { 611 629 return this.multivalue ? [] : ""; // this is forced behaviour for user-formatting, while wire-formatting reuse would pas undefined in this case 612 630 } 613 631 return this.format('user-format', value); 614 } 632 }; 615 633 616 634 /** … … 622 640 FieldType.prototype.parseWireValue = function( value) { 623 641 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 } 625 645 return this.parse('wire-format', value); 626 } 646 }; 627 647 628 648 /** … … 634 654 FieldType.prototype.toWireValue = function( value) { 635 655 636 if (value === undefined) 656 if (value === undefined) { 637 657 return undefined; // this is forced behaviour for wire-formatting, while user-formatting reuse would yield "" here 658 } 638 659 var wireValue = this.format('wire-format', value); 639 if (wireValue !== undefined && $.isFunction(wireValue.valueOf)) 660 if (wireValue !== undefined && $.isFunction(wireValue.valueOf)) { 640 661 wireValue = wireValue.valueOf(); // unwrap standard objects like Number and Boolean 662 } 641 663 return wireValue; 642 } 664 }; 643 665 644 666 /** … … 652 674 653 675 return this.convert(format, "parse", value); 654 } 676 }; 655 677 656 678 /** … … 664 686 665 687 return this.convert(format, "format", value); 666 } 688 }; 667 689 668 690 /** … … 677 699 678 700 format = this.getFormat(format); 679 if (!format || !$.isFunction(format[method])) 701 if (!format || !$.isFunction(format[method])) { 680 702 return value; 703 } 681 704 682 705 var values = [ value ]; 683 706 var num = 1; 684 707 var wrap = true; 685 if (this.multivalue && value && value.constructor == Array) {708 if (this.multivalue && value && value.constructor === Array) { 686 709 values = value; 687 710 num = values.length; … … 690 713 var result = new Array(num); 691 714 692 for ( var i = 0; i < num; i++) { 715 var i; 716 for ( i = 0; i < num; i++) { 693 717 result[i] = format[method](values[i]); 694 718 } 695 719 696 if (wrap) 720 if (wrap) { 697 721 return result[0]; 722 } 698 723 699 724 return result; 700 } 725 }; 701 726 702 727 /** … … 708 733 FieldType.prototype.getFormat = function( format) { 709 734 710 if (typeof format == 'string')735 if (typeof format === 'string') { 711 736 return this[format]; 737 } 712 738 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 */ 1 2 /** 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 */ 4 5 ; 5 6 ( function( $) { 6 7 7 if (!$) 8 if (!$) { 8 9 throw "[form.js] requires jQuery"; 9 if (!$.org.kauriproject.forms) 10 } 11 if (!$.org.kauriproject.forms) { 10 12 throw "[form.js] requires the kauri-form namespace"; 13 } 11 14 12 15 var kf = $.org.kauriproject.forms; 13 16 var kp = $.org.kauriproject; 14 17 15 $.inherit(Form, kf.CompositeControl);16 18 /** 17 19 * Form holds and controls a set of controls getting build up from a descriptive configuration object. It matches the HTML … … 32 34 id = (elmOrId && elmOrId.jquery) ? "" : elmOrId; 33 35 34 if (space.size() != 1)36 if (space.size() !== 1) { 35 37 throw "[Form.initElementIndex] No matching <form> element found for id #" + elmOrId; 38 } 36 39 37 40 this.initRegistries(conf); … … 55 58 var complete = false; // keeping this local so it can't be tampered with, 56 59 this.isComplete = function() { 57 58 60 return complete; 59 61 }; // only read 60 62 this.initComplete( function() { 61 62 63 complete = true; 63 64 }); // first trigger to execute. … … 71 72 $submitBtn = $submitBtn.length > 0 ? $submitBtn : $("<input type='submit' value='submit'/>").appendTo(this); 72 73 // 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(); 80 92 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); 93 94 }); 94 }); // last trigger to execute 95 }); 96 }); // last trigger to execute 95 97 96 98 this.initComplete(); // trigger event to execute callbacks. … … 100 102 // TODO check if there is not a nicer way to do this 101 103 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 } 104 107 var wireValue = this.format('wire-format', value); 105 if (wireValue !== undefined && $.isFunction(wireValue.valueOf)) 108 if (wireValue !== undefined && $.isFunction(wireValue.valueOf)) { 106 109 wireValue = wireValue.valueOf(); // unwrap standard objects like Number and Boolean 110 } 107 111 return wireValue; 108 112 }; 109 113 } 114 $.inherit(Form, kf.CompositeControl); 110 115 111 116 Form.prototype.initEvents = function() { … … 114 119 this._makeEventHandler("submitsuccess"); 115 120 this._makeEventHandler("submiterror"); 116 } 121 }; 117 122 118 123 Form.prototype.initComplete = function( fn) { … … 123 128 }; 124 129 125 if (this.isComplete && this.isComplete() && fn) 130 if (this.isComplete && this.isComplete() && fn) { 126 131 return fn.apply(root, [data]); // execute immediately, no need to register any more 132 } 127 133 128 134 var $root = $(root); 129 135 return fn ? $root.one("initComplete", data, fn) : $root.trigger("initComplete"); 130 } 136 }; 131 137 132 138 … … 138 144 // load conf-registries 139 145 this.buildTypes(conf); 140 } 146 }; 141 147 142 148 Form.prototype.initDataURIs = function( conf) { 143 149 144 if (conf.dataURI != undefined) 150 if (conf.dataURI != undefined) { 145 151 this._dataURITemplate = new kp.UriTemplate(conf.dataURI); 152 } 146 153 delete conf.dataURI; 147 if (conf.createURI != undefined) 154 if (conf.createURI != undefined) { 148 155 this._createURITemplate = new kp.UriTemplate(conf.createURI); 156 } 149 157 delete conf.createURI; 150 151 } 158 }; 152 159 153 160 Form.prototype.initElementIndex = function( space ) { … … 159 166 var $layoutElts = $("[" + kf.ControlElements.ATTR_LAYOUT_CURSOR + "]", space); 160 167 $.each($layoutElts, function(index, element){ 161 $(element).hide();162 }168 $(element).hide(); 169 } 163 170 ); 164 171 165 166 172 167 173 space.attr(kf.ControlElements.ATTR_INDEX, '/'); … … 171 177 172 178 this.setRootElement(space); 173 } 179 }; 174 180 175 181 176 182 Form.prototype.setRootElement = function( elm) { 177 183 178 if (this.rootElement) 184 if (this.rootElement) { 179 185 throw "[Form#setRootElement] Root element already set."; 186 } 180 187 this.rootElement = elm; 181 188 this.addElementIndex("/", $(elm)); 182 } 189 }; 183 190 184 191 Form.prototype.getRootElement = function() { 185 192 186 193 return this.rootElement; 187 } 194 }; 188 195 189 196 Form.prototype.getAbsoluteId = function() { … … 201 208 202 209 this.allowInvalid = allow; 203 } 210 }; 204 211 205 212 Form.prototype.preSubmitValidationCheck = function(allowInvalid) { 206 213 207 if (allowInvalid || this.allowInvalid) return true;214 if (allowInvalid || this.allowInvalid) { return true; } 208 215 209 216 var previousAsync = $.ajaxSettings.async; // clone current async settings … … 213 220 formValid = this.isValid(true); // force validation if it didn't happen yet 214 221 } finally { 215 if (previousAsync) $.ajaxSetup({async: true});// reset async settings222 if (previousAsync) { $.ajaxSetup({async: true}); } // reset async settings 216 223 } 217 224 … … 222 229 223 230 return true; 224 } 231 }; 225 232 226 233 Form.prototype.submit = function($trigger, saveMode, allowInvalid) { 227 234 var me = this; 228 235 229 if (saveMode == undefined) saveMode = true;230 if (allowInvalid == undefined) allowInvalid = false;236 if (saveMode == undefined) { saveMode = true; } 237 if (allowInvalid == undefined) { allowInvalid = false; } 231 238 232 239 $(this).triggerHandler("prevalidation"); 233 240 234 241 var proceed = this.preSubmitValidationCheck(allowInvalid); 235 if (!proceed) return;242 if (!proceed) { return; } 236 243 237 244 // update data object … … 256 263 257 264 $(this).triggerHandler("presubmit", formSubmissionData); 258 if (formSubmissionData.cancelsubmit) return; 259 265 if (formSubmissionData.cancelsubmit) { return; } 260 266 261 267 var json = kp.JSON.stringify(data); … … 268 274 var modeMsg; 269 275 270 if(this._createMode || !saveMode) {276 if(this._createMode || !saveMode) { 271 277 uriTemplate = this.getCreateURITemplate(); 272 modeMsg = "createURI" 273 } else{278 modeMsg = "createURI"; 279 } else { 274 280 // put 275 281 uriTemplate = this.getDataURITemplate(); … … 287 293 var params = $.param(uriSuffix); 288 294 if (params.length > 0) { 289 uri += (uri.match(/\?/) ? "&" : "?") + params;295 uri += (uri.match(/\?/) ? "&" : "?") + params; 290 296 } 291 297 … … 298 304 dataType :"json", 299 305 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 } 306 312 }, 307 313 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); 313 319 } 314 320 }, … … 316 322 dataFilter : me.dataFilter 317 323 }); 318 } 324 }; 319 325 320 326 /** … … 325 331 */ 326 332 Form.prototype.dataFilter = function (data, type) { 327 if (!data && type =="json") {333 if (!data && type === "json") { 328 334 return "{}"; 329 } else 335 } else { 330 336 return data; 337 } 331 338 }; 332 339 333 340 Form.prototype.setCreateMode = function (isCreate) { 334 341 this._createMode = isCreate; 335 } 342 }; 336 343 337 344 Form.prototype.isCreateMode = function () { 338 345 return this._createMode; 339 } 346 }; 340 347 341 348 Form.prototype.getDataURITemplate = function () { 342 349 return this._dataURITemplate; 343 } 350 }; 344 351 345 352 Form.prototype.getCreateURITemplate = function () { 346 353 // fallback if createURITemplate is null 347 if(this._createURITemplate) 354 if(this._createURITemplate) { 348 355 return this._createURITemplate; 349 else356 } else { 350 357 return this._dataURITemplate; 351 } 358 } 359 }; 352 360 353 361 /** … … 358 366 Form.prototype._submitSuccess = function (data, status) { 359 367 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 } 362 371 }; 363 372 … … 370 379 Form.prototype._submitError = function (request, status, error) { 371 380 alert("Error submitting form:\n" + request.status + ": " + request.statusText); 372 } 381 }; 373 382 374 383 /** … … 378 387 Form.prototype.beforeSubmit = function (request) { 379 388 // by default do nothing here 380 } 389 }; 381 390 382 391 … … 403 412 $.define("kauriform", Form); 404 413 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 */ 1 2 /** 2 3 * @fileOverview This file holds the basic structure of the formatter system … … 5 6 ( function( $) { 6 7 7 if (!$) 8 if (!$) { 8 9 throw "[formatter.js] requires jQuery"; 9 if (!$.org.kauriproject.forms) 10 } 11 if (!$.org.kauriproject.forms) { 10 12 throw "[formatter.js] requires the kauri-form namespace"; 13 } 11 14 12 15 var kf = $.org.kauriproject.forms; 13 16 var locale = kf.locale; 14 15 $.extend(kf, {16 Formatter :Formatter17 });18 17 19 18 … … 25 24 */ 26 25 function Formatter() { 27 28 26 } 29 27 … … 36 34 Formatter.prototype.format = function( val) { 37 35 38 if (val == undefined) 36 if (val == undefined) { 39 37 return ""; 38 } 40 39 return val.toString(); 41 } 40 }; 42 41 43 42 /** … … 52 51 53 52 valstr = $.trim(valstr); 54 if (valstr == "")53 if (valstr === "") { 55 54 return undefined; 55 } 56 56 return valstr; 57 } 57 }; 58 58 59 59 Formatter.prototype.toString = function() { 60 60 61 61 return "Formatter('" + this['org.kauriproject.registry-name'] + "')"; 62 } 62 }; 63 63 64 64 Formatter.prototype.fail = function( msg, args) { … … 66 66 msg = this.message || msg; 67 67 throw new kf.Message.build(msg, args, "Formatter.fail"); 68 } 68 }; 69 69 70 70 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 */ 1 2 /** 2 3 * @fileOverview This file holds some advanced controltypes for standard forms. … … 5 6 ( function( $) { 6 7 7 if (!$) 8 if (!$) { 8 9 throw "Kauri Forms Location module requires jQuery"; 9 if (!$.org.kauriproject.forms) 10 } 11 if (!$.org.kauriproject.forms) { 10 12 throw "Kauri Forms Location module requires the kauri-form namespace"; 13 } 11 14 12 15 var kp = $.org.kauriproject; … … 24 27 25 28 26 $.inherit(GMapControl, kf.AbstractContainerControl);27 28 29 /** 29 30 * @class Uses a google map as a control for choosing a location … … 39 40 kf.Control.init(this, id, form, conf); 40 41 } 42 $.inherit(GMapControl, kf.AbstractContainerControl); 43 41 44 42 45 /** … … 58 61 var type = this.getType(); 59 62 var memberTypes = type.getMemberTypes(); 60 61 for ( varmemberName in memberTypes) {63 var memberName; 64 for ( memberName in memberTypes) { 62 65 var memberType = memberTypes[memberName]; 63 66 var childControl = this.createChildControl(memberName, memberType); … … 96 99 }; 97 100 98 GMapControl.prototype.initEvents = function(){99 var me = this;101 GMapControl.prototype.initEvents = function(){ 102 var me = this; 100 103 101 104 // we are now setting the valueChanged handler 102 105 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 } 108 111 109 112 }); 110 }113 }; 111 114 112 115 GMapControl.prototype.setMapValue = function (value) { … … 121 124 this.gmap.panTo(point); 122 125 } 123 } 126 }; 127 124 128 kf.controlTypes.put("gmap-control", GMapControl); 125 129 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 */ 1 2 /** 2 3 * @fileOverview This file holds some advanced controltypes for standard forms. … … 5 6 ( function( $) { 6 7 7 if (!$) 8 if (!$) { 8 9 throw "Kauri Forms Advanced-Controls requires jQuery"; 9 if (!$.org.kauriproject.forms) 10 } 11 if (!$.org.kauriproject.forms) { 10 12 throw "Kauri Forms Advanced-Controls requires the kauri-form namespace"; 13 } 11 14 12 15 var kp = $.org.kauriproject; … … 17 20 18 21 format : function( val) { 19 if (val == undefined) 22 if (val == undefined) { 20 23 return ""; 21 if (val.start == undefined || val.end == undefined) 24 } 25 if (val.start == undefined || val.end == undefined) { 22 26 this.fail("The range doesn't have a start or end"); 23 if (val.start.constructor != Number) 27 } 28 if (val.start.constructor !== Number) { 24 29 this.fail("Not a valid number: {0}.", [ val.start ]); 25 if (val.end.constructor != Number) 30 } 31 if (val.end.constructor !== Number) { 26 32 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 } 29 37 return val.start.toLocaleString() + " - " + val.end.toLocaleString(); 30 38 }, … … 33 41 var start, end; 34 42 35 if (typeof valstr == 'string') {43 if (typeof valstr === 'string') { 36 44 valstr = $.trim(valstr); 37 if (valstr.length == 0)45 if (valstr.length === 0) { 38 46 return undefined; 47 } 39 48 40 49 var valArr = valstr.split(" - "); 41 if (valArr.length != 2)50 if (valArr.length !== 2) { 42 51 this.fail("Not a valid number range : {0}.", [ valstr ]); 52 } 43 53 44 54 start = new Number(valArr[0]); 45 55 end = new Number(valArr[1]); 46 56 47 if (isNaN(start) || isNaN(end)) 57 if (isNaN(start) || isNaN(end)) { 48 58 this.fail("Not a valid number range : {0}.", [ valstr ]); 49 50 if (start > end) 59 } 60 61 if (start > end) { 51 62 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) { 54 66 start = valstr.start; 55 67 end = valstr.end; … … 63 75 validate : function( value) { 64 76 65 if (value == undefined) 77 if (value == undefined) { 66 78 return this.notifySuccess(); 79 } 67 80 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 } 70 84 71 85 var response = kf.Validator.validateInt(this, value.start); 72 if(response == true)86 if(response === true) { 73 87 response = kf.Validator.validateInt(this, value.end); 88 } 74 89 75 90 return response; … … 87 102 }); 88 103 89 $.inherit(SliderControl, kf.Control);90 104 91 105 function SliderControl ( id, form, conf) { 92 106 kf.Control.init(this, id, form, conf); 93 107 } 108 $.inherit(SliderControl, kf.Control); 109 94 110 SliderControl.prototype.elements = {}; 95 111 $.extend(SliderControl.prototype.elements, kf.Control.prototype.elements); … … 120 136 range :me.isRange, 121 137 change : function( e, ui) { 122 123 138 me.syncInputValue(ui.value); 124 139 } … … 131 146 132 147 this.$slider.slider(sliderConf); 133 } 148 }; 134 149 135 150 /** … … 141 156 var $input = this.getElement(); 142 157 return $input.val(); 143 } 158 }; 144 159 145 160 /** … … 155 170 var val = this.getType().parseUserValue(value); 156 171 this.syncSlider( val); 157 } 172 }; 158 173 159 174 … … 161 176 162 177 // 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; } 168 180 169 181 // set event-handler-flag and be sure to unset it … … 180 192 this.inChangeEventHandler = false; 181 193 } 182 } 194 }; 183 195 184 196 SliderControl.prototype.syncInputValue = function( value) { … … 186 198 187 199 // escape from event loops between the two sources of change 188 if (this.inChangeEventHandler) 189 return; 200 if (this.inChangeEventHandler) { return; } 190 201 191 202 // set event-handler-flag and be sure to unset it … … 206 217 this.inChangeEventHandler = false; 207 218 } 208 } 219 }; 209 220 210 221 211 222 kf.controlTypes.put("slider-control", SliderControl); 212 223 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 */ 1 2 /** 2 3 * @fileOverview This script creates the Registry system based for managing the various types of types and objects in the forms … … 7 8 ( function( $) { 8 9 9 if (!$) 10 if (!$) { 10 11 throw "[registry.js] requires jQuery"; 11 if (!$.org.kauriproject.forms) 12 } 13 if (!$.org.kauriproject.forms) { 12 14 throw "[registry.js] requires the kauri-form namespace"; 15 } 13 16 14 17 var kf = $.org.kauriproject.forms; … … 47 50 48 51 this.toString = function() { 49 50 52 return 'ConstructorRegistry: ' + description; 51 53 }; … … 72 74 ConstructorRegistry.prototype.setBaseConstructor = function( /* constructor */baseConstructor, /* string */baseName) { 73 75 74 if (this._baseConstructor != undefined) 76 if (this._baseConstructor != undefined) { 75 77 throw "[ConstructorRegistry.setBaseConstructor] can only be set once"; 78 } 76 79 this._baseConstructor = baseConstructor; 77 if (baseName != undefined) 80 if (baseName != undefined) { 78 81 this.put(baseName, baseConstructor); 82 } 79 83 }; 80 84 … … 82 86 83 87 var found = this._baseConstructor; 84 if (found == undefined && this._parent != undefined) 88 if (found == undefined && this._parent != undefined) { 85 89 found = this._parent.getBaseConstructor(); 90 } 86 91 return found; 87 } 92 }; 88 93 89 94 ConstructorRegistry.prototype.setConfigBuilder = function( builder) { 90 95 91 96 this._configBuilder = builder; 92 } 97 }; 93 98 94 99 /** … … 101 106 102 107 if (loadPath != undefined) { 103 if (typeof loadPath == "string")108 if (typeof loadPath === "string") { 104 109 loadPath = new kp.UriTemplate(loadPath); 105 else if (loadPath.constructor != kp.UriTemplate)110 } else if (loadPath.constructor !== kp.UriTemplate) { 106 111 throw "[ConstructorRegistry.setLoadPath] loadPath constructor argument should be either string or UriTemplate."; 112 } 107 113 this._loadPath = loadPath; 108 114 } … … 117 123 ConstructorRegistry.prototype.load = function( /* string */name) { 118 124 119 if (!this._loadPath) 120 return; 125 if (!this._loadPath) { return; } 121 126 122 127 var uri = this._loadPath.expand( { … … 148 153 }); 149 154 150 if (constr && this._autoAdd) 155 if (constr && this._autoAdd) { 151 156 this.put(name, constr); 157 } 152 158 153 159 return constr; … … 172 178 173 179 var constr = classSpec; 174 if (name == undefined) 180 if (name == undefined) { 175 181 throw "[ConstructorRegistry.put] Can't register without a proper name."; 176 if (this._reg[name] != undefined) 182 } 183 if (this._reg[name] != undefined) { 177 184 throw "[ConstructorRegistry.put] can't register constructor (" + constr + ") in registry (" + this 178 185 + "). Reason: Name (" + name + ") already exists."; 186 } 179 187 180 188 classSpec = classSpec || {}; … … 183 191 var baseConstructor = extender.base; 184 192 delete extender.base; 185 if (!$.isFunction(baseConstructor) && baseConstructor != undefined) 193 if (!$.isFunction(baseConstructor) && baseConstructor != undefined) { 186 194 baseConstructor = this.get(baseConstructor); 195 } 187 196 baseConstructor = baseConstructor || this.getBaseConstructor(); 188 197 constr = this.extendConstructor(baseConstructor, extender); 189 198 } 190 199 191 if (!$.isFunction(constr)) 200 if (!$.isFunction(constr)) { 192 201 throw "[ConstructorRegistry.put] can only register functions/constructors."; 202 } 193 203 194 204 addNameProperty = addNameProperty || true; 195 if (addNameProperty) 205 if (addNameProperty) { 196 206 constr.prototype['org.kauriproject.registry-name'] = name; 207 } 197 208 198 209 this._reg[name] = constr; … … 215 226 addNameProperty = addNameProperty || true; 216 227 217 for ( var name in classSpecs) { 228 var name; 229 for ( name in classSpecs) { 218 230 this.put(name, classSpecs[name], addNameProperty); 219 231 } … … 227 239 ConstructorRegistry.isObject = function( val) { 228 240 229 return (val != undefined && val.constructor != Array)230 } 241 return (val != undefined && val.constructor !== Array); 242 }; 231 243 232 244 /** … … 239 251 ConstructorRegistry.prototype.extendProperties = function( protype, extender) { 240 252 241 for ( var atProp in extender) { 242 if (atProp.charAt(0) == '+') { 253 var atProp; 254 for ( atProp in extender) { 255 if (atProp.charAt(0) === '+') { 243 256 var prop = atProp.substring(1); 244 257 var oldPropVal = protype[prop]; … … 247 260 var newPropVal = isObjectProperty ? {} : []; // we need to make a new instance, otherwise the parent prototype 248 261 // gets extended. 249 250 for ( varknownRef in oldPropVal) {262 var knownRef; 263 for ( knownRef in oldPropVal) { 251 264 newPropVal[knownRef] = oldPropVal[knownRef]; 252 265 } 253 266 254 for ( var fresh in freshPropVal) { 267 var fresh; 268 for ( fresh in freshPropVal) { 255 269 var ref = isObjectProperty ? fresh : newPropVal.length; 256 270 var freshVal = freshPropVal[fresh]; 257 if (ConstructorRegistry.isObject(freshPropVal)) 271 if (ConstructorRegistry.isObject(freshPropVal)) { 258 272 freshVal.base = fresh; 273 } 259 274 260 275 newPropVal[ref] = freshVal; … … 265 280 } 266 281 } 267 } 282 }; 268 283 269 284 … … 276 291 ConstructorRegistry.prototype.configureProperties = function( constr) { 277 292 278 if (this._configBuilder == undefined || constr.configBuild == undefined || !$.isFunction(constr.configBuild)) 293 if (this._configBuilder == undefined || constr.configBuild == undefined || !$.isFunction(constr.configBuild)) { 279 294 return; 295 } 280 296 281 297 constr.configBuild(this._configBuilder, constr.prototype); 282 } 298 }; 283 299 284 300 … … 294 310 ConstructorRegistry.prototype.extendConstructor = function( /* function */baseConstructor, /* object */extender) { 295 311 296 if (!$.hasProperties(extender)) 312 if (!$.hasProperties(extender)) { 297 313 return baseConstructor; 314 } 298 315 299 316 //clone extender making sure it can be reused. … … 303 320 delete extender["<init>"]; 304 321 305 $.inherit(newConstructor, baseConstructor);306 322 function newConstructor() { 307 323 … … 313 329 } 314 330 } 331 $.inherit(newConstructor, baseConstructor); 315 332 316 333 this.extendProperties(newConstructor.prototype, extender); … … 326 343 // deep-clone these properties 327 344 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++) { 329 347 var name = deepClonePropertyNames[i]; 330 348 if (extender[name] != null) { … … 345 363 346 364 var found = this._reg[name]; 347 if (!found && this._parent) 365 if (!found && this._parent) { 348 366 found = this._parent.getWithoutLoad(name); 367 } 349 368 return found; 350 } 369 }; 351 370 352 371 /** … … 365 384 ConstructorRegistry.prototype.get = function( /* string */name, /* object */extender) { 366 385 367 if (!name) 386 if (!name) { 368 387 throw "[ConstructorRegistry.get] Need the name to get the registered constructor in registry " + this.toString(); 388 } 369 389 370 390 var found = this.getWithoutLoad(name); 371 if (!found) 391 if (!found) { 372 392 found = this.load(name); 373 if (!found) 393 } 394 if (!found) { 374 395 throw "[ConstructorRegistry.get] No registered constructor found: " + name + " in registry " + this.toString(); 375 376 if ($.hasProperties(extender)) 396 } 397 if ($.hasProperties(extender)) { 377 398 found = this.extendConstructor(found, extender); 399 } 378 400 379 401 return found; … … 394 416 ConstructorRegistry.prototype.getInstance = function( /* string */name, /* object */extender, /* array */args) { 395 417 396 if (!name) 418 if (!name) { 397 419 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)) { 401 424 return undefined; 425 } 402 426 403 427 // ie -jscript doesn't like args == undefined in tha call to fn.apply(this, args); 404 428 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(); 412 436 }; 413 437 … … 416 440 }); 417 441 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 */ 1 2 /** 2 3 * @fileOverview This file holds some advanced controltypes for standard forms. … … 5 6 (function($){ 6 7 7 if (!$) 8 if (!$) { 8 9 throw "Kauri Forms Upload module requires jQuery"; 9 if (!$.org.kauriproject.forms) 10 } 11 if (!$.org.kauriproject.forms) { 10 12 throw "Kauri Forms Upload module requires the kauri-form namespace"; 13 } 11 14 12 15 var kp = $.org.kauriproject; … … 18 21 }); 19 22 20 $.inherit(UploadControl, kf.Control);21 23 22 24 /** … … 31 33 kf.Control.init(this, id, form, conf); 32 34 } 35 $.inherit(UploadControl, kf.Control); 33 36 34 37 /** … … 56 59 57 60 // by default show the remove link 58 if (this.showRemove == undefined) 61 if (this.showRemove == undefined) { 59 62 this.showRemove = true; 63 } 60 64 61 65 var $container = this.getElement("input"); … … 111 115 $container = $container || this.getElement("input"); 112 116 113 if (this.uploadInput) 117 if (this.uploadInput) { 114 118 this.uploadInput.remove(); 119 } 115 120 116 121 // the visual input control the end user will see … … 119 124 me.performUpload(); 120 125 }); 121 } 126 }; 122 127 123 128 UploadControl.prototype.performUpload = function() { … … 142 147 // start upload by submitting the upload-form 143 148 this.uploadForm.submit(); 144 } 149 }; 145 150 146 151 UploadControl.prototype.handleUploadResponse = function(idoc) { 147 if (!idoc || INIT_FRAME_URL == idoc.URL)152 if (!idoc || INIT_FRAME_URL === idoc.URL) { 148 153 return; // no data to be read, this is just starting up 154 } 149 155 150 156 try { … … 167 173 this.updateView(); 168 174 } 169 } 175 }; 170 176 171 177 UploadControl.prototype.dataRef = function(id){ … … 175 181 176 182 return base + id; 177 } 183 }; 178 184 179 185 UploadControl.prototype.leaseRef = function(id){ … … 183 189 184 190 return base + id + "/lease.json"; 185 } 186 191 }; 187 192 188 193 … … 191 196 level = level || 0; 192 197 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) { 194 199 return this.humanSize(nextOrder, level+1); 200 } 195 201 //else 196 202 return size + ORDER_SIZES[level]; 197 } 203 }; 198 204 199 205 var FILE_PART_REGEXP = /^.*?([^\/\\]+)$/; 200 206 UploadControl.prototype.fileNameOnly = function(path) { 201 207 var m = FILE_PART_REGEXP.exec(path); 202 if (m == null) 208 if (m == null) { 203 209 return path; 210 } 204 211 return m[1]; 205 } 212 }; 206 213 207 214 UploadControl.prototype.updateView = function () { … … 213 220 214 221 // remove the input if still there and replace with file information 215 if (this.uploadInput) 222 if (this.uploadInput) { 216 223 this.uploadInput.remove(); 224 } 217 225 218 226 // display file information … … 236 244 }); 237 245 } 238 if (isTemporary) 246 if (isTemporary) { 239 247 this.startHeartBeat(value.id); 240 248 } 241 249 } else { 242 250 //no value set, so allow end-user to enter one … … 244 252 this.newUploadInput(me); 245 253 } 246 } 254 }; 247 255 248 256 UploadControl.prototype.clearUploadedFile = function (key, isTemporary) { … … 256 264 url :uri 257 265 }); 258 } 266 }; 259 267 260 268 UploadControl.prototype.heartbeatTimer = null; … … 265 273 266 274 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 }; 270 278 271 279 UploadControl.prototype.getLeaseInfo = function (leaseRef, method) { … … 275 283 url :leaseRef, 276 284 success: function(data) { 277 if(data) refreshTime = data.refreshTime;285 if(data) { refreshTime = data.refreshTime; } 278 286 } 279 287 }); 280 288 return refreshTime; 281 } 289 }; 282 290 283 291 UploadControl.prototype.endHeartBeat = function (key) { 284 clearInterval( heartbeatTimer);285 } 292 clearInterval(this.heartbeatTimer); 293 }; 286 294 287 295 UploadControl.prototype.writeUserValue = function (value) { 288 296 // no such thing, we just use the event to update the visual 289 297 this.updateView(); 290 } 298 }; 291 299 292 300 UploadControl.prototype.readUserValue = function () { 293 301 // 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 }; 311 319 312 320 kf.controlTypes.put("upload-control", UploadControl); 313 321 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 */ 1 2 /** 2 3 * @fileOverview This file holds the basic structure of the validation system … … 5 6 ( function( $) { 6 7 7 if (!$) 8 if (!$) { 8 9 throw "[validator.js] requires jQuery"; 9 if (!$.org.kauriproject.forms) 10 } 11 if (!$.org.kauriproject.forms) { 10 12 throw "[validator.js] requires the kauri-form namespace"; 13 } 11 14 12 15 var kf = $.org.kauriproject.forms; 13 16 var locale = kf.locale; 14 15 $.extend(kf, {16 Validator :Validator,17 ValidationListener :ValidationListener18 });19 17 20 18 /** … … 34 32 */ 35 33 function Validator() { 36 37 34 } 38 35 … … 53 50 54 51 return this.notifySuccess(); 55 } 52 }; 56 53 57 54 Validator.prototype.inSequence = function( listener, seqId) { … … 59 56 this.listener = listener; 60 57 this.seqId = seqId; 61 } 58 }; 62 59 63 60 Validator.prototype.clearSequence = function() { 64 61 65 62 this.inSequence(); 66 } 63 }; 67 64 68 65 Validator.prototype.toString = function() { 69 66 70 67 return "Validator('" + this['org.kauriproject.registry-name'] + "')"; 71 } 68 }; 72 69 73 70 Validator.prototype.notify = function( result, msg) { 74 71 Validator.notify(this, result, msg); 75 } 72 }; 76 73 77 74 Validator.notify = function(me, result, msg) { 78 75 79 if (!me.listener || !me.seqId) 76 if (!me.listener || !me.seqId) { 80 77 return result; 78 } 81 79 82 80 me.listener.report(me.seqId, result, msg); … … 84 82 85 83 return result; 86 } 84 }; 87 85 88 86 Validator.prototype.notifyFail = function( msg, args) { 89 87 Validator.notifyFail(this, msg, args); 90 } 88 }; 91 89 92 90 Validator.notifyFail = function(me, msg, args) { … … 99 97 Validator.prototype.notifySuccess = function() { 100 98 Validator.notifySuccess(this); 101 } 99 }; 102 100 Validator.notifySuccess = function(me) { 103 101 return Validator.notify(me, true); 104 } 102 }; 105 103 106 104 /** … … 108 106 * @return true by default 109 107 */ 110 Validator.prototype.isEnabled = function( ) {111 return true;112 }108 Validator.prototype.isEnabled = function() { 109 return true; 110 }; 113 111 114 112 /** … … 118 116 function ValidationListener( delegate) { 119 117 120 this.currentSequenceId ;121 this.expects ;118 this.currentSequenceId = undefined; 119 this.expects = undefined; 122 120 this.delegate = delegate || this; 123 121 } … … 126 124 127 125 return new Number(Math.random() * 10000).toFixed(); 128 } 126 }; 129 127 130 128 ValidationListener.prototype.newSequenceId = function() { 131 129 132 130 return ValidationListener.newSequenceId(); 133 } 131 }; 134 132 135 133 ValidationListener.prototype.expect = function( n) { … … 139 137 this.delegate.validationStart(); 140 138 return this.sequenceId; 141 } 139 }; 142 140 143 141 ValidationListener.prototype.report = function( seqId, result, message) { 144 142 145 if (this.sequenceId == seqId) {146 if (result) 143 if (this.sequenceId === seqId) { 144 if (result) { 147 145 this.delegate.validationSuccess(); 148 else146 } else { 149 147 this.delegate.validationFail(message); 150 if (--this.expects == 0) 148 } 149 if (--this.expects === 0) { 151 150 this.delegate.validationComplete(); 152 } else 151 } 152 } else { 153 153 this.delegate.validationIgnored(seqId, result, message); 154 } 154 } 155 }; 155 156 156 157 ValidationListener.prototype.validationSuccess = function() { 157 158 } 158 }; 159 159 160 160 ValidationListener.prototype.validationFail = function( message) { 161 162 } 161 }; 163 162 164 163 ValidationListener.prototype.validationStart = function() { 165 166 } 164 }; 167 165 168 166 ValidationListener.prototype.validationComplete = function() { 169 170 } 167 }; 171 168 172 169 ValidationListener.prototype.validationIgnored = function( seqId, result, message) { 170 }; 173 171 174 } 172 173 $.extend(kf, { 174 Validator :Validator, 175 ValidationListener :ValidationListener 176 }); 175 177 176 })(jQuery); 178 179 }(jQuery));
Note: See TracChangeset
for help on using the changeset viewer.