From 7ed8dd25a2d26047c71ac625000eaa6dd5abf63b Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Thu, 29 Dec 2016 07:28:49 +0100 Subject: [PATCH] Fix editing and inserting searched media MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit … and improve naming of variables --- .../WoltLabSuite/Core/Media/Manager/Base.js | 28 +++++++++---------- .../WoltLabSuite/Core/Media/Manager/Editor.js | 2 +- .../WoltLabSuite/Core/Media/Manager/Select.js | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Base.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Base.js index a17dc50245..536fbf3c00 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Base.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Base.js @@ -32,8 +32,8 @@ define( minSearchLength: 3 }, options); + this._listItems = new Dictionary(); this._media = new Dictionary(); - this._mediaData = new Dictionary(); this._mediaCache = null; this._mediaManagerMediaList = null; this._search = null; @@ -115,7 +115,7 @@ define( var media = data.returnValues.media || { }; for (var mediaId in media) { if (objOwns(media, mediaId)) { - this._mediaData.set(~~mediaId, media[mediaId]); + this._media.set(~~mediaId, media[mediaId]); } } @@ -126,7 +126,7 @@ define( for (var i = 0, length = listItems.length; i < length; i++) { var listItem = listItems[i]; - this._media.set(~~elData(listItem, 'object-id'), listItem); + this._listItems.set(~~elData(listItem, 'object-id'), listItem); } if (Permission.get('admin.content.cms.canManageMedia')) { @@ -212,7 +212,7 @@ define( UiDialog.close('mediaManager'); - this._mediaEditor.edit(this._mediaData.get(~~elData(event.currentTarget, 'object-id'))); + this._mediaEditor.edit(this._media.get(~~elData(event.currentTarget, 'object-id'))); }, /** @@ -231,9 +231,9 @@ define( _editorSuccess: function(media) { UiDialog.open(this); - this._mediaData.set(~~media.mediaID, media); + this._media.set(~~media.mediaID, media); - var listItem = this._media.get(~~media.mediaID); + var listItem = this._listItems.get(~~media.mediaID); var p = elByClass('mediaTitle', listItem)[0]; if (media.isMultilingual) { p.textContent = media.title[LANGUAGE_ID] || media.filename; @@ -315,10 +315,10 @@ define( addMedia: function(media, listItem) { if (!media.languageID) media.isMultilingual = 1; - this._mediaData.set(~~media.mediaID, media); - this._media.set(~~media.mediaID, listItem); + this._media.set(~~media.mediaID, media); + this._listItems.set(~~media.mediaID, listItem); - if (this._media.size === 1) { + if (this._listItems.size === 1) { this._search.showSearch(); } }, @@ -353,17 +353,17 @@ define( * @param {boolean|undefined} checkCache media file will also be removed from the local cache if true */ removeMedia: function(mediaId, checkCache) { - if (this._media.has(mediaId)) { + if (this._listItems.has(mediaId)) { // remove list item try { - elRemove(this._media.get(mediaId)); + elRemove(this._listItems.get(mediaId)); } catch (e) { // ignore errors if item has already been removed like by WCF.Action.Delete } + this._listItems.delete(mediaId); this._media.delete(mediaId); - this._mediaData.delete(mediaId); } if (checkCache && this._mediaCache && this._mediaCache.has(mediaId)) { @@ -410,8 +410,8 @@ define( var listItems = DomTraverse.childrenByTag(ul, 'LI'); for (var i = 0, length = listItems.length; i < length; i++) { var listItem = listItems[i]; - if (!this._mediaData.has(~~elData(listItem, 'object-id'))) { - this._mediaData.set(elData(listItem, 'object-id'), listItem); + if (!this._listItems.has(~~elData(listItem, 'object-id'))) { + this._listItems.set(elData(listItem, 'object-id'), listItem); this._mediaManagerMediaList.appendChild(listItem); } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Editor.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Editor.js index 56aac514ca..e79192a731 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Editor.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Editor.js @@ -311,7 +311,7 @@ define(['Core', 'Dictionary', 'Dom/Traverse', 'Language', 'Ui/Dialog', 'WoltLabS // open the insert dialog if all media files are images var imagesOnly = true, media; for (var i = 0, length = mediaIds.length; i < length; i++) { - media = this._mediaData.get(mediaIds[i]); + media = this._media.get(mediaIds[i]); this._mediaToInsert.set(media.mediaID, media); if (!media.isImage) { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Select.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Select.js index b63056b6ca..428f213e4c 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Select.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Manager/Select.js @@ -78,7 +78,7 @@ define(['Core', 'Dom/Traverse', 'Dom/Util', 'Language', 'ObjectMap', 'Ui/Dialog' throw new Error("Media cannot be chosen if no button is active."); } - var media = this._mediaData.get(~~elData(event.currentTarget, 'object-id')); + var media = this._media.get(~~elData(event.currentTarget, 'object-id')); // save selected media in store element elById(elData(this._activeButton, 'store')).value = media.mediaID; -- 2.20.1