Fix edit and update actions
This commit is contained in:
@@ -30,7 +30,7 @@ App.Documentable =
|
|||||||
if result.status == 200
|
if result.status == 200
|
||||||
$(data.progressBar).find('.loading-bar').removeClass 'uploading'
|
$(data.progressBar).find('.loading-bar').removeClass 'uploading'
|
||||||
$(data.progressBar).find('.loading-bar').addClass 'complete'
|
$(data.progressBar).find('.loading-bar').addClass 'complete'
|
||||||
inputId = '#' + $(e.target).data('chached-attachment-input-field')
|
inputId = '#' + $(e.target).data('cached-attachment-input-field')
|
||||||
$(inputId).val result.attachment
|
$(inputId).val result.attachment
|
||||||
else
|
else
|
||||||
$(data.progressBar).find('.loading-bar').addClass 'errors'
|
$(data.progressBar).find('.loading-bar').addClass 'errors'
|
||||||
|
|||||||
@@ -55,11 +55,12 @@ module CommentableActions
|
|||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
prepare_edit_resource_documents(resource)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
resource.assign_attributes(strong_params)
|
resource.assign_attributes(strong_params)
|
||||||
resource = parse_documents(resource)
|
parse_documents(resource)
|
||||||
if resource.save
|
if resource.save
|
||||||
redirect_to resource, notice: t("flash.actions.update.#{resource_name.underscore}")
|
redirect_to resource, notice: t("flash.actions.update.#{resource_name.underscore}")
|
||||||
else
|
else
|
||||||
@@ -114,12 +115,20 @@ module CommentableActions
|
|||||||
|
|
||||||
def prepare_new_resource_documents
|
def prepare_new_resource_documents
|
||||||
if @resource.class == Proposal || @resource.class == Budget::Investment
|
if @resource.class == Proposal || @resource.class == Budget::Investment
|
||||||
(0..@resource.class.max_documents_allowed - 1).each do
|
(1..@resource.class.max_documents_allowed).each do
|
||||||
@resource.documents.build
|
@resource.documents.build
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def prepare_edit_resource_documents(resource)
|
||||||
|
if resource.class == Proposal || resource.class == Budget::Investment
|
||||||
|
(resource.documents.count + 1 .. resource.class.max_documents_allowed).each do
|
||||||
|
resource.documents.build
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def parse_documents(resource)
|
def parse_documents(resource)
|
||||||
resource.documents.each do |document|
|
resource.documents.each do |document|
|
||||||
document.user = current_user
|
document.user = current_user
|
||||||
@@ -127,7 +136,6 @@ module CommentableActions
|
|||||||
resource.documents = resource.documents.select{|document| document.valid? }.each do |document|
|
resource.documents = resource.documents.select{|document| document.valid? }.each do |document|
|
||||||
document.attachment = File.open(document.cached_attachment)
|
document.attachment = File.open(document.cached_attachment)
|
||||||
end
|
end
|
||||||
resource
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class ProposalsController < ApplicationController
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
@proposal = Proposal.new(proposal_params.merge(author: current_user))
|
@proposal = Proposal.new(proposal_params.merge(author: current_user))
|
||||||
@proposal = parse_documents(@proposal)
|
parse_documents(@proposal)
|
||||||
|
|
||||||
if @proposal.save
|
if @proposal.save
|
||||||
redirect_to share_proposal_path(@proposal), notice: I18n.t('flash.actions.create.proposal')
|
redirect_to share_proposal_path(@proposal), notice: I18n.t('flash.actions.create.proposal')
|
||||||
@@ -78,7 +78,7 @@ class ProposalsController < ApplicationController
|
|||||||
def proposal_params
|
def proposal_params
|
||||||
params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url,
|
params.require(:proposal).permit(:title, :question, :summary, :description, :external_url, :video_url,
|
||||||
:responsible_name, :tag_list, :terms_of_service, :geozone_id,
|
:responsible_name, :tag_list, :terms_of_service, :geozone_id,
|
||||||
documents_attributes: [:cached_attachment, :title] )
|
documents_attributes: [:id, :title, :attachment, :cached_attachment ] )
|
||||||
end
|
end
|
||||||
|
|
||||||
def retired_params
|
def retired_params
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class Proposal < ActiveRecord::Base
|
|||||||
documentable max_documents_allowed: 3,
|
documentable max_documents_allowed: 3,
|
||||||
max_file_size: 3.megabytes,
|
max_file_size: 3.megabytes,
|
||||||
accepted_content_types: [ "application/pdf" ]
|
accepted_content_types: [ "application/pdf" ]
|
||||||
accepts_nested_attributes_for :documents
|
accepts_nested_attributes_for :documents, allow_destroy: true
|
||||||
|
|
||||||
acts_as_votable
|
acts_as_votable
|
||||||
acts_as_paranoid column: :hidden_at
|
acts_as_paranoid column: :hidden_at
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
class: 'document_ajax_attachment show-for-sr',
|
class: 'document_ajax_attachment show-for-sr',
|
||||||
data: {
|
data: {
|
||||||
url: upload_documents_url(documentable_type: @document.documentable_type, documentable_id: @document.documentable_id),
|
url: upload_documents_url(documentable_type: @document.documentable_type, documentable_id: @document.documentable_id),
|
||||||
chached_attachment_input_field: "document_cached_attachment",
|
cached_attachment_input_field: "document_cached_attachment",
|
||||||
multiple: false
|
multiple: false
|
||||||
} %>
|
} %>
|
||||||
<%= f.label :attachment, t("documents.form.attachment_label"), class: 'button hollow' %>
|
<%= f.label :attachment, t("documents.form.attachment_label"), class: 'button hollow' %>
|
||||||
|
|||||||
@@ -64,7 +64,7 @@
|
|||||||
documentable_type: document_fields.object.documentable_type,
|
documentable_type: document_fields.object.documentable_type,
|
||||||
documentable_id: document_fields.object.documentable_id
|
documentable_id: document_fields.object.documentable_id
|
||||||
),
|
),
|
||||||
chached_attachment_input_field: "proposal_documents_attributes_#{index}_cached_attachment",
|
cached_attachment_input_field: "proposal_documents_attributes_#{index}_cached_attachment",
|
||||||
multiple: false
|
multiple: false
|
||||||
} %>
|
} %>
|
||||||
<%= document_fields.label :attachment, t("documents.form.attachment_label"), class: 'button hollow' %>
|
<%= document_fields.label :attachment, t("documents.form.attachment_label"), class: 'button hollow' %>
|
||||||
|
|||||||
Reference in New Issue
Block a user