Added support for attachment management during inline edit
authorAlexander Ebert <ebert@woltlab.com>
Thu, 17 Apr 2014 11:57:42 +0000 (13:57 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 17 Apr 2014 11:57:42 +0000 (13:57 +0200)
com.woltlab.wcf/templates/wysiwyg.tpl
wcfsetup/install/files/js/3rdParty/redactor/plugins/wupload.js
wcfsetup/install/files/js/WCF.Message.js
wcfsetup/install/files/lib/system/message/QuickReplyManager.class.php

index 889da3d3283c6532b4f3a0dcc5671a4046c4f75b..c721a908b8c32a6901e4ba091e4ea7521ee3c64a 100644 (file)
@@ -46,12 +46,25 @@ $(function() {
                {if $wysiwygEnableUpload}
                        $config.plugins.push('wupload');
                        $config.wattachment = {
+                               attachments: [ ],
                                maxCount: {@$attachmentHandler->getMaxCount()},
                                objectType: '{@$attachmentObjectType}',
                                objectID: '{@$attachmentObjectID}',
                                parentObjectID: '{@$attachmentParentObjectID}',
                                tmpHash: '{$tmpHash|encodeJS}'
                        };
+                       
+                       {if $attachmentList|isset && !$attachmentList|empty}
+                               {foreach from=$attachmentList item=attachment}
+                                       $config.wattachment.attachments.push({
+                                               attachmentID: {@$attachment->attachmentID},
+                                               filename: '{$attachment->filename|encodeJs}',
+                                               isImage: {if $attachment->isImage}true{else}false{/if},
+                                               tinyThumbnailUrl: '{if $attachment->tinyThumbnailType}{link controller='Attachment' object=$attachment}tiny=1{/link}{/if}',
+                                               url: '{link controller='Attachment' object=$attachment}{/link}'
+                                       });
+                               {/foreach}
+                       {/if}
                {/if}
                
                {event name='javascriptInit'}
index eb7b2142f5eeafe0d723f0c179d401480b1686fc..2ba974dcb0321b9bcbe705147177cbd44b8c0b9b 100644 (file)
@@ -30,10 +30,34 @@ RedactorPlugins.wupload = {
         */
        _initAttachments: function() {
                this._attachmentsContainer = $('<div class="redactorAttachmentContainer" />').hide().appendTo(this.$box);
-               $('<ul class="formAttachmentList clearfix" />').hide().appendTo(this._attachmentsContainer);
+               var $attachmentList = $('<ul class="formAttachmentList clearfix" />').hide().appendTo(this._attachmentsContainer);
                $('<dl class="wide"><dt></dt><dd><div data-max-size="{@$attachmentHandler->getMaxSize()}"></div><small>' + WCF.String.unescapeHTML(WCF.Language.get('wcf.attachment.upload.limits')) + '</small></dd></dl>').appendTo(this._attachmentsContainer);
                
                var $options = this.getOption('wattachment');
+               if ($options.attachments.length) {
+                       for (var $i = 0; $i < $options.attachments.length; $i++) {
+                               var $attachment = $options.attachments[$i];
+                               var $listItem = $('<li class="box48" />');
+                               if ($attachment.tinyThumbnailUrl) {
+                                       $('<img src="' + $attachment.tinyThumbnailUrl + '" alt="" class="attachmentTinyThumbnail" />').appendTo($listItem);
+                               }
+                               else {
+                                       $('<span class="icon icon48 icon-paper-clip" />').appendTo($listItem);
+                               }
+                               
+                               var $div = $('<div />').appendTo($listItem);
+                               $('<div><p><a href="' + $attachment.url + '"' + ($attachment.isImage ? ' title="' + $attachment.filename + '" class="jsImageViewer"' : '') + '>' + $attachment.filename + '</a></p></div>').appendTo($div);
+                               var $list = $('<ul />').appendTo($div);
+                               $('<li><span class="icon icon16 icon-remove pointer jsTooltip jsDeleteButton " title="' + WCF.Language.get('wcf.global.button.delete') + '" data-object-id="' + $attachment.attachmentID + '" data-confirm-message="' + WCF.Language.get('wcf.attachment.delete.sure') + '"></span></li>').appendTo($list);
+                               $('<li><span class="icon icon16 icon-paste pointer jsTooltip jsButtonInsertAttachment" title="' + WCF.Language.get('wcf.attachment.insert') + '" data-object-id="' + $attachment.attachmentID + '"></span></li>').appendTo($list);
+                               
+                               $listItem.appendTo($attachmentList);
+                               
+                               this._attachmentsContainer.show();
+                               $attachmentList.show();
+                       }
+               }
+               
                new WCF.Attachment.Upload(this._attachmentsContainer.find('> dl > dd > div'), this._attachmentsContainer.children('ul'), $options.objectType, $options.objectID, $options.tmpHash, $options.parentObjectID, $options.maxCount, this.$source.wcfIdentify());
                new WCF.Action.Delete('wcf\\data\\attachment\\AttachmentAction', '.formAttachmentList > li');
        }
index bec2fe99a4843e9e497dce28c0b916629b74e5c4..b84a0a4f1c140c8240aa289b87b8c52482006c55 100644 (file)
@@ -1212,6 +1212,7 @@ WCF.Message.InlineEditor = Class.extend({
                
                // hide unrelated content
                $content.parent().children('.jsInlineEditorHideContent').hide();
+               $messageBody.children('.attachmentThumbnailList, .attachmentFileList').hide();
                
                this._cache = $content.detach();
        },
@@ -1231,6 +1232,7 @@ WCF.Message.InlineEditor = Class.extend({
                var $messageBody = $container.find('.messageBody');
                $messageBody.children('.icon-spinner').remove();
                $messageBody.children('div:eq(0)').html(this._cache);
+               $messageBody.children('.attachmentThumbnailList, .attachmentFileList').show();
                
                // show unrelated content
                $messageBody.find('.jsInlineEditorHideContent').show();
@@ -1316,6 +1318,7 @@ WCF.Message.InlineEditor = Class.extend({
                var $messageBody = this._container[this._activeElementID].removeClass('jsInvalidQuoteTarget').find('.messageBody');
                $messageBody.children('span.icon-spinner').remove();
                $messageBody.children('div:eq(0)').children().show();
+               $messageBody.children('.attachmentThumbnailList, .attachmentFileList').show();
                
                // show unrelated content
                $messageBody.find('.jsInlineEditorHideContent').show();
@@ -1396,6 +1399,7 @@ WCF.Message.InlineEditor = Class.extend({
                var $messageBody = this._container[this._activeElementID].removeClass('jsInvalidQuoteTarget').find('.messageBody');
                $('<span class="icon icon48 icon-spinner" />').appendTo($messageBody);
                $messageBody.children('div:eq(0)').children().hide();
+               $messageBody.children('.attachmentThumbnailList, .attachmentFileList').show();
                
                // show unrelated content
                $messageBody.find('.jsInlineEditorHideContent').show();
@@ -1432,6 +1436,17 @@ WCF.Message.InlineEditor = Class.extend({
                // insert new message
                $content.html('<div class="messageText">' + data.returnValues.message + '</div>');
                
+               if (data.returnValues.attachmentList == undefined) {
+                       $messageBody.children('.attachmentThumbnailList, .attachmentFileList').show();
+               }
+               else {
+                       $messageBody.children('.attachmentThumbnailList, .attachmentFileList').remove();
+                       
+                       if (data.returnValues.attachmentList) {
+                               $(data.returnValues.attachmentList).insertAfter($messageBody.children('div:eq(0)'));
+                       }
+               }
+               
                this._activeElementID = '';
                
                this._updateHistory(this._getHash($container.data('objectID')));
index 165ce50fcb6503990be5086b15c1f02daed1697e..016186389b5a95661869faf66c7f410aef149de8 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\system\message;
 use wcf\data\DatabaseObjectDecorator;
+use wcf\data\IAttachmentMessageQuickReplyAction;
 use wcf\data\IMessage;
 use wcf\data\IMessageQuickReplyAction;
 use wcf\system\bbcode\PreParser;
@@ -13,7 +14,6 @@ use wcf\util\ArrayUtil;
 use wcf\util\ClassUtil;
 use wcf\util\MessageUtil;
 use wcf\util\StringUtil;
-use wcf\data\IAttachmentMessageQuickReplyAction;
 
 /**
  * Manages quick replies and stored messages.