comparison core/modules/quickedit/js/models/FieldModel.js @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 /**
2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
5 * @preserve
6 **/
7
8 (function (_, Backbone, Drupal) {
9 Drupal.quickedit.FieldModel = Drupal.quickedit.BaseModel.extend({
10 defaults: {
11 el: null,
12
13 fieldID: null,
14
15 id: null,
16
17 entity: null,
18
19 metadata: null,
20
21 acceptStateChange: null,
22
23 logicalFieldID: null,
24
25 state: 'inactive',
26
27 isChanged: false,
28
29 inTempStore: false,
30
31 html: null,
32
33 htmlForOtherViewModes: null
34 },
35
36 initialize: function initialize(options) {
37 this.set('html', options.el.outerHTML);
38
39 this.get('entity').get('fields').add(this);
40
41 this.set('logicalFieldID', this.get('fieldID').split('/').slice(0, 4).join('/'));
42
43 Drupal.quickedit.BaseModel.prototype.initialize.call(this, options);
44 },
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.');
48 }
49 Drupal.quickedit.BaseModel.prototype.destroy.call(this, options);
50 },
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';
58 }
59
60 if (!this.get('acceptStateChange')(current, next, options, this)) {
61 return 'state change not accepted';
62 }
63 }
64 },
65 getEntityID: function getEntityID() {
66 return this.get('fieldID').split('/').slice(0, 2).join('/');
67 },
68 getViewMode: function getViewMode() {
69 return this.get('fieldID').split('/').pop();
70 },
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) {} else if (field.get('fieldID') === currentField.get('fieldID')) {} else {
76 otherViewModes.push(field.getViewMode());
77 }
78 });
79 return otherViewModes;
80 }
81 }, {
82 states: ['inactive', 'candidate', 'highlighted', 'activating', 'active', 'changed', 'saving', 'saved', 'invalid'],
83
84 followsStateSequence: function followsStateSequence(from, to) {
85 return _.indexOf(this.states, from) < _.indexOf(this.states, to);
86 }
87 });
88
89 Drupal.quickedit.FieldCollection = Backbone.Collection.extend({
90 model: Drupal.quickedit.FieldModel
91 });
92 })(_, Backbone, Drupal);