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

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

Started the QuestionEditorPreview? bit - now works with headers and texts, fully stores and restores this in order properly.

Note: there must be a better way for this, but seeing as all content pieces can differ greatly I couldn't think of a way to make it properly generic. @Hendrik: need discussion about this.

Note2: Currently I don't use any internal events in the question editor. Not sure if it would be a lot better we would.

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                this._preview.insertObjects(this.question.content || []);
42            },
43            _onSave: function() {
44                lang.mixin(this.question, this._toolkit.propertiesForm.get('value'));
45                this.question.categories = this._toolkit._categories;
46                this.question.content = this._preview.getContent();
47                store.put(this.question)
48                .then(function() {
49                    content.goTo('questions');
50                });
51                return false;
52            },
53            _onDiscard: function() {
54                content.goTo('questions');
55                return false;
56            },
57            _setupButtons: function() {
58                var behaviorMap = {
59                    "#btnSave": {
60                        onclick: lang.hitch(this, function(){
61                            this._onSave();
62                        })
63                    },
64                    "#btnDiscard": {
65                        onclick: lang.hitch(this, function(){
66                            this._onDiscard();
67                        })
68                    }
69                }
70                behavior.add(behaviorMap);
71                behavior.apply();
72            },
73            _setupEditor: function() {
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.