Remove new_nested action from images controller. Use cocoon gem to manage new nested fields creation on images.
This commit is contained in:
@@ -6,8 +6,11 @@ App.Documentable =
|
||||
App.Documentable.initializeDirectUploadInput(input)
|
||||
|
||||
if $(nested_document).closest('#nested-documents').find('.document').length >= $('#nested-documents').data('max-documents-allowed')
|
||||
$('#max-documents-notice').removeClass('hide')
|
||||
$('#new_document_link').addClass('hide')
|
||||
App.Documentable.lockUploads()
|
||||
|
||||
inputFiles = $('.js-document-attachment')
|
||||
$.each inputFiles, (index, input) ->
|
||||
App.Documentable.initializeDirectUploadInput(input)
|
||||
|
||||
initializeDirectUploadInput: (input) ->
|
||||
|
||||
@@ -108,6 +111,14 @@ App.Documentable =
|
||||
errors = '<small class="error">' + data.jqXHR.responseJSON.errors + '</small>'
|
||||
$(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')
|
||||
|
||||
doDeleteCachedAttachmentRequest: (url, data) ->
|
||||
$.ajax
|
||||
type: "POST"
|
||||
@@ -122,8 +133,7 @@ App.Documentable =
|
||||
App.Documentable.clearInputErrors(data)
|
||||
App.Documentable.clearProgressBar(data)
|
||||
|
||||
$('#new_document_link').removeClass('hide')
|
||||
$('#max-documents-notice').addClass('hide')
|
||||
App.Documentable.unlockUploads()
|
||||
$(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')
|
||||
|
||||
@@ -136,8 +146,7 @@ App.Documentable =
|
||||
$(remove_document_link).on 'click', (e) ->
|
||||
e.preventDefault()
|
||||
$(wrapper).remove()
|
||||
$('#new_document_link').removeClass('hide')
|
||||
$('#max-documents-notice').addClass('hide')
|
||||
App.Documentable.unlockUploads()
|
||||
|
||||
initializeRemoveCachedDocumentLink: (input, data) ->
|
||||
wrapper = $(input).closest(".direct-upload")
|
||||
@@ -149,3 +158,5 @@ App.Documentable =
|
||||
|
||||
destroyNestedDocument: (id) ->
|
||||
$('#' + id).remove()
|
||||
if $('#nested-documents .document').length < $('#nested-documents').data('max-documents-allowed')
|
||||
App.Documentable.unlockUploads()
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
App.Imageable =
|
||||
|
||||
initialize: ->
|
||||
inputFiles = $('input.js-document-attachment[type=file]')
|
||||
$('#nested-image').on 'cocoon:after-insert', (e, nested_image) ->
|
||||
input = $(nested_image).find('.js-image-attachment')
|
||||
App.Imageable.initializeDirectUploadInput(input)
|
||||
|
||||
inputFiles = $('.js-image-attachment')
|
||||
$.each inputFiles, (index, input) ->
|
||||
App.Imageable.initializeDirectUploadInput(input)
|
||||
|
||||
$("#new_image_link").on 'click', -> $(this).hide()
|
||||
$("#new_image_link").on 'click', ->
|
||||
$(this).addClass('hide')
|
||||
|
||||
initializeDirectUploadInput: (input) ->
|
||||
|
||||
@@ -52,8 +56,8 @@ App.Imageable =
|
||||
$(data.addAttachmentLabel).hide()
|
||||
$(data.wrapper).find(".attachment-actions").removeClass('small-12').addClass('small-6 float-right')
|
||||
$(data.wrapper).find(".attachment-actions .action-remove").removeClass('small-3').addClass('small-12')
|
||||
|
||||
App.Imageable.setPreview(data)
|
||||
|
||||
destroyAttachmentLink = $(data.result.destroy_link)
|
||||
$(data.destroyAttachmentLinkContainer).html(destroyAttachmentLink)
|
||||
$(destroyAttachmentLink).on 'click', (e) ->
|
||||
@@ -80,8 +84,8 @@ App.Imageable =
|
||||
data.fileNameContainer = $(wrapper).find('p.file-name')
|
||||
data.destroyAttachmentLinkContainer = $(wrapper).find('.action-remove')
|
||||
data.addAttachmentLabel = $(wrapper).find('.action-add label')
|
||||
data.cachedAttachmentField = $(wrapper).find("#" + $(input).data('cached-attachment-input-field'))
|
||||
data.titleField = $(wrapper).find("#" + $(input).data('title-input-field'))
|
||||
data.cachedAttachmentField = $(wrapper).find("input[name$='[cached_attachment]']")
|
||||
data.titleField = $(wrapper).find("input[name$='[title]']")
|
||||
$(wrapper).find('.progress-bar-placeholder').css('display', 'block')
|
||||
return data
|
||||
|
||||
@@ -114,7 +118,6 @@ App.Imageable =
|
||||
$(data.errorContainer).append(errors)
|
||||
|
||||
setPreview: (data) ->
|
||||
console.log 'App.Imageable.setPreview'
|
||||
image_preview = '<div class="small-12 column text-center image-preview"><figure><img src="' + data.result.attachment_url + '" class="cached-image"/></figure></div>'
|
||||
if $(data.preview).length > 0
|
||||
$(data.preview).replaceWith(image_preview)
|
||||
@@ -122,13 +125,6 @@ App.Imageable =
|
||||
$(image_preview).insertBefore($(data.wrapper).find(".attachment-actions"))
|
||||
data.preview = $(data.wrapper).find('.image-preview')
|
||||
|
||||
watchRemoveImagebutton: (wrapper) ->
|
||||
remove_image_button = $(wrapper).find('a.delete[href="#"]')
|
||||
$(remove_image_button).on 'click', (e) ->
|
||||
e.preventDefault()
|
||||
$(wrapper).remove()
|
||||
$('#new_image_link').show()
|
||||
|
||||
doDeleteCachedAttachmentRequest: (url, data) ->
|
||||
$.ajax
|
||||
type: "POST"
|
||||
@@ -144,9 +140,10 @@ App.Imageable =
|
||||
App.Imageable.clearProgressBar(data)
|
||||
App.Imageable.clearPreview(data)
|
||||
|
||||
$('#new_image_link').removeClass('hide')
|
||||
|
||||
if $(data.input).data('nested-image') == true
|
||||
$(data.wrapper).remove()
|
||||
$('#new_image_link').show()
|
||||
else
|
||||
$(data.destroyAttachmentLinkContainer).find('a.delete').remove()
|
||||
|
||||
@@ -156,7 +153,7 @@ App.Imageable =
|
||||
$(remove_image_link).on 'click', (e) ->
|
||||
e.preventDefault()
|
||||
$(wrapper).remove()
|
||||
$('#new_image_link').show()
|
||||
$('#new_image_link').removeClass('hide')
|
||||
|
||||
initializeRemoveCachedImageLink: (input, data) ->
|
||||
wrapper = $(input).closest(".direct-upload")
|
||||
@@ -166,37 +163,6 @@ App.Imageable =
|
||||
e.stopPropagation()
|
||||
App.Imageable.doDeleteCachedAttachmentRequest(this.href, data)
|
||||
|
||||
new: (nested_field) ->
|
||||
nested_field = $(nested_field)
|
||||
$(".images-list").append(nested_field)
|
||||
input = nested_field.find("input[type='file']")
|
||||
@initializeDirectUploadInput(input)
|
||||
$("#new_image_link").hide()
|
||||
|
||||
destroyNestedImage: (id, notice) ->
|
||||
$('#' + id).remove()
|
||||
$("#new_image_link").show()
|
||||
@updateNotice(notice)
|
||||
|
||||
replacePlainImage: (id, notice, plain_image) ->
|
||||
$('#' + id).replaceWith(plain_image)
|
||||
@updateNotice(notice)
|
||||
@initialize()
|
||||
|
||||
updateNotice: (notice) ->
|
||||
if $('[data-alert]').length > 0
|
||||
$('[data-alert]').replaceWith(notice)
|
||||
else
|
||||
$("body").append(notice)
|
||||
|
||||
updateNewImageButton: (link) ->
|
||||
if $('.image').length >= $('.images').data('max-images')
|
||||
$('#new_image_link').hide()
|
||||
$('.max-images-notice').removeClass('hide')
|
||||
$('.max-images-notice').show()
|
||||
else if $('#new_image_link').length > 0
|
||||
$('#new_image_link').replaceWith(link)
|
||||
$('.max-images-notice').hide()
|
||||
else
|
||||
$('.max-images-notice').hide()
|
||||
$(link).insertBefore('.images hr:last')
|
||||
$("#new_image_link").removeClass('hide')
|
||||
|
||||
Reference in New Issue
Block a user