2014-01-02 13:46:53 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* A Backbone Model subclass that enforces validation when calling set().
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function (Backbone) {
|
|
|
|
|
2015-10-13 22:37:56 +00:00
|
|
|
'use strict';
|
2014-01-02 13:46:53 +00:00
|
|
|
|
2015-06-06 15:55:42 +00:00
|
|
|
Drupal.quickedit.BaseModel = Backbone.Model.extend(/** @lends Drupal.quickedit.BaseModel# */{
|
2014-01-02 13:46:53 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
/**
|
2015-06-06 15:55:42 +00:00
|
|
|
* @constructs
|
|
|
|
*
|
|
|
|
* @augments Backbone.Model
|
|
|
|
*
|
|
|
|
* @param {object} options
|
2015-08-29 06:33:28 +00:00
|
|
|
* Options for the base model-
|
2015-06-06 15:55:42 +00:00
|
|
|
*
|
|
|
|
* @return {Drupal.quickedit.BaseModel}
|
2015-08-29 06:33:28 +00:00
|
|
|
* A quickedit base model.
|
2014-01-27 21:41:32 +00:00
|
|
|
*/
|
|
|
|
initialize: function (options) {
|
|
|
|
this.__initialized = true;
|
|
|
|
return Backbone.Model.prototype.initialize.call(this, options);
|
|
|
|
},
|
2014-01-02 13:46:53 +00:00
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
/**
|
2015-08-29 06:33:28 +00:00
|
|
|
* Set a value on the model
|
2015-06-06 15:55:42 +00:00
|
|
|
*
|
|
|
|
* @param {object|string} key
|
2015-08-29 06:33:28 +00:00
|
|
|
* The key to set a value for.
|
2015-06-06 15:55:42 +00:00
|
|
|
* @param {*} val
|
2015-08-29 06:33:28 +00:00
|
|
|
* The value to set.
|
2015-06-06 15:55:42 +00:00
|
|
|
* @param {object} [options]
|
2015-08-29 06:33:28 +00:00
|
|
|
* Options for the model.
|
2015-06-06 15:55:42 +00:00
|
|
|
*
|
|
|
|
* @return {*}
|
2015-08-29 06:33:28 +00:00
|
|
|
* The result of `Backbone.Model.prototype.set` with the specified
|
|
|
|
* parameters.
|
2014-01-27 21:41:32 +00:00
|
|
|
*/
|
|
|
|
set: function (key, val, options) {
|
|
|
|
if (this.__initialized) {
|
|
|
|
// Deal with both the "key", value and {key:value}-style arguments.
|
|
|
|
if (typeof key === 'object') {
|
|
|
|
key.validate = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!options) {
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
options.validate = true;
|
2014-01-02 13:46:53 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-27 21:41:32 +00:00
|
|
|
return Backbone.Model.prototype.set.call(this, key, val, options);
|
2014-01-02 13:46:53 +00:00
|
|
|
}
|
|
|
|
|
2014-01-27 21:41:32 +00:00
|
|
|
});
|
2014-01-02 13:46:53 +00:00
|
|
|
|
|
|
|
}(Backbone));
|