1 |
2111fb8f
|
cagy
|
let ROW = 'row';
|
2 |
|
|
let COLUMN = 'column';
|
3 |
|
|
let VALUE = 'value';
|
4 |
|
|
|
5 |
b3c57a7c
|
cagy
|
$(document).ready(function() {
|
6 |
|
|
|
7 |
74db519b
|
cagy
|
// init handlers for position buttons
|
8 |
|
|
initPositionButtons();
|
9 |
|
|
|
10 |
|
|
// init actions
|
11 |
|
|
initParameters();
|
12 |
|
|
|
13 |
|
|
// spinner init
|
14 |
|
|
initSpinnerToButtons();
|
15 |
|
|
|
16 |
|
|
// generation init
|
17 |
|
|
initTableGenerationButtons();
|
18 |
|
|
|
19 |
|
|
// sort selected parameters
|
20 |
|
|
initSelectedParameters();
|
21 |
|
|
|
22 |
|
|
// set up tooltips
|
23 |
|
|
initTooltips();
|
24 |
|
|
|
25 |
|
|
});
|
26 |
|
|
|
27 |
|
|
/**
|
28 |
|
|
* Sets up functionality for position buttons (add/remove elements from position box), headlights
|
29 |
|
|
*/
|
30 |
|
|
function initPositionButtons() {
|
31 |
d149244c
|
cagy
|
// reaction for add/delete parameters from selected fields (row, column, value)
|
32 |
b3c57a7c
|
cagy
|
$('.select-action-button').on('click', function () {
|
33 |
d149244c
|
cagy
|
// if input has headlight class (parameter is already added -> remove)
|
34 |
b3c57a7c
|
cagy
|
if ($(this).hasClass('select-action-headlight'))
|
35 |
|
|
{
|
36 |
d149244c
|
cagy
|
// remove headlight class from type
|
37 |
b3c57a7c
|
cagy
|
$(this).removeClass('select-action-headlight');
|
38 |
d149244c
|
cagy
|
|
39 |
|
|
// remove parameter from selected inputs
|
40 |
b3c57a7c
|
cagy
|
removeParameter(getParameterTitle($(this)), getParameterType($(this)));
|
41 |
|
|
}
|
42 |
|
|
else
|
43 |
|
|
{
|
44 |
d149244c
|
cagy
|
// remove headlight from other types for parameter if exists
|
45 |
b3c57a7c
|
cagy
|
$(this).closest('.select-action-buttons').find('.select-action-button').removeClass('select-action-headlight');
|
46 |
|
|
|
47 |
d149244c
|
cagy
|
// remove element from selected inputs if exists
|
48 |
b3c57a7c
|
cagy
|
removeFromAll(getParameterTitle($(this)));
|
49 |
|
|
|
50 |
d149244c
|
cagy
|
// headlight selected input
|
51 |
b3c57a7c
|
cagy
|
$(this).addClass('select-action-headlight');
|
52 |
|
|
|
53 |
d149244c
|
cagy
|
// add selected parameter to selected parameters by type
|
54 |
b3c57a7c
|
cagy
|
addParameter(getParameterIndex($(this)),
|
55 |
|
|
getParameterTitle($(this)),
|
56 |
|
|
getParameterType($(this)),
|
57 |
|
|
getParameterHiddenValue($(this)));
|
58 |
|
|
|
59 |
d149244c
|
cagy
|
// reinitialize actions for new parameter
|
60 |
b3c57a7c
|
cagy
|
initParameters();
|
61 |
|
|
}
|
62 |
2111fb8f
|
cagy
|
|
63 |
|
|
validateCombination();
|
64 |
b3c57a7c
|
cagy
|
});
|
65 |
74db519b
|
cagy
|
}
|
66 |
b3c57a7c
|
cagy
|
|
67 |
d149244c
|
cagy
|
/**
|
68 |
|
|
* Remove value from all selected fields
|
69 |
|
|
* @param title
|
70 |
|
|
*/
|
71 |
b3c57a7c
|
cagy
|
function removeFromAll(title) {
|
72 |
|
|
$rows = $('.selected-input-container');
|
73 |
|
|
|
74 |
|
|
$rows.each(function () {
|
75 |
|
|
$(this).find('.parameter-name').each(function () {
|
76 |
|
|
if ($(this).text() == title)
|
77 |
|
|
{
|
78 |
|
|
$(this).closest('.parameter').remove();
|
79 |
|
|
}
|
80 |
|
|
})
|
81 |
|
|
});
|
82 |
|
|
}
|
83 |
|
|
|
84 |
d149244c
|
cagy
|
/**
|
85 |
|
|
* Returns parameter index
|
86 |
|
|
* @param button
|
87 |
|
|
* @returns {*|jQuery|string|undefined}
|
88 |
|
|
*/
|
89 |
b3c57a7c
|
cagy
|
function getParameterIndex(button) {
|
90 |
|
|
return $(button).closest('.parameter-row').find('.parameterIndex').val();
|
91 |
|
|
}
|
92 |
|
|
|
93 |
d149244c
|
cagy
|
/**
|
94 |
|
|
* Adds new parameter to selected fields
|
95 |
|
|
* @param index
|
96 |
|
|
* @param parameterName
|
97 |
|
|
* @param type
|
98 |
|
|
* @param hiddenValue
|
99 |
|
|
*/
|
100 |
b3c57a7c
|
cagy
|
function addParameter(index, parameterName, type, hiddenValue) {
|
101 |
74db519b
|
cagy
|
// basic set up for mapping element to dao object
|
102 |
b3c57a7c
|
cagy
|
var row = document.createElement('tr');
|
103 |
|
|
row.classList.add(type + '-parameter', 'parameter');
|
104 |
|
|
|
105 |
|
|
let hiddenInput = document.createElement('input');
|
106 |
|
|
hiddenInput.type = 'hidden';
|
107 |
|
|
hiddenInput.id = `parametersInConfiguration${index}.location.id`;
|
108 |
|
|
hiddenInput.name = `parametersInConfiguration[${index}].location.id`;
|
109 |
36a626d9
|
cagy
|
hiddenInput.setAttribute('value', hiddenValue);
|
110 |
|
|
|
111 |
|
|
let hiddenInputOrder = document.createElement('input');
|
112 |
|
|
hiddenInputOrder.type = 'hidden';
|
113 |
|
|
hiddenInputOrder.id = `parametersInConfiguration${index}.parameterOrder`;
|
114 |
|
|
hiddenInputOrder.name = `parametersInConfiguration[${index}].parameterOrder`;
|
115 |
|
|
hiddenInputOrder.classList.add('parametr-order');
|
116 |
b3c57a7c
|
cagy
|
|
117 |
|
|
row.appendChild(hiddenInput);
|
118 |
36a626d9
|
cagy
|
row.appendChild(hiddenInputOrder);
|
119 |
b3c57a7c
|
cagy
|
|
120 |
|
|
var firstTd = document.createElement('td');
|
121 |
|
|
|
122 |
|
|
var firstTdBody = document.createElement('span');
|
123 |
|
|
firstTdBody.classList.add('parameter-name');
|
124 |
|
|
firstTdBody.innerHTML = parameterName;
|
125 |
|
|
|
126 |
|
|
firstTd.appendChild(firstTdBody);
|
127 |
|
|
|
128 |
|
|
row.appendChild(firstTd);
|
129 |
|
|
|
130 |
|
|
var thirdTd = document.createElement('td');
|
131 |
|
|
|
132 |
|
|
var thirdTdBody;
|
133 |
|
|
|
134 |
74db519b
|
cagy
|
// for value copy hidden select
|
135 |
2111fb8f
|
cagy
|
if (type == VALUE)
|
136 |
b3c57a7c
|
cagy
|
{
|
137 |
74db519b
|
cagy
|
// get parameter select for functions
|
138 |
|
|
thirdTdBody = $('#tmp-function-select-' + index).clone()[0];
|
139 |
|
|
|
140 |
|
|
// set up id for select
|
141 |
|
|
thirdTdBody.id = `parametersInConfiguration${index}.functions`;
|
142 |
|
|
|
143 |
|
|
// set up name for select
|
144 |
|
|
thirdTdBody.name = `parametersInConfiguration[${index}].functions`;
|
145 |
|
|
|
146 |
|
|
// select first option
|
147 |
2f725e7f
|
cagy
|
thirdTdBody.selectedIndex = 0;
|
148 |
b3c57a7c
|
cagy
|
|
149 |
74db519b
|
cagy
|
// remove hidden class
|
150 |
b3c57a7c
|
cagy
|
$(thirdTdBody).removeClass('hidden');
|
151 |
|
|
}
|
152 |
74db519b
|
cagy
|
// for row and column add textfield
|
153 |
b3c57a7c
|
cagy
|
else
|
154 |
|
|
{
|
155 |
|
|
var secondTd = document.createElement('td');
|
156 |
|
|
|
157 |
|
|
var secondTdBody = document.createElement('input');
|
158 |
|
|
secondTdBody.type = 'text';
|
159 |
|
|
secondTdBody.classList.add('form-control', 'select-filter-input-name');
|
160 |
|
|
secondTdBody.name = `parametersInConfiguration[${index}].columnName`;
|
161 |
|
|
|
162 |
|
|
secondTd.appendChild(secondTdBody);
|
163 |
|
|
|
164 |
|
|
row.appendChild(secondTd);
|
165 |
|
|
|
166 |
|
|
thirdTdBody = document.createElement('span');
|
167 |
|
|
thirdTdBody.innerHTML = "<i class=\"fas fa-sort\"></i>";
|
168 |
|
|
}
|
169 |
|
|
|
170 |
|
|
thirdTd.appendChild(thirdTdBody);
|
171 |
|
|
|
172 |
|
|
row.appendChild(thirdTd);
|
173 |
|
|
|
174 |
74db519b
|
cagy
|
// append element to type wrapper
|
175 |
b3c57a7c
|
cagy
|
$('#' + type + '-wrapper').append($(row));
|
176 |
|
|
|
177 |
74db519b
|
cagy
|
// reindex parameters order
|
178 |
36a626d9
|
cagy
|
reindexOrder();
|
179 |
|
|
|
180 |
b3c57a7c
|
cagy
|
}
|
181 |
|
|
|
182 |
d149244c
|
cagy
|
/**
|
183 |
|
|
* Remove specific parameter from fields by name and container
|
184 |
|
|
* @param title
|
185 |
|
|
* @param parameterClass
|
186 |
|
|
*/
|
187 |
b3c57a7c
|
cagy
|
function removeParameter(title, parameterClass) {
|
188 |
|
|
$rows = $('.' + parameterClass + '-parameter');
|
189 |
|
|
|
190 |
|
|
$rows.each(function () {
|
191 |
|
|
$(this).find('.parameter-name').each(function () {
|
192 |
|
|
if ($(this).text() == title)
|
193 |
|
|
{
|
194 |
|
|
$(this).closest('.' + parameterClass + '-parameter').remove();
|
195 |
|
|
}
|
196 |
|
|
})
|
197 |
|
|
});
|
198 |
|
|
}
|
199 |
|
|
|
200 |
d149244c
|
cagy
|
/**
|
201 |
|
|
* Base on class returns type
|
202 |
|
|
* @param context
|
203 |
|
|
* @returns {string}
|
204 |
|
|
*/
|
205 |
b3c57a7c
|
cagy
|
function getParameterType(context) {
|
206 |
|
|
if ($(context).hasClass('column-button'))
|
207 |
|
|
{
|
208 |
2111fb8f
|
cagy
|
return COLUMN;
|
209 |
b3c57a7c
|
cagy
|
}
|
210 |
|
|
else if ($(context).hasClass('row-button'))
|
211 |
|
|
{
|
212 |
2111fb8f
|
cagy
|
return ROW;
|
213 |
b3c57a7c
|
cagy
|
}
|
214 |
|
|
else if ($(context).hasClass('value-button'))
|
215 |
|
|
{
|
216 |
2111fb8f
|
cagy
|
return VALUE;
|
217 |
b3c57a7c
|
cagy
|
}
|
218 |
|
|
}
|
219 |
|
|
|
220 |
d149244c
|
cagy
|
/**
|
221 |
|
|
* Base on type return integer value
|
222 |
|
|
* @param context
|
223 |
|
|
* @returns {number}
|
224 |
|
|
*/
|
225 |
b3c57a7c
|
cagy
|
function getParameterHiddenValue(context) {
|
226 |
|
|
if ($(context).hasClass('column-button'))
|
227 |
|
|
{
|
228 |
|
|
return 1;
|
229 |
|
|
}
|
230 |
|
|
else if ($(context).hasClass('row-button'))
|
231 |
|
|
{
|
232 |
|
|
return 2;
|
233 |
|
|
}
|
234 |
|
|
else if ($(context).hasClass('value-button'))
|
235 |
|
|
{
|
236 |
|
|
return 3;
|
237 |
|
|
}
|
238 |
|
|
}
|
239 |
|
|
|
240 |
d149244c
|
cagy
|
/**
|
241 |
|
|
* Returns parameter name
|
242 |
|
|
* @param context
|
243 |
|
|
* @returns {*|jQuery}
|
244 |
|
|
*/
|
245 |
b3c57a7c
|
cagy
|
function getParameterTitle(context) {
|
246 |
|
|
return $(context).closest('.parameter-row').find('.parameter-name').text();
|
247 |
|
|
}
|
248 |
|
|
|
249 |
d149244c
|
cagy
|
/**
|
250 |
74db519b
|
cagy
|
* Allow sort on parameters
|
251 |
d149244c
|
cagy
|
*/
|
252 |
b3c57a7c
|
cagy
|
function initParameters()
|
253 |
|
|
{
|
254 |
36a626d9
|
cagy
|
$('.sortable').sortable({
|
255 |
|
|
stop: function () {
|
256 |
74db519b
|
cagy
|
// after change reindex parameters order
|
257 |
36a626d9
|
cagy
|
reindexOrder();
|
258 |
|
|
}
|
259 |
|
|
});
|
260 |
b3c57a7c
|
cagy
|
$("select").selectpicker('refresh');
|
261 |
36a626d9
|
cagy
|
}
|
262 |
|
|
|
263 |
|
|
/**
|
264 |
|
|
* Update parametr order
|
265 |
|
|
*/
|
266 |
|
|
function reindexOrder() {
|
267 |
|
|
var rowValues = $('.row-parameter');
|
268 |
|
|
var columnValues = $('.column-parameter');
|
269 |
|
|
var valueValues = $('.value-parameter');
|
270 |
|
|
|
271 |
|
|
var index = 0;
|
272 |
|
|
|
273 |
|
|
rowValues.each(function () {
|
274 |
|
|
$(this).find('.parametr-order').attr('value', index);
|
275 |
|
|
index++;
|
276 |
|
|
});
|
277 |
|
|
|
278 |
|
|
columnValues.each(function () {
|
279 |
|
|
$(this).find('.parametr-order').attr('value', index);
|
280 |
|
|
index++;
|
281 |
|
|
});
|
282 |
|
|
|
283 |
|
|
valueValues.each(function () {
|
284 |
|
|
$(this).find('.parametr-order').attr('value', index);
|
285 |
|
|
index++;
|
286 |
|
|
});
|
287 |
10920ea3
|
Vojtěch Danišík
|
}
|
288 |
36a626d9
|
cagy
|
|
289 |
10920ea3
|
Vojtěch Danišík
|
function checkIfConfigurationNameIsNull() {
|
290 |
|
|
var configurationName = document.getElementById('configurationName');
|
291 |
36a626d9
|
cagy
|
|
292 |
10920ea3
|
Vojtěch Danišík
|
if (configurationName.value == null || configurationName.value == "") {
|
293 |
|
|
alert("Není vyplněn název šablony !");
|
294 |
|
|
}
|
295 |
0486d642
|
cagy
|
}
|
296 |
|
|
|
297 |
|
|
/**
|
298 |
|
|
* Set up listener to export buttons to show spinner
|
299 |
|
|
*/
|
300 |
|
|
function initSpinnerToButtons() {
|
301 |
|
|
hideSpinner();
|
302 |
|
|
|
303 |
|
|
document.querySelectorAll('.show-spinner').forEach(button => {
|
304 |
|
|
button.addEventListener('click', showSpinner);
|
305 |
fb86dc6a
|
cagy
|
});
|
306 |
|
|
|
307 |
|
|
// check for form response to hide spinner
|
308 |
|
|
$('#assembly-form').on('submit',function(e){
|
309 |
|
|
|
310 |
|
|
// csfr protection
|
311 |
|
|
var token = $("meta[name='_csrf']").attr("content");
|
312 |
|
|
|
313 |
|
|
$.ajax({
|
314 |
|
|
url: $('#form').attr('action'),
|
315 |
|
|
headers: {"X-CSRF-TOKEN": token},
|
316 |
|
|
type: 'POST',
|
317 |
|
|
contentType: "application/json; charset=utf-8",
|
318 |
|
|
data : $('#assembly-form').serialize(),
|
319 |
|
|
complete: function () {
|
320 |
|
|
hideSpinner();
|
321 |
|
|
}
|
322 |
|
|
});
|
323 |
|
|
});
|
324 |
0486d642
|
cagy
|
}
|
325 |
|
|
|
326 |
2111fb8f
|
cagy
|
/**
|
327 |
|
|
* Shows spinner with overlay
|
328 |
|
|
*/
|
329 |
0486d642
|
cagy
|
function showSpinner() {
|
330 |
|
|
let spinner = document.getElementById('spinner-overlay');
|
331 |
|
|
|
332 |
|
|
spinner.style.display = 'block';
|
333 |
|
|
}
|
334 |
|
|
|
335 |
2111fb8f
|
cagy
|
/**
|
336 |
|
|
* Hides spinner with overlay
|
337 |
|
|
*/
|
338 |
0486d642
|
cagy
|
function hideSpinner() {
|
339 |
|
|
let spinner = document.getElementById('spinner-overlay');
|
340 |
|
|
|
341 |
|
|
spinner.style.display = 'none';
|
342 |
2111fb8f
|
cagy
|
}
|
343 |
|
|
|
344 |
|
|
/**
|
345 |
|
|
* Table generation button validator
|
346 |
|
|
* If row is selected allow to generate
|
347 |
|
|
* if column is selected, value and row must be also selected
|
348 |
|
|
*/
|
349 |
|
|
function initTableGenerationButtons() {
|
350 |
|
|
validateCombination();
|
351 |
|
|
}
|
352 |
|
|
|
353 |
|
|
/**
|
354 |
|
|
* Check action buttons combination
|
355 |
|
|
*/
|
356 |
|
|
function validateCombination() {
|
357 |
|
|
let selectedActionButtons = $('.select-action-headlight');
|
358 |
|
|
|
359 |
|
|
var rowSelected = false;
|
360 |
|
|
var columnSelected = false;
|
361 |
|
|
var valueSelected = false;
|
362 |
|
|
|
363 |
|
|
// check selected buttons
|
364 |
|
|
selectedActionButtons.each(function () {
|
365 |
|
|
let type = getParameterType($(this));
|
366 |
|
|
|
367 |
|
|
switch (type) {
|
368 |
|
|
case VALUE:
|
369 |
|
|
valueSelected = true;
|
370 |
|
|
break;
|
371 |
|
|
case ROW:
|
372 |
|
|
rowSelected = true;
|
373 |
|
|
break;
|
374 |
|
|
case COLUMN:
|
375 |
|
|
columnSelected = true;
|
376 |
|
|
break;
|
377 |
|
|
}
|
378 |
|
|
});
|
379 |
|
|
|
380 |
|
|
// possible combinations with allowed export
|
381 |
|
|
if (rowSelected && columnSelected && valueSelected)
|
382 |
|
|
{
|
383 |
|
|
allowExport();
|
384 |
|
|
}
|
385 |
|
|
else if (columnSelected && !rowSelected && !valueSelected)
|
386 |
|
|
{
|
387 |
|
|
allowExport();
|
388 |
|
|
}
|
389 |
|
|
else
|
390 |
|
|
{
|
391 |
|
|
disableExportButtons();
|
392 |
|
|
}
|
393 |
|
|
|
394 |
|
|
|
395 |
|
|
}
|
396 |
|
|
|
397 |
|
|
/**
|
398 |
|
|
* Disables buttons for export
|
399 |
|
|
*/
|
400 |
|
|
function disableExportButtons() {
|
401 |
|
|
$('.show-spinner').attr('disabled','disabled');
|
402 |
|
|
}
|
403 |
|
|
|
404 |
|
|
/**
|
405 |
|
|
* Allow buttons for export
|
406 |
|
|
*/
|
407 |
|
|
function allowExport() {
|
408 |
|
|
$('.show-spinner').removeAttr('disabled');
|
409 |
d9b0bac7
|
cagy
|
}
|
410 |
|
|
|
411 |
|
|
/**
|
412 |
|
|
* Sort selected parameters by order
|
413 |
|
|
*/
|
414 |
|
|
function initSelectedParameters() {
|
415 |
|
|
|
416 |
|
|
sortSelectedParameters('.column-parameter', '#column-wrapper');
|
417 |
|
|
sortSelectedParameters('.row-parameter', '#row-wrapper');
|
418 |
|
|
|
419 |
|
|
}
|
420 |
|
|
|
421 |
|
|
/**
|
422 |
|
|
* Checks and sort specific parameters
|
423 |
|
|
* @param parameterName
|
424 |
|
|
* @param parameterWrapper
|
425 |
|
|
*/
|
426 |
|
|
function sortSelectedParameters(parameterName, parameterWrapper) {
|
427 |
|
|
|
428 |
|
|
var tmpArray = [];
|
429 |
|
|
|
430 |
|
|
var parameters = $(parameterName);
|
431 |
|
|
|
432 |
|
|
// load specific parameters to array orderIndex => parameter
|
433 |
|
|
parameters.each(function () {
|
434 |
|
|
var orderIndex = $(this).find('.parametr-order').val();
|
435 |
|
|
|
436 |
|
|
tmpArray[orderIndex] = $(this);
|
437 |
|
|
|
438 |
|
|
});
|
439 |
|
|
|
440 |
|
|
// sort parameters by key (order index)
|
441 |
|
|
tmpArray.sort((a, b) => a - b);
|
442 |
|
|
|
443 |
|
|
let wrapper = $(parameterWrapper);
|
444 |
|
|
|
445 |
|
|
// clear wrapper
|
446 |
|
|
wrapper.empty();
|
447 |
|
|
|
448 |
|
|
// append sorted elements
|
449 |
|
|
wrapper.append(tmpArray);
|
450 |
121f8add
|
cagy
|
}
|
451 |
|
|
|
452 |
|
|
/**
|
453 |
|
|
* Set up tooltips
|
454 |
|
|
*/
|
455 |
|
|
function initTooltips() {
|
456 |
|
|
$('[data-toggle="tooltip"]').tooltip();
|
457 |
b3c57a7c
|
cagy
|
}
|