Removing embedded attachments upon delete from WYSIWYG view
authorAlexander Ebert <ebert@woltlab.com>
Wed, 26 Nov 2014 01:09:43 +0000 (02:09 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 26 Nov 2014 01:09:43 +0000 (02:09 +0100)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js
wcfsetup/install/files/js/WCF.Attachment.js
wcfsetup/install/files/js/WCF.js

index 671197ef3eb532d13329fc8a0793157b02957ab7..c2d4e601757a40cdf3af2b6595d35005d2540e99 100644 (file)
@@ -1095,6 +1095,25 @@ RedactorPlugins.wbbcode = function() {
                        }
                },
                
+               /**
+                * Removes an attachment from WYSIWYG view.
+                * 
+                * @param       integer         attachmentID
+                */
+               removeAttachment: function(attachmentID) {
+                       if (!this.opts.visual) {
+                               // we're not going to mess with the code view
+                               return;
+                       }
+                       
+                       this.$editor.find('img.redactorEmbeddedAttachment').each(function(index, attachment) {
+                               var $attachment = $(attachment);
+                               if ($attachment.data('attachmentID') == attachmentID) {
+                                       $attachment.remove();
+                               }
+                       });
+               },
+               
                /**
                 * Returns a list of attachments representing an image.
                 * 
index 59040dcfe960c8adef0c9618ef283fb8e8aaf2f9..b96cc4974fc13545d9507bdc5be8a3150af0abd2 100644 (file)
@@ -58,7 +58,7 @@ WCF.Attachment.Upload = WCF.Upload.extend({
         */
        init: function(buttonSelector, fileListSelector, objectType, objectID, tmpHash, parentObjectID, maxUploads, wysiwygContainerID) {
                this._super(buttonSelector, fileListSelector, 'wcf\\data\\attachment\\AttachmentAction', { multiple: true, maxUploads: maxUploads });
-               console.debug(wysiwygContainerID);
+               
                this._autoInsert = [ ];
                this._objectType = objectType;
                this._objectID = objectID;
@@ -71,7 +71,8 @@ WCF.Attachment.Upload = WCF.Upload.extend({
                this._fileListSelector.find('.jsButtonAttachmentInsertThumbnail').click($.proxy(this._insert, this));
                this._fileListSelector.find('.jsButtonAttachmentInsertFull').click($.proxy(this._insert, this));
                
-               WCF.DOMNodeRemovedHandler.addCallback('WCF.Attachment.Upload', $.proxy(this._removeLimitError, this));
+               //WCF.DOMNodeRemovedHandler.addCallback('WCF.Attachment.Upload', $.proxy(this._removeLimitError, this));
+               WCF.System.Event.addListener('com.woltlab.wcf.action.delete', 'attachment_' + this._wysiwygContainerID, $.proxy(this._removeLimitError, this));
                
                this._makeSortable();
                
@@ -181,14 +182,9 @@ WCF.Attachment.Upload = WCF.Upload.extend({
        /**
         * Removes the limit error message.
         * 
-        * @param       object          event
+        * @param       object          data
         */
-       _removeLimitError: function(event) {
-               var $target = $(event.target);
-               if ($target.is('li.box48') && $target.parent().wcfIdentify() === this._fileListSelector.wcfIdentify()) {
-                       this._buttonSelector.next('small.innerError').remove();
-               }
-               
+       _removeLimitError: function(data) {
                var $listItems = this._fileListSelector.children('li');
                if (!$listItems.filter(':not(.uploadFailed)').length) {
                        this._insertAllButton.hide();
@@ -199,6 +195,10 @@ WCF.Attachment.Upload = WCF.Upload.extend({
                                this._fileListSelector.wcfBlindOut();
                        }).bind(this), 250);
                }
+               
+               if (this._wysiwygContainerID) {
+                       $('#' + this._wysiwygContainerID).redactor('wbbcode.removeAttachment', data.button.data('objectID'));
+               }
        },
        
        /**
@@ -308,7 +308,7 @@ WCF.Attachment.Upload = WCF.Upload.extend({
                                
                                // init buttons
                                var $buttonList = $li.find('ul').addClass('buttonGroup');
-                               var $deleteButton = $('<li><span class="button small jsDeleteButton" data-object-id="'+data.returnValues.attachments[$internalFileID]['attachmentID']+'" data-confirm-message="'+WCF.Language.get('wcf.attachment.delete.sure')+'">' + WCF.Language.get('wcf.global.button.delete') + '</span></li>');
+                               var $deleteButton = $('<li><span class="button small jsDeleteButton" data-object-id="'+data.returnValues.attachments[$internalFileID]['attachmentID']+'" data-confirm-message="'+WCF.Language.get('wcf.attachment.delete.sure')+'" data-event-name="attachment_' + this._wysiwygContainerID + '">' + WCF.Language.get('wcf.global.button.delete') + '</span></li>');
                                $buttonList.append($deleteButton);
                                
                                $li.data('objectID', data.returnValues.attachments[$internalFileID].attachmentID);
index 2e8d32506660111b1057827413440b1b7655c339..19c91e621a877747d85717e37082fa8cac1992c3 100755 (executable)
@@ -2519,12 +2519,20 @@ WCF.Action.Delete = Class.extend({
        triggerEffect: function(objectIDs) {
                for (var $index in this._containers) {
                        var $container = $('#' + this._containers[$index]);
-                       if (WCF.inArray($container.find(this._buttonSelector).data('objectID'), objectIDs)) {
+                       var $button = $container.find(this._buttonSelector);
+                       if (WCF.inArray($button.data('objectID'), objectIDs)) {
                                var self = this;
                                $container.wcfBlindOut('up',function() {
-                                       $(this).remove();
-                                       self._containers.splice(self._containers.indexOf($(this).wcfIdentify()), 1);
-                                       self._didTriggerEffect($(this));
+                                       var $container = $(this).remove();
+                                       self._containers.splice(self._containers.indexOf($container.wcfIdentify()), 1);
+                                       self._didTriggerEffect($container);
+                                       
+                                       if ($button.data('eventName')) {
+                                               WCF.System.Event.fireEvent('com.woltlab.wcf.action.delete', $button.data('eventName'), {
+                                                       button: $button,
+                                                       container: $container
+                                               });
+                                       }
                                });
                        }
                }