From 4252ea67cffe31b584bfeb40883e3481b2997be6 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 20 Jan 2015 18:18:35 +0100 Subject: [PATCH] Preserving tmpHash when jumping to extended form --- wcfsetup/install/files/js/WCF.Attachment.js | 16 ++++++++++++++-- wcfsetup/install/files/js/WCF.Message.js | 12 ++++++++---- .../install/files/lib/form/MessageForm.class.php | 8 +++++++- .../system/message/QuickReplyManager.class.php | 9 +++++++++ 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.Attachment.js b/wcfsetup/install/files/js/WCF.Attachment.js index ffc1fbd2ac..06c19c9c21 100644 --- a/wcfsetup/install/files/js/WCF.Attachment.js +++ b/wcfsetup/install/files/js/WCF.Attachment.js @@ -61,9 +61,9 @@ WCF.Attachment.Upload = WCF.Upload.extend({ this._autoInsert = [ ]; this._objectType = objectType; - this._objectID = objectID; + this._objectID = parseInt(objectID); this._tmpHash = tmpHash; - this._parentObjectID = parentObjectID; + this._parentObjectID = parseInt(parentObjectID); this._wysiwygContainerID = wysiwygContainerID; this._buttonSelector.children('p.button').click($.proxy(this._validateLimit, this)); @@ -85,6 +85,7 @@ WCF.Attachment.Upload = WCF.Upload.extend({ if (this._wysiwygContainerID) { WCF.System.Event.addListener('com.woltlab.wcf.messageOptionsInline', 'submit_' + this._wysiwygContainerID, $.proxy(this._submitInline, this)); + WCF.System.Event.addListener('com.woltlab.wcf.messageOptionsInline', 'prepareExtended_' + this._wysiwygContainerID, $.proxy(this._prepareExtended, this)); WCF.System.Event.addListener('com.woltlab.wcf.redactor', 'reset', $.proxy(this._reset, this)); WCF.System.Event.addListener('com.woltlab.wcf.redactor', 'upload_' + this._wysiwygContainerID, $.proxy(this._editorUpload, this)); WCF.System.Event.addListener('com.woltlab.wcf.redactor', 'getImageAttachments_' + this._wysiwygContainerID, $.proxy(this._getImageAttachments, this)); @@ -141,6 +142,17 @@ WCF.Attachment.Upload = WCF.Upload.extend({ } }, + /** + * Adds parameters send to the server before jumping to extended form. + * + * @param object data + */ + _prepareExtended: function(data) { + if (!this._objectID && this._tmpHash && this._fileListSelector.children('li:not(.uploadFailed)').length) { + data.tmpHash = this._tmpHash; + } + }, + /** * Resets the attachment container. */ diff --git a/wcfsetup/install/files/js/WCF.Message.js b/wcfsetup/install/files/js/WCF.Message.js index dd0a35a724..fc93ab9163 100644 --- a/wcfsetup/install/files/js/WCF.Message.js +++ b/wcfsetup/install/files/js/WCF.Message.js @@ -1079,16 +1079,20 @@ WCF.Message.QuickReply = Class.extend({ $message = $.trim(this._messageField.val()); } + var $parameters = { + containerID: this._getObjectID(), + message: $message + }; + + WCF.System.Event.fireEvent('com.woltlab.wcf.messageOptionsInline', 'prepareExtended_' + this._messageField.wcfIdentify(), $parameters); + new WCF.Action.Proxy({ autoSend: true, data: { actionName: 'jumpToExtended', className: this._getClassName(), interfaceName: 'wcf\\data\\IExtendedMessageQuickReplyAction', - parameters: { - containerID: this._getObjectID(), - message: $message - } + parameters: $parameters }, success: (function(data) { this._messageField.redactor('wutil.saveTextToStorage'); diff --git a/wcfsetup/install/files/lib/form/MessageForm.class.php b/wcfsetup/install/files/lib/form/MessageForm.class.php index ee7f07a177..93bbb92d76 100644 --- a/wcfsetup/install/files/lib/form/MessageForm.class.php +++ b/wcfsetup/install/files/lib/form/MessageForm.class.php @@ -172,7 +172,13 @@ abstract class MessageForm extends AbstractCaptchaForm { $this->tmpHash = $_REQUEST['tmpHash']; } if (empty($this->tmpHash)) { - $this->tmpHash = StringUtil::getRandomID(); + $this->tmpHash = WCF::getSession()->getVar('__wcfAttachmentTmpHash'); + if ($this->tmpHash === null) { + $this->tmpHash = StringUtil::getRandomID(); + } + else { + WCF::getSession()->unregister('__wcfAttachmentTmpHash'); + } } if ($this->enableMultilingualism) { diff --git a/wcfsetup/install/files/lib/system/message/QuickReplyManager.class.php b/wcfsetup/install/files/lib/system/message/QuickReplyManager.class.php index fce35eaf73..73bab5df0c 100644 --- a/wcfsetup/install/files/lib/system/message/QuickReplyManager.class.php +++ b/wcfsetup/install/files/lib/system/message/QuickReplyManager.class.php @@ -259,4 +259,13 @@ class QuickReplyManager extends SingletonFactory { public function getContainer() { return $this->container; } + + /** + * Stores tmpHash in current session, used in combination with the extended form. + * + * @param string $tmpHash + */ + public function setTmpHash($tmpHash) { + WCF::getSession()->register('__wcfAttachmentTmpHash', $tmpHash); + } } -- 2.20.1