Sha256: 1ab1cc7fdcbe72e8b03e9d4209bc230fcfaeecf0160081017c8d22c037ca31a1
Contents?: true
Size: 1.59 KB
Versions: 42
Compression:
Stored size: 1.59 KB
Contents
# This class handles rails' remote form 'ajax:aborted:file' event to serialize # forms with files and send them through ajax using the `FormData` HTML5 # feature. # # The general approach and request implementation respects the same lifecycle # of original rails' remote form requests, to allow existing handling code # to run without any modification. # class @RemoteFileForm extends Vertebra.View @supported = FormData isnt undefined initialize: (options = {}) -> @submitForm() if $.rails.fire(@$el, 'ajax:before') submitForm: -> formData = new FormData(@$el[0]) url = @$el.attr('action') method = @$el.attr('method') Para.ajax url: url method: method data: formData cache: false contentType: false processData: false xhr: @buildXHR beforeSend: @beforeSend success: @success complete: @complete error: @error crossDomain: $.rails.isCrossDomain?(url) buildXHR: => xhr = $.ajaxSettings.xhr() $(xhr.upload).on('progress', @progress) if xhr.upload xhr beforeSend: (xhr, settings) => if $.rails.fire(@$el, 'ajax:beforeSend', [xhr, settings]) @$el.trigger('ajax:send', xhr) else return false success: (data, status, xhr) => @$el.trigger('ajax:success', [data, status, xhr]) complete: (xhr, status) => @$el.trigger('ajax:complete', [xhr, status]) error: (xhr, status, error) => @$el.trigger('ajax:error', [xhr, status, error]) progress: (e) => @trigger('progress', e) $(document).on 'ajax:aborted:file', (e) -> new RemoteFileForm(el: e.target) return false
Version data entries
42 entries across 42 versions & 1 rubygems