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

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

Made QuestionEditorPreview? a ContentPane? that scales with the layout
correctly, no preset height in CSS needed anymore.
ISSUE: scrolling also starts a DnD event, Dojo bug?

File size: 2.9 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.loadQuestion(this.question);
35                this._preview.insertObjects(this.question.content || []);
36            },
37            _onSave: function() {
38                lang.mixin(this.question, this._toolkit.propertiesForm.get('value'));
39                this.question.categories = this._toolkit._categories;
40                this.question.content = this._preview.getContent();
41                store.put(this.question)
42                .then(function() {
43                    content.goTo('questions');
44                });
45                return true;
46            },
47            _onDiscard: function() {
48                content.goTo('questions');
49                return true;
50            },
51            _setupButtons: function() {
52                var behaviorMap = {
53                    "#btnSave": {
54                        onclick: lang.hitch(this, function(){
55                            this._onSave();
56                        })
57                    },
58                    "#btnDiscard": {
59                        onclick: lang.hitch(this, function(){
60                            this._onDiscard();
61                        })
62                    }
63                }
64                behavior.add(behaviorMap);
65                behavior.apply();
66            },
67            _setupEditor: function() {
68                this._toolkit = new QuestionEditorToolkit({
69                },this.QuestionEditorToolkitNode);
70                this._toolkit.startup();
71
72                this._preview = new QuestionEditorPreview({
73                    region: 'center'
74                },this.QuestionEditorPreviewNode);
75                this._preview.startup();
76                this._supportingWidgets.push(this._toolkit, this._preview);
77            }
78        });
79});
80
Note: See TracBrowser for help on using the repository browser.