Projekt

Obecné

Profil

Stáhnout (3.94 KB) Statistiky
| Větev: | Revize:
1 b3c57a7c cagy
$(document).ready(function() {
2
3
    $('.select-action-button').on('click', function () {
4
        if ($(this).hasClass('select-action-headlight'))
5
        {
6
            $(this).removeClass('select-action-headlight');
7
            removeParameter(getParameterTitle($(this)), getParameterType($(this)));
8
        }
9
        else
10
        {
11
            $(this).closest('.select-action-buttons').find('.select-action-button').removeClass('select-action-headlight');
12
13
            removeFromAll(getParameterTitle($(this)));
14
15
            $(this).addClass('select-action-headlight');
16
17
            addParameter(getParameterIndex($(this)),
18
                getParameterTitle($(this)),
19
                getParameterType($(this)),
20
                getParameterHiddenValue($(this)));
21
22
            initParameters();
23
        }
24
    });
25
26
    initParameters();
27
28
});
29
30
function removeFromAll(title) {
31
    $rows = $('.selected-input-container');
32
33
    $rows.each(function () {
34
        $(this).find('.parameter-name').each(function () {
35
            if ($(this).text() == title)
36
            {
37
                $(this).closest('.parameter').remove();
38
            }
39
        })
40
    });
41
}
42
43
function getParameterIndex(button) {
44
    return $(button).closest('.parameter-row').find('.parameterIndex').val();
45
}
46
47
function addParameter(index, parameterName, type, hiddenValue) {
48
    var row = document.createElement('tr');
49
    row.classList.add(type + '-parameter', 'parameter');
50
51
    let hiddenInput = document.createElement('input');
52
    hiddenInput.type = 'hidden';
53
    hiddenInput.id = `parametersInConfiguration${index}.location.id`;
54
    hiddenInput.name = `parametersInConfiguration[${index}].location.id`;
55
    hiddenInput.value = hiddenValue;
56
57
    row.appendChild(hiddenInput);
58
59
    var firstTd = document.createElement('td');
60
61
    var firstTdBody = document.createElement('span');
62
    firstTdBody.classList.add('parameter-name');
63
    firstTdBody.innerHTML = parameterName;
64
65
    firstTd.appendChild(firstTdBody);
66
67
    row.appendChild(firstTd);
68
69
    var thirdTd = document.createElement('td');
70
71
    var thirdTdBody;
72
73
74
    if (type == 'value')
75
    {
76
        thirdTdBody = $('#function-select-' + index).clone()[0];
77
78
        $(thirdTdBody).removeClass('hidden');
79
    }
80
    else
81
    {
82
        var secondTd = document.createElement('td');
83
84
        var secondTdBody = document.createElement('input');
85
        secondTdBody.type = 'text';
86
        secondTdBody.classList.add('form-control', 'select-filter-input-name');
87
        secondTdBody.name = `parametersInConfiguration[${index}].columnName`;
88
89
        secondTd.appendChild(secondTdBody);
90
91
        row.appendChild(secondTd);
92
93
        thirdTdBody = document.createElement('span');
94
        thirdTdBody.innerHTML = "<i class=\"fas fa-sort\"></i>";
95
    }
96
97
    thirdTd.appendChild(thirdTdBody);
98
99
    row.appendChild(thirdTd);
100
101
    $('#' + type + '-wrapper').append($(row));
102
103
}
104
105
function removeParameter(title, parameterClass) {
106
    $rows = $('.' + parameterClass + '-parameter');
107
108
    $rows.each(function () {
109
        $(this).find('.parameter-name').each(function () {
110
            if ($(this).text() == title)
111
            {
112
                $(this).closest('.' + parameterClass + '-parameter').remove();
113
            }
114
        })
115
    });
116
}
117
118
function getParameterType(context) {
119
    if ($(context).hasClass('column-button'))
120
    {
121
        return 'column';
122
    }
123
    else if ($(context).hasClass('row-button'))
124
    {
125
        return 'row';
126
    }
127
    else if ($(context).hasClass('value-button'))
128
    {
129
        return 'value';
130
    }
131
}
132
133
function getParameterHiddenValue(context) {
134
    if ($(context).hasClass('column-button'))
135
    {
136
        return 1;
137
    }
138
    else if ($(context).hasClass('row-button'))
139
    {
140
        return 2;
141
    }
142
    else if ($(context).hasClass('value-button'))
143
    {
144
        return 3;
145
    }
146
}
147
148
function getParameterTitle(context) {
149
    return $(context).closest('.parameter-row').find('.parameter-name').text();
150
}
151
152
153
function initParameters()
154
{
155
    $('.sortable').sortable();
156
    $("select").selectpicker('refresh');
157
}