Changeset 292 for Dev/branches/rest-dojo-ui/client/rft/content.js
- Timestamp:
- 02/28/12 16:19:52 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/rest-dojo-ui/client/rft/content.js
r274 r292 19 19 * this e.g. to ask confirmation of changed values are not saved. 20 20 */ 21 define(['dojo/_base/declare','dojo/_base/connect','dojo/_base/xhr', 22 'dojo/_base/lang','dojo/_base/Deferred','dojo/hash', 21 define(['dojo/_base/declare','dojo/_base/connect','dojo/_base/xhr','dojo/_base/json', 22 'dojo/_base/lang','dojo/_base/Deferred','dojo/hash','dojo/dom-attr','dojo/dom-construct', 23 23 'dojo/io-query','dijit','rft/util','rft/ui/_Page'], 24 function(declare,connect,xhr, lang,Deferred,hash,uriQuery,dijit,util,_Page){24 function(declare,connect,xhr,json,lang,Deferred,hash,attr,domConstruct,uriQuery,dijit,util,_Page){ 25 25 return new (function() { 26 26 var self = this; 27 var currentHash = ""; 28 var currentPage = null; 29 27 30 28 var HRI = declare(null,{ 31 29 constructor: function() { … … 73 71 }); 74 72 73 var currentHri = null; 74 var currentPage = null; 75 75 76 function _goTo(hri,replace) { 76 77 var contentPane = dijit.byId('content'); 77 78 var dfd = new Deferred(); 78 var newHash = hri.hash();79 79 80 80 // if already there, return 81 if ( currentH ash === newHash) {81 if ( currentHri && currentHri.hash() === hri.hash() ) { 82 82 dfd.resolve(); 83 83 return dfd.promise; … … 88 88 if ( currentPage.onLeave() === false ) { 89 89 // restore hash if changed by hand or back button 90 hash(currentH ash);90 hash(currentHri.hash()); 91 91 dfd.reject(); 92 92 return dfd.promise; … … 95 95 } 96 96 97 function mixinArgs(node) { 98 var props = {}; 99 if ( attr.has(node,'data-dojo-props') ) { 100 props = json.fromJson(attr.get(node,'data-dojo-props')); 101 } 102 lang.mixin(props,{pageArgs:hri.args()}); 103 var jsonStr = json.toJson(props); 104 attr.set(node,'data-dojo-props',jsonStr.slice(1,jsonStr.length-1)); 105 } 106 97 107 // update hash 98 currentH ash = newHash;99 hash( newHash,replace);108 currentHri = hri; 109 hash(hri.hash(),replace); 100 110 101 111 // load html … … 108 118 // initialize page or create error message 109 119 .then(function(html){ 110 contentPane.set('content',html); 111 var rootNode = contentPane.containerNode.firstChild; 120 var rootNode = domConstruct.toDom(html); 121 mixinArgs(rootNode); 122 contentPane.set('content',rootNode); 112 123 currentPage = dijit.byNode(rootNode); 113 124 if ( !currentPage ) { … … 123 134 124 135 self.initial = function(path,args) { 125 if ( currentH ash) {136 if ( currentHri ) { 126 137 var dfd = new Deferred(); 127 138 dfd.resolve(); … … 140 151 } 141 152 153 self.getArgs = function() { 154 if ( currentHri ) { 155 return currentHri.args(); 156 } else { 157 return {}; 158 } 159 } 160 142 161 connect.subscribe('/dojo/hashchange', function(){ 143 162 _goTo(new HRI(hash()));
Note: See TracChangeset
for help on using the changeset viewer.