Ignore:
Timestamp:
02/13/12 19:18:57 (13 years ago)
Author:
hendrikvanantwerpen
Message:

Changed hashtag to hashbang syntax and allow parameters to be passed to pages.
Added simple session page that dumps retrieved session in page content.

Location:
Dev/branches/rest-dojo-ui
Files:
3 added
3 deleted
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • Dev/branches/rest-dojo-ui/client/pages/sessions.html

    r256 r257  
    11<div data-dojo-type="rft.ui.Page">
    2     <script type="dojo/method" data-dojo-event="startup">
     2    <script type="dojo/method" data-dojo-event="init" data-dojo-args="args">
    33        require(['dojo/store/JsonRest','dojox/grid/DataGrid',
    44                'dojo/data/ObjectStore','dojo/domReady!'],
  • 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 = "";
     1define(['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 = "";
    56           
    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                }
    1050            });
    11         }
    1251
    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                });
    2679                return d.promise;
    2780            }
    2881
    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()));
    40100            });
    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  
    22function(declare,_WidgetBase,_Container){
    33    return declare('rft.ui.Page',[_WidgetBase,_Container],{
     4        init: function(args){
     5        }
    46    });
    57});
Note: See TracChangeset for help on using the changeset viewer.