Add _destroy parameter to nested documents
This commit is contained in:
@@ -1,23 +1,25 @@
|
|||||||
App.Documentable =
|
App.Documentable =
|
||||||
|
|
||||||
initialize: ->
|
initialize: ->
|
||||||
$('#nested-documents').on 'cocoon:after-insert', (e, nested_document) ->
|
|
||||||
input = $(nested_document).find('.js-document-attachment')
|
|
||||||
App.Documentable.initializeDirectUploadInput(input)
|
|
||||||
|
|
||||||
if $(nested_document).closest('#nested-documents').find('.document').length >= $('#nested-documents').data('max-documents-allowed')
|
|
||||||
App.Documentable.lockUploads()
|
|
||||||
|
|
||||||
inputFiles = $('.js-document-attachment')
|
inputFiles = $('.js-document-attachment')
|
||||||
$.each inputFiles, (index, input) ->
|
$.each inputFiles, (index, input) ->
|
||||||
App.Documentable.initializeDirectUploadInput(input)
|
App.Documentable.initializeDirectUploadInput(input)
|
||||||
|
|
||||||
|
$('#nested-documents').on 'cocoon:after-remove', (e, insertedItem) ->
|
||||||
|
App.Documentable.unlockUploads()
|
||||||
|
|
||||||
|
$('#nested-documents').on 'cocoon:after-insert', (e, nested_document) ->
|
||||||
|
input = $(nested_document).find('.js-document-attachment')
|
||||||
|
App.Documentable.initializeDirectUploadInput(input)
|
||||||
|
|
||||||
|
if $(nested_document).closest('#nested-documents').find('.document:visible').length >= $('#nested-documents').data('max-documents-allowed')
|
||||||
|
App.Documentable.lockUploads()
|
||||||
|
|
||||||
initializeDirectUploadInput: (input) ->
|
initializeDirectUploadInput: (input) ->
|
||||||
|
|
||||||
inputData = @buildData([], input)
|
inputData = @buildData([], input)
|
||||||
|
|
||||||
@initializeRemoveDocumentLink(input)
|
|
||||||
|
|
||||||
@initializeRemoveCachedDocumentLink(input, inputData)
|
@initializeRemoveCachedDocumentLink(input, inputData)
|
||||||
|
|
||||||
$(input).fileupload
|
$(input).fileupload
|
||||||
@@ -139,14 +141,8 @@ App.Documentable =
|
|||||||
|
|
||||||
if $(data.input).data('nested-document') == true
|
if $(data.input).data('nested-document') == true
|
||||||
$(data.wrapper).remove()
|
$(data.wrapper).remove()
|
||||||
|
else
|
||||||
initializeRemoveDocumentLink: (input) ->
|
$(data.wrapper).find('a.remove-cached-attachment').remove()
|
||||||
wrapper = $(input).closest(".direct-upload")
|
|
||||||
remove_document_link = $(wrapper).find('a.remove-nested-field')
|
|
||||||
$(remove_document_link).on 'click', (e) ->
|
|
||||||
e.preventDefault()
|
|
||||||
$(wrapper).remove()
|
|
||||||
App.Documentable.unlockUploads()
|
|
||||||
|
|
||||||
initializeRemoveCachedDocumentLink: (input, data) ->
|
initializeRemoveCachedDocumentLink: (input, data) ->
|
||||||
wrapper = $(input).closest(".direct-upload")
|
wrapper = $(input).closest(".direct-upload")
|
||||||
@@ -156,7 +152,5 @@ App.Documentable =
|
|||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
App.Documentable.doDeleteCachedAttachmentRequest(this.href, data)
|
App.Documentable.doDeleteCachedAttachmentRequest(this.href, data)
|
||||||
|
|
||||||
destroyNestedDocument: (id) ->
|
removeDocument: (id) ->
|
||||||
$('#' + id).remove()
|
$('#' + id).remove()
|
||||||
if $('#nested-documents .document').length < $('#nested-documents').data('max-documents-allowed')
|
|
||||||
App.Documentable.unlockUploads()
|
|
||||||
|
|||||||
@@ -317,7 +317,8 @@
|
|||||||
.budget-investment-new,
|
.budget-investment-new,
|
||||||
.proposal-form,
|
.proposal-form,
|
||||||
.proposal-edit,
|
.proposal-edit,
|
||||||
.image-form {
|
.image-form,
|
||||||
|
.document-form {
|
||||||
@include upload-image-documents;
|
@include upload-image-documents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController
|
|||||||
|
|
||||||
def question_params
|
def question_params
|
||||||
params.require(:poll_question).permit(:poll_id, :title, :question, :description, :proposal_id, :valid_answers, :video_url,
|
params.require(:poll_question).permit(:poll_id, :title, :question, :description, :proposal_id, :valid_answers, :video_url,
|
||||||
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id])
|
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_params
|
def search_params
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ module Budgets
|
|||||||
.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],
|
||||||
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id])
|
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_ballot
|
def load_ballot
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class ProposalsController < ApplicationController
|
|||||||
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],
|
||||||
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id] )
|
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy] )
|
||||||
end
|
end
|
||||||
|
|
||||||
def retired_params
|
def retired_params
|
||||||
|
|||||||
@@ -21,15 +21,8 @@ module DocumentsHelper
|
|||||||
"document_#{index}"
|
"document_#{index}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_destroy_document_link(document)
|
def render_destroy_document_link(builder, document)
|
||||||
if document.persisted?
|
if !document.persisted? && document.cached_attachment.present?
|
||||||
link_to t('documents.form.delete_button'),
|
|
||||||
document_path(document, nested_document: true),
|
|
||||||
method: :delete,
|
|
||||||
remote: true,
|
|
||||||
data: { confirm: t('documents.actions.destroy.confirm') },
|
|
||||||
class: "delete remove-document"
|
|
||||||
elsif !document.persisted? && document.cached_attachment.present?
|
|
||||||
link_to t('documents.form.delete_button'),
|
link_to t('documents.form.delete_button'),
|
||||||
direct_upload_destroy_url("direct_upload[resource_type]": document.documentable_type,
|
direct_upload_destroy_url("direct_upload[resource_type]": document.documentable_type,
|
||||||
"direct_upload[resource_id]": document.documentable_id,
|
"direct_upload[resource_id]": document.documentable_id,
|
||||||
@@ -39,9 +32,7 @@ module DocumentsHelper
|
|||||||
remote: true,
|
remote: true,
|
||||||
class: "delete remove-cached-attachment"
|
class: "delete remove-cached-attachment"
|
||||||
else
|
else
|
||||||
link_to t('documents.form.delete_button'),
|
link_to_remove_association t('documents.form.delete_button'), builder, class: "delete remove-document"
|
||||||
"#",
|
|
||||||
class: "delete remove-nested-field"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,8 @@
|
|||||||
ckeditor: { language: I18n.locale } %>
|
ckeditor: { language: I18n.locale } %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="documents small-12" data-max-documents="<%= Poll::Question.max_documents_allowed %>">
|
<div class="documents small-12">
|
||||||
<%= render 'documents/nested_documents', documentable: @question %>
|
<%= render 'documents/nested_documents', documentable: @question, f: f %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-12">
|
<div class="small-12">
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<div id="<%= dom_id(f.object) %>" class="document direct-upload">
|
<div id="<%= dom_id(f.object) %>" class="document direct-upload document-fields 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 %>
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
<%= render_attachment(f, f.object) %>
|
<%= render_attachment(f, f.object) %>
|
||||||
</div>
|
</div>
|
||||||
<div class="small-3 column action-remove text-right">
|
<div class="small-3 column action-remove text-right">
|
||||||
<%= render_destroy_document_link(f.object) %>
|
<%= render_destroy_document_link(f, f.object) %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
documentable_id: @document.documentable_id,
|
documentable_id: @document.documentable_id,
|
||||||
from: params[:from]
|
from: params[:from]
|
||||||
),
|
),
|
||||||
html: { multipart: true, class: "documentable" } do |f| %>
|
html: { multipart: true, class: "documentable document-form" } do |f| %>
|
||||||
|
|
||||||
<%= render 'shared/errors', resource: @document %>
|
<%= render 'shared/errors', resource: @document %>
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
App.Documentable.destroyNestedDocument("<%= dom_id(@document) %>")
|
App.Documentable.removeDocument("<%= dom_id(@document) %>")
|
||||||
|
|||||||
Reference in New Issue
Block a user