Mercurial > hg > isophonics-drupal-site
comparison core/modules/quickedit/js/models/BaseModel.es6.js @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 /** | |
2 * @file | |
3 * A Backbone Model subclass that enforces validation when calling set(). | |
4 */ | |
5 | |
6 (function (Drupal, Backbone) { | |
7 Drupal.quickedit.BaseModel = Backbone.Model.extend(/** @lends Drupal.quickedit.BaseModel# */{ | |
8 | |
9 /** | |
10 * @constructs | |
11 * | |
12 * @augments Backbone.Model | |
13 * | |
14 * @param {object} options | |
15 * Options for the base model- | |
16 * | |
17 * @return {Drupal.quickedit.BaseModel} | |
18 * A quickedit base model. | |
19 */ | |
20 initialize(options) { | |
21 this.__initialized = true; | |
22 return Backbone.Model.prototype.initialize.call(this, options); | |
23 }, | |
24 | |
25 /** | |
26 * Set a value on the model | |
27 * | |
28 * @param {object|string} key | |
29 * The key to set a value for. | |
30 * @param {*} val | |
31 * The value to set. | |
32 * @param {object} [options] | |
33 * Options for the model. | |
34 * | |
35 * @return {*} | |
36 * The result of `Backbone.Model.prototype.set` with the specified | |
37 * parameters. | |
38 */ | |
39 set(key, val, options) { | |
40 if (this.__initialized) { | |
41 // Deal with both the "key", value and {key:value}-style arguments. | |
42 if (typeof key === 'object') { | |
43 key.validate = true; | |
44 } | |
45 else { | |
46 if (!options) { | |
47 options = {}; | |
48 } | |
49 options.validate = true; | |
50 } | |
51 } | |
52 return Backbone.Model.prototype.set.call(this, key, val, options); | |
53 }, | |
54 | |
55 }); | |
56 }(Drupal, Backbone)); |