$(document).ready(function() { // Show and activate password fields after box was checked // Hidden by default if ( !$("#togglePwNew").is(':checked') ) { $(".passFields").hide(); } $('#togglePwNew').click(function() { $("#user_new_pass").attr("disabled", !this.checked); $("#user_new_pass2").attr("disabled", !this.checked); var $this = $(this); if ($this.is(':checked')) { $(".passFields").slideDown(); } else { $(".passFields").slideUp(); } }); // Show generate button after time selection $('#generate_tla').hide(); $('#validity').change(function(){ $('#generate_tla').show(); }); // Init Bootstrap Switch $.fn.bootstrapSwitch.defaults.onColor = 'success'; $("#tls_out").bootstrapSwitch(); $("#tls_in").bootstrapSwitch(); // Log modal $('#logModal').on('show.bs.modal', function(e) { var logText = $(e.relatedTarget).data('log-text'); $(e.currentTarget).find('#logText').html('
' + logText + ''); }); // Collect values of input fields with name multi_select with same data-id to js array multi_data[data-id] var multi_data = []; $(document).on('change', 'input[name=multi_select]:checkbox', function() { if ($(this).is(':checked') && $(this).data('id')) { var id = $(this).data('id'); if (typeof multi_data[id] == "undefined") { multi_data[id] = []; } multi_data[id].push($(this).val()); } else { var id = $(this).data('id'); multi_data[id].splice($.inArray($(this).val(), multi_data[id]),1); } }); // Select checkbox by click on parent tr $(document).on('click', 'tbody>tr', function(e) { if (e.target.type == "checkbox") { e.stopPropagation(); } else { var checkbox = $(this).find(':checkbox'); checkbox.trigger('click'); } }); // Select or deselect all checkboxes with same data-id $(document).on('click', '#toggle_multi_select_all', function(e) { e.preventDefault(); id = $(this).data("id"); multi_data[id] = []; var all_checkboxes = $("input[data-id=" + id + "]:enabled"); all_checkboxes.prop("checked", !all_checkboxes.prop("checked")).change(); }); // General API edit actions $(document).on('click', '#edit_selected', function(e) { e.preventDefault(); var id = $(this).data('id'); if (typeof multi_data[id] == "undefined") return; data_array = multi_data[id]; api_url = $(this).data('api-url'); api_attr = $(this).data('api-attr'); if (Object.keys(data_array).length !== 0) { $.ajax({ type: "POST", dataType: "json", data: { "items": JSON.stringify(data_array), "attr": JSON.stringify(api_attr), "csrf_token": csrf_token }, url: '/api/v1/' + api_url, jsonp: false, complete: function (data) { // var reponse = (JSON.parse(data.responseText)); // console.log(reponse.type); // console.log(reponse.msg); location.assign(window.location); } }); } }); // General API delete actions $(document).on('click', '#delete_selected', function(e) { e.preventDefault(); var id = $(this).data('id'); if (typeof multi_data[id] == "undefined" || multi_data[id] == "") return; data_array = multi_data[id]; api_url = $(this).data('api-url'); $(document).on('show.bs.modal','#ConfirmDeleteModal', function () { $("#ItemsToDelete").empty(); for (var i in data_array) { $("#ItemsToDelete").append("
' + item.exclude + '
'
item.server_w_port = item.host1 + ':' + item.port1;
item.action = '