Changeset 487 for Dev/trunk/src/client
- Timestamp:
- 03/05/14 22:44:48 (11 years ago)
- Location:
- Dev/trunk/src/client/qed-client
- Files:
-
- 5 added
- 3 deleted
- 20 edited
- 5 moved
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/src/client/qed-client/app/Router.js
r457 r487 78 78 route.callback(params); 79 79 } catch(err) { 80 console.error("Page change failed with",err .toString());80 console.error("Page change failed with",err,err.toString()); 81 81 } 82 82 return; -
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(){ -
Dev/trunk/src/client/qed-client/pages/previewSurvey.js
r443 r487 1 1 define([ 2 2 "../app/Page", 3 "../ store",3 "../model/classes/surveys", 4 4 "dojo/_base/array", 5 5 "dojo/_base/declare", … … 8 8 "require", 9 9 "dojo/text!./templates/previewSurvey.html" 10 ], function(Page, s tore, array, declare, lang, when, require, template) {10 ], function(Page, surveys, array, declare, lang, when, require, template) { 11 11 return declare([Page],{ 12 12 contextRequire: require, … … 16 16 this.inherited(arguments); 17 17 if ( this.surveyId ) { 18 when(s tore.get(this.surveyId))18 when(surveys.load(this.surveyId)) 19 19 .then(lang.hitch(this,function(survey){ 20 this.titleNode.innerHTML = survey.title ;20 this.titleNode.innerHTML = survey.title || ""; 21 21 this.surveyWidget.set('survey',survey); 22 22 })); -
Dev/trunk/src/client/qed-client/pages/question.js
r443 r487 3 3 "../app/Page", 4 4 "../app/Router", 5 "../model/classes/ Question",5 "../model/classes/questions", 6 6 "../model/widgets/QuestionEditorPreview", 7 7 "../model/widgets/QuestionEditorToolkit", 8 "../store",9 8 "../widgets/_ComplexValueMixin", 10 9 "dojo/_base/declare", … … 13 12 "dojo/when", 14 13 "dojo/text!./templates/question.html" 15 ], function(Content, Page, Router, Question, QuestionEditorPreview, QuestionEditorToolkit, store, _ComplexValueMixin, declare, event, lang, when, template) {14 ], function(Content, Page, Router, questions, QuestionEditorPreview, QuestionEditorToolkit, _ComplexValueMixin, declare, event, lang, when, template) { 16 15 return declare([Page,_ComplexValueMixin], { 17 16 templateString: template, … … 43 42 } 44 43 if (this.questionId === "new") { 45 this.set('value', Question.create());44 this.set('value', questions.create()); 46 45 } else { 47 when( store.get(this.questionId))46 when(questions.load(this.questionId)) 48 47 .then(lang.hitch(this, function(value) { 49 48 this.set('value', value); … … 54 53 this.value = value; 55 54 this.inherited(arguments); 56 this.titleNode.innerHTML = Question.DisplayTitle.get(value);55 this.titleNode.innerHTML = value.title || ""; 57 56 }, 58 57 _getValueAttr: function() { … … 63 62 _onSave: function(evt) { 64 63 if ( this.validate() ) { 65 var value = this.get('value'); 66 store.put(value) 64 questions.save(this.get('value')) 67 65 .then(function() { 68 66 Router.go('/questions'); -
Dev/trunk/src/client/qed-client/pages/questions.js
r443 r487 1 1 define([ 2 'dojo/_base/declare',3 'dojo/_base/Deferred',4 'dojo/_base/event',5 'dojo/_base/lang',6 '../store',7 '../app/Content',8 '../app/Router',9 '../app/Page',10 '../model/widgets/TabbedQuestionBrowser',11 'dojo/text!./templates/questions.html'12 ], function(declare,Deferred,event,lang,store,Content,Router,Page,TabbedQuestionBrowser,template) {2 "../app/Content", 3 "../app/Page", 4 "../app/Router", 5 "../model/classes/questions", 6 "../model/widgets/TabbedQuestionBrowser", 7 "dojo/_base/Deferred", 8 "dojo/_base/declare", 9 "dojo/_base/event", 10 "dojo/_base/lang", 11 "dojo/text!./templates/questions.html" 12 ], function(Content, Page, Router, questions, TabbedQuestionBrowser, Deferred, declare, event, lang, template) { 13 13 return declare([Page],{ 14 14 templateString: template, … … 44 44 }, 45 45 onDeleteQuestion: function(question) { 46 store.remove(store.getIdentity(question),store.getRevision(question))46 questions.remove(question) 47 47 .then(function(){ 48 48 Content.notify("Question deleted."); … … 55 55 }, 56 56 onPublishQuestion: function(question) { 57 question.publicationDate = store.timestamp();58 store.put(question)57 question.publicationDate = new Date(); 58 questions.save(question) 59 59 .then(function(){ 60 60 Content.notify("Question published."); -
Dev/trunk/src/client/qed-client/pages/response.js
r478 r487 3 3 "../app/Page", 4 4 "../lib/async", 5 "../model/classes/Response", 6 "../model/classes/Survey", 7 "../model/classes/SurveyRun", 8 "../store", 5 "../model/classes/responses", 9 6 "dojo/_base/declare", 10 7 "dojo/_base/event", … … 16 13 "require", 17 14 "dojo/text!./templates/response.html" 18 ], function(Content, Page, async, Response, Survey, SurveyRun, store, declare, event, json, lang, all, request, when, require, template) {15 ], function(Content, Page, async, responses, declare, event, json, lang, all, request, when, require, template) { 19 16 return declare([Page],{ 20 17 contextRequire: require, … … 28 25 this.inherited(arguments); 29 26 this._disableSubmit(); 30 var surveyRunId = this.surveyRunId; 31 var responseId = this.options && this.options.id; 32 if ( surveyRunId && responseId ) { 33 this._loadSurveyAndResponse(surveyRunId,responseId) 34 .then(lang.hitch(this, function() { 35 if ( this.response.publicationDate ) { 36 this._showInfo("<div>You already submitted your survey and cannot change it anymore. You can still view your answers here.</div>"); 37 this._disableSubmit(); 38 } else { 39 this._enableSubmit(); 40 } 41 }), lang.hitch(this,function() { 42 this._showInfo("<div>The url seems to be incorrect, no survey found.</div>"); 43 })); 27 if ( !this.response ) { 28 this._showInfo("<div>The url seems to be incorrect, no response found.</div>"); 44 29 } else { 45 throw new Error("No valid uid or survey passed!"); 30 this.titleNode.innerHTML = this.response._surveyRun.survey.title || ""; 31 this.surveyWidget.set('survey', this.response._surveyRun.survey); 32 this.surveyWidget.set('value', this.response.answers || {}); 33 if ( this.response.publicationDate ) { 34 this._showInfo("<div>You already submitted your survey and cannot change it anymore. You can still view your answers here.</div>"); 35 this._disableSubmit(); 36 } else { 37 this._enableSubmit(); 38 } 46 39 } 47 },48 _loadSurveyAndResponse: function(surveyRunId,responseId){49 return all([request.get('/api/surveyRuns/'+surveyRunId,{handleAs:'json'}),50 request.get('/api/responses/'+responseId,{handleAs:'json'})])51 .then(lang.hitch(this,function(surveyAndResponse){52 var surveyRun = surveyAndResponse[0];53 this.response = surveyAndResponse[1];54 if ( this.response.surveyRunId !== surveyRunId ) {55 throw "Survey does not match the response...";56 }57 this.titleNode.innerHTML = Survey.DisplayTitle.get(surveyRun.survey);58 this.surveyWidget.set('survey', surveyRun.survey);59 this.surveyWidget.set('value', this.response.answers || {});60 }));61 40 }, 62 41 _enableSubmit: function() { … … 78 57 var answers = this.surveyWidget.get('value'); 79 58 this.response.answers = answers; 80 return request.put('/api/responses/'+store.getIdentity(this.response),{ 81 handleAs:'json', 82 data:json.toJson(this.response), 83 headers:{"Content-Type": "application/json"} 84 }).then(lang.hitch(this,function(res){ 85 this.response._rev = res.rev; 59 return responses.putWithSecret(this.response,this.response.secret) 60 .then(lang.hitch(this,function(response){ 61 this.response = response; 86 62 Content.notify("Your response is saved."); 87 63 }), function(err){ … … 90 66 }, 91 67 _onSubmit: function(e) { 92 this.response.publicationDate = store.timestamp();68 this.response.publicationDate = new Date(); 93 69 this._getAnswersAndSaveResponse() 94 70 .then(lang.hitch(this,function(){ … … 110 86 this._disableSubmit(); 111 87 this.surveyWidget.destroy(); 112 request('/api/responses/'+store.getIdentity(this.response)+'?rev='+store.getRevision(this.response),{ 113 method: 'DELETE', 114 handleAs:'json', 115 data:json.toJson(this.response), 116 headers:{"Content-Type": "application/json"} 117 }).then(lang.hitch(this,function(res){ 88 responses.removeWithSecret(this.response,this.response.secret) 89 .then(lang.hitch(this,function(res){ 118 90 this._showInfo("<div>Your response has been deleted, no answers have been saved.</div>"); 119 91 Content.notify("Your response is deleted."); -
Dev/trunk/src/client/qed-client/pages/session.js
r443 r487 1 1 define([ 2 'dojo/_base/array',2 /*'dojo/_base/array', 3 3 'dojo/_base/declare', 4 4 'dojo/_base/event', … … 12 12 '../model/classes/SessionTemplate', 13 13 '../model/widgets/AccountListView', 14 'dojo/text!./templates/session.html' 14 'dojo/text!./templates/session.html'*/ 15 15 ],function(array,declare,event,lang,when,search,store,Page,Router,ThresholdFilteringSelect,SessionTemplate,AccountListView,template){ 16 return declare([Page],{16 /*return declare([Page],{ 17 17 templateString: template, 18 18 session: null, … … 92 92 93 93 94 }); 94 });*/ 95 95 }); 96 96 -
Dev/trunk/src/client/qed-client/pages/sessions.js
r443 r487 1 1 define([ 2 'dojo/_base/declare',2 /*'dojo/_base/declare', 3 3 'dojo/_base/lang', 4 4 'dojo/date/stamp', … … 7 7 '../app/Page', 8 8 '../widgets/ObjectBox', 9 'dojo/text!./templates/sessions.html' 9 'dojo/text!./templates/sessions.html'*/ 10 10 ],function(declare,lang,dateStamp,store,Router,Page,ObjectBox,template){ 11 return declare([Page],{11 /*return declare([Page],{ 12 12 templateString: template, 13 13 templateActions: null, … … 18 18 this.templateActions = { 19 19 "Edit": function(obj){ 20 Router.go('/session/'+ store.getIdentity(obj));20 Router.go('/session/'+obj.get('id')); 21 21 }, 22 22 "Delete": lang.hitch(this,function(obj){ 23 store.remove(store.getIdentity(obj),store.getRevision(obj))23 obj.remove() 24 24 .then(lang.hitch(this,function(){ 25 25 this._refresh(); … … 30 30 this.sessionActions = { 31 31 "Facilitate": function(obj){ 32 Router.go('run',{uid: store.getIdentity(obj)});32 Router.go('run',{uid: obj.get('id')}); 33 33 }, 34 34 "Delete": lang.hitch(this,function(obj){ 35 store.remove(store.getIdentity(obj),store.getRevision(obj))35 obj.remove() 36 36 .then(lang.hitch(this,function(){ 37 37 this._refresh(); … … 48 48 }, 49 49 _refreshByType: function(type,container,actions) { 50 // FIXME 50 51 store.query("_design/default/_view/by_type",{key:type}) 51 52 .forEach(lang.hitch(this,function(obj){ … … 61 62 }, 62 63 _publishSession: function(sessionTemplate) { 64 // FIXME 63 65 var session = lang.clone(sessionTemplate); 64 66 delete session[store.idProperty]; … … 73 75 })); 74 76 } 75 }); 77 });*/ 76 78 }); -
Dev/trunk/src/client/qed-client/pages/survey.js
r443 r487 2 2 "../app/Page", 3 3 "../app/Router", 4 "../model/classes/ Survey",4 "../model/classes/surveys", 5 5 "../model/widgets/QuestionListView", 6 6 "../model/widgets/TabbedQuestionBrowser", 7 "../store",8 7 "dojo/_base/array", 9 8 "dojo/_base/declare", … … 13 12 "require", 14 13 "dojo/text!./templates/survey.html" 15 ], function(Page, Router, Survey, QuestionListView, TabbedQuestionBrowser, store, array, declare, event, lang, when, require, template) {14 ], function(Page, Router, surveys, QuestionListView, TabbedQuestionBrowser, array, declare, event, lang, when, require, template) { 16 15 return declare([Page],{ 17 16 contextRequire: require, … … 63 62 _loadSurvey: function() { 64 63 if ( this.surveyId === "new" ) { 65 this.survey = Survey.create();64 this.survey = surveys.create(); 66 65 this.refresh(); 67 66 } else { 68 when(s tore.get(this.surveyId))67 when(surveys.load(this.surveyId)) 69 68 .then(lang.hitch(this,function(survey){ 70 69 this.survey = survey; 71 70 this.questionList.set('value', 72 Survey.Questions.get(this.survey));71 this.survey.questions); 73 72 this.refresh(); 74 73 })); … … 79 78 }, 80 79 refresh: function() { 81 this.titleNode.innerHTML = Survey.DisplayTitle.get(this.survey)|| "(set title in properties)";80 this.titleNode.innerHTML = this.survey.title || "(set title in properties)"; 82 81 this.propertiesDialog.set('value',this.survey); 83 82 }, … … 100 99 _onSave: function(evt) { 101 100 this.survey.questions = this.questionList.get('value'); 102 s tore.put(this.survey)101 surveys.save(this.survey) 103 102 .then(function() { 104 103 Router.go('/surveys'); … … 111 110 }, 112 111 _onShowPreview: function() { 113 Router.go('/previewSurvey/'+ store.getIdentity(this.survey),{112 Router.go('/previewSurvey/'+this.survey._id,{ 114 113 preview: true 115 114 }); -
Dev/trunk/src/client/qed-client/pages/surveyRun.js
r466 r487 4 4 "../app/Router", 5 5 "../lib/func", 6 "../model/classes/ SurveyRun",7 "../ store",6 "../model/classes/responses", 7 "../model/classes/surveyRuns", 8 8 "../widgets/LineWithActionsWidget", 9 "dojo/_base/array", 9 10 "dojo/_base/declare", 10 11 "dojo/_base/event", … … 13 14 "require", 14 15 "dojo/text!./templates/surveyRun.html" 15 ], function(Content, Page, Router, func, SurveyRun, store, LineWithActionsWidget, declare, event, lang, when, require, template) {16 ], function(Content, Page, Router, func, responses, surveyRuns, LineWithActionsWidget, array, declare, event, lang, when, require, template) { 16 17 return declare([Page],{ 17 18 contextRequire: require, … … 24 25 if ( this.surveyRunId ) { 25 26 this._loadSurveyRun(); 26 this._loadResponses();27 27 } else { 28 28 throw "No valid uid or survey passed!"; … … 30 30 }, 31 31 _loadSurveyRun: function() { 32 when(s tore.get(this.surveyRunId))32 when(surveyRuns.load(this.surveyRunId)) 33 33 .then(lang.hitch(this,function(surveyRun){ 34 34 this.surveyRun = surveyRun; 35 35 this.refreshSurveyRun(); 36 this._loadResponses(); 36 37 })); 37 38 }, 38 39 refreshSurveyRun: function() { 39 this.titleNode.innerHTML = SurveyRun.DisplayTitle.get(this.surveyRun);40 this.surveySummaryWidget.set('value', SurveyRun.Survey.get(this.surveyRun));40 this.titleNode.innerHTML = this.surveyRun.title || ""; 41 this.surveySummaryWidget.set('value',this.surveyRun.survey); 41 42 this.surveyRunWidget.set('value',this.surveyRun); 42 43 this._onPropChange(); 43 44 }, 44 45 _loadResponses: function() { 45 when(store.query("_design/responses/_view/by_surveyrun",{key:this.surveyRunId})) 46 .forEach(lang.hitch(this,function(response){ 47 var actions = { 48 view: { 49 callback: function(){}, 50 properties: { 51 title: "View response" 52 } 53 } 54 }; 55 if ( !response.publicationDate ) { 56 actions.remove = { 57 callback: function(){}, 58 properties: { 59 title: "Remove response" 46 responses.query({surveyRunId:surveyRuns.getId(this.surveyRun)}) 47 .then(lang.hitch(this,function(allResponses){ 48 array.forEach(allResponses, function(response){ 49 var actions = { 50 view: { 51 callback: function(){}, 52 properties: { 53 title: "View response" 54 } 60 55 } 61 56 }; 62 } 63 var w = new LineWithActionsWidget({ 64 actions: actions 65 }); 66 var responseId = store.getIdentity(response); 67 w.set('title',this._link(this._getResponseURL(this.surveyRunId,responseId),responseId)); 68 w.placeAt(this.responsesNode); 57 if ( !response.publicationDate ) { 58 actions.remove = { 59 callback: function(){}, 60 properties: { 61 title: "Remove response" 62 } 63 }; 64 } 65 var w = new LineWithActionsWidget({ 66 actions: actions 67 }); 68 var rid = responses.getId(response); 69 w.set('title',this._link(this._buildResponseURL(response),rid),rid); 70 w.placeAt(this.responsesNode); 71 }, this); 69 72 })); 70 73 }, … … 73 76 if ( surveyRun.mode === "open" ) { 74 77 this.runURLNode.innerHTML = 75 this._link(this._ getGeneralURL(store.getIdentity(this.surveyRun)));78 this._link(this._buildGeneralURL(this.surveyRun)); 76 79 } else { 77 80 this.runURLNode.innerHTML = … … 79 82 } 80 83 }, 81 _ getGeneralURL: function(surveyRunId) {82 return 'response.html#!/ '+surveyRunId;84 _buildGeneralURL: function(surveyRun) { 85 return 'response.html#!/surveyRuns/'+surveyRuns.getId(surveyRun)+'!secret='+surveyRun.secret; 83 86 }, 84 _ getResponseURL: function(surveyRunId,responseId) {85 return 'response.html#!/ '+surveyRunId+'!id='+responseId;87 _buildResponseURL: function(response) { 88 return 'response.html#!/responses/'+responses.getId(response)+'!secret='+response.secret; 86 89 }, 87 90 _link: function(url,label) { … … 92 95 lang.mixin(this.surveyRun,this.surveyRunWidget.get('value')); 93 96 94 var SD = SurveyRun.StartDate; 95 var ED = SurveyRun.EndDate; 96 SD.set(this.surveyRun, SD.get(this.surveyRun)); 97 ED.set(this.surveyRun, ED.get(this.surveyRun)); 98 99 store.put(this.surveyRun) 97 surveyRuns.save(this.surveyRun) 100 98 .then(function() { 101 99 Router.go('/surveys'); -
Dev/trunk/src/client/qed-client/pages/surveys.js
r443 r487 1 1 define([ 2 'dojo/_base/array', 3 'dojo/_base/declare', 4 'dojo/_base/lang', 5 'dojo/when', 6 '../store', 7 '../app/Content', 8 '../app/Page', 9 '../app/Router', 10 '../model/classes/Survey', 11 '../model/classes/SurveyRun', 12 '../widgets/LineWithActionsWidget', 13 'dojo/text!./templates/surveys.html' 14 ],function(array,declare,lang,when,store,Content,Page,Router,Survey,SurveyRun,LineWithActionsWidget,template){ 2 "../app/Content", 3 "../app/Page", 4 "../app/Router", 5 "../model/classes/surveys", 6 "../model/classes/surveyRuns", 7 "../widgets/LineWithActionsWidget", 8 "dojo/_base/array", 9 "dojo/_base/declare", 10 "dojo/_base/lang", 11 "dojo/when", 12 "dojo/text!./templates/surveys.html" 13 ], function(Content, Page, Router, surveys, surveyRuns, LineWithActionsWidget, array, declare, lang, when, template) { 15 14 return declare([Page],{ 16 15 templateString: template, … … 25 24 _onPublishSurvey:function(survey){ 26 25 var self = this; 27 survey.publicationDate = store.timestamp(); 28 store.put(survey).then(function(){ 26 survey.publicationDate = new Date(); 27 surveys.save(survey) 28 .then(function(){ 29 29 self.refreshDrafts(); 30 30 self.refreshPublished(); … … 35 35 _onDeleteSurvey:function(survey){ 36 36 var self = this; 37 s tore.remove(store.getIdentity(survey),store.getRevision(survey))37 surveys.remove(survey) 38 38 .then(function(){ 39 39 self.refreshDrafts(); … … 43 43 }, 44 44 _onEditSurvey:function(survey){ 45 Router.go('/survey/'+s tore.getIdentity(survey));45 Router.go('/survey/'+survey._id); 46 46 }, 47 47 _onPreviewSurvey:function(survey){ 48 Router.go('/previewSurvey/'+s tore.getIdentity(survey));48 Router.go('/previewSurvey/'+survey._id); 49 49 }, 50 50 _onRunSurvey:function(survey){ 51 var surveyRun = SurveyRun.create();52 SurveyRun.Survey.set(surveyRun,survey);53 s tore.put(surveyRun)51 var surveyRun = surveyRuns.create(); 52 surveyRun.survey = survey; 53 surveyRuns.save(surveyRun) 54 54 .then(lang.hitch(this,function(surveyRun){ 55 55 this._onRunDetails(surveyRun); … … 59 59 }, 60 60 _onRunDetails: function(surveyRun) { 61 Router.go('/surveyRun/'+s tore.getIdentity(surveyRun));61 Router.go('/surveyRun/'+surveyRun._id); 62 62 }, 63 63 refresh: function() { … … 68 68 refreshDrafts: function() { 69 69 this.draftsContainer.set('content',''); 70 when(store.query("_design/surveys/_view/drafts"), 71 lang.hitch(this,function(surveys) { 70 when(surveys.query({drafts:true}), lang.hitch(this,function(surveys) { 72 71 this.draftsTab.set('title','Drafts ('+surveys.length+')'); 73 72 array.forEach(surveys,function(survey){ 74 73 var w = new LineWithActionsWidget({ 75 title: Survey.DisplayTitle.get(survey)|| '(unnamed)',74 title: survey.title || '(unnamed)', 76 75 actions: [{ 77 76 callback: lang.hitch(this,'_onPublishSurvey',survey), … … 110 109 refreshPublished: function() { 111 110 this.publishedContainer.set('content',''); 112 when(store.query("_design/surveys/_view/published"), 113 lang.hitch(this, function(surveys) { 111 when(surveys.query({published:true}), lang.hitch(this, function(surveys) { 114 112 this.publishedTab.set('title','Published ('+surveys.length+')'); 115 113 array.forEach(surveys,function(survey){ 116 114 var w = new LineWithActionsWidget({ 117 title: Survey.DisplayTitle.get(survey),115 title: survey.title || "", 118 116 actions:[{ 119 117 callback: lang.hitch(this,'_onPreviewSurvey',survey), … … 138 136 refreshRuns: function() { 139 137 this.runsContainer.set('content',''); 140 when(store.query("_design/default/_view/by_type",{key:'SurveyRun'}), 141 lang.hitch(this,function(surveyRuns){ 138 when(surveyRuns.query(), lang.hitch(this,function(surveyRuns){ 142 139 this.runsTab.set('title','Runs ('+surveyRuns.length+')'); 143 140 array.forEach(surveyRuns,function(surveyRun){ 144 141 var w = new LineWithActionsWidget({ 145 title: SurveyRun.DisplayTitle.get(surveyRun),142 title: surveyRun.title || "", 146 143 actions:[{ 147 144 callback: lang.hitch(this,'_onRunDetails',surveyRun), -
Dev/trunk/src/client/qed-client/response.js
r477 r487 4 4 "./app/Path", 5 5 "./lib/async", 6 "./model/classes/ Response",7 "./model/classes/ SurveyRun",6 "./model/classes/responses", 7 "./model/classes/surveyRuns", 8 8 "./pages/response", 9 "./store",10 9 "dojo/_base/json", 11 10 "dojo/date", … … 16 15 "./stddeps", 17 16 "dojo/domReady!" 18 ], function(Content, Page, Path, async, Response, SurveyRun, ResponsePage, store, json, date, locale, hash, parser, request) {17 ], function(Content, Page, Path, async, responses, surveyRuns, ResponsePage, json, date, locale, hash, parser, request) { 19 18 parser.parse(); 20 19 Content.startup(); … … 26 25 } 27 26 28 var path = new Path('/: surveyRunId');27 var path = new Path('/:type/:id'); 29 28 var params = path.match(hash()); 30 29 params.options = params.options || {}; 31 32 if ( !params || !params.surveyRunId ) { 30 31 if ( params && params.type === 'surveyRuns' ) { 32 var response = responses.create(); 33 response.surveyRunId = params.id; 34 responses.postWithSecret(response,params.options.secret) 35 .then(setContent,function(err){ error(err.error); }); 36 } else if ( params && params.type === 'responses' ) { 37 responses.getWithSecret(params.id,params.options.secret) 38 .then(setContent,function(err){ error(err.error); }); 39 } else { 33 40 error("Something is wrong with the URL, don't know what survey to show you. Sorry."); 34 return;35 41 } 36 42 37 var surveyRunId = params.surveyRunId; 38 39 function checkDates(surveyRun) { 40 var now = new Date(); 41 var startDate = SurveyRun.StartDate.get(surveyRun); 42 var endDate = SurveyRun.EndDate.get(surveyRun); 43 if ( startDate && date.compare(startDate,now) > 0 ) { 44 error("This survey will start on "+locale.format(startDate,'date')); 45 throw false; 46 } 47 if ( endDate && date.compare(now,endDate) > 0 ) { 48 error("This survey ended on "+locale.format(endDate,'date')); 49 throw false; 50 } 43 function setContent(response) { 44 hash(Path.format("/responses/"+responses.getId(response), 45 {secret:response.secret})); 46 Content.set(new ResponsePage({ 47 response: response 48 })); 51 49 } 52 50 53 request.get('/api/surveyRuns/'+surveyRunId,{handleAs:'json'})54 .then(function(surveyRun){55 checkDates(surveyRun);56 if ( params.options.id ) {57 return params.options.id;58 } else {59 if ( surveyRun.mode === "open") {60 var response = Response.create();61 response.surveyRunId = surveyRunId;62 return request.post('/api/responses',{63 handleAs:'json',64 data:json.toJson(response),65 headers:{"Content-Type": "application/json"}66 }).then(function(res){67 return res.id;68 });69 } else {70 error("Cannot respond to closed survey without response id. Sorry.");71 throw false;72 }73 }74 return surveyRun;75 },function(){76 error("No running survey found for the given id. Sorry.");77 throw false;78 })79 .then(function(responseId){80 hash(Path.format("/"+surveyRunId,{ id: responseId }));81 Content.set(new ResponsePage({82 surveyRunId: surveyRunId,83 options: {84 id: responseId85 }86 }));87 });88 51 }); -
Dev/trunk/src/client/qed-client/routes.js
r443 r487 1 1 define([ 2 './pages/index', 3 './pages/questions', 4 './pages/question', 5 './pages/surveys', 6 './pages/survey', 7 './pages/surveyRun', 8 './pages/sessions', 9 './pages/session', 10 './pages/previewSurvey' 11 ],function(index,questions,question,surveys,survey,surveyRun,sessions,session,previewSurvey){ 2 "./pages/index", 3 "./pages/previewSurvey", 4 "./pages/question", 5 "./pages/questions", 6 "./pages/survey", 7 "./pages/surveyRun", 8 "./pages/surveys" 9 ], function(index, previewSurvey, question, questions, survey, surveyRun, surveys) { 12 10 13 11 return [ -
Dev/trunk/src/client/qed-client/session.coffee
r468 r487 2 2 "dojo/_base/declare", 3 3 "dojo/_base/json", 4 "dojo/Deferred", 4 5 "dojo/Evented", 5 6 "dojo/request" 6 ], (declare, json, Evented, request) ->7 ], (declare, json, Deferred, Evented, request) -> 7 8 Session = declare [Evented], 8 9 info: null … … 18 19 @_set res 19 20 , () => 20 throw(@_set null)21 new Deferred().reject (@_set null) 21 22 22 23 login: (username, password) -> … … 30 31 @_set res 31 32 , () => 32 throw(@_set null)33 new Deferred().reject (@_set null) 33 34 34 35 logout: () -> … … 45 46 @info = newInfo 46 47 @emit 'change', @info 47 48 @info 48 49 49 50 new Session() -
Dev/trunk/src/client/qed-client/stddeps.js
r468 r487 1 1 define([ 2 2 3 // dijit & rft widgets used declaratively in templates 3 4 'dijit/Dialog', … … 43 44 './widgets/Selector', 44 45 './widgets/TitleGroup' 46 45 47 ],function(){}); -
Dev/trunk/src/client/qed-client/ui/LoginDialogWrapper.coffee
r468 r487 17 17 if @_started then return 18 18 @inherited arguments 19 _on session, 'change', (lang.hitch @, @onUserChange)19 _on session, 'change', (lang.hitch @, 'onUserChange') 20 20 @onUserChange session.get() 21 21 onLogin: (evt) -> … … 35 35 else 36 36 @loginDialog.show() 37 null -
Dev/trunk/src/client/qed-client/xhr.js
r486 r487 2 2 "./session", 3 3 "dojo/Deferred", 4 "dojo/_base/lang", 4 5 "dojo/on", 5 "dojo/ request"6 ], function(session, Deferred, on, request) {6 "dojo/_base/xhr" 7 ], function(session, Deferred, lang, on, xhr) { 7 8 8 9 var user = session.get(); 9 10 var queue = []; 10 11 11 on(session, 'change', function(newUser) 12 on(session, 'change', function(newUser){ 12 13 user = newUser; 13 if ( user ) { 14 retry(); 15 } 14 retry(); 16 15 }); 17 16 18 17 function retry() { 19 if ( queue.length > 0) {18 if (user && queue.length > 0) { 20 19 var item = queue.shift(); 21 console.log("Retry",item. url);20 console.log("Retry",item.options.url); 22 21 real_request(item); 23 22 } … … 25 24 26 25 function real_request(item) { 27 var req = request(item.url,item.options); 26 var req = xhr(item.method,lang.mixin(item.options||{},{ 27 failOk: true 28 })); 29 item.promise.ioArgs = req.ioArgs; 28 30 29 // forward successfull response 30 req.then(function(body){ 31 item.dfd.resolve(body); 32 }); 33 34 // handle unauthenticated and queued requests 35 req.response.then(function(response){ 31 req.then(function(result){ 32 item.dfd.resolve(result); 36 33 retry(); 37 }, function(error) 34 }, function(error){ 38 35 if ( error.response.status === 401 ) { 39 36 queue.unshift(item); 40 37 session.restore(); 41 38 } else { 42 item.dfd.reject(error); // this should be error body 43 // not, the request? 39 item.dfd.reject(error); 44 40 retry(); 45 41 } … … 47 43 } 48 44 49 var _request = function( url, options) {45 var _request = function(method, options) { 50 46 var item = { 51 url: url,47 method: method, 52 48 options: options, 53 49 dfd: new Deferred() 54 50 }; 51 item.promise = lang.delegate(item.dfd.promise); 55 52 // only do the request directly if we are authenticated and 56 53 // there are no earlier requests queued. 57 54 if ( user && queue.length === 0 ) { 58 console.log("Request", url);55 console.log("Request",options.url); 59 56 real_request(item); 60 57 } else { 61 console.log("Push", url);58 console.log("Push",options.url); 62 59 queue.push(item); 63 60 } 64 return item. dfd.promise;61 return item.promise; 65 62 }; 66 63
Note: See TracChangeset
for help on using the changeset viewer.