- Timestamp:
- 2011-09-14 12:14:34 (8 months ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/control.js (modified) (1 diff)
-
modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/field.js (modified) (3 diffs)
-
samples/kauri-forms-sample/src/main/kauri/pages/selection-control.html.xml (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/control.js
r1948 r1950 1203 1203 1204 1204 if (opts) { 1205 var options = kf.Options.create(opts, this.getType() );1205 var options = kf.Options.create(opts, this.getType(), this); 1206 1206 if (options.toShare()) { 1207 1207 options = this.getType().share("options", options); -
trunk/modules/kauri-forms/kauri-forms-framework/src/main/kauri/static-{build}.key/kauri.forms/field.js
r1948 r1950 46 46 * @static 47 47 */ 48 Options.create = function(config, type ) {48 Options.create = function(config, type, control) { 49 49 var opts = new Options(); 50 50 $.extend(opts, config); … … 63 63 } 64 64 65 //translate opt.requires into an array. 66 if (opts.requires === undefined || opts.requires === null || opts.requires === false) { 67 opts.requires = []; 68 } else if (opts.requires === true || opts.requires === "all") { 69 opts.requires = []; 70 if (control && control.depends) { 71 var depname; 72 for(depname in control.depends) { 73 opts.requires.push(depname); 74 } 75 } 76 } 65 77 return opts; 66 78 } … … 222 234 Options.prototype.refresh = function() { 223 235 224 if (this.refreshable()) { 225 this.uriContext = this.uriContext || {}; 226 var uri = this.uri.expand(this.uriContext); 227 var me = this; 228 var onSuccess = function( data, status, xhr) { 229 if (xhr && me.lastXhr === xhr) { //ignore responses that are not linked to the last request 230 me.parseOptions(data); 231 me.lastXhr = null; 232 } 233 }; 234 var onError = function( xhr, status, err) { 235 if (xhr && me.lastXhr === xhr) { 236 me.clearOptions(); 237 me.lastXhr = null; 238 } 239 }; 240 241 // assign lastXhr to make sure only the return of this last one is accepted 242 $.ajax( { 243 // take async setting from setup 244 type : "GET", 245 cache : false, 246 url : uri, 247 processData: false, 248 dataType : "json", 249 success : onSuccess, 250 error : onError, 251 beforeSend : function(xhr) { 252 // setting datatype to json should be enough, unfortunately 253 // the restlet content negotiation chokes on the resulting 254 // accept header: application/json, text/javascript, */* 255 // and doesn't prefer the json variant. 256 // see issue #95 257 xhr.setRequestHeader("Accept", "application/json"); 258 me.lastXhr = xhr; 259 } 260 }); 261 } 262 }; 263 236 if (! this.refreshable() ){ 237 return; 238 } 239 240 if (! this.uriContextComplete() ) { 241 return; 242 } 243 244 var uri = this.uri.expand(this.uriContext); 245 var me = this; 246 var onSuccess = function( data, status, xhr) { 247 if (xhr && me.lastXhr === xhr) { //ignore responses that are not linked to the last request 248 me.parseOptions(data); 249 me.lastXhr = null; 250 } 251 }; 252 var onError = function( xhr, status, err) { 253 if (xhr && me.lastXhr === xhr) { 254 me.clearOptions(); 255 me.lastXhr = null; 256 } 257 }; 258 259 // assign lastXhr to make sure only the return of this last one is accepted 260 $.ajax( { 261 // take async setting from setup 262 type : "GET", 263 cache : false, 264 url : uri, 265 processData: false, 266 dataType : "json", 267 success : onSuccess, 268 error : onError, 269 beforeSend : function(xhr) { 270 // setting datatype to json should be enough, unfortunately 271 // the restlet content negotiation chokes on the resulting 272 // accept header: application/json, text/javascript, */* 273 // and doesn't prefer the json variant. 274 // see issue #95 275 xhr.setRequestHeader("Accept", "application/json"); 276 me.lastXhr = xhr; 277 } 278 }); 279 }; 280 281 /** 282 * Checks if all required members in the uri-context are present. 283 */ 284 Options.prototype.uriContextComplete = function() { 285 this.uriContext = this.uriContext || {}; 286 287 var i = 0, last = this.requires.length; 288 for (i = 0; i<last ; i++) { 289 var requiredContext = this.uriContext[this.requires[i]] 290 if (requiredContext === undefined || requiredContext === null) { 291 return false; 292 } 293 } 294 295 return true; 296 } 264 297 265 298 /** -
trunk/samples/kauri-forms-sample/src/main/kauri/pages/selection-control.html.xml
r1890 r1950 90 90 "depends": {"carMake": "/carMake"}, 91 91 "options": { 92 "requires": "all", 92 93 "uri": "${publicUri('service:/data/carmake/{carMake}/models')}", 93 94 "valueTemplate": "{name}", … … 151 152 } 152 153 } 153 } 154 }; 154 155 155 156
Note: See TracChangeset
for help on using the changeset viewer.