Changeset 510 for Dev/trunk/src/client/qed-client/model/classes
- Timestamp:
- 03/12/14 15:16:54 (11 years ago)
- Location:
- Dev/trunk/src/client/qed-client/model/classes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/src/client/qed-client/model/classes/_Class.js
r506 r510 1 1 define([ 2 "../../lib/object", 2 3 "./_View", 3 4 "dojo/_base/array", … … 5 6 "dojo/_base/lang", 6 7 "dojo/date/stamp" 7 ], function( _View, array, declare, lang, stamp) {8 ], function(objectFuns, _View, array, declare, lang, stamp) { 8 9 9 10 var _Class = declare([_View],{ … … 24 25 obj = lang.clone(obj); 25 26 obj = this._serialize(obj) || obj; 26 this._s trip(obj);27 this._sanitize(obj); 27 28 return obj; 28 29 }, … … 65 66 return stamp.toISOString(date,{zulu:true,milliseconds:false}); 66 67 }, 67 _s trip: function(obj) {68 _sanitize: function(obj) { 68 69 if ( lang.isArray(obj) ) { 69 array.forEach(obj,this._s trip,this);70 array.forEach(obj,this._sanitize,this); 70 71 } else if ( lang.isObject(obj) ) { 71 for ( var prop in obj ) { 72 if ( obj.hasOwnProperty(prop) ) { 73 var v = obj[prop]; 74 if ( v === null || v === "" || (typeof v === "number" && isNaN(v)) ) { 75 delete obj[prop]; 76 } else { 77 this._strip(v); 78 } 72 objectFuns.forEach(obj,function(v,prop){ 73 if ( v === null || 74 v === "" || 75 (typeof v === "number" && isNaN(v)) ) { 76 delete obj[prop]; 77 } else { 78 this._sanitize(v); 79 79 } 80 } 80 81 },this); 81 82 } 82 83 83 } 84 84 }); -
Dev/trunk/src/client/qed-client/model/classes/responses.js
r509 r510 1 1 define([ 2 "../../lib/object", 2 3 "./_Class", 3 4 "./surveyRuns", … … 7 8 "dojo/_base/lang", 8 9 "dojo/_base/xhr" 9 ], function( _Class, surveyRuns, Deferred, declare, json, lang, xhr) {10 ], function(objectFuns, _Class, surveyRuns, Deferred, declare, json, lang, xhr) { 10 11 11 12 var Responses = declare([_Class],{ … … 29 30 }, 30 31 _serialize: function(obj) { 32 this._convertCheckAndRadio(obj.answers); 31 33 if (obj._surveyRun) { 32 34 obj._surveyRun = surveyRuns._doSerialize(obj._surveyRun); … … 84 86 return result; 85 87 },lang.hitch(this,'_deserializeError')); 88 }, 89 _convertCheckAndRadio: function(answers) { 90 // When we encounter an array, we assume it's really a 91 // checkbox value. 92 objectFuns.forEach(answers,function(v,prop){ 93 if ( lang.isArray(v) ) { 94 switch (v.length) { 95 case 0: 96 case 1: 97 answers[prop] = v[0]; 98 break; 99 default: 100 throw new Error("Responses cannot exist of array values."); 101 } 102 } 103 },this); 86 104 } 87 105 });
Note: See TracChangeset
for help on using the changeset viewer.