Changeset 420 for Dev/branches/rest-dojo-ui/client/qed/pages/surveyRun.js
- Timestamp:
- 12/16/12 20:07:35 (12 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
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 });
Note: See TracChangeset
for help on using the changeset viewer.