Ignore:
Timestamp:
03/08/14 22:51:23 (11 years ago)
Author:
hendrikvanantwerpen
Message:
  • Mark content as dirty to prevent moving away from unsaved data.
  • Better change propagation from lists and our own widgets.
  • Generate notifications for errors and show correct message.
  • Moved all path/url generation to the class stores, not everywhere we use it.
  • Give user always a choice between Save and Save & Close.
  • Better refresh behaviour on form changes and saves.
  • Don't generate duplicate code error when existing object is the one you're storing.
File:
1 edited

Legend:

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

    r487 r490  
    11define([
    2     "../app/Content",
    3     "../app/Page",
    42    "../app/Router",
    53    "../model/classes/questions",
    6     "../model/widgets/QuestionEditorPreview",
    7     "../model/widgets/QuestionEditorToolkit",
    8     "../widgets/_ComplexValueMixin",
     4    "./_ObjectPage",
     5    "dojo/Deferred",
    96    "dojo/_base/declare",
    107    "dojo/_base/event",
    118    "dojo/_base/lang",
    12     "dojo/when",
     9    "require",
    1310    "dojo/text!./templates/question.html"
    14 ], function(Content, Page, Router, questions, QuestionEditorPreview, QuestionEditorToolkit, _ComplexValueMixin, declare, event, lang, when, template) {
    15     return declare([Page,_ComplexValueMixin], {
     11], function(Router, questions, _ObjectPage, Deferred, declare, event, lang, require, template) {
     12    return declare([_ObjectPage], {
     13        contextRequire: require,
    1614        templateString: template,
    1715        _toolkit: null,
    1816        _preview: null,
    19         value: null,
    20        
    21         buildRendering: function() {
    22             this.inherited(arguments);
    23 
    24             this._toolkit = new QuestionEditorToolkit({
    25             },this.QuestionEditorToolkitNode);
    26             this._toolkit.on('submit',lang.hitch(this,"_onSave"));
    27             this._toolkit.startup();
    28 
    29             this._preview = new QuestionEditorPreview({
    30                 name: 'content',
    31                 delay: 5,
    32                 region: 'center'
    33             });
    34             this._preview.startup();
    35             this.addChild(this._preview);
    36         },
     17        classStore: questions,
    3718        startup: function() {
    3819            if ( this._started ) { return; }
    3920            this.inherited(arguments);
    40             if ( !this.questionId ) {
    41                 throw new Error("Error: no reference to object set!");
     21            this.propertiesForm.on('change',lang.hitch(this,'_handlePropertiesChange'));
     22            this.contentList.on('change',lang.hitch(this,'_handleContentChange'));
     23            this._load();
     24        },
     25        _refresh: function() {
     26            this.titleNode.innerHTML = this.object.title || "";
     27            this.propertiesForm.set('value',this.object);
     28            this.contentList.set('value',this.object.content);
     29        },
     30        _handlePropertiesChange: function() {
     31            if ( this.propertiesForm.validate() ) {
     32                lang.mixin(this.object,this.propertiesForm.get('value'));
    4233            }
    43             if (this.questionId === "new") {
    44                 this.set('value', questions.create());
     34            this.markDirty();
     35        },
     36        _handleContentChange: function() {
     37            if ( this.contentList.validate() ) {
     38                this.object.content = this.contentList.get('value');
     39            }
     40            this.markDirty();
     41        },
     42        _save: function() {
     43            if ( this.propertiesForm.validate() && this.contentList.validate() ) {
     44                lang.mixin(this.object,this.propertiesForm.get('value'));
     45                this.object.content = this.contentList.get('value');
     46                return this.inherited(arguments);
    4547            } else {
    46                 when(questions.load(this.questionId))
    47                 .then(lang.hitch(this, function(value) {
    48                     this.set('value', value);
    49                 }));
     48                return new Deferred().reject();
    5049            }
    5150        },
    52         _setValueAttr: function(value) {
    53             this.value = value;
    54             this.inherited(arguments);
    55             this.titleNode.innerHTML = value.title || "";
    56         },
    57         _getValueAttr: function() {
    58             var value = this.inherited(arguments);
    59             lang.mixin(this.value, value);
    60             return this.value;
    61         },
    6251        _onSave: function(evt) {
    63             if ( this.validate() ) {
    64                 questions.save(this.get('value'))
    65                 .then(function() {
    66                     Router.go('/questions');
    67                 },function(err){
    68                     Content.notify(err,'error');
    69                 });
    70             }
     52            this._save();
    7153            if ( evt ) { event.stop( evt ); }
    7254            return false;
    7355        },
    74         _onDiscard: function() {
    75             Router.go('/questions');
    76             return true;
     56        _onSaveAndClose: function(evt) {
     57            this._save()
     58            .then(function(){
     59                Router.go(questions.getCollectionPath());
     60            });
     61            if ( evt ) { event.stop( evt ); }
     62            return false;
     63        },
     64        _onDiscard: function(evt) {
     65            this.markClean();
     66            Router.go(questions.getCollectionPath());
     67            if ( evt ) { event.stop( evt ); }
     68            return false;
     69        },
     70        _ignore: function(evt) {
     71            if ( evt ) { event.stop( evt ); }
     72            return false;
    7773        }
    7874    });
Note: See TracChangeset for help on using the changeset viewer.