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

Last change on this file since 392 was 390, checked in by hendrikvanantwerpen, 13 years ago
  • Removed some id's from elements in templates, these give problems when a widget or page is loaded more then once (use data-*-attach-point to access the nodes).
  • Removed some unnecessary attach-* attributes from templates.
  • Fixed some event handling.
File size: 2.4 KB
Line 
1define([
2    'dojo/_base/declare',
3    'dojo/_base/Deferred',
4    'dojo/_base/event',
5    'dojo/_base/lang',
6    'rft/store',
7    'rft/content',
8    'rft/ui/_Page',
9    'rft/ui/QuestionEditorPreview',
10    'rft/ui/QuestionEditorToolkit'
11    ],function(declare, Deferred, event, lang, 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            },
29            onLeave: function() {
30                this.inherited(arguments);
31            },
32            _refresh: function () {
33                this._toolkit.set('value',this.question);
34                this._preview.appendItems(this.question.content || []);
35            },
36            _onSave: function(evt) {
37                lang.mixin(this.question, this._toolkit.get('value'));
38                this.question.content = this._preview.getItems();
39                store.put(this.question)
40                .then(function() {
41                    content.goTo('questions');
42                });
43                evt && event.stop( evt );
44                return false;
45            },
46            _onDiscard: function() {
47                content.goTo('questions');
48                return true;
49            },
50            _setupEditor: function() {
51                this._toolkit = new QuestionEditorToolkit({
52                },this.QuestionEditorToolkitNode);
53                this._toolkit.on('submit',lang.hitch(this,"_onSave"));
54                this._toolkit.startup();
55
56                this._preview = new QuestionEditorPreview({
57                    region: 'center'
58                },this.QuestionEditorPreviewNode);
59                this._preview.startup();
60                this._supportingWidgets.push(this._toolkit, this._preview);
61            }
62        });
63});
64
Note: See TracBrowser for help on using the repository browser.