Changeset 490 for Dev/trunk/src/client/qed-client/app
- Timestamp:
- 03/08/14 22:51:23 (11 years ago)
- Location:
- Dev/trunk/src/client/qed-client/app
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/src/client/qed-client/app/Content.js
r443 r490 8 8 _container: null, 9 9 _previousContent: null, 10 _dirty: false, 10 11 startup: function() { 11 12 if ( this._started ) { return; } … … 32 33 } 33 34 widget.region = 'center'; 35 this._previousContent = widget; 34 36 this._container.addChild(widget); 35 this._previousContent = widget;36 37 }, 37 38 notify: function(text,type) { … … 40 41 } 41 42 this._toaster.setContent(text,type || 'message'); 43 }, 44 markDirty: function() { 45 this._dirty = true; 46 }, 47 markClean:function() { 48 this._dirty = false; 49 }, 50 isDirty: function() { 51 return this._dirty; 42 52 } 43 53 }); -
Dev/trunk/src/client/qed-client/app/Page.js
r443 r490 1 1 define([ 2 'dojo/_base/declare', 3 'dijit/_TemplatedMixin', 4 'dijit/_WidgetsInTemplateMixin', 5 'dijit/layout/BorderContainer' 6 ],function(declare,_TemplatedMixin,_WidgetsInTemplateMixin,BorderContainer){ 7 return declare([BorderContainer,_TemplatedMixin,_WidgetsInTemplateMixin],{ 8 templateString: '<div>Empty page.</div>' 2 "./Content", 3 "./Path", 4 "dijit/_TemplatedMixin", 5 "dijit/_WidgetsInTemplateMixin", 6 "dijit/layout/BorderContainer", 7 "dojo/_base/declare", 8 "dojo/_base/lang", 9 "dojo/hash" 10 ], function(Content, Path, _TemplatedMixin, _WidgetsInTemplateMixin, BorderContainer, declare, lang, hash) { 11 var Page = declare([BorderContainer,_TemplatedMixin,_WidgetsInTemplateMixin],{ 12 templateString: '<div>Empty page.</div>', 13 die: function(msg) { 14 Content.set(new Page({templateString:'<div>Error: '+msg+'</div>'})); 15 }, 16 notify: lang.hitch(Content,'notify'), 17 setURL: function(url,opts,addToHistory) { 18 hash(Path.format(url,opts),addToHistory !== true); 19 }, 20 markDirty: lang.hitch(Content,'markDirty'), 21 markClean: lang.hitch(Content,'markClean') 9 22 }); 23 return Page; 10 24 }); -
Dev/trunk/src/client/qed-client/app/Router.js
r487 r490 1 1 define([ 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) { 9 13 10 14 var Router = declare(null,{ … … 12 16 _routes: null, 13 17 _previousHash: null, 18 _beforePreviousHash: null, 14 19 15 20 constructor: function() { … … 18 23 startup: function() { 19 24 if ( this._started ) { return; } 20 if ( !Content._started ) { 21 Content.startup(); 22 } 25 Content.startup(); 23 26 this._started = true; 24 25 var self = this;26 27 27 if ( hash() === "" ) { 28 28 hash(Path.getDefault()); 29 29 } 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')); 34 36 }, 35 37 register: function(route) { … … 68 70 return callback; 69 71 }, 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; 72 90 this._previousHash = newHash; 73 91 for (var i = this._routes.length-1; i >= 0; i--) { … … 78 96 route.callback(params); 79 97 } catch(err) { 80 console.error("Page change failed with",err,err. toString());98 console.error("Page change failed with",err,err.stack,err.toString()); 81 99 } 82 return ;100 return true; 83 101 } 84 102 } … … 88 106 console.error("Default page failed.",err); 89 107 } 108 return true; 90 109 }, 91 110 go: function(path,args) { 92 111 if ( !this._started ) { return; } 93 112 var newHash = Path.format(path,args); 94 this._handlePathChange(newHash);95 113 hash(newHash); 96 114 },
Note: See TracChangeset
for help on using the changeset viewer.