-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathshopping.mobl
81 lines (71 loc) · 1.78 KB
/
shopping.mobl
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
application shopping
import mobl
entity Item {
name : String
checked : Bool
favorite : Bool
onlist : Bool
order : Num
}
screen editItem(it : Item) {
header("Edit item")
topRightButton("Done", onclick={ screen return; })
inputs {
inputString(it.name, placeholder="Name")
item { checkbox(it.favorite, label="favorite") }
inputNum(it.order, placeholder="Shop order (0 = early, 999=late)")
}
}
function clean() {
for(it : Item in Item.all().filter("checked", "=", true)) {
if(it.favorite) {
it.checked = false;
it.onlist = false;
} else {
remove(it);
}
}
}
template showItemsHeader() {
header("Items")
topRightButton("Clean", onclick={ clean(); })
}
template showItems() {
group {
list(it in Item.all().filter("onlist", "=", true).order("order", true)) {
item(onclick={ it.checked = it.checked ? false: true; }) {
checkbox(it.checked, label=it.name)
sideButton("Edit", onclick={ editItem(it); })
}
}
}
quickAdd()
}
template showFavoritesHeader() {
header("Favorites")
}
template showFavorites() {
group {
list(it in Item.all().filter("favorite", "=", true).order("order", true)) {
item(onclick={ editItem(it); }) {
label(it.name)
cond(it.onlist == false) {
sideButton("Add", onclick={ it.onlist = true; })
}
}
}
}
}
template quickAdd() {
var newItem = Item{ order=999, onlist=true }
group {
inputString(newItem.name, placeholder="New item")
}
altButton("Add", onclick={
add(newItem);
newItem = Item{order=999, onlist=true};
})
}
screen root() {
tabsetCustomHeaders([("Items", "lib/toolbar/icon_users.png", showItemsHeader, showItems), ("Favorite", "lib/toolbar/icon_users.png", showFavoritesHeader, showFavorites)])
}