From f1d74871e7f00e8bbde3501a759487ac8cc4c3fc Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 13 Apr 2018 16:23:04 -0700 Subject: Rename from Active Text to Action Text This is more like Action View than Active Model. --- app/javascript/actiontext/attachment_upload.js | 45 ++++++++++++++++++++++++++ app/javascript/actiontext/index.js | 11 +++++++ app/javascript/activetext/attachment_upload.js | 45 -------------------------- app/javascript/activetext/index.js | 11 ------- 4 files changed, 56 insertions(+), 56 deletions(-) create mode 100644 app/javascript/actiontext/attachment_upload.js create mode 100644 app/javascript/actiontext/index.js delete mode 100644 app/javascript/activetext/attachment_upload.js delete mode 100644 app/javascript/activetext/index.js (limited to 'app/javascript') diff --git a/app/javascript/actiontext/attachment_upload.js b/app/javascript/actiontext/attachment_upload.js new file mode 100644 index 0000000000..a716f1f589 --- /dev/null +++ b/app/javascript/actiontext/attachment_upload.js @@ -0,0 +1,45 @@ +import { DirectUpload } from "activestorage" + +export class AttachmentUpload { + constructor(attachment, element) { + this.attachment = attachment + this.element = element + this.directUpload = new DirectUpload(attachment.file, this.directUploadUrl, this) + } + + start() { + this.directUpload.create(this.directUploadDidComplete.bind(this)) + } + + directUploadWillStoreFileWithXHR(xhr) { + xhr.upload.addEventListener("progress", event => { + const progress = event.loaded / event.total * 100 + this.attachment.setUploadProgress(progress) + }) + } + + directUploadDidComplete(error, attributes) { + if (error) { + throw new Error(`Direct upload failed: ${error}`) + } + + this.attachment.setAttributes({ + sgid: attributes.attachable_sgid, + url: this.createBlobUrl(attributes.signed_id, attributes.filename) + }) + } + + createBlobUrl(signedId, filename) { + return this.blobUrlTemplate + .replace(":signed_id", signedId) + .replace(":filename", encodeURIComponent(filename)) + } + + get directUploadUrl() { + return this.element.dataset.directUploadUrl + } + + get blobUrlTemplate() { + return this.element.dataset.blobUrlTemplate + } +} diff --git a/app/javascript/actiontext/index.js b/app/javascript/actiontext/index.js new file mode 100644 index 0000000000..c149eda952 --- /dev/null +++ b/app/javascript/actiontext/index.js @@ -0,0 +1,11 @@ +import * as Trix from "trix" +import { AttachmentUpload } from "./attachment_upload" + +addEventListener("trix-attachment-add", event => { + const { attachment, target } = event + + if (attachment.file) { + const upload = new AttachmentUpload(attachment, target) + upload.start() + } +}) diff --git a/app/javascript/activetext/attachment_upload.js b/app/javascript/activetext/attachment_upload.js deleted file mode 100644 index a716f1f589..0000000000 --- a/app/javascript/activetext/attachment_upload.js +++ /dev/null @@ -1,45 +0,0 @@ -import { DirectUpload } from "activestorage" - -export class AttachmentUpload { - constructor(attachment, element) { - this.attachment = attachment - this.element = element - this.directUpload = new DirectUpload(attachment.file, this.directUploadUrl, this) - } - - start() { - this.directUpload.create(this.directUploadDidComplete.bind(this)) - } - - directUploadWillStoreFileWithXHR(xhr) { - xhr.upload.addEventListener("progress", event => { - const progress = event.loaded / event.total * 100 - this.attachment.setUploadProgress(progress) - }) - } - - directUploadDidComplete(error, attributes) { - if (error) { - throw new Error(`Direct upload failed: ${error}`) - } - - this.attachment.setAttributes({ - sgid: attributes.attachable_sgid, - url: this.createBlobUrl(attributes.signed_id, attributes.filename) - }) - } - - createBlobUrl(signedId, filename) { - return this.blobUrlTemplate - .replace(":signed_id", signedId) - .replace(":filename", encodeURIComponent(filename)) - } - - get directUploadUrl() { - return this.element.dataset.directUploadUrl - } - - get blobUrlTemplate() { - return this.element.dataset.blobUrlTemplate - } -} diff --git a/app/javascript/activetext/index.js b/app/javascript/activetext/index.js deleted file mode 100644 index c149eda952..0000000000 --- a/app/javascript/activetext/index.js +++ /dev/null @@ -1,11 +0,0 @@ -import * as Trix from "trix" -import { AttachmentUpload } from "./attachment_upload" - -addEventListener("trix-attachment-add", event => { - const { attachment, target } = event - - if (attachment.file) { - const upload = new AttachmentUpload(attachment, target) - upload.start() - } -}) -- cgit v1.2.3