Add _destroy parameter to nested image
This commit is contained in:
@@ -1,23 +1,22 @@
|
|||||||
App.Imageable =
|
App.Imageable =
|
||||||
|
|
||||||
initialize: ->
|
initialize: ->
|
||||||
$('#nested-image').on 'cocoon:after-insert', (e, nested_image) ->
|
|
||||||
input = $(nested_image).find('.js-image-attachment')
|
|
||||||
App.Imageable.initializeDirectUploadInput(input)
|
|
||||||
|
|
||||||
inputFiles = $('.js-image-attachment')
|
inputFiles = $('.js-image-attachment')
|
||||||
$.each inputFiles, (index, input) ->
|
$.each inputFiles, (index, input) ->
|
||||||
App.Imageable.initializeDirectUploadInput(input)
|
App.Imageable.initializeDirectUploadInput(input)
|
||||||
|
|
||||||
$("#new_image_link").on 'click', ->
|
$('#nested-image').on 'cocoon:after-remove', (e, item) ->
|
||||||
$(this).addClass('hide')
|
$("#new_image_link").removeClass('hide')
|
||||||
|
|
||||||
|
$('#nested-image').on 'cocoon:after-insert', (e, nested_image) ->
|
||||||
|
$("#new_image_link").addClass('hide')
|
||||||
|
input = $(nested_image).find('.js-image-attachment')
|
||||||
|
App.Imageable.initializeDirectUploadInput(input)
|
||||||
|
|
||||||
initializeDirectUploadInput: (input) ->
|
initializeDirectUploadInput: (input) ->
|
||||||
|
|
||||||
inputData = @buildData([], input)
|
inputData = @buildData([], input)
|
||||||
|
|
||||||
@initializeRemoveImageLink(input)
|
|
||||||
|
|
||||||
@initializeRemoveCachedImageLink(input, inputData)
|
@initializeRemoveCachedImageLink(input, inputData)
|
||||||
|
|
||||||
$(input).fileupload
|
$(input).fileupload
|
||||||
@@ -142,18 +141,13 @@ App.Imageable =
|
|||||||
|
|
||||||
$('#new_image_link').removeClass('hide')
|
$('#new_image_link').removeClass('hide')
|
||||||
|
|
||||||
|
$(data.wrapper).find(".attachment-actions").addClass('small-12').removeClass('small-6 float-right')
|
||||||
|
$(data.wrapper).find(".attachment-actions .action-remove").addClass('small-3').removeClass('small-12')
|
||||||
|
|
||||||
if $(data.input).data('nested-image') == true
|
if $(data.input).data('nested-image') == true
|
||||||
$(data.wrapper).remove()
|
$(data.wrapper).remove()
|
||||||
else
|
else
|
||||||
$(data.destroyAttachmentLinkContainer).find('a.delete').remove()
|
$(data.wrapper).find('a.remove-cached-attachment').remove()
|
||||||
|
|
||||||
initializeRemoveImageLink: (input) ->
|
|
||||||
wrapper = $(input).closest(".direct-upload")
|
|
||||||
remove_image_link = $(wrapper).find('a.remove-nested-field')
|
|
||||||
$(remove_image_link).on 'click', (e) ->
|
|
||||||
e.preventDefault()
|
|
||||||
$(wrapper).remove()
|
|
||||||
$('#new_image_link').removeClass('hide')
|
|
||||||
|
|
||||||
initializeRemoveCachedImageLink: (input, data) ->
|
initializeRemoveCachedImageLink: (input, data) ->
|
||||||
wrapper = $(input).closest(".direct-upload")
|
wrapper = $(input).closest(".direct-upload")
|
||||||
@@ -163,6 +157,6 @@ App.Imageable =
|
|||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
App.Imageable.doDeleteCachedAttachmentRequest(this.href, data)
|
App.Imageable.doDeleteCachedAttachmentRequest(this.href, data)
|
||||||
|
|
||||||
destroyNestedImage: (id, notice) ->
|
removeImage: (id) ->
|
||||||
$('#' + id).remove()
|
$('#' + id).remove()
|
||||||
$("#new_image_link").removeClass('hide')
|
$("#new_image_link").removeClass('hide')
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ module Budgets
|
|||||||
params.require(:budget_investment)
|
params.require(:budget_investment)
|
||||||
.permit(:title, :description, :external_url, :heading_id, :tag_list,
|
.permit(:title, :description, :external_url, :heading_id, :tag_list,
|
||||||
:organization_name, :location, :terms_of_service,
|
:organization_name, :location, :terms_of_service,
|
||||||
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id],
|
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
|
||||||
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
|
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,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,
|
||||||
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id],
|
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
|
||||||
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy] )
|
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy] )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -35,15 +35,8 @@ module ImagesHelper
|
|||||||
image.persisted? ? "persisted-image" : "cached-image"
|
image.persisted? ? "persisted-image" : "cached-image"
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_destroy_image_link(image)
|
def render_destroy_image_link(builder, image)
|
||||||
if image.persisted?
|
if !image.persisted? && image.cached_attachment.present?
|
||||||
link_to t('images.form.delete_button'),
|
|
||||||
image_path(image, nested_image: true),
|
|
||||||
method: :delete,
|
|
||||||
remote: true,
|
|
||||||
data: { confirm: t('images.actions.destroy.confirm') },
|
|
||||||
class: "delete remove-image"
|
|
||||||
elsif !image.persisted? && image.cached_attachment.present?
|
|
||||||
link_to t('images.form.delete_button'),
|
link_to t('images.form.delete_button'),
|
||||||
direct_upload_destroy_url("direct_upload[resource_type]": image.imageable_type,
|
direct_upload_destroy_url("direct_upload[resource_type]": image.imageable_type,
|
||||||
"direct_upload[resource_id]": image.imageable_id,
|
"direct_upload[resource_id]": image.imageable_id,
|
||||||
@@ -53,9 +46,7 @@ module ImagesHelper
|
|||||||
remote: true,
|
remote: true,
|
||||||
class: "delete remove-cached-attachment"
|
class: "delete remove-cached-attachment"
|
||||||
else
|
else
|
||||||
link_to t('images.form.delete_button'),
|
link_to_remove_association t('images.form.delete_button'), builder, class: "delete remove-image"
|
||||||
"#",
|
|
||||||
class: "delete remove-nested-field"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
<div id="<%= dom_id(f.object) %>" class="image direct-upload">
|
<div id="<%= dom_id(f.object) %>" class="image direct-upload nested-fields">
|
||||||
<%= f.hidden_field :id %>
|
<%= f.hidden_field :id %>
|
||||||
<%= f.hidden_field :user_id, value: current_user.id %>
|
<%= f.hidden_field :user_id, value: current_user.id %>
|
||||||
<%= f.hidden_field :cached_attachment %>
|
<%= f.hidden_field :cached_attachment %>
|
||||||
|
<%= f.hidden_field :_destroy %>
|
||||||
|
|
||||||
<div class="small-12 column title">
|
<div class="small-12 column title">
|
||||||
<%= f.text_field :title, placeholder: t("images.new.form.title_placeholder") %>
|
<%= f.text_field :title, placeholder: t("images.new.form.title_placeholder") %>
|
||||||
@@ -14,7 +15,7 @@
|
|||||||
<%= render_image_attachment(f, imageable, f.object) %>
|
<%= render_image_attachment(f, imageable, f.object) %>
|
||||||
</div>
|
</div>
|
||||||
<div class="small-3 column action-remove text-right">
|
<div class="small-3 column action-remove text-right">
|
||||||
<%= render_destroy_image_link(f.object) %>
|
<%= render_destroy_image_link(f, f.object) %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
App.Imageable.destroyNestedImage("<%= dom_id(@image) %>")
|
App.Imageable.removeImage("<%= dom_id(@image) %>")
|
||||||
Reference in New Issue
Block a user