From c04be19746bc56a72063c9d77537458b2c541d55 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 22 Oct 2016 09:45:54 +0200 Subject: [PATCH] Hide multilingual media options if only one language is installed --- com.woltlab.wcf/templates/mediaEditor.tpl | 36 +++++++++++------- .../files/acp/templates/mediaEditor.tpl | 38 +++++++++++-------- .../js/WoltLabSuite/Core/Media/Editor.js | 30 ++++++++++----- .../lib/data/media/MediaAction.class.php | 20 +++++++--- 4 files changed, 80 insertions(+), 44 deletions(-) diff --git a/com.woltlab.wcf/templates/mediaEditor.tpl b/com.woltlab.wcf/templates/mediaEditor.tpl index 28b74c2c5b..65f0fe0813 100644 --- a/com.woltlab.wcf/templates/mediaEditor.tpl +++ b/com.woltlab.wcf/templates/mediaEditor.tpl @@ -31,17 +31,19 @@

{lang}wcf.global.form.data{/lang}

-
-
-
- -
-
- - {include file='languageChooser' label='wcf.media.languageID'} + {if $availableLanguages|count > 1} +
+
+
+ +
+
+ + {include file='languageChooser' label='wcf.media.languageID'} + {/if}
@@ -49,7 +51,9 @@
- {include file='multipleLanguageInputJavascript' elementIdentifier='title'|concat:'_':$media->mediaID forceSelection=true} + {if $availableLanguages|count > 1} + {include file='multipleLanguageInputJavascript' elementIdentifier='title'|concat:'_':$media->mediaID forceSelection=true} + {/if}
@@ -57,7 +61,9 @@
- {include file='multipleLanguageInputJavascript' elementIdentifier='caption'|concat:'_':$media->mediaID forceSelection=true} + {if $availableLanguages|count > 1} + {include file='multipleLanguageInputJavascript' elementIdentifier='caption'|concat:'_':$media->mediaID forceSelection=true} + {/if}
@@ -65,7 +71,9 @@
- {include file='multipleLanguageInputJavascript' elementIdentifier='altText'|concat:'_':$media->mediaID forceSelection=true} + {if $availableLanguages|count > 1} + {include file='multipleLanguageInputJavascript' elementIdentifier='altText'|concat:'_':$media->mediaID forceSelection=true} + {/if} {event name='dataFields'}
diff --git a/wcfsetup/install/files/acp/templates/mediaEditor.tpl b/wcfsetup/install/files/acp/templates/mediaEditor.tpl index 28b74c2c5b..576bb515e8 100644 --- a/wcfsetup/install/files/acp/templates/mediaEditor.tpl +++ b/wcfsetup/install/files/acp/templates/mediaEditor.tpl @@ -30,18 +30,20 @@

{lang}wcf.global.form.data{/lang}

- -
-
-
- -
-
- - {include file='languageChooser' label='wcf.media.languageID'} + + {if $availableLanguages|count > 1} +
+
+
+ +
+
+ + {include file='languageChooser' label='wcf.media.languageID'} + {/if}
@@ -49,7 +51,9 @@
- {include file='multipleLanguageInputJavascript' elementIdentifier='title'|concat:'_':$media->mediaID forceSelection=true} + {if $availableLanguages|count > 1} + {include file='multipleLanguageInputJavascript' elementIdentifier='title'|concat:'_':$media->mediaID forceSelection=true} + {/if}
@@ -57,7 +61,9 @@
- {include file='multipleLanguageInputJavascript' elementIdentifier='caption'|concat:'_':$media->mediaID forceSelection=true} + {if $availableLanguages|count > 1} + {include file='multipleLanguageInputJavascript' elementIdentifier='caption'|concat:'_':$media->mediaID forceSelection=true} + {/if}
@@ -65,7 +71,9 @@
- {include file='multipleLanguageInputJavascript' elementIdentifier='altText'|concat:'_':$media->mediaID forceSelection=true} + {if $availableLanguages|count > 1} + {include file='multipleLanguageInputJavascript' elementIdentifier='altText'|concat:'_':$media->mediaID forceSelection=true} + {/if} {event name='dataFields'}
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Editor.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Editor.js index 57b07d4fd6..c1b640ec85 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Editor.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Media/Editor.js @@ -34,6 +34,7 @@ define( } this._media = null; + this._availableLanguageCount = 1; this._dialogs = new Dictionary(); } @@ -109,13 +110,18 @@ define( var captionError = DomTraverse.childByClass(caption.parentNode.parentNode, 'innerError'); var titleError = DomTraverse.childByClass(title.parentNode.parentNode, 'innerError'); - this._media.isMultilingual = ~~elBySel('input[name=isMultilingual]', content).checked; - this._media.languageID = this._media.isMultilingual ? null : LanguageChooser.getLanguageId('languageID'); + if (this._availableLanguageCount > 1) { + this._media.isMultilingual = ~~elBySel('input[name=isMultilingual]', content).checked; + this._media.languageID = this._media.isMultilingual ? null : LanguageChooser.getLanguageId('languageID'); + } + else { + this._media.languageID = LANGUAGE_ID; + } this._media.altText = {}; this._media.caption = {}; this._media.title = {}; - if (this._media.isMultilingual) { + if (this._availableLanguageCount > 1 && this._media.isMultilingual) { if (!LanguageInput.validate('altText_' + this._media.mediaID, true)) { hasError = true; if (!altTextError) { @@ -247,6 +253,8 @@ define( }, source: { after: (function(content, data) { + this._availableLanguageCount = ~~data.returnValues.availableLanguageCount; + var didLoadMediaData = false; if (data.returnValues.mediaData) { this._media = data.returnValues.mediaData; @@ -256,12 +264,14 @@ define( // make sure that the language chooser is initialized first setTimeout(function() { - LanguageChooser.setLanguageId('languageID', this._media.languageID || LANGUAGE_ID); + if (this._availableLanguageCount > 1) { + 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) { + if (this._availableLanguageCount > 1 && 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 || { })); @@ -272,10 +282,12 @@ define( 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)); - - this._updateLanguageFields(null, isMultilingual); + if (this._availableLanguageCount > 1) { + var isMultilingual = elBySel('input[name=isMultilingual]', content); + isMultilingual.addEventListener('change', this._updateLanguageFields.bind(this)); + + this._updateLanguageFields(null, isMultilingual); + } var keyPress = this._keyPress.bind(this); altText.addEventListener('keypress', keyPress); diff --git a/wcfsetup/install/files/lib/data/media/MediaAction.class.php b/wcfsetup/install/files/lib/data/media/MediaAction.class.php index 245e8d23be..1d6c56aeaf 100644 --- a/wcfsetup/install/files/lib/data/media/MediaAction.class.php +++ b/wcfsetup/install/files/lib/data/media/MediaAction.class.php @@ -257,11 +257,13 @@ class MediaAction extends AbstractDatabaseObjectAction implements ISearchAction, I18nHandler::getInstance()->assignVariables(); return [ + 'availableLanguageCount' => count(LanguageFactory::getInstance()->getLanguages()), '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), '__languageChooserPrefix' => 'mediaEditor_' . $media->mediaID . '_', + 'aclValues' => SimpleAclHandler::getInstance()->getValues('com.woltlab.wcf.media', $media->mediaID), + 'availableLanguages' => LanguageFactory::getInstance()->getLanguages(), 'languageID' => WCF::getUser()->languageID, 'languages' => LanguageFactory::getInstance()->getLanguages(), 'media' => $media @@ -286,11 +288,17 @@ class MediaAction extends AbstractDatabaseObjectAction implements ISearchAction, $this->readInteger('languageID', true, 'data'); $this->readBoolean('isMultilingual', true, 'data'); - // languageID: convert zero to null - if (!$this->parameters['data']['languageID']) $this->parameters['data']['languageID'] = null; - - // isMultilingual: convert boolean to integer - $this->parameters['data']['isMultilingual'] = intval($this->parameters['data']['isMultilingual']); + if (count(LanguageFactory::getInstance()->getLanguages()) > 1) { + // languageID: convert zero to null + if (!$this->parameters['data']['languageID']) $this->parameters['data']['languageID'] = null; + + // isMultilingual: convert boolean to integer + $this->parameters['data']['isMultilingual'] = intval($this->parameters['data']['isMultilingual']); + } + else { + $this->parameters['data']['isMultilingual'] = 0; + $this->parameters['data']['languageID'] = WCF::getLanguage()->languageID; + } // if data is not multilingual, a language id has to be given if (!$this->parameters['data']['isMultilingual'] && !$this->parameters['data']['languageID']) { -- 2.20.1