source: Dev/trunk/client/qed/pages/question.js @ 435

Last change on this file since 435 was 426, checked in by hendrikvanantwerpen, 12 years ago

Added grunt tasks and code cleanup.

Added grunt for less and jshint procesing.
Cleanup of code to pass jshint (one bug found :).

File size: 2.7 KB
Line 
1define([
2    'dojo/_base/declare',
3    'dojo/_base/event',
4    'dojo/_base/lang',
5    'dojo/when',
6    '../store',
7    '../app/Content',
8    '../app/Router',
9    '../app/Page',
10    '../model/classes/Question',
11    '../model/widgets/QuestionEditorPreview',
12    '../model/widgets/QuestionEditorToolkit',
13    'dojo/text!./templates/question.html'
14],function(declare, event, lang, when, store, Content, Router, Page, Question, QuestionEditorPreview, QuestionEditorToolkit, template){
15    return declare([Page], {
16        templateString: template,
17        question: null,
18        _toolkit: null,
19        _preview: null,
20       
21        startup: function() {
22            if ( this._started ) { return; }
23            this.inherited(arguments);
24            if ( !this.questionId ) {
25                throw new Error("Error: no reference to object set!");
26            }
27            this._setupEditor();
28            if (this.questionId === "new") {
29                this.question = Question.create();
30                this._refresh();
31            } else {
32                when(store.get(this.questionId))
33                .then(lang.hitch(this, function(obj) {
34                    this.question = obj;
35                    this._refresh();
36                }));
37            }
38        },
39        onLeave: function() {
40            this.inherited(arguments);
41        },
42        _refresh: function () {
43            this.titleNode.innerHTML = Question.DisplayTitle.get(this.question);
44            this._toolkit.set('value',this.question);
45            this._preview.appendItems(Question.Content.get(this.question));
46        },
47        _onSave: function(evt) {
48            lang.mixin(this.question, this._toolkit.get('value'));
49            Question.Content.set(this.question, this._preview.getItems());
50            store.put(this.question)
51            .then(function() {
52                Router.go('/questions');
53            },function(err){
54                Content.notify(err,'error');
55            });
56            if ( evt ) { event.stop( evt ); }
57            return false;
58        },
59        _onDiscard: function() {
60            Router.go('/questions');
61            return true;
62        },
63        _setupEditor: function() {
64            this._toolkit = new QuestionEditorToolkit({
65            },this.QuestionEditorToolkitNode);
66            this._toolkit.on('submit',lang.hitch(this,"_onSave"));
67            this._toolkit.startup();
68
69            this._preview = new QuestionEditorPreview({
70            },this.QuestionEditorPreviewNode);
71            this._preview.startup();
72            this._supportingWidgets.push(this._toolkit, this._preview);
73        }
74    });
75});
Note: See TracBrowser for help on using the repository browser.