Skip to content

Instantly share code, notes, and snippets.

@joes1876
Created November 20, 2013 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joes1876/7564133 to your computer and use it in GitHub Desktop.
Save joes1876/7564133 to your computer and use it in GitHub Desktop.
$(document).ready ->
$('.chosen-select').chosen()
$('#import_form').fileupload
autoUpload: false
dataType: "json"
add: (e, data) ->
$form = $("#import_form")
files = $form.data("files") or {}
data.context = $(tmpl("template-upload", data.files[0]))
$form.append data.context
files[data.files[0].name] = data
$form.data "files", files
progress: (e, data) ->
if data.context
progress = parseInt(data.loaded / data.total * 100, 10)
data.context.find('.bar').css('width', progress + '%')
$("#import_button").on "click", ->
files = $('#import_form').data("files")
$.each files, (fileName, data) ->
data.submit()
$('#import_form').on("ajax:success", (e, data, status, xhr) ->
console.log("It works")
).bind("ajax:error", (e, xhr, status, error) ->
alert(error)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment