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
|
});
|
40
|
|
41
|
/**
|
42
|
* Remove value from all selected fields
|
43
|
* @param title
|
44
|
*/
|
45
|
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
|
/**
|
59
|
* Returns parameter index
|
60
|
* @param button
|
61
|
* @returns {*|jQuery|string|undefined}
|
62
|
*/
|
63
|
function getParameterIndex(button) {
|
64
|
return $(button).closest('.parameter-row').find('.parameterIndex').val();
|
65
|
}
|
66
|
|
67
|
/**
|
68
|
* Adds new parameter to selected fields
|
69
|
* @param index
|
70
|
* @param parameterName
|
71
|
* @param type
|
72
|
* @param hiddenValue
|
73
|
*/
|
74
|
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
|
/**
|
133
|
* Remove specific parameter from fields by name and container
|
134
|
* @param title
|
135
|
* @param parameterClass
|
136
|
*/
|
137
|
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
|
/**
|
151
|
* Base on class returns type
|
152
|
* @param context
|
153
|
* @returns {string}
|
154
|
*/
|
155
|
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
|
/**
|
171
|
* Base on type return integer value
|
172
|
* @param context
|
173
|
* @returns {number}
|
174
|
*/
|
175
|
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
|
/**
|
191
|
* Returns parameter name
|
192
|
* @param context
|
193
|
* @returns {*|jQuery}
|
194
|
*/
|
195
|
function getParameterTitle(context) {
|
196
|
return $(context).closest('.parameter-row').find('.parameter-name').text();
|
197
|
}
|
198
|
|
199
|
/**
|
200
|
* Init base actions
|
201
|
*/
|
202
|
function initParameters()
|
203
|
{
|
204
|
$('.sortable').sortable();
|
205
|
$("select").selectpicker('refresh');
|
206
|
}
|