Duplicate documentable code and rename for imageable
This commit is contained in:
@@ -21,6 +21,10 @@
|
||||
<%= f.text_field :external_url %>
|
||||
</div>
|
||||
|
||||
<div class="images small-12 column" data-max-images="1">
|
||||
<%= render 'images/nested_images', imageable: @investment %>
|
||||
</div>
|
||||
|
||||
<div class="documents small-12 column" data-max-documents="<%= Budget::Investment.max_documents_allowed %>">
|
||||
<%= render 'documents/nested_documents', documentable: @investment %>
|
||||
</div>
|
||||
@@ -53,29 +57,6 @@
|
||||
data: {js_url: suggest_tags_path} %>
|
||||
</div>
|
||||
|
||||
<%= f.fields_for :image do |builder| %>
|
||||
|
||||
<div class="small-12 column">
|
||||
<div class="image-upload">
|
||||
<%= f.file_field :attachment, accept: 'image/jpg,image/jpeg', label: false, class:'show-for-sr' %>
|
||||
<br>
|
||||
<%= f.label :attachment, t("budgets.investments.form.image_label"), class:'button' %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% if @investment.errors.has_key?(:attachment) %>
|
||||
<div class="small-12 column">
|
||||
<div class="image-errors">
|
||||
<small class="error"><%= errors_on_image(@investment)%></small>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= f.text_field :title %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% unless current_user.manager? %>
|
||||
|
||||
<div class="small-12 column">
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
<%= form_for([@investment.budget, @investment], url: update_image_budget_investment_path(@investment.budget, @investment), multipart: true, method: :put) do |f| %>
|
||||
<%= render 'shared/errors', resource: @investment %>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 column">
|
||||
<span class="note-marked">
|
||||
<p><%= investment_image_advice_note(@investment) %></p>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<% if @investment.image.exists? %>
|
||||
<div class="small-12 column">
|
||||
<%= image_tag @investment.image_url(:large) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="small-12 column">
|
||||
<div class="image-upload">
|
||||
<%= f.file_field :attachment, accept: 'image/jpg,image/jpeg', label: false, class:'show-for-sr' %>
|
||||
<br>
|
||||
<%= f.label :attachment, t("budgets.investments.edit_image.form.image_label"), class:'button' %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% if @investment.errors.has_key?(:image) %>
|
||||
<div class="small-12 column">
|
||||
<div class="image-errors">
|
||||
<small class="error"><%= errors_on_image(@investment)%></small>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= f.label :title, t("budgets.investments.edit_image.form.image_title") %>
|
||||
<%= f.text_field :title, placeholder: t("budgets.investments.edit_image.form.image_title"), label: false %>
|
||||
</div>
|
||||
|
||||
<div class="actions small-12 column">
|
||||
<%= f.submit(class: "button", value: t("budgets.investments.edit_image.form.submit_button")) %>
|
||||
|
||||
<% if @investment.image.exists? %>
|
||||
<div class="float-right">
|
||||
<%= link_to t("budgets.investments.edit_image.form.remove_button"),
|
||||
remove_image_budget_investment_path(@investment.budget, @investment),
|
||||
class: "button hollow alert",
|
||||
method: :delete,
|
||||
data: { confirm: t("budgets.investments.edit_image.form.remove_alert") } %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -3,11 +3,8 @@
|
||||
<div class="row">
|
||||
|
||||
<div class="small-12 medium-3 large-2 column">
|
||||
<% if investment.image.exists? %>
|
||||
<figure>
|
||||
<%= image_tag investment.image_url(:thumb), alt: investment.image.title %>
|
||||
<figcaption><%= investment.image.title %></figcaption>
|
||||
</figure>
|
||||
<% if investment.image.present? %>
|
||||
<%= image_tag investment.image_url(:thumb), alt: investment.image.title %>
|
||||
<% else %>
|
||||
<div class="no-image"></div>
|
||||
<% end %>
|
||||
|
||||
@@ -10,9 +10,16 @@
|
||||
class: 'button hollow float-right' %>
|
||||
<% end %>
|
||||
|
||||
<% if can?(:edit_image, @investment) %>
|
||||
<%= link_to investment_image_button_text(@investment),
|
||||
edit_image_budget_investment_path(investment.budget, investment),
|
||||
<% if can?(:create, @image) %>
|
||||
<%= link_to t("images.upload_image"),
|
||||
new_image_path(imageable_id:investment, imageable_type: investment.class.name, from: request.url),
|
||||
class: 'button hollow float-right' %>
|
||||
<% end %>
|
||||
|
||||
<% if @investment.image.present? && can?(:destroy, @investment.image) %>
|
||||
<%= link_to t("images.remove_image"),
|
||||
image_path(@investment.image, from: request.url),
|
||||
method: :delete,
|
||||
class: 'button hollow float-right' %>
|
||||
<% end %>
|
||||
|
||||
@@ -28,20 +35,7 @@
|
||||
|
||||
<br>
|
||||
|
||||
<% if investment.image.exists? %>
|
||||
<div class="row">
|
||||
<div class="small-12 column text-center">
|
||||
<figure>
|
||||
<%= image_tag investment.image_url(:large),
|
||||
alt: investment.image.title %>
|
||||
<figcaption class="text-right">
|
||||
<em><%= investment.image.title %></em>
|
||||
</figcaption>
|
||||
</figure>
|
||||
<hr>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<%= render_image(investment.image, :large, true) if investment.image.present? %>
|
||||
|
||||
<p id="investment_code">
|
||||
<%= t("budgets.investments.show.code_html", code: investment.id) %>
|
||||
@@ -138,7 +132,7 @@
|
||||
<%= render partial: 'shared/social_share', locals: {
|
||||
share_title: t("budgets.investments.show.share"),
|
||||
title: investment.title,
|
||||
image_url: investment.image.exists? ? investment_image_full_url(investment, :thumb) : '',
|
||||
image_url: investment.image.present? ? investment_image_full_url(investment, :thumb) : '',
|
||||
url: budget_investment_url(budget_id: investment.budget_id, id: investment.id)
|
||||
} %>
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
<div class="budget-investment-image-form row">
|
||||
|
||||
<div class="small-12 medium-9 column">
|
||||
<%= render "shared/back_link" %>
|
||||
|
||||
<h1><%= t("budgets.investments.edit_image.title") %></h1>
|
||||
|
||||
<%= render "image_form" %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-3 column">
|
||||
<span class="icon-budget-investment-image float-right"></span>
|
||||
<h2><%= t("budgets.investments.edit_image.recommendation_title") %></h2>
|
||||
<ul class="recommendations">
|
||||
<li><%= t("budgets.investments.edit_image.recommendation_one") %></li>
|
||||
<li><%= t("budgets.investments.edit_image.recommendation_two") %></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -3,8 +3,9 @@
|
||||
<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 %>
|
||||
<%= render 'documents/nested_fields', document: document, index: index %>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
||||
<% unless max_documents_allowed?(documentable) %>
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
<% 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>
|
||||
<small class="error"><%= document_errors_on_attachment(document) %></small>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
</li>
|
||||
<li>
|
||||
<%= t "documents.recommendation_two_html",
|
||||
accepted_content_types: humanized_accepted_content_types(@document.documentable) %>
|
||||
accepted_content_types: documentable_humanized_accepted_content_types(@document.documentable) %>
|
||||
</li>
|
||||
<li>
|
||||
<%= t "documents.recommendation_three_html",
|
||||
|
||||
20
app/views/images/_form.html.erb
Normal file
20
app/views/images/_form.html.erb
Normal file
@@ -0,0 +1,20 @@
|
||||
<%= form_for @image,
|
||||
url: images_path(
|
||||
imageable_type: @image.imageable_type,
|
||||
imageable_id: @image.imageable_id,
|
||||
from: params[:from]
|
||||
),
|
||||
html: { multipart: true, class: "imageable"},
|
||||
data: { direct_upload_url: upload_images_url(imageable_type: @image.imageable_type, imageable_id: @image.imageable_id) } do |f| %>
|
||||
|
||||
<%= render 'shared/errors', resource: @image %>
|
||||
|
||||
<div class="row">
|
||||
|
||||
<%= render 'plain_fields', image: @image %>
|
||||
|
||||
<div class="actions small-12 medium-6 large-4 end column">
|
||||
<%= f.submit(t("images.form.submit_button"), class: "button expanded") %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
19
app/views/images/_image.html.erb
Normal file
19
app/views/images/_image.html.erb
Normal file
@@ -0,0 +1,19 @@
|
||||
<div class="row">
|
||||
<div class="small-12 column text-center">
|
||||
<figure>
|
||||
<%= image_tag image.attachment.url(version),
|
||||
class: image_class(image),
|
||||
alt: image.title %>
|
||||
<% if show_caption %>
|
||||
<figcaption class="text-right">
|
||||
<em><%= image.title %></em>
|
||||
</figcaption>
|
||||
<% end %>
|
||||
</figure>
|
||||
|
||||
<% if show_caption %>
|
||||
<hr>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
32
app/views/images/_nested_fields.html.erb
Normal file
32
app/views/images/_nested_fields.html.erb
Normal file
@@ -0,0 +1,32 @@
|
||||
<div id="<%= image_nested_field_wrapper_id %>" class="image">
|
||||
<%= hidden_field_tag :id,
|
||||
image.id,
|
||||
name: image_nested_field_name(image, :id),
|
||||
id: image_nested_field_id(image, :id) if image.persisted? %>
|
||||
<%= hidden_field_tag :user_id,
|
||||
current_user.id,
|
||||
name: image_nested_field_name(image, :user_id),
|
||||
id: image_nested_field_id(image, :user_id) %>
|
||||
<%= hidden_field_tag :cached_attachment,
|
||||
image.cached_attachment,
|
||||
name: image_nested_field_name(image, :cached_attachment),
|
||||
id: image_nested_field_id(image, :cached_attachment) %>
|
||||
|
||||
<%= label_tag :title, t("activerecord.attributes.image.title") %>
|
||||
<%= text_field_tag :title,
|
||||
image.title,
|
||||
name: image_nested_field_name(image, :title),
|
||||
id: image_nested_field_id(image, :title),
|
||||
class: "image-title" %>
|
||||
<% if image.errors[:title].any? %>
|
||||
<small class="error"><%= image.errors[:title].join(", ") %></small>
|
||||
<% end %>
|
||||
|
||||
<%= render_image(image, :thumb, false) if image.attachment.exists? %>
|
||||
|
||||
<%= render_image_attachment(image) %>
|
||||
|
||||
<%= render_destroy_image_link(image) %>
|
||||
<p class="file-name"><%= image_attachment_file_name(image) %></p>
|
||||
<div class="progress-bar-placeholder"><div class="loading-bar"></div></div>
|
||||
</div>
|
||||
16
app/views/images/_nested_images.html.erb
Normal file
16
app/views/images/_nested_images.html.erb
Normal file
@@ -0,0 +1,16 @@
|
||||
<div class="images-list">
|
||||
<%= label_tag :image, t("images.form.title") %>
|
||||
<p class="help-text"><%= imageables_note(imageable) %></p>
|
||||
|
||||
<%= render 'images/nested_fields', image: imageable.image if imageable.image.present? %>
|
||||
</div>
|
||||
|
||||
<% if imageable.image.blank? %>
|
||||
<%= link_to t("images.form.add_new_image"),
|
||||
new_nested_images_path(imageable_type: imageable.class.name, index: 0),
|
||||
remote: true,
|
||||
id: "new_image_link",
|
||||
class: "button hollow" %>
|
||||
<% end %>
|
||||
|
||||
<hr>
|
||||
50
app/views/images/_plain_fields.html.erb
Normal file
50
app/views/images/_plain_fields.html.erb
Normal file
@@ -0,0 +1,50 @@
|
||||
<div id="plain_image_fields" class="image">
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= label_tag :image_title, t("activerecord.attributes.image.title") %>
|
||||
<%= text_field_tag :image_title, image.title, name: "image[title]", class: "image-title" %>
|
||||
<% if image.errors.has_key?(:title) %>
|
||||
<small class="error"><%= image.errors[:title].join(", ") %></small>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= hidden_field_tag :cached_attachment, image.cached_attachment, name: "image[cached_attachment]" %>
|
||||
<%= file_field_tag :attachment,
|
||||
accept: imageable_accepted_content_types_extensions,
|
||||
label: false,
|
||||
class: 'image_ajax_attachment',
|
||||
data: {
|
||||
url: upload_images_url(imageable_type: image.imageable_type, imageable_id: image.imageable_id),
|
||||
cached_attachment_input_field: "image_cached_attachment",
|
||||
multiple: false,
|
||||
nested_image: false
|
||||
},
|
||||
id: "image_attachment",
|
||||
name: "image[attachment]" %>
|
||||
|
||||
<% if image.cached_attachment.blank? %>
|
||||
<%= label_tag :image_attachment, t("images.form.attachment_label"), class: 'button hollow' %>
|
||||
<% else %>
|
||||
<%= link_to t('images.form.delete_button'),
|
||||
destroy_upload_images_path(path: image.cached_attachment,
|
||||
nested_image: false,
|
||||
imageable_type: image.imageable_type,
|
||||
imageable_id: image.imageable_id),
|
||||
method: :delete,
|
||||
remote: true,
|
||||
class: "delete float-right" %>
|
||||
<% end %>
|
||||
|
||||
<% if image.errors.has_key?(:attachment) %>
|
||||
<div class="small-12 column source-option-file">
|
||||
<div class="attachment-errors">
|
||||
<small class="error"><%= image_errors_on_attachment(image) %></small>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<p class="file-name"><%= image_attachment_file_name(image) %></p>
|
||||
<div class="progress-bar-placeholder"><div class="loading-bar"></div></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
17
app/views/images/destroy.js.erb
Normal file
17
app/views/images/destroy.js.erb
Normal file
@@ -0,0 +1,17 @@
|
||||
<% if params[:nested_image] == "true" %>
|
||||
|
||||
App.Imageable.destroyNestedImage("<%= image_nested_field_wrapper_id %>", "<%= j render('layouts/flash') %>")
|
||||
<% new_image_link = link_to t("images.form.add_new_image"),
|
||||
new_nested_images_path(imageable_type: @image.imageable_type),
|
||||
remote: true,
|
||||
id: "new_image_link",
|
||||
class: "button hollow" %>
|
||||
App.Imageable.updateNewImageButton("<%= j new_image_link %>")
|
||||
|
||||
<% else %>
|
||||
|
||||
App.Imageable.replacePlainImage("plain_image_fields",
|
||||
"<%= j render('layouts/flash') %>",
|
||||
"<%= j render('plain_fields', image: @image) %>")
|
||||
|
||||
<% end %>
|
||||
26
app/views/images/new.html.erb
Normal file
26
app/views/images/new.html.erb
Normal file
@@ -0,0 +1,26 @@
|
||||
<div class="image-form <%= imageable_class(@image.imageable) %> row">
|
||||
|
||||
<div class="small-12 medium-9 column">
|
||||
<%= back_link_to params[:from] %>
|
||||
<h1><%= t("images.new.title") %></h1>
|
||||
<%= render "form", form_url: images_url %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-3 column">
|
||||
<span class="icon-images float-right"></span>
|
||||
<h2><%= t("images.recommendations_title") %></h2>
|
||||
<ul class="recommendations">
|
||||
<li>
|
||||
<%= t "images.recommendation_one_html" %>
|
||||
</li>
|
||||
<li>
|
||||
<%= t "images.recommendation_two_html",
|
||||
accepted_content_types: imageable_humanized_accepted_content_types %>
|
||||
</li>
|
||||
<li>
|
||||
<%= t "images.recommendation_three_html",
|
||||
max_file_size: imageable_max_file_size %>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
9
app/views/images/new_nested.js.erb
Normal file
9
app/views/images/new_nested.js.erb
Normal file
@@ -0,0 +1,9 @@
|
||||
<%
|
||||
new_image_link = link_to t("images.form.add_new_image"),
|
||||
new_nested_images_path(imageable_type: params[:imageable_type]),
|
||||
remote: true,
|
||||
id: "new_image_link",
|
||||
class: "button hollow"
|
||||
%>
|
||||
App.Imageable.new("<%= j render('images/nested_fields', image: @image) %>")
|
||||
App.Imageable.updateNewImageButton("<%= j new_image_link %>")
|
||||
12
app/views/images/upload.js.erb
Normal file
12
app/views/images/upload.js.erb
Normal file
@@ -0,0 +1,12 @@
|
||||
<% if params[:nested_image] == "true" %>
|
||||
|
||||
App.Imageable.uploadNestedImage("<%= image_nested_field_wrapper_id %>",
|
||||
"<%= j render('images/nested_fields', image: @image) %>",
|
||||
<%= @image.cached_attachment.present? %>)
|
||||
<% else %>
|
||||
|
||||
App.Imageable.uploadPlainImage("plain_image_fields",
|
||||
"<%= j render('images/plain_fields', image: @image) %>",
|
||||
<%= @image.cached_attachment.present? %>)
|
||||
|
||||
<% end %>
|
||||
@@ -46,6 +46,10 @@
|
||||
<%= f.text_field :external_url, placeholder: t("proposals.form.proposal_external_url"), label: false %>
|
||||
</div>
|
||||
|
||||
<div class="images small-12 column" data-max-images="1">
|
||||
<%= render 'images/nested_images', imageable: @proposal %>
|
||||
</div>
|
||||
|
||||
<div class="documents small-12 column" data-max-documents="<%= Proposal.max_documents_allowed %>">
|
||||
<%= render 'documents/nested_documents', documentable: @proposal %>
|
||||
</div>
|
||||
|
||||
@@ -48,6 +48,8 @@
|
||||
|
||||
</div>
|
||||
|
||||
<%= render_image(@proposal.image, :large, true) if @proposal.image.present? %>
|
||||
|
||||
<br>
|
||||
<p>
|
||||
<%= t("proposals.show.code") %>
|
||||
@@ -106,7 +108,8 @@
|
||||
</div>
|
||||
|
||||
<aside class="small-12 medium-3 column">
|
||||
<% if can_create_document?(@document, @proposal) || author_of_proposal?(@proposal) || current_editable?(@proposal) %>
|
||||
<% if can_create_document?(@document, @proposal) || author_of_proposal?(@proposal) || current_editable?(@proposal) ||
|
||||
can?(:create, @image) || (@proposal.image.present? && can?(:destroy, @proposal.image)) %>
|
||||
<div class="sidebar-divider"></div>
|
||||
<h2><%= t("proposals.show.author") %></h2>
|
||||
<div class="show-actions-menu">
|
||||
@@ -132,6 +135,22 @@
|
||||
<%= t("proposals.show.edit_proposal_link") %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if can?(:create, @image) %>
|
||||
<%= link_to new_image_path(imageable_id: @proposal, imageable_type: @proposal.class.name, from: request.url),
|
||||
class: 'button hollow float-right' do %>
|
||||
<%= t("images.upload_image") %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if @proposal.image.present? && can?(:destroy, @proposal.image) %>
|
||||
<%= link_to image_path(@proposal.image, from: request.url),
|
||||
method: :delete,
|
||||
class: 'button hollow float-right',
|
||||
data: { confirm: 'Are you sure?' } do %>
|
||||
<% t("images.remove_image") %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user