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/app/Router.js

    r487 r490  
    11define([
    2     'dojo/_base/declare',
    3     'dojo/hash',
    4     'dojo/topic',
    5     './Content',
    6     './Page',
    7     './Path'
    8 ],function(declare,hash,topic,Content,Page,Path){
     2    "./Content",
     3    "./Page",
     4    "./Path",
     5    "dojo/_base/declare",
     6    "dojo/_base/event",
     7    "dojo/_base/lang",
     8    "dojo/_base/window",
     9    "dojo/hash",
     10    "dojo/on",
     11    "dojo/topic"
     12], function(Content, Page, Path, declare, event, lang, window, hash, on, topic) {
    913
    1014    var Router = declare(null,{
     
    1216        _routes: null,
    1317        _previousHash: null,
     18        _beforePreviousHash: null,
    1419
    1520        constructor: function() {
     
    1823        startup: function() {
    1924            if ( this._started ) { return; }
    20             if ( !Content._started ) {
    21                 Content.startup();
    22             }
     25            Content.startup();
    2326            this._started = true;
    24 
    25             var self = this;
    26 
    2727            if ( hash() === "" ) {
    2828                hash(Path.getDefault());
    2929            }
    30             this._handlePathChange(hash());
    31                         topic.subscribe("/dojo/hashchange", function(){
    32                 self._handlePathChange.apply(self,arguments);
    33             });
     30            this._handleHashChange(hash());
     31            window.onbeforeunload = function() {
     32                return Content.isDirty() && "Unsaved changes, leave anyway?";
     33            };
     34                        topic.subscribe("/dojo/hashchange",
     35                            lang.hitch(this,'_handleHashChange'));
    3436        },
    3537        register: function(route) {
     
    6870            return callback;
    6971        },
    70         _handlePathChange: function(newHash) {
    71             if ( this._previousHash === newHash ) { return; }
     72        _handleHashChange: function(newHash) {
     73            if ( this._previousHash === newHash ) {
     74                return false;
     75            }
     76            if ( Content.isDirty() ) {
     77                if ( !confirm("Unsaved changes, leave anyway?") ) {
     78                    var probablyBack = this._beforePreviousHash === newHash;
     79                    // if we think we go backwards, we re-add the history
     80                    // entry, otherwise we reset the current one,
     81                    // resulting in minor annoyance of double back
     82                    // behaviour.
     83                    hash(this._previousHash,!probablyBack);
     84                    return false;
     85                } else {
     86                    Content.markClean();
     87                }
     88            }
     89            this._beforePreviousHash = this._previousHash;
    7290            this._previousHash = newHash;
    7391            for (var i = this._routes.length-1; i >= 0; i--) {
     
    7896                        route.callback(params);
    7997                    } catch(err) {
    80                         console.error("Page change failed with",err,err.toString());
     98                        console.error("Page change failed with",err,err.stack,err.toString());
    8199                    }
    82                     return;
     100                    return true;
    83101                }
    84102            }
     
    88106                console.error("Default page failed.",err);
    89107            }
     108            return true;
    90109        },
    91110        go: function(path,args) {
    92111            if ( !this._started ) { return; }
    93112            var newHash = Path.format(path,args);
    94             this._handlePathChange(newHash);
    95113            hash(newHash);
    96114        },
Note: See TracChangeset for help on using the changeset viewer.