diff --git a/assets/javascripts/wizard/components/wizard-field-upload.js.es6 b/assets/javascripts/wizard/components/wizard-field-upload.js.es6
new file mode 100644
index 00000000..f7f82faf
--- /dev/null
+++ b/assets/javascripts/wizard/components/wizard-field-upload.js.es6
@@ -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);
+ });
+ }
+});
diff --git a/assets/javascripts/wizard/templates/components/wizard-field-upload.hbs b/assets/javascripts/wizard/templates/components/wizard-field-upload.hbs
new file mode 100644
index 00000000..4d984912
--- /dev/null
+++ b/assets/javascripts/wizard/templates/components/wizard-field-upload.hbs
@@ -0,0 +1,16 @@
+
+
+{{#if field.value}}
+
+ {{field.value.original_filename}}
+
+{{/if}}
diff --git a/assets/stylesheets/wizard/wizard_custom.scss b/assets/stylesheets/wizard/wizard_custom.scss
index d0f58475..93989e00 100644
--- a/assets/stylesheets/wizard/wizard_custom.scss
+++ b/assets/stylesheets/wizard/wizard_custom.scss
@@ -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;
}
diff --git a/lib/field.rb b/lib/field.rb
index a56ff40f..e59d4bba 100644
--- a/lib/field.rb
+++ b/lib/field.rb
@@ -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