Preserving tmpHash when jumping to extended form
authorAlexander Ebert <ebert@woltlab.com>
Tue, 20 Jan 2015 17:18:35 +0000 (18:18 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 20 Jan 2015 17:18:35 +0000 (18:18 +0100)
wcfsetup/install/files/js/WCF.Attachment.js
wcfsetup/install/files/js/WCF.Message.js
wcfsetup/install/files/lib/form/MessageForm.class.php
wcfsetup/install/files/lib/system/message/QuickReplyManager.class.php

index ffc1fbd2acaed424644b63ad6e2a9a8c18c32e20..06c19c9c21151ccaca37bf162fe4b2d396676d39 100644 (file)
@@ -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.
         */
index dd0a35a72418b9d00a973898c9faec4202719bdb..fc93ab916308471acf0fa9375fd7ee753e9c1e66 100644 (file)
@@ -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');
index ee7f07a1777710f17676ce79462629ca6000cf74..93bbb92d76d02adf326e106b392eb4c1f1a7ce5b 100644 (file)
@@ -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) {
index fce35eaf73bb9068750d6c86ac91e4bb91daf729..73bab5df0cc14937b618c689a493caf751866456 100644 (file)
@@ -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);
+       }
 }