Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/quickedit/js/views/EditorView.js @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | a9cd425dd02b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
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 { padding: false, unifiedToolbar: false, fullWidthToolbar: false, popup: false }; | |
23 }, | |
24 stateChange: function stateChange(fieldModel, state) { | |
25 var from = fieldModel.previous('state'); | |
26 var to = state; | |
27 switch (to) { | |
28 case 'inactive': | |
29 break; | |
30 | |
31 case 'candidate': | |
32 if (from === 'invalid') { | |
33 this.removeValidationErrors(); | |
34 } | |
35 break; | |
36 | |
37 case 'highlighted': | |
38 break; | |
39 | |
40 case 'activating': | |
41 { | |
42 var loadDependencies = function loadDependencies(callback) { | |
43 callback(); | |
44 }; | |
45 loadDependencies(function () { | |
46 fieldModel.set('state', 'active'); | |
47 }); | |
48 break; | |
49 } | |
50 | |
51 case 'active': | |
52 break; | |
53 | |
54 case 'changed': | |
55 break; | |
56 | |
57 case 'saving': | |
58 if (from === 'invalid') { | |
59 this.removeValidationErrors(); | |
60 } | |
61 this.save(); | |
62 break; | |
63 | |
64 case 'saved': | |
65 break; | |
66 | |
67 case 'invalid': | |
68 this.showValidationErrors(); | |
69 break; | |
70 } | |
71 }, | |
72 revert: function revert() {}, | |
73 save: function save() { | |
74 var fieldModel = this.fieldModel; | |
75 var editorModel = this.model; | |
76 var backstageId = 'quickedit_backstage-' + this.fieldModel.id.replace(/[/[\]_\s]/g, '-'); | |
77 | |
78 function fillAndSubmitForm(value) { | |
79 var $form = $('#' + backstageId).find('form'); | |
80 | |
81 $form.find(':input[type!="hidden"][type!="submit"]:not(select)').not('[name$="\\[summary\\]"]').val(value); | |
82 | |
83 $form.find('.quickedit-form-submit').trigger('click.quickedit'); | |
84 } | |
85 | |
86 var formOptions = { | |
87 fieldID: this.fieldModel.get('fieldID'), | |
88 $el: this.$el, | |
89 nocssjs: true, | |
90 other_view_modes: fieldModel.findOtherViewModes(), | |
91 | |
92 reset: !this.fieldModel.get('entity').get('inTempStore') | |
93 }; | |
94 | |
95 var self = this; | |
96 Drupal.quickedit.util.form.load(formOptions, function (form, ajax) { | |
97 var $backstage = $(Drupal.theme('quickeditBackstage', { id: backstageId })).appendTo('body'); | |
98 | |
99 var $form = $(form).appendTo($backstage); | |
100 | |
101 $form.prop('novalidate', true); | |
102 var $submit = $form.find('.quickedit-form-submit'); | |
103 self.formSaveAjax = Drupal.quickedit.util.form.ajaxifySaving(formOptions, $submit); | |
104 | |
105 function removeHiddenForm() { | |
106 Drupal.quickedit.util.form.unajaxifySaving(self.formSaveAjax); | |
107 delete self.formSaveAjax; | |
108 $backstage.remove(); | |
109 } | |
110 | |
111 self.formSaveAjax.commands.quickeditFieldFormSaved = function (ajax, response, status) { | |
112 removeHiddenForm(); | |
113 | |
114 fieldModel.set('state', 'saved'); | |
115 | |
116 fieldModel.set('htmlForOtherViewModes', response.other_view_modes); | |
117 | |
118 fieldModel.set('html', response.data); | |
119 }; | |
120 | |
121 self.formSaveAjax.commands.quickeditFieldFormValidationErrors = function (ajax, response, status) { | |
122 removeHiddenForm(); | |
123 editorModel.set('validationErrors', response.data); | |
124 fieldModel.set('state', 'invalid'); | |
125 }; | |
126 | |
127 self.formSaveAjax.commands.quickeditFieldForm = function () {}; | |
128 | |
129 fillAndSubmitForm(editorModel.get('currentValue')); | |
130 }); | |
131 }, | |
132 showValidationErrors: function showValidationErrors() { | |
133 var $errors = $('<div class="quickedit-validation-errors"></div>').append(this.model.get('validationErrors')); | |
134 this.getEditedElement().addClass('quickedit-validation-error').after($errors); | |
135 }, | |
136 removeValidationErrors: function removeValidationErrors() { | |
137 this.getEditedElement().removeClass('quickedit-validation-error').next('.quickedit-validation-errors').remove(); | |
138 } | |
139 }); | |
140 })(jQuery, Backbone, Drupal); |