Remove media add page and media edit form in ACP
authorMatthias Schmidt <gravatronics@live.com>
Thu, 1 Sep 2016 15:51:44 +0000 (17:51 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Thu, 1 Sep 2016 15:51:47 +0000 (17:51 +0200)
Media add page has only been a minimal page anyway without any benefit
over the direct upload button on the media list page and media editing
is now always handled via the dialog editor directly.

16 files changed:
com.woltlab.wcf/acpMenu.xml
com.woltlab.wcf/templates/headIncludeJavaScript.tpl
com.woltlab.wcf/templates/mediaEditor.tpl
wcfsetup/install/files/acp/templates/header.tpl
wcfsetup/install/files/acp/templates/mediaAdd.tpl [deleted file]
wcfsetup/install/files/acp/templates/mediaEditor.tpl
wcfsetup/install/files/acp/templates/mediaList.tpl
wcfsetup/install/files/js/WoltLabSuite/Core/Controller/Media/List.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Media/Editor.js
wcfsetup/install/files/js/WoltLabSuite/Core/Media/List/Upload.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Upload.js
wcfsetup/install/files/lib/acp/form/MediaEditForm.class.php [deleted file]
wcfsetup/install/files/lib/acp/page/MediaAddPage.class.php [deleted file]
wcfsetup/install/files/lib/data/media/MediaAction.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index fe7c1a951775f5b517b357f62a8132ae10f26e85..1dee560d6c395aedf6c7b9e837a4cd9d5175fb26 100644 (file)
                                <parent>wcf.acp.menu.link.cms</parent>
                                <permissions>admin.content.cms.canManageMedia</permissions>
                        </acpmenuitem>
-                       <acpmenuitem name="wcf.acp.menu.link.cms.media.add">
-                               <controller>wcf\acp\form\MediaAddForm</controller>
-                               <parent>wcf.acp.menu.link.cms.media.list</parent>
-                               <permissions>admin.content.cms.canManageMedia</permissions>
-                               <icon>fa-plus</icon>
-                       </acpmenuitem>
                        <!-- /cms -->
                
                        <!-- article -->
index b3f9ac4eb31d7f798f778f00774a474e117ce5a7..edc2ff04ee0fa7684f8f21accf57093e179d8718 100644 (file)
@@ -67,8 +67,8 @@ requirejs.config({
                        'wcf.global.form.error.empty': '{lang}wcf.global.form.error.empty{/lang}',
                        'wcf.global.form.error.greaterThan': '{lang __literal=true}wcf.global.form.error.greaterThan{/lang}',
                        'wcf.global.form.error.lessThan': '{lang __literal=true}wcf.global.form.error.lessThan{/lang}',
-                       'wcf.global.form.input.maxItems': '{lang}wcf.global.form.input.maxItems{/lang}',
                        'wcf.global.form.error.multilingual': '{lang}wcf.global.form.error.multilingual{/lang}',
+                       'wcf.global.form.input.maxItems': '{lang}wcf.global.form.input.maxItems{/lang}',
                        'wcf.global.language.noSelection': '{lang}wcf.global.language.noSelection{/lang}',
                        'wcf.global.loading': '{lang}wcf.global.loading{/lang}',
                        'wcf.global.noSelection': '{lang}wcf.global.noSelection{/lang}',
index ef718a76d85f42a352c9d883adf317e1aa7f67ed..28b74c2c5b7c7a0ec5bf3ed6aa0de4b355baff2c 100644 (file)
        {else}
                {@$media->getElementTag(48)}
        {/if}
-
+       
        <dl class="plain dataList">
                <dt>{lang}wcf.media.filename{/lang}</dt>
                <dd id="mediaFilename">{$media->filename}</dd>
-
+               
                <dt>{lang}wcf.media.filesize{/lang}</dt>
                <dd id="mediaFilesize">{@$media->filesize|filesize}</dd>
-
+               
                {if $media->isImage}
                        <dt>{lang}wcf.media.imageDimensions{/lang}</dt>
                        <dd id="mediaImageDimensions">{lang}wcf.media.imageDimensions.value{/lang}</dd>
                {/if}
-
+               
                <dt>{lang}wcf.media.uploader{/lang}</dt>
                <dd id="mediaUploader">{@$media->getUserProfile()->getAnchorTag()}</dd>
        </dl>
@@ -30,7 +30,7 @@
 
 <section class="section">
        <h2 class="sectionTitle">{lang}wcf.global.form.data{/lang}</h2>
-
+       
        <dl>
                <dt></dt>
                <dd>
                        </label>
                </dd>
        </dl>
-
+       
        {include file='languageChooser' label='wcf.media.languageID'}
-
+       
        <dl>
                <dt><label for="title_{@$media->mediaID}">{lang}wcf.global.title{/lang}</label></dt>
                <dd>
-                       <input type="text" id="title_{@$media->mediaID}" name="title" class="long" value="TODO">
+                       <input type="text" id="title_{@$media->mediaID}" name="title" class="long">
                </dd>
        </dl>
        {include file='multipleLanguageInputJavascript' elementIdentifier='title'|concat:'_':$media->mediaID forceSelection=true}
-
+       
        <dl>
                <dt><label for="caption_{@$media->mediaID}">{lang}wcf.media.caption{/lang}</label></dt>
                <dd>
-                       <textarea id="caption_{@$media->mediaID}" name="caption" cols="40" rows="3">TODO</textarea>
+                       <textarea id="caption_{@$media->mediaID}" name="caption" cols="40" rows="3"></textarea>
                </dd>
        </dl>
        {include file='multipleLanguageInputJavascript' elementIdentifier='caption'|concat:'_':$media->mediaID forceSelection=true}
-
+       
        <dl>
                <dt><label for="altText_{@$media->mediaID}">{lang}wcf.media.altText{/lang}</label></dt>
                <dd>
-                       <input type="text" id="altText_{@$media->mediaID}" name="altText" class="long" value="TODO">
+                       <input type="text" id="altText_{@$media->mediaID}" name="altText" class="long">
                </dd>
        </dl>
        {include file='multipleLanguageInputJavascript' elementIdentifier='altText'|concat:'_':$media->mediaID forceSelection=true}
-
+       
        {event name='dataFields'}
 </section>
 
index 6321d46f81c85545599240970895c5d3e4993e66..7badf6ea271e9a1fa006fb66f112916cce72d0da 100644 (file)
@@ -83,6 +83,7 @@
                                        'wcf.global.form.error.empty': '{lang}wcf.global.form.error.empty{/lang}',
                                        'wcf.global.form.error.greaterThan': '{lang __literal=true}wcf.global.form.error.greaterThan{/lang}',
                                        'wcf.global.form.error.lessThan': '{lang __literal=true}wcf.global.form.error.lessThan{/lang}',
+                                       'wcf.global.form.error.multilingual': '{lang}wcf.global.form.error.multilingual{/lang}',
                                        'wcf.global.loading': '{lang}wcf.global.loading{/lang}',
                                        'wcf.global.noSelection': '{lang}wcf.global.noSelection{/lang}',
                                        'wcf.page.jumpTo': '{lang}wcf.page.jumpTo{/lang}',
diff --git a/wcfsetup/install/files/acp/templates/mediaAdd.tpl b/wcfsetup/install/files/acp/templates/mediaAdd.tpl
deleted file mode 100644 (file)
index 1279f72..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-{include file='header' pageTitle='wcf.acp.media.'|concat:$action}
-
-{if $action == 'add'}
-       <script data-relocate="true">
-               require(['EventHandler', 'WoltLabSuite/Core/Media/Upload'], function(EventHandler, MediaUpload) {
-                       new MediaUpload('uploadButton', 'mediaFile');
-                       
-                       // redirect the user to the edit form after uploading the file
-                       EventHandler.add('com.woltlab.wcf.media.upload', 'success', function(data) {
-                               for (var index in data.media) {
-                                       window.location = '{link controller='MediaEdit' id=2147483648 encode=false}{/link}'.replace(2147483648, data.media[index].mediaID);
-                               }
-                       });
-               });
-       </script>
-{/if}
-
-<header class="contentHeader">
-       <div class="contentHeaderTitle">
-               <h1 id="mediaActionTitle" class="contentTitle">{lang}wcf.acp.media.{$action}{/lang}</h1>
-       </div>
-       
-       <nav class="contentHeaderNavigation">
-               <ul>
-                       <li><a href="{link controller='MediaList'}{/link}" class="button"><span class="icon icon16 fa-list"></span> <span>{lang}wcf.acp.menu.link.media.list{/lang}</span></a></li>
-                       
-                       {event name='contentHeaderNavigation'}
-               </ul>
-       </nav>
-</header>
-
-{if $action == 'edit'}
-       {include file='formError'}
-{/if}
-
-{if $success|isset}
-       <p class="success">{lang}wcf.global.success.{$action}{/lang}</p>
-{/if}
-
-{if $action == 'add'}
-       <section class="section">
-               <h2 class="sectionTitle">{lang}wcf.media.file{/lang}</h2>
-               
-               <dl>
-                       <dt></dt>
-                       <dd>
-                               <div id="mediaFile"></div>
-                               <div id="uploadButton"></div>
-                       </dd>
-               </dl>
-       </section>
-{else}
-       <form method="post" action="{link controller='MediaEdit' object=$media}{/link}">
-               <section class="section">
-                       <h2 class="sectionTitle">{lang}wcf.global.form.data{/lang}</h2>
-                       
-                       <dl>
-                               <dt>{lang}wcf.media.file{/lang}</dt>
-                               <dd>
-                                       {if $media->isImage}
-                                               {@$media->getThumbnailTag('small')}
-                                       {else}
-                                               {$media->filename}
-                                       {/if}
-                               </dd>
-                       </dl>
-                       
-                       <dl>
-                               <dt></dt>
-                               <dd>
-                                       <label>
-                                               <input type="checkbox" id="isMultilingual" name="isMultilingual" value="1"{if $isMultilingual} checked{/if}>
-                                               <span>{lang}wcf.media.isMultilingual{/lang}</span>
-                                       </label>
-                               </dd>
-                       </dl>
-                       
-                       {include file='languageChooser' label='wcf.media.languageID'}
-                       
-                       <dl{if $errorField == 'title'} class="formError"{/if}>
-                               <dt>{lang}wcf.global.title{/lang}</dt>
-                               <dd>
-                                       <input type="text" id="title" name="title" value="{$i18nPlainValues['title']}" class="long">
-                                       {if $errorField == 'title'}
-                                               <small class="innerError">
-                                                       {if $errorType == 'title' || $errorType == 'multilingual'}
-                                                               {lang}wcf.global.form.error.{@$errorType}{/lang}
-                                                       {else}
-                                                               {lang}wcf.media.title.error.{@$errorType}{/lang}
-                                                       {/if}
-                                               </small>
-                                       {/if}
-                               </dd>
-                       </dl>
-                       {include file='multipleLanguageInputJavascript' elementIdentifier='title' forceSelection=true}
-                       
-                       <dl{if $errorField == 'caption'} class="formError"{/if}>
-                               <dt>{lang}wcf.media.caption{/lang}</dt>
-                               <dd>
-                                       <textarea id="caption" name="caption" cols="40" rows="3">{$i18nPlainValues['caption']}</textarea>
-                                       {if $errorField == 'caption'}
-                                               <small class="innerError">
-                                                       {if $errorType == 'title' || $errorType == 'multilingual'}
-                                                               {lang}wcf.global.form.error.{@$errorType}{/lang}
-                                                       {else}
-                                                               {lang}wcf.media.caption.error.{@$errorType}{/lang}
-                                                       {/if}
-                                               </small>
-                                       {/if}
-                               </dd>
-                       </dl>
-                       {include file='multipleLanguageInputJavascript' elementIdentifier='caption' forceSelection=true}
-                       
-                       <dl{if $errorField == 'altText'} class="formError"{/if}>
-                               <dt>{lang}wcf.media.altText{/lang}</dt>
-                               <dd>
-                                       <input type="text" id="altText" name="altText" value="{$i18nPlainValues['altText']}" class="long">
-                                       {if $errorField == 'altText'}
-                                               <small class="innerError">
-                                                       {if $errorType == 'title' || $errorType == 'multilingual'}
-                                                               {lang}wcf.global.form.error.{@$errorType}{/lang}
-                                                       {else}
-                                                               {lang}wcf.media.altText.error.{@$errorType}{/lang}
-                                                       {/if}
-                                               </small>
-                                       {/if}
-                               </dd>
-                       </dl>
-                       {include file='multipleLanguageInputJavascript' elementIdentifier='altText' forceSelection=true}
-                       
-                       {event name='dataFields'}
-               </section>
-               
-               {include file='aclSimple'}
-               
-               {event name='sections'}
-               
-               <div class="formSubmit">
-                       <input type="submit" value="{lang}wcf.global.button.submit{/lang}" accesskey="s">
-                       {@SECURITY_TOKEN_INPUT_TAG}
-               </div>
-       </form>
-{/if}
-
-{if $action == 'edit'}
-       {* this code needs to be put after all multipleLanguageInputJavascript template have been included *}
-       <script data-relocate="true">
-               require(['WoltLabSuite/Core/Language/Input'], function(LanguageInput) {
-                       function updateLanguageFields() {
-                               var languageIdContainer = elById('languageIDContainer').parentNode;
-                               
-                               if (elById('isMultilingual').checked) {
-                                       LanguageInput.enable('title');
-                                       LanguageInput.enable('caption');
-                                       LanguageInput.enable('altText');
-                                       
-                                       elHide(languageIdContainer);
-                               }
-                               else {
-                                       LanguageInput.disable('title');
-                                       LanguageInput.disable('caption');
-                                       LanguageInput.disable('altText');
-                                       
-                                       elShow(languageIdContainer);
-                               }
-                       };
-                       
-                       elById('isMultilingual').addEventListener('change', updateLanguageFields);
-                       
-                       updateLanguageFields();
-                       
-                       {if !$isMultilingual}
-                               elById('title').value = '{$i18nPlainValues['title']|encodeJS}';
-                               elById('caption').value = '{$i18nPlainValues['caption']|encodeJS}';
-                               elById('altText').value = '{$i18nPlainValues['altText']|encodeJS}';
-                       {/if}
-               });
-       </script>
-{/if}
-
-{include file='footer'}
index 69e982028f3355b2c09d8c13fc9d7ddc6b49e499..28b74c2c5b7c7a0ec5bf3ed6aa0de4b355baff2c 100644 (file)
@@ -46,7 +46,7 @@
        <dl>
                <dt><label for="title_{@$media->mediaID}">{lang}wcf.global.title{/lang}</label></dt>
                <dd>
-                       <input type="text" id="title_{@$media->mediaID}" name="title" class="long" value="TODO">
+                       <input type="text" id="title_{@$media->mediaID}" name="title" class="long">
                </dd>
        </dl>
        {include file='multipleLanguageInputJavascript' elementIdentifier='title'|concat:'_':$media->mediaID forceSelection=true}
@@ -54,7 +54,7 @@
        <dl>
                <dt><label for="caption_{@$media->mediaID}">{lang}wcf.media.caption{/lang}</label></dt>
                <dd>
-                       <textarea id="caption_{@$media->mediaID}" name="caption" cols="40" rows="3">TODO</textarea>
+                       <textarea id="caption_{@$media->mediaID}" name="caption" cols="40" rows="3"></textarea>
                </dd>
        </dl>
        {include file='multipleLanguageInputJavascript' elementIdentifier='caption'|concat:'_':$media->mediaID forceSelection=true}
@@ -62,7 +62,7 @@
        <dl>
                <dt><label for="altText_{@$media->mediaID}">{lang}wcf.media.altText{/lang}</label></dt>
                <dd>
-                       <input type="text" id="altText_{@$media->mediaID}" name="altText" class="long" value="TODO">
+                       <input type="text" id="altText_{@$media->mediaID}" name="altText" class="long">
                </dd>
        </dl>
        {include file='multipleLanguageInputJavascript' elementIdentifier='altText'|concat:'_':$media->mediaID forceSelection=true}
index fc8d748f9b4eab1f7020f6fbea49014a90df106e..14589086e5d4dae26396c47c9278333b64a5a391 100644 (file)
@@ -1,48 +1,18 @@
 {include file='header' pageTitle='wcf.acp.media.list'}
 
 <script data-relocate="true">
-       document.addEventListener('DOMContentLoaded', function() {
-               require(['EventHandler', 'Language', 'Ui/SimpleDropdown', 'WoltLabSuite/Core/Controller/Clipboard', 'WoltLabSuite/Core/Media/Search'], function (EventHandler, Language, UiSimpleDropdown, Clipboard, MediaSearch) {
-                       Language.add('wcf.media.search.filetype', '{lang}wcf.media.search.filetype{/lang}');
-                       
-                       Clipboard.setup({
-                               hasMarkedItems: {if $hasMarkedItems}true{else}false{/if},
-                               pageClassName: 'wcf\\acp\\page\\MediaListPage'
-                       });
-                       
-                       EventHandler.add('com.woltlab.wcf.clipboard', 'com.woltlab.wcf.media', function (actionData) {
-                               // only consider events if the action has been executed
-                               if (actionData.responseData === null) {
-                                       return;
-                               }
-                               
-                               if (actionData.data.actionName === 'com.woltlab.wcf.media.delete') {
-                                       var mediaIds = actionData.responseData.objectIDs;
-                                       
-                                       var mediaRows = elByClass('jsMediaRow');
-                                       for (var i = 0; i < mediaRows.length; i++) {
-                                               var media = mediaRows[i];
-                                               var mediaID = ~~elData(elByClass('jsClipboardItem', media)[0], 'object-id');
-                                               
-                                               if (mediaIds.indexOf(mediaID) !== -1) {
-                                                       elRemove(media);
-                                                       i--;
-                                               }
-                                       }
-                                       
-                                       if (!mediaRows.length) {
-                                               window.location.reload();
-                                       }
-                               }
-                       });
-                       
-                       new MediaSearch('{$fileType}');
-                       
-                       new WCF.Action.Delete('wcf\\data\\media\\MediaAction', '.jsMediaRow');
+       {include file='mediaJavaScript'}
+       
+       require(['WoltLabSuite/Core/Controller/Media/List'], function (ControllerMediaList) {
+               ControllerMediaList.init({
+                       hasMarkedItems: {if $hasMarkedItems}true{else}false{/if}
                });
        });
 </script>
 
+{* hidden container element containg the element for the uploaded media file *}
+<p id="mediaFile" style="display: none;"></p>
+
 <header class="contentHeader">
        <div class="contentHeaderTitle">
                <h1 class="contentTitle">{lang}wcf.acp.media.list{/lang}</h1>
@@ -51,7 +21,7 @@
        
        <nav class="contentHeaderNavigation">
                <ul>
-                       <li><a href="{link controller='MediaAdd'}{/link}" class="button"><span class="icon icon16 fa-plus"></span> <span>{lang}wcf.acp.media.add{/lang}</span></a></li>
+                       <li><div id="uploadButton"></div></li>
                        
                        {event name='contentHeaderNavigation'}
                </ul>
                                        <tr class="jsMediaRow jsClipboardObject">
                                                <td class="columnMark"><input type="checkbox" class="jsClipboardItem" data-object-id="{@$media->mediaID}"></td>
                                                <td class="columnIcon">
-                                                       <a href="{link controller='MediaEdit' object=$media}{/link}" title="{lang}wcf.global.button.edit{/lang}" class="jsTooltip"><span class="icon icon24 fa-pencil"></span></a>
+                                                       <span class="icon icon24 fa-pencil jsMediaEditButton jsTooltip pointer" title="{lang}wcf.global.button.edit{/lang}" data-object-id="{@$media->mediaID}"></span>
                                                        <span class="icon icon24 fa-times jsDeleteButton jsTooltip pointer" title="{lang}wcf.global.button.delete{/lang}" data-object-id="{@$media->mediaID}" data-confirm-message-html="{lang title=$media->filename __encode=true}wcf.media.delete.confirmMessage{/lang}"></span>
                                                        
                                                        {event name='rowButtons'}
                                                                {@$media->getElementTag(48)}
                                                                
                                                                <div>
-                                                                       <p><a href="{link controller='MediaEdit' object=$media}{/link}">{$media->filename|tableWordwrap}</a></p>
+                                                                       <p>{$media->filename|tableWordwrap}</p>
                                                                        <p><small>{if $media->userID}{if $__wcf->session->getPermission('admin.user.canEditUser')}<a href="{link controller='UserEdit' id=$media->userID}{/link}">{$media->username}</a>{else}{$media->username}{/if}{else}{lang}wcf.user.guest{/lang}{/if}</small></p>
                                                                </div>
                                                        </div>
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Controller/Media/List.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Controller/Media/List.js
new file mode 100644 (file)
index 0000000..379d0c8
--- /dev/null
@@ -0,0 +1,75 @@
+/**
+ * Initializes modules required for media list view.
+ *
+ * @author     Matthias Schmidt
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module     WoltLabSuite/Core/Controller/Media/List
+ */
+define(['EventHandler', 'WoltLabSuite/Core/Controller/Clipboard', 'WoltLabSuite/Core/Media/Editor', 'WoltLabSuite/Core/Media/Search', 'WoltLabSuite/Core/Media/List/Upload'], function(EventHandler, Clipboard, MediaEditor, MediaSearch, MediaListUpload) {
+       "use strict";
+       
+       var _mediaEditor;
+       
+       /**
+        * @exports     WoltLabSuite/Core/Controller/Media/List
+        */
+       return {
+               init: function(options) {
+                       options = options || {};
+                       new MediaListUpload('uploadButton', 'mediaFile');
+                       
+                       Clipboard.setup({
+                               hasMarkedItems: options.hasMarkedItems || false,
+                               pageClassName: 'wcf\\acp\\page\\MediaListPage'
+                       });
+                       
+                       EventHandler.add('com.woltlab.wcf.clipboard', 'com.woltlab.wcf.media', this._clipboardAction.bind(this));
+                       
+                       new MediaSearch('{$fileType}');
+                       
+                       new WCF.Action.Delete('wcf\\data\\media\\MediaAction', '.jsMediaRow');
+                       
+                       _mediaEditor = new MediaEditor();
+                       
+                       var editButtons = elByClass('jsMediaEditButton');
+                       for (var i = 0, length = editButtons.length; i < length; i++) {
+                               editButtons[i].addEventListener(WCF_CLICK_EVENT, this._edit.bind(this));
+                       }
+               },
+               
+               /**
+                * 
+                * @param       {object}        actionData
+                */
+               _clipboardAction: function(actionData) {
+                       // only consider events if the action has been executed
+                       if (actionData.responseData === null) {
+                               return;
+                       }
+                       
+                       if (actionData.data.actionName === 'com.woltlab.wcf.media.delete') {
+                               var mediaIds = actionData.responseData.objectIDs;
+                               
+                               var mediaRows = elByClass('jsMediaRow');
+                               for (var i = 0; i < mediaRows.length; i++) {
+                                       var media = mediaRows[i];
+                                       var mediaID = ~~elData(elByClass('jsClipboardItem', media)[0], 'object-id');
+                                       
+                                       if (mediaIds.indexOf(mediaID) !== -1) {
+                                               elRemove(media);
+                                               i--;
+                                       }
+                               }
+                               
+                               if (!mediaRows.length) {
+                                       window.location.reload();
+                               }
+                       }
+               },
+               
+               _edit: function(event) {
+                       _mediaEditor.edit(elData(event.currentTarget, 'object-id'));
+               }
+       }
+});
\ No newline at end of file
index 26dea2802d59b2da8141b9739a9c80a43adde352..5e17eaafe066d89e6103ae228c1c0a87980313d0 100644 (file)
@@ -24,17 +24,15 @@ define(
         * @constructor
         */
        function MediaEditor(callbackObject) {
-               if (typeof callbackObject !== 'object') {
-                       throw new TypeError("Parameter 'callbackObject' has to be an object, " + typeof callbackObject + " given.");
-               }
-               if (typeof callbackObject._editorClose !== 'function') {
+               this._callbackObject = callbackObject || {};
+               
+               if (this._callbackObject._editorClose && typeof this._callbackObject._editorClose !== 'function') {
                        throw new TypeError("Callback object has no function '_editorClose'.");
                }
-               if (typeof callbackObject._editorSuccess !== 'function') {
+               if (this._callbackObject._editorSuccess && typeof this._callbackObject._editorSuccess !== 'function') {
                        throw new TypeError("Callback object has no function '_editorSuccess'.");
                }
                
-               this._callbackObject = callbackObject;
                this._media = null;
                
                this._dialogs = new Dictionary();
@@ -62,7 +60,9 @@ define(
                _ajaxSuccess: function(data) {
                        UiNotification.show();
                        
-                       this._callbackObject._editorSuccess(this._media);
+                       if (this._callbackObject._editorSuccess) {
+                               this._callbackObject._editorSuccess(this._media);
+                       }
                        
                        UiDialog.close('mediaEditor_' + this._media.mediaID);
                        
@@ -75,7 +75,9 @@ define(
                _close: function() {
                        this._media = null;
                        
-                       this._callbackObject._editorClose();
+                       if (this._callbackObject._editorClose) {
+                               this._callbackObject._editorClose();
+                       }
                },
                
                /**
@@ -138,7 +140,7 @@ define(
                                                var error = elCreate('small');
                                                error.className = 'innerError';
                                                error.textContent = Language.get('wcf.global.form.error.multilingual');
-                                               thistitle.parentNode.parentNode.appendChild(error);
+                                               title.parentNode.parentNode.appendChild(error);
                                        }
                                }
                                
@@ -218,9 +220,15 @@ define(
                /**
                 * Edits the media with the given data.
                 * 
-                * @param       {object}        media           data of the edited media
+                * @param       {object|integer}        media           data of the edited media or media id for which the data will be loaded
                 */
                edit: function(media) {
+                       if (typeof media !== 'object') {
+                               media = {
+                                       mediaID: ~~media
+                               };
+                       }
+                       
                        if (this._media !== null) {
                                throw new Error("Cannot edit media with id '" + media.mediaID + "' while editing media with id '" + this._media.mediaID + "'");
                        }
@@ -239,15 +247,30 @@ define(
                                                        },
                                                        source: {
                                                                after: (function(content, data) {
+                                                                       var didLoadMediaData = false;
+                                                                       if (data.returnValues.mediaData) {
+                                                                               this._media = data.returnValues.mediaData;
+                                                                               
+                                                                               didLoadMediaData = true;
+                                                                       }
+                                                                       
                                                                        // make sure that the language chooser is initialized first
                                                                        setTimeout(function() {
                                                                                LanguageChooser.setLanguageId('languageID', this._media.languageID || LANGUAGE_ID);
                                                                                
+                                                                               var title = elBySel('input[name=title]', content);
+                                                                               var altText = elBySel('input[name=altText]', content);
+                                                                               
                                                                                if (this._media.isMultilingual) {
                                                                                        LanguageInput.setValues('altText_' + this._media.mediaID, Dictionary.fromObject(this._media.altText || { }));
                                                                                        LanguageInput.setValues('caption_' + this._media.mediaID, Dictionary.fromObject(this._media.caption || { }));
                                                                                        LanguageInput.setValues('title_' + this._media.mediaID, Dictionary.fromObject(this._media.title || { }));
                                                                                }
+                                                                               else {
+                                                                                       title.value = this._media.title ? this._media.title[LANGUAGE_ID] : ''; 
+                                                                                       altText.value = this._media.altText ? this._media.altText[LANGUAGE_ID] : '';
+                                                                                       elBySel('textarea[name=caption]', content).value = this._media.caption ? this._media.caption[LANGUAGE_ID] : '';
+                                                                               }
                                                                                
                                                                                var isMultilingual = elBySel('input[name=isMultilingual]', content);
                                                                                isMultilingual.addEventListener('change', this._updateLanguageFields.bind(this));
@@ -255,8 +278,8 @@ define(
                                                                                this._updateLanguageFields(null, isMultilingual);
                                                                                
                                                                                var keyPress = this._keyPress.bind(this);
-                                                                               elBySel('input[name=altText]', content).addEventListener('keypress', keyPress);
-                                                                               elBySel('input[name=title]', content).addEventListener('keypress', keyPress);
+                                                                               altText.addEventListener('keypress', keyPress);
+                                                                               title.addEventListener('keypress', keyPress);
                                                                                
                                                                                elBySel('button[data-type=submit]', content).addEventListener(WCF_CLICK_EVENT, this._saveData.bind(this));
                                                                                
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Media/List/Upload.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Media/List/Upload.js
new file mode 100644 (file)
index 0000000..e88e514
--- /dev/null
@@ -0,0 +1,107 @@
+/**
+ * Uploads media files.
+ *
+ * @author     Matthias Schmidt
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module     WoltLabSuite/Core/Media/List/Upload
+ */
+define(
+       [
+               'Core', 'Dom/ChangeListener', 'Dom/Traverse', 'Dom/Util', 'Language', 'Ui/Confirmation', 'Ui/Notification', '../Upload'
+       ],
+       function(
+               Core, DomChangeListener, DomTraverse, DomUtil, Language, UiConfirmation, UiNotification, MediaUpload
+       )
+{
+       "use strict";
+       
+       /**
+        * @constructor
+        */
+       function MediaListUpload(buttonContainerId, targetId, options) {
+               options = options || {};
+               
+               // only one file may be uploaded file list upload for proper error display
+               options.multiple = false;
+               
+               MediaUpload.call(this, buttonContainerId, targetId, options);
+       }
+       Core.inherit(MediaListUpload, MediaUpload, {
+               /**
+                * Creates the upload button.
+                */
+               _createButton: function() {
+                       this._fileUpload = elCreate('input');
+                       elAttr(this._fileUpload, 'type', 'file');
+                       elAttr(this._fileUpload, 'name', this._options.name);
+                       this._fileUpload.addEventListener('change', this._upload.bind(this));
+                       
+                       this._button = elCreate('p');
+                       this._button.className = 'button uploadButton';
+                       
+                       this._button.innerHTML = '<span class="icon icon16 fa-upload"></span> <span>' + Language.get('wcf.global.button.upload') + '</span>';
+                       
+                       DomUtil.prepend(this._fileUpload, this._button);
+                       
+                       this._insertButton();
+                       
+                       DomChangeListener.trigger();
+               },
+               
+               /**
+                * @see WoltLabSuite/Core/Upload#_success
+                */
+               _success: function(uploadId, data) {
+                       var icon = DomTraverse.childByClass(this._button, 'icon');
+                       icon.classList.remove('fa-spinner');
+                       icon.classList.add('fa-upload');
+                       
+                       var file = this._fileElements[uploadId][0];
+                       
+                       var internalFileId = elData(file, 'internal-file-id');
+                       var media = data.returnValues.media[internalFileId];
+                       
+                       if (media) {
+                               UiNotification.show(Language.get('wcf.media.upload.success'), function() {
+                                       window.location.reload();
+                               });
+                       }
+                       else {
+                               var error = data.returnValues.errors[internalFileId];
+                               if (!error) {
+                                       error = {
+                                               errorType: 'uploadFailed',
+                                               filename: elData(file, 'filename')
+                                       };
+                               }
+                               
+                               UiConfirmation.show({
+                                       confirm: function() {
+                                               // do nothing
+                                       },
+                                       message: Language.get('wcf.media.upload.error.' + error.errorType, {
+                                               filename: error.filename
+                                       })
+                               });
+                       }
+               },
+               
+               /**
+                * @see WoltLabSuite/Core/Upload#_success
+                */
+               _upload: function(event, file, blob) {
+                       var uploadId = MediaListUpload._super.prototype._upload.call(this, event, file, blob);
+                       
+                       var icon = DomTraverse.childByClass(this._button, 'icon');
+                       window.setTimeout(function() {
+                               icon.classList.remove('fa-upload');
+                               icon.classList.add('fa-spinner');
+                       }, 500);
+                       
+                       return uploadId;
+               }
+       });
+       
+       return MediaListUpload;
+});
index 52b1fffe489110cd7c40cbcc192ef0744b9ecfb5..f629c11d1d89ecbf6ed6bacbbc8f8ea78b4eba64 100644 (file)
@@ -70,8 +70,7 @@ define(['AjaxRequest', 'Core', 'Dom/ChangeListener', 'Language', 'Dom/Util', 'Do
                        this._fileUpload.addEventListener('change', this._upload.bind(this));
                        
                        this._button = elCreate('p');
-                       this._button.classList.add('button');
-                       this._button.classList.add('uploadButton');
+                       this._button.className = 'button uploadButton';
                        
                        var span = elCreate('span');
                        span.textContent = Language.get('wcf.global.button.upload');
diff --git a/wcfsetup/install/files/lib/acp/form/MediaEditForm.class.php b/wcfsetup/install/files/lib/acp/form/MediaEditForm.class.php
deleted file mode 100644 (file)
index 97f3754..0000000
+++ /dev/null
@@ -1,205 +0,0 @@
-<?php
-namespace wcf\acp\form;
-use wcf\data\media\MediaAction;
-use wcf\data\media\ViewableMedia;
-use wcf\form\AbstractForm;
-use wcf\system\acl\simple\SimpleAclHandler;
-use wcf\system\exception\IllegalLinkException;
-use wcf\system\exception\UserInputException;
-use wcf\system\language\I18nHandler;
-use wcf\system\language\LanguageFactory;
-use wcf\system\WCF;
-use wcf\util\ArrayUtil;
-
-/**
- * Shows the form to edit a media file.
- *
- * @author     Matthias Schmidt
- * @copyright  2001-2016 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    WoltLabSuite\Core\Acp\Form
- * @since      3.0
- */
-class MediaEditForm extends AbstractForm {
-       /**
-        * acl values
-        * @var array
-        */
-       public $aclValues = [];
-       
-       /**
-        * @inheritDoc
-        */
-       public $activeMenuItem = 'wcf.acp.menu.link.cms.media.list';
-       
-       /**
-        * is 1 if media data is multilingual
-        * @var integer
-        */
-       public $isMultilingual = 0;
-       
-       /**
-        * id of the selected language
-        * @var integer
-        */
-       public $languageID = 0;
-       
-       /**
-        * edited media
-        * @var ViewableMedia
-        */
-       public $media = null;
-       
-       /**
-        * id of the edited media
-        * @var integer
-        */
-       public $mediaID = 0;
-       
-       /**
-        * @inheritDoc
-        */
-       public $neededPermissions = ['admin.content.cms.canManageMedia'];
-       
-       /**
-        * @inheritDoc
-        */
-       public function assignVariables() {
-               parent::assignVariables();
-               
-               I18nHandler::getInstance()->assignVariables();
-               
-               WCF::getTPL()->assign([
-                       'aclValues' => SimpleAclHandler::getInstance()->getOutputValues($this->aclValues),
-                       'action' => 'edit',
-                       'isMultilingual' => $this->isMultilingual,
-                       'languages' => LanguageFactory::getInstance()->getLanguages(),
-                       'languageID' => $this->languageID,
-                       'media' => $this->media
-               ]);
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function readData() {
-               parent::readData();
-               
-               if (empty($_POST)) {
-                       $this->isMultilingual = $this->media->isMultilingual;
-                       if (!$this->isMultilingual && !$this->media->languageID) {
-                               $this->isMultilingual = 1;
-                       }
-                       
-                       if ($this->media->languageID) {
-                               $this->languageID = $this->media->languageID;
-                       }
-                       else {
-                               $this->languageID = WCF::getUser()->languageID;
-                       }
-                       
-                       $contentData = $this->media->getI18nData();
-                       if (!empty($contentData)) {
-                               if (!empty($contentData['altText'])) I18nHandler::getInstance()->setValues('altText', $contentData['altText']);
-                               if (!empty($contentData['caption'])) I18nHandler::getInstance()->setValues('caption', $contentData['caption']);
-                               if (!empty($contentData['title'])) I18nHandler::getInstance()->setValues('title', $contentData['title']);
-                       }
-                       
-                       $this->aclValues = SimpleAclHandler::getInstance()->getValues('com.woltlab.wcf.media', $this->media->mediaID);
-               }
-               
-               if (!$this->languageID) {
-                       $this->languageID = WCF::getUser()->languageID;
-               }
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function readFormParameters() {
-               parent::readFormParameters();
-               
-               if (isset($_POST['isMultilingual'])) $this->isMultilingual = intval($_POST['isMultilingual']);
-               if (!$this->isMultilingual) {
-                       if (isset($_POST['languageID'])) $this->languageID = intval($_POST['languageID']);
-               }
-               I18nHandler::getInstance()->readValues();
-               
-               if (isset($_POST['aclValues']) && is_array($_POST['aclValues'])) $this->aclValues = $_POST['aclValues'];
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function readParameters() {
-               parent::readParameters();
-               
-               if (isset($_REQUEST['id'])) $this->mediaID = intval($_REQUEST['id']);
-               
-               $this->media = ViewableMedia::getMedia($this->mediaID);
-               if ($this->media === null) {
-                       throw new IllegalLinkException();
-               }
-               
-               I18nHandler::getInstance()->register('title');
-               I18nHandler::getInstance()->register('caption');
-               I18nHandler::getInstance()->register('altText');
-       }
-       
-       /**
-        * @inheritDoc
-        */
-       public function save() {
-               parent::save();
-               
-               $this->objectAction = new MediaAction([$this->media->getDecoratedObject()], 'update', array_merge($this->additionalFields, [
-                       'data' => [
-                               'isMultilingual' => $this->isMultilingual,
-                               'languageID' => $this->languageID ?: null
-                       ],
-                       'altText' => I18nHandler::getInstance()->getValues('altText'),
-                       'caption' => I18nHandler::getInstance()->getValues('caption'),
-                       'title' => I18nHandler::getInstance()->getValues('title')
-               ]));
-               $this->objectAction->executeAction();
-               
-               // save acl
-               SimpleAclHandler::getInstance()->setValues('com.woltlab.wcf.media', $this->media->mediaID, $this->aclValues);
-               
-               $this->saved();
-               
-               WCF::getTPL()->assign('success', true);
-       }
-       
-       /**
-        * @inheritDoc
-        * @throws      UserInputException
-        */
-       public function validate() {
-               parent::validate();
-               
-               if (!$this->isMultilingual && !$this->languageID) {
-                       throw new UserInputException('languageID');
-               }
-               
-               if ($this->languageID && !LanguageFactory::getInstance()->getLanguage($this->languageID)) {
-                       throw new UserInputException('languageID');
-               }
-               
-               foreach (['title', 'caption', 'altText'] as $i18nData) {
-                       if (!I18nHandler::getInstance()->validateValue($i18nData, $this->isMultilingual? true : false, true)) {
-                               if ($this->isMultilingual) {
-                                       // in contrast to I18nHandler::validateValues(), we allow all fields to be empty
-                                       if (empty(ArrayUtil::trim(I18nHandler::getInstance()->getValues($i18nData)))) {
-                                               continue;
-                                       }
-                                       
-                                       throw new UserInputException($i18nData, 'multilingual');
-                               }
-                               else {
-                                       throw new UserInputException($i18nData);
-                               }
-                       }
-               }
-       }
-}
diff --git a/wcfsetup/install/files/lib/acp/page/MediaAddPage.class.php b/wcfsetup/install/files/lib/acp/page/MediaAddPage.class.php
deleted file mode 100644 (file)
index 11ecf00..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-namespace wcf\acp\page;
-use wcf\page\AbstractPage;
-use wcf\system\WCF;
-
-/**
- * Shows the page to upload a media file.
- *
- * @author     Matthias Schmidt
- * @copyright  2001-2016 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    WoltLabSuite\Core\Acp\Page
- * @since      3.0
- */
-class MediaAddPage extends AbstractPage {
-       /**
-        * @inheritDoc
-        */
-       public $activeMenuItem = 'wcf.acp.menu.link.cms.media.add';
-       
-       /**
-        * @inheritDoc
-        */
-       public $neededPermissions = ['admin.content.cms.canManageMedia'];
-       
-       /**
-        * @inheritDoc
-        */
-       public function assignVariables() {
-               parent::assignVariables();
-               
-               WCF::getTPL()->assign('action', 'add');
-       }
-}
index a3851e23d9d57017bb1618b0cfaeb56654754ffb..1682f5e28bfb12718f001e76a4b03cc8aa289a1e 100644 (file)
@@ -249,7 +249,10 @@ class MediaAction extends AbstractDatabaseObjectAction implements ISearchAction,
         * @return      string[]
         */
        public function getEditorDialog() {
-               $media = new ViewableMedia($this->getSingleObject()->getDecoratedObject());
+               $mediaList = new ViewableMediaList();
+               $mediaList->setObjectIDs([$this->getSingleObject()->mediaID]);
+               $mediaList->readObjects();
+               $media = $mediaList->search($this->getSingleObject()->mediaID);
                
                I18nHandler::getInstance()->register('title_' . $media->mediaID);
                I18nHandler::getInstance()->register('caption_' . $media->mediaID);
@@ -257,6 +260,7 @@ class MediaAction extends AbstractDatabaseObjectAction implements ISearchAction,
                I18nHandler::getInstance()->assignVariables();
                
                return [
+                       'mediaData' => $this->getI18nMediaData($mediaList)[$this->getSingleObject()->mediaID],
                        'template' => WCF::getTPL()->fetch('mediaEditor', 'wcf', [
                                '__aclSimplePrefix' => 'mediaEditor_' . $media->mediaID . '_',
                                'aclValues' => SimpleAclHandler::getInstance()->getValues('com.woltlab.wcf.media', $media->mediaID),
index 841486d11ff07d3ae8cf27c2c9a6c6bf4ed1d3d0..c265f1457eff2880d49dc1cae90d509b1eed7f30 100644 (file)
                <item name="wcf.acp.menu.link.cms.box.list"><![CDATA[Boxen]]></item>
                <item name="wcf.acp.menu.link.cms.box.add"><![CDATA[Box hinzufügen]]></item>
                <item name="wcf.acp.menu.link.cms.media.list"><![CDATA[Medien]]></item>
-               <item name="wcf.acp.menu.link.cms.media.add"><![CDATA[Medium hinzufügen]]></item>
                <item name="wcf.acp.menu.link.article"><![CDATA[Artikel]]></item>
                <item name="wcf.acp.menu.link.article.list"><![CDATA[Artikel]]></item>
                <item name="wcf.acp.menu.link.article.add"><![CDATA[Artikel hinzufügen]]></item>
index 9f5ff1f03374e35091242d12fcd721fabd2a7f44..6ca788dc925894cb1024b35e43e0a3a37db8fd09 100644 (file)
@@ -712,7 +712,6 @@ Examples for medium ID detection:
                <item name="wcf.acp.menu.link.cms.box.list"><![CDATA[Boxes]]></item>
                <item name="wcf.acp.menu.link.cms.box.add"><![CDATA[Add Box]]></item>
                <item name="wcf.acp.menu.link.cms.media.list"><![CDATA[Media]]></item>
-               <item name="wcf.acp.menu.link.cms.media.add"><![CDATA[Add Medium]]></item>
                <item name="wcf.acp.menu.link.article"><![CDATA[Articles]]></item>
                <item name="wcf.acp.menu.link.article.list"><![CDATA[Articles]]></item>
                <item name="wcf.acp.menu.link.article.add"><![CDATA[Add Article]]></item>
@@ -2513,6 +2512,7 @@ Errors are:
                <item name="wcf.media.search.filetype.other"><![CDATA[Other]]></item>
                <item name="wcf.media.search.filetype.text"><![CDATA[Texts]]></item>
                <item name="wcf.media.search.placeholder"><![CDATA[Search Files]]></item>
+               <item name="wcf.media.upload.success"><![CDATA[The file has been successfully uploaded.]]></item>
                <item name="wcf.media.uploader"><![CDATA[Uploaded By]]></item>
        </category>