-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4586 from consul/attach_with_keyboard
Allow attaching files using the keyboard
- Loading branch information
Showing
40 changed files
with
324 additions
and
450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<div class="document direct-upload document-fields nested-fields"> | ||
<%= f.hidden_field :id %> | ||
<%= f.hidden_field :user_id, value: current_user.id %> | ||
<%= f.hidden_field :cached_attachment %> | ||
|
||
<div class="small-12 column title"> | ||
<%= f.text_field :title, placeholder: t("documents.form.title_placeholder") %> | ||
</div> | ||
|
||
<div class="small-12 column attachment-actions"> | ||
<p class="file-name small-9 column"><%= file_name %></p> | ||
|
||
<div class="small-9 column action-add attachment-errors document-attachment"> | ||
<%= file_field %> | ||
</div> | ||
|
||
<div class="small-3 column action-remove text-right"> | ||
<%= destroy_link %> | ||
</div> | ||
</div> | ||
|
||
<div class="small-12 column"> | ||
<div class="progress-bar-placeholder"><div class="loading-bar"></div></div> | ||
</div> | ||
|
||
<hr> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
class Documents::FieldsComponent < ApplicationComponent | ||
attr_reader :f | ||
delegate :current_user, to: :helpers | ||
|
||
def initialize(f) | ||
@f = f | ||
end | ||
|
||
private | ||
|
||
def document | ||
f.object | ||
end | ||
|
||
def file_name | ||
document.attachment_file_name | ||
end | ||
|
||
def destroy_link | ||
if !document.persisted? && document.cached_attachment.present? | ||
link_to t("documents.form.delete_button"), | ||
direct_upload_destroy_path( | ||
"direct_upload[resource_type]": document.documentable_type, | ||
"direct_upload[resource_id]": document.documentable_id, | ||
"direct_upload[resource_relation]": "documents", | ||
"direct_upload[cached_attachment]": document.cached_attachment | ||
), | ||
method: :delete, | ||
remote: true, | ||
class: "delete remove-cached-attachment" | ||
else | ||
link_to_remove_association document.new_record? ? t("documents.form.cancel_button") : t("documents.form.delete_button"), f, class: "delete remove-document" | ||
end | ||
end | ||
|
||
def file_field | ||
klass = document.persisted? || document.cached_attachment.present? ? " hide" : "" | ||
f.file_field :attachment, | ||
label_options: { class: "button hollow #{klass}" }, | ||
accept: accepted_content_types_extensions, | ||
class: "js-document-attachment", | ||
data: { url: direct_upload_path } | ||
end | ||
|
||
def direct_upload_path | ||
direct_uploads_path("direct_upload[resource_type]": document.documentable_type, | ||
"direct_upload[resource_id]": document.documentable_id, | ||
"direct_upload[resource_relation]": "documents") | ||
end | ||
|
||
def accepted_content_types_extensions | ||
Setting.accepted_content_types_for("documents").map { |content_type| ".#{content_type}" }.join(",") | ||
end | ||
end |
Oops, something went wrong.