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

Last change on this file since 374 was 374, checked in by jkraaijeveld, 13 years ago

Can now edit basic question properties and store them.

File size: 3.0 KB
Line 
1define(['dojo/_base/declare',
2    'dojo/_base/lang',
3    'dojo/_base/event',
4    'dojo/_base/Deferred',
5    'rft/ui/LineWithActionsWidget',
6    'rft/store',
7    'rft/ui/_Page',
8    'rft/api',
9    'rft/content',
10    'dijit/registry',
11    'dojo/on',
12    'dojo/behavior',
13    'dojo/query',
14    'rft/ui/QuestionEditorPreview',
15    'rft/ui/QuestionEditorToolkit',
16    'dijit/form/FilteringSelect'],
17    function(declare, lang, event, Deferred, LineWithActionsWidget, store, _Page, api, content, registry, on, behavior, query){
18        return declare('rft.pages.question', [_Page], {
19            question: null,
20            _toolkit: null,
21            _preview: null,
22           
23            onVisit: function() {
24                if (this.pageArgs.uid) {
25                    Deferred.when(store.get(this.pageArgs.uid))
26                    .then(lang.hitch(this, function(obj) {
27                        this.question = obj;
28                        this._refresh();
29                    }));
30                } else {
31                    throw new Error("Error: no reference to object set!");
32                }
33                this._setupEditor();
34                this._setupButtons();
35            },
36            onLeave: function() {
37                this.inherited(arguments);
38            },
39            _refresh: function () {
40                this._toolkit.loadQuestion(this.question);
41            },
42            _onSave: function() {
43                lang.mixin(this.question, this._toolkit.propertiesForm.get('value'));
44                this.question.categories = this._toolkit._categories;
45                store.put(this.question)
46                .then(function() {
47                    content.goTo('questions');
48                });
49                return false;
50            },
51            _onDiscard: function() {
52                this._toolkit.propertiesForm.reset();
53                content.goTo('questions');
54                return false;
55            },
56            _setupButtons: function() {
57                var behaviorMap = {
58                    "#btnSave": {
59                        onclick: lang.hitch(this, function(){
60                            this._onSave();
61                        })
62                    },
63                    "#btnDiscard": {
64                        onclick: lang.hitch(this, function(){
65                            this._onDiscard();
66                        })
67                    }
68                }
69                behavior.add(behaviorMap);
70                behavior.apply();
71            },
72            _setupEditor: function() {
73//                this.toolkit = new rft.ui.QuestionEditorToolkit( { question: this.question } );
74                this._toolkit = new rft.ui.QuestionEditorToolkit();
75                this._toolkit.placeAt("QuestionEditorToolkit");
76
77                this._preview = new rft.ui.QuestionEditorPreview();
78                this._preview.placeAt("QuestionEditorPreview");
79            }
80        });
81});
82
Note: See TracBrowser for help on using the repository browser.