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 |
|
|
hiddenInput.value = hiddenValue;
|
83 |
|
|
|
84 |
|
|
row.appendChild(hiddenInput);
|
85 |
|
|
|
86 |
|
|
var firstTd = document.createElement('td');
|
87 |
|
|
|
88 |
|
|
var firstTdBody = document.createElement('span');
|
89 |
|
|
firstTdBody.classList.add('parameter-name');
|
90 |
|
|
firstTdBody.innerHTML = parameterName;
|
91 |
|
|
|
92 |
|
|
firstTd.appendChild(firstTdBody);
|
93 |
|
|
|
94 |
|
|
row.appendChild(firstTd);
|
95 |
|
|
|
96 |
|
|
var thirdTd = document.createElement('td');
|
97 |
|
|
|
98 |
|
|
var thirdTdBody;
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
if (type == 'value')
|
102 |
|
|
{
|
103 |
|
|
thirdTdBody = $('#function-select-' + index).clone()[0];
|
104 |
|
|
|
105 |
|
|
$(thirdTdBody).removeClass('hidden');
|
106 |
|
|
}
|
107 |
|
|
else
|
108 |
|
|
{
|
109 |
|
|
var secondTd = document.createElement('td');
|
110 |
|
|
|
111 |
|
|
var secondTdBody = document.createElement('input');
|
112 |
|
|
secondTdBody.type = 'text';
|
113 |
|
|
secondTdBody.classList.add('form-control', 'select-filter-input-name');
|
114 |
|
|
secondTdBody.name = `parametersInConfiguration[${index}].columnName`;
|
115 |
|
|
|
116 |
|
|
secondTd.appendChild(secondTdBody);
|
117 |
|
|
|
118 |
|
|
row.appendChild(secondTd);
|
119 |
|
|
|
120 |
|
|
thirdTdBody = document.createElement('span');
|
121 |
|
|
thirdTdBody.innerHTML = "<i class=\"fas fa-sort\"></i>";
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
thirdTd.appendChild(thirdTdBody);
|
125 |
|
|
|
126 |
|
|
row.appendChild(thirdTd);
|
127 |
|
|
|
128 |
|
|
$('#' + type + '-wrapper').append($(row));
|
129 |
|
|
|
130 |
|
|
}
|
131 |
|
|
|
132 |
d149244c
|
cagy
|
/**
|
133 |
|
|
* Remove specific parameter from fields by name and container
|
134 |
|
|
* @param title
|
135 |
|
|
* @param parameterClass
|
136 |
|
|
*/
|
137 |
b3c57a7c
|
cagy
|
function removeParameter(title, parameterClass) {
|
138 |
|
|
$rows = $('.' + parameterClass + '-parameter');
|
139 |
|
|
|
140 |
|
|
$rows.each(function () {
|
141 |
|
|
$(this).find('.parameter-name').each(function () {
|
142 |
|
|
if ($(this).text() == title)
|
143 |
|
|
{
|
144 |
|
|
$(this).closest('.' + parameterClass + '-parameter').remove();
|
145 |
|
|
}
|
146 |
|
|
})
|
147 |
|
|
});
|
148 |
|
|
}
|
149 |
|
|
|
150 |
d149244c
|
cagy
|
/**
|
151 |
|
|
* Base on class returns type
|
152 |
|
|
* @param context
|
153 |
|
|
* @returns {string}
|
154 |
|
|
*/
|
155 |
b3c57a7c
|
cagy
|
function getParameterType(context) {
|
156 |
|
|
if ($(context).hasClass('column-button'))
|
157 |
|
|
{
|
158 |
|
|
return 'column';
|
159 |
|
|
}
|
160 |
|
|
else if ($(context).hasClass('row-button'))
|
161 |
|
|
{
|
162 |
|
|
return 'row';
|
163 |
|
|
}
|
164 |
|
|
else if ($(context).hasClass('value-button'))
|
165 |
|
|
{
|
166 |
|
|
return 'value';
|
167 |
|
|
}
|
168 |
|
|
}
|
169 |
|
|
|
170 |
d149244c
|
cagy
|
/**
|
171 |
|
|
* Base on type return integer value
|
172 |
|
|
* @param context
|
173 |
|
|
* @returns {number}
|
174 |
|
|
*/
|
175 |
b3c57a7c
|
cagy
|
function getParameterHiddenValue(context) {
|
176 |
|
|
if ($(context).hasClass('column-button'))
|
177 |
|
|
{
|
178 |
|
|
return 1;
|
179 |
|
|
}
|
180 |
|
|
else if ($(context).hasClass('row-button'))
|
181 |
|
|
{
|
182 |
|
|
return 2;
|
183 |
|
|
}
|
184 |
|
|
else if ($(context).hasClass('value-button'))
|
185 |
|
|
{
|
186 |
|
|
return 3;
|
187 |
|
|
}
|
188 |
|
|
}
|
189 |
|
|
|
190 |
d149244c
|
cagy
|
/**
|
191 |
|
|
* Returns parameter name
|
192 |
|
|
* @param context
|
193 |
|
|
* @returns {*|jQuery}
|
194 |
|
|
*/
|
195 |
b3c57a7c
|
cagy
|
function getParameterTitle(context) {
|
196 |
|
|
return $(context).closest('.parameter-row').find('.parameter-name').text();
|
197 |
|
|
}
|
198 |
|
|
|
199 |
d149244c
|
cagy
|
/**
|
200 |
|
|
* Init base actions
|
201 |
|
|
*/
|
202 |
b3c57a7c
|
cagy
|
function initParameters()
|
203 |
|
|
{
|
204 |
|
|
$('.sortable').sortable();
|
205 |
|
|
$("select").selectpicker('refresh');
|
206 |
|
|
}
|