Skip to content

Commit

Permalink
reinitialize fileupload after validation failed
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamfall committed Apr 24, 2015
1 parent 28f8c6c commit c70fe62
Showing 1 changed file with 34 additions and 31 deletions.
65 changes: 34 additions & 31 deletions app/assets/javascripts/admin/form_answers.js.coffee
Expand Up @@ -63,37 +63,40 @@ ready = ->
errors += error

form.find(".errors-holder").text(errors)
$("#new_form_answer_attachment").fileupload
autoUpload: false
dataType: "html"
forceIframeTransport: true
formData: [
{ name: "authenticity_token", value: $("meta[name='csrf-token']").attr("content")},
{ name: "format", value: "js" }
]
add: (e, data) ->
$(".attachment-title").val(data.files[0].name)
$("#new_form_answer_attachment").closest(".sidebar-section").addClass("show-attachment-form")
$("#new_form_answer_attachment .btn-submit").focus().blur()
$("#new_form_answer_attachment .btn-submit").unbind("click").on "click", (e) ->
e.preventDefault()
data.submit()
success: (result, textStatus, jqXHR) ->
result = $($.parseHTML(result))
$("#attachment-buffer").append(result.text())

if $("#form-answer-attachment-valid", $("#attachment-buffer")).length
$("#application-attachment-form").html(result.text())
moveAttachDocumentButton()
else
$(".document-list .p-empty").addClass("visuallyhidden")
$(".document-list ul").append(result.text())
form = $("#new_form_answer_attachment")
form.closest(".sidebar-section").removeClass("show-attachment-form")
$("#form_answer_attachment_title").val(null)
$("#form_answer_attachment_restricted_to_admin").prop("checked", false)

$("#attachment-buffer").empty()

do initializeFileUpload = ->
$("#new_form_answer_attachment").fileupload
autoUpload: false
dataType: "html"
forceIframeTransport: true
formData: [
{ name: "authenticity_token", value: $("meta[name='csrf-token']").attr("content")},
{ name: "format", value: "js" }
]
add: (e, data) ->
$(".attachment-title").val(data.files[0].name)
$("#new_form_answer_attachment").closest(".sidebar-section").addClass("show-attachment-form")
$("#new_form_answer_attachment .btn-submit").focus().blur()
$("#new_form_answer_attachment .btn-submit").unbind("click").on "click", (e) ->
e.preventDefault()
data.submit()
success: (result, textStatus, jqXHR) ->
result = $($.parseHTML(result))
$("#attachment-buffer").append(result.text())

if $("#form-answer-attachment-valid", $("#attachment-buffer")).length
$("#application-attachment-form").html(result.text())
moveAttachDocumentButton()
initializeFileUpload()
else
$(".document-list .p-empty").addClass("visuallyhidden")
$(".document-list ul").append(result.text())
form = $("#new_form_answer_attachment")
form.closest(".sidebar-section").removeClass("show-attachment-form")
$("#form_answer_attachment_title").val(null)
$("#form_answer_attachment_restricted_to_admin").prop("checked", false)

$("#attachment-buffer").empty()

moveAttachDocumentButton()

Expand Down

0 comments on commit c70fe62

Please sign in to comment.