Sha256: 7415236b4381ade472cc5a2d19a7fe6c3bcebbf005b1e8380c378ccbd06a4682

Contents?: true

Size: 883 Bytes

Versions: 4

Compression:

Stored size: 883 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', @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

4 entries across 4 versions & 1 rubygems

Version Path
ende-0.2.3 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.2.2 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.2.1 vendor/components/indefinido-indemma/src/lib/record/rest.coffee
ende-0.2.0 vendor/components/indefinido-indemma/src/lib/record/rest.coffee