Mercurial > hg > isophonics-drupal-site
annotate core/modules/quickedit/js/models/BaseModel.es6.js @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 129ea1e6d783 |
children |
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@17 | 6 (function(Drupal, Backbone) { |
Chris@17 | 7 Drupal.quickedit.BaseModel = Backbone.Model.extend( |
Chris@17 | 8 /** @lends Drupal.quickedit.BaseModel# */ { |
Chris@17 | 9 /** |
Chris@17 | 10 * @constructs |
Chris@17 | 11 * |
Chris@17 | 12 * @augments Backbone.Model |
Chris@17 | 13 * |
Chris@17 | 14 * @param {object} options |
Chris@17 | 15 * Options for the base model- |
Chris@17 | 16 * |
Chris@17 | 17 * @return {Drupal.quickedit.BaseModel} |
Chris@17 | 18 * A quickedit base model. |
Chris@17 | 19 */ |
Chris@17 | 20 initialize(options) { |
Chris@17 | 21 this.__initialized = true; |
Chris@17 | 22 return Backbone.Model.prototype.initialize.call(this, options); |
Chris@17 | 23 }, |
Chris@0 | 24 |
Chris@17 | 25 /** |
Chris@17 | 26 * Set a value on the model |
Chris@17 | 27 * |
Chris@17 | 28 * @param {object|string} key |
Chris@17 | 29 * The key to set a value for. |
Chris@17 | 30 * @param {*} val |
Chris@17 | 31 * The value to set. |
Chris@17 | 32 * @param {object} [options] |
Chris@17 | 33 * Options for the model. |
Chris@17 | 34 * |
Chris@17 | 35 * @return {*} |
Chris@17 | 36 * The result of `Backbone.Model.prototype.set` with the specified |
Chris@17 | 37 * parameters. |
Chris@17 | 38 */ |
Chris@17 | 39 set(key, val, options) { |
Chris@17 | 40 if (this.__initialized) { |
Chris@17 | 41 // Deal with both the "key", value and {key:value}-style arguments. |
Chris@17 | 42 if (typeof key === 'object') { |
Chris@17 | 43 key.validate = true; |
Chris@17 | 44 } else { |
Chris@17 | 45 if (!options) { |
Chris@17 | 46 options = {}; |
Chris@17 | 47 } |
Chris@17 | 48 options.validate = true; |
Chris@17 | 49 } |
Chris@17 | 50 } |
Chris@17 | 51 return Backbone.Model.prototype.set.call(this, key, val, options); |
Chris@17 | 52 }, |
Chris@0 | 53 }, |
Chris@17 | 54 ); |
Chris@17 | 55 })(Drupal, Backbone); |