Changeset 487 for Dev/trunk/src/client/qed-client/pages
- Timestamp:
- 03/05/14 22:44:48 (11 years ago)
- Location:
- Dev/trunk/src/client/qed-client/pages
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
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),
Note: See TracChangeset
for help on using the changeset viewer.