-
-
Save AlexTiTanium/9434336 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Created by alex on 03.03.14. | |
*/ | |
/** | |
* Created by akucherenko on 21.10.13. | |
*/ | |
define(['backbone', 'jquery', 'lodash', 'q'], function (Backbone, $, _, Q) { | |
/** | |
* ProjectModel class | |
* @class ProjectModel | |
*/ | |
return Backbone.Model.extend({ | |
/** | |
* Urls to the api`s | |
*/ | |
url: function(){ return app.config.api.url + '/subscription'; }, | |
urlPaypal: function(){ return this.url() + '/paypal'; }, | |
/** | |
* Get current subscribe state | |
*/ | |
getCurrentPlan: function(){ | |
var promise = app.api.get(this.url()); | |
this.handlePromiseEvents(promise); | |
promise.done(function(result){ | |
console.log(result); | |
console.log("result:currentPlan", result); | |
}); | |
}, | |
/** | |
* Crete paypal url | |
*/ | |
payByPaypal: function(){ | |
var promise = app.api.get(this.urlPaypal()); | |
this.handlePromiseEvents(promise); | |
}, | |
/** | |
* Handle promise events | |
* | |
* @param {*|Promise|Object} promise | |
*/ | |
handlePromiseEvents: function(promise){ | |
var self = this; | |
self.trigger('request:begin'); | |
promise.catch(function(request){ | |
console.log("request:error", request.statusText, request); | |
self.trigger('request:error', request.statusText); | |
}); | |
promise.finally(function(){ | |
self.trigger('request:end'); | |
}); | |
promise.done(function(result){ | |
self.trigger('request:begin', result); | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment