1
|
|
|
export class Edit { |
2
|
|
|
constructor() { |
3
|
|
|
this.intiSwitchListener() |
4
|
|
|
this.initCheckboxListener() |
5
|
|
|
this.autoCheck() |
6
|
|
|
this.autoDisplayApiCapabilities() |
7
|
|
|
this.autoDisplaySwitch() |
8
|
|
|
} |
9
|
|
|
|
10
|
|
|
intiSwitchListener() { |
11
|
|
|
$('#manage-api-capabilities').on('change', (event) => { |
12
|
|
|
let element = $(event.currentTarget) |
13
|
|
|
|
14
|
|
|
if (element.is(':checked')) { |
15
|
|
|
$("#permissions-table .for-api").removeClass('hide') |
16
|
|
|
} else { |
17
|
|
|
$("#permissions-table .for-api").addClass('hide') |
18
|
|
|
} |
19
|
|
|
}) |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
initCheckboxListener() { |
23
|
|
|
// Select all checkbox |
24
|
|
|
$('#permissions-table input.select-all').on('change', (event) => { |
25
|
|
|
let element = $(event.currentTarget) |
26
|
|
|
|
27
|
|
|
if (element.is(':checked')) { |
28
|
|
|
$("#permissions-table input[type='checkbox']").prop('checked', true) |
29
|
|
|
} else { |
30
|
|
|
$("#permissions-table input[type='checkbox']").prop('checked', false) |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
this.autoCheck() |
34
|
|
|
}) |
35
|
|
|
|
36
|
|
|
// Select row checkboxes |
37
|
|
|
$('#permissions-table input.select-row').on('change', (event) => { |
38
|
|
|
let element = $(event.currentTarget) |
39
|
|
|
let parentElement = $(element).parents('tr:first') |
40
|
|
|
|
41
|
|
|
if (element.is(':checked')) { |
42
|
|
|
$(".select-item", parentElement).prop('checked', true) |
43
|
|
|
} else { |
44
|
|
|
$(".select-item", parentElement).prop('checked', false) |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
this.autoCheck() |
48
|
|
|
}) |
49
|
|
|
|
50
|
|
|
// Select item checkboxes |
51
|
|
|
$('#permissions-table input.select-item').on('change', (event) => { |
52
|
|
|
let element = $(event.currentTarget) |
|
|
|
|
53
|
|
|
|
54
|
|
|
this.autoCheck() |
55
|
|
|
}) |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
autoCheck() { |
59
|
|
|
// All modules |
60
|
|
|
const globalCheckedCount = $("#permissions-table .select-item:checked").length |
61
|
|
|
const globalTotalCount = $("#permissions-table .select-item").length |
62
|
|
|
$("#permissions-table .select-all").prop('checked', globalCheckedCount === globalTotalCount) |
63
|
|
|
|
64
|
|
|
// Each row |
65
|
|
|
$("#permissions-table tbody tr").each((index, el) => { |
66
|
|
|
let rowElement = $(el) |
67
|
|
|
let rowCheckedCount = $(".select-item:checked", rowElement).length |
68
|
|
|
let rowTotalCount = $(".select-item", rowElement).length |
69
|
|
|
$(".select-row", rowElement).prop('checked', rowCheckedCount === rowTotalCount) |
70
|
|
|
}) |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
autoDisplayApiCapabilities() { |
74
|
|
|
const globalApiTotalCount = $("#permissions-table td.for-api input.select-item").length |
75
|
|
|
const globalApiCheckedCount = $("#permissions-table td.for-api input.select-item:checked").length |
76
|
|
|
|
77
|
|
|
if (globalApiCheckedCount > 0 && globalApiTotalCount !== globalApiCheckedCount) { |
78
|
|
|
$('#manage-api-capabilities').prop('checked', true).change() |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
autoDisplaySwitch() { |
83
|
|
|
const globalApiTotalCount = $("#permissions-table td.for-api input.select-item").length |
84
|
|
|
|
85
|
|
|
if (globalApiTotalCount > 0) { |
86
|
|
|
$(".api-switch").removeClass('hide') |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |