-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
126 lines (118 loc) · 3.62 KB
/
main.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
function compare (a,b){
if (a.name < b.name)
return -1;
if (a.name > b.name)
return 1;
return 0;
}
new Vue({
el:"#main",
data: {
items: [],
count: 0,
checked: [],
unchecked: [],
userInput: "",
activate: 0
},
methods:{
add: function(userInput){
if (userInput.length === 0){
alert("Empty items not allowed")
} else {
console.log(this, this.items);
this.activate = 0;
var k = this.count + 1;
this.items.push({key: k, name: this.userInput, show: true});
this.count++;
this.userInput = "";
}
},
showAll: function(){
this.activate = 0;
var self = this;
this.items.forEach(function(item){
item.show = true
})
// this.items.forEach( function(item){
// self.checked.forEach(function(checkedid){
// if(item.show === false){
// item.show = true; }
// })
// })
},
unselectAll: function(){
this.activate = 0;
this.checked = [];
},
deleteSelected: function(){
this.activate = 0;
var self = this;
this.checked.sort(); this.checked.reverse();
this.checked.forEach(function(checkedid, checkedix, checkedkey){
self.items = self.items.filter(item => item.key != checkedid);
})
this.checked = [];
// console.log(this.items, this.checked);
},
orderASC: function(){
this.activate = 1;
this.items = this.items.sort(compare);
},
orderDESC: function(){
this.activate = 1;
this.items = this.items.sort(compare).reverse();
},
showUnchecked: function(){
this.showAll();
this.activate = 1;
var self = this;
this.checked.forEach(function(checkedelt){
self.items.forEach(function(item){
if (item.key === checkedelt){
item.show = false;
}
})
});
},
showChecked: function(){
this.activate = 1;
var self = this;
// console.log(this.items, this.checked);
this.items.forEach(function(item){
item.show = false
})
this.checked.forEach(function(checkedelt){
self.items.forEach(function(item){
if (item.key === checkedelt){
item.show = true;
}
})
})
},
del: function(k){
this.activate = 0;
this.items = this.items.filter(item => item.key != k);
},
deleteAll: function(){
this.activate = 0;
this.items = [];
},
}, //end of methods
computed: {
selectAll: {
get: function () {
return this.items ? this.checked.length == this.items.length : false;
},
set: function (getvalue) {
var selected = [];
if (getvalue) {
this.items.forEach(function (item) {
selected.push(item.key);
});
}
this.checked = selected;
}
}
} // end of computed
})