source: Dev/branches/rest-dojo-ui/client/rft/pages/question.js @ 389

Last change on this file since 389 was 389, checked in by hendrikvanantwerpen, 13 years ago
File size: 2.8 KB
Line 
1define([
2    'dojo/_base/declare',
3    'dojo/_base/Deferred',
4    'dojo/_base/lang',
5    'dojo/behavior',
6    'rft/store',
7    'rft/content',
8    'rft/ui/_Page',
9    'rft/ui/QuestionEditorPreview',
10    'rft/ui/QuestionEditorToolkit'
11    ],function(declare, Deferred, lang, behavior, store, content, _Page, QuestionEditorPreview, QuestionEditorToolkit){
12        return declare('rft.pages.question', [_Page], {
13            question: null,
14            _toolkit: null,
15            _preview: null,
16           
17            onVisit: function() {
18                if (this.pageArgs.uid) {
19                    Deferred.when(store.get(this.pageArgs.uid))
20                    .then(lang.hitch(this, function(obj) {
21                        this.question = obj;
22                        this._refresh();
23                    }));
24                } else {
25                    throw new Error("Error: no reference to object set!");
26                }
27                this._setupEditor();
28                this._setupButtons();
29            },
30            onLeave: function() {
31                this.inherited(arguments);
32            },
33            _refresh: function () {
34                this._toolkit.set('value',this.question);
35                this._preview.appendItems(this.question.content || []);
36            },
37            _onSave: function() {
38                lang.mixin(this.question, this._toolkit.get('value'));
39                this.question.content = this._preview.getItems();
40                store.put(this.question)
41                .then(function() {
42                    content.goTo('questions');
43                });
44                return true;
45            },
46            _onDiscard: function() {
47                content.goTo('questions');
48                return true;
49            },
50            _setupButtons: function() {
51                var behaviorMap = {
52                    "#btnSave": {
53                        onclick: lang.hitch(this, function(){
54                            this._onSave();
55                        })
56                    },
57                    "#btnDiscard": {
58                        onclick: lang.hitch(this, function(){
59                            this._onDiscard();
60                        })
61                    }
62                }
63                behavior.add(behaviorMap);
64                behavior.apply();
65            },
66            _setupEditor: function() {
67                this._toolkit = new QuestionEditorToolkit({
68                },this.QuestionEditorToolkitNode);
69                this._toolkit.startup();
70
71                this._preview = new QuestionEditorPreview({
72                    region: 'center'
73                },this.QuestionEditorPreviewNode);
74                this._preview.startup();
75                this._supportingWidgets.push(this._toolkit, this._preview);
76            }
77        });
78});
79
Note: See TracBrowser for help on using the repository browser.