gridstack-8.x-2.5/js/admin/gridstack.admin.backbone.model.js
js/admin/gridstack.admin.backbone.model.js
/**
* @file
* Provides GridStack Backbone.Model.
*/
(function (Drupal, Backbone, _, window) {
'use strict';
Drupal.gridstack = Drupal.gridstack || {};
_.each(['base', 'models', 'collections'], function (key) {
Drupal.gridstack[key] = Drupal.gridstack[key] || {};
});
/**
* The GridStack models.
*/
Drupal.gridstack.models.Box = Backbone.Model.extend({
defaults: function () {
return _.extend(Drupal.gridstack.base.getDefaultBox(), {
id: null,
index: 1,
nested: [],
gid: null,
deleted: false
});
},
getDataToSave: function (node) {
var me = this;
node = node || me.attributes;
return Drupal.gridstack.base.node(node);
},
getDataNestedToSave: function () {
var me = this;
var nested = [];
var nodes = me.get('nested') || [];
if (nodes.length) {
nested = _.map(nodes, function (node) {
return me.getDataToSave(node) || [];
}, this);
}
return nested;
},
initialize: function (o) {
var me = this;
o = o || {};
o.index = _.isUndefined(o.index) ? me.get('index') : o.index;
me.set(Drupal.gridstack.base.attributes(o), {
silent: true
});
}
});
/**
* The GridStack box collections.
*/
Drupal.gridstack.collections.Boxes = Backbone.Collection.extend({
model: Drupal.gridstack.models.Box
});
})(Drupal, Backbone, _, this);
