Changes for page InplaceEditing

From version 4.1
edited by Nazzareno Pompei
on 28/10/2022 08:43
Change comment: Install extension [org.xwiki.platform:xwiki-platform-edit-ui/14.9]
To version 5.1
edited by Nazzareno Pompei
on 30/01/2023 10:31
Change comment: Install extension [org.xwiki.platform:xwiki-platform-edit-ui/14.10.3]

Summary

Details

XWiki.JavaScriptExtension[0]
Code
... ... @@ -223,7 +223,7 @@
223 223   };
224 224  
225 225   var loadCSS = function(url) {
226 - var link = $('<link>').attr({
226 + $('<link/>').attr({
227 227   type: 'text/css',
228 228   rel: 'stylesheet',
229 229   href: url
... ... @@ -695,6 +695,12 @@
695 695   });
696 696   };
697 697  
698 + function addToFormData(formData, inputs) {
699 + inputs.serializeArray().forEach(function(entry) {
700 + formData.append(entry.name, entry.value);
701 + });
702 + }
703 +
698 698   // actionButtons.js expects a form so we use a fake form. Refactoring actionButtons.js is too dangerous ATM.
699 699   var fakeForm = {
700 700   action: XWiki.currentDocument.getURL('save'),
... ... @@ -725,45 +725,33 @@
725 725   return this._getActionButtons().find(selector)[0];
726 726   },
727 727   serialize: function() {
728 - var extra = this._getActionButtons().find(':input').serializeArray().reduce(function(extra, entry) {
729 - var value = extra[entry.name] || [];
730 - value.push(entry.value);
731 - extra[entry.name] = value;
732 - return extra;
733 - }, {});
734 + var formData = new FormData();
735 + addToFormData(formData, this._getActionButtons().find(':input'));
734 734   // retrieve all input fields listing the temporary uploaded files.
735 - var uploadedFiles = $('#xwikicontent').nextAll('input[name="uploadedFiles"]').serializeArray().reduce(function(extra, entry) {
736 - var value = extra[entry.name] || [];
737 - value.push(entry.value);
738 - extra[entry.name] = value;
739 - return extra;
740 - }, {});
741 741   var xwikiDocument = this._getActionButtons().data('xwikiDocument');
742 - var formData = {
743 - title: xwikiDocument.rawTitle,
744 - language: xwikiDocument.getRealLocale(),
745 - isNew: xwikiDocument.isNew
746 - };
747 - if (xwikiDocument.content != xwikiDocument.originalDocument.content) {
738 + formData.set('title', xwikiDocument.rawTitle);
739 + formData.set('language', xwikiDocument.getRealLocale());
740 + formData.set('isNew', xwikiDocument.isNew);
741 +
742 + if (xwikiDocument.content !== xwikiDocument.originalDocument.content) {
748 748   // Submit the raw (source) content. No syntax conversion is needed in this case.
749 - formData.content = xwikiDocument.content;
744 + formData.set('content', xwikiDocument.content);
750 750   } else {
751 751   // Submit the rendered content (HTML), but make sure it is converted to the document syntax on the server.
752 - $.extend(formData, {
753 - content: xwikiDocument.renderedContent,
754 - RequiresHTMLConversion: 'content',
755 - content_syntax: xwikiDocument.syntax
756 - });
747 + formData.set('content', xwikiDocument.renderedContent);
748 + formData.set('RequiresHTMLConversion', 'content');
749 + formData.set('content_syntax', xwikiDocument.syntax);
757 757   }
758 758   // Add the temporary uploaded files to the form.
759 - $.extend(formData, uploadedFiles);
752 + addToFormData(formData, $('#xwikicontent').nextAll('input[name="uploadedFiles"]'));
753 +
760 760   // Check for merge conflicts only if the document is not new and we know the current version.
761 761   if (!xwikiDocument.isNew && xwikiDocument.version) {
762 - formData.previousVersion = xwikiDocument.version;
763 - formData.editingVersionDate = new Date(xwikiDocument.modified).getTime();
756 + formData.set('previousVersion', xwikiDocument.version);
757 + formData.set('editingVersionDate', new Date(xwikiDocument.modified).getTime());
764 764   }
765 - // Ensure that formData information has priority over extra information.
766 - return $.extend({}, extra, formData);
759 + // Note: if you refactor, please make sure that actionsButtons inputs have the lowest priority.
760 + return formData;
767 767   }
768 768   };
769 769