-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathshoppinglist.js
85 lines (81 loc) · 2.01 KB
/
shoppinglist.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
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
82
83
84
85
// Vue Material plugin
Vue.use(VueMaterial);
const sampleShoppingList = {
"_id": "",
"type": "list",
"version": 1,
"title": "",
"checked": false,
"place": {
"title": "",
"license": null,
"lat": null,
"lon": null,
"address": {}
},
"createdAt": "",
"updatedAt": ""
};
const sampleListItem = {
"_id": "list:cj6mj1zfj000001n1ugjfkj33:item:cj6mn7e36000001p9n14fgk6s",
"type": "item",
"version": 1,
"title": "",
"checked": false,
"createdAt": "",
"updatedAt": ""
};
// Vue Material theme
Vue.material.registerTheme('default', {
primary: 'blue',
accent: 'white',
warn: 'red',
background: 'grey'
});
var app = new Vue({
el: '#app',
data: {
pagetitle: 'Shopping Lists',
shoppingLists: [],
shoppingListItems: [],
mode: 'showlist',
singleList: null,
currentListId: null,
newItemTitle:''
},
methods: {
onClickAddShoppingList: function() {
// open shopping list form
this.pagetitle = 'New Shopping List';
this.mode='addlist';
this.singleList = JSON.parse(JSON.stringify(sampleShoppingList));
this.singleList._id = 'list:' + cuid();
this.singleList.createdAt = new Date().toISOString();
},
onBack: function() {
this.mode='showlist';
this.pagetitle='Shopping Lists';
},
onClickSaveShoppingList: function() {
this.singleList.updatedAt = new Date().toISOString();
this.shoppingLists.unshift(this.singleList);
this.onBack();
},
onClickList: function(id, title) {
this.currentListId = id;
this.pagetitle = title;
this.mode = 'itemedit';
},
onAddListItem: function() {
if (!this.newItemTitle) return;
var obj = JSON.parse(JSON.stringify(sampleListItem));
obj._id = 'item:' + cuid();
obj.title = this.newItemTitle;
obj.list = this.currentListId;
obj.createdAt = new Date().toISOString();
obj.updatedAt = new Date().toISOString();
this.shoppingListItems.unshift(obj);
this.newItemTitle = '';
}
}
});