Ignore:
Timestamp:
02/16/12 14:47:39 (13 years ago)
Author:
hendrikvanantwerpen
Message:
  • [Client] Finished page framework. See rft/ui/content.js or test files for details.
  • [Client] Allow login by pressing Enter.
  • [API] On exception include details in json response.
  • [Server Use Exceptions when save() fails, iso return values.
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','dojo/_base/json','dijit','rft/util'],
    4     function(declare,connect,xhr,domConstruct,attr,lang,Deferred,hash,uriQuery,json,dijit,util){
     1define(['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){
    55        return new (function() {
    66            var self = this;
    7             var current = "";
     7            var currentHash = "";
     8            var currentPage = null;
    89           
    910            var HRI = declare(null,{
    1011                constructor: function() {
    11                     this._path = '/';
     12                    this._path = this._fixPath('/');
    1213                    this._args = {};
    1314                    if ( arguments.length == 1 ) {
     
    5455            function _goTo(hri,replace) {
    5556                var contentPane = dijit.byId('content');
    56                 var d = new Deferred();
     57                var dfd = new Deferred();
    5758                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;
    6164                }
    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;
    6376                hash(newHash,replace);
     77               
     78                // load html
     79                var pageUrl = 'pages'+hri.path()+'.html';
    6480                xhr.get({
    65                     url: 'pages'+hri.path()+'.html',
     81                    url: pageUrl,
    6682                    failOk: true
    6783                })
     84               
     85                // initialize page or create error message
    6886                .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();
    7693                },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();
    7999                });
    80                 return d.promise;
     100                return dfd.promise;
    81101            }
    82102
    83103            self.initial = function(path,args) {
    84                 if ( current ) {
     104                if ( currentHash ) {
    85105                    var dfd = new Deferred();
    86                     dfd.resolved();
     106                    dfd.resolve();
    87107                    return dfd.promise;
    88108                }
Note: See TracChangeset for help on using the changeset viewer.