Ignore:
Timestamp:
12/16/12 20:07:35 (12 years ago)
Author:
hendrikvanantwerpen
Message:

We can store answers for surveys now!

Introduces SurveyRun?, which can be edited. Workflow not quite clear yet. A
running survey can be accessed to leave a response. When the response
has an ID, it is loaded (used for closed surveys and continuations). A
researcher cannot create responses yet. He should also be able to add
comments to responses (that he creates).

Introduced caching of store requests.

Factored out path matching and formatting.

Put object creation in separate classes, to localize model/storage
dependency. Not consistent at the moment.

Location:
Dev/branches/rest-dojo-ui/client/qed/app
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • Dev/branches/rest-dojo-ui/client/qed/app/Notifications.js

    r418 r420  
    33    return declare([Toaster],{
    44        positionDirection: "br-up",
    5         duration: 1000
     5        duration: 3000
    66    });
    77});
  • Dev/branches/rest-dojo-ui/client/qed/app/Router.js

    r410 r420  
    22    'dojo/_base/declare',
    33    'dojo/hash',
    4     'dojo/io-query',
    54    'dojo/topic',
    65    './Content',
    7     './Page'
    8 ],function(declare,hash,ioQuery,topic,Content,Page){
     6    './Page',
     7    './Path'
     8],function(declare,hash,topic,Content,Page,Path){
    99
    1010    var Router = declare(null,{
     
    1212        _routes: null,
    1313        _previousHash: null,
    14 
    15         _paramMatch: /:(\w[\w\d]*)/g,
    16         _paramReplace: "([^\\/!]+)",
    1714
    1815        constructor: function() {
     
    2926
    3027            if ( hash() === "" ) {
    31                 hash("#!/");
     28                hash(Path.getDefault());
    3229            }
    3330            this._handlePathChange(hash());
     
    4037                console.warn('Registering routes after startup() is called is discouraged.');
    4138            }
     39            var callback = this._normalizeCallback(route);
     40            if ( callback ) {
     41                if ( route.path ) {
     42                    route.callback = callback;
     43                    route.path = new Path(route.path);
     44                    this._routes.push(route);
     45                } else {
     46                    this._defaultCallback = callback;
     47                }
     48            } else {
     49                console.warn("Route "+(route.path||"default")+" has no action.");
     50            }
     51        },
     52        _normalizeCallback: function(route) {
    4253            var self = this;
    43             var callback;
     54            var callback = null;
    4455            if ( route.callback ) {
    4556                callback = function(params){
     
    5566                };
    5667            }
    57             if ( callback ) {
    58                 if ( route.path ) {
    59                     this._routes.push(this._createRoute(route.path,callback));
    60                 } else {
    61                     this._defaultCallback = callback;
    62                 }
    63             } else {
    64                 console.warn("Route "+(route.path||"default")+" has no action.");
    65             }
    66         },
    67         _createRoute: function(path,callback) {
    68             var match, route = {};
    69             route.callback = callback;
    70             route.paramNames = [];
    71                         while((match = this._paramMatch.exec(path)) !== null){
    72                                 route.paramNames.push(match[1]);
    73                         }
    74             path = path.replace(this._paramMatch, this._paramReplace);
    75             route.regexp = new RegExp('^!'+path+'(!(.*))?$');
    76             return route;
     68            return callback;
    7769        },
    7870        _handlePathChange: function(newHash) {
    7971            if ( this._previousHash === newHash ) { return; }
    8072            this._previousHash = newHash;
    81 
    8273            for (var i = this._routes.length-1; i >= 0; i--) {
    83                 var result;
    8474                var route = this._routes[i];
    85 
    86                 if ((result = route.regexp.exec(newHash)) !== null) {
    87                     var numParams = route.paramNames.length;
    88 
    89                     var params = {};
    90                     for (var j = 0; j < numParams; j++) {
    91                         params[route.paramNames[j]] = result[j+1];
    92                     }
    93 
    94                     if ( result.length > numParams+1 && result[numParams+2] ) {
    95                         params.options = ioQuery.queryToObject(result[numParams+2]);
    96                     }
    97 
     75                var params = null;
     76                if ((params = route.path.match(newHash)) !== null) {
    9877                    try {
    9978                        route.callback(params);
    10079                    } catch(err) {
    101                         console.warn("Page change failed.",err);
     80                        console.error("Page change failed.",err);
    10281                    }
    10382                    return;
    10483                }
    10584            }
    106 
    10785            try {
    10886                this._defaultCallback();
    10987            } catch(err) {
    110                 console.warn("Default page failed.",err);
     88                console.error("Default page failed.",err);
    11189            }
    11290        },
    11391        go: function(path,args) {
    11492            if ( !this._started ) { return; }
    115             var newHash = this._pathToHash(path,args);
     93            var newHash = Path.format(path,args);
    11694            this._handlePathChange(newHash);
    11795            hash(newHash);
    11896        },
    119         _pathToHash: function(path,args) {
    120             var hash = '!'+path;
    121             if ( args ) {
    122                 hash += '!'+ioQuery.objectToQuery(args);
    123             }
    124             return hash;
    125         },
    12697        _defaultCallback: function() {
    12798            Content.set(new Page({
    128                 templateString: "<div>Requested page not found. Go <a href=\"#!/\">home</a>.</div>"
     99                templateString: "<div>Requested page not found. Go <a href=\"#"+Path.getDefault()+"\">home</a>.</div>"
    129100            }));
    130101        }
Note: See TracChangeset for help on using the changeset viewer.