FIX: improves UI state when no extensions are allowed for upload

This commit is contained in:
Joffrey JAFFEUX 2018-01-26 18:12:23 +01:00 committed by GitHub
parent 56834dbd98
commit 3d595a52ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 8 deletions

View File

@ -13,6 +13,8 @@ import { tinyAvatar,
displayErrorForUpload,
getUploadMarkdown,
validateUploadedFiles,
authorizesOneOrMoreExtensions,
authorizesOneOrMoreImageExtensions,
formatUsername,
clipboardData
} from 'discourse/lib/utilities';
@ -36,6 +38,12 @@ export default Ember.Component.extend({
return `[${I18n.t('uploading')}]() `;
},
@computed()
replyPlaceholder() {
const key = authorizesOneOrMoreImageExtensions() ? "reply_placeholder" : "reply_placeholder_no_images";
return `composer.${key}`;
},
@observes('composer.uploadCancelled')
_cancelUpload() {
if (!this.get('composer.uploadCancelled')) { return; }
@ -662,6 +670,7 @@ export default Ember.Component.extend({
unshift: true
});
if (authorizesOneOrMoreExtensions()) {
toolbar.addButton({
id: 'upload',
group: 'insertions',
@ -669,6 +678,7 @@ export default Ember.Component.extend({
title: 'upload',
sendAction: 'showUploadModal'
});
}
toolbar.addButton({
id: 'options',

View File

@ -193,6 +193,8 @@ export function validateUploadedFiles(files, opts) {
}
export function validateUploadedFile(file, opts) {
if (!authorizesOneOrMoreExtensions()) return false;
opts = opts || {};
const name = file && file.name;
@ -277,6 +279,21 @@ export function authorizesAllExtensions() {
return Discourse.SiteSettings.authorized_extensions.indexOf("*") >= 0;
}
export function authorizesOneOrMoreExtensions() {
if (authorizesAllExtensions()) return true;
return Discourse.SiteSettings.authorized_extensions
.split("|")
.filter(ext => ext)
.length > 0;
}
export function authorizesOneOrMoreImageExtensions() {
if (authorizesAllExtensions()) return true;
return imagesExtensions().length > 0;
}
export function isAnImage(path) {
return (/\.(png|jpe?g|gif|bmp|tiff?|svg|webp|ico)$/i).test(path);
}

View File

@ -1,7 +1,7 @@
{{d-editor
tabindex="4"
value=composer.reply
placeholder="composer.reply_placeholder"
placeholder=replyPlaceholder
previewUpdated="previewUpdated"
markdownOptions=markdownOptions
extraButtons="extraButtons"

View File

@ -1247,6 +1247,7 @@ en:
topic_featured_link_placeholder: "Enter link shown with title."
remove_featured_link: "Remove link from topic."
reply_placeholder: "Type here. Use Markdown, BBCode, or HTML to format. Drag or paste images."
reply_placeholder_no_images: "Type here. Use Markdown, BBCode, or HTML to format."
view_new_post: "View your new post."
saving: "Saving"
saved: "Saved!"