Item15189: Redirectto parameter breaks preview function

pencil
Priority: Normal
Current State: Closed
Released In: 2.1.8
Target Release: patch
Applies To: Extension
Component: NatEditPlugin
Branches: Release02x01 master
Reported By: LynnwoodBrown
Waiting For:
Last Change By: MichaelDaum
If the edit url includes a redirectto parameter, clicking the "Preview" button in topic action bar does not work as expected (no pop-up with preview). No other url parameter causes this issue.

In my effort to find a work-around, I was able to modify jquery.natedit.js as follows to simply disable the redirectto form element prior to triggering the preview url and then re-enabling after preview is rendered. Here's my modification (in red):
 /* preview handler */
  self.form.find(".ui-natedit-preview").on("click", function() {

    if (self.form.validate().form()) {
      self.beforeSubmit("preview");
      self.form.find("input[name=redirectto]").prop('disabled',true);
      self.form.ajaxSubmit({
        url: foswiki.getScriptUrl( 'rest', 'NatEditPlugin', 'save'),  // SMELL: use this one for REST as long as the normal save can't cope with REST
        beforeSubmit: function() {
          self.hideMessages();
          $.blockUI({
            message: '<h1> Loading preview ... </h1>'
          });
        },
        error: function(xhr, textStatus, errorThrown) {
          var message = self.extractErrorMessage(xhr.responseText || textStatus);
          $.unblockUI();
          self.showMessage("error", message);
        },
        success: function(data, textStatus) {
          var $window = $(window),
            height = Math.round(parseInt($window.height() * 0.6, 10)),
            width = Math.round(parseInt($window.width() * 0.6, 10));

          $.unblockUI();

          if (width < 640) {
            width = 640;
          }

          data = data.replace(/%width%/g, width).replace(/%height%/g, height);
          $("body").append(data);
        }
      });
      self.form.find("input[name=redirectto]").prop('disabled',false);
    }
    return false;
  });

-- LynnwoodBrown - 25 Apr 2023

 
Topic revision: r4 - 06 Aug 2023, MichaelDaum
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy