Files
discourse-subscriptions/assets/javascripts/discourse/models/plan.js.es6
T

31 lines
779 B
JavaScript
Raw Normal View History

2019-10-31 10:44:46 +11:00
import computed from "ember-addons/ember-computed-decorators";
2019-10-08 19:37:22 +11:00
import { ajax } from "discourse/lib/ajax";
2019-10-31 10:44:46 +11:00
const Plan = Discourse.Model.extend({
2019-10-31 13:29:11 +11:00
amountDollars: Ember.computed("amount", {
get() {
return parseFloat(this.get("amount") / 100).toFixed(2);
},
set(key, value) {
const decimal = parseFloat(value) * 100;
this.set("amount", decimal);
return value;
}
}),
2019-10-31 11:41:01 +11:00
@computed("amountDollars", "currency", "interval")
subscriptionRate(amountDollars, currency, interval) {
return `$${amountDollars} ${currency.toUpperCase()} / ${interval}`;
2019-10-31 13:31:24 +11:00
}
2019-10-31 10:44:46 +11:00
});
2019-10-08 19:37:22 +11:00
Plan.reopenClass({
2019-10-17 12:07:06 +11:00
findAll() {
2019-10-10 13:52:55 +11:00
return ajax("/patrons/plans", { method: "get" }).then(result =>
2019-10-17 20:34:26 +11:00
result.map(plan => Plan.create(plan))
2019-10-09 09:11:02 +11:00
);
2019-10-08 19:37:22 +11:00
}
});
export default Plan;