Ignore:
Timestamp:
02/28/12 16:19:52 (13 years ago)
Author:
hendrikvanantwerpen
Message:

[Client] Added surveys list and survey details skeleton pages.
[Client] Changed method of passing parameters to pages. This still feels clumsy, because we're working against Dojo a bit with this.
[Server] Integrated REST resources for collections and objects, since they shared more than they differed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/rest-dojo-ui/client/rft/content.js

    r274 r292  
    1919 * this e.g. to ask confirmation of changed values are not saved.
    2020 */
    21 define(['dojo/_base/declare','dojo/_base/connect','dojo/_base/xhr',
    22     'dojo/_base/lang','dojo/_base/Deferred','dojo/hash',
     21define(['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',
    2323    '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){
    2525        return new (function() {
    2626            var self = this;
    27             var currentHash = "";
    28             var currentPage = null;
    29            
     27
    3028            var HRI = declare(null,{
    3129                constructor: function() {
     
    7371            });
    7472
     73            var currentHri = null;
     74            var currentPage = null;
     75           
    7576            function _goTo(hri,replace) {
    7677                var contentPane = dijit.byId('content');
    7778                var dfd = new Deferred();
    78                 var newHash = hri.hash();
    7979               
    8080                // if already there, return
    81                 if ( currentHash === newHash ) {
     81                if ( currentHri && currentHri.hash() === hri.hash() ) {
    8282                    dfd.resolve();
    8383                    return dfd.promise;
     
    8888                    if ( currentPage.onLeave() === false ) {
    8989                        // restore hash if changed by hand or back button
    90                         hash(currentHash);
     90                        hash(currentHri.hash());
    9191                        dfd.reject();
    9292                        return dfd.promise;
     
    9595                }
    9696               
     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               
    97107                // update hash
    98                 currentHash = newHash;
    99                 hash(newHash,replace);
     108                currentHri = hri;
     109                hash(hri.hash(),replace);
    100110               
    101111                // load html
     
    108118                // initialize page or create error message
    109119                .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);
    112123                    currentPage = dijit.byNode(rootNode);
    113124                    if ( !currentPage ) {
     
    123134
    124135            self.initial = function(path,args) {
    125                 if ( currentHash ) {
     136                if ( currentHri ) {
    126137                    var dfd = new Deferred();
    127138                    dfd.resolve();
     
    140151            }
    141152
     153            self.getArgs = function() {
     154                if ( currentHri ) {
     155                    return currentHri.args();
     156                } else {
     157                    return {};
     158                }
     159            }
     160
    142161            connect.subscribe('/dojo/hashchange', function(){
    143162                _goTo(new HRI(hash()));
Note: See TracChangeset for help on using the changeset viewer.