Sha256: 478dfe5d666f6c097745d4f54b0886194d3800237050bea66f23862c74d07b01
Contents?: true
Size: 1.41 KB
Versions: 15
Compression:
Stored size: 1.41 KB
Contents
class ManagedRequest defaults: type: "GET" url: "" name: "managedRequest" parseResponse: (jqXHR) -> obj = {} obj.responseText = jqXHR.responseText obj.responseStatus = jqXHR.status try obj.data= JSON.parse( jqXHR.responseText ) catch error obj.data= {} obj constructor: ( options ) -> @options = _.extend {}, @defaults, @options, options @requester = Backbone.ajax #@requester = window.app.ajax @requester = @options.ajax if @options.ajax @trigger = () -> debug "NO TRIGGER" if @options.context and @options.context.trigger @trigger = @options.context.trigger @trigger = _.bind(@options.context.trigger,@options.context) _.bindAll @ execute: -> @requester type: @options.type url: @options.url data: @options.data success: @success error: @error complete: @complete dataType: "json" contentType: "application/json" processData: false success: (data, textStatus, jqXHR) -> if data.errors @trigger "#{@options.name}:fail", @parseResponse( jqXHR ) else @trigger "#{@options.name}:done", @parseResponse( jqXHR ) error: (jqXHR, textStatus, errorThrown) -> @trigger "#{@options.name}:fail", @parseResponse( jqXHR ) complete: (jqXHR, textStatus, errorThrown) -> @trigger "#{@options.name}:all", @parseResponse( jqXHR ) @ManagedRequest = ManagedRequest
Version data entries
15 entries across 15 versions & 1 rubygems