#App.ApplicationAdapter = DS.ActiveModelAdapter.extend
#  namespace: 'supplier'
#  headers:
#    "Accept": "application/json, text/javascript; q=0.01"
App.ApplicationAdapter = DS.JSONAPIAdapter.extend
  namespace: 'waiter'
  pathForType: (type)->
    type.underscore().pluralize()
  # Code for createRecord and updateRecord taken from ember data v2.0.0 restadapter
  createRecord: (store, type, snapshot)->
    data = {}
    #var serializer = store.serializerFor(type.modelName);
    serializer = Ember.get(snapshot.record, 'store').serializerFor('creation')
    url = @buildURL(type.modelName, null, snapshot, 'createRecord')

    serializer.serializeIntoHash data, type, snapshot, includeId: true

    @ajax url, "POST", data: data

  updateRecord: (store, type, snapshot)->
    data = {}
    #var serializer = store.serializerFor(type.modelName);
    serializer = Ember.get(snapshot.record, 'store').serializerFor('creation')
    id = snapshot.id
    url = @buildURL(type.modelName, id, snapshot, 'updateRecord')
    serializer.serializeIntoHash data, type, snapshot, includeId: true
    @ajax url, "PUT", data: data
