source: Dev/branches/rest-dojo-ui/client/rft/pages/questions.js @ 360

Last change on this file since 360 was 343, checked in by hendrikvanantwerpen, 13 years ago

[Client] Changed store and pages to use CouchDB.
[Client] Disabled login for now, have to figure out some more details about CouchDB.

File size: 2.1 KB
Line 
1define(['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._list = new AccordionList({
11                    actions: {
12                        'Edit': lang.hitch(this,'_editQuestion')
13                    },
14                    idProperty: store.idProperty,
15                    categoryProperty: 'category',
16                    titleProperty: 'title'
17                },this.list);
18                this._list.startup();
19                this._refresh();
20            },
21            _refresh: function() {
22                Deferred.when(store.query('_design/default/_view/by_type',{key: 'Question'}))
23                .then(lang.hitch(this,function(items){
24                    this._list.setItems(items);
25                }));
26            },
27            onNewQuestion: function() {
28                Deferred.when(store.add({type:'Question'}))
29                .then(lang.hitch(this,function(question){
30                    this._editQuestion(question);
31                }));
32            },
33            _editQuestion: function(question) {
34                this.questionForm.reset();
35                this.questionWidget.set('value',question);
36                this.questionDialog.show();
37            },
38            onSaveQuestion: function(evt) {
39                var value = this.questionWidget.get('value');
40                Deferred.when(store.put(value))
41                .then(lang.hitch(this,function(){
42                    this.questionDialog.hide();
43                    this.questionForm.reset();
44                    this._refresh();
45                }));
46                event.stop(evt);
47                return false;
48            },
49            onCancelQuestion: function() {
50                this.questionDialog.hide();
51                this.questionForm.reset();
52            }
53        });
54    });
Note: See TracBrowser for help on using the repository browser.