1 | define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/event', |
---|
2 | 'dojo/_base/Deferred','rft/store','rft/ui/_Page','rft/ui/AccordionList'], |
---|
3 | function(declare,lang,event,Deferred,store,_Page,AccordionList) { |
---|
4 | return declare('rft.pages.questions',[_Page],{ |
---|
5 | constructor: function() { |
---|
6 | this.inherited(arguments); |
---|
7 | this.questions = {}; |
---|
8 | }, |
---|
9 | onVisit: function() { |
---|
10 | this._store = store.getStore('Question'); |
---|
11 | this._list = new AccordionList({ |
---|
12 | store: this._store, |
---|
13 | actions: { |
---|
14 | 'Edit': lang.hitch(this,'_editQuestion') |
---|
15 | }, |
---|
16 | categoryProperty: 'category', |
---|
17 | titleProperty: 'title' |
---|
18 | },this.list); |
---|
19 | this._list.startup(); |
---|
20 | this._refresh(); |
---|
21 | }, |
---|
22 | _refresh: function() { |
---|
23 | this._list.refresh(); |
---|
24 | }, |
---|
25 | onNewQuestion: function() { |
---|
26 | Deferred.when( this._store.add({}) ) |
---|
27 | .then(lang.hitch(this,function(question){ |
---|
28 | this._editQuestion(question); |
---|
29 | })); |
---|
30 | }, |
---|
31 | _editQuestion: function(question) { |
---|
32 | this.questionForm.reset(); |
---|
33 | this.questionWidget.set('value',question); |
---|
34 | this.questionDialog.show(); |
---|
35 | }, |
---|
36 | onSaveQuestion: function(evt) { |
---|
37 | var value = this.questionWidget.get('value'); |
---|
38 | Deferred.when( this._store.put(value) ) |
---|
39 | .then(lang.hitch(this,function(){ |
---|
40 | this.questionDialog.hide(); |
---|
41 | this.questionForm.reset(); |
---|
42 | this._refresh(); |
---|
43 | })); |
---|
44 | event.stop(evt); |
---|
45 | return false; |
---|
46 | }, |
---|
47 | onCancelQuestion: function() { |
---|
48 | this.questionDialog.hide(); |
---|
49 | this.questionForm.reset(); |
---|
50 | } |
---|
51 | }); |
---|
52 | }); |
---|