Sha256: a88f5439058f2b4b634f6e47fd3d26c326f164a3161d9bdab923004d4383822f

Contents?: true

Size: 1022 Bytes

Versions: 12

Compression:

Stored size: 1022 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


# TODO move to serialization module
data_for = (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']

  data

request  = (method, url, data) ->
  data = data_for.call @, data

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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ende-0.5.22 components/indefinido/indemma/master/src/lib/record/rest.coffee
ende-0.5.21 components/indefinido/indemma/master/src/lib/record/rest.coffee
ende-0.4.25 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.24 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.23 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.22 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.21 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.5.0 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.20 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.19 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.18 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.4.12 vendor/components/indefinido-indemma/src/lib/record/rest.coffee