annotate core/modules/quickedit/js/models/FieldModel.js @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 1fec387a4317
children
rev   line source
Chris@0 1 /**
Chris@0 2 * DO NOT EDIT THIS FILE.
Chris@0 3 * See the following change record for more information,
Chris@0 4 * https://www.drupal.org/node/2815083
Chris@0 5 * @preserve
Chris@0 6 **/
Chris@0 7
Chris@0 8 (function (_, Backbone, Drupal) {
Chris@0 9 Drupal.quickedit.FieldModel = Drupal.quickedit.BaseModel.extend({
Chris@0 10 defaults: {
Chris@0 11 el: null,
Chris@0 12
Chris@0 13 fieldID: null,
Chris@0 14
Chris@0 15 id: null,
Chris@0 16
Chris@0 17 entity: null,
Chris@0 18
Chris@0 19 metadata: null,
Chris@0 20
Chris@0 21 acceptStateChange: null,
Chris@0 22
Chris@0 23 logicalFieldID: null,
Chris@0 24
Chris@0 25 state: 'inactive',
Chris@0 26
Chris@0 27 isChanged: false,
Chris@0 28
Chris@0 29 inTempStore: false,
Chris@0 30
Chris@0 31 html: null,
Chris@0 32
Chris@0 33 htmlForOtherViewModes: null
Chris@0 34 },
Chris@0 35
Chris@0 36 initialize: function initialize(options) {
Chris@0 37 this.set('html', options.el.outerHTML);
Chris@0 38
Chris@0 39 this.get('entity').get('fields').add(this);
Chris@0 40
Chris@0 41 this.set('logicalFieldID', this.get('fieldID').split('/').slice(0, 4).join('/'));
Chris@0 42
Chris@0 43 Drupal.quickedit.BaseModel.prototype.initialize.call(this, options);
Chris@0 44 },
Chris@0 45 destroy: function destroy(options) {
Chris@0 46 if (this.get('state') !== 'inactive') {
Chris@0 47 throw new Error('FieldModel cannot be destroyed if it is not inactive state.');
Chris@0 48 }
Chris@0 49 Drupal.quickedit.BaseModel.prototype.destroy.call(this, options);
Chris@0 50 },
Chris@0 51 sync: function sync() {},
Chris@0 52 validate: function validate(attrs, options) {
Chris@0 53 var current = this.get('state');
Chris@0 54 var next = attrs.state;
Chris@0 55 if (current !== next) {
Chris@0 56 if (_.indexOf(this.constructor.states, next) === -1) {
Chris@0 57 return '"' + next + '" is an invalid state';
Chris@0 58 }
Chris@0 59
Chris@0 60 if (!this.get('acceptStateChange')(current, next, options, this)) {
Chris@0 61 return 'state change not accepted';
Chris@0 62 }
Chris@0 63 }
Chris@0 64 },
Chris@0 65 getEntityID: function getEntityID() {
Chris@0 66 return this.get('fieldID').split('/').slice(0, 2).join('/');
Chris@0 67 },
Chris@0 68 getViewMode: function getViewMode() {
Chris@0 69 return this.get('fieldID').split('/').pop();
Chris@0 70 },
Chris@0 71 findOtherViewModes: function findOtherViewModes() {
Chris@0 72 var currentField = this;
Chris@0 73 var otherViewModes = [];
Chris@0 74 Drupal.quickedit.collections.fields.where({ logicalFieldID: currentField.get('logicalFieldID') }).forEach(function (field) {
Chris@14 75 if (field !== currentField && field.get('fieldID') !== currentField.get('fieldID')) {
Chris@14 76 otherViewModes.push(field.getViewMode());
Chris@14 77 }
Chris@0 78 });
Chris@0 79 return otherViewModes;
Chris@0 80 }
Chris@0 81 }, {
Chris@0 82 states: ['inactive', 'candidate', 'highlighted', 'activating', 'active', 'changed', 'saving', 'saved', 'invalid'],
Chris@0 83
Chris@0 84 followsStateSequence: function followsStateSequence(from, to) {
Chris@0 85 return _.indexOf(this.states, from) < _.indexOf(this.states, to);
Chris@0 86 }
Chris@0 87 });
Chris@0 88
Chris@0 89 Drupal.quickedit.FieldCollection = Backbone.Collection.extend({
Chris@0 90 model: Drupal.quickedit.FieldModel
Chris@0 91 });
Chris@0 92 })(_, Backbone, Drupal);