Changeset 263 for Dev/branches/rest-dojo-ui/client/rft/content.js
- Timestamp:
- 02/16/12 14:47:39 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/rest-dojo-ui/client/rft/content.js
r260 r263 1 define(['dojo/_base/declare','dojo/_base/connect','dojo/_base/xhr', 'dojo/dom-construct',2 'dojo/ dom-attr','dojo/_base/lang','dojo/_base/Deferred','dojo/hash',3 'dojo/io-query','d ojo/_base/json','dijit','rft/util'],4 function(declare,connect,xhr, domConstruct,attr,lang,Deferred,hash,uriQuery,json,dijit,util){1 define(['dojo/_base/declare','dojo/_base/connect','dojo/_base/xhr', 2 'dojo/_base/lang','dojo/_base/Deferred','dojo/hash', 3 'dojo/io-query','dijit','rft/util','rft/ui/_Page'], 4 function(declare,connect,xhr,lang,Deferred,hash,uriQuery,dijit,util,_Page){ 5 5 return new (function() { 6 6 var self = this; 7 var current = ""; 7 var currentHash = ""; 8 var currentPage = null; 8 9 9 10 var HRI = declare(null,{ 10 11 constructor: function() { 11 this._path = '/';12 this._path = this._fixPath('/'); 12 13 this._args = {}; 13 14 if ( arguments.length == 1 ) { … … 54 55 function _goTo(hri,replace) { 55 56 var contentPane = dijit.byId('content'); 56 var d = new Deferred();57 var dfd = new Deferred(); 57 58 var newHash = hri.hash(); 58 if ( current == newHash ) { 59 d.resolve(); 60 return d.promise; 59 60 // if already there, return 61 if ( currentHash === newHash ) { 62 dfd.resolve(); 63 return dfd.promise; 61 64 } 62 current = newHash; 65 66 // check if we can leave current page 67 if ( currentPage ) { 68 if ( currentPage.onLeave() === false ) { 69 dfd.reject(); 70 return dfd.promise; 71 } 72 } 73 74 // update hash 75 currentHash = newHash; 63 76 hash(newHash,replace); 77 78 // load html 79 var pageUrl = 'pages'+hri.path()+'.html'; 64 80 xhr.get({ 65 url: 'pages'+hri.path()+'.html',81 url: pageUrl, 66 82 failOk: true 67 83 }) 84 85 // initialize page or create error message 68 86 .then(function(html){ 69 var root = domConstruct.toDom(html) 70 var props = json.toJson(hri.args()); 71 props = props.slice(1,props.length-2); 72 if ( props ) 73 attr.set(root,'data-rft-props',props); 74 contentPane.set('content',root); 75 d.resolve(); 87 currentPage = new _Page({ 88 templateString: html, 89 pageQuery: hri.args() 90 }); 91 contentPane.set('content',currentPage); 92 dfd.resolve(); 76 93 },function(){ 77 contentPane.set('content',"Page "+hri.path()+" not found."); 78 d.reject(); 94 currentPage = new _Page({ 95 templateString: "<div>Page "+hri.path()+" not found.</div>" 96 }); 97 contentPane.set('content',currentPage); 98 dfd.reject(); 79 99 }); 80 return d .promise;100 return dfd.promise; 81 101 } 82 102 83 103 self.initial = function(path,args) { 84 if ( current ) {104 if ( currentHash ) { 85 105 var dfd = new Deferred(); 86 dfd.resolve d();106 dfd.resolve(); 87 107 return dfd.promise; 88 108 }
Note: See TracChangeset
for help on using the changeset viewer.