1
|
$(document).ready(function() {
|
2
|
|
3
|
// reaction for add/delete parameters from selected fields (row, column, value)
|
4
|
$('.select-action-button').on('click', function () {
|
5
|
// if input has headlight class (parameter is already added -> remove)
|
6
|
if ($(this).hasClass('select-action-headlight'))
|
7
|
{
|
8
|
// remove headlight class from type
|
9
|
$(this).removeClass('select-action-headlight');
|
10
|
|
11
|
// remove parameter from selected inputs
|
12
|
removeParameter(getParameterTitle($(this)), getParameterType($(this)));
|
13
|
}
|
14
|
else
|
15
|
{
|
16
|
// remove headlight from other types for parameter if exists
|
17
|
$(this).closest('.select-action-buttons').find('.select-action-button').removeClass('select-action-headlight');
|
18
|
|
19
|
// remove element from selected inputs if exists
|
20
|
removeFromAll(getParameterTitle($(this)));
|
21
|
|
22
|
// headlight selected input
|
23
|
$(this).addClass('select-action-headlight');
|
24
|
|
25
|
// add selected parameter to selected parameters by type
|
26
|
addParameter(getParameterIndex($(this)),
|
27
|
getParameterTitle($(this)),
|
28
|
getParameterType($(this)),
|
29
|
getParameterHiddenValue($(this)));
|
30
|
|
31
|
// reinitialize actions for new parameter
|
32
|
initParameters();
|
33
|
}
|
34
|
});
|
35
|
|
36
|
// init actions
|
37
|
initParameters();
|
38
|
|
39
|
initSpinnerToButtons();
|
40
|
|
41
|
});
|
42
|
|
43
|
/**
|
44
|
* Remove value from all selected fields
|
45
|
* @param title
|
46
|
*/
|
47
|
function removeFromAll(title) {
|
48
|
$rows = $('.selected-input-container');
|
49
|
|
50
|
$rows.each(function () {
|
51
|
$(this).find('.parameter-name').each(function () {
|
52
|
if ($(this).text() == title)
|
53
|
{
|
54
|
$(this).closest('.parameter').remove();
|
55
|
}
|
56
|
})
|
57
|
});
|
58
|
}
|
59
|
|
60
|
/**
|
61
|
* Returns parameter index
|
62
|
* @param button
|
63
|
* @returns {*|jQuery|string|undefined}
|
64
|
*/
|
65
|
function getParameterIndex(button) {
|
66
|
return $(button).closest('.parameter-row').find('.parameterIndex').val();
|
67
|
}
|
68
|
|
69
|
/**
|
70
|
* Adds new parameter to selected fields
|
71
|
* @param index
|
72
|
* @param parameterName
|
73
|
* @param type
|
74
|
* @param hiddenValue
|
75
|
*/
|
76
|
function addParameter(index, parameterName, type, hiddenValue) {
|
77
|
var row = document.createElement('tr');
|
78
|
row.classList.add(type + '-parameter', 'parameter');
|
79
|
|
80
|
let hiddenInput = document.createElement('input');
|
81
|
hiddenInput.type = 'hidden';
|
82
|
hiddenInput.id = `parametersInConfiguration${index}.location.id`;
|
83
|
hiddenInput.name = `parametersInConfiguration[${index}].location.id`;
|
84
|
hiddenInput.setAttribute('value', hiddenValue);
|
85
|
|
86
|
let hiddenInputOrder = document.createElement('input');
|
87
|
hiddenInputOrder.type = 'hidden';
|
88
|
hiddenInputOrder.id = `parametersInConfiguration${index}.parameterOrder`;
|
89
|
hiddenInputOrder.name = `parametersInConfiguration[${index}].parameterOrder`;
|
90
|
hiddenInputOrder.classList.add('parametr-order');
|
91
|
|
92
|
row.appendChild(hiddenInput);
|
93
|
row.appendChild(hiddenInputOrder);
|
94
|
|
95
|
var firstTd = document.createElement('td');
|
96
|
|
97
|
var firstTdBody = document.createElement('span');
|
98
|
firstTdBody.classList.add('parameter-name');
|
99
|
firstTdBody.innerHTML = parameterName;
|
100
|
|
101
|
firstTd.appendChild(firstTdBody);
|
102
|
|
103
|
row.appendChild(firstTd);
|
104
|
|
105
|
var thirdTd = document.createElement('td');
|
106
|
|
107
|
var thirdTdBody;
|
108
|
|
109
|
|
110
|
if (type == 'value')
|
111
|
{
|
112
|
thirdTdBody = $('#function-select-' + index).clone()[0];
|
113
|
thirdTdBody.selectedIndex = 0;
|
114
|
|
115
|
$(thirdTdBody).removeClass('hidden');
|
116
|
}
|
117
|
else
|
118
|
{
|
119
|
var secondTd = document.createElement('td');
|
120
|
|
121
|
var secondTdBody = document.createElement('input');
|
122
|
secondTdBody.type = 'text';
|
123
|
secondTdBody.classList.add('form-control', 'select-filter-input-name');
|
124
|
secondTdBody.name = `parametersInConfiguration[${index}].columnName`;
|
125
|
|
126
|
secondTd.appendChild(secondTdBody);
|
127
|
|
128
|
row.appendChild(secondTd);
|
129
|
|
130
|
thirdTdBody = document.createElement('span');
|
131
|
thirdTdBody.innerHTML = "<i class=\"fas fa-sort\"></i>";
|
132
|
}
|
133
|
|
134
|
thirdTd.appendChild(thirdTdBody);
|
135
|
|
136
|
row.appendChild(thirdTd);
|
137
|
|
138
|
$('#' + type + '-wrapper').append($(row));
|
139
|
|
140
|
reindexOrder();
|
141
|
|
142
|
}
|
143
|
|
144
|
/**
|
145
|
* Remove specific parameter from fields by name and container
|
146
|
* @param title
|
147
|
* @param parameterClass
|
148
|
*/
|
149
|
function removeParameter(title, parameterClass) {
|
150
|
$rows = $('.' + parameterClass + '-parameter');
|
151
|
|
152
|
$rows.each(function () {
|
153
|
$(this).find('.parameter-name').each(function () {
|
154
|
if ($(this).text() == title)
|
155
|
{
|
156
|
$(this).closest('.' + parameterClass + '-parameter').remove();
|
157
|
}
|
158
|
})
|
159
|
});
|
160
|
}
|
161
|
|
162
|
/**
|
163
|
* Base on class returns type
|
164
|
* @param context
|
165
|
* @returns {string}
|
166
|
*/
|
167
|
function getParameterType(context) {
|
168
|
if ($(context).hasClass('column-button'))
|
169
|
{
|
170
|
return 'column';
|
171
|
}
|
172
|
else if ($(context).hasClass('row-button'))
|
173
|
{
|
174
|
return 'row';
|
175
|
}
|
176
|
else if ($(context).hasClass('value-button'))
|
177
|
{
|
178
|
return 'value';
|
179
|
}
|
180
|
}
|
181
|
|
182
|
/**
|
183
|
* Base on type return integer value
|
184
|
* @param context
|
185
|
* @returns {number}
|
186
|
*/
|
187
|
function getParameterHiddenValue(context) {
|
188
|
if ($(context).hasClass('column-button'))
|
189
|
{
|
190
|
return 1;
|
191
|
}
|
192
|
else if ($(context).hasClass('row-button'))
|
193
|
{
|
194
|
return 2;
|
195
|
}
|
196
|
else if ($(context).hasClass('value-button'))
|
197
|
{
|
198
|
return 3;
|
199
|
}
|
200
|
}
|
201
|
|
202
|
/**
|
203
|
* Returns parameter name
|
204
|
* @param context
|
205
|
* @returns {*|jQuery}
|
206
|
*/
|
207
|
function getParameterTitle(context) {
|
208
|
return $(context).closest('.parameter-row').find('.parameter-name').text();
|
209
|
}
|
210
|
|
211
|
/**
|
212
|
* Init base actions
|
213
|
*/
|
214
|
function initParameters()
|
215
|
{
|
216
|
$('.sortable').sortable({
|
217
|
stop: function () {
|
218
|
reindexOrder();
|
219
|
}
|
220
|
});
|
221
|
$("select").selectpicker('refresh');
|
222
|
}
|
223
|
|
224
|
/**
|
225
|
* Update parametr order
|
226
|
*/
|
227
|
function reindexOrder() {
|
228
|
var rowValues = $('.row-parameter');
|
229
|
var columnValues = $('.column-parameter');
|
230
|
var valueValues = $('.value-parameter');
|
231
|
|
232
|
var index = 0;
|
233
|
|
234
|
rowValues.each(function () {
|
235
|
$(this).find('.parametr-order').attr('value', index);
|
236
|
index++;
|
237
|
});
|
238
|
|
239
|
columnValues.each(function () {
|
240
|
$(this).find('.parametr-order').attr('value', index);
|
241
|
index++;
|
242
|
});
|
243
|
|
244
|
valueValues.each(function () {
|
245
|
$(this).find('.parametr-order').attr('value', index);
|
246
|
index++;
|
247
|
});
|
248
|
}
|
249
|
|
250
|
function checkIfConfigurationNameIsNull() {
|
251
|
var configurationName = document.getElementById('configurationName');
|
252
|
|
253
|
if (configurationName.value == null || configurationName.value == "") {
|
254
|
alert("Není vyplněn název šablony !");
|
255
|
}
|
256
|
}
|
257
|
|
258
|
/**
|
259
|
* Set up listener to export buttons to show spinner
|
260
|
*/
|
261
|
function initSpinnerToButtons() {
|
262
|
hideSpinner();
|
263
|
|
264
|
document.querySelectorAll('.show-spinner').forEach(button => {
|
265
|
button.addEventListener('click', showSpinner);
|
266
|
})
|
267
|
}
|
268
|
|
269
|
function showSpinner() {
|
270
|
let spinner = document.getElementById('spinner-overlay');
|
271
|
|
272
|
spinner.style.display = 'block';
|
273
|
}
|
274
|
|
275
|
function hideSpinner() {
|
276
|
let spinner = document.getElementById('spinner-overlay');
|
277
|
|
278
|
spinner.style.display = 'none';
|
279
|
}
|