2019-08-27 20:37:20 +10:00
|
|
|
import { default as computed } from "ember-addons/ember-computed-decorators";
|
|
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
|
import { getOwner } from "discourse-common/lib/get-owner";
|
2018-09-22 14:03:30 +10:00
|
|
|
import { emailValid } from "discourse/lib/utilities";
|
2018-06-25 18:14:50 +10:00
|
|
|
|
|
|
|
|
export default Ember.Controller.extend({
|
|
|
|
|
loadingDonations: false,
|
2019-08-27 20:37:20 +10:00
|
|
|
loadDonationsDisabled: Ember.computed.not("emailVaild"),
|
2018-06-28 09:32:58 +10:00
|
|
|
|
2019-08-27 20:37:20 +10:00
|
|
|
@computed("charges.[]", "subscriptions.[]")
|
2018-06-25 18:14:50 +10:00
|
|
|
hasDonations(charges, subscriptions) {
|
2019-08-27 20:37:20 +10:00
|
|
|
return (
|
|
|
|
|
(charges && charges.length > 0) ||
|
|
|
|
|
(subscriptions && subscriptions.length > 0)
|
|
|
|
|
);
|
2018-06-28 09:32:58 +10:00
|
|
|
},
|
|
|
|
|
|
2019-08-27 20:37:20 +10:00
|
|
|
@computed("email")
|
2018-06-28 09:32:58 +10:00
|
|
|
emailVaild(email) {
|
|
|
|
|
return emailValid(email);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
actions: {
|
2019-08-28 18:36:19 +10:00
|
|
|
stripeTransationCompleteCtr() {},
|
2019-08-28 14:59:45 +10:00
|
|
|
|
2018-06-28 09:32:58 +10:00
|
|
|
loadDonations() {
|
2019-08-27 20:37:20 +10:00
|
|
|
let email = this.get("email");
|
2018-06-28 09:32:58 +10:00
|
|
|
|
2019-08-27 20:37:20 +10:00
|
|
|
this.set("loadingDonations", true);
|
2018-06-28 09:32:58 +10:00
|
|
|
|
2019-08-27 20:37:20 +10:00
|
|
|
ajax("/donate/charges", {
|
2018-06-28 09:32:58 +10:00
|
|
|
data: { email },
|
2019-08-27 20:37:20 +10:00
|
|
|
type: "GET"
|
|
|
|
|
})
|
|
|
|
|
.then(result => {
|
|
|
|
|
this.setProperties({
|
|
|
|
|
charges: Ember.A(result.charges),
|
|
|
|
|
subscriptions: Ember.A(result.subscriptions),
|
|
|
|
|
customer: result.customer
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch(popupAjaxError)
|
|
|
|
|
.finally(() => {
|
|
|
|
|
this.setProperties({
|
|
|
|
|
loadingDonations: false,
|
|
|
|
|
hasEmailResult: true
|
|
|
|
|
});
|
2018-06-28 09:32:58 +10:00
|
|
|
|
2019-08-27 20:37:20 +10:00
|
|
|
Ember.run.later(() => {
|
|
|
|
|
this.set("hasEmailResult", false);
|
|
|
|
|
}, 6000);
|
|
|
|
|
});
|
2018-06-28 09:32:58 +10:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
showLogin() {
|
2019-08-27 20:37:20 +10:00
|
|
|
const controller = getOwner(this).lookup("route:application");
|
|
|
|
|
controller.send("showLogin");
|
2018-06-28 09:32:58 +10:00
|
|
|
}
|
2018-06-25 18:14:50 +10:00
|
|
|
}
|
2018-09-22 14:03:30 +10:00
|
|
|
});
|