0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-09 20:02:54 +01:00

Merge pull request #5 from angusmcleod/pr/4

Add upload component
Dieser Commit ist enthalten in:
Angus McLeod 2018-09-15 16:22:08 +10:00 committet von GitHub
Commit 5c7ab3d550
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
4 geänderte Dateien mit 87 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,51 @@
import getUrl from "discourse-common/lib/get-url";
import { getToken } from "wizard/lib/ajax";
export default Ember.Component.extend({
classNames: ["wizard-field-upload"],
uploading: false,
didInsertElement() {
this._super();
const $upload = this.$();
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
});
});
$upload.on("fileuploadfail", (e, response) => {
let message = I18n.t("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);
});
}
});

Datei anzeigen

@ -0,0 +1,16 @@
<label class="wizard-btn wizard-btn-upload-file {{if uploading 'disabled'}}">
{{#if uploading}}
{{i18n "wizard.uploading"}}
{{else}}
{{i18n "wizard.upload"}}
{{d-icon "upload"}}
{{/if}}
<input disabled={{uploading}} type="file" accept="image/*,application/pdf" style="visibility: hidden; position: absolute;" />
</label>
{{#if field.value}}
<a href="{{field.value.url}}" class="filename">
{{field.value.original_filename}}
</a>
{{/if}}

Datei anzeigen

@ -218,6 +218,25 @@
margin: 0;
}
.wizard-field-upload {
.wizard-btn-upload-file {
display: inline-block;
position: relative;
cursor: pointer;
input {
left: 0;
right: 0;
top: 0;
bottom: 0;
}
}
.filename {
margin-left: 10px;
}
}
.wizard-column .wizard-field .input-area {
margin: 0.5em 0;
}

Datei anzeigen

@ -1,6 +1,6 @@
class CustomWizard::Field
def self.types
@types ||= ['text', 'textarea', 'dropdown', 'image', 'checkbox', 'user-selector', 'text-only', 'composer']
@types ||= ['checkbox', 'composer', 'dropdown', 'image', 'text', 'textarea', 'text-only', 'upload', 'user-selector']
end
def self.require_assets