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

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

Mockup included.

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