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