Changes for page InplaceEditing

From version 2.1
edited by Andrea Omicini
on 2026/09/02 14:00
Change comment: There is no comment for this version
To version 3.1
edited by Andrea Omicini
on 2026/09/23 10:24
Change comment: Install extension [org.xwiki.platform:xwiki-platform-edit-ui/17.10.13]

Summary

Details

XWiki.JavaScriptExtension[0]
Code
... ... @@ -195,6 +195,7 @@
195 195   lockAction: action,
196 196   force: force,
197 197   language: this.getRealLocale(),
198 + force_token: xcontext.form_token,
198 198   // Make sure the response is not retrieved from cache (IE11 doesn't obey the caching HTTP headers).
199 199   timestamp: new Date().getTime()
200 200   })).then(() => {
... ... @@ -276,11 +276,13 @@
276 276   'xwiki-meta',
277 277   // We need this in order to easily work with the XWiki document JSON.
278 278   'xwiki-document-api',
280 + // We need this to display the edit confirmation modal when the lock needs to be forced.
281 + 'xwiki-edit-confirmation',
279 279   // We need this for the confirmation modals.
280 280   'bootstrap',
281 281   // We need this in order to catch events triggered by actionButtons.js using Prototype.js
282 282   'xwiki-events-bridge'
283 -], function($, xcontext, XWikiDocument) {
286 +], function($, xcontext, XWikiDocument, editConfirmation) {
284 284   var preload = function() {
285 285   paths.css.forEach(loadCSS);
286 286   return initActionButtons();
... ... @@ -398,10 +398,11 @@
398 398   if (xwikiDocument.lockConfirmation) {
399 399   var confirmation = xwikiDocument.lockConfirmation;
400 400   delete xwikiDocument.lockConfirmation;
401 - return maybeForceLock(confirmation).then(xwikiDocument.lock.bind(xwikiDocument, 'edit', true), function() {
402 - // Cancel the edit action.
403 - return Promise.reject(xwikiDocument);
404 - });
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 + });
405 405   } else {
406 406   new XWiki.widgets.Notification(l10n['edit.inplace.page.lockFailed'], 'error');
407 407   return Promise.reject(xwikiDocument);
... ... @@ -409,73 +409,6 @@
409 409   });
410 410   };
411 411  
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 -
479 479   var load = function(xwikiDocument) {
480 480   return xwikiDocument.reload().then(xwikiDocument => {
481 481   // 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,7 +15,6 @@
15 15   #set ($l10nKeys = [
16 16   'edit.inplace.page.renderFailed',
17 17   'edit.inplace.page.lockFailed',
18 - 'edit.inplace.close',
19 19   'edit.inplace.page.loadFailed',
20 20   'edit.inplace.actionButtons.loadFailed',
21 21   'core.editors.content.titleField.label',