Ignore:
Timestamp:
05/02/13 13:13:13 (12 years ago)
Author:
hendrikvanantwerpen
Message:

Enable validation on all fields of question.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/client/qed/pages/question.js

    r441 r442  
    11define([
    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], {
     2    "../app/Content",
     3    "../app/Page",
     4    "../app/Router",
     5    "../model/classes/Question",
     6    "../model/widgets/QuestionEditorPreview",
     7    "../model/widgets/QuestionEditorToolkit",
     8    "../store",
     9    "../widgets/_ComplexValueMixin",
     10    "dojo/_base/declare",
     11    "dojo/_base/event",
     12    "dojo/_base/lang",
     13    "dojo/when",
     14    "dojo/text!./templates/question.html"
     15], function(Content, Page, Router, Question, QuestionEditorPreview, QuestionEditorToolkit, store, _ComplexValueMixin, declare, event, lang, when, template) {
     16    return declare([Page,_ComplexValueMixin], {
    1617        templateString: template,
    17         question: null,
    1818        _toolkit: null,
    1919        _preview: null,
     20        value: null,
    2021       
     22        buildRendering: function() {
     23            this.inherited(arguments);
     24
     25            this._toolkit = new QuestionEditorToolkit({
     26            },this.QuestionEditorToolkitNode);
     27            this._toolkit.on('submit',lang.hitch(this,"_onSave"));
     28            this._toolkit.startup();
     29
     30            this._preview = new QuestionEditorPreview({
     31                name: 'content',
     32                delay: 5,
     33                region: 'center'
     34            });
     35            this._preview.startup();
     36            this.addChild(this._preview);
     37        },
    2138        startup: function() {
    2239            if ( this._started ) { return; }
     
    2542                throw new Error("Error: no reference to object set!");
    2643            }
    27             this._setupEditor();
    2844            if (this.questionId === "new") {
    29                 this.question = Question.create();
    30                 this._refresh();
     45                this.set('value', Question.create());
    3146            } else {
    3247                when(store.get(this.questionId))
    33                 .then(lang.hitch(this, function(obj) {
    34                     this.question = obj;
    35                     this._refresh();
     48                .then(lang.hitch(this, function(value) {
     49                    this.set('value', value);
    3650                }));
    3751            }
    3852        },
    39         onLeave: function() {
     53        _setValueAttr: function(value) {
     54            this.value = value;
    4055            this.inherited(arguments);
     56            this.titleNode.innerHTML = Question.DisplayTitle.get(value);
    4157        },
    42         _refresh: function () {
    43             this.titleNode.innerHTML = Question.DisplayTitle.get(this.question);
    44             this._toolkit.set('value', this.question);
    45             this._preview.set('value', Question.Content.get(this.question));
     58        _getValueAttr: function() {
     59            var value = this.inherited(arguments);
     60            lang.mixin(this.value, value);
     61            return this.value;
    4662        },
    4763        _onSave: function(evt) {
    48             if ( this._preview.validate() ) {
    49                 lang.mixin(this.question, this._toolkit.get('value'));
    50                 Question.Content.set(this.question, this._preview.get('value'));
    51                 store.put(this.question)
     64            if ( this.validate() ) {
     65                var value = this.get('value');
     66                store.put(value)
    5267                .then(function() {
    5368                    Router.go('/questions');
     
    6277            Router.go('/questions');
    6378            return true;
    64         },
    65         _setupEditor: function() {
    66             this._toolkit = new QuestionEditorToolkit({
    67             },this.QuestionEditorToolkitNode);
    68             this._toolkit.on('submit',lang.hitch(this,"_onSave"));
    69             this._toolkit.startup();
    70 
    71             this._preview = new QuestionEditorPreview({
    72                 name: 'content',
    73                 delay: 5,
    74                 region: 'center'
    75             });
    76             this._preview.startup();
    77             this.addChild(this._preview);
    7879        }
    7980    });
Note: See TracChangeset for help on using the changeset viewer.