Created
October 31, 2012 21:51
-
-
Save jcuffe/3990158 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define([ | |
| 'jquery', 'underscore', 'backbone', | |
| 'models/passenger/model' | |
| ], function ($, _, Backbone, Passenger) { | |
| Passengers = Backbone.Collection.extend({ | |
| model: Passenger | |
| }); | |
| return Passengers; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define([ | |
| 'jquery', 'underscore', 'backbone', | |
| 'collections/endpoints/collection', | |
| 'models/passenger/defaults', | |
| 'templates/ride/new' | |
| ], function ($, _, Backbone, Endpoints, defaults, rideNew) { | |
| Passenger = Backbone.Model.extend({ | |
| defaults: defaults, | |
| initialize: function (endpoints) { | |
| $.ajaxSetup({ | |
| accept: 'application/json', | |
| contentType: 'application/json', | |
| dataType: 'json', | |
| error: function (xhr, status, err) { | |
| console.log(err); | |
| } | |
| }); | |
| this.set('endpoints', new Endpoints()); | |
| self = this; | |
| this.login = _.wrap(this.login, function (func) { | |
| var now = (new Date()).getTime(); | |
| func(self); | |
| console.log(((new Date()).getTime() - now) / 1000); | |
| }); | |
| }, | |
| login: function (self) { | |
| endpoint = self.get('endpoints').get('login'); | |
| $.ajax({ | |
| url: endpoint.url(), | |
| type: endpoint.method(), | |
| data: JSON.stringify({ | |
| email: self.get('email'), | |
| password: self.get('password') | |
| }), | |
| success: function(data, status, xhr) { | |
| self.set('token', data.auth_token); | |
| console.log(self.get('token')); | |
| } | |
| }); | |
| }, | |
| createRide: function () { | |
| var self = this; | |
| endpoint = self.get('endpoints').get('createRide'); | |
| console.log(JSON.stringify(self.format(rideNew))); | |
| $.ajax({ | |
| url: endpoint.url(), | |
| type: endpoint.method(), | |
| data: JSON.stringify(self.format(rideNew)), | |
| success: function (data, status, xhr) { | |
| console.log(data.content.id); | |
| self.set('rideId', data.content.id); | |
| } | |
| }); | |
| }, | |
| showRide: function () { | |
| var self = this; | |
| endpoint = self.get('endpoints').get('showRide'); | |
| $.ajax({ | |
| url: endpoint.url(), | |
| type: endpoint.method(), | |
| data: JSON.stringify({ | |
| content: { | |
| id: self.get('rideId') | |
| } | |
| }), | |
| success: function (data, status, xhr) { | |
| console.log(data); | |
| } | |
| }); | |
| }, | |
| updateRide: function () { | |
| var self = this; | |
| endpoint = self.get('endpoints').get('viewRide'); | |
| $.ajax({ | |
| url: endpoint.url(), | |
| type: endpoint.method(), | |
| data: JSON.stringify({ | |
| }), | |
| success: function (data, status, xhr) { | |
| console.log(data); | |
| } | |
| }); | |
| }, | |
| format: function (template) { | |
| var attrs = self.attributes; | |
| return _.extend(template, { | |
| auth_token: self.get('token'), | |
| content: { | |
| id: '', | |
| passenger: _.pick(attrs, 'id'), | |
| pickup_location: self.get('pickup_location'), | |
| drop_off_location: self.get('drop_off_location'), | |
| notes: self.get('notes') | |
| } | |
| }); | |
| } | |
| }); | |
| return Passenger; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment