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