Chris@0: /** Chris@0: * DO NOT EDIT THIS FILE. Chris@0: * See the following change record for more information, Chris@0: * https://www.drupal.org/node/2815083 Chris@0: * @preserve Chris@0: **/ Chris@0: Chris@0: (function (_, Backbone, Drupal) { Chris@0: Drupal.quickedit.FieldModel = Drupal.quickedit.BaseModel.extend({ Chris@0: defaults: { Chris@0: el: null, Chris@0: Chris@0: fieldID: null, Chris@0: Chris@0: id: null, Chris@0: Chris@0: entity: null, Chris@0: Chris@0: metadata: null, Chris@0: Chris@0: acceptStateChange: null, Chris@0: Chris@0: logicalFieldID: null, Chris@0: Chris@0: state: 'inactive', Chris@0: Chris@0: isChanged: false, Chris@0: Chris@0: inTempStore: false, Chris@0: Chris@0: html: null, Chris@0: Chris@0: htmlForOtherViewModes: null Chris@0: }, Chris@0: Chris@0: initialize: function initialize(options) { Chris@0: this.set('html', options.el.outerHTML); Chris@0: Chris@0: this.get('entity').get('fields').add(this); Chris@0: Chris@0: this.set('logicalFieldID', this.get('fieldID').split('/').slice(0, 4).join('/')); Chris@0: Chris@0: Drupal.quickedit.BaseModel.prototype.initialize.call(this, options); Chris@0: }, Chris@0: destroy: function destroy(options) { Chris@0: if (this.get('state') !== 'inactive') { Chris@0: throw new Error('FieldModel cannot be destroyed if it is not inactive state.'); Chris@0: } Chris@0: Drupal.quickedit.BaseModel.prototype.destroy.call(this, options); Chris@0: }, Chris@0: sync: function sync() {}, Chris@0: validate: function validate(attrs, options) { Chris@0: var current = this.get('state'); Chris@0: var next = attrs.state; Chris@0: if (current !== next) { Chris@0: if (_.indexOf(this.constructor.states, next) === -1) { Chris@0: return '"' + next + '" is an invalid state'; Chris@0: } Chris@0: Chris@0: if (!this.get('acceptStateChange')(current, next, options, this)) { Chris@0: return 'state change not accepted'; Chris@0: } Chris@0: } Chris@0: }, Chris@0: getEntityID: function getEntityID() { Chris@0: return this.get('fieldID').split('/').slice(0, 2).join('/'); Chris@0: }, Chris@0: getViewMode: function getViewMode() { Chris@0: return this.get('fieldID').split('/').pop(); Chris@0: }, Chris@0: findOtherViewModes: function findOtherViewModes() { Chris@0: var currentField = this; Chris@0: var otherViewModes = []; Chris@0: Drupal.quickedit.collections.fields.where({ logicalFieldID: currentField.get('logicalFieldID') }).forEach(function (field) { Chris@14: if (field !== currentField && field.get('fieldID') !== currentField.get('fieldID')) { Chris@14: otherViewModes.push(field.getViewMode()); Chris@14: } Chris@0: }); Chris@0: return otherViewModes; Chris@0: } Chris@0: }, { Chris@0: states: ['inactive', 'candidate', 'highlighted', 'activating', 'active', 'changed', 'saving', 'saved', 'invalid'], Chris@0: Chris@0: followsStateSequence: function followsStateSequence(from, to) { Chris@0: return _.indexOf(this.states, from) < _.indexOf(this.states, to); Chris@0: } Chris@0: }); Chris@0: Chris@0: Drupal.quickedit.FieldCollection = Backbone.Collection.extend({ Chris@0: model: Drupal.quickedit.FieldModel Chris@0: }); Chris@0: })(_, Backbone, Drupal);