ducky/web

Paddy 2015-05-31 Parent:99a43a6d1d30 Child:d51e39bf909c

6:a641906b8267 Go to Latest

ducky/web/src/models/profiles.js

Enable catch-all in our ValidationError component. We're doing this an ugly, hacky way. But it works, and right now, that's what counts. To match our params/fields/headers properties on the ValidationError component, we're going to add the notParams/notFields/notHeaders properties--they match any error _not_ targeting those params/fields/headers. Basically, "any error that wouldn't be caught by these filters". Which is an ugly, but workable, solution for a catch-all ValidationError--just tell it to catch anything but the params/fields/headers that are being handled by the other ValidationErrors. Our implementation of this in the RegisterPage component validates (ha!) that it's at least workable model, if not overly pretty. Also, I anticipate some human error bugs in the future, where one of the field-specific ValidationErrors gets updated and the catch-all ValidationError does not. But whatever. For now, this is Good Enoughâ„¢.

History
1 import Collection from 'ampersand-collection'
2 import Sync from 'ampersand-sync'
3 import Profile from './profile'
4 import config from '../config'
5 import isObject from 'lodash.isobject'
7 export default Collection.extend({
8 model: Profile,
9 url: config.urlBase + '/profiles',
10 ajaxConfig: {
11 headers: {
12 'Content-Type': 'application/json',
13 }
14 },
16 register (email, passphrase) {
17 let options = {
18 data: JSON.stringify({
19 'email': email,
20 'passphrase': passphrase,
21 })
22 }
23 let moc = this
24 options.success = function(resp) {
25 if (!resp.profiles || resp.profiles.length < 1) {
26 return false
27 }
28 let serverAttrs = moc.parse(resp.profiles[0], options)
29 if (options.wait) serverAttrs = assign({}, serverAttrs)
30 if (isObject(serverAttrs) && !moc.add(serverAttrs, options)) {
31 return false
32 }
33 moc.trigger('sync', moc, resp, options)
34 }
35 options.error = function(resp) {
36 moc.trigger('error', moc, resp, options)
37 }
38 let sync = Sync('create', moc, options)
39 return sync
40 },
41 })