Merge pull request #1809 from rockandror/documentable-ajax
[WIP] Documentable
This commit is contained in:
@@ -17,6 +17,14 @@
|
||||
</h3>
|
||||
<% end %>
|
||||
</li>
|
||||
<li class="tabs-title">
|
||||
<%= link_to "#tab-documents" do %>
|
||||
<h3>
|
||||
<%= t("documents.tab") %>
|
||||
(<%= @investment.documents.count %>)
|
||||
</h3>
|
||||
<% end %>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -21,6 +21,10 @@
|
||||
<%= f.text_field :external_url %>
|
||||
</div>
|
||||
|
||||
<div class="documents small-12 column" data-max-documents="<%= Budget::Investment.max_documents_allowed %>">
|
||||
<%= render 'documents/nested_documents', documentable: @investment %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= f.text_field :location %>
|
||||
</div>
|
||||
|
||||
@@ -4,6 +4,12 @@
|
||||
<div class="small-12 medium-9 column">
|
||||
<%= back_link_to budget_investments_path(investment.budget, heading_id: investment.heading) %>
|
||||
|
||||
<% if can?(:create, @document) && investment.documents.size < Budget::Investment.max_documents_allowed %>
|
||||
<%= link_to t("documents.upload_document"),
|
||||
new_document_path(documentable_id:investment, documentable_type: investment.class.name, from: request.url),
|
||||
class: 'button hollow float-right' %>
|
||||
<% end %>
|
||||
|
||||
<h1><%= investment.title %></h1>
|
||||
|
||||
<div class="budget-investment-info">
|
||||
@@ -14,7 +20,6 @@
|
||||
<span class="bullet"> • </span>
|
||||
<%= investment.heading.name %>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<p id="investment_code">
|
||||
<%= t("budgets.investments.show.code_html", code: investment.id) %>
|
||||
@@ -51,6 +56,7 @@
|
||||
<h2><%= t('budgets.investments.show.price_explanation') %></h2>
|
||||
<p><%= investment.price_explanation %></p>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
||||
<aside class="small-12 medium-3 column">
|
||||
|
||||
@@ -19,4 +19,11 @@
|
||||
comment_flags: @comment_flags,
|
||||
display_comments_count: false } %>
|
||||
</div>
|
||||
|
||||
<div class="tabs-panel" id="tab-documents">
|
||||
<%= render 'documents/documents',
|
||||
documents: @investment.documents,
|
||||
max_documents_allowed: Budget::Investment.max_documents_allowed %>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
20
app/views/documents/_document.html.erb
Normal file
20
app/views/documents/_document.html.erb
Normal file
@@ -0,0 +1,20 @@
|
||||
<tr id="<%= dom_id(document)%>">
|
||||
<td class="document-link">
|
||||
<%= document.title %>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<%= link_to t('documents.buttons.download_document'),
|
||||
document.attachment.url,
|
||||
target: "_blank",
|
||||
rel: "nofollow",
|
||||
class: 'button hollow' %>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<% if can? :destroy, Document %>
|
||||
<%= link_to t('documents.buttons.destroy_document'),
|
||||
document_path(document, from: request.url), method: :delete,
|
||||
data: { confirm: t('documents.actions.destroy.confirm') },
|
||||
class: 'button hollow alert' %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
35
app/views/documents/_documents.html.erb
Normal file
35
app/views/documents/_documents.html.erb
Normal file
@@ -0,0 +1,35 @@
|
||||
<% if documents.any? %>
|
||||
|
||||
<% if documents.size == max_documents_allowed && can?(:create, Document) %>
|
||||
<div class="row documents-list">
|
||||
<div class="small-12 column">
|
||||
<div class="callout warning text-center">
|
||||
<%= t "documents.max_documents_allowed_reached_html" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="row documents-list">
|
||||
<div class="small-12 column">
|
||||
<table>
|
||||
<tbody>
|
||||
<% documents.each do |document| %>
|
||||
<%= render "documents/document", document: document %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% else %>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 column">
|
||||
<div class="callout primary text-center">
|
||||
<%= t('documents.no_documents') %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
20
app/views/documents/_form.html.erb
Normal file
20
app/views/documents/_form.html.erb
Normal file
@@ -0,0 +1,20 @@
|
||||
<%= form_for @document,
|
||||
url: documents_path(
|
||||
documentable_type: @document.documentable_type,
|
||||
documentable_id: @document.documentable_id,
|
||||
from: params[:from]
|
||||
),
|
||||
html: { multipart: true, class: "documentable"},
|
||||
data: { direct_upload_url: upload_documents_url(documentable_type: @document.documentable_type, documentable_id: @document.documentable_id) } do |f| %>
|
||||
|
||||
<%= render 'shared/errors', resource: @document %>
|
||||
|
||||
<div class="row">
|
||||
|
||||
<%= render 'plain_fields', document: @document %>
|
||||
|
||||
<div class="actions small-12 medium-6 large-4 end column">
|
||||
<%= f.submit(t("documents.form.submit_button"), class: "button expanded") %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
22
app/views/documents/_nested_documents.html.erb
Normal file
22
app/views/documents/_nested_documents.html.erb
Normal file
@@ -0,0 +1,22 @@
|
||||
<div class="documents-list">
|
||||
<%= label_tag :documents, t("documents.form.title") %>
|
||||
<p class="help-text"><%= documentables_note(documentable) %></p>
|
||||
|
||||
<% documentable.documents.each_with_index do |document, index| %>
|
||||
<%= render 'documents/nested_fields', document: document, index: index, documentable: documentable %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<% unless max_documents_allowed?(documentable) %>
|
||||
<%= link_to t("documents.form.add_new_document"),
|
||||
new_nested_documents_path(documentable_type: documentable.class.name, index: documentable.documents.size),
|
||||
remote: true,
|
||||
id: "new_document_link",
|
||||
class: "button hollow" %>
|
||||
<% end %>
|
||||
|
||||
<div class="max-documents-notice callout warning text-center <%= "hide" unless max_documents_allowed?(documentable) %>">
|
||||
<%= t "documents.max_documents_allowed_reached_html" %>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
31
app/views/documents/_nested_fields.html.erb
Normal file
31
app/views/documents/_nested_fields.html.erb
Normal file
@@ -0,0 +1,31 @@
|
||||
<div id="<%= document_nested_field_wrapper_id(index) %>" class="document">
|
||||
<%= hidden_field_tag :id,
|
||||
document.id,
|
||||
name: document_nested_field_name(document, index, :id),
|
||||
id: document_nested_field_id(document, index, :id) if document.persisted? %>
|
||||
<%= hidden_field_tag :user_id,
|
||||
current_user.id,
|
||||
name: document_nested_field_name(document, index, :user_id),
|
||||
id: document_nested_field_id(document, index, :user_id) %>
|
||||
<%= hidden_field_tag :cached_attachment,
|
||||
document.cached_attachment,
|
||||
name: document_nested_field_name(document, index, :cached_attachment),
|
||||
id: document_nested_field_id(document, index, :cached_attachment) %>
|
||||
|
||||
<%= label_tag :title, t("activerecord.attributes.document.title") %>
|
||||
<%= text_field_tag :title,
|
||||
document.title,
|
||||
name: document_nested_field_name(document, index, :title),
|
||||
id: document_nested_field_id(document, index, :title),
|
||||
class: "document-title" %>
|
||||
<% if document.errors[:title].any? %>
|
||||
<small class="error"><%= document.errors[:title].join(", ") %></small>
|
||||
<% end %>
|
||||
|
||||
<%= render_attachment(document, index) %>
|
||||
|
||||
<%= render_destroy_document_link(document, index) %>
|
||||
<p class="file-name"><%= document_attachment_file_name(document) %></p>
|
||||
<div class="progress-bar-placeholder"><div class="loading-bar"></div></div>
|
||||
<hr>
|
||||
</div>
|
||||
50
app/views/documents/_plain_fields.html.erb
Normal file
50
app/views/documents/_plain_fields.html.erb
Normal file
@@ -0,0 +1,50 @@
|
||||
<div id="plain_document_fields" class="document">
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= label_tag :document_title, t("activerecord.attributes.document.title") %>
|
||||
<%= text_field_tag :document_title, document.title, name: "document[title]", class: "document-title" %>
|
||||
<% if document.errors.has_key?(:title) %>
|
||||
<small class="error"><%= document.errors[:title].join(", ") %></small>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= hidden_field_tag :cached_attachment, document.cached_attachment, name: "document[cached_attachment]" %>
|
||||
<%= file_field_tag :attachment,
|
||||
accept: accepted_content_types_extensions(document.documentable.class),
|
||||
label: false,
|
||||
class: 'document_ajax_attachment',
|
||||
data: {
|
||||
url: upload_documents_url(documentable_type: document.documentable_type, documentable_id: document.documentable_id),
|
||||
cached_attachment_input_field: "document_cached_attachment",
|
||||
multiple: false,
|
||||
nested_document: false
|
||||
},
|
||||
id: "document_attachment",
|
||||
name: "document[attachment]" %>
|
||||
|
||||
<% if document.cached_attachment.blank? %>
|
||||
<%= label_tag :document_attachment, t("documents.form.attachment_label"), class: 'button hollow' %>
|
||||
<% else %>
|
||||
<%= link_to t('documents.form.delete_button'),
|
||||
destroy_upload_documents_path(path: document.cached_attachment,
|
||||
nested_document: false,
|
||||
documentable_type: document.documentable_type,
|
||||
documentable_id: document.documentable_id),
|
||||
method: :delete,
|
||||
remote: true,
|
||||
class: "delete float-right" %>
|
||||
<% end %>
|
||||
|
||||
<% if document.errors.has_key?(:attachment) %>
|
||||
<div class="small-12 column source-option-file">
|
||||
<div class="attachment-errors">
|
||||
<small class="error"><%= errors_on_attachment(document) %></small>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<p class="file-name"><%= document_attachment_file_name(document) %></p>
|
||||
<div class="progress-bar-placeholder"><div class="loading-bar"></div></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
17
app/views/documents/destroy.js.erb
Normal file
17
app/views/documents/destroy.js.erb
Normal file
@@ -0,0 +1,17 @@
|
||||
<% if params[:nested_document] == "true" %>
|
||||
|
||||
App.Documentable.destroyNestedDocument("<%= document_nested_field_wrapper_id(params[:index]) %>", "<%= j render('layouts/flash') %>")
|
||||
<% new_document_link = link_to t("documents.form.add_new_document"),
|
||||
new_nested_documents_path(documentable_type: @document.documentable_type, index: params[:index]),
|
||||
remote: true,
|
||||
id: "new_document_link",
|
||||
class: "button hollow" %>
|
||||
App.Documentable.updateNewDocumentButton("<%= j new_document_link %>")
|
||||
|
||||
<% else %>
|
||||
|
||||
App.Documentable.replacePlainDocument("plain_document_fields",
|
||||
"<%= j render('layouts/flash') %>",
|
||||
"<%= j render('plain_fields', document: @document) %>")
|
||||
|
||||
<% end %>
|
||||
27
app/views/documents/new.html.erb
Normal file
27
app/views/documents/new.html.erb
Normal file
@@ -0,0 +1,27 @@
|
||||
<div class="document-form <%= documentable_class(@document.documentable) %> row">
|
||||
|
||||
<div class="small-12 medium-9 column">
|
||||
<%= back_link_to params[:from] %>
|
||||
<h1><%= t("documents.new.title") %></h1>
|
||||
<%= render "documents/form", form_url: documents_url %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-3 column">
|
||||
<span class="icon-documents float-right"></span>
|
||||
<h2><%= t("documents.recommendations_title") %></h2>
|
||||
<ul class="recommendations">
|
||||
<li>
|
||||
<%= t "documents.recommendation_one_html",
|
||||
max_documents_allowed: max_documents_allowed(@document.documentable) %>
|
||||
</li>
|
||||
<li>
|
||||
<%= t "documents.recommendation_two_html",
|
||||
accepted_content_types: humanized_accepted_content_types(@document.documentable) %>
|
||||
</li>
|
||||
<li>
|
||||
<%= t "documents.recommendation_three_html",
|
||||
max_file_size: max_file_size(@document.documentable) %>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
9
app/views/documents/new_nested.js.erb
Normal file
9
app/views/documents/new_nested.js.erb
Normal file
@@ -0,0 +1,9 @@
|
||||
<%
|
||||
new_document_link = link_to t("documents.form.add_new_document"),
|
||||
new_nested_documents_path(documentable_type: params[:documentable_type], index: params[:index].to_i + 1),
|
||||
remote: true,
|
||||
id: "new_document_link",
|
||||
class: "button hollow"
|
||||
%>
|
||||
App.Documentable.new("<%= j render('documents/nested_fields', document: @document, index: params[:index]) %>")
|
||||
App.Documentable.updateNewDocumentButton("<%= j new_document_link %>")
|
||||
12
app/views/documents/upload.js.erb
Normal file
12
app/views/documents/upload.js.erb
Normal file
@@ -0,0 +1,12 @@
|
||||
<% if params[:nested_document] == "true" %>
|
||||
|
||||
App.Documentable.uploadNestedDocument("<%= document_nested_field_wrapper_id(params[:index]) %>",
|
||||
"<%= j render('documents/nested_fields', document: @document, index: params[:index]) %>",
|
||||
<%= @document.cached_attachment.present? %>)
|
||||
<% else %>
|
||||
|
||||
App.Documentable.uploadPlainDocument("plain_document_fields",
|
||||
"<%= j render('documents/plain_fields', document: @document) %>",
|
||||
<%= @document.cached_attachment.present? %>)
|
||||
|
||||
<% end %>
|
||||
@@ -17,6 +17,14 @@
|
||||
</h3>
|
||||
<% end %>
|
||||
</li>
|
||||
<li class="tabs-title">
|
||||
<%= link_to "#tab-documents" do %>
|
||||
<h3>
|
||||
<%= t("documents.tab") %>
|
||||
(<%= @proposal.documents.count %>)
|
||||
</h3>
|
||||
<% end %>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
<%= f.cktext_area :description, maxlength: Proposal.description_max_length, ckeditor: { language: I18n.locale }, label: false %>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= f.label :video_url, t("proposals.form.proposal_video_url") %>
|
||||
<p class="help-text" id="video-url-help-text"><%= t("proposals.form.proposal_video_url_note") %></p>
|
||||
@@ -47,6 +46,10 @@
|
||||
<%= f.text_field :external_url, placeholder: t("proposals.form.proposal_external_url"), label: false %>
|
||||
</div>
|
||||
|
||||
<div class="documents small-12 column" data-max-documents="<%= Proposal.max_documents_allowed %>">
|
||||
<%= render 'documents/nested_documents', documentable: @proposal %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= f.label :geozone_id, t("proposals.form.geozone") %>
|
||||
<%= f.select :geozone_id, geozone_select_options, {include_blank: t("geozones.none"), label: false} %>
|
||||
|
||||
@@ -16,6 +16,12 @@
|
||||
<div class="small-12 medium-9 column">
|
||||
<%= back_link_to %>
|
||||
|
||||
<% if can?(:create, @document) && @proposal.documents.size < Proposal.max_documents_allowed %>
|
||||
<%= link_to t("documents.upload_document"),
|
||||
new_document_path(documentable_id: @proposal, documentable_type: @proposal.class.name, from: request.url),
|
||||
class: 'button hollow float-right' %>
|
||||
<% end %>
|
||||
|
||||
<% if author_of?(@proposal, current_user) %>
|
||||
<%= link_to t("proposals.show.send_notification"), new_proposal_notification_path(proposal_id: @proposal.id),
|
||||
class: 'button hollow float-right' %>
|
||||
@@ -165,4 +171,10 @@
|
||||
<div class="tabs-panel is-active" id="tab-comments">
|
||||
<%= render "proposals/comments" %>
|
||||
</div>
|
||||
|
||||
<div class="tabs-panel" id="tab-documents">
|
||||
<%= render 'documents/documents',
|
||||
documents: @proposal.documents,
|
||||
max_documents_allowed: Proposal.max_documents_allowed %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user