-
-
Notifications
You must be signed in to change notification settings - Fork 153
/
PaymentPage.js
56 lines (45 loc) · 1.42 KB
/
PaymentPage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var Observable = require("FuseJS/Observable")
var paymentOpts = {
cash: { label: "Cash", desc: "Have cash ready at the door." },
credit: { label: "Credit Card", desc: "Pay now with a credit card." },
paypal: { label: "PayPal", desc: "Pay in advance with PayPal." },
coupon: { label: "Coupon", desc: "Have your coupon ready at the door." },
};
var deliveryOpts = {
normal: { label: "Normal (<1hr)", cost: 0 },
express: { label: "Express (<30min)", cost: 5 },
drone: { label: "Drone (<15min)", cost: 10 },
};
var payment = Observable("cash");
var delivery = Observable("express");
var notice = Observable("");
payment.onValueChanged(module, update);
delivery.onValueChanged(module, update);
function update() {
var payOpt = paymentOpts[payment.value];
var delOpt = deliveryOpts[delivery.value];
//safety check (a binding may reset the value to null during rooting/unrooting)
if (!payOpt || !delOpt) {
return;
}
var q = payOpt.desc;
var cost = delOpt.cost;
if (cost > 0) {
q += " An extra delivery fee of $" + cost + " applies.";
}
notice.value = q;
};
// converts our own options object into an array of options for an `Each`
function mapOptions(opts) {
return Object.keys(opts).map(function(key) {
return { value: key, label: opts[key].label };
});
};
update();
module.exports = {
payment: payment,
delivery: delivery,
paymentOpts: mapOptions(paymentOpts),
deliveryOpts: mapOptions(deliveryOpts),
notice: notice
};