PageRenderTime 21ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/web/core/modules/quickedit/js/models/FieldModel.js

https://gitlab.com/mohamed_hussein/prodt
JavaScript | 79 lines | 69 code | 4 blank | 6 comment | 7 complexity | 602e8be1a7f056f03ac8229fa3cf4ff5 MD5 | raw file
  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. (function (_, Backbone, Drupal) {
  8. Drupal.quickedit.FieldModel = Drupal.quickedit.BaseModel.extend({
  9. defaults: {
  10. el: null,
  11. fieldID: null,
  12. id: null,
  13. entity: null,
  14. metadata: null,
  15. acceptStateChange: null,
  16. logicalFieldID: null,
  17. state: 'inactive',
  18. isChanged: false,
  19. inTempStore: false,
  20. html: null,
  21. htmlForOtherViewModes: null
  22. },
  23. initialize: function initialize(options) {
  24. this.set('html', options.el.outerHTML);
  25. this.get('entity').get('fields').add(this);
  26. this.set('logicalFieldID', this.get('fieldID').split('/').slice(0, 4).join('/'));
  27. Drupal.quickedit.BaseModel.prototype.initialize.call(this, options);
  28. },
  29. destroy: function destroy(options) {
  30. if (this.get('state') !== 'inactive') {
  31. throw new Error('FieldModel cannot be destroyed if it is not inactive state.');
  32. }
  33. Drupal.quickedit.BaseModel.prototype.destroy.call(this, options);
  34. },
  35. sync: function sync() {},
  36. validate: function validate(attrs, options) {
  37. var current = this.get('state');
  38. var next = attrs.state;
  39. if (current !== next) {
  40. if (_.indexOf(this.constructor.states, next) === -1) {
  41. return "\"".concat(next, "\" is an invalid state");
  42. }
  43. if (!this.get('acceptStateChange')(current, next, options, this)) {
  44. return 'state change not accepted';
  45. }
  46. }
  47. },
  48. getEntityID: function getEntityID() {
  49. return this.get('fieldID').split('/').slice(0, 2).join('/');
  50. },
  51. getViewMode: function getViewMode() {
  52. return this.get('fieldID').split('/').pop();
  53. },
  54. findOtherViewModes: function findOtherViewModes() {
  55. var currentField = this;
  56. var otherViewModes = [];
  57. Drupal.quickedit.collections.fields.where({
  58. logicalFieldID: currentField.get('logicalFieldID')
  59. }).forEach(function (field) {
  60. if (field !== currentField && field.get('fieldID') !== currentField.get('fieldID')) {
  61. otherViewModes.push(field.getViewMode());
  62. }
  63. });
  64. return otherViewModes;
  65. }
  66. }, {
  67. states: ['inactive', 'candidate', 'highlighted', 'activating', 'active', 'changed', 'saving', 'saved', 'invalid'],
  68. followsStateSequence: function followsStateSequence(from, to) {
  69. return _.indexOf(this.states, from) < _.indexOf(this.states, to);
  70. }
  71. });
  72. Drupal.quickedit.FieldCollection = Backbone.Collection.extend({
  73. model: Drupal.quickedit.FieldModel
  74. });
  75. })(_, Backbone, Drupal);