Changeset 487 for Dev/trunk/src/client/qed-client/model
- Timestamp:
- 03/05/14 22:44:48 (11 years ago)
- Location:
- Dev/trunk/src/client/qed-client/model
- Files:
-
- 4 added
- 2 deleted
- 5 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 }); -
Dev/trunk/src/client/qed-client/model/widgets/QuestionEditorToolkit.js
r443 r487 1 1 define([ 2 "../../store", 2 "../classes/categories", 3 "../classes/topics", 3 4 "./CategoryListView", 4 5 "dijit/_Container", … … 15 16 "require", 16 17 "dojo/text!./templates/QuestionEditorToolkit.html" 17 ], function( store, CategoryListView, _Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, Button, ComboBox, declare, lang, Source, domConstruct, Memory, require, template) {18 ], function(categories, topics, CategoryListView, _Container, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, Button, ComboBox, declare, lang, Source, domConstruct, Memory, require, template) { 18 19 return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _Container], { 19 20 … … 107 108 this.inherited(arguments); 108 109 109 store.query("_design/questions/_view/all", {reduce:true, group:false, group_level:1}) 110 .forPairs(lang.hitch(this, function(value, key) { 111 this._categoryStore.put({ id: key[0] }); 110 categories.query().forEach(lang.hitch(this,function(cat){ 111 this._categoryStore.put({ id: cat }); 112 112 })); 113 113 114 store.query("_design/questions/_view/all_topics", {reduce:true, group:true}) 115 .forPairs(lang.hitch(this, function(value, key) { 116 this._topicStore.put({ id: key }); 114 topics.query().forEach(lang.hitch(this,function(topic){ 115 this._categoryStore.put({ id: topic }); 117 116 })); 118 117 }, -
Dev/trunk/src/client/qed-client/model/widgets/SurveyRenderWidget.js
r461 r487 1 1 define([ 2 2 "../../widgets/_ComplexValueWidget", 3 "../classes/Survey",4 3 "./questions/Factory", 5 4 "dojo/_base/array", … … 7 6 "dojo/dom-construct", 8 7 "dojo/text!./templates/SurveyRenderWidget.html" 9 ], function(_ComplexValueWidget, Survey,QuestionWidgetFactory, array, declare, domConstruct, template) {8 ], function(_ComplexValueWidget, QuestionWidgetFactory, array, declare, domConstruct, template) { 10 9 return declare([_ComplexValueWidget],{ 11 10 templateString: template, … … 22 21 this.survey = survey; 23 22 var f = new QuestionWidgetFactory(); 24 array.forEach( Survey.Questions.get(this.survey),function(question,question_index){23 array.forEach(this.survey.questions,function(question,question_index){ 25 24 array.forEach(question.content || [], function(item,item_index){ 26 25 // The dot causes values to be grouped in an object! -
Dev/trunk/src/client/qed-client/model/widgets/SurveySummary.js
r457 r487 1 1 define([ 2 "../../store",3 "../classes/Survey",4 2 "dijit/_TemplatedMixin", 5 3 "dijit/_WidgetBase", … … 7 5 "dojo/dom-attr", 8 6 "dojo/text!./templates/SurveySummary.html" 9 ], function( store, Survey,_TemplatedMixin, _WidgetBase, declare, domAttr, template) {7 ], function(_TemplatedMixin, _WidgetBase, declare, domAttr, template) { 10 8 return declare([_WidgetBase,_TemplatedMixin],{ 11 9 templateString: template, … … 18 16 }, 19 17 _setValueAttr: function(survey) { 20 this.titleNode.innerHTML = Survey.DisplayTitle.get(survey); 21 var id = store.getIdentity(survey); 22 domAttr.set(this.titleNode, "href", id && ("#!/survey/"+id)); 18 this.titleNode.innerHTML = survey.title || ""; 19 domAttr.set(this.titleNode, "href", survey._id && ("#!/survey/"+survey._id)); 23 20 this.descriptionNode.innerHTML = survey.description; 24 this.questionsNode.innerHTML = (survey.questions || []).length;21 this.questionsNode.innerHTML = survey.questions.length; 25 22 } 26 23 }); -
Dev/trunk/src/client/qed-client/model/widgets/TabbedQuestionBrowser.js
r477 r487 1 1 define([ 2 'dojo/_base/declare', 3 'dojo/_base/lang', 4 'dojo/_base/window', 5 'dijit/layout/ContentPane', 6 'dijit/layout/TabContainer', 7 'dojox/widget/Standby', 8 '../../store', 9 '../../widgets/Selector' 10 ],function(declare,lang,win,ContentPane,TabContainer,Standby,store,Selector){ 2 "../../widgets/Selector", 3 "../classes/categories", 4 "../classes/questions", 5 "../classes/topics", 6 "dijit/layout/ContentPane", 7 "dijit/layout/TabContainer", 8 "dojo/_base/declare", 9 "dojo/_base/lang", 10 "dojo/_base/window", 11 "dojox/widget/Standby" 12 ], function(Selector, categories, questions, topics, ContentPane, TabContainer, declare, lang, win, Standby) { 11 13 return declare([TabContainer],{ 12 14 tabPosition: 'left-h', … … 38 40 this._fillCategoryTab(newTab.__category); 39 41 })); 40 store.query(this._query, {reduce:true,group:true,group_level:1})41 .for Pairs(lang.hitch(this,function(value,key){42 this._createCategoryTab( key[0],value);42 categories.query() 43 .forEach(lang.hitch(this,function(cat){ 44 this._createCategoryTab(cat.name,cat.count); 43 45 })); 44 46 }, … … 61 63 this._busy(); 62 64 categoryMap._filled = true; 63 store.query(this._query, {reduce:true,group:true,group_level:2,startkey:[category],endkey:[category,{}]})64 .for Pairs(lang.hitch(this,function(value,key){65 this._createTopicSelector( key[1],category,value);65 topics.query({category:category}) 66 .forEach(lang.hitch(this,function(topic){ 67 this._createTopicSelector(topic.name,category,topic.count); 66 68 })).then(lang.hitch(this,function(){ 67 69 this._done(); … … 101 103 topicMap._filled = true; 102 104 this._busy(); 103 store.query(this._query, { 104 reduce:false, 105 include_docs:true, 106 key:[category,topic] 107 }).forEach(lang.hitch(this,function(value){ 105 questions.query({category:category,topic:topic}) 106 .forEach(lang.hitch(this,function(value){ 108 107 topicMap._widget.addItem(value); 109 108 })).then(lang.hitch(this,function(){
Note: See TracChangeset
for help on using the changeset viewer.