Some fixes and refactor
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
}
|
||||
|
||||
|
||||
@mixin upload-image-documents {
|
||||
@mixin direct-uploads {
|
||||
|
||||
.cached-image {
|
||||
max-width: 150px;
|
||||
|
||||
@@ -321,7 +321,7 @@
|
||||
.document-form,
|
||||
.new_poll_question,
|
||||
.edit_poll_question {
|
||||
@include upload-image-documents;
|
||||
@include direct-uploads;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
module DocumentablesHelper
|
||||
|
||||
def can_create_document?(documentable)
|
||||
can?(:create, Document.new(documentable: documentable)) && documentable.documents.size < documentable.class.max_documents_allowed
|
||||
end
|
||||
|
||||
def documentable_class(documentable)
|
||||
documentable.class.name.parameterize('_')
|
||||
end
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
module ImageablesHelper
|
||||
|
||||
def can_create_image?(imageable)
|
||||
can?(:create, Image.new(imageable: imageable))
|
||||
end
|
||||
|
||||
def can_destroy_image?(imageable)
|
||||
imageable.image.present? && can?(:destroy, imageable.image)
|
||||
end
|
||||
|
||||
def imageable_class(imageable)
|
||||
imageable.class.name.parameterize('_')
|
||||
end
|
||||
|
||||
@@ -32,14 +32,6 @@ module ProposalsHelper
|
||||
Proposal::RETIRE_OPTIONS.collect { |option| [ t("proposals.retire_options.#{option}"), option ] }
|
||||
end
|
||||
|
||||
def can_create_document?(document, proposal)
|
||||
can?(:create, document) && proposal.documents.size < Proposal.max_documents_allowed
|
||||
end
|
||||
|
||||
def can_destroy_image?(image, proposal)
|
||||
proposal.image.present? && can?(:destroy, image)
|
||||
end
|
||||
|
||||
def author_of_proposal?(proposal)
|
||||
author_of?(proposal, current_user)
|
||||
end
|
||||
|
||||
@@ -4,21 +4,21 @@
|
||||
<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 %>
|
||||
<% if can_create_document?(investment) %>
|
||||
<%= 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 %>
|
||||
|
||||
<% if can?(:create, @image) %>
|
||||
<% if can_create_image?(investment) %>
|
||||
<%= 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) %>
|
||||
<% if can_destroy_image?(investment) %>
|
||||
<%= link_to t("images.remove_image"),
|
||||
image_path(@investment.image, from: request.url),
|
||||
image_path(investment.image, from: request.url),
|
||||
method: :delete,
|
||||
class: 'button hollow float-right' %>
|
||||
<% end %>
|
||||
|
||||
@@ -108,12 +108,12 @@
|
||||
</div>
|
||||
|
||||
<aside class="small-12 medium-3 column">
|
||||
<% if can_create_document?(@document, @proposal) || author_of_proposal?(@proposal) || current_editable?(@proposal) ||
|
||||
can?(:create, @image) || can_destroy_image?(@proposal.image, @proposal) %>
|
||||
<% if can_create_document?(@proposal) || author_of_proposal?(@proposal) || current_editable?(@proposal) ||
|
||||
can_create_image?(@proposal) || can_destroy_image?(@proposal) %>
|
||||
<div class="sidebar-divider"></div>
|
||||
<h2><%= t("proposals.show.author") %></h2>
|
||||
<div class="show-actions-menu">
|
||||
<% if can_create_document?(@document, @proposal) %>
|
||||
<% if can_create_document?(@proposal) %>
|
||||
<%= link_to new_document_path(documentable_id: @proposal, documentable_type: @proposal.class.name, from: request.url),
|
||||
class: 'button hollow expanded' do %>
|
||||
<span class="icon-document"></span>
|
||||
@@ -129,7 +129,7 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if can?(:create, @image) %>
|
||||
<% if can_create_image?(@proposal) %>
|
||||
<%= link_to new_image_path(imageable_id: @proposal, imageable_type: @proposal.class.name, from: request.url),
|
||||
class: 'button hollow expanded' do %>
|
||||
<span class="icon-document"></span>
|
||||
@@ -137,7 +137,7 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if can_destroy_image?(@proposal.image, @proposal) %>
|
||||
<% if can_destroy_image?(@proposal) %>
|
||||
<%= link_to image_path(@proposal.image, from: request.url),
|
||||
method: :delete,
|
||||
class: 'button hollow expanded',
|
||||
|
||||
Reference in New Issue
Block a user