[370] | 1 | define([ |
---|
[379] | 2 | 'dojo/_base/array', |
---|
[370] | 3 | 'dojo/_base/declare', |
---|
| 4 | 'dojo/_base/event', |
---|
| 5 | 'dojo/_base/lang', |
---|
[420] | 6 | 'dojo/when', |
---|
[410] | 7 | '../app/Router', |
---|
[389] | 8 | '../store', |
---|
[407] | 9 | '../app/Page', |
---|
[420] | 10 | '../model/classes/Survey', |
---|
[417] | 11 | '../model/widgets/QuestionListView', |
---|
| 12 | '../model/widgets/TabbedQuestionBrowser', |
---|
| 13 | 'dojo/text!./templates/survey.html' |
---|
[420] | 14 | ],function(array,declare,event,lang,when,Router,store,Page,Survey, |
---|
[407] | 15 | QuestionListView,TabbedQuestionBrowser,template){ |
---|
| 16 | return declare([Page],{ |
---|
| 17 | templateString: template, |
---|
| 18 | survey: null, |
---|
| 19 | questionList: null, |
---|
| 20 | startup: function() { |
---|
| 21 | if ( this._started ) { return; } |
---|
| 22 | this.inherited(arguments); |
---|
| 23 | if ( this.surveyId ) { |
---|
| 24 | this._setupQuestionBrowser(); |
---|
| 25 | this._setupListView(); |
---|
[416] | 26 | this._loadSurvey(); |
---|
[407] | 27 | } else { |
---|
| 28 | throw "No valid uid or survey passed!"; |
---|
| 29 | } |
---|
| 30 | }, |
---|
| 31 | _setupQuestionBrowser: function() { |
---|
| 32 | this.questionBrowser = new TabbedQuestionBrowser({ |
---|
| 33 | region: 'center', |
---|
| 34 | 'class': 'blue', |
---|
[410] | 35 | include: 'published', |
---|
[407] | 36 | selectedActions: { |
---|
| 37 | "Include": { |
---|
| 38 | callback: lang.hitch(this,this._includeQuestion), |
---|
| 39 | icon: "Accept", |
---|
| 40 | description: "Include in survey" |
---|
| 41 | } |
---|
| 42 | }, |
---|
| 43 | itemActions: { |
---|
| 44 | "Info": { |
---|
[426] | 45 | callback: function(item){ |
---|
| 46 | if ( item.description ) { alert(item.description); } |
---|
| 47 | }, |
---|
[407] | 48 | icon: "Inspect", |
---|
| 49 | description: "Show item description" |
---|
| 50 | } |
---|
[360] | 51 | } |
---|
[407] | 52 | },this.questionBrowser); |
---|
| 53 | this.questionBrowser.startup(); |
---|
| 54 | }, |
---|
| 55 | _setupListView: function() { |
---|
| 56 | this.questionList = new QuestionListView({ |
---|
[441] | 57 | region: 'center', |
---|
| 58 | name: 'questions' |
---|
[407] | 59 | },this.surveyListViewNode); |
---|
| 60 | this.questionList.startup(); |
---|
| 61 | }, |
---|
[416] | 62 | _loadSurvey: function() { |
---|
| 63 | if ( this.surveyId === "new" ) { |
---|
[420] | 64 | this.survey = Survey.create(); |
---|
[410] | 65 | this.refresh(); |
---|
[416] | 66 | } else { |
---|
[420] | 67 | when(store.get(this.surveyId)) |
---|
[416] | 68 | .then(lang.hitch(this,function(survey){ |
---|
| 69 | this.survey = survey; |
---|
[441] | 70 | this.questionList.set('value', |
---|
| 71 | Survey.Questions.get(this.survey)); |
---|
[416] | 72 | this.refresh(); |
---|
| 73 | })); |
---|
| 74 | } |
---|
[410] | 75 | }, |
---|
| 76 | _includeQuestion: function(question) { |
---|
[441] | 77 | this.questionList.appendItem(question); |
---|
[410] | 78 | }, |
---|
[407] | 79 | refresh: function() { |
---|
[420] | 80 | this.titleNode.innerHTML = Survey.DisplayTitle.get(this.survey) || "(set title in properties)"; |
---|
[417] | 81 | this.propertiesDialog.set('value',this.survey); |
---|
[407] | 82 | }, |
---|
| 83 | _onShowProperties: function(evt) { |
---|
| 84 | this.propertiesDialog.show(); |
---|
| 85 | }, |
---|
| 86 | _onPropertiesOk: function(evt) { |
---|
| 87 | this.propertiesDialog.hide(); |
---|
[417] | 88 | lang.mixin(this.survey, this.propertiesDialog.get('value')); |
---|
[407] | 89 | this.refresh(); |
---|
| 90 | event.stop(evt); |
---|
| 91 | return false; |
---|
| 92 | }, |
---|
| 93 | _onPropertiesCancel: function(evt) { |
---|
| 94 | this.propertiesDialog.hide(); |
---|
[417] | 95 | this.propertiesDialog.reset('value',this.survey); |
---|
[407] | 96 | event.stop(evt); |
---|
| 97 | return false; |
---|
| 98 | }, |
---|
| 99 | _onSave: function(evt) { |
---|
[441] | 100 | this.survey.questions = this.questionList.get('value'); |
---|
[407] | 101 | store.put(this.survey) |
---|
| 102 | .then(function() { |
---|
[410] | 103 | Router.go('/surveys'); |
---|
[407] | 104 | }); |
---|
| 105 | event.stop(evt); |
---|
| 106 | return false; |
---|
| 107 | }, |
---|
| 108 | _onDiscard: function(evt) { |
---|
[410] | 109 | Router.go('/surveys'); |
---|
[407] | 110 | }, |
---|
| 111 | _onShowPreview: function() { |
---|
[420] | 112 | Router.go('/previewSurvey/'+store.getIdentity(this.survey),{ |
---|
[410] | 113 | preview: true |
---|
| 114 | }); |
---|
[407] | 115 | } |
---|
| 116 | }); |
---|
[354] | 117 | }); |
---|
[292] | 118 | |
---|