Hide multilingual media options if only one language is installed
authorMatthias Schmidt <gravatronics@live.com>
Sat, 22 Oct 2016 07:45:54 +0000 (09:45 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 22 Oct 2016 07:45:54 +0000 (09:45 +0200)
com.woltlab.wcf/templates/mediaEditor.tpl
wcfsetup/install/files/acp/templates/mediaEditor.tpl
wcfsetup/install/files/js/WoltLabSuite/Core/Media/Editor.js
wcfsetup/install/files/lib/data/media/MediaAction.class.php

index 28b74c2c5b7c7a0ec5bf3ed6aa0de4b355baff2c..65f0fe0813472a04b4f379256626e966cc5d1719 100644 (file)
 <section class="section">
        <h2 class="sectionTitle">{lang}wcf.global.form.data{/lang}</h2>
        
-       <dl>
-               <dt></dt>
-               <dd>
-                       <label>
-                               <input type="checkbox" name="isMultilingual" value="1"{if $media->isMultilingual} checked{/if}>
-                               <span>{lang}wcf.media.isMultilingual{/lang}</span>
-                       </label>
-               </dd>
-       </dl>
-       
-       {include file='languageChooser' label='wcf.media.languageID'}
+       {if $availableLanguages|count > 1}
+               <dl>
+                       <dt></dt>
+                       <dd>
+                               <label>
+                                       <input type="checkbox" name="isMultilingual" value="1"{if $media->isMultilingual} checked{/if}>
+                                       <span>{lang}wcf.media.isMultilingual{/lang}</span>
+                               </label>
+                       </dd>
+               </dl>
+               
+               {include file='languageChooser' label='wcf.media.languageID'}
+       {/if}
        
        <dl>
                <dt><label for="title_{@$media->mediaID}">{lang}wcf.global.title{/lang}</label></dt>
@@ -49,7 +51,9 @@
                        <input type="text" id="title_{@$media->mediaID}" name="title" class="long">
                </dd>
        </dl>
-       {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}
        
        <dl>
                <dt><label for="caption_{@$media->mediaID}">{lang}wcf.media.caption{/lang}</label></dt>
@@ -57,7 +61,9 @@
                        <textarea id="caption_{@$media->mediaID}" name="caption" cols="40" rows="3"></textarea>
                </dd>
        </dl>
-       {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}
        
        <dl>
                <dt><label for="altText_{@$media->mediaID}">{lang}wcf.media.altText{/lang}</label></dt>
@@ -65,7 +71,9 @@
                        <input type="text" id="altText_{@$media->mediaID}" name="altText" class="long">
                </dd>
        </dl>
-       {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'}
 </section>
index 28b74c2c5b7c7a0ec5bf3ed6aa0de4b355baff2c..576bb515e86cfdf940d722299e44dc1fafb9715c 100644 (file)
 
 <section class="section">
        <h2 class="sectionTitle">{lang}wcf.global.form.data{/lang}</h2>
-       
-       <dl>
-               <dt></dt>
-               <dd>
-                       <label>
-                               <input type="checkbox" name="isMultilingual" value="1"{if $media->isMultilingual} checked{/if}>
-                               <span>{lang}wcf.media.isMultilingual{/lang}</span>
-                       </label>
-               </dd>
-       </dl>
-       
-       {include file='languageChooser' label='wcf.media.languageID'}
+
+       {if $availableLanguages|count > 1}
+               <dl>
+                       <dt></dt>
+                       <dd>
+                               <label>
+                                       <input type="checkbox" name="isMultilingual" value="1"{if $media->isMultilingual} checked{/if}>
+                                       <span>{lang}wcf.media.isMultilingual{/lang}</span>
+                               </label>
+                       </dd>
+               </dl>
+               
+               {include file='languageChooser' label='wcf.media.languageID'}
+       {/if}
        
        <dl>
                <dt><label for="title_{@$media->mediaID}">{lang}wcf.global.title{/lang}</label></dt>
@@ -49,7 +51,9 @@
                        <input type="text" id="title_{@$media->mediaID}" name="title" class="long">
                </dd>
        </dl>
-       {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}
        
        <dl>
                <dt><label for="caption_{@$media->mediaID}">{lang}wcf.media.caption{/lang}</label></dt>
@@ -57,7 +61,9 @@
                        <textarea id="caption_{@$media->mediaID}" name="caption" cols="40" rows="3"></textarea>
                </dd>
        </dl>
-       {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}
        
        <dl>
                <dt><label for="altText_{@$media->mediaID}">{lang}wcf.media.altText{/lang}</label></dt>
@@ -65,7 +71,9 @@
                        <input type="text" id="altText_{@$media->mediaID}" name="altText" class="long">
                </dd>
        </dl>
-       {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'}
 </section>
index 57b07d4fd67f4472cfd9b455ce776df46b26b250..c1b640ec854083761f24aea75a9d03e9bc6a49da 100644 (file)
@@ -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);
index 245e8d23be87181f31e8dc6032870abe124e54a7..1d6c56aeafb44dfb9b46e529f23f01a4da634057 100644 (file)
@@ -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']) {