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

    r487 r490  
    11define([
    22    "../app/Content",
    3     "../app/Page",
     3    "../app/Path",
    44    "../app/Router",
    55    "../lib/func",
    66    "../model/classes/responses",
    77    "../model/classes/surveyRuns",
     8    "../model/classes/surveys",
    89    "../widgets/LineWithActionsWidget",
     10    "./_ObjectPage",
     11    "dojo/Deferred",
    912    "dojo/_base/array",
    1013    "dojo/_base/declare",
     
    1417    "require",
    1518    "dojo/text!./templates/surveyRun.html"
    16 ], function(Content, Page, Router, func, responses, surveyRuns, LineWithActionsWidget, array, declare, event, lang, when, require, template) {
    17     return declare([Page],{
     19], function(Content, Path, Router, func, responses, surveyRuns, surveys, LineWithActionsWidget, _ObjectPage, Deferred, array, declare, event, lang, when, require, template) {
     20    return declare([_ObjectPage],{
    1821        contextRequire: require,
    1922        templateString: template,
    20         surveyRun: null,
     23        classStore: surveyRuns,
    2124        startup: function() {
    2225            if ( this._started ) { return; }
    2326            this.inherited(arguments);
    24             this.surveyRunWidget.on("blur",lang.hitch(this,'_onPropChange'));
    25             if ( this.surveyRunId ) {
    26                 this._loadSurveyRun();
     27            this.surveyRunWidget.on("change",lang.hitch(this,'_onPropChange'));
     28            this._load();
     29        },
     30        _refresh: function() {
     31            this.titleNode.innerHTML = this.object.title || "";
     32            this.surveySummaryWidget.set('value',this.object.survey);
     33            this.surveyRunWidget.set('value',this.object);
     34            this._refreshURL();
     35            this._loadResponses();
     36        },
     37        _refreshURL: function() {
     38            if ( this.object.mode === "open" ) {
     39                this.runURLNode.innerHTML =
     40                    this._link(this._buildGeneralURL(this.object));
    2741            } else {
    28                 throw "No valid uid or survey passed!";
     42                this.runURLNode.innerHTML =
     43                    "No general URL. Add individual respondents below.";
    2944            }
    3045        },
    31         _loadSurveyRun: function() {
    32             when(surveyRuns.load(this.surveyRunId))
    33             .then(lang.hitch(this,function(surveyRun){
    34                 this.surveyRun = surveyRun;
    35                 this.refreshSurveyRun();
    36                 this._loadResponses();
    37             }));
    38         },
    39         refreshSurveyRun: function() {
    40             this.titleNode.innerHTML = this.surveyRun.title || "";
    41             this.surveySummaryWidget.set('value',this.surveyRun.survey);
    42             this.surveyRunWidget.set('value',this.surveyRun);
    43             this._onPropChange();
    44         },
    4546        _loadResponses: function() {
    46             responses.query({surveyRunId:surveyRuns.getId(this.surveyRun)})
     47            responses.query({surveyRunId:surveyRuns.getId(this.object)})
    4748            .then(lang.hitch(this,function(allResponses){
    4849                array.forEach(allResponses, function(response){
     
    7374        },
    7475        _onPropChange: function(e) {
    75             var surveyRun = this.surveyRunWidget.get('value');
    76             if ( surveyRun.mode === "open" ) {
    77                 this.runURLNode.innerHTML =
    78                     this._link(this._buildGeneralURL(this.surveyRun));
    79             } else {
    80                 this.runURLNode.innerHTML =
    81                     "No general URL. Add individual respondents below.";
     76            if ( this.surveyRunWidget.validate() ) {
     77                lang.mixin(this.object,this.surveyRunWidget.get('value'));
     78                this._refreshURL();
    8279            }
     80            this.markDirty();
    8381        },
    8482        _buildGeneralURL: function(surveyRun) {
    85             return 'response.html#!/surveyRuns/'+surveyRuns.getId(surveyRun)+'!secret='+surveyRun.secret;
     83            return 'response.html#'+Path.format(surveyRuns.getObjectPath(surveyRun),{secret:surveyRun.secret});
    8684        },
    8785        _buildResponseURL: function(response) {
    88             return 'response.html#!/responses/'+responses.getId(response)+'!secret='+response.secret;
     86            return 'response.html#'+Path.format(responses.getObjectPath(response),{secret:response.secret});
    8987        },
    9088        _link: function(url,label) {
    9189            return '<a target="_blank" href="'+url+'">'+(label || url)+'</a>';
    9290        },
     91        _save: function() {
     92            if ( this.surveyRunWidget.validate() ) {
     93                lang.mixin(this.object,this.surveyRunWidget.get('value'));
     94                return this.inherited(arguments);
     95            } else {
     96                return new Deferred.reject();
     97            }
     98        },
    9399        _onSave: function(evt) {
    94             if ( this.surveyRunWidget.validate() ) {
    95                 lang.mixin(this.surveyRun,this.surveyRunWidget.get('value'));
    96 
    97                 surveyRuns.save(this.surveyRun)
    98                 .then(function() {
    99                     Router.go('/surveys');
    100                 },function(err){
    101                     Content.notify(err);
    102                 });
    103             }
     100            this._save();
     101            if ( evt ) { event.stop(evt); }
     102            return false;
     103        },
     104        _onSaveAndClose: function(evt) {
     105            this._save()
     106            .then(function() {
     107                Router.go(surveys.getCollectionPath());
     108            });
    104109            if ( evt ) { event.stop(evt); }
    105110            return false;
    106111        },
    107112        _onDiscard: function(evt) {
    108             Router.go('/surveys');
     113            this.markClean();
     114            Router.go(surveys.getCollectionPath());
    109115            if ( evt ) { event.stop(evt); }
    110116            return false;
Note: See TracChangeset for help on using the changeset viewer.