source: Dev/trunk/client/qed/store.js @ 428

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

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.

File size: 1.3 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        idProperty: couchStore.idProperty
24    });
25    var cacheStore = new Cache(couchStore,memoryStore,{
26        isLoaded: function(object) {
27            // Unfortunately we cannot determine of the full documents were
28            // loaded or not. Therefore never cache query results.
29            return false;
30        }
31    });
32
33    var store = cacheStore;
34    store.formatDate = function(date){
35        return stamp.toISOString(date,{zulu:true});
36    };
37    store.parseDate = function(dateString){
38        return stamp.fromISOString(dateString);
39    };
40    store.timestamp = function() {
41        return this.formatDate(new Date());
42    };
43    return store;
44
45});
Note: See TracBrowser for help on using the repository browser.