Added Entity and Entity Reference Revisions which got dropped somewhere along the...
[yaffs-website] / web / core / modules / quickedit / js / models / BaseModel.es6.js
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(
8     /** @lends Drupal.quickedit.BaseModel# */ {
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           } else {
45             if (!options) {
46               options = {};
47             }
48             options.validate = true;
49           }
50         }
51         return Backbone.Model.prototype.set.call(this, key, val, options);
52       },
53     },
54   );
55 })(Drupal, Backbone);