1 |
d149244c
|
cagy
|
/**
|
2 |
|
|
* Default action
|
3 |
|
|
*/
|
4 |
b3c57a7c
|
cagy
|
$(document).ready(function() {
|
5 |
|
|
|
6 |
d149244c
|
cagy
|
// init sorting
|
7 |
b3c57a7c
|
cagy
|
$(".panel-wrapper").sortable({
|
8 |
|
|
stop: function(event, ui) {
|
9 |
d149244c
|
cagy
|
// after switch place reindex parameters
|
10 |
b3c57a7c
|
cagy
|
reindexParametrOrder();
|
11 |
|
|
}
|
12 |
|
|
}).disableSelection();
|
13 |
|
|
|
14 |
d149244c
|
cagy
|
// denny action with buttons with thrash icon
|
15 |
b3c57a7c
|
cagy
|
$('.fa-trash-alt').click(function(event){
|
16 |
|
|
event.preventDefault();
|
17 |
|
|
});
|
18 |
|
|
|
19 |
d149244c
|
cagy
|
// add new collapse after click on button add-param-button
|
20 |
b3c57a7c
|
cagy
|
$('#add-param-button').on('click', function () {
|
21 |
|
|
addCollapse();
|
22 |
|
|
});
|
23 |
|
|
|
24 |
d149244c
|
cagy
|
$('#permission-button').on('click', function () {
|
25 |
|
|
addPermission();
|
26 |
|
|
});
|
27 |
|
|
|
28 |
|
|
// index parameters order
|
29 |
b3c57a7c
|
cagy
|
reindexParametrOrder();
|
30 |
d149244c
|
cagy
|
|
31 |
|
|
// init actions for panel body
|
32 |
b3c57a7c
|
cagy
|
initPanelBody();
|
33 |
|
|
|
34 |
|
|
});
|
35 |
|
|
|
36 |
d149244c
|
cagy
|
/**
|
37 |
|
|
* Get value from permission input and create new input
|
38 |
|
|
*/
|
39 |
|
|
function addPermission()
|
40 |
|
|
{
|
41 |
b3c57a7c
|
cagy
|
var selectedRoleId = $('select[name=permission-select] option').filter(':selected').val();
|
42 |
|
|
var selectedRoleValue = $('select[name=permission-select] option').filter(':selected').text();
|
43 |
|
|
|
44 |
|
|
var addedRoles = $('.permission-role');
|
45 |
|
|
|
46 |
|
|
var roles = [];
|
47 |
|
|
|
48 |
|
|
// get assigned roles
|
49 |
|
|
addedRoles.each(function () {
|
50 |
|
|
roles.push($(this).val())
|
51 |
|
|
});
|
52 |
|
|
|
53 |
|
|
if (roles.includes(selectedRoleId))
|
54 |
|
|
{
|
55 |
|
|
return;
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
addPermissionRow(selectedRoleId, selectedRoleValue);
|
59 |
d149244c
|
cagy
|
}
|
60 |
b3c57a7c
|
cagy
|
|
61 |
|
|
|
62 |
d149244c
|
cagy
|
/**
|
63 |
|
|
* Add new permission input
|
64 |
|
|
* @param id
|
65 |
|
|
* @param value
|
66 |
|
|
*/
|
67 |
b3c57a7c
|
cagy
|
function addPermissionRow(id, value){
|
68 |
|
|
|
69 |
|
|
let row = document.createElement('div');
|
70 |
|
|
row.classList.add('input-action-box', 'input-border-bottom', 'permission-row');
|
71 |
|
|
|
72 |
|
|
let input = document.createElement('input');
|
73 |
|
|
input.type = 'text';
|
74 |
|
|
input.classList.add('form-control-plaintext', 'permission-title');
|
75 |
|
|
input.id = id;
|
76 |
|
|
input.value = value;
|
77 |
|
|
input.setAttribute('readonly', "true");
|
78 |
|
|
|
79 |
|
|
let hiddenInput = document.createElement('input');
|
80 |
|
|
hiddenInput.type = 'hidden';
|
81 |
|
|
hiddenInput.classList.add('permission-role');
|
82 |
|
|
hiddenInput.value = id;
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
row.appendChild(input);
|
86 |
|
|
row.appendChild(hiddenInput);
|
87 |
|
|
|
88 |
|
|
let actionButton = document.createElement('span');
|
89 |
|
|
actionButton.classList.add('action-padding', 'action-button', 'input-action-margin');
|
90 |
|
|
|
91 |
|
|
let deleteButton = document.createElement('span');
|
92 |
|
|
deleteButton.classList.add('action-link', 'far', 'fa-trash-alt');
|
93 |
|
|
deleteButton.setAttribute('onclick', 'removeRole(this);');
|
94 |
|
|
deleteButton.setAttribute('role', 'button');
|
95 |
|
|
|
96 |
|
|
actionButton.appendChild(deleteButton);
|
97 |
|
|
row.appendChild(actionButton);
|
98 |
|
|
|
99 |
|
|
document.getElementById('permission-wrapper').appendChild(row);
|
100 |
|
|
|
101 |
|
|
var permissionRoles = $('.permission-row');
|
102 |
|
|
var permissionIndex = 0;
|
103 |
|
|
|
104 |
|
|
permissionRoles.each(function () {
|
105 |
|
|
var hiddenInput = $(this).find('.permission-role');
|
106 |
|
|
|
107 |
|
|
hiddenInput.attr("id",`roles${permissionIndex}.id`);
|
108 |
|
|
|
109 |
|
|
hiddenInput.attr("name",`roles[${permissionIndex}].id`);
|
110 |
|
|
|
111 |
|
|
var input = $(this).find('.permission-title');
|
112 |
|
|
input.attr("name", `roles[${permissionIndex}].name`);
|
113 |
|
|
input.attr("id", `roles${permissionIndex}.name`);
|
114 |
|
|
permissionIndex++;
|
115 |
|
|
});
|
116 |
|
|
|
117 |
d149244c
|
cagy
|
}
|
118 |
b3c57a7c
|
cagy
|
|
119 |
|
|
|
120 |
d149244c
|
cagy
|
/**
|
121 |
|
|
* Add new enum value for type "Výčet"
|
122 |
|
|
* @param context
|
123 |
|
|
* @param value
|
124 |
|
|
*/
|
125 |
b3c57a7c
|
cagy
|
function addEnumRow(context, value)
|
126 |
|
|
{
|
127 |
|
|
let enumIndex = $(context).closest('.enum_box').find('.enum-index').val();
|
128 |
a9fb2046
|
cagy
|
|
129 |
|
|
var countIndex = 0;
|
130 |
|
|
|
131 |
|
|
// find largest parameter index
|
132 |
|
|
$(".enum-row").each(function ()
|
133 |
|
|
{
|
134 |
|
|
var tmpIndex = Number($(this).find('.enum-parameter-index').val());
|
135 |
|
|
|
136 |
|
|
if (tmpIndex >= countIndex)
|
137 |
|
|
{
|
138 |
|
|
countIndex = tmpIndex + 1;
|
139 |
|
|
}
|
140 |
|
|
});
|
141 |
|
|
|
142 |
b3c57a7c
|
cagy
|
|
143 |
|
|
let row = document.createElement('div');
|
144 |
|
|
row.classList.add('input-action-box', 'input-border-bottom', 'enum-row');
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
let input = document.createElement('input');
|
148 |
|
|
input.type = 'text';
|
149 |
|
|
input.classList.add('form-control-plaintext');
|
150 |
|
|
input.value = value;
|
151 |
|
|
input.setAttribute('readonly', "true");
|
152 |
|
|
input.setAttribute('id', `parameters${enumIndex}.parameterValues${countIndex}.value`);
|
153 |
|
|
input.setAttribute('name', `parameters[${enumIndex}].parameterValues[${countIndex}].value`);
|
154 |
|
|
|
155 |
a9fb2046
|
cagy
|
let inputIndex = document.createElement('input');
|
156 |
|
|
inputIndex.type = 'hidden';
|
157 |
|
|
inputIndex.classList.add('enum-parameter-index');
|
158 |
|
|
inputIndex.setAttribute('value', countIndex);
|
159 |
|
|
|
160 |
b3c57a7c
|
cagy
|
row.appendChild(input);
|
161 |
a9fb2046
|
cagy
|
row.appendChild(inputIndex);
|
162 |
b3c57a7c
|
cagy
|
|
163 |
|
|
let sortSpan = document.createElement('span');
|
164 |
|
|
sortSpan.classList.add('action-padding', 'input-action-margin', 'sort-icon');
|
165 |
|
|
sortSpan.innerHTML = "<i class=\"fas fa-sort\"></i>";
|
166 |
|
|
|
167 |
|
|
row.appendChild(sortSpan);
|
168 |
|
|
|
169 |
|
|
let deleteSpan = document.createElement('span');
|
170 |
|
|
deleteSpan.classList.add('action-padding', 'input-action-margin', 'action-button');
|
171 |
|
|
|
172 |
|
|
let deleteButton = document.createElement('span');
|
173 |
|
|
deleteButton.classList.add('action-link', 'far', 'fa-trash-alt');
|
174 |
|
|
deleteButton.setAttribute('onclick', 'removeEnum(this)');
|
175 |
|
|
|
176 |
|
|
deleteSpan.appendChild(deleteButton);
|
177 |
|
|
|
178 |
|
|
row.appendChild(deleteSpan);
|
179 |
|
|
|
180 |
|
|
$(context).closest(".enum_box").find(".enum-wrapper").append($(row));
|
181 |
|
|
|
182 |
|
|
}
|
183 |
|
|
|
184 |
d149244c
|
cagy
|
/**
|
185 |
|
|
* Remove permission role
|
186 |
|
|
* @param selectedField
|
187 |
|
|
*/
|
188 |
b3c57a7c
|
cagy
|
function removeRole (selectedField) {
|
189 |
|
|
selectedField.closest('.permission-row').remove();
|
190 |
|
|
}
|
191 |
|
|
|
192 |
d149244c
|
cagy
|
/**
|
193 |
|
|
* Show enum box for parameter
|
194 |
|
|
* @param select
|
195 |
|
|
*/
|
196 |
b3c57a7c
|
cagy
|
function showEnum(select) {
|
197 |
|
|
var enumBox = $(select).closest(".panel-collapse").find(".enum_box");
|
198 |
|
|
enumBox.removeClass("hidden");
|
199 |
|
|
}
|
200 |
|
|
|
201 |
d149244c
|
cagy
|
/**
|
202 |
|
|
* Hide enum box for parameter
|
203 |
|
|
* @param select
|
204 |
|
|
*/
|
205 |
b3c57a7c
|
cagy
|
function hideEnum(select) {
|
206 |
|
|
var enumBox = $(select).closest(".panel-collapse").find(".enum_box");
|
207 |
|
|
enumBox.addClass("hidden");
|
208 |
|
|
}
|
209 |
|
|
|
210 |
d149244c
|
cagy
|
/**
|
211 |
|
|
* Remove enum value
|
212 |
|
|
* @param select
|
213 |
|
|
*/
|
214 |
b3c57a7c
|
cagy
|
function removeEnum(select) {
|
215 |
|
|
$(select).closest(".enum-row").remove();
|
216 |
|
|
}
|
217 |
|
|
|
218 |
d149244c
|
cagy
|
/**
|
219 |
|
|
* Remove parameter
|
220 |
|
|
* @param panel
|
221 |
|
|
*/
|
222 |
b3c57a7c
|
cagy
|
function removePanel(panel) {
|
223 |
|
|
var r = confirm("Opravdu si přejete odstranit parametr?");
|
224 |
|
|
if (r == true) {
|
225 |
|
|
$(panel).closest(".parameter").remove();
|
226 |
|
|
}
|
227 |
|
|
|
228 |
|
|
}
|
229 |
|
|
|
230 |
d149244c
|
cagy
|
/**
|
231 |
|
|
* Add new parameter
|
232 |
|
|
*/
|
233 |
b3c57a7c
|
cagy
|
function addCollapse() {
|
234 |
|
|
|
235 |
a9e9c158
|
cagy
|
var index = 0;
|
236 |
|
|
|
237 |
|
|
// find largest parameter index
|
238 |
|
|
$(".parameter").each(function ()
|
239 |
|
|
{
|
240 |
|
|
var tmpIndex = Number($(this).find('.enum-index').val());
|
241 |
|
|
|
242 |
|
|
if (tmpIndex >= index)
|
243 |
|
|
{
|
244 |
|
|
index = tmpIndex + 1;
|
245 |
|
|
}
|
246 |
|
|
});
|
247 |
b3c57a7c
|
cagy
|
|
248 |
|
|
var typeSelectValues = $("#allParametersHiddenSelect").html();
|
249 |
|
|
var functionSelectValues = $("#allFunctionsHiddenSelect").html();
|
250 |
|
|
var operatorSelectValues = $("#allOperatorsHiddenSelect").html();
|
251 |
|
|
|
252 |
d149244c
|
cagy
|
// parameter body
|
253 |
b3c57a7c
|
cagy
|
$(".panel-wrapper").append('\n' +
|
254 |
|
|
' <div class="panel-group parameter">\n' +
|
255 |
|
|
` <input type="hidden" class="parametr-order" value="0" id="parameters${index}.parameterOrder" name="parameters[${index}].parameterOrder">\n` +
|
256 |
|
|
' <div class="panel panel-default">\n' +
|
257 |
|
|
' <div class="panel-heading">\n' +
|
258 |
|
|
' <span class="panel-title">\n' +
|
259 |
|
|
` <a data-toggle="collapse" data-parent="#accordion" href=#collapse${index}>\n` +
|
260 |
|
|
` <i class="fas fa-angle-right"></i> Nový parametr\n` +
|
261 |
|
|
' </a>\n' +
|
262 |
|
|
' <span class="align-right collapse-actions">\n' +
|
263 |
|
|
' <span class="action-padding input-action-margin-collapse sort-icon">\n' +
|
264 |
|
|
' <i class="fas fa-sort"></i>\n' +
|
265 |
|
|
' </span>\n' +
|
266 |
|
|
' <span class="action-padding action-button input-action-margin-collapse">\n' +
|
267 |
|
|
' <span href=# class="action-link far fa-trash-alt" onclick="removePanel(this);"></span>\n' +
|
268 |
|
|
' </span>\n' +
|
269 |
|
|
' </span>\n' +
|
270 |
|
|
' </span>\n' +
|
271 |
|
|
' </div>\n' +
|
272 |
|
|
` <div id="collapse${index}" class="panel-collapse collapse">\n` +
|
273 |
|
|
' <div class="panel-body">\n' +
|
274 |
|
|
' <div class="form-group row">\n' +
|
275 |
|
|
' <label for="name" class="col-sm-2 col-form-label">Název:</label>\n' +
|
276 |
|
|
' <div class="col-sm-10">\n' +
|
277 |
|
|
` <input type="text" class="form-control" name="parameters[${index}].name" id="parameterName${index}" value="Nový parametr" required>\n` +
|
278 |
|
|
' </div>\n' +
|
279 |
|
|
' </div>\n' +
|
280 |
|
|
' <div class="form-group row">\n' +
|
281 |
|
|
' <label for="name" class="col-sm-2 col-form-label">V SQL:</label>\n' +
|
282 |
|
|
' <div class="col-sm-10">\n' +
|
283 |
|
|
` <input type="text" class="form-control" name="parameters[${index}].nameOfSelect" id="parameterSQLName${index}" required>\n` +
|
284 |
|
|
' </div>\n' +
|
285 |
|
|
' </div>\n' +
|
286 |
|
|
' <div class="form-group row">\n' +
|
287 |
|
|
' <label for="exampleFormControlSelect1" class="col-sm-2">Typ:</label>\n' +
|
288 |
|
|
' <div class="col-sm-10">\n' +
|
289 |
|
|
` <select name="parameters[${index}].parameterType" class="form-control type-select">\n` +
|
290 |
|
|
typeSelectValues+
|
291 |
|
|
' </select>\n' +
|
292 |
|
|
' </div>\n' +
|
293 |
|
|
' </div>\n' +
|
294 |
|
|
'\n' +
|
295 |
|
|
' <div class="enum_box">\n' +
|
296 |
|
|
' Hodnoty:\n' +
|
297 |
|
|
' <div class="enum_values col-md-8">\n' +
|
298 |
|
|
' <div class="enum-wrapper">\n' +
|
299 |
|
|
` <input type="hidden" class="enum-index" value="${index}">\n` +
|
300 |
|
|
' </div>\n' +
|
301 |
|
|
'\n' +
|
302 |
|
|
' <div class="form-group row form-add-item">\n' +
|
303 |
|
|
' <div class="col-md-9">\n' +
|
304 |
|
|
' <input type="text" class="form-control enum-add-input">\n' +
|
305 |
|
|
' </div>\n' +
|
306 |
|
|
' <span class="btn btn-primary mb-2 enum-add-button">Přidat</span>\n' +
|
307 |
|
|
' </div>\n' +
|
308 |
|
|
' </div>\n' +
|
309 |
|
|
' </div>\n' +
|
310 |
|
|
'\n' +
|
311 |
|
|
` <div class="form-group row">\n` +
|
312 |
|
|
' <label for="exampleFormControlSelect1" class="col-sm-2">Umístění:</label>\n' +
|
313 |
|
|
' <div class="col-sm-10">\n' +
|
314 |
|
|
' <div class="form-check form-check-inline">\n' +
|
315 |
|
|
` <input type="hidden" name="_parameters[${index}].locations" value="on">\n` +
|
316 |
|
|
` <input class="form-check-input" name="parameters[${index}].locations" id="parameters${index}.locations1" type="checkbox" value="1">\n` +
|
317 |
|
|
` <label class="form-check-label" for="parameters[${index}].locations" >Sloupec</label>\n` +
|
318 |
|
|
' </div>\n' +
|
319 |
|
|
' <div class="form-check form-check-inline">\n' +
|
320 |
|
|
` <input type="hidden" name="_parameters[${index}].locations" value="on">\n` +
|
321 |
|
|
` <input class="form-check-input" name="parameters[${index}].locations" id="parameters${index}.locations2" type="checkbox" value="2">\n` +
|
322 |
|
|
' <label class="form-check-label" for="parameters[${index}].locations">Řádek</label>\n' +
|
323 |
|
|
' </div>\n' +
|
324 |
|
|
' <div class="form-check form-check-inline">\n' +
|
325 |
|
|
` <input type="hidden" name="_parameters[${index}].locations" value="on">\n` +
|
326 |
|
|
` <input class="form-check-input" name="parameters[${index}].locations" id="parameters${index}.locations3" type="checkbox" value="3">\n` +
|
327 |
|
|
' <label class="form-check-label" for="parameters[${index}].locations" >Hodnota</label>\n' +
|
328 |
|
|
' </div>\n' +
|
329 |
|
|
' </div>\n' +
|
330 |
|
|
' </div>\n' +
|
331 |
|
|
' <div class="form-group row">\n' +
|
332 |
|
|
' <label for="exampleFormControlSelect1" class="col-sm-2">Funkce:</label>\n' +
|
333 |
|
|
' <div class="col-sm-10">\n' +
|
334 |
|
|
` <select name="parameters[${index}].functions" id="parameters${index}.functions" class="mbSelect selectpicker" multiple data-live-search="true">\n` +
|
335 |
|
|
functionSelectValues +
|
336 |
|
|
' </select>\n' +
|
337 |
|
|
' </div>\n' +
|
338 |
|
|
' </div>\n' +
|
339 |
|
|
' <div class="form-group row">\n' +
|
340 |
|
|
' <label for="exampleFormControlSelect1" class="col-sm-2">Operátory:</label>\n' +
|
341 |
|
|
' <div class="col-sm-10">\n' +
|
342 |
|
|
` <select name="parameters[${index}].operators" id="parameters${index}.operators" class="mbSelect selectpicker" multiple data-live-search="true">\n` +
|
343 |
|
|
operatorSelectValues +
|
344 |
|
|
' </select>\n' +
|
345 |
|
|
' </div>\n' +
|
346 |
|
|
' </div>\n' +
|
347 |
|
|
' </div>\n' +
|
348 |
|
|
' </div>\n' +
|
349 |
|
|
' </div>\n' +
|
350 |
|
|
' </div>\n' +
|
351 |
|
|
' ');
|
352 |
|
|
|
353 |
|
|
this.reindexParametrOrder();
|
354 |
|
|
this.initPanelBody();
|
355 |
|
|
|
356 |
|
|
}
|
357 |
|
|
|
358 |
d149244c
|
cagy
|
/**
|
359 |
|
|
* Init scripts for parameters body
|
360 |
|
|
*/
|
361 |
b3c57a7c
|
cagy
|
function initPanelBody() {
|
362 |
|
|
$('.enum-add-button').on('click', function () {
|
363 |
|
|
var input = $(this).closest(".row").find('.enum-add-input');
|
364 |
|
|
addEnumRow(this, input.val());
|
365 |
|
|
|
366 |
|
|
input.val("");
|
367 |
|
|
});
|
368 |
|
|
|
369 |
|
|
$('.enum-wrapper').sortable().disableSelection();
|
370 |
|
|
|
371 |
|
|
$('.type-select').on('change', function () {
|
372 |
|
|
if (this.value == 1)
|
373 |
|
|
{
|
374 |
|
|
showEnum(this);
|
375 |
|
|
}
|
376 |
|
|
else
|
377 |
|
|
{
|
378 |
|
|
hideEnum(this);
|
379 |
|
|
}
|
380 |
|
|
});
|
381 |
|
|
|
382 |
|
|
$(".selectpicker").selectpicker('refresh');
|
383 |
|
|
|
384 |
|
|
$('.fa-trash-alt').click(function(event){
|
385 |
|
|
event.preventDefault();
|
386 |
|
|
});
|
387 |
|
|
}
|
388 |
|
|
|
389 |
d149244c
|
cagy
|
/**
|
390 |
|
|
* Reindex parameter body order
|
391 |
|
|
*/
|
392 |
b3c57a7c
|
cagy
|
function reindexParametrOrder() {
|
393 |
|
|
var data = $(".parametr-order");
|
394 |
|
|
|
395 |
|
|
let index = 0;
|
396 |
|
|
$(data).each(function () {
|
397 |
|
|
$(this).attr('value', index);
|
398 |
|
|
index++;
|
399 |
|
|
});
|
400 |
|
|
}
|