Ignore:
Timestamp:
12/04/12 16:29:49 (12 years ago)
Author:
hendrikvanantwerpen
Message:

Support data validation and increase dendency separation.

Added json-schema validation before documents are saved. Acts both as
a safe-guard and as a reference of the data model.

Added directory for server related material. For now it contains scripts
to configure CouchDB and check validity of documents against the schema.

Started separating out parts that depend on the data model from parts
that do not.

File:
1 edited

Legend:

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

    r414 r415  
    1010   
    1111    function getCouchError(err){
    12         return (err.response && err.response.data)
    13                 ? json.fromJson(err.response.data)
    14                 : "Unknown error.";
     12        var reason = err.response &&
     13                     err.response.data &&
     14                     json.fromJson(err.response.data).reason;
     15        return reason || "Unknown error.";
    1516    }
    1617
     
    7475            return dfd.promise;
    7576        },
     77        validate: function(object) {
     78            return true;
     79        },
    7680        put: function(object, options){
    7781             // summary:
     
    8387             //         id: String
    8488             //
     89
     90            if ( !this.validate(object) ) {
     91                var dfd = new Deferred();
     92                dfd.reject("Invalid document.");
     93                return dfd.promise;
     94            }
     95            return this._putValid(object, options);
     96
     97        },
     98        _putValid: function(object,options) {
     99            var dfd = new Deferred();
    85100            options = options || {};
    86 
    87             var dfd = new Deferred();
    88101            var id = options.id ? options.id : this.getIdentity(object);
    89             var hasId = typeof id != "undefined";
     102            var hasId = typeof id !== "undefined";
    90103            xhr(hasId ? "PUT" : "POST", {
    91104                url: hasId ? this.target + id : this.target,
Note: See TracChangeset for help on using the changeset viewer.