Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 2111fb8f

Přidáno uživatelem Jan Čarnogurský před téměř 4 roky(ů)

re #8169 - validate action button combination

Zobrazit rozdíly:

src/main/webapp/js/assemblyScripts.js
1
let ROW = 'row';
2
let COLUMN = 'column';
3
let VALUE = 'value';
4

  
1 5
$(document).ready(function() {
2 6

  
3 7
    // reaction for add/delete parameters from selected fields (row, column, value)
......
31 35
            // reinitialize actions for new parameter
32 36
            initParameters();
33 37
        }
38

  
39
        validateCombination();
34 40
    });
35 41

  
36 42
    // init actions
37 43
    initParameters();
38 44

  
45
    // spinner init
39 46
    initSpinnerToButtons();
40 47

  
48
    // generation init
49
    initTableGenerationButtons();
50

  
41 51
});
42 52

  
43 53
/**
......
107 117
    var thirdTdBody;
108 118

  
109 119

  
110
    if (type == 'value')
120
    if (type == VALUE)
111 121
    {
112 122
        thirdTdBody = $('#function-select-' + index).clone()[0];
113 123
        thirdTdBody.selectedIndex = 0;
......
167 177
function getParameterType(context) {
168 178
    if ($(context).hasClass('column-button'))
169 179
    {
170
        return 'column';
180
        return COLUMN;
171 181
    }
172 182
    else if ($(context).hasClass('row-button'))
173 183
    {
174
        return 'row';
184
        return ROW;
175 185
    }
176 186
    else if ($(context).hasClass('value-button'))
177 187
    {
178
        return 'value';
188
        return VALUE;
179 189
    }
180 190
}
181 191

  
......
266 276
    })
267 277
}
268 278

  
279
/**
280
 * Shows spinner with overlay
281
 */
269 282
function showSpinner() {
270 283
    let spinner = document.getElementById('spinner-overlay');
271 284

  
272 285
    spinner.style.display = 'block';
273 286
}
274 287

  
288
/**
289
 * Hides spinner with overlay
290
 */
275 291
function hideSpinner() {
276 292
    let spinner = document.getElementById('spinner-overlay');
277 293

  
278 294
    spinner.style.display = 'none';
295
}
296

  
297
/**
298
 * Table generation button validator
299
 * If row is selected allow to generate
300
 * if column is selected, value and row must be also selected
301
 */
302
function initTableGenerationButtons() {
303
    validateCombination();
304
}
305

  
306
/**
307
 * Check action buttons combination
308
 */
309
function validateCombination() {
310
    let selectedActionButtons = $('.select-action-headlight');
311

  
312
    var rowSelected = false;
313
    var columnSelected = false;
314
    var valueSelected = false;
315

  
316
    // check selected buttons
317
    selectedActionButtons.each(function () {
318
        let type = getParameterType($(this));
319

  
320
        switch (type) {
321
            case VALUE:
322
                valueSelected = true;
323
                break;
324
            case ROW:
325
                rowSelected = true;
326
                break;
327
            case COLUMN:
328
                columnSelected = true;
329
                break;
330
        }
331
    });
332

  
333
    // possible combinations with allowed export
334
    if (rowSelected && columnSelected && valueSelected)
335
    {
336
        allowExport();
337
    }
338
    else if (columnSelected && !rowSelected && !valueSelected)
339
    {
340
        allowExport();
341
    }
342
    else
343
    {
344
        disableExportButtons();
345
    }
346

  
347

  
348
}
349

  
350
/**
351
 * Disables buttons for export
352
 */
353
function disableExportButtons() {
354
    $('.show-spinner').attr('disabled','disabled');
355
}
356

  
357
/**
358
 * Allow buttons for export
359
 */
360
function allowExport() {
361
    $('.show-spinner').removeAttr('disabled');
279 362
}

Také k dispozici: Unified diff