Sha256: 5eed0d97428f16061fac53aefe15617bd66a7dd3b10bb814adf9c163caa7a207

Contents?: true

Size: 924 Bytes

Versions: 43

Compression:

Stored size: 924 Bytes

Contents

$ = require 'jquery'

module.exports =
  # TODO render route in the object itself with getter, and normalize this methods
  get   : (data) -> request.call @, 'get'   , (if @_id then  "#{@route}/#{@_id}" else @route), data
  put   : (data) -> request.call @, 'put'   , (if @_id then  "#{@route}/#{@_id}" else @route), data # TODO change from put to patch
  post  : (data) -> request.call @, 'post'  , @route, data
  delete: (data) -> request.call @, 'delete', (if @_id then  "#{@route}/#{@_id}" else @route), data

request = (method, url, data) ->
  param_name = @resource.param_name || @resource.toString()

  # TODO optmize this serialization lookup
  if not data and @json
   data = {}
   data[param_name] = @json()

  if data and data[param_name]
    delete data[param_name]['id']
    delete data[param_name]['_id']


  $.ajax
    url     : url
    data    : data
    type    : method
    dataType: 'json'
    context : @

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
ende-0.5.1 components/indefinido/indemma/master/src/lib/record/rest.coffee
ende-0.4.17 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.16 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.3.13 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.3.12 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.3.11 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.15 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.14 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.13 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.10 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.9 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.8 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.7 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.6 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.5 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.4 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.3 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.2 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.1 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.0 vendor/components/indefinido-indemma/src/lib/record/rest.coffee