Mercurial > hg > isophonics-drupal-site
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/modules/quickedit/js/models/FieldModel.js Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,92 @@ +/** +* DO NOT EDIT THIS FILE. +* See the following change record for more information, +* https://www.drupal.org/node/2815083 +* @preserve +**/ + +(function (_, Backbone, Drupal) { + Drupal.quickedit.FieldModel = Drupal.quickedit.BaseModel.extend({ + defaults: { + el: null, + + fieldID: null, + + id: null, + + entity: null, + + metadata: null, + + acceptStateChange: null, + + logicalFieldID: null, + + state: 'inactive', + + isChanged: false, + + inTempStore: false, + + html: null, + + htmlForOtherViewModes: null + }, + + initialize: function initialize(options) { + this.set('html', options.el.outerHTML); + + this.get('entity').get('fields').add(this); + + this.set('logicalFieldID', this.get('fieldID').split('/').slice(0, 4).join('/')); + + Drupal.quickedit.BaseModel.prototype.initialize.call(this, options); + }, + destroy: function destroy(options) { + if (this.get('state') !== 'inactive') { + throw new Error('FieldModel cannot be destroyed if it is not inactive state.'); + } + Drupal.quickedit.BaseModel.prototype.destroy.call(this, options); + }, + sync: function sync() {}, + validate: function validate(attrs, options) { + var current = this.get('state'); + var next = attrs.state; + if (current !== next) { + if (_.indexOf(this.constructor.states, next) === -1) { + return '"' + next + '" is an invalid state'; + } + + if (!this.get('acceptStateChange')(current, next, options, this)) { + return 'state change not accepted'; + } + } + }, + getEntityID: function getEntityID() { + return this.get('fieldID').split('/').slice(0, 2).join('/'); + }, + getViewMode: function getViewMode() { + return this.get('fieldID').split('/').pop(); + }, + findOtherViewModes: function findOtherViewModes() { + var currentField = this; + var otherViewModes = []; + Drupal.quickedit.collections.fields.where({ logicalFieldID: currentField.get('logicalFieldID') }).forEach(function (field) { + if (field === currentField) {} else if (field.get('fieldID') === currentField.get('fieldID')) {} else { + otherViewModes.push(field.getViewMode()); + } + }); + return otherViewModes; + } + }, { + states: ['inactive', 'candidate', 'highlighted', 'activating', 'active', 'changed', 'saving', 'saved', 'invalid'], + + followsStateSequence: function followsStateSequence(from, to) { + return _.indexOf(this.states, from) < _.indexOf(this.states, to); + } + }); + + Drupal.quickedit.FieldCollection = Backbone.Collection.extend({ + model: Drupal.quickedit.FieldModel + }); +})(_, Backbone, Drupal); \ No newline at end of file