Skip to content

Instantly share code, notes, and snippets.

@hysios
Created March 28, 2012 03:39
Show Gist options
  • Save hysios/2223378 to your computer and use it in GitHub Desktop.
Save hysios/2223378 to your computer and use it in GitHub Desktop.
wrapError = (onError, model, options) ->
(resp) ->
if onError?
onError(model, resp, options);
else
model.trigger('error', model, resp, options)
apply: (name = null, options = {}) ->
name ||= @get('name')
success = options.success
options.success = (resp, status, xhr) ->
if resp == true
success(model, resp, xhr) if success?
options.url = "#{@urlRoot}/select/#{name}"
options.error = wrapError(options.error, @, options)
method = 'update'
return (@sync || Backbone.sync).call(@, method, @, options)
apply: (name = null) ->
name ||= @get('name')
attributes = {
'name' : name
}
options = {
url: "#{@urlRoot}/select/#{order_id}" # => /themes/select
success: (resp) ->
@set(resp)
}
# { }
@save(attributes, options)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment