0 Votes

Changes for page LiveTable View Sheet

Last modified by Сергей Коршунов on 2025/05/01 21:19

From version 3.1
edited by Сергей Коршунов
on 2022/10/05 21:06
Change comment: Install extension [org.xwiki.platform:xwiki-platform-appwithinminutes-ui/14.8]
To version 1.1
edited by admins admins
on 2021/12/11 17:11
Change comment: Install extension [org.xwiki.platform:xwiki-platform-appwithinminutes-ui/13.10]

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.skorshunov
1 +XWiki.admins
Content
... ... @@ -122,30 +122,23 @@
122 122   data-backdrop="static" data-keyboard="false">
123 123   <div class="modal-dialog" role="document">
124 124   <form class="modal-content xform">
125 - ## The fieldset allows us to disable and enable the entire form quickly and easy.
126 - <fieldset>
127 - <div class="modal-header">
128 - <button type="button" class="close" data-dismiss="modal"
129 - title="$escapetool.xml($services.localization.render('appWithinMinutes.renameApp.close'))"
130 - aria-label="$escapetool.xml($services.localization.render('appWithinMinutes.renameApp.close'))">
131 - <span aria-hidden="true">&times;</span>
132 - </button>
133 - <span class="modal-title" id="renameAppModal-label">
134 - $escapetool.xml($services.localization.render('appWithinMinutes.renameApp.label'))
135 - </span>
136 - </div>
137 - <div class="modal-body">
138 - #renameAppModalBody
139 - </div>
140 - <div class="modal-footer">
141 - <button type="button" class="btn btn-default" data-dismiss="modal">
142 - $escapetool.xml($services.localization.render('cancel'))
143 - </button>
144 - <button type="submit" class="btn btn-primary" disabled="disabled">
145 - $escapetool.xml($services.localization.render('core.rename.submit'))
146 - </button>
147 - </div>
148 - </fieldset>
125 + <div class="modal-header">
126 + <button type="button" class="close" data-dismiss="modal" aria-label="Close">
127 + <span aria-hidden="true">&times;</span>
128 + </button>
129 + <span class="modal-title" id="renameAppModal-label">Rename Application</span>
130 + </div>
131 + <div class="modal-body">
132 + #renameAppModalBody
133 + </div>
134 + <div class="modal-footer">
135 + <button type="button" class="btn btn-default" data-dismiss="modal">
136 + $escapetool.xml($services.localization.render('cancel'))
137 + </button>
138 + <button type="submit" class="btn btn-primary" disabled="disabled">
139 + $escapetool.xml($services.localization.render('core.rename.submit'))
140 + </button>
141 + </div>
149 149   </form>
150 150   </div>
151 151   </div>
XWiki.JavaScriptExtension[0]
Code
... ... @@ -58,7 +58,7 @@
58 58  /**
59 59   * Rename Application
60 60   */
61 -require(['jquery', 'bootstrap', 'xwiki-form-validation-async'], function($) {
61 +require(['jquery', 'bootstrap'], function($) {
62 62   #set ($currentDocReference = $xwiki.getDocument($request.currentApp).getDocumentReference())
63 63   // if we cannot find any extension related to this page app, it's not part of an extension.
64 64   var isNotAnExtension = $services.extension.xar.getInstalledExtensions($currentDocReference).isEmpty();
... ... @@ -69,7 +69,7 @@
69 69   }
70 70   // Hijack the rename page action.
71 71   var renameAppModal = $('#renameAppModal');
72 - $('#tmActionRename').on('click', function(event) {
72 + $('#tmActionRename').click(function(event) {
73 73   event.preventDefault();
74 74   renameAppModal.modal();
75 75   });
... ... @@ -77,6 +77,7 @@
77 77   // Form validation.
78 78   var appNameInput = $('#renameAppTitle');
79 79   var appParentInput = $('#renameAppParentReference');
80 + var submitButton = renameAppModal.find('.btn-primary[type="submit"]');
80 80  
81 81   var appNameEmptyError = renameAppModal.find('.appNameEmptyError');
82 82   var pageExistsError = renameAppModal.find('.pageExistsError');
... ... @@ -99,44 +99,52 @@
99 99  
100 100   var startValidation = function() {
101 101   if (appNameInput.val() === '') {
102 - return Promise.reject(appNameEmptyError);
103 + endValidation(appNameEmptyError);
103 103   } else {
104 104   var newAppHomePage = getNewAppHomePage();
105 105   if (newAppHomePage.documentReference.equals(XWiki.currentDocument.documentReference)) {
106 - return Promise.reject(pageExistsError);
107 + endValidation(pageExistsError);
107 107   } else {
108 - return new Promise((resolve, reject) => {
109 - $.ajax({
110 - type: 'HEAD',
111 - url: newAppHomePage.getURL()
112 - }).then(reject.bind(null, pageExistsError), response => {
113 - if (response.status === 404) {
114 - $.ajax({
115 - type: 'HEAD',
116 - url: newAppHomePage.getURL('edit')
117 - }).then(
118 - () => resolve(),
119 - () => reject(locationForbiddenError)
120 - );
121 - } else if (response.status === 403) {
122 - reject(locationForbiddenError);
123 - } else {
124 - resolve();
125 - }
126 - });
109 + $.ajax({
110 + type: 'HEAD',
111 + url: newAppHomePage.getURL()
112 + }).done(function() {
113 + endValidation(pageExistsError);
114 + }).fail(function(response) {
115 + if (response.status === 404) {
116 + $.ajax({
117 + type: 'HEAD',
118 + url: newAppHomePage.getURL('edit')
119 + }).done(function() {
120 + endValidation();
121 + }).fail(function() {
122 + endValidation(locationForbiddenError);
123 + });
124 + } else if (response.status === 403) {
125 + endValidation(locationForbiddenError);
126 + } else {
127 + endValidation();
128 + }
127 127   });
128 128   }
129 129   }
130 130   };
131 131  
134 + var endValidation = function(error) {
135 + if (error) {
136 + error.show();
137 + }
138 + appNameInput.removeClass('loading');
139 + submitButton.prop('disabled', !!error);
140 + };
141 +
142 + var validationTimeout;
132 132   var scheduleValidation = function() {
133 - // Hide all error messages before starting the asynchronous validation.
144 + clearTimeout(validationTimeout);
134 134   renameAppModal.find('.xErrorMsg').hide();
135 - appNameInput.addClass('loading').validateAsync(startValidation, 500, 'awm').catch((error) => {
136 - error.show();
137 - }).finally(() => {
138 - appNameInput.removeClass('loading');
139 - });
146 + appNameInput.addClass('loading');
147 + submitButton.prop('disabled', true);
148 + validationTimeout = setTimeout(startValidation, 500);
140 140   };
141 141  
142 142   appNameInput.add(appParentInput).on('input', scheduleValidation);
... ... @@ -158,7 +158,7 @@
158 158   renameAppModal.modal('show');
159 159   });
160 160  
161 - renameAppModal.find('form').on('submit', function(event) {
170 + renameAppModal.find('form').submit(function(event) {
162 162   event.preventDefault();
163 163   renameApp(getRenameData($(this)));
164 164   });
... ... @@ -185,13 +185,13 @@
185 185  
186 186   var renameApp = function(data) {
187 187   // Disable the form to prevent it from being submitted twice.
188 - renameAppModal.find('fieldset').prop('disabled', true);
197 + renameAppModal.find(':input').prop('disabled', true);
189 189   var notification = new XWiki.widgets.Notification(
190 190   $jsontool.serialize($services.localization.render('appWithinMinutes.renameApp.inProgress')),
191 191   'inprogress'
192 192   );
193 193   var renameAppURL = new XWiki.Document('RenameApplication', 'AppWithinMinutes').getURL('get');
194 - Promise.resolve($.post(renameAppURL, data)).then(updateAppHomePage).then(function() {
203 + $.post(renameAppURL, data).then(updateAppHomePage).done(function() {
195 195   renameAppModal.modal('hide');
196 196   notification.replace(new XWiki.widgets.Notification(
197 197   $jsontool.serialize($services.localization.render('appWithinMinutes.renameApp.done')),
... ... @@ -201,29 +201,33 @@
201 201   setTimeout(function() {
202 202   window.location.href = getNewAppHomePage().getURL();
203 203   }, 0);
204 - }).catch(function() {
213 + }).fail(function() {
205 205   notification.replace(new XWiki.widgets.Notification(
206 206   $jsontool.serialize($services.localization.render('appWithinMinutes.renameApp.failed')),
207 207   'error'
208 208   ));
209 - }).finally(function() {
218 + }).always(function() {
210 210   // Re-enable the form.
211 - renameAppModal.find('fieldset').prop('disabled', false);
220 + renameAppModal.find(':input').prop('disabled', false);
212 212   });
213 213   };
214 214  
215 215   var updateAppHomePage = function() {
216 - return new Promise((resolve, reject) => {
217 - var newAppHomePageEditURL = getNewAppHomePage().getURL('edit');
218 - $('<div/>').load(newAppHomePageEditURL + ' #inline', function() {
219 - var formData = $(this).children('form#inline').serializeArray();
220 - if (formData.length) {
221 - formData.push({name: 'xaction_save', value: true});
222 - $.post(newAppHomePageEditURL, formData).then(resolve, reject);
223 - } else {
224 - reject();
225 - }
226 - });
225 + var deferred = $.Deferred();
226 + var newAppHomePageEditURL = getNewAppHomePage().getURL('edit');
227 + $('<div/>').load(newAppHomePageEditURL + ' #inline', function() {
228 + var formData = $(this).children('form#inline').serializeArray();
229 + if (formData.length > 0) {
230 + formData.push({name: 'xaction_save', value: true});
231 + $.post(newAppHomePageEditURL, formData).done(function() {
232 + deferred.resolve();
233 + }).fail(function() {
234 + deferred.reject();
235 + });
236 + } else {
237 + deferred.reject();
238 + }
227 227   });
240 + return deferred.promise();
228 228   }
229 229  });