Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / quickedit / js / views / EditorView.js
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.EditorView = Backbone.View.extend({
10     initialize: function initialize(options) {
11       this.fieldModel = options.fieldModel;
12       this.listenTo(this.fieldModel, 'change:state', this.stateChange);
13     },
14     remove: function remove() {
15       this.setElement();
16       Backbone.View.prototype.remove.call(this);
17     },
18     getEditedElement: function getEditedElement() {
19       return this.$el;
20     },
21     getQuickEditUISettings: function getQuickEditUISettings() {
22       return {
23         padding: false,
24         unifiedToolbar: false,
25         fullWidthToolbar: false,
26         popup: false
27       };
28     },
29     stateChange: function stateChange(fieldModel, state) {
30       var from = fieldModel.previous('state');
31       var to = state;
32       switch (to) {
33         case 'inactive':
34           break;
35
36         case 'candidate':
37           if (from === 'invalid') {
38             this.removeValidationErrors();
39           }
40           break;
41
42         case 'highlighted':
43           break;
44
45         case 'activating':
46           {
47             var loadDependencies = function loadDependencies(callback) {
48               callback();
49             };
50             loadDependencies(function () {
51               fieldModel.set('state', 'active');
52             });
53             break;
54           }
55
56         case 'active':
57           break;
58
59         case 'changed':
60           break;
61
62         case 'saving':
63           if (from === 'invalid') {
64             this.removeValidationErrors();
65           }
66           this.save();
67           break;
68
69         case 'saved':
70           break;
71
72         case 'invalid':
73           this.showValidationErrors();
74           break;
75       }
76     },
77     revert: function revert() {},
78     save: function save() {
79       var fieldModel = this.fieldModel;
80       var editorModel = this.model;
81       var backstageId = 'quickedit_backstage-' + this.fieldModel.id.replace(/[/[\]_\s]/g, '-');
82
83       function fillAndSubmitForm(value) {
84         var $form = $('#' + backstageId).find('form');
85
86         $form.find(':input[type!="hidden"][type!="submit"]:not(select)').not('[name$="\\[summary\\]"]').val(value);
87
88         $form.find('.quickedit-form-submit').trigger('click.quickedit');
89       }
90
91       var formOptions = {
92         fieldID: this.fieldModel.get('fieldID'),
93         $el: this.$el,
94         nocssjs: true,
95         other_view_modes: fieldModel.findOtherViewModes(),
96
97         reset: !this.fieldModel.get('entity').get('inTempStore')
98       };
99
100       var self = this;
101       Drupal.quickedit.util.form.load(formOptions, function (form, ajax) {
102         var $backstage = $(Drupal.theme('quickeditBackstage', { id: backstageId })).appendTo('body');
103
104         var $form = $(form).appendTo($backstage);
105
106         $form.prop('novalidate', true);
107         var $submit = $form.find('.quickedit-form-submit');
108         self.formSaveAjax = Drupal.quickedit.util.form.ajaxifySaving(formOptions, $submit);
109
110         function removeHiddenForm() {
111           Drupal.quickedit.util.form.unajaxifySaving(self.formSaveAjax);
112           delete self.formSaveAjax;
113           $backstage.remove();
114         }
115
116         self.formSaveAjax.commands.quickeditFieldFormSaved = function (ajax, response, status) {
117           removeHiddenForm();
118
119           fieldModel.set('state', 'saved');
120
121           fieldModel.set('htmlForOtherViewModes', response.other_view_modes);
122
123           fieldModel.set('html', response.data);
124         };
125
126         self.formSaveAjax.commands.quickeditFieldFormValidationErrors = function (ajax, response, status) {
127           removeHiddenForm();
128           editorModel.set('validationErrors', response.data);
129           fieldModel.set('state', 'invalid');
130         };
131
132         self.formSaveAjax.commands.quickeditFieldForm = function () {};
133
134         fillAndSubmitForm(editorModel.get('currentValue'));
135       });
136     },
137     showValidationErrors: function showValidationErrors() {
138       var $errors = $('<div class="quickedit-validation-errors"></div>').append(this.model.get('validationErrors'));
139       this.getEditedElement().addClass('quickedit-validation-error').after($errors);
140     },
141     removeValidationErrors: function removeValidationErrors() {
142       this.getEditedElement().removeClass('quickedit-validation-error').next('.quickedit-validation-errors').remove();
143     }
144   });
145 })(jQuery, Backbone, Drupal);