app/assets/javascripts/backbone/models/model.js.coffee
ff94bdbf
 class Xmpp.Models.Model extends Backbone.Model
   communicator: App.Com
 
   sync: (method, model, options) ->
     params = {}
 
     if (!options.event)
       params.event = model.namespace + '.' + method
 
     if (!options.data? && model && (method == 'create' || method == 'update' || method == 'patch'))
       params.data = JSON.stringify(options.attrs || model.toJSON(options))
     else
       params.data = JSON.stringify({})
 
     success = options.success;
     success = (resp) ->
       if (success)
         success(model, resp, options)
       model.trigger('sync', model, resp, options)
 
     error = options.error
     options.error = (xhr) ->
       if (error)
         error(model, xhr, options)
       model.trigger('error', model, xhr, options);
 
     if (! @communicator?)
       throw new Error('A communicator object must be specified');
 
     result = options.result = @communicator.fetch(_.extend(params, options))
 
     model.trigger('request', model, result, options)
     return result