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

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

QuestionEditorToolkit? now uses a TitleGroup? rather than an AccordionContainer? - they do the same but the TitlePanes? scales automatically (which was required for the list of categories of a question).

There still needs to be done some .css for this TitleGroup? stuff, but I'm not booking much progress on that.

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 true;
52            },
53            _onDiscard: function() {
54                content.goTo('questions');
55                return true;
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                this._supportingWidgets.push(this._toolkit, this._preview);
80            }
81        });
82});
83
Note: See TracBrowser for help on using the repository browser.