Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-30 04:30:29 +01:00
cf50a7deb3
* Apply prettier * applied prettier for similar-topics-validator Co-authored-by: Faizaan Gagan <fzngagan@gmail.com>
63 Zeilen
1,6 KiB
JavaScript
63 Zeilen
1,6 KiB
JavaScript
import getUrl from "discourse-common/lib/get-url";
|
|
import { getToken } from "wizard/lib/ajax";
|
|
import WizardI18n from "../lib/wizard-i18n";
|
|
|
|
export default Ember.Component.extend({
|
|
classNames: ["wizard-field-upload"],
|
|
classNameBindings: ["isImage"],
|
|
uploading: false,
|
|
isImage: false,
|
|
|
|
didInsertElement() {
|
|
this._super();
|
|
|
|
const $upload = $(this.element);
|
|
|
|
const id = this.get("field.id");
|
|
|
|
$upload.fileupload({
|
|
url: getUrl("/uploads.json"),
|
|
formData: {
|
|
synchronous: true,
|
|
type: `wizard_${id}`,
|
|
authenticity_token: getToken(),
|
|
},
|
|
dataType: "json",
|
|
dropZone: $upload,
|
|
});
|
|
|
|
$upload.on("fileuploadsubmit", () => this.set("uploading", true));
|
|
|
|
$upload.on("fileuploaddone", (e, response) => {
|
|
this.setProperties({
|
|
"field.value": response.result,
|
|
uploading: false,
|
|
});
|
|
if (
|
|
Discourse.SiteSettings.wizard_recognised_image_upload_formats
|
|
.split("|")
|
|
.includes(response.result.extension)
|
|
) {
|
|
this.setProperties({
|
|
isImage: true,
|
|
});
|
|
}
|
|
});
|
|
|
|
$upload.on("fileuploadfail", (e, response) => {
|
|
let message = WizardI18n("wizard.upload_error");
|
|
if (response.jqXHR.responseJSON && response.jqXHR.responseJSON.errors) {
|
|
message = response.jqXHR.responseJSON.errors.join("\n");
|
|
}
|
|
|
|
window.swal({
|
|
customClass: "wizard-warning",
|
|
title: "",
|
|
text: message,
|
|
type: "warning",
|
|
confirmButtonColor: "#6699ff",
|
|
});
|
|
this.set("uploading", false);
|
|
});
|
|
},
|
|
});
|