FIX: csv-uploader has been removed from core (#116)

FIX: csv-uploader has been removed from core (#116)

For now copy previous component into discourse-calendar plugin

diff --git a/assets/javascripts/discourse/components/csv-uploader.js.es6 b/assets/javascripts/discourse/components/csv-uploader.js.es6
new file mode 100644
index 0000000..dd21c2c
--- /dev/null
+++ b/assets/javascripts/discourse/components/csv-uploader.js.es6
@@ -0,0 +1,49 @@
+import Component from "@ember/component";
+import I18n from "I18n";
+import UploadMixin from "discourse/mixins/upload";
+import bootbox from "bootbox";
+import discourseComputed from "discourse-common/utils/decorators";
+import { on } from "@ember/object/evented";
+
+export default Component.extend(UploadMixin, {
+  type: "csv",
+  tagName: "span",
+  uploadUrl: null,
+  i18nPrefix: null,
+
+  validateUploadedFilesOptions() {
+    return { csvOnly: true };
+  },
+
+  @discourseComputed("uploading")
+  uploadButtonText(uploading) {
+    return uploading ? I18n.t("uploading") : I18n.t(`${this.i18nPrefix}.text`);
+  },
+
+  @discourseComputed("uploading")
+  uploadButtonDisabled(uploading) {
+    // https://github.com/emberjs/ember.js/issues/10976#issuecomment-132417731
+    return uploading ? true : null;
+  },
+
+  uploadDone() {
+    bootbox.alert(I18n.t(`${this.i18nPrefix}.success`));
+  },
+
+  uploadOptions() {
+    return { autoUpload: false };
+  },
+
+  _init: on("didInsertElement", function () {
+    const $upload = $(this.element);
+
+    $upload.on("fileuploadadd", (e, data) => {
+      bootbox.confirm(
+        I18n.t(`${this.i18nPrefix}.confirmation_message`),
+        I18n.t("cancel"),
+        I18n.t("go_ahead"),
+        (result) => (result ? data.submit() : data.abort())
+      );
+    });
+  }),
+});
diff --git a/assets/javascripts/discourse/templates/components/csv-uploader.hbs b/assets/javascripts/discourse/templates/components/csv-uploader.hbs
new file mode 100644
index 0000000..4d03e30
--- /dev/null
+++ b/assets/javascripts/discourse/templates/components/csv-uploader.hbs
@@ -0,0 +1,7 @@
+<label class="btn" disabled={{uploadButtonDisabled}}>
+  {{d-icon "upload"}}&nbsp;{{uploadButtonText}}
+  <input class="hidden-upload-field" disabled={{uploading}} type="file" accept=".csv">
+</label>
+{{#if uploading}}
+  <span>{{i18n "upload_selector.uploading"}} {{uploadProgress}}%</span>
+{{/if}}
diff --git a/assets/javascripts/discourse/templates/modal/discourse-post-event-bulk-invite.hbs b/assets/javascripts/discourse/templates/modal/discourse-post-event-bulk-invite.hbs
index 831a3c8..7515eb4 100644
--- a/assets/javascripts/discourse/templates/modal/discourse-post-event-bulk-invite.hbs
+++ b/assets/javascripts/discourse/templates/modal/discourse-post-event-bulk-invite.hbs
@@ -62,7 +62,7 @@
       {{bulk-invite-sample-csv-file}}
 
       {{csv-uploader
-        uploadUrl=(concat "/discourse-post-event/events/" model.id "/csv-bulk-invite")
+        uploadUrl=(concat "/discourse-post-event/events/" model.eventModel.id "/csv-bulk-invite")
         i18nPrefix="discourse_post_event.bulk_invite_modal"
         uploading=uploading
         uploadDone=(action "uploadDone")

GitHub sha: c382248c

This commit appears in #116 which was approved by markvanlan. It was merged by jjaffeux.