diff --git a/app/assets/javascripts/documentable.js.coffee b/app/assets/javascripts/documentable.js.coffee
index 7cc71f39d..a61458150 100644
--- a/app/assets/javascripts/documentable.js.coffee
+++ b/app/assets/javascripts/documentable.js.coffee
@@ -11,10 +11,9 @@ App.Documentable =
$('#nested-documents').on 'cocoon:after-insert', (e, nested_document) ->
input = $(nested_document).find('.js-document-attachment')
+ input["lockUpload"] = $(nested_document).closest('#nested-documents').find('.document:visible').length >= $('#nested-documents').data('max-documents-allowed')
App.Documentable.initializeDirectUploadInput(input)
-
- if $(nested_document).closest('#nested-documents').find('.document:visible').length >= $('#nested-documents').data('max-documents-allowed')
- App.Documentable.lockUploads()
+ App.Documentable.lockUploads() if input["lockUpload"]
initializeDirectUploadInput: (input) ->
@@ -65,6 +64,9 @@ App.Documentable =
e.stopPropagation()
App.Documentable.doDeleteCachedAttachmentRequest(this.href, data)
+ App.Documentable.showNotice() if input["lockUpload"]
+
+
progress: (e, data) ->
progress = parseInt(data.loaded / data.total * 100, 10)
$(data.progressBar).find('.loading-bar').css 'width', progress + '%'
@@ -114,13 +116,15 @@ App.Documentable =
$(data.errorContainer).append(errors)
lockUploads: ->
- $('#max-documents-notice').removeClass('hide')
$('#new_document_link').addClass('hide')
unlockUploads: ->
$('#max-documents-notice').addClass('hide')
$('#new_document_link').removeClass('hide')
+ showNotice: ->
+ $('#max-documents-notice').removeClass('hide')
+
doDeleteCachedAttachmentRequest: (url, data) ->
$.ajax
type: "POST"
diff --git a/app/helpers/documents_helper.rb b/app/helpers/documents_helper.rb
index cbc94c9bb..4766de0aa 100644
--- a/app/helpers/documents_helper.rb
+++ b/app/helpers/documents_helper.rb
@@ -27,7 +27,7 @@ module DocumentsHelper
remote: true,
class: "delete remove-cached-attachment"
else
- link_to_remove_association t('documents.form.delete_button'), builder, class: "delete remove-document"
+ link_to_remove_association document.new_record? ? t('documents.form.cancel_button') : t('documents.form.delete_button') , builder, class: "delete remove-document"
end
end
diff --git a/app/views/documents/_nested_documents.html.erb b/app/views/documents/_nested_documents.html.erb
index 04fd4e8a2..a72cbe270 100644
--- a/app/views/documents/_nested_documents.html.erb
+++ b/app/views/documents/_nested_documents.html.erb
@@ -17,7 +17,7 @@
association_insertion_method: "append"
} %>
-
">
+
">
<%= t "documents.max_documents_allowed_reached_html" %>
diff --git a/config/locales/en/documents.yml b/config/locales/en/documents.yml
index 4cd868d40..12e839941 100644
--- a/config/locales/en/documents.yml
+++ b/config/locales/en/documents.yml
@@ -7,6 +7,7 @@ en:
title_placeholder: Add a descriptive title for the document
attachment_label: Choose document
delete_button: Remove document
+ cancel_button: Cancelar
note: "You can upload up to a maximum of %{max_documents_allowed} documents of following content types: %{accepted_content_types}, up to %{max_file_size} MB per file."
add_new_document: Add new document
actions:
diff --git a/config/locales/es/documents.yml b/config/locales/es/documents.yml
index 3e2c0e3bd..cb588e2a4 100644
--- a/config/locales/es/documents.yml
+++ b/config/locales/es/documents.yml
@@ -7,6 +7,7 @@ es:
title_placeholder: Añade un título descriptivo para el documento
attachment_label: Selecciona un documento
delete_button: Eliminar documento
+ cancel_button: Cancelar
note: 'Puedes subir hasta un máximo de %{max_documents_allowed} documentos en los formatos: %{accepted_content_types}, y de hasta %{max_file_size} MB por archivo.'
add_new_document: Añadir nuevo documento
actions:
diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb
index f11068b65..53212032e 100644
--- a/spec/controllers/application_controller_spec.rb
+++ b/spec/controllers/application_controller_spec.rb
@@ -16,4 +16,4 @@ describe ApplicationController do
end
-end
\ No newline at end of file
+end
diff --git a/spec/shared/features/nested_documentable.rb b/spec/shared/features/nested_documentable.rb
index 14c4a9e0f..2f6906ea1 100644
--- a/spec/shared/features/nested_documentable.rb
+++ b/spec/shared/features/nested_documentable.rb
@@ -51,12 +51,12 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should show max documents warning when max documents allowed limit is reached", :js do
login_as user_to_login
visit send(path, arguments)
-
documentable.class.max_documents_allowed.times.each do
- click_link "Add new document"
+ documentable_attach_new_file("spec/fixtures/files/empty.pdf")
end
expect(page).to have_css ".max-documents-notice", visible: true
+ expect(page).to have_content 'Remove document'
end
scenario "Should hide max documents warning after any document removal", :js do
@@ -67,7 +67,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
click_link "Add new document"
end
- all("a", text: "Remove document").last.click
+ all("a", text: "Cancel").last.click
expect(page).to have_css ".max-documents-notice", visible: false
end