Skip to content

Instantly share code, notes, and snippets.

@AlexTiTanium
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexTiTanium/9434336 to your computer and use it in GitHub Desktop.
Save AlexTiTanium/9434336 to your computer and use it in GitHub Desktop.
/**
* 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