Security update to Drupal 8.4.6
[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(/** @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));