Modifiche per il documento InplaceEditing

Dalla versione 3.1
modificato da Andrea Omicini
il 2026/09/23 10:24
Cambia il commento: Install extension [org.xwiki.platform:xwiki-platform-edit-ui/17.10.13]
Alla versione 2.1
modificato da Andrea Omicini
il 2026/09/02 14:00
Cambia il commento: Nessun commento per questa versione

Summary

Details

XWiki.JavaScriptExtension[0]
Codice
... ... @@ -195,7 +195,6 @@
195 195   lockAction: action,
196 196   force: force,
197 197   language: this.getRealLocale(),
198 - force_token: xcontext.form_token,
199 199   // Make sure the response is not retrieved from cache (IE11 doesn't obey the caching HTTP headers).
200 200   timestamp: new Date().getTime()
201 201   })).then(() => {
... ... @@ -277,13 +277,11 @@
277 277   'xwiki-meta',
278 278   // We need this in order to easily work with the XWiki document JSON.
279 279   'xwiki-document-api',
280 - // We need this to display the edit confirmation modal when the lock needs to be forced.
281 - 'xwiki-edit-confirmation',
282 282   // We need this for the confirmation modals.
283 283   'bootstrap',
284 284   // We need this in order to catch events triggered by actionButtons.js using Prototype.js
285 285   'xwiki-events-bridge'
286 -], function($, xcontext, XWikiDocument, editConfirmation) {
283 +], function($, xcontext, XWikiDocument) {
287 287   var preload = function() {
288 288   paths.css.forEach(loadCSS);
289 289   return initActionButtons();
... ... @@ -401,11 +401,10 @@
401 401   if (xwikiDocument.lockConfirmation) {
402 402   var confirmation = xwikiDocument.lockConfirmation;
403 403   delete xwikiDocument.lockConfirmation;
404 - return editConfirmation.showConfirmationModal(confirmation)
405 - .then(xwikiDocument.lock.bind(xwikiDocument, 'edit', true), function() {
406 - // Cancel the edit action.
407 - return Promise.reject(xwikiDocument);
408 - });
401 + return maybeForceLock(confirmation).then(xwikiDocument.lock.bind(xwikiDocument, 'edit', true), function() {
402 + // Cancel the edit action.
403 + return Promise.reject(xwikiDocument);
404 + });
409 409   } else {
410 410   new XWiki.widgets.Notification(l10n['edit.inplace.page.lockFailed'], 'error');
411 411   return Promise.reject(xwikiDocument);
... ... @@ -413,6 +413,73 @@
413 413   });
414 414   };
415 415  
412 + var maybeForceLock = function(confirmation) {
413 + var deferred, promise = new Promise((resolve, reject) => {
414 + deferred = {resolve, reject};
415 + });
416 + // We need the catch() to prevent the "Uncaught (in promise)" error log in the console.
417 + promise.catch(() => {}).finally(() => {
418 + // This flag is used by the Force Lock modal to know whether the promise is settled when the modal is closing.
419 + deferred.settled = true;
420 + });
421 + // Reuse the confirmation modal once it is created.
422 + var modal = $('.force-edit-lock-modal');
423 + if (!modal.length) {
424 + modal = createForceLockModal();
425 + }
426 + // Update the deferred that needs to be resolved or rejected.
427 + modal.data('deferred', deferred);
428 + // Update the confirmation modal.
429 + modal.find('.modal-title').text(confirmation.title);
430 + modal.find('.modal-body').html(confirmation.message);
431 + modal.find('.modal-footer .btn-default').text(confirmation.reject);
432 + if (confirmation.confirm) {
433 + modal.find('.modal-footer .btn-warning').show().text(confirmation.confirm);
434 + } else {
435 + modal.find('.modal-footer .btn-warning').hide();
436 + }
437 + // Show the confirmation modal.
438 + modal.modal('show');
439 + return promise;
440 + };
441 +
442 + var createForceLockModal = function() {
443 + var modal = $([
444 + '<div class="modal fade force-edit-lock-modal" tabindex="-1" role="dialog">',
445 + '<div class="modal-dialog" role="document">',
446 + '<div class="modal-content">',
447 + '<div class="modal-header">',
448 + '<button type="button" class="close" data-dismiss="modal">',
449 + '<span aria-hidden="true">&times;</span>',
450 + '</button>',
451 + '<h4 class="modal-title"></h4>',
452 + '</div>',
453 + '<div class="modal-body"></div>',
454 + '<div class="modal-footer">',
455 + '<button type="button" class="btn btn-default" data-dismiss="modal"></button>',
456 + '<button type="button" class="btn btn-warning"></button>',
457 + '</div>',
458 + '</div>',
459 + '</div>',
460 + '</div>'
461 + ].join(''));
462 + modal.find('.close').attr('aria-label', l10n['edit.inplace.close']);
463 + modal.find('.modal-footer .btn-warning').on('click', function() {
464 + // The user has confirmed they want to force the lock.
465 + modal.data('deferred').resolve();
466 + modal.modal('hide');
467 + });
468 + modal.on('hide.bs.modal', function() {
469 + // If the lock promise is not yet settled when the modal is closing then it means the modal was canceled,
470 + // i.e. the user doesn't want to force the lock.
471 + var deferred = modal.data('deferred');
472 + if (!deferred.settled) {
473 + deferred.reject();
474 + }
475 + });
476 + return modal.appendTo('body').modal();
477 + };
478 +
416 416   var load = function(xwikiDocument) {
417 417   return xwikiDocument.reload().then(xwikiDocument => {
418 418   // Clone the current document version and keep a reference to it in order to be able to restore it on cancel.
XWiki.UIExtensionClass[0]
Executed Content
... ... @@ -15,6 +15,7 @@
15 15   #set ($l10nKeys = [
16 16   'edit.inplace.page.renderFailed',
17 17   'edit.inplace.page.lockFailed',
18 + 'edit.inplace.close',
18 18   'edit.inplace.page.loadFailed',
19 19   'edit.inplace.actionButtons.loadFailed',
20 20   'core.editors.content.titleField.label',