Changeset 487 for Dev/trunk/src/client/qed-client/model/classes
- Timestamp:
- 03/05/14 22:44:48 (11 years ago)
- Location:
- Dev/trunk/src/client/qed-client/model/classes
- Files:
-
- 4 added
- 1 deleted
- 1 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/src/client/qed-client/model/classes
-
Property
svn:ignore
set to
### begin grunt-svn-ignore managed ignores
### edits will be overwritten when grunt svn-ignore is run
Question.js
Response.js
Survey.js
SurveyRun.js
### end grunt-svn-ignore managed ignores
-
Property
svn:ignore
set to
-
Dev/trunk/src/client/qed-client/model/classes/questions.js
r486 r487 1 define(function(){ 2 return { 3 create: function(){ 4 return { type:'Question' }; 1 define([ 2 "./_Class", 3 "dojo/_base/declare", 4 "dojo/date/stamp" 5 ], function(_Class, declare, stamp) { 6 7 var Questions = declare([_Class],{ 8 _collection: 'questions', 9 _type: 'Question', 10 create: function() { 11 var obj = { 12 type: this._type, 13 categories: [], 14 code: "", 15 content: [], 16 title: "" 17 }; 18 return obj; 5 19 }, 6 DisplayTitle:{7 get: function(q) {8 return q.title || '';20 _deserialize: function(obj) { 21 if (obj.publicationDate) { 22 obj.publicationDate = stamp.fromISOString(obj.publicationDate); 9 23 } 10 24 }, 11 Content: { 12 get: function(q) { 13 return q.content || []; 14 }, 15 set: function(q,content) { 16 q.content = content; 25 _serialize: function(obj) { 26 if (obj.publicationDate) { 27 obj.publicationDate = stamp.toISOString(obj.publicationDate); 17 28 } 18 29 } 19 }; 30 }); 31 32 return new Questions(); 33 20 34 }); -
Dev/trunk/src/client/qed-client/model/classes/responses.js
r486 r487 1 define([],function(){ 2 var SurveyRun = { 3 create: function(){ 4 return { type:'Response' }; 1 define([ 2 "./_Class", 3 "./surveyRuns", 4 "dojo/Deferred", 5 "dojo/_base/declare", 6 "dojo/_base/json", 7 "dojo/_base/lang", 8 "dojo/_base/xhr", 9 "dojo/date/stamp" 10 ], function(_Class, surveyRuns, Deferred, declare, json, lang, xhr, stamp) { 11 12 var Responses = declare([_Class],{ 13 _collection: 'responses', 14 _type: 'Response', 15 create: function() { 16 var obj = { 17 type: this._type, 18 answers: {}, 19 surveyRunId: null 20 }; 21 return obj; 5 22 }, 6 SurveyRun: { 7 get: function(r) { 8 return r.surveyRunId || null; 9 }, 10 set: function(r,sr) { 11 r.surveyRunId = sr; 12 return r; 23 _deserialize: function(obj) { 24 if (obj._surveyRun) { 25 obj._surveyRun = surveyRuns._doDeserialize(obj._surveyRun); 13 26 } 27 if (obj.publicationDate) { 28 obj.publicationDate = stamp.fromISOString(obj.publicationDate); 29 } 30 }, 31 _serialize: function(obj) { 32 if (obj._surveyRun) { 33 obj._surveyRun = surveyRuns._doSerialize(obj._surveyRun); 34 } 35 if (obj.publicationDate) { 36 obj.publicationDate = stamp.toISOString(obj.publicationDate); 37 } 38 }, 39 getWithSecret: function(id,secret) { 40 var query = xhr.objectToQuery({secret:secret}); 41 return xhr('GET',{ 42 url: '/api/open/responses/' + id + '?' + query, 43 handleAs: 'json', 44 contentType: false 45 }).then(lang.hitch(this,'_doDeserialize'),function(err){ 46 return new Deferred().reject(json.fromJson(err.responseText)); 47 }); 48 }, 49 postWithSecret: function(response,secret) { 50 var query = xhr.objectToQuery({secret:secret}); 51 var body = json.toJson(this._doSerialize(response)); 52 return xhr('POST',{ 53 url: '/api/open/responses?' + query, 54 handleAs: 'json', 55 contentType: 'application/json', 56 rawBody: body 57 }).then(lang.hitch(this,'_doDeserialize'),function(err){ 58 return new Deferred().reject(json.fromJson(err.responseText)); 59 }); 60 }, 61 putWithSecret: function(response,secret) { 62 var query = xhr.objectToQuery({secret:secret}); 63 var body = json.toJson(this._doSerialize(response)); 64 return xhr('PUT',{ 65 url: '/api/open/responses/' + this.getId(response) + '?' + query, 66 handleAs: 'json', 67 contentType: 'application/json', 68 rawBody: body 69 }).then(lang.hitch(this,'_doDeserialize'),function(err){ 70 return new Deferred().reject(json.fromJson(err.responseText)); 71 }); 72 }, 73 removeWithSecret: function(response,secret) { 74 var query = xhr.objectToQuery({secret:secret}); 75 var rev = this.getRev(response); 76 var body = json.toJson(this._doSerialize(response)); 77 var headers = {}; 78 if ( rev ) { 79 headers['If-Match'] = '"'+rev+'"'; 80 } 81 return xhr('DELETE',{ 82 url: '/api/open/responses/' + this.getId(response) + '?' + query, 83 headers: headers, 84 handleAs: 'json', 85 contentType: 'application/json', 86 rawBody: body 87 }); 14 88 } 15 }; 16 return SurveyRun; 89 }); 90 91 return new Responses(); 92 17 93 }); -
Dev/trunk/src/client/qed-client/model/classes/surveyRuns.js
r486 r487 1 define(['dojo/_base/lang','dojo/date/locale','dojo/date/stamp'],function(lang,locale,stamp){ 2 var SurveyRun = { 3 create: function(){ 4 return { type:'SurveyRun' }; 1 define([ 2 "./_Class", 3 "./surveys", 4 "dojo/_base/declare", 5 "dojo/date/stamp" 6 ], function(_Class, surveys, declare, stamp) { 7 8 var SurveyRuns = declare([_Class],{ 9 _collection: 'surveyRuns', 10 _type: 'SurveyRun', 11 create: function() { 12 var obj = { 13 type: this._type, 14 description: "", 15 mode: "open", 16 survey: null, 17 title: "" 18 }; 19 return obj; 5 20 }, 6 StartDate: { 7 get: function(sr) { 8 var d; 9 if ( sr.startDate ) { 10 d = lang.isString(sr.startDate) ? stamp.fromISOString(sr.startDate) : sr.startDate; 11 } 12 return d; 13 }, 14 set: function(sr,d) { 15 if ( d ) { 16 sr.startDate = lang.isString(d) ? stamp.toISOString(d) : d; 17 } 21 _deserialize: function(obj) { 22 if (obj.endDate) { 23 obj.endDate = stamp.fromISOString(obj.endDate); 24 } 25 if (obj.startDate) { 26 obj.startDate = stamp.fromISOString(obj.startDate); 27 } 28 if (obj.survey) { 29 obj.survey = surveys._doDeserialize(obj.survey); 18 30 } 19 31 }, 20 EndDate: { 21 get: function(sr) { 22 var d; 23 if ( sr.endDate ) { 24 d = lang.isString(sr.endDate) ? stamp.fromISOString(sr.endDate) : sr.endDate; 25 } 26 return d; 27 }, 28 set: function(sr,d) { 29 if ( d ) { 30 sr.endDate = lang.isString(d) ? stamp.toISOString(d) : d; 31 } 32 _serialize: function(obj) { 33 if (obj.endDate) { 34 obj.endDate = stamp.toISOString(obj.endDate); 32 35 } 33 }, 34 DisplayTitle: { 35 get: function(sr) { 36 var t = "Run of '"+sr.survey.title+"'"; 37 if ( sr.startDate ) { 38 t += " from "+locale.format(SurveyRun.StartDate.get(sr)); 39 } 40 if ( sr.endDate ) { 41 t += " until "+locale.format(SurveyRun.EndDate.get(sr)); 42 } 43 return t; 36 if (obj.startDate) { 37 obj.startDate = stamp.toISOString(obj.startDate); 44 38 } 45 }, 46 Survey: { 47 get: function(sr) { 48 return sr.survey || null; 49 }, 50 set: function(sr,s) { 51 sr.survey = s; 52 return sr; 39 if (obj.survey) { 40 obj.survey = surveys._doSerialize(obj.survey); 53 41 } 54 42 } 55 }; 56 return SurveyRun; 43 }); 44 45 return new SurveyRuns(); 46 57 47 }); -
Dev/trunk/src/client/qed-client/model/classes/surveys.js
r486 r487 1 define(function(){ 2 return { 3 create: function(){ 4 return { type:'Survey' }; 1 define([ 2 "./_Class", 3 "dojo/_base/declare", 4 "dojo/date/stamp", 5 "dojo/store/JsonRest" 6 ], function(_Class, declare, stamp, JsonRest) { 7 8 var Surveys = declare([_Class],{ 9 _collection: 'surveys', 10 _type: 'Survey', 11 create: function() { 12 var obj = { 13 type: this._type, 14 questions: [], 15 title: "" 16 }; 17 return obj; 5 18 }, 6 DisplayTitle:{7 get: function(s) {8 return s.title || '';19 _deserialize: function(obj) { 20 if (obj.publicationDate) { 21 obj.publicationDate = stamp.fromISOString(obj.publicationDate); 9 22 } 10 23 }, 11 Questions: { 12 get: function(s) { 13 return s.questions || []; 14 }, 15 set: function(s,questions) { 16 s.questions = questions; 24 _serialize: function(obj) { 25 if (obj.publicationDate) { 26 obj.publicationDate = stamp.toISOString(obj.publicationDate); 17 27 } 18 28 } 19 }; 29 }); 30 31 return new Surveys(); 32 20 33 });
Note: See TracChangeset
for help on using the changeset viewer.