inviton-powerduck 0.0.64 → 0.0.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,162 +4,162 @@ import { DateWrapper } from "../date-wrapper";
|
|
|
4
4
|
import { capitalize } from "./capitalize-string";
|
|
5
5
|
|
|
6
6
|
export default class DateLocalizationUtils {
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
7
|
+
private static readonly DATE_FORMAT_FOR_RANGE_PICKER = (function () {
|
|
8
|
+
const dummyDate = new Date(Date.UTC(2022, 11, 20));
|
|
9
|
+
const formatted = dummyDate.toLocaleDateString(PowerduckState.getCurrentLanguageCode(), {
|
|
10
|
+
day: '2-digit',
|
|
11
|
+
month: '2-digit',
|
|
12
|
+
year: "numeric",
|
|
13
|
+
timeZone: 'UTC'
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return formatted.replace('20', 'DD').replace('12', 'MM').replace('2022', 'YYYY');
|
|
17
|
+
})();
|
|
18
|
+
|
|
19
|
+
private static readonly MONTH_IS_FIRST: boolean = (function () {
|
|
20
|
+
const dummyDate = new Date(Date.UTC(2024, 9, 20));
|
|
21
|
+
try {
|
|
22
|
+
const formatted = dummyDate.toLocaleDateString(PowerduckState.getCurrentLanguageCode(), {
|
|
23
|
+
day: '2-digit',
|
|
24
|
+
month: '2-digit',
|
|
25
|
+
timeZone: 'UTC'
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const monthIndex = formatted.indexOf('10');
|
|
29
|
+
const dayIndex = formatted.indexOf('20');
|
|
30
|
+
return monthIndex < dayIndex;
|
|
31
|
+
|
|
32
|
+
} catch (error) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
})();
|
|
36
|
+
|
|
37
|
+
private static readonly PATTERN_WITHOUT_YEAR: string = (function () {
|
|
38
|
+
const dummyDate = new Date(Date.UTC(2024, 9, 30));
|
|
39
|
+
try {
|
|
40
|
+
const monthName = dummyDate.toLocaleDateString(PowerduckState.getCurrentLanguageCode(), {
|
|
41
|
+
day: '2-digit',
|
|
42
|
+
month: 'long',
|
|
43
|
+
timeZone: 'UTC'
|
|
44
|
+
}).split('30').join('').split('.').join('').trim();
|
|
45
|
+
|
|
46
|
+
const formatted = dummyDate.toLocaleDateString(PowerduckState.getCurrentLanguageCode(), {
|
|
47
|
+
day: '2-digit',
|
|
48
|
+
month: 'long',
|
|
49
|
+
timeZone: 'UTC'
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return formatted.replace(monthName, '{{month}}').replace('30', '{{day}}');
|
|
53
|
+
|
|
54
|
+
} catch (error) {
|
|
55
|
+
return '{{day}}. {{month}}'
|
|
56
|
+
}
|
|
57
|
+
})();
|
|
58
|
+
|
|
59
|
+
private static readonly PATTERN_WITH_YEAR: string = (function () {
|
|
60
|
+
const dummyDate = new Date(Date.UTC(2024, 9, 30));
|
|
61
|
+
try {
|
|
62
|
+
const monthName = dummyDate.toLocaleDateString(PowerduckState.getCurrentLanguageCode(), {
|
|
63
|
+
day: '2-digit',
|
|
64
|
+
month: 'long',
|
|
65
|
+
timeZone: 'UTC'
|
|
66
|
+
}).split('30').join('').split('.').join('').trim();
|
|
67
|
+
|
|
68
|
+
const formatted = dummyDate.toLocaleDateString(PowerduckState.getCurrentLanguageCode(), {
|
|
69
|
+
day: '2-digit',
|
|
70
|
+
year: 'numeric',
|
|
71
|
+
month: 'long',
|
|
72
|
+
timeZone: 'UTC'
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return formatted.replace(monthName, '{{month}}').replace('30', '{{day}}').replace('2024', '{{year}}');
|
|
76
|
+
|
|
77
|
+
} catch (error) {
|
|
78
|
+
return '{{day}}. {{month}}'
|
|
79
|
+
}
|
|
80
|
+
})();
|
|
81
|
+
|
|
82
|
+
private static readonly PATTERN_PLACEHOLDERED: string = (function () {
|
|
83
|
+
const dummyDate = new Date(Date.UTC(2024, 9, 30));
|
|
84
|
+
try {
|
|
85
|
+
const monthName = dummyDate.toLocaleDateString(PowerduckState.getCurrentLanguageCode(), {
|
|
86
|
+
month: 'long',
|
|
87
|
+
timeZone: 'UTC'
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const formatted = dummyDate.toLocaleDateString(PowerduckState.getCurrentLanguageCode(), {
|
|
91
|
+
year: 'numeric',
|
|
92
|
+
month: 'long',
|
|
93
|
+
timeZone: 'UTC'
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return formatted.replace(monthName, '{{date}}').replace('30', '{{day}}').replace('2024', '{{year}}');
|
|
97
|
+
|
|
98
|
+
} catch (error) {
|
|
99
|
+
return '{{day}}. {{month}}'
|
|
100
|
+
}
|
|
101
|
+
})();
|
|
102
|
+
|
|
103
|
+
static formatRange = (from: DateWrapper, to: DateWrapper): string => {
|
|
104
|
+
if (from.getMonth() == to.getMonth()) {
|
|
105
|
+
const convertDate = new Date(Date.UTC(from.getFullYear(), from.getMonth(), from.getDate()));
|
|
106
|
+
convertDate.setDate(28);
|
|
107
|
+
|
|
108
|
+
const monthName = convertDate.toLocaleDateString(PowerduckState.getCurrentLanguageCode(), {
|
|
109
|
+
day: '2-digit',
|
|
110
|
+
month: 'long',
|
|
111
|
+
timeZone: 'UTC'
|
|
112
|
+
}).split('28').join('').split('.').join('').trim();
|
|
113
|
+
|
|
114
|
+
return this.PATTERN_WITH_YEAR
|
|
115
|
+
.replace('{{day}}', `${from.getDate()} - ${to.getDate()}`)
|
|
116
|
+
.replace('{{month}}', monthName)
|
|
117
|
+
.replace('{{year}}', from.getFullYear().toString());
|
|
118
|
+
} else if (from.getFullYear() == to.getFullYear()) {
|
|
119
|
+
const fromDate = this.getFormatted(from, this.PATTERN_WITHOUT_YEAR, 'numeric', 'short');
|
|
120
|
+
const toDate = this.getFormatted(to, this.PATTERN_WITHOUT_YEAR, 'numeric', 'short');
|
|
121
|
+
const rangeVal = `${fromDate} - ${toDate}`
|
|
122
|
+
return this.PATTERN_PLACEHOLDERED.replace('{{date}}', rangeVal).replace('{{year}}', to.getFullYear().toString());
|
|
123
|
+
} else {
|
|
124
|
+
const fromVal = this.getFormatted(from, this.PATTERN_WITH_YEAR, 'numeric', 'short', 'numeric');
|
|
125
|
+
const toVal = this.getFormatted(to, this.PATTERN_WITH_YEAR, 'numeric', 'short', 'numeric');
|
|
126
|
+
return `${fromVal} - ${toVal}`
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
static getFormatedDateWithoutTime = (dte: DateWrapper, showYear: boolean, day: "numeric" | "2-digit" | undefined, month?: "numeric" | "2-digit" | "long" | "short" | "narrow" | undefined, year?: "numeric" | "2-digit" | undefined) => {
|
|
131
|
+
if (showYear) {
|
|
132
|
+
return this.getFormatted(dte, this.PATTERN_WITH_YEAR, day, month, year);
|
|
133
|
+
} else {
|
|
134
|
+
return this.getFormatted(dte, this.PATTERN_WITHOUT_YEAR, day, month);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private static getFormatted = (dte: DateWrapper, pattern: string, day: "numeric" | "2-digit" | undefined, month?: "numeric" | "2-digit" | "long" | "short" | "narrow" | undefined, year?: "numeric" | "2-digit" | undefined): string => {
|
|
139
|
+
let monthVal: string;
|
|
140
|
+
try {
|
|
141
|
+
monthVal = capitalize(dte.innerDate.toLocaleDateString(PowerduckState.getCurrentLanguageCode(), {
|
|
142
|
+
month: month,
|
|
143
|
+
timeZone: 'UTC'
|
|
144
|
+
}));
|
|
145
|
+
} catch (error) {
|
|
146
|
+
monthVal = (dte.getMonth() + 1).toString();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let dayVal: string;
|
|
150
|
+
if (day == '2-digit') {
|
|
151
|
+
dayVal = dte.getDate().toString();
|
|
152
|
+
if (dayVal.length == 1) {
|
|
153
|
+
dayVal = '0' + dayVal
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
dayVal = dte.getDate().toString();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (year == null) {
|
|
160
|
+
return pattern.replace('{{day}}', dayVal).replace('{{month}}', monthVal);
|
|
161
|
+
} else {
|
|
162
|
+
return pattern.replace('{{day}}', dayVal).replace('{{month}}', monthVal).replace('{{year}}', dte.getFullYear().toString());
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -11,226 +11,242 @@ import { PortalUtils } from "../../../common/utils/utils";
|
|
|
11
11
|
* License : MIT
|
|
12
12
|
*/
|
|
13
13
|
(function ($) {
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
14
|
+
var exclusiveBinder = function (jqElem, s2Instance) {
|
|
15
|
+
var uuid = PortalUtils.randomString(10);
|
|
16
|
+
var ctx = jqElem.data("select2").$dropdown.find(".s2-cb-btn");
|
|
17
|
+
|
|
18
|
+
if (!ctx.hasClass("s2-incl-excl")) {
|
|
19
|
+
ctx.addClass("s2-incl-excl").prepend(
|
|
20
|
+
'<div class="inv-md-checkbox s2-incl-excl-chb"><div class="inv-cbrb-inner"><input type="checkbox" id="iei-input-' +
|
|
21
|
+
uuid +
|
|
22
|
+
'"><label for="iei-input-' +
|
|
23
|
+
uuid +
|
|
24
|
+
'" class="form-check-label ">' +
|
|
25
|
+
PowerduckState.getResourceValue('dtOnlyExclusive') +
|
|
26
|
+
"</label></div></div>",
|
|
27
|
+
);
|
|
28
|
+
ctx.find("input").change(function (this: any) {
|
|
29
|
+
s2Instance.exclusivity = $(this).prop("checked") ? 1 : 0;
|
|
30
|
+
jqElem.trigger("change");
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
var updateValue = function ($element, values) {
|
|
36
|
+
$element.attr("multiple", "multiple").val(values).trigger("change.select2");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var flattenData = (data): any[] => {
|
|
40
|
+
const retArr = [];
|
|
41
|
+
const recCheck = (arr: any[]) => {
|
|
42
|
+
for (const item of arr) {
|
|
43
|
+
if (item.id != null) {
|
|
44
|
+
retArr.push(item);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (item.children?.length > 0) {
|
|
48
|
+
recCheck(item.children);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
recCheck(data);
|
|
53
|
+
return retArr;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
var S2MultiCheckboxes = function (this: any, options, element) {
|
|
57
|
+
var self = this;
|
|
58
|
+
self.options = options;
|
|
59
|
+
self.$element = $(element);
|
|
60
|
+
var values = self.$element.val();
|
|
61
|
+
var getSelected = () => {
|
|
62
|
+
let retArr = [];
|
|
63
|
+
if (self.currentData != null) {
|
|
64
|
+
const recCheck = (arr: any[]) => {
|
|
65
|
+
for (const item of arr) {
|
|
66
|
+
if (item.selected == true) {
|
|
67
|
+
retArr.push(item);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (item.children?.length > 0) {
|
|
71
|
+
recCheck(item.children);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
recCheck(self.currentData);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return retArr;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
self.$element.removeAttr("multiple");
|
|
82
|
+
self.currentData = options.data;
|
|
83
|
+
self.select2 = self.$element
|
|
84
|
+
.select2({
|
|
85
|
+
allowClear: true,
|
|
86
|
+
ajax: {
|
|
87
|
+
transport: function (params, success, failure) {
|
|
88
|
+
success({ results: self.currentData });
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
language: options.language,
|
|
92
|
+
dropdownAutoWidth: options.dropdownAutoWidth == true,
|
|
93
|
+
minimumResultsForSearch: options.minimumResultsForSearch,
|
|
94
|
+
placeholder: options.placeholder,
|
|
95
|
+
closeOnSelect: false,
|
|
96
|
+
templateSelection: function () {
|
|
97
|
+
return self.options.templateSelection(
|
|
98
|
+
getSelected(),
|
|
99
|
+
self.currentData,
|
|
100
|
+
self.$element
|
|
101
|
+
);
|
|
102
|
+
},
|
|
103
|
+
templateResult: function (result) {
|
|
104
|
+
if (options.templateResult != null) {
|
|
105
|
+
return options.templateResult(result);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (result.loading !== undefined) return result.text;
|
|
109
|
+
return $("<div>").text(result.text).addClass(self.options.wrapClass);
|
|
110
|
+
},
|
|
111
|
+
matcher: function (params, data) {
|
|
112
|
+
var original_matcher = $.fn["select2"].defaults.defaults.matcher;
|
|
113
|
+
var result = original_matcher(params, data);
|
|
114
|
+
if (result && self.options.searchMatchOptGroups && data.children && result.children && data.children.length != result.children.length) {
|
|
115
|
+
result.children = data.children;
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
},
|
|
119
|
+
})
|
|
120
|
+
.data("select2");
|
|
121
|
+
|
|
122
|
+
if (self.initialSelect2 == null) {
|
|
123
|
+
self.initialSelect2 = self.select2;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const currentMethod = self.select2.dataAdapter.current;
|
|
127
|
+
self.select2.dataAdapter.current = (cb) => {
|
|
128
|
+
if (self.currentData != null) {
|
|
129
|
+
cb.call(self.select2.dataAdapter, getSelected());
|
|
130
|
+
} else {
|
|
131
|
+
currentMethod.call(self.select2.dataAdapter, cb);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
element.select2MutliCheckboxes = this;
|
|
136
|
+
self.$element.on("select2:opening", function (this: any, e) {
|
|
137
|
+
if (options.allowExclusiveSearch == true) {
|
|
138
|
+
let jqElem = $(this);
|
|
139
|
+
let openingSelect2 = jqElem.data("select2");
|
|
140
|
+
exclusiveBinder(jqElem, openingSelect2);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
self.rebindResultList = () => {
|
|
145
|
+
self.select2.$results.off("mouseup").on(
|
|
146
|
+
"mouseup",
|
|
147
|
+
".select2-results__option[aria-selected]",
|
|
148
|
+
(function (mySelf) {
|
|
149
|
+
return function (this: any, evt) {
|
|
150
|
+
var $this = $(this);
|
|
151
|
+
|
|
152
|
+
var data = $this.data("data");
|
|
153
|
+
|
|
154
|
+
if ($this.attr("aria-selected") === "true") {
|
|
155
|
+
if (self.currentData != null) {
|
|
156
|
+
for (const item of flattenData(self.currentData)) {
|
|
157
|
+
if (data.id == item.id) {
|
|
158
|
+
item.selected = false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
mySelf.trigger("unselect", {
|
|
164
|
+
originalEvent: evt,
|
|
165
|
+
data: data,
|
|
166
|
+
});
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (self.currentData != null) {
|
|
171
|
+
for (const item of flattenData(self.currentData)) {
|
|
172
|
+
if (data.id == item.id) {
|
|
173
|
+
item.selected = true;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
mySelf.trigger("select", {
|
|
179
|
+
originalEvent: evt,
|
|
180
|
+
data: data,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
evt.preventDefault();
|
|
184
|
+
evt.stopPropagation();
|
|
185
|
+
evt.stopImmediatePropagation();
|
|
186
|
+
return false;
|
|
187
|
+
};
|
|
188
|
+
})(self.select2),
|
|
189
|
+
);
|
|
190
|
+
};
|
|
191
|
+
self.rebindResultList();
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
self.select2.$dropdown.children().first().prepend('<div class="s2-cb-btn"><button class="btn btn-success btn-sm">OK</button></div>');
|
|
195
|
+
if (options.allowExclusiveSearch == true) {
|
|
196
|
+
exclusiveBinder(self.$element, self.select2);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
self.select2.$dropdown
|
|
200
|
+
.children()
|
|
201
|
+
.first()
|
|
202
|
+
.find("button")
|
|
203
|
+
.click(function () {
|
|
204
|
+
self.select2.close();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
self.select2.exclusivity = 0;
|
|
208
|
+
self.select2.$dropdown.addClass("s2-multi-cb");
|
|
209
|
+
updateValue(self.$element, values);
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
$.fn.extend({
|
|
213
|
+
select2MultiCheckboxes: function (this: any) {
|
|
214
|
+
const firstArg = arguments[0];
|
|
215
|
+
const secondArg = arguments[1];
|
|
216
|
+
|
|
217
|
+
this.each(function (this: any) {
|
|
218
|
+
const multiCheckboxes = this.select2MutliCheckboxes;
|
|
219
|
+
if (multiCheckboxes == null) {
|
|
220
|
+
const options = $.extend(
|
|
221
|
+
{
|
|
222
|
+
placeholder: "Choose elements",
|
|
223
|
+
templateSelection: function (selected, allData, $elem) {
|
|
224
|
+
const flatData = flattenData(allData);
|
|
225
|
+
if (selected.length == 0 || selected.length == flatData.length) {
|
|
226
|
+
return "[" + PowerduckState.getResourceValue('all') + "]";
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (Array.isArray(selected) && selected.length == 1) {
|
|
230
|
+
return selected[0].text;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return PowerduckState.getResourceValue('itemsOutOfArray').replace('{0}', selected.length.toString()).replace('{1}', flatData.length.toString());
|
|
234
|
+
},
|
|
235
|
+
wrapClass: "wrap",
|
|
236
|
+
minimumResultsForSearch: -1,
|
|
237
|
+
searchMatchOptGroups: true,
|
|
238
|
+
},
|
|
239
|
+
firstArg,
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
new S2MultiCheckboxes(options, this);
|
|
243
|
+
} else {
|
|
244
|
+
if (firstArg.data != null) {
|
|
245
|
+
multiCheckboxes.currentData = firstArg.data;
|
|
246
|
+
multiCheckboxes.rebindResultList();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
},
|
|
251
|
+
});
|
|
236
252
|
})(jQuery);
|