Projekt

Obecné

Profil

« Předchozí | Další » 

Revize d149244c

Přidáno uživatelem Jan Čarnogurský před asi 4 roky(ů)

re #7972 - Allow assembly order only for role Administrator, javascript comments

Zobrazit rozdíly:

src/main/webapp/WEB-INF/templates/index.html
37 37
			<div class="button-container">
38 38

  
39 39
				<a sec:authorize="hasAuthority('Administrátor')" th:href="@{/assembly_new}" class="btn btn-success mb-2"><i class="fas fa-plus"></i> Přidat novou sestavu</a>
40
				<span class="btn btn-success align-right" id="saveSort">Uložit řazení</span>
40
				<span sec:authorize="hasAuthority('Administrátor')" class="btn btn-success align-right" id="saveSort">Uložit řazení</span>
41 41
			</div>
42 42

  
43 43
			<table class="table table-bordered table-striped">
src/main/webapp/js/assemblyManageScripts.js
1

  
1
/**
2
 * Default action
3
 */
2 4
$(document).ready(function() {
3 5

  
6
    // init sorting
4 7
    $(".panel-wrapper").sortable({
5 8
        stop: function(event, ui) {
9
            // after switch place reindex parameters
6 10
            reindexParametrOrder();
7 11
        }
8 12
    }).disableSelection();
9 13

  
10

  
14
    // denny action with buttons with thrash icon
11 15
    $('.fa-trash-alt').click(function(event){
12 16
        event.preventDefault();
13 17
    });
14 18

  
19
    // add new collapse after click on button add-param-button
15 20
    $('#add-param-button').on('click', function () {
16 21
        addCollapse();
17 22
    });
18 23

  
24
    $('#permission-button').on('click', function () {
25
        addPermission();
26
    });
27

  
28
    // index parameters order
19 29
    reindexParametrOrder();
30

  
31
    // init actions for panel body
20 32
    initPanelBody();
21 33

  
22 34
});
23 35

  
24
$('#permission-button').on('click', function () {
36
/**
37
 * Get value from permission input and create new input
38
 */
39
function addPermission()
40
{
25 41
    var selectedRoleId = $('select[name=permission-select] option').filter(':selected').val();
26 42
    var selectedRoleValue = $('select[name=permission-select] option').filter(':selected').text();
27 43

  
......
40 56
    }
41 57

  
42 58
    addPermissionRow(selectedRoleId, selectedRoleValue);
43

  
44
});
59
}
45 60

  
46 61

  
62
/**
63
 * Add new permission input
64
 * @param id
65
 * @param value
66
 */
47 67
function addPermissionRow(id, value){
48 68

  
49 69
    let row = document.createElement('div');
......
94 114
        permissionIndex++;
95 115
    });
96 116

  
97
};
98

  
117
}
99 118

  
100 119

  
120
/**
121
 * Add new enum value for type "Výčet"
122
 * @param context
123
 * @param value
124
 */
101 125
function addEnumRow(context, value)
102 126
{
103 127
    let enumIndex = $(context).closest('.enum_box').find('.enum-index').val();
......
138 162

  
139 163
}
140 164

  
141

  
165
/**
166
 * Remove permission role
167
 * @param selectedField
168
 */
142 169
function removeRole (selectedField) {
143 170
    selectedField.closest('.permission-row').remove();
144 171
}
145 172

  
146

  
173
/**
174
 * Show enum box for parameter
175
 * @param select
176
 */
147 177
function showEnum(select) {
148 178
    var enumBox = $(select).closest(".panel-collapse").find(".enum_box");
149 179
    enumBox.removeClass("hidden");
150 180
}
151 181

  
182
/**
183
 * Hide enum box for parameter
184
 * @param select
185
 */
152 186
function hideEnum(select) {
153 187
    var enumBox = $(select).closest(".panel-collapse").find(".enum_box");
154 188
    enumBox.addClass("hidden");
155 189
}
156 190

  
157

  
191
/**
192
 * Remove enum value
193
 * @param select
194
 */
158 195
function removeEnum(select) {
159 196
    $(select).closest(".enum-row").remove();
160 197
}
161 198

  
199
/**
200
 * Remove parameter
201
 * @param panel
202
 */
162 203
function removePanel(panel) {
163 204
    var r = confirm("Opravdu si přejete odstranit parametr?");
164 205
    if (r == true) {
......
167 208

  
168 209
}
169 210

  
170

  
211
/**
212
 * Add new parameter
213
 */
171 214
function addCollapse() {
172 215

  
173 216
    var index = $(".parameter").length;
......
176 219
    var functionSelectValues = $("#allFunctionsHiddenSelect").html();
177 220
    var operatorSelectValues = $("#allOperatorsHiddenSelect").html();
178 221

  
222
    // parameter body
179 223
    $(".panel-wrapper").append('\n' +
180 224
        '      <div class="panel-group parameter">\n' +
181 225
        `      <input type="hidden" class="parametr-order" value="0" id="parameters${index}.parameterOrder" name="parameters[${index}].parameterOrder">\n` +
......
281 325

  
282 326
}
283 327

  
328
/**
329
 * Init scripts for parameters body
330
 */
284 331
function initPanelBody() {
285 332
    $('.enum-add-button').on('click', function () {
286 333
        var input = $(this).closest(".row").find('.enum-add-input');
......
309 356
    });
310 357
}
311 358

  
359
/**
360
 * Reindex parameter body order
361
 */
312 362
function reindexParametrOrder() {
313 363
    var data = $(".parametr-order");
314 364

  
src/main/webapp/js/assemblyScripts.js
1 1
$(document).ready(function() {
2 2

  
3
    // reaction for add/delete parameters from selected fields (row, column, value)
3 4
    $('.select-action-button').on('click', function () {
5
        // if input has headlight class (parameter is already added -> remove)
4 6
        if ($(this).hasClass('select-action-headlight'))
5 7
        {
8
            // remove headlight class from type
6 9
            $(this).removeClass('select-action-headlight');
10

  
11
            // remove parameter from selected inputs
7 12
            removeParameter(getParameterTitle($(this)), getParameterType($(this)));
8 13
        }
9 14
        else
10 15
        {
16
            // remove headlight from other types for parameter if exists
11 17
            $(this).closest('.select-action-buttons').find('.select-action-button').removeClass('select-action-headlight');
12 18

  
19
            // remove element from selected inputs if exists
13 20
            removeFromAll(getParameterTitle($(this)));
14 21

  
22
            // headlight selected input
15 23
            $(this).addClass('select-action-headlight');
16 24

  
25
            // add selected parameter to selected parameters by type
17 26
            addParameter(getParameterIndex($(this)),
18 27
                getParameterTitle($(this)),
19 28
                getParameterType($(this)),
20 29
                getParameterHiddenValue($(this)));
21 30

  
31
            // reinitialize actions for new parameter
22 32
            initParameters();
23 33
        }
24 34
    });
25 35

  
36
    // init actions
26 37
    initParameters();
27 38

  
28 39
});
29 40

  
41
/**
42
 * Remove value from all selected fields
43
 * @param title
44
 */
30 45
function removeFromAll(title) {
31 46
    $rows = $('.selected-input-container');
32 47

  
......
40 55
    });
41 56
}
42 57

  
58
/**
59
 * Returns parameter index
60
 * @param button
61
 * @returns {*|jQuery|string|undefined}
62
 */
43 63
function getParameterIndex(button) {
44 64
    return $(button).closest('.parameter-row').find('.parameterIndex').val();
45 65
}
46 66

  
67
/**
68
 * Adds new parameter to selected fields
69
 * @param index
70
 * @param parameterName
71
 * @param type
72
 * @param hiddenValue
73
 */
47 74
function addParameter(index, parameterName, type, hiddenValue) {
48 75
    var row = document.createElement('tr');
49 76
    row.classList.add(type + '-parameter', 'parameter');
......
102 129

  
103 130
}
104 131

  
132
/**
133
 * Remove specific parameter from fields by name and container
134
 * @param title
135
 * @param parameterClass
136
 */
105 137
function removeParameter(title, parameterClass) {
106 138
    $rows = $('.' + parameterClass + '-parameter');
107 139

  
......
115 147
    });
116 148
}
117 149

  
150
/**
151
 * Base on class returns type
152
 * @param context
153
 * @returns {string}
154
 */
118 155
function getParameterType(context) {
119 156
    if ($(context).hasClass('column-button'))
120 157
    {
......
130 167
    }
131 168
}
132 169

  
170
/**
171
 * Base on type return integer value
172
 * @param context
173
 * @returns {number}
174
 */
133 175
function getParameterHiddenValue(context) {
134 176
    if ($(context).hasClass('column-button'))
135 177
    {
......
145 187
    }
146 188
}
147 189

  
190
/**
191
 * Returns parameter name
192
 * @param context
193
 * @returns {*|jQuery}
194
 */
148 195
function getParameterTitle(context) {
149 196
    return $(context).closest('.parameter-row').find('.parameter-name').text();
150 197
}
151 198

  
152

  
199
/**
200
 * Init base actions
201
 */
153 202
function initParameters()
154 203
{
155 204
    $('.sortable').sortable();
src/main/webapp/js/indexScripts.js
1 1
$(document).ready(function(){
2

  
3
    // test if button for save order exists
4
    if ($('#saveSort').length < 1)
5
    {
6
        return;
7
    }
8

  
2 9
    // set up sorting
3 10
    $(".sort").sortable().disableSelection();
4 11

  
......
29 36
                }
30 37
            });
31 38
        }
32

  
33 39
    });
34 40
});

Také k dispozici: Unified diff