Changeset 221
- Timestamp:
- 2008-05-13 15:20:08 (5 years ago)
- Location:
- trunk/modules/kauri-forms/kauri-forms-framework/src/main/resources/KAURI-INF/js
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/kauri-forms/kauri-forms-framework/src/main/resources/KAURI-INF/js/basics.js
r220 r221 112 112 } 113 113 114 BooleanWidgetType. initialize = function(/* WidgetInstance */widgetInstance)114 BooleanWidgetType.prototype.initialize = function(/* WidgetInstance */widgetInstance) 115 115 { 116 116 if (widgetInstance.getContainer().attr("type") != "checkbox") … … 123 123 124 124 // TODO we can probably just remove this... 125 BooleanWidgetType. configure = function(/* WidgetInstance */widgetInstance)125 BooleanWidgetType.prototype.configure = function(/* WidgetInstance */widgetInstance) 126 126 { 127 127 } 128 128 129 BooleanWidgetType. getValue = function(/* WidgetInstance */widgetInstance)129 BooleanWidgetType.prototype.getValue = function(/* WidgetInstance */widgetInstance) 130 130 { 131 131 if (widgetInstance.getContainer().attr("checked") == true) … … 135 135 } 136 136 137 BooleanWidgetType. setValue = function(/* WidgetInstance */widgetInstance, value)137 BooleanWidgetType.prototype.setValue = function(/* WidgetInstance */widgetInstance, value) 138 138 { 139 139 if (value == true || value == "true") -
trunk/modules/kauri-forms/kauri-forms-framework/src/main/resources/KAURI-INF/js/composite.js
r220 r221 145 145 } 146 146 147 CompositeWidgetType. setValue = function(/* WidgetInstance */widgetInstance, value)147 CompositeWidgetType.prototype.setValue = function(/* WidgetInstance */widgetInstance, value) 148 148 { 149 149 var members = widgetInstance.getType().getMembers(); -
trunk/modules/kauri-forms/kauri-forms-framework/src/main/resources/KAURI-INF/js/field.js
r220 r221 136 136 return this; 137 137 else 138 { 138 { 139 139 140 // clone Type obj 140 var cloneType = $.extend({}, this); 141 //var cloneType = {}; 142 //$.extend(/*deep*/true, cloneType, this); 143 //TODO: check why extend doesn't work correctly 144 var cloneType = new cloneObject(this); 141 145 142 146 /* _DEV_ */kf.debug("extended type"); … … 184 188 } 185 189 190 function cloneObject(obj) 191 { 192 for (i in obj) 193 { 194 if (obj && obj.constructor == Array) 195 { 196 // Clone an array 197 var clone = []; 198 for ( var i = 0; i < obj.length; i++) 199 { 200 clone[i] = obj[i]; 201 } 202 return clone; 203 } else if (typeof obj[i] == 'object') 204 { 205 this[i] = new cloneObject(obj[i]); 206 } else 207 this[i] = obj[i]; 208 } 209 } 210 211 186 212 /** 187 213 * FieldInstance controls... -
trunk/modules/kauri-forms/kauri-forms-framework/src/main/resources/KAURI-INF/js/form.js
r220 r221 1 /** 2 * @fileOverview This file holds the classes composing the actual Form structure. 1 /** 2 * @fileOverview This file holds the classes composing the actual Form 3 * structure. 3 4 */ 4 ;(function($){ 5 if (!$) throw "Kauri Form & Model requires jQuery"; 6 if (!$.org.kauriproject.forms) throw "Kauri Form & Model requires the kauri-form namespace"; 7 8 var kf = $.org.kauriproject.forms; 5 ; 6 ( function($) 7 { 8 if (!$) 9 throw "Kauri Form & Model requires jQuery"; 10 if (!$.org.kauriproject.forms) 11 throw "Kauri Form & Model requires the kauri-form namespace"; 12 13 var kf = $.org.kauriproject.forms; 9 14 10 15 $.extend(kf, { 11 Model :Model,12 Form : Form13 } );16 Model :Model, 17 Form :Form 18 }); 14 19 15 20 // TODO think and discuss about a good path location 16 21 var REMOTE_WIDGET_PATH = "/kauri/forms/widgets/load_"; 17 22 /* _DEV_ *//* for local test purpose */REMOTE_WIDGET_PATH = "../public/widgets/load_"; 18 19 // TODO more thinking for dynamic loaded fieltypes and validators (if needed) 20 23 24 // TODO more thinking for dynamic loaded fieltypes and validators (if 25 // needed) 26 21 27 /** 22 28 * Model holds and controlls ... 23 29 * 24 30 * TODO document 25 * 31 * 26 32 * 27 33 * @constructor … … 37 43 this.validators = new kf.Registry("Registry for Local Validators", kf.validators); 38 44 } 39 40 //TODO consider removing these add** methods in favour of direct calls to the registries... 45 46 // TODO consider removing these add** methods in favour of direct calls to 47 // the registries... 41 48 Model.prototype.addWidgetType = function(/* String */name, /* WidgetDefinition */widgetType) 42 49 { 43 50 this.widgetTypes.put(widgetType, name); 44 51 } 45 52 46 53 Model.prototype.addFieldType = function(/* String */name, /* Type */type) 47 54 { 48 55 this.fieldTypes.put(type, name); 49 // todo check this was here before: needed? 56 // todo check this was here before: needed? 50 57 // type._name = name; 51 58 } 52 59 53 60 Model.prototype.addValidator = function(/* String */name, /* function */validator) 54 61 { 55 62 this.validators.put(validator, name); 56 63 } 57 64 58 65 Model.prototype.setDatatype = function(/* Type */type) 59 66 { 60 67 this._datatype = type; 61 68 } 62 69 63 70 Model.prototype.getDatatype = function() 64 71 { 65 72 return this._datatype; 66 73 } 67 68 //TODO consider removing these find** methods in favour of direct calls to the registries... 74 75 // TODO consider removing these find** methods in favour of direct calls to 76 // the registries... 69 77 Model.prototype.findWidgetType = function(/* String */name) 70 78 { 71 79 return this.widgetTypes.get(name); 72 80 } 73 81 74 82 Model.prototype.findFieldType = function(/* String */name) 75 83 { 76 84 return this.fieldTypes.get(name); 77 85 } 78 86 79 87 Model.prototype.findValidator = function(/* String */name) 80 88 { … … 82 90 } 83 91 84 85 86 87 92 /** 88 93 * Form holds and controlls.... … … 102 107 alert("No correct container specified for form."); 103 108 } 104 109 105 110 this._widgetInstanceInventory = {}; 106 111 107 112 this.formWidgetFQN = "form"; 108 113 } 109 114 110 115 /** 111 116 * Finds a WidgetType by name. … … 117 122 { 118 123 var localType = this._model.findWidgetType(widgetDefinitionName); 119 if (localType) 120 return localType; 121 else 122 return kf.widgetTypes.get(widgetDefinitionName); 123 } 124 125 /** 126 * Finds a Type by name. 124 return localType; 125 } 126 127 /** 128 * Finds a FieldType by name. 127 129 * 128 130 * First search local reg, if nothing found, search global reg 131 * 132 * @type FieldType 129 133 */ 130 134 Form.prototype.findFieldType = function(/* String */typeName) 131 135 { 132 var localType = this._model.findFieldType(typeName); 133 if (localType) 134 return localType; 135 else 136 return kf.fieldTypes.get(typeName); 137 } 138 139 /** 140 * Finds a Validation method by name. 141 * 142 * First search local reg, if nothing found, search global reg 136 var localType = this._model.findFieldType(typeName); 137 return localType; 138 } 139 140 /** 141 * Finds a Validator by name. 142 * 143 * First search local reg, if nothing found, search global reg * 144 * 145 * @type Validator 143 146 */ 144 147 Form.prototype.findValidator = function(/* String */validationName) … … 146 149 return this._model.findValidator(validationName); 147 150 } 148 149 150 / /TODO describe/understand what this inventory is?151 /**152 * Finds a WidgetInstancein the widgetInstanceInventory by its fully qualified153 * name.154 * 151 152 // TODO describe/understand what this inventory is? 153 /** 154 * Finds a WidgetInstance in the widgetInstanceInventory by its fully 155 * qualified name. The purpose for this registry is widgetbinding. 156 * 157 * @type WidgetInstance 155 158 */ 156 159 Form.prototype.findWidgetInstance = function(/* String */widgetFQN) … … 158 161 return this._widgetInstanceInventory[widgetFQN]; 159 162 } 160 163 161 164 /** 162 165 * Adds a WidgetInstance to the widgetInstanceInventory … … 172 175 } 173 176 } 174 177 175 178 /** 176 179 * Creates a Member from a chunck of data. … … 183 186 if (!memberdata.type) 184 187 return kf.reportDesignError("Missing type for member '" + name + "'!"); 185 188 186 189 var type = this.findFieldType(memberdata.type); 187 190 if (!type) 188 191 return kf.reportDesignError("Unknown type: '" + memberdata.type + "' for member '" + name + "'!"); 189 192 190 193 // check if widget gets overridden 191 194 var widgetType; … … 199 202 + widgetType.getName() + "'!"); 200 203 } 201 204 202 205 // parse validation rules 203 206 var validationRules; … … 221 224 } 222 225 } 223 226 224 227 // instantiate Member with possible extensions to type 225 228 var member = new kf.FieldInstance(name, type.extend(widgetType, memberdata.options, undefined, validationRules, 226 229 memberdata.validationTriggers), ((memberdata.label) ? memberdata.label : ""), 227 230 ((memberdata.isCollection) ? memberdata.isCollection : false)); 228 231 229 232 return member; 230 233 } 231 234 232 235 /** 233 236 * Creates a Type from a chunck of data. … … 252 255 return kf.reportDesignError("Type not found: '" + typedata.type + "'!"); 253 256 } 254 257 255 258 var widgetType; 256 259 if (typedata.widget) … … 260 263 return kf.reportDesignError("WidgetType not found: '" + typedata.widget + "'!"); 261 264 if (!widgetType.isTypeCompatible(typedata.type)) 262 return kf.reportDesignError("Type '" + typedata.type + "' is not compatible with widget '" 263 + widgetType.getName() +"'!");264 } 265 265 return kf.reportDesignError("Type '" + typedata.type + "' is not compatible with widget '" + widgetType.getName() 266 + "'!"); 267 } 268 266 269 return type.extend(widgetType, typedata.options, {}, typedata.validations); 267 270 } 268 271 269 272 /** 270 273 * Loads the model data and returns a Model 271 274 * 272 * order of filling the regs is important: first custom widgets and validations,273 * than the types275 * order of filling the regs is important: first custom widgets and 276 * validations, than the types 274 277 */ 275 278 Form.prototype.loadModel = function(/* object */formmodeldata) 276 279 { 277 280 var model = this._model; 278 281 279 282 // load local widget-definitions 280 283 if (formmodeldata.widgets) … … 283 286 { 284 287 var widgetdata = formmodeldata.widgets[widgetname]; 285 model.widgetTypes.put( 286 new kf.WidgetType( 287 widgetname, 288 widgetdata.compatibleTypes, 289 widgetdata.initFunction, 290 widgetdata.configFunction, 291 widgetdata.getValueFunction, 292 widgetdata.setValueFunction, 293 widgetdata.events 294 ) 295 ); 296 } 297 } 298 288 model.widgetTypes.put(new kf.WidgetType(widgetname, widgetdata.compatibleTypes, widgetdata.initFunction, 289 widgetdata.configFunction, widgetdata.getValueFunction, widgetdata.setValueFunction, widgetdata.events)); 290 } 291 } 292 299 293 // load local type-definitions 300 294 if (formmodeldata.types) … … 303 297 { 304 298 var typedata = formmodeldata.types[typename]; 305 model.fieldTypes.put(this.createType(typedata), typename );306 } 307 } 308 299 model.fieldTypes.put(this.createType(typedata), typename); 300 } 301 } 302 309 303 // set base composite 310 304 model.setDatatype(this.findFieldType(formmodeldata.datatype)); 311 305 312 306 if (formmodeldata.getDataUri) 313 307 model._getDataURI = new kauri.util.Template(formmodeldata.getDataUri); 314 308 if (formmodeldata.putDataUri) 315 309 model._putDataURI = new kauri.util.Template(formmodeldata.putDataUri); 316 310 317 311 model._postDataURI = formmodeldata.postDataUri; 318 312 319 313 return model; 320 314 } 321 315 322 316 /** 323 317 * Initializes the form by instantiating the widgets and binding the submit … … 330 324 this.addWidgetInstance(datatype.getWidgetType().createWidgetInstance(this.getContainer(), this, this.formWidgetFQN, 331 325 datatype)); 332 326 333 327 // configure widgets 334 328 /* _DEV_ */kf.debug("Start config of all widgets"); 335 329 this.findWidgetInstance(this.formWidgetFQN).configure(); 336 330 /* _DEV_ */kf.debug("End config"); 337 331 338 332 var form = this; 339 333 $(".submit", this.getContainer()).click( function() … … 342 336 }); 343 337 } 344 338 345 339 /** 346 340 * Sets the data of the form by filling in all the widgets … … 359 353 } 360 354 } 361 355 362 356 Form.prototype.setRemoteJsonData = function() 363 357 { 364 358 var form = this; 365 if (form._model._getDataURI && !(function(){for (var p in form._resourceIdObject){return false;} return true;}())) 359 if (form._model._getDataURI && !( function() 360 { 361 for ( var p in form._resourceIdObject) 362 { 363 return false; 364 } 365 return true; 366 }())) 366 367 { 367 368 $.getJSON(form._model._getDataURI.expand(this._resourceIdObject), function(data) … … 371 372 } 372 373 } 373 374 374 375 Form.prototype.validate = function() 375 376 { … … 379 380 return valid; 380 381 } 381 382 382 383 Form.prototype.submit = function() 383 384 { … … 387 388 return; 388 389 } 389 390 390 391 // update data object 391 392 var json = {}; … … 397 398 json[formmembers[i].getName()] = widget.getValue(); 398 399 } 399 400 400 401 // post 401 402 var postUrl; … … 404 405 else 405 406 postUrl = this._model._postDataURI; 406 407 407 408 $.ajax( { 408 409 type :"POST", … … 420 421 }); 421 422 } 422 423 423 424 Form.prototype.getContainer = function() 424 425 {
Note: See TracChangeset
for help on using the changeset viewer.