0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 17:30:29 +01:00

Add authorized_extensions support to wizard composer

Dieser Commit ist enthalten in:
Angus McLeod 2020-10-06 20:30:24 +11:00
Ursprung fc5279cd0a
Commit 96e85bb2b3
3 geänderte Dateien mit 19 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -1,5 +1,5 @@
import ComposerEditor from "discourse/components/composer-editor"; import ComposerEditor from "discourse/components/composer-editor";
import { default as computed, on } from "discourse-common/utils/decorators"; import { default as discourseComputed, on } from "discourse-common/utils/decorators";
import { findRawTemplate } from "discourse-common/lib/raw-templates"; import { findRawTemplate } from "discourse-common/lib/raw-templates";
import { throttle } from "@ember/runloop"; import { throttle } from "@ember/runloop";
import { scheduleOnce, next } from "@ember/runloop"; import { scheduleOnce, next } from "@ember/runloop";
@ -14,9 +14,8 @@ import {
validateUploadedFiles, validateUploadedFiles,
getUploadMarkdown getUploadMarkdown
} from "discourse/lib/uploads"; } from "discourse/lib/uploads";
import { import { cacheShortUploadUrl } from "pretty-text/upload-short-url";
cacheShortUploadUrl, import { alias } from "@ember/object/computed";
} from "pretty-text/upload-short-url";
const uploadMarkdownResolvers = []; const uploadMarkdownResolvers = [];
@ -34,6 +33,7 @@ export default ComposerEditor.extend({
uploadIcon: "upload", uploadIcon: "upload",
popupMenuOptions: [], popupMenuOptions: [],
draftStatus: "null", draftStatus: "null",
replyPlaceholder: alias("field.placeholder"),
@on("didInsertElement") @on("didInsertElement")
_composerEditorInit() { _composerEditorInit() {
@ -66,6 +66,13 @@ export default ComposerEditor.extend({
this._bindUploadTarget(); this._bindUploadTarget();
}, },
@discourseComputed
allowedFileTypes() {
return this.siteSettings.authorized_extensions.split('|')
.map(ext => "." + ext)
.join(',')
},
_setUploadPlaceholderSend() { _setUploadPlaceholderSend() {
if (!this.composer.get("reply")) { if (!this.composer.get("reply")) {
this.composer.set("reply", ""); this.composer.set("reply", "");
@ -157,7 +164,7 @@ export default ComposerEditor.extend({
this._setUploadPlaceholderSend(data); this._setUploadPlaceholderSend(data);
this.appEvents.trigger("wizard-editor:insert-text", { this.appEvents.trigger("wizard-editor:insert-text", {
fieldId: this.fieldId, fieldId: this.field.id,
text: this.uploadPlaceholder text: this.uploadPlaceholder
}); });
@ -181,7 +188,7 @@ export default ComposerEditor.extend({
cacheShortUploadUrl(upload.short_url, upload); cacheShortUploadUrl(upload.short_url, upload);
this.appEvents.trigger( this.appEvents.trigger(
"wizard-editor:replace-text", { "wizard-editor:replace-text", {
fieldId: this.fieldId, fieldId: this.field.id,
oldVal: this.uploadPlaceholder.trim(), oldVal: this.uploadPlaceholder.trim(),
newVal: markdown newVal: markdown
} }
@ -208,7 +215,7 @@ export default ComposerEditor.extend({
if (removePlaceholder) { if (removePlaceholder) {
this.appEvents.trigger( this.appEvents.trigger(
"wizard-editor:replace-text", { "wizard-editor:replace-text", {
fieldId: this.fieldId, fieldId: this.field.id,
oldVal: this.uploadPlaceholder, oldVal: this.uploadPlaceholder,
newVal: "" newVal: ""
} }
@ -240,7 +247,7 @@ export default ComposerEditor.extend({
this.appEvents.trigger( this.appEvents.trigger(
"wizard-editor:replace-text", "wizard-editor:replace-text",
{ {
fieldId: this.fieldId, fieldId: this.field.id,
oldVal: matchingPlaceholder[index], oldVal: matchingPlaceholder[index],
newVal: replacement, newVal: replacement,
options: { options: {
@ -295,7 +302,7 @@ export default ComposerEditor.extend({
addLink(linkName, linkUrl) { addLink(linkName, linkUrl) {
let link = `[${linkName}](${linkUrl})`; let link = `[${linkName}](${linkUrl})`;
this.appEvents.trigger("wizard-editor:insert-text", { this.appEvents.trigger("wizard-editor:insert-text", {
fieldId: this.fieldId, fieldId: this.field.id,
text: link text: link
}); });
this.set("showHyperlinkBox", false); this.set("showHyperlinkBox", false);

Datei anzeigen

@ -12,7 +12,7 @@
loading=composer.loading loading=composer.loading
showLink=showLink showLink=showLink
wizardComposerEvents=true wizardComposerEvents=true
fieldId=fieldId fieldId=field.id
disabled=disableTextarea disabled=disableTextarea
outletArgs=(hash composer=composer editorType="composer")}} outletArgs=(hash composer=composer editorType="composer")}}
@ -20,6 +20,7 @@
class="wizard-composer-upload hidden-upload-field" class="wizard-composer-upload hidden-upload-field"
disabled=isUploading disabled=isUploading
type="file" type="file"
accept=allowedFileTypes
multiple=true}} multiple=true}}
{{#if showHyperlinkBox}} {{#if showHyperlinkBox}}

Datei anzeigen

@ -1,6 +1,5 @@
{{wizard-composer-editor {{wizard-composer-editor
replyPlaceholder=field.placeholder field=field
fieldId=field.id
composer=composer composer=composer
groupsMentioned=(action "groupsMentioned") groupsMentioned=(action "groupsMentioned")
cannotSeeMention=(action "cannotSeeMention") cannotSeeMention=(action "cannotSeeMention")