Changeset 257 for Dev/branches/rest-dojo-ui/client/rft
- Timestamp:
- 02/13/12 19:18:57 (13 years ago)
- Location:
- Dev/branches/rest-dojo-ui/client/rft
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/rest-dojo-ui/client/rft/content.js
r256 r257 1 define(['dojo/_base/connect','dojo/_base/xhr','dojo/_base/Deferred','dojo/hash'],function(connect,xhr,Deferred,hash){ 2 return new (function() { 3 var self = this; 4 var current = ""; 1 define(['dojo/_base/declare','dojo/_base/connect','dojo/_base/xhr','dojo/_base/lang','dojo/_base/Deferred','dojo/hash','dojo/io-query','dijit/registry','dijit','rft/util','rft/ui/Page'], 2 function(declare,connect,xhr,lang,Deferred,hash,uriQuery,registry,dijit,util,Page){ 3 return new (function() { 4 var self = this; 5 var current = ""; 5 6 6 function init() { 7 connect.subscribe('/dojo/hashchange', function(){ 8 var url = hash(); 9 self.goTo(url); 7 var HRI = declare(null,{ 8 constructor: function(){ 9 this._path = '/'; 10 this._args = {}; 11 if ( arguments.length == 1 ) { 12 this.hash(arguments[0]); 13 } else if ( arguments.length == 2 ) { 14 this.path(arguments[0]); 15 this.args(arguments[1]); 16 } 17 }, 18 path: function(path) { 19 if ( path ) 20 this._path = this._fixPath(path); 21 return this._path; 22 }, 23 args: function(args) { 24 if ( args && lang.isObject(args) ) 25 this._args = args; 26 return this._args; 27 }, 28 hash: function(hash) { 29 if ( hash && lang.isString(hash) ) { 30 var parts = hash.split('!'); 31 if ( parts[1] ) 32 this._path = this._fixPath(parts[1]); 33 if ( parts[2] ) 34 this._args = uriQuery.queryToObject(parts[2]); 35 } 36 return '!'+this._path+'!'+uriQuery.objectToQuery(this._args); 37 }, 38 _fixPath: function(path) { 39 if ( !lang.isString(path) || util.isEmptyString(path) ) { 40 path = "/"; 41 } 42 if ( path[0] != '/' ) { 43 path = '/'+path; 44 } 45 if ( path[path.length-1] == '/' ) { 46 path = path + "index"; 47 } 48 return path; 49 } 10 50 }); 11 }12 51 13 self.initial = function(location) { 14 if ( current ) { 15 self.goTo(location); 16 } 17 var url = hash(); 18 self.goTo(url || location); 19 } 20 21 self.goTo = function(location) { 22 var contentPane = dijit.byId('content'); 23 var d = new Deferred(); 24 if ( current == location ) { 25 d.resolve(); 52 function _goTo(hri,replace) { 53 var contentPane = dijit.byId('content'); 54 var d = new Deferred(); 55 var newHash = hri.hash(); 56 if ( current == newHash ) { 57 d.resolve(); 58 return d.promise; 59 } 60 current = newHash; 61 hash(newHash,replace); 62 xhr.get({ 63 url: 'pages'+hri.path()+'.html' 64 }) 65 .then(function(html){ 66 contentPane.set('content',html); 67 var widgets = registry.findWidgets(contentPane.containerNode); 68 for(var i in widgets) { 69 if ( widgets[i].isInstanceOf(Page) ) { 70 widgets[i].init(hri.args()); 71 break; 72 } 73 } 74 d.resolve(); 75 },function(){ 76 contentPane.set('content',"Page "+hri.path()+" not found."); 77 d.reject(); 78 }); 26 79 return d.promise; 27 80 } 28 81 29 current = location; 30 hash(location); 31 xhr.get({ 32 url: 'pages/'+location+'/'+location+'.html' 33 }) 34 .then(function(content){ 35 contentPane.set('content',content); 36 d.resolve(); 37 },function(){ 38 contentPane.set('content',"Page "+location+" not found."); 39 d.reject(); 82 self.initial = function(path,args) { 83 if ( current ) { 84 return; 85 } 86 if ( hash() ) { 87 var hri = new HRI(hash()); 88 _goTo(hri, true); 89 } else { 90 _goTo(new HRI(path,args)); 91 } 92 } 93 94 self.goTo = function(path,args) { 95 _goTo(new HRI(path,args)); 96 } 97 98 connect.subscribe('/dojo/hashchange', function(){ 99 _goTo(new HRI(hash())); 40 100 }); 41 return d.promise; 42 } 43 44 init(); 45 })(); 46 }); 101 102 })(); 103 }); -
Dev/branches/rest-dojo-ui/client/rft/ui/Page.js
r256 r257 2 2 function(declare,_WidgetBase,_Container){ 3 3 return declare('rft.ui.Page',[_WidgetBase,_Container],{ 4 init: function(args){ 5 } 4 6 }); 5 7 });
Note: See TracChangeset
for help on using the changeset viewer.