1 | define(['dojo/_base/declare','dojo/_base/lang','dojo/_base/event', |
---|
2 | 'dojo/_base/Deferred','rft/store','rft/ui/_Page','rft/ui/AccordionList', 'rft/content'], |
---|
3 | function(declare,lang,event,Deferred,store,_Page,AccordionList,content) { |
---|
4 | return declare('rft.pages.questions',[_Page],{ |
---|
5 | constructor: function() { |
---|
6 | this.inherited(arguments); |
---|
7 | this.questions = {}; |
---|
8 | }, |
---|
9 | onVisit: function() { |
---|
10 | debugger; |
---|
11 | this._list = new AccordionList({ |
---|
12 | actions: { |
---|
13 | 'Edit': { |
---|
14 | callback: lang.hitch(this,'_editQuestion'), |
---|
15 | properties: { |
---|
16 | blockButton: true, |
---|
17 | icon: "Edit", |
---|
18 | label: "Edit" |
---|
19 | } |
---|
20 | } |
---|
21 | |
---|
22 | |
---|
23 | }, |
---|
24 | idProperty: store.idProperty, |
---|
25 | categoryProperty: 'category', |
---|
26 | titleProperty: 'title' |
---|
27 | },this.list); |
---|
28 | this._list.startup(); |
---|
29 | this._refresh(); |
---|
30 | }, |
---|
31 | _refresh: function() { |
---|
32 | Deferred.when(store.query('_design/default/_view/by_type',{key: 'Question'})) |
---|
33 | .then(lang.hitch(this,function(items){ |
---|
34 | this._list.setItems(items); |
---|
35 | })); |
---|
36 | }, |
---|
37 | onNewQuestion: function() { |
---|
38 | Deferred.when(store.add({type:'Question'})) |
---|
39 | .then(lang.hitch(this,function(question){ |
---|
40 | this._editQuestion(question); |
---|
41 | })); |
---|
42 | }, |
---|
43 | _editQuestion: function(question) { |
---|
44 | content.goTo("question", {uid: question._id}); |
---|
45 | // this.questionForm.reset(); |
---|
46 | // this.questionWidget.set('value',question); |
---|
47 | // this.questionDialog.show(); |
---|
48 | }, |
---|
49 | onSaveQuestion: function(evt) { |
---|
50 | var value = this.questionWidget.get('value'); |
---|
51 | Deferred.when(store.put(value)) |
---|
52 | .then(lang.hitch(this,function(){ |
---|
53 | this.questionDialog.hide(); |
---|
54 | this.questionForm.reset(); |
---|
55 | this._refresh(); |
---|
56 | })); |
---|
57 | event.stop(evt); |
---|
58 | return false; |
---|
59 | }, |
---|
60 | onCancelQuestion: function() { |
---|
61 | this.questionDialog.hide(); |
---|
62 | this.questionForm.reset(); |
---|
63 | } |
---|
64 | }); |
---|
65 | }); |
---|