source: Dev/trunk/src/client/qed-client/model/classes/_View.js

Last change on this file was 492, checked in by hendrikvanantwerpen, 11 years ago
  • Enable/disable buttons on content change.
  • One place to do date formatting, because it was going wrong again.
  • Serialize questions in survey properly.
  • _ComplexValueMixin consumes submit events, but does trigger outer forms if present.
  • Trigger dialog show/hide for login only after previous effect is finished.
  • Check that documents are actually valid, not just that validator returned a result.
  • Validate email and timestamp formats.
  • Prepared for live runs.
File size: 1.5 KB
Line 
1define([
2    "../../store/JsonRest",
3    "dojo/Deferred",
4    "dojo/_base/declare",
5    "dojo/_base/json",
6    "dojo/_base/lang",
7    "dojo/date/stamp",
8    "dojo/store/util/QueryResults"
9], function(JsonRest, Deferred, declare, json, lang, stamp, queryResults) {
10
11    var _View = declare([],{
12        _collection: null,
13        _store: null,
14        constructor: function() {
15            if ( this._collection === null ) {
16                throw new Error("You must specify a concrete collection.");
17            }
18            this._store = new JsonRest({
19                target: '/api/'+this._collection+'/',
20                idProperty: '_id'
21            });
22        },
23        _deserializeError: function(err) {
24            return new Deferred().reject(json.fromJson(err.responseText));
25        },
26        _doDeserialize: function(obj) {
27            obj = lang.clone(obj);
28            return this._deserialize(obj) || obj;
29        },
30        _deserialize: function(obj) {
31            console.warn("You may want to override _deserialize for concrete types.");
32        },
33        query: function(query) {
34            return queryResults(this._store.query(query).map(lang.hitch(this,'_doDeserialize')));
35        },
36        getId: function(obj) {
37            return obj._id;
38        },
39        getCollectionPath: function() {
40            return '/'+this._collection;
41        },
42        _parseDate: function(str) {
43            return stamp.fromISOString(str);
44        }
45    });
46
47    return _View;
48
49});
Note: See TracBrowser for help on using the repository browser.