Changeset 410 for Dev/branches/rest-dojo-ui/client/rft/app/Router.js
- Timestamp:
- 09/07/12 16:59:14 (13 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/rest-dojo-ui/client/rft/app/Router.js
r407 r410 4 4 'dojo/io-query', 5 5 'dojo/topic', 6 './ Page',7 ' dijit/registry'8 ],function(declare,hash,ioQuery,topic, Page,registry){6 './Content', 7 './Page' 8 ],function(declare,hash,ioQuery,topic,Content,Page){ 9 9 10 11 var Controller = declare(null,{ 10 var Router = declare(null,{ 12 11 _started: false, 13 12 _routes: null, 14 _container: null,15 13 _previousHash: null, 16 _previousContent: null,17 14 18 15 _paramMatch: /:(\w[\w\d]*)/g, 19 _paramReplace: "([^\\/ ]+)",16 _paramReplace: "([^\\/!]+)", 20 17 21 18 constructor: function() { … … 24 21 startup: function() { 25 22 if ( this._started ) { return; } 23 if ( !Content._started ) { 24 Content.startup(); 25 } 26 this._started = true; 26 27 27 28 var self = this; 28 29 this._container = registry.byId('content');30 if ( !this._container || !this._container.addChild ) {31 throw new Error("Cannot find container widget with id 'content'.");32 }33 this._started = true;34 29 35 30 if ( hash() === "" ) { … … 42 37 }, 43 38 register: function(route) { 39 if ( this._started ) { 40 console.warn('Registering routes after startup() is called is discouraged.'); 41 } 44 42 var self = this; 45 43 var callback; 46 44 if ( route.callback ) { 47 45 callback = function(params){ 48 self._setContent(route.callback(params));46 Content.set(route.callback(params)); 49 47 }; 50 48 } else if ( route.redirect ) { … … 54 52 } else if ( route.constructor ) { 55 53 callback = function(params){ 56 self._setContent( new route.constructor(params) );54 Content.set( new route.constructor(params) ); 57 55 }; 58 56 } … … 75 73 } 76 74 path = path.replace(this._paramMatch, this._paramReplace); 77 route.regexp = new RegExp('^!'+path+'(! .*)?$');75 route.regexp = new RegExp('^!'+path+'(!(.*))?$'); 78 76 return route; 79 77 }, … … 94 92 } 95 93 96 if ( result.length > numParams+1 ) {97 params.options = ioQuery.queryToObject(result[numParams ]);94 if ( result.length > numParams+1 && result[numParams+2] ) { 95 params.options = ioQuery.queryToObject(result[numParams+2]); 98 96 } 99 97 … … 126 124 return hash; 127 125 }, 128 _setContent: function(widget) {129 if ( this._previousContent ) {130 this._previousContent.destroyRecursive();131 this._previousContent = null;132 }133 widget.region = 'center';134 this._container.addChild(widget);135 this._previousContent = widget;136 },137 126 _defaultCallback: function() { 138 this._setContent(new Page({127 Content.set(new Page({ 139 128 templateString: "<div>Requested page not found. Go <a href=\"#!/\">home</a>.</div>" 140 129 })); … … 142 131 }); 143 132 144 return new Controller();133 return new Router(); 145 134 });
Note: See TracChangeset
for help on using the changeset viewer.