2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function ($, Drupal, _) {
9 Drupal.quickedit.editors.form = Drupal.quickedit.EditorView.extend({
14 stateChange: function stateChange(fieldModel, state) {
15 var from = fieldModel.previous('state');
22 if (from !== 'inactive') {
31 if (from !== 'invalid') {
50 this.showValidationErrors();
54 getQuickEditUISettings: function getQuickEditUISettings() {
55 return { padding: true, unifiedToolbar: true, fullWidthToolbar: true, popup: true };
57 loadForm: function loadForm() {
58 var fieldModel = this.fieldModel;
60 var id = 'quickedit-form-for-' + fieldModel.id.replace(/[/[\]]/g, '_');
62 var $formContainer = $(Drupal.theme('quickeditFormContainer', {
64 loadingMsg: Drupal.t('Loading…')
66 this.$formContainer = $formContainer;
67 $formContainer.find('.quickedit-form').addClass('quickedit-editable quickedit-highlighted quickedit-editing').attr('role', 'dialog');
69 if (this.$el.css('display') === 'inline') {
70 $formContainer.prependTo(this.$el.offsetParent());
72 var pos = this.$el.position();
73 $formContainer.css('left', pos.left).css('top', pos.top);
75 $formContainer.insertBefore(this.$el);
79 fieldID: fieldModel.get('fieldID'),
83 reset: !fieldModel.get('entity').get('inTempStore')
85 Drupal.quickedit.util.form.load(formOptions, function (form, ajax) {
86 Drupal.AjaxCommands.prototype.insert(ajax, {
88 selector: '#' + id + ' .placeholder'
91 $formContainer.on('formUpdated.quickedit', ':input', function (event) {
92 var state = fieldModel.get('state');
94 if (state === 'invalid') {
95 fieldModel.set('state', 'activating');
97 fieldModel.set('state', 'changed');
99 }).on('keypress.quickedit', 'input', function (event) {
100 if (event.keyCode === 13) {
105 fieldModel.set('state', 'active');
108 removeForm: function removeForm() {
109 if (this.$formContainer === null) {
113 delete this.formSaveAjax;
115 Drupal.detachBehaviors(this.$formContainer.get(0), null, 'unload');
116 this.$formContainer.off('change.quickedit', ':input').off('keypress.quickedit', 'input').remove();
117 this.$formContainer = null;
119 save: function save() {
120 var $formContainer = this.$formContainer;
121 var $submit = $formContainer.find('.quickedit-form-submit');
122 var editorModel = this.model;
123 var fieldModel = this.fieldModel;
125 function cleanUpAjax() {
126 Drupal.quickedit.util.form.unajaxifySaving(formSaveAjax);
130 var formSaveAjax = Drupal.quickedit.util.form.ajaxifySaving({
132 other_view_modes: fieldModel.findOtherViewModes()
135 formSaveAjax.commands.quickeditFieldFormSaved = function (ajax, response, status) {
138 fieldModel.set('state', 'saved');
140 fieldModel.set('htmlForOtherViewModes', response.other_view_modes);
142 _.defer(function () {
143 fieldModel.set('html', response.data);
147 formSaveAjax.commands.quickeditFieldFormValidationErrors = function (ajax, response, status) {
148 editorModel.set('validationErrors', response.data);
149 fieldModel.set('state', 'invalid');
152 formSaveAjax.commands.quickeditFieldForm = function (ajax, response, status) {
153 Drupal.AjaxCommands.prototype.insert(ajax, {
155 selector: '#' + $formContainer.attr('id') + ' form'
159 $submit.trigger('click.quickedit');
161 showValidationErrors: function showValidationErrors() {
162 this.$formContainer.find('.quickedit-form').addClass('quickedit-validation-error').find('form').prepend(this.model.get('validationErrors'));
165 })(jQuery, Drupal, _);