Sha256: c8e14572752640d1c7c07d5c8c74ab5abcc85b7ccb226edf5fd5fa3afc80db2f

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

Backbone.sync = (method, model, options) ->
  type = methodMap[method]
  params =
    type: type
    dataType: "json"

  params.url = getUrl(model) or urlError()  unless options.url

  if not options.data and model and (method is 'create' or method is 'update')
    extra              = options.extra
    data               = model.toJSON()
    data               = _.extend data, extra  unless extra is undefined
    params.contentType = "application/json"
    params.data        = JSON.stringify data

  if method is 'delete'
    param              = $("meta[name= 'csrf-param']").attr 'content'
    token              = $("meta[name= 'csrf-token']").attr 'content'
    data               = authenticity_token: token
    params.contentType = 'application/json'
    params.data        = JSON.stringify data

  emulate_json = Backbone.emulateJSON
  if emulate_json
    params.contentType = 'application/x-www-form-urlencoded'
    params.data        = if params.data then model: params.data else {}

  if Backbone.emulateHTTP
    if type is 'PUT' or type is 'DELETE'
      params.data._method = type  if emulate_json
      params.type         = 'POST'
      params.beforeSend   = (xhr) -> xhr.setRequestHeader "X-HTTP-Method-Override", type

  if params.type isnt 'GET' and not emulate_json
    params.processData = false

  params = _.extend params, options
  $.ajax params

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
laces-0.1.0 templates/app/assets/javascripts/lib/backbone/sync.coffee