Changeset 420 for Dev/branches/rest-dojo-ui/client/qed/pages
- Timestamp:
- 12/16/12 20:07:35 (12 years ago)
- Location:
- Dev/branches/rest-dojo-ui/client/qed/pages
- Files:
-
- 3 added
- 5 edited
- 1 copied
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/rest-dojo-ui/client/qed/pages/previewSurvey.js
r418 r420 2 2 'dojo/_base/array', 3 3 'dojo/_base/declare', 4 'dojo/_base/Deferred',5 'dojo/_base/event',6 4 'dojo/_base/lang', 5 'dojo/when', 7 6 '../store', 8 7 '../app/Page', 9 '../model/widgets/QuestionWidgetFactory', 10 'dojo/text!./templates/viewSurvey.html' 11 ],function(array,declare,Deferred,event,lang,store,Page,QuestionWidgetFactory,template){ 8 'dojo/text!./templates/previewSurvey.html' 9 ],function(array,declare,lang,when,store,Page,template){ 12 10 return declare([Page],{ 13 11 templateString: template, 14 survey: null,15 surveyId: "",16 options: null,17 constructor: function(){18 this._dataMap = {};19 this.options = this.options || {};20 },21 12 startup: function() { 22 13 if ( this._started ) { return; } 23 14 this.inherited(arguments); 24 25 26 15 if ( this.surveyId ) { 27 Deferred.when(store.get(this.surveyId))16 when(store.get(this.surveyId)) 28 17 .then(lang.hitch(this,function(survey){ 29 if ( !survey.published ) { 30 this.options.preview = true; 31 } 32 if ( this.options.preview ) { 33 this.buttonsPane.destroyRecursive(); 34 } 35 this.titleNode.innerHTML = survey.title + 36 (this.options.preview?' [preview]':''); 37 var f = new QuestionWidgetFactory(); 38 this.survey = survey; 39 store.query(null,{keys:this.survey.questions,include_docs:true}) 40 .forEach(function(question){ 41 array.forEach(question.content || [],function(item){ 42 var w = f.createViewWidget(item,{ 43 name: question.code+'.'+item.code 44 }); 45 if ( w !== null ) { 46 w.placeAt(this.questionsAnchor,'before'); 47 } 48 },this); 49 },this); 18 this.titleNode.innerHTML = survey.title; 19 this.surveyWidget.set('survey',survey); 50 20 })); 51 21 } else { 52 22 throw new Error("No valid uid or survey passed!"); 53 23 } 54 },55 _onSubmit: function(evt) {56 if ( this.options.preview ) { return; }57 var value = this.questionsForm.get('value');58 this.questionsPane.set('content','<pre>'+JSON.stringify(value)+'</pre>');59 event.stop(evt);60 return false;61 },62 _onCancel: function(evt) {63 if ( this.options.preview ) { return; }64 event.stop(evt);65 return false;66 24 } 67 25 }); -
Dev/branches/rest-dojo-ui/client/qed/pages/question.js
r418 r420 1 1 define([ 2 2 'dojo/_base/declare', 3 'dojo/_base/Deferred',4 3 'dojo/_base/event', 5 4 'dojo/_base/lang', 5 'dojo/when', 6 6 '../store', 7 7 '../app/Content', 8 8 '../app/Router', 9 9 '../app/Page', 10 '../model/classes/Question', 10 11 '../model/widgets/QuestionEditorPreview', 11 12 '../model/widgets/QuestionEditorToolkit', 12 13 'dojo/text!./templates/question.html' 13 ],function(declare, Deferred, event, lang, store, Content, Router, Page, QuestionEditorPreview, QuestionEditorToolkit, template){14 ],function(declare, event, lang, when, store, Content, Router, Page, Question, QuestionEditorPreview, QuestionEditorToolkit, template){ 14 15 return declare([Page], { 15 16 templateString: template, … … 26 27 this._setupEditor(); 27 28 if (this.questionId === "new") { 28 this.question = { type: 'Question' };29 this.question = Question.create(); 29 30 this._refresh(); 30 31 } else { 31 Deferred.when(store.get(this.questionId))32 when(store.get(this.questionId)) 32 33 .then(lang.hitch(this, function(obj) { 33 34 this.question = obj; … … 40 41 }, 41 42 _refresh: function () { 42 this.titleNode.innerHTML = this.question.title || "";43 this.titleNode.innerHTML = Question.DisplayTitle.get(this.question); 43 44 this._toolkit.set('value',this.question); 44 this._preview.appendItems( this.question.content || []);45 this._preview.appendItems(Question.Content.get(this.question)); 45 46 }, 46 47 _onSave: function(evt) { 47 48 lang.mixin(this.question, this._toolkit.get('value')); 48 this.question.content = this._preview.getItems();49 Question.Content.set(this.question, this._preview.getItems()); 49 50 store.put(this.question) 50 51 .then(function() { -
Dev/branches/rest-dojo-ui/client/qed/pages/session.js
r418 r420 2 2 'dojo/_base/array', 3 3 'dojo/_base/declare', 4 'dojo/_base/Deferred',5 4 'dojo/_base/event', 6 5 'dojo/_base/lang', 6 'dojo/when', 7 7 '../search', 8 8 '../store', … … 10 10 '../app/Router', 11 11 '../widgets/ThresholdFilteringSelect', 12 '../model/classes/SessionTemplate', 12 13 '../model/widgets/AccountListView', 13 14 'dojo/text!./templates/session.html' 14 ],function(array,declare, Deferred,event,lang,search,store,Page,Router,ThresholdFilteringSelect,AccountListView,template){15 ],function(array,declare,event,lang,when,search,store,Page,Router,ThresholdFilteringSelect,SessionTemplate,AccountListView,template){ 15 16 return declare([Page],{ 16 17 templateString: template, … … 30 31 _loadSession: function() { 31 32 if ( this.sessionId === "new" ) { 32 this.session = { 33 type: 'SessionTemplate' 34 }; 33 this.session = SessionTemplate.create(); 35 34 } else { 36 Deferred.when(store.get(this.sessionId))35 when(store.get(this.sessionId)) 37 36 .then(lang.hitch(this,function(obj){ 38 37 this.session = obj; … … 43 42 }, 44 43 _refresh: function() { 45 this.titleNode.innerHTML = this.session.title || '';44 this.titleNode.innerHTML = SessionTemplate.DisplayTitle.get(this.session); 46 45 this.propertiesForm.set('value',this.session); 47 46 }, -
Dev/branches/rest-dojo-ui/client/qed/pages/survey.js
r418 r420 2 2 'dojo/_base/array', 3 3 'dojo/_base/declare', 4 'dojo/_base/Deferred',5 4 'dojo/_base/event', 6 5 'dojo/_base/lang', 6 'dojo/when', 7 7 '../app/Router', 8 8 '../store', 9 9 '../app/Page', 10 '../model/classes/Survey', 10 11 '../model/widgets/QuestionListView', 11 12 '../model/widgets/TabbedQuestionBrowser', 12 13 'dojo/text!./templates/survey.html' 13 ],function(array,declare, Deferred,event,lang,Router,store,Page,14 ],function(array,declare,event,lang,when,Router,store,Page,Survey, 14 15 QuestionListView,TabbedQuestionBrowser,template){ 15 16 return declare([Page],{ … … 17 18 survey: null, 18 19 questionList: null, 19 _dataMap: null,20 constructor: function(){21 this._dataMap = {};22 },23 20 startup: function() { 24 21 if ( this._started ) { return; } … … 62 59 _loadSurvey: function() { 63 60 if ( this.surveyId === "new" ) { 64 this.survey = { 65 type: 'Survey' 66 }; 61 this.survey = Survey.create(); 67 62 this.refresh(); 68 63 } else { 69 Deferred.when(store.get(this.surveyId))64 when(store.get(this.surveyId)) 70 65 .then(lang.hitch(this,function(survey){ 71 66 this.survey = survey; 72 store.query(null,{keys:this.survey.questions || [], include_docs: true})73 .forEach(lang.hitch(this.questionList,'appendItem'));67 array.forEach(Survey.Questions.get(this.survey), 68 lang.hitch(this.questionList,'appendItem')); 74 69 this.refresh(); 75 70 })); … … 80 75 }, 81 76 refresh: function() { 82 this.titleNode.innerHTML = this.survey.title|| "(set title in properties)";77 this.titleNode.innerHTML = Survey.DisplayTitle.get(this.survey) || "(set title in properties)"; 83 78 this.propertiesDialog.set('value',this.survey); 84 79 }, … … 100 95 }, 101 96 _onSave: function(evt) { 102 this.survey.questions = array.map(this.questionList.getItems(),function(item){ 103 return store.getIdentity(item); 104 }); 97 this.survey.questions = this.questionList.getItems(); 105 98 store.put(this.survey) 106 99 .then(function() { … … 114 107 }, 115 108 _onShowPreview: function() { 116 Router.go('/ viewSurvey/'+store.getIdentity(this.survey),{109 Router.go('/previewSurvey/'+store.getIdentity(this.survey),{ 117 110 preview: true 118 111 }); -
Dev/branches/rest-dojo-ui/client/qed/pages/surveyRun.js
r418 r420 1 1 define([ 2 'dojo/_base/array',3 2 'dojo/_base/declare', 4 'dojo/_base/Deferred',5 3 'dojo/_base/event', 6 4 'dojo/_base/lang', 5 'dojo/when', 6 '../app/Content', 7 7 '../app/Router', 8 '../lib/func', 8 9 '../store', 9 10 '../app/Page', 10 '../model/widgets/QuestionListView', 11 '../model/widgets/TabbedQuestionBrowser', 12 'dojo/text!./templates/survey.html' 13 ],function(array,declare,Deferred,event,lang,Router,store,Page, 14 QuestionListView,TabbedQuestionBrowser,template){ 11 '../model/classes/SurveyRun', 12 'dojo/text!./templates/surveyRun.html' 13 ],function(declare,event,lang,when,Content,Router,func,store,Page,SurveyRun,template){ 15 14 return declare([Page],{ 16 15 templateString: template, 17 survey: null, 18 questionList: null, 19 _dataMap: null, 20 constructor: function(){ 21 this._dataMap = {}; 22 }, 16 surveyRun: null, 23 17 startup: function() { 24 18 if ( this._started ) { return; } 25 19 this.inherited(arguments); 26 if ( this.surveyId ) { 27 this._setupQuestionBrowser(); 28 this._setupListView(); 29 this._loadSurvey(); 20 this.propertiesForm.on("blur",lang.hitch(this,'_onPropChange')); 21 if ( this.surveyRunId ) { 22 this._loadSurveyRun(); 30 23 } else { 31 24 throw "No valid uid or survey passed!"; 32 25 } 33 26 }, 34 _setupQuestionBrowser: function() { 35 this.questionBrowser = new TabbedQuestionBrowser({ 36 region: 'center', 37 'class': 'blue', 38 include: 'published', 39 selectedActions: { 40 "Include": { 41 callback: lang.hitch(this,this._includeQuestion), 42 icon: "Accept", 43 description: "Include in survey" 44 } 45 }, 46 itemActions: { 47 "Info": { 48 callback: function(item){ item.description && alert(item.description); }, 49 icon: "Inspect", 50 description: "Show item description" 51 } 52 } 53 },this.questionBrowser); 54 this.questionBrowser.startup(); 27 _loadSurveyRun: function() { 28 when(store.get(this.surveyRunId)) 29 .then(lang.hitch(this,function(surveyRun){ 30 this.surveyRun = surveyRun; 31 this.refresh(); 32 })); 55 33 }, 56 _setupListView: function() {57 this. questionList = new QuestionListView({58 region: 'center'59 },this.surveyListViewNode);60 this. questionList.startup();34 refresh: function() { 35 this.titleNode.innerHTML = SurveyRun.DisplayTitle.get(this.surveyRun); 36 this.surveyNode.set('value',SurveyRun.Survey.get(this.surveyRun)); 37 this.propertiesForm.set('value',this.surveyRun); 38 this._onPropChange(); 61 39 }, 62 _loadSurvey: function() { 63 if ( this.surveyId === "new" ) { 64 this.survey = { 65 type: 'Survey' 66 }; 67 this.refresh(); 40 _onPropChange: function(e) { 41 var surveyRun = this.propertiesForm.get('value'); 42 if ( surveyRun.mode === "open" ) { 43 var url = 'response.html#!/'+store.getIdentity(this.surveyRun); 44 this.runURLNode.innerHTML = '<a target="_black" href="'+url+'">'+url+'</a>'; 68 45 } else { 69 Deferred.when(store.get(this.surveyId)) 70 .then(lang.hitch(this,function(survey){ 71 this.survey = survey; 72 store.query(null,{keys:this.survey.questions || [], include_docs: true}) 73 .forEach(lang.hitch(this.questionList,'appendItem')); 74 this.refresh(); 75 })); 46 this.runURLNode.innerHTML = "No general URL. Add individual respondents below."; 76 47 } 77 48 }, 78 _includeQuestion: function(question) {79 this.questionList.insertItem(question);80 },81 refresh: function() {82 this.titleNode.innerHTML = this.survey.title || "(set title in properties)";83 this.propertiesDialog.set('value',this.survey);84 },85 _onShowProperties: function(evt) {86 this.propertiesDialog.show();87 },88 _onPropertiesOk: function(evt) {89 this.propertiesDialog.hide();90 lang.mixin(this.survey, this.propertiesDialog.get('value'));91 this.refresh();92 event.stop(evt);93 return false;94 },95 _onPropertiesCancel: function(evt) {96 this.propertiesDialog.hide();97 this.propertiesDialog.reset('value',this.survey);98 event.stop(evt);99 return false;100 },101 49 _onSave: function(evt) { 102 this.survey.questions = array.map(this.questionList.getItems(),function(item){ 103 return store.getIdentity(item); 104 }); 105 store.put(this.survey) 50 lang.mixin(this.surveyRun,this.propertiesForm.get('value')); 51 var not = function(p){ return !p; }; 52 func.modPropIf(this.surveyRun,"startDate",not.compose(lang.isString),store.formatDate); 53 func.modPropIf(this.surveyRun,"endDate",not.compose(lang.isString),store.formatDate); 54 store.put(this.surveyRun) 106 55 .then(function() { 107 56 Router.go('/surveys'); 57 },function(err){ 58 Content.notify(err); 108 59 }); 109 60 event.stop(evt); … … 112 63 _onDiscard: function(evt) { 113 64 Router.go('/surveys'); 114 },115 _onShowPreview: function() {116 Router.go('/viewSurvey/'+store.getIdentity(this.survey),{117 preview: true118 });119 65 } 120 66 }); -
Dev/branches/rest-dojo-ui/client/qed/pages/surveys.js
r418 r420 9 9 '../app/Page', 10 10 '../app/Router', 11 '../model/classes/Survey', 12 '../model/classes/SurveyRun', 11 13 '../widgets/LineWithActionsWidget', 12 14 'dojo/text!./templates/surveys.html' 13 ],function(array,declare,lang,when,Rx,store,Content,Page,Router, LineWithActionsWidget,template){15 ],function(array,declare,lang,when,Rx,store,Content,Page,Router,Survey,SurveyRun,LineWithActionsWidget,template){ 14 16 return declare([Page],{ 15 17 templateString: template, … … 45 47 }, 46 48 _onPreviewSurvey:function(survey){ 47 Router.go('/ viewSurvey/'+store.getIdentity(survey),{preview:true});49 Router.go('/previewSurvey/'+store.getIdentity(survey)); 48 50 }, 49 51 _onRunSurvey:function(survey){ 50 this.surveyRun = { 51 type: 'SurveyRun', 52 surveyId: store.getIdentity(survey), 53 publicationDate: store.timestamp() 54 }; 55 this.surveyRunDialog.set('value',this.surveyRun); 56 this.surveyRunDialog.show(); 57 }, 58 _onSurveyRunOk: function() { 59 var surveyRun = lang.mixin(lang.clone(this.surveyRun),this.surveyRunDialog.get('value')); 52 var surveyRun = SurveyRun.create(); 53 SurveyRun.Survey.set(surveyRun,survey); 60 54 store.put(surveyRun) 61 .then(lang.hitch(this,function(){ 62 this.surveyRunDialog.hide(); 63 this.refreshRuns(); 55 .then(lang.hitch(this,function(surveyRun){ 56 this._onRunDetails(surveyRun); 64 57 }),function(err){ 65 58 Content.notify(err); 66 59 }); 67 60 }, 68 _on SurveyRunCancel: function() {69 this.surveyRunDialog.hide();61 _onRunDetails: function(surveyRun) { 62 Router.go('/surveyRun/'+store.getIdentity(surveyRun)); 70 63 }, 71 64 refresh: function() { … … 81 74 array.forEach(surveys,function(survey){ 82 75 var w = new LineWithActionsWidget({ 83 title: survey.title|| '(unnamed)',76 title: Survey.DisplayTitle.get(survey) || '(unnamed)', 84 77 actions: [{ 85 78 callback: lang.hitch(this,'_onPublishSurvey',survey), … … 123 116 array.forEach(surveys,function(survey){ 124 117 var w = new LineWithActionsWidget({ 125 title: survey.title,118 title: Survey.DisplayTitle.get(survey), 126 119 actions:[{ 127 120 callback: lang.hitch(this,'_onPreviewSurvey',survey), … … 151 144 array.forEach(surveyRuns,function(surveyRun){ 152 145 var w = new LineWithActionsWidget({ 153 title: surveyRun.title+" (from "+surveyRun.startDate+" to "+surveyRun.endDate+")",146 title: SurveyRun.DisplayTitle.get(surveyRun), 154 147 actions:[{ 155 callback: lang.hitch(this,'_on CloseRun',surveyRun),148 callback: lang.hitch(this,'_onRunDetails',surveyRun), 156 149 properties: { 157 label: ' Close',158 tooltip: ' Close survey',159 icon: ' Close'150 label: 'Details', 151 tooltip: 'Show details for this run', 152 icon: 'Details' 160 153 } 161 154 }] -
Dev/branches/rest-dojo-ui/client/qed/pages/templates/previewSurvey.html
r418 r420 9 9 10 10 <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'" data-dojo-attach-point="questionsPane"> 11 <form data-dojo-type="dijit/form/Form" data-dojo-attach-point="questionsForm" 12 data-dojo-attach-event="onSubmit:_onSubmit" 13 style="overflow: auto"> 14 <div data-dojo-attach-point="questionsAnchor"></div> 11 <form data-dojo-type="dijit/form/Form" data-dojo-attach-point="questionsForm" style="overflow: auto"> 12 <div data-dojo-type="qed/model/widgets/SurveyWidget" data-dojo-attach-point="surveyWidget"></div> 15 13 </form> 16 14 </div> 17 15 18 <div data-dojo-attach-point="buttonsPane" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'bottom'">19 <button data-dojo-type="dijit/form/Button"20 type="submit"21 data-dojo-attach-event="onClick:_onSubmit">22 Submit</button>23 <button data-dojo-type="dijit/form/Button"24 type="button"25 data-dojo-attach-event="onClick:_onCancel">26 Cancel</button>27 </div>28 29 16 </div> -
Dev/branches/rest-dojo-ui/client/qed/pages/templates/surveys.html
r419 r420 36 36 </div> 37 37 38 <div data-dojo-type="dijit/Dialog"39 title="SurveyRun properties"40 data-dojo-attach-point="surveyRunDialog">41 <fieldset data-dojo-type="qed/model/widgets/SurveyRunFieldset"></fieldset>42 <button data-dojo-type="dijit/form/Button" data-dojo-attach-event="onClick:_onSurveyRunOk">OK</button>43 <button data-dojo-type="dijit/form/Button" data-dojo-attach-event="onClick:_onSurveyRunCancel">Cancel</button>44 </div>45 46 38 </div>
Note: See TracChangeset
for help on using the changeset viewer.