1
|
|
|
import template from './sw-cms-product-assignment.html.twig'; |
2
|
|
|
import './sw-cms-product-assignment.scss'; |
3
|
|
|
|
4
|
|
|
const { Component } = Shopware; |
|
|
|
|
5
|
|
|
const { Criteria } = Shopware.Data; |
6
|
|
|
|
7
|
|
|
Component.extend('sw-cms-product-assignment', 'sw-many-to-many-assignment-card', { |
8
|
|
|
template, |
9
|
|
|
data() { |
10
|
|
|
return { |
11
|
|
|
steps: [5] |
12
|
|
|
}; |
13
|
|
|
}, |
14
|
|
|
|
15
|
|
|
watch: { |
16
|
|
|
criteria: { |
17
|
|
|
immediate: true, |
18
|
|
|
handler() { |
19
|
|
|
this.gridCriteria = Criteria.fromCriteria(this.criteria); |
20
|
|
|
this.searchCriteria = Criteria.fromCriteria(this.criteria); |
21
|
|
|
|
22
|
|
|
this.paginateGrid(); |
23
|
|
|
} |
24
|
|
|
}, |
25
|
|
|
|
26
|
|
|
entityCollection() { |
27
|
|
|
this.selectedIds = this.entityCollection.getIds(); |
28
|
|
|
|
29
|
|
|
this.paginateGrid(); |
30
|
|
|
}, |
31
|
|
|
|
32
|
|
|
languageId() { |
33
|
|
|
this.paginateGrid(); |
34
|
|
|
} |
35
|
|
|
}, |
36
|
|
|
|
37
|
|
|
created() { |
38
|
|
|
this.createdComponent(); |
39
|
|
|
}, |
40
|
|
|
|
41
|
|
|
methods: { |
42
|
|
|
createdComponent() { |
43
|
|
|
this.initData(); |
44
|
|
|
}, |
45
|
|
|
|
46
|
|
|
initData() { |
47
|
|
|
this.page = 1; |
48
|
|
|
this.selectedIds = this.entityCollection.getIds(); |
49
|
|
|
}, |
50
|
|
|
|
51
|
|
|
searchItems() { |
52
|
|
|
return this.searchRepository.search(this.searchCriteria, this.context).then((result) => { |
53
|
|
|
const criteria = new Criteria(1, this.searchCriteria.limit); |
54
|
|
|
criteria.setIds(result.getIds()); |
55
|
|
|
|
56
|
|
|
return result; |
57
|
|
|
}); |
58
|
|
|
}, |
59
|
|
|
|
60
|
|
|
onItemSelect(item) { |
61
|
|
|
if (this.isSelected(item)) { |
62
|
|
|
this.removeItem(item); |
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
this.entityCollection.add(item); |
67
|
|
|
|
68
|
|
|
this.selectedIds = this.entityCollection.getIds(); |
69
|
|
|
this.gridData = this.entityCollection; |
70
|
|
|
|
71
|
|
|
this.$emit('change', this.entityCollection); |
72
|
|
|
}, |
73
|
|
|
|
74
|
|
|
removeItem(item) { |
75
|
|
|
this.entityCollection.remove(item.id); |
76
|
|
|
|
77
|
|
|
this.selectedIds = this.entityCollection.getIds(); |
78
|
|
|
this.gridData = this.entityCollection; |
79
|
|
|
this.$emit('change', this.entityCollection); |
80
|
|
|
|
81
|
|
|
return Promise.resolve(); |
82
|
|
|
}, |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
onSelectCollapsed() { |
86
|
|
|
this.resultCollection = null; |
87
|
|
|
this.focusEl.blur(); |
88
|
|
|
|
89
|
|
|
this.paginateGrid(); |
90
|
|
|
}, |
91
|
|
|
|
92
|
|
|
paginateGrid({ page, limit } = this.gridCriteria) { |
93
|
|
|
this.gridCriteria.page = page; |
94
|
|
|
this.gridCriteria.limit = limit; |
95
|
|
|
this.isLoadingGrid = true; |
96
|
|
|
const currentPaginateCollection = this.entityCollection.slice((page - 1) * limit, (page - 1) * limit + limit); |
97
|
|
|
this.gridData = currentPaginateCollection; |
98
|
|
|
this.isLoadingGrid = false; |
99
|
|
|
this.$emit('paginate', this.gridData); |
100
|
|
|
}, |
101
|
|
|
|
102
|
|
|
removeFromGrid(item) { |
103
|
|
|
this.removeItem(item).then(() => { |
104
|
|
|
this.paginateGrid(); |
105
|
|
|
}); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
}); |
109
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.