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/survey.js

    r487 r490  
    11define([
    2     "../app/Page",
    32    "../app/Router",
    43    "../model/classes/surveys",
    54    "../model/widgets/QuestionListView",
    65    "../model/widgets/TabbedQuestionBrowser",
     6    "./_ObjectPage",
    77    "dojo/_base/array",
    88    "dojo/_base/declare",
     
    1212    "require",
    1313    "dojo/text!./templates/survey.html"
    14 ], function(Page, Router, surveys, QuestionListView, TabbedQuestionBrowser, array, declare, event, lang, when, require, template) {
    15     return declare([Page],{
     14], function(Router, surveys, QuestionListView, TabbedQuestionBrowser, _ObjectPage, array, declare, event, lang, when, require, template) {
     15    return declare([_ObjectPage],{
    1616        contextRequire: require,
    1717        templateString: template,
    18         survey: null,
     18        classStore: surveys,
    1919        questionList: null,
    2020        startup: function() {
    2121            if ( this._started ) { return; }
    2222            this.inherited(arguments);
    23             if ( this.surveyId ) {
    24                 this._setupQuestionBrowser();
    25                 this._setupListView();
    26                 this._loadSurvey();
    27             } else {
    28                 throw "No valid uid or survey passed!";
    29             }
     23            this._setupQuestionBrowser();
     24            this._setupListView();
     25            this._load();
    3026        },
    3127        _setupQuestionBrowser: function() {
     
    6056            this.questionList.startup();
    6157        },
    62         _loadSurvey: function() {
    63             if ( this.surveyId === "new" ) {
    64                 this.survey = surveys.create();
    65                 this.refresh();
    66             } else {
    67                 when(surveys.load(this.surveyId))
    68                 .then(lang.hitch(this,function(survey){
    69                     this.survey = survey;
    70                     this.questionList.set('value',
    71                                           this.survey.questions);
    72                     this.refresh();
    73                 }));
    74             }
     58        _refresh: function() {
     59            this.titleNode.innerHTML = this.object.title || "(set title in properties)";
     60            this.propertiesDialog.set('value',this.object);
     61            this.questionList.set('value',
     62                                  this.object.questions);
     63        },
     64        _save: function() {
     65            this.object.questions = this.questionList.get('value');
     66            return this.inherited(arguments);
    7567        },
    7668        _includeQuestion: function(question) {
    7769            this.questionList.appendItem(question);
    7870        },
    79         refresh: function() {
    80             this.titleNode.innerHTML = this.survey.title || "(set title in properties)";
    81             this.propertiesDialog.set('value',this.survey);
    82         },
    8371        _onShowProperties: function(evt) {
    8472            this.propertiesDialog.show();
     73            if ( evt ) { event.stop(evt); }
     74            return false;
    8575        },
    8676        _onPropertiesOk: function(evt) {
    8777            this.propertiesDialog.hide();
    88             lang.mixin(this.survey, this.propertiesDialog.get('value'));
    89             this.refresh();
    90             event.stop(evt);
     78            lang.mixin(this.object, this.propertiesDialog.get('value'));
     79            this.markDirty();
     80            this._refresh();
     81            if ( evt ) { event.stop(evt); }
    9182            return false;
    9283        },
    9384        _onPropertiesCancel: function(evt) {
    9485            this.propertiesDialog.hide();
    95             this.propertiesDialog.reset('value',this.survey);
    96             event.stop(evt);
     86            this.propertiesDialog.set('value',this.object);
     87            if ( evt ) { event.stop(evt); }
    9788            return false;
    9889        },
    9990        _onSave: function(evt) {
    100             this.survey.questions = this.questionList.get('value');
    101             surveys.save(this.survey)
     91            this._save();
     92            if ( evt ) { event.stop(evt); }
     93            return false;
     94        },
     95        _onSaveAndClose: function(evt) {
     96            this._save()
    10297            .then(function() {
    103                 Router.go('/surveys');
     98                Router.go(surveys.getCollectionPath());
    10499            });
    105100            event.stop(evt);
    106101            return false;
    107102        },
    108         _onDiscard: function(evt) {
    109             Router.go('/surveys');
     103        _onDiscardAndClose: function(evt) {
     104            this.markClean();
     105            Router.go(surveys.getCollectionPath());
    110106        },
    111107        _onShowPreview: function() {
    112             Router.go('/previewSurvey/'+this.survey._id,{
     108            Router.go(surveys.getPreviewPath(this.object),{
    113109                preview: true
    114110            });
Note: See TracChangeset for help on using the changeset viewer.