2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function (_, Backbone, Drupal) {
9 Drupal.quickedit.FieldModel = Drupal.quickedit.BaseModel.extend({
21 acceptStateChange: null,
33 htmlForOtherViewModes: null
36 initialize: function initialize(options) {
37 this.set('html', options.el.outerHTML);
39 this.get('entity').get('fields').add(this);
41 this.set('logicalFieldID', this.get('fieldID').split('/').slice(0, 4).join('/'));
43 Drupal.quickedit.BaseModel.prototype.initialize.call(this, options);
45 destroy: function destroy(options) {
46 if (this.get('state') !== 'inactive') {
47 throw new Error('FieldModel cannot be destroyed if it is not inactive state.');
49 Drupal.quickedit.BaseModel.prototype.destroy.call(this, options);
51 sync: function sync() {},
52 validate: function validate(attrs, options) {
53 var current = this.get('state');
54 var next = attrs.state;
55 if (current !== next) {
56 if (_.indexOf(this.constructor.states, next) === -1) {
57 return '"' + next + '" is an invalid state';
60 if (!this.get('acceptStateChange')(current, next, options, this)) {
61 return 'state change not accepted';
65 getEntityID: function getEntityID() {
66 return this.get('fieldID').split('/').slice(0, 2).join('/');
68 getViewMode: function getViewMode() {
69 return this.get('fieldID').split('/').pop();
71 findOtherViewModes: function findOtherViewModes() {
72 var currentField = this;
73 var otherViewModes = [];
74 Drupal.quickedit.collections.fields.where({ logicalFieldID: currentField.get('logicalFieldID') }).forEach(function (field) {
75 if (field !== currentField && field.get('fieldID') !== currentField.get('fieldID')) {
76 otherViewModes.push(field.getViewMode());
79 return otherViewModes;
82 states: ['inactive', 'candidate', 'highlighted', 'activating', 'active', 'changed', 'saving', 'saved', 'invalid'],
84 followsStateSequence: function followsStateSequence(from, to) {
85 return _.indexOf(this.states, from) < _.indexOf(this.states, to);
89 Drupal.quickedit.FieldCollection = Backbone.Collection.extend({
90 model: Drupal.quickedit.FieldModel
92 })(_, Backbone, Drupal);