1 | define([ |
---|
2 | 'dojo/_base/declare', |
---|
3 | 'dojo/_base/Deferred', |
---|
4 | 'dojo/_base/event', |
---|
5 | 'dojo/_base/lang', |
---|
6 | 'rft/content', |
---|
7 | 'rft/store', |
---|
8 | 'rft/ui/_Page', |
---|
9 | 'rft/ui/SurveyListView', |
---|
10 | 'rft/ui/TabbedQuestionBrowser' |
---|
11 | ], |
---|
12 | function(declare,Deferred,event,lang,content,store,_Page,SurveyListView,TabbedQuestionBrowser){ |
---|
13 | return declare('rft.pages.survey',[_Page],{ |
---|
14 | object: null, |
---|
15 | listView: null, |
---|
16 | _dataMap: null, |
---|
17 | constructor: function(){ |
---|
18 | this._dataMap = {}; |
---|
19 | }, |
---|
20 | onVisit: function() { |
---|
21 | if ( this.pageArgs.uid ) { |
---|
22 | Deferred.when(store.get(this.pageArgs.uid)) |
---|
23 | .then(lang.hitch(this,function(obj){ |
---|
24 | this.object = obj; |
---|
25 | return Deferred.when( obj.creator && store.dereference(obj.creator) ); |
---|
26 | })); |
---|
27 | this._setupQuestionBrowser(); |
---|
28 | this._setupListView(); |
---|
29 | } else { |
---|
30 | throw "No valid uid or survey passed!"; |
---|
31 | } |
---|
32 | }, |
---|
33 | onProperties: function(evt) { |
---|
34 | |
---|
35 | }, |
---|
36 | onSave: function(evt) { |
---|
37 | // lang.mixin(this.object, this.propertiesForm.get('value')); |
---|
38 | store.put(this.object) |
---|
39 | .then(function() { |
---|
40 | content.goTo('surveys'); |
---|
41 | }); |
---|
42 | event.stop(evt); |
---|
43 | return false; |
---|
44 | }, |
---|
45 | _goToPreview: function() { |
---|
46 | content.goTo('surveyAdvanced', {uid: this.object._id}); |
---|
47 | }, |
---|
48 | _setupQuestionBrowser: function() { |
---|
49 | this.questionBrowser = new TabbedQuestionBrowser({ |
---|
50 | region: 'center', |
---|
51 | 'class': 'blue', |
---|
52 | selectedActions: { |
---|
53 | "Include": { |
---|
54 | callback: lang.hitch(this,this.includeQuestion), |
---|
55 | icon: "Accept", |
---|
56 | description: "Include in survey" |
---|
57 | } |
---|
58 | }, |
---|
59 | itemActions: { |
---|
60 | "Info": { |
---|
61 | callback: function(item){ item.description && alert(item.description); }, |
---|
62 | icon: "Inspect", |
---|
63 | description: "Show item description" |
---|
64 | } |
---|
65 | } |
---|
66 | },this.questionBrowser); |
---|
67 | this.questionBrowser.startup(); |
---|
68 | }, |
---|
69 | /* ListView code */ |
---|
70 | includeQuestion: function(question) { |
---|
71 | var item = this.listView.insertItem(question); |
---|
72 | }, |
---|
73 | _setupListView: function() { |
---|
74 | this.listView = new SurveyListView({ |
---|
75 | controller: this |
---|
76 | }).placeAt(this.surveyListViewNode); |
---|
77 | this.listView.startup(); |
---|
78 | } |
---|
79 | }); |
---|
80 | }); |
---|
81 | |
---|