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() {
58 fullWidthToolbar: true,
62 loadForm: function loadForm() {
63 var fieldModel = this.fieldModel;
65 var id = 'quickedit-form-for-' + fieldModel.id.replace(/[/[\]]/g, '_');
67 var $formContainer = $(Drupal.theme('quickeditFormContainer', {
69 loadingMsg: Drupal.t('Loading…')
71 this.$formContainer = $formContainer;
72 $formContainer.find('.quickedit-form').addClass('quickedit-editable quickedit-highlighted quickedit-editing').attr('role', 'dialog');
74 if (this.$el.css('display') === 'inline') {
75 $formContainer.prependTo(this.$el.offsetParent());
77 var pos = this.$el.position();
78 $formContainer.css('left', pos.left).css('top', pos.top);
80 $formContainer.insertBefore(this.$el);
84 fieldID: fieldModel.get('fieldID'),
88 reset: !fieldModel.get('entity').get('inTempStore')
90 Drupal.quickedit.util.form.load(formOptions, function (form, ajax) {
91 Drupal.AjaxCommands.prototype.insert(ajax, {
93 selector: '#' + id + ' .placeholder'
96 $formContainer.on('formUpdated.quickedit', ':input', function (event) {
97 var state = fieldModel.get('state');
99 if (state === 'invalid') {
100 fieldModel.set('state', 'activating');
102 fieldModel.set('state', 'changed');
104 }).on('keypress.quickedit', 'input', function (event) {
105 if (event.keyCode === 13) {
110 fieldModel.set('state', 'active');
113 removeForm: function removeForm() {
114 if (this.$formContainer === null) {
118 delete this.formSaveAjax;
120 Drupal.detachBehaviors(this.$formContainer.get(0), null, 'unload');
121 this.$formContainer.off('change.quickedit', ':input').off('keypress.quickedit', 'input').remove();
122 this.$formContainer = null;
124 save: function save() {
125 var $formContainer = this.$formContainer;
126 var $submit = $formContainer.find('.quickedit-form-submit');
127 var editorModel = this.model;
128 var fieldModel = this.fieldModel;
130 var formSaveAjax = Drupal.quickedit.util.form.ajaxifySaving({
132 other_view_modes: fieldModel.findOtherViewModes()
135 function cleanUpAjax() {
136 Drupal.quickedit.util.form.unajaxifySaving(formSaveAjax);
140 formSaveAjax.commands.quickeditFieldFormSaved = function (ajax, response, status) {
143 fieldModel.set('state', 'saved');
145 fieldModel.set('htmlForOtherViewModes', response.other_view_modes);
147 _.defer(function () {
148 fieldModel.set('html', response.data);
152 formSaveAjax.commands.quickeditFieldFormValidationErrors = function (ajax, response, status) {
153 editorModel.set('validationErrors', response.data);
154 fieldModel.set('state', 'invalid');
157 formSaveAjax.commands.quickeditFieldForm = function (ajax, response, status) {
158 Drupal.AjaxCommands.prototype.insert(ajax, {
160 selector: '#' + $formContainer.attr('id') + ' form'
164 $submit.trigger('click.quickedit');
166 showValidationErrors: function showValidationErrors() {
167 this.$formContainer.find('.quickedit-form').addClass('quickedit-validation-error').find('form').prepend(this.model.get('validationErrors'));
170 })(jQuery, Drupal, _);