Fix deletion of media files via button
authorMatthias Schmidt <gravatronics@live.com>
Tue, 16 Aug 2016 17:07:37 +0000 (19:07 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 16 Aug 2016 17:07:41 +0000 (19:07 +0200)
com.woltlab.wcf/templates/mediaJavaScript.tpl
com.woltlab.wcf/templates/mediaListItems.tpl
wcfsetup/install/files/acp/templates/mediaJavaScript.tpl
wcfsetup/install/files/acp/templates/mediaListItems.tpl
wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Base.js
wcfsetup/install/files/js/WoltLabSuite/Core/Media/Upload.js

index 76d9aae80de49c658da8e97325c5daa9aeda57c8..c929e711be5ba473cdc32d3bd57e4be2a0a7aaa3 100644 (file)
@@ -3,6 +3,7 @@
                Language.addObject({
                        'wcf.global.button.insert': '{lang}wcf.global.button.insert{/lang}',
                        
+                       'wcf.media.delete.confirmMessage': '{lang __encode=true}wcf.media.delete.confirmMessage{/lang}',
                        'wcf.media.insert': '{lang}wcf.media.insert{/lang}',
                        'wcf.media.insert.imageSize': '{lang}wcf.media.insert.imageSize{/lang}',
                        'wcf.media.insert.imageSize.small': '{lang}wcf.media.insert.imageSize.small{/lang}',
index e87f2937ebe42e161e9cde87a560b99e064f4d9b..b2f0c5e53903a27f2b396fd62a590807d6af6458 100644 (file)
@@ -1,5 +1,5 @@
 {foreach from=$mediaList item=media}
-       <li class="jsClipboardObject" data-object-id="{@$media->mediaID}">
+       <li class="jsClipboardObject mediaFile" data-object-id="{@$media->mediaID}">
                <div class="mediaThumbnail">
                        {@$media->getElementTag(144)}
                </div>
@@ -18,7 +18,7 @@
                                                <a><span class="icon icon16 fa-pencil jsTooltip jsMediaEditIcon" data-object-id="{@$media->mediaID}" title="{lang}wcf.global.button.edit{/lang}"></span></a>
                                        </li>
                                        <li>
-                                               <a><span class="icon icon16 fa-times jsTooltip jsMediaDeleteIcon" data-object-id="{@$media->mediaID}" title="{lang}wcf.global.button.delete{/lang}"></span></a>
+                                               <a><span class="icon icon16 fa-times jsTooltip jsDeleteButton" data-object-id="{@$media->mediaID}" title="{lang}wcf.global.button.delete{/lang}" data-confirm-message-html="{lang __encode=true}wcf.media.delete.confirmMessage{/lang}"></span></a>
                                        </li>
                                {/if}
                                {if $mode == 'editor'}
index 76d9aae80de49c658da8e97325c5daa9aeda57c8..c929e711be5ba473cdc32d3bd57e4be2a0a7aaa3 100644 (file)
@@ -3,6 +3,7 @@
                Language.addObject({
                        'wcf.global.button.insert': '{lang}wcf.global.button.insert{/lang}',
                        
+                       'wcf.media.delete.confirmMessage': '{lang __encode=true}wcf.media.delete.confirmMessage{/lang}',
                        'wcf.media.insert': '{lang}wcf.media.insert{/lang}',
                        'wcf.media.insert.imageSize': '{lang}wcf.media.insert.imageSize{/lang}',
                        'wcf.media.insert.imageSize.small': '{lang}wcf.media.insert.imageSize.small{/lang}',
index 48ffdb73d9f71cfa0a367dbb989835e2662fc08e..ce2ff7e855d207cbea4643cebe6f27402a15d80e 100644 (file)
@@ -1,5 +1,5 @@
 {foreach from=$mediaList item=media}
-       <li class="jsClipboardObject" data-object-id="{@$media->mediaID}">
+       <li class="jsClipboardObject mediaFile" data-object-id="{@$media->mediaID}">
                <div class="mediaThumbnail">
                        {@$media->getElementTag(144)}
                </div>
@@ -18,7 +18,7 @@
                                                <a><span class="icon icon16 fa-pencil jsTooltip jsMediaEditIcon" data-object-id="{@$media->mediaID}" title="{lang}wcf.global.button.edit{/lang}"></span></a>
                                        </li>
                                        <li>
-                                               <a><span class="icon icon16 fa-times jsTooltip jsMediaDeleteIcon" data-object-id="{@$media->mediaID}" title="{lang}wcf.global.button.delete{/lang}"></span></a>
+                                               <a><span class="icon icon16 fa-times jsTooltip jsDeleteButton" data-object-id="{@$media->mediaID}" title="{lang}wcf.global.button.delete{/lang}" data-confirm-message-html="{lang __encode=true}wcf.media.delete.confirmMessage{/lang}"></span></a>
                                        </li>
                                {/if}
                                {if $mode == 'editor'}
index ee4036e929c53684176a99c9783a46d119db9ece..3de3e45265a1e6a641c1d6e8fe7e95cde910e6f6 100644 (file)
@@ -83,7 +83,7 @@ define(
                 */
                _clipboardAction: function(actionData) {
                        // only consider events if the action has been executed
-                       if (actionData.data.actionName === 'com.woltlab.wcf.media.delete' && actionData.responseData === null) {
+                       if (actionData.data.actionName === 'com.woltlab.wcf.media.delete' && actionData.responseData !== null) {
                                var mediaIds = actionData.responseData.objectIDs;
                                for (var i = 0, length = mediaIds.length; i < length; i++) {
                                        this.removeMedia(~~mediaIds[i], true);
@@ -137,6 +137,11 @@ define(
                                });
                                
                                EventHandler.add('com.woltlab.wcf.clipboard', 'com.woltlab.wcf.media', this._clipboardAction.bind(this));
+                               
+                               var deleteAction = new WCF.Action.Delete('wcf\\data\\media\\MediaAction', '.mediaFile');
+                               deleteAction._didTriggerEffect = function(element) {
+                                       this.removeMedia(elData(element[0], 'object-id'), true);
+                               }.bind(this);
                        }
                        
                        this._search = new MediaManagerSearch(this);
@@ -325,7 +330,12 @@ define(
                removeMedia: function(mediaId, checkCache) {
                        if (this._media.has(mediaId)) {
                                // remove list item
-                               elRemove(this._media.get(mediaId));
+                               try {
+                                       elRemove(this._media.get(mediaId));
+                               }
+                               catch (e) {
+                                       // ignore errors if item has already been removed like by WCF.Action.Delete
+                               }
                                
                                this._media.delete(mediaId);
                                this._mediaData.delete(mediaId);
@@ -432,8 +442,9 @@ define(
                                listItem.appendChild(a);
                                
                                icon = elCreate('span');
-                               icon.className = 'icon icon16 fa-times jsTooltip jsMediaDeleteIcon';
+                               icon.className = 'icon icon16 fa-times jsTooltip jsDeleteButton';
                                elData(icon, 'object-id', media.mediaID);
+                               elData(icon, 'confirm-message-html', Language.get('wcf.media.delete.confirmMessage'));
                                elAttr(icon, 'title', Language.get('wcf.global.button.delete'));
                                a.appendChild(icon);
                        }
index e26f6821e7b98462a364a33c3148e0d5a69de464..80a411f679d0d041df117b9d38bcb268799718ef 100644 (file)
@@ -123,7 +123,7 @@ define(
                                                fileIcon.classList.add(FileUtil.getIconClassByMimeType(media.fileType));
                                        }
                                        
-                                       file.className = 'jsClipboardObject';
+                                       file.className = 'jsClipboardObject mediaFile';
                                        elData(file, 'object-id', media.mediaID);
                                        
                                        if (this._mediaManager) {