Projekt

Obecné

Profil

Stáhnout (12.2 KB) Statistiky
| Větev: | Revize:
1

    
2
$(document).ready(function() {
3

    
4
    $(".panel-wrapper").sortable({
5
        stop: function(event, ui) {
6
            reindexParametrOrder();
7
        }
8
    }).disableSelection();
9

    
10

    
11
    $('.fa-trash-alt').click(function(event){
12
        event.preventDefault();
13
    });
14

    
15
    $('#add-param-button').on('click', function () {
16
        addCollapse();
17
    });
18

    
19
    reindexParametrOrder();
20
    initPanelBody();
21

    
22
});
23

    
24
$('#permission-button').on('click', function () {
25
    var selectedRoleId = $('select[name=permission-select] option').filter(':selected').val();
26
    var selectedRoleValue = $('select[name=permission-select] option').filter(':selected').text();
27

    
28
    var addedRoles = $('.permission-role');
29

    
30
    var roles = [];
31

    
32
    // get assigned roles
33
    addedRoles.each(function () {
34
        roles.push($(this).val())
35
    });
36

    
37
    if (roles.includes(selectedRoleId))
38
    {
39
        return;
40
    }
41

    
42
    addPermissionRow(selectedRoleId, selectedRoleValue);
43

    
44
});
45

    
46

    
47
function addPermissionRow(id, value){
48

    
49
    let row = document.createElement('div');
50
    row.classList.add('input-action-box', 'input-border-bottom', 'permission-row');
51

    
52
    let input = document.createElement('input');
53
    input.type = 'text';
54
    input.classList.add('form-control-plaintext', 'permission-title');
55
    input.id = id;
56
    input.value = value;
57
    input.setAttribute('readonly', "true");
58

    
59
    let hiddenInput = document.createElement('input');
60
    hiddenInput.type = 'hidden';
61
    hiddenInput.classList.add('permission-role');
62
    hiddenInput.value = id;
63

    
64

    
65
    row.appendChild(input);
66
    row.appendChild(hiddenInput);
67

    
68
    let actionButton = document.createElement('span');
69
    actionButton.classList.add('action-padding', 'action-button', 'input-action-margin');
70

    
71
    let deleteButton = document.createElement('span');
72
    deleteButton.classList.add('action-link', 'far', 'fa-trash-alt');
73
    deleteButton.setAttribute('onclick', 'removeRole(this);');
74
    deleteButton.setAttribute('role', 'button');
75

    
76
    actionButton.appendChild(deleteButton);
77
    row.appendChild(actionButton);
78

    
79
    document.getElementById('permission-wrapper').appendChild(row);
80

    
81
    var permissionRoles = $('.permission-row');
82
    var permissionIndex = 0;
83

    
84
    permissionRoles.each(function () {
85
        var hiddenInput = $(this).find('.permission-role');
86

    
87
        hiddenInput.attr("id",`roles${permissionIndex}.id`);
88

    
89
        hiddenInput.attr("name",`roles[${permissionIndex}].id`);
90

    
91
        var input = $(this).find('.permission-title');
92
        input.attr("name", `roles[${permissionIndex}].name`);
93
        input.attr("id", `roles${permissionIndex}.name`);
94
        permissionIndex++;
95
    });
96

    
97
};
98

    
99

    
100

    
101
function addEnumRow(context, value)
102
{
103
    let enumIndex = $(context).closest('.enum_box').find('.enum-index').val();
104
    let countIndex = $(context).closest('.enum_box').find('.enum-row').length;
105

    
106
    let row = document.createElement('div');
107
    row.classList.add('input-action-box', 'input-border-bottom', 'enum-row');
108

    
109

    
110
    let input = document.createElement('input');
111
    input.type = 'text';
112
    input.classList.add('form-control-plaintext');
113
    input.value = value;
114
    input.setAttribute('readonly', "true");
115
    input.setAttribute('id', `parameters${enumIndex}.parameterValues${countIndex}.value`);
116
    input.setAttribute('name', `parameters[${enumIndex}].parameterValues[${countIndex}].value`);
117

    
118
    row.appendChild(input);
119

    
120
    let sortSpan = document.createElement('span');
121
    sortSpan.classList.add('action-padding', 'input-action-margin', 'sort-icon');
122
    sortSpan.innerHTML = "<i class=\"fas fa-sort\"></i>";
123

    
124
    row.appendChild(sortSpan);
125

    
126
    let deleteSpan = document.createElement('span');
127
    deleteSpan.classList.add('action-padding', 'input-action-margin', 'action-button');
128

    
129
    let deleteButton = document.createElement('span');
130
    deleteButton.classList.add('action-link', 'far', 'fa-trash-alt');
131
    deleteButton.setAttribute('onclick', 'removeEnum(this)');
132

    
133
    deleteSpan.appendChild(deleteButton);
134

    
135
    row.appendChild(deleteSpan);
136

    
137
    $(context).closest(".enum_box").find(".enum-wrapper").append($(row));
138

    
139
}
140

    
141

    
142
function removeRole (selectedField) {
143
    selectedField.closest('.permission-row').remove();
144
}
145

    
146

    
147
function showEnum(select) {
148
    var enumBox = $(select).closest(".panel-collapse").find(".enum_box");
149
    enumBox.removeClass("hidden");
150
}
151

    
152
function hideEnum(select) {
153
    var enumBox = $(select).closest(".panel-collapse").find(".enum_box");
154
    enumBox.addClass("hidden");
155
}
156

    
157

    
158
function removeEnum(select) {
159
    $(select).closest(".enum-row").remove();
160
}
161

    
162
function removePanel(panel) {
163
    var r = confirm("Opravdu si přejete odstranit parametr?");
164
    if (r == true) {
165
        $(panel).closest(".parameter").remove();
166
    }
167

    
168
}
169

    
170

    
171
function addCollapse() {
172

    
173
    var index = $(".parameter").length;
174

    
175
    var typeSelectValues = $("#allParametersHiddenSelect").html();
176
    var functionSelectValues = $("#allFunctionsHiddenSelect").html();
177
    var operatorSelectValues = $("#allOperatorsHiddenSelect").html();
178

    
179
    $(".panel-wrapper").append('\n' +
180
        '      <div class="panel-group parameter">\n' +
181
        `      <input type="hidden" class="parametr-order" value="0" id="parameters${index}.parameterOrder" name="parameters[${index}].parameterOrder">\n` +
182
        '        <div class="panel panel-default">\n' +
183
        '          <div class="panel-heading">\n' +
184
        '            <span class="panel-title">\n' +
185
        `              <a data-toggle="collapse" data-parent="#accordion" href=#collapse${index}>\n` +
186
        `                <i class="fas fa-angle-right"></i> Nový parametr\n` +
187
        '              </a>\n' +
188
        '              <span class="align-right collapse-actions">\n' +
189
        '                <span class="action-padding input-action-margin-collapse sort-icon">\n' +
190
        '                  <i class="fas fa-sort"></i>\n' +
191
        '                </span>\n' +
192
        '                <span class="action-padding action-button input-action-margin-collapse">\n' +
193
        '                  <span href=# class="action-link far fa-trash-alt" onclick="removePanel(this);"></span>\n' +
194
        '                </span>\n' +
195
        '              </span>\n' +
196
        '            </span>\n' +
197
        '          </div>\n' +
198
        `          <div id="collapse${index}" class="panel-collapse collapse">\n` +
199
        '            <div class="panel-body">\n' +
200
        '              <div class="form-group row">\n' +
201
        '                <label for="name" class="col-sm-2 col-form-label">Název:</label>\n' +
202
        '                <div class="col-sm-10">\n' +
203
        `                  <input type="text" class="form-control" name="parameters[${index}].name" id="parameterName${index}" value="Nový parametr" required>\n` +
204
        '                </div>\n' +
205
        '              </div>\n' +
206
        '              <div class="form-group row">\n' +
207
        '                <label for="name" class="col-sm-2 col-form-label">V&nbsp;SQL:</label>\n' +
208
        '                <div class="col-sm-10">\n' +
209
        `                  <input type="text" class="form-control" name="parameters[${index}].nameOfSelect" id="parameterSQLName${index}" required>\n` +
210
        '                </div>\n' +
211
        '              </div>\n' +
212
        '              <div class="form-group row">\n' +
213
        '                <label for="exampleFormControlSelect1" class="col-sm-2">Typ:</label>\n' +
214
        '                <div class="col-sm-10">\n' +
215
        `                  <select name="parameters[${index}].parameterType" class="form-control type-select">\n` +
216
        typeSelectValues+
217
        '                  </select>\n' +
218
        '                </div>\n' +
219
        '              </div>\n' +
220
        '\n' +
221
        '              <div class="enum_box">\n' +
222
        '                Hodnoty:\n' +
223
        '                <div class="enum_values col-md-8">\n' +
224
        '                  <div class="enum-wrapper">\n' +
225
        `                     <input type="hidden" class="enum-index" value="${index}">\n` +
226
        '                  </div>\n' +
227
        '\n' +
228
        '                  <div class="form-group row form-add-item">\n' +
229
        '                    <div class="col-md-9">\n' +
230
        '                      <input type="text" class="form-control enum-add-input">\n' +
231
        '                    </div>\n' +
232
        '                    <span class="btn btn-primary mb-2 enum-add-button">Přidat</span>\n' +
233
        '                  </div>\n' +
234
        '                </div>\n' +
235
        '              </div>\n' +
236
        '\n' +
237
        `              <div class="form-group row">\n` +
238
        '                <label for="exampleFormControlSelect1" class="col-sm-2">Umístění:</label>\n' +
239
        '                <div class="col-sm-10">\n' +
240
        '                  <div class="form-check form-check-inline">\n' +
241
        `                    <input type="hidden" name="_parameters[${index}].locations" value="on">\n` +
242
        `                    <input class="form-check-input" name="parameters[${index}].locations" id="parameters${index}.locations1" type="checkbox" value="1">\n` +
243
        `                    <label class="form-check-label" for="parameters[${index}].locations" >Sloupec</label>\n` +
244
        '                  </div>\n' +
245
        '                  <div class="form-check form-check-inline">\n' +
246
        `                    <input type="hidden" name="_parameters[${index}].locations" value="on">\n` +
247
        `                    <input class="form-check-input" name="parameters[${index}].locations" id="parameters${index}.locations2" type="checkbox" value="2">\n` +
248
        '                    <label class="form-check-label" for="parameters[${index}].locations">Řádek</label>\n' +
249
        '                  </div>\n' +
250
        '                  <div class="form-check form-check-inline">\n' +
251
        `                    <input type="hidden" name="_parameters[${index}].locations" value="on">\n` +
252
        `                    <input class="form-check-input" name="parameters[${index}].locations" id="parameters${index}.locations3" type="checkbox" value="3">\n` +
253
        '                    <label class="form-check-label" for="parameters[${index}].locations" >Hodnota</label>\n' +
254
        '                  </div>\n' +
255
        '                </div>\n' +
256
        '              </div>\n' +
257
        '              <div class="form-group row">\n' +
258
        '                  <label for="exampleFormControlSelect1" class="col-sm-2">Funkce:</label>\n' +
259
        '                  <div class="col-sm-10">\n' +
260
        `                    <select name="parameters[${index}].functions" id="parameters${index}.functions" class="mbSelect selectpicker" multiple data-live-search="true">\n` +
261
        functionSelectValues +
262
        '                    </select>\n' +
263
        '                  </div>\n' +
264
        '              </div>\n' +
265
        '              <div class="form-group row">\n' +
266
        '                  <label for="exampleFormControlSelect1" class="col-sm-2">Operátory:</label>\n' +
267
        '                  <div class="col-sm-10">\n' +
268
        `                    <select name="parameters[${index}].operators" id="parameters${index}.operators" class="mbSelect selectpicker" multiple data-live-search="true">\n` +
269
        operatorSelectValues +
270
        '                    </select>\n' +
271
        '                  </div>\n' +
272
        '              </div>\n' +
273
        '            </div>\n' +
274
        '          </div>\n' +
275
        '        </div>\n' +
276
        '      </div>\n' +
277
        '    ');
278

    
279
    this.reindexParametrOrder();
280
    this.initPanelBody();
281

    
282
}
283

    
284
function initPanelBody() {
285
    $('.enum-add-button').on('click', function () {
286
        var input = $(this).closest(".row").find('.enum-add-input');
287
        addEnumRow(this, input.val());
288

    
289
        input.val("");
290
    });
291

    
292
    $('.enum-wrapper').sortable().disableSelection();
293

    
294
    $('.type-select').on('change', function () {
295
        if (this.value == 1)
296
        {
297
            showEnum(this);
298
        }
299
        else
300
        {
301
            hideEnum(this);
302
        }
303
    });
304

    
305
    $(".selectpicker").selectpicker('refresh');
306

    
307
    $('.fa-trash-alt').click(function(event){
308
        event.preventDefault();
309
    });
310
}
311

    
312
function reindexParametrOrder() {
313
    var data = $(".parametr-order");
314

    
315
    let index = 0;
316
    $(data).each(function () {
317
        $(this).attr('value', index);
318
        index++;
319
    });
320
}
(1-1/16)