2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
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);
14 remove: function remove() {
16 Backbone.View.prototype.remove.call(this);
18 getEditedElement: function getEditedElement() {
21 getQuickEditUISettings: function getQuickEditUISettings() {
22 return { padding: false, unifiedToolbar: false, fullWidthToolbar: false, popup: false };
24 stateChange: function stateChange(fieldModel, state) {
25 var from = fieldModel.previous('state');
32 if (from === 'invalid') {
33 this.removeValidationErrors();
41 var loadDependencies = function loadDependencies(callback) {
44 loadDependencies(function () {
45 fieldModel.set('state', 'active');
56 if (from === 'invalid') {
57 this.removeValidationErrors();
66 this.showValidationErrors();
70 revert: function revert() {},
71 save: function save() {
72 var fieldModel = this.fieldModel;
73 var editorModel = this.model;
74 var backstageId = 'quickedit_backstage-' + this.fieldModel.id.replace(/[\/\[\]\_\s]/g, '-');
76 function fillAndSubmitForm(value) {
77 var $form = $('#' + backstageId).find('form');
79 $form.find(':input[type!="hidden"][type!="submit"]:not(select)').not('[name$="\\[summary\\]"]').val(value);
81 $form.find('.quickedit-form-submit').trigger('click.quickedit');
85 fieldID: this.fieldModel.get('fieldID'),
88 other_view_modes: fieldModel.findOtherViewModes(),
90 reset: !this.fieldModel.get('entity').get('inTempStore')
94 Drupal.quickedit.util.form.load(formOptions, function (form, ajax) {
95 var $backstage = $(Drupal.theme('quickeditBackstage', { id: backstageId })).appendTo('body');
97 var $form = $(form).appendTo($backstage);
99 $form.prop('novalidate', true);
100 var $submit = $form.find('.quickedit-form-submit');
101 self.formSaveAjax = Drupal.quickedit.util.form.ajaxifySaving(formOptions, $submit);
103 function removeHiddenForm() {
104 Drupal.quickedit.util.form.unajaxifySaving(self.formSaveAjax);
105 delete self.formSaveAjax;
109 self.formSaveAjax.commands.quickeditFieldFormSaved = function (ajax, response, status) {
112 fieldModel.set('state', 'saved');
114 fieldModel.set('htmlForOtherViewModes', response.other_view_modes);
116 fieldModel.set('html', response.data);
119 self.formSaveAjax.commands.quickeditFieldFormValidationErrors = function (ajax, response, status) {
121 editorModel.set('validationErrors', response.data);
122 fieldModel.set('state', 'invalid');
125 self.formSaveAjax.commands.quickeditFieldForm = function () {};
127 fillAndSubmitForm(editorModel.get('currentValue'));
130 showValidationErrors: function showValidationErrors() {
131 var $errors = $('<div class="quickedit-validation-errors"></div>').append(this.model.get('validationErrors'));
132 this.getEditedElement().addClass('quickedit-validation-error').after($errors);
134 removeValidationErrors: function removeValidationErrors() {
135 this.getEditedElement().removeClass('quickedit-validation-error').next('.quickedit-validation-errors').remove();
138 })(jQuery, Backbone, Drupal);