source: Dev/branches/rest-dojo-ui/client/rft/store.js @ 417

Last change on this file since 417 was 417, checked in by hendrikvanantwerpen, 12 years ago

Put all model dependent code in one place. More separation of general and domain code.

File size: 1.0 KB
Line 
1define([
2    'dojo/date/stamp',
3    'dojo/store/Cache',
4    'dojo/store/Memory',
5    'dojox/json/schema',
6    './model/schema',
7    './store/CouchStore'
8],function(stamp,Cache,Memory,jsonSchema,schema,CouchStore){
9   
10    var couchStore = new CouchStore({
11        target: 'data/couch/',
12        validate: function(object) {
13            var result = jsonSchema.validate(object,schema);
14            if ( result.valid ) {
15                return true;
16            } else {
17                console.log("Found error ",result," for invalid object ",object);
18                return false;
19            }
20        }
21    });
22    var memoryStore = new Memory();
23    var cacheStore = new Cache(couchStore,memoryStore,{});
24
25    var store = cacheStore;
26    store.formatDate = function(date){
27        return stamp.toISOString(date,{zulu:true});
28    };
29    store.parseDate = function(dateString){
30        return stamp.fromISOString(dateString);
31    };
32    store.timestamp = function() {
33        return this.formatDate(new Date());
34    };
35    return store;
36
37});
Note: See TracBrowser for help on using the repository browser.