123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- $(document).ready(function() {
-
- // Collect values of input fields with name multi_select with same data-form-id to js array multi_data[data-form-id-of-checkbox]
- var multi_data = [];
- $(document).on('change', 'input[name=multi_select]:checkbox', function() {
- if ($(this).is(':checked') && $(this).attr('data-form-id')) {
- var id = $(this).data('form-id');
- if (typeof multi_data[id] == "undefined") {
- multi_data[id] = [];
- }
- multi_data[id].push($(this).val());
- }
- else {
- var id = $(this).data('form-id');
- multi_data[id].splice($.inArray($(this).val(), multi_data[id]),1);
- }
- });
- // Select checkbox by click on parent tr
- $(document).on('click', '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-form-id
- $(document).on('click', '#toggle_multi_select_all', function(e) {
- e.preventDefault();
- var all_checkboxes = $("input[data-form-id=" + $(this).attr("data-form-id") + "]");
- all_checkboxes.prop("checked", !all_checkboxes.prop("checked")).change();
- });
- // Draw domain admin table
- $.ajax({
- dataType: 'json',
- url: '/api/v1/get/domain-admin/all',
- jsonp: false,
- error: function () {
- console.log('Cannot draw domain admin table');
- },
- success: function (data) {
- $.each(data, function (i, item) {
- item.action = '<div class="btn-group">' +
- '<a href="/edit.php?domainadmin=' + encodeURI(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
- '<a href="/delete.php?domainadmin=' + encodeURI(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
- '</div>';
- });
- $('#domainadminstable').footable({
- "columns": [
- {"sorted": true,"name":"username","title":lang.username,"style":{"width":"250px"}},
- {"name":"selected_domains","title":lang.admin_domains,"breakpoints":"xs sm"},
- {"name":"tfa_active","title":"TFA", "filterable": false,"style":{"maxWidth":"80px","width":"80px"}},
- {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
- {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
- ],
- "rows": data,
- "empty": lang.empty,
- "paging": {
- "enabled": true,
- "limit": 5,
- "size": pagination_size
- },
- "filtering": {
- "enabled": true,
- "position": "left",
- "placeholder": lang.filter_table
- },
- "sorting": {
- "enabled": true
- }
- });
- }
- });
-
- // Draw fwd hosts table
- $.ajax({
- dataType: 'json',
- url: '/api/v1/get/fwdhost/all',
- jsonp: false,
- error: function () {
- console.log('Cannot draw forwarding hosts table');
- },
- success: function (data) {
- $.each(data, function (i, item) {
- item.action = '<div class="btn-group">' +
- '<a href="/delete.php?forwardinghost=' + encodeURI(item.host) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
- '</div>';
- if (item.keep_spam == "yes") {
- item.keep_spam = lang.no;
- }
- else {
- item.keep_spam = lang.yes;
- }
- item.chkbox = '<input type="checkbox" data-form-id="fwdhosts" name="multi_select" value="' + item.host + '" />';
- });
- $('#forwardinghoststable').footable({
- "columns": [
- {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
- {"name":"host","type":"text","title":lang.host,"style":{"width":"250px"}},
- {"name":"source","title":lang.source,"breakpoints":"xs sm"},
- {"name":"keep_spam","title":lang.spamfilter, "type": "text","style":{"maxWidth":"80px","width":"80px"}},
- {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
- ],
- "rows": data,
- "empty": lang.empty,
- "paging": {
- "enabled": true,
- "limit": 5,
- "size": pagination_size
- },
- "sorting": {
- "enabled": true
- }
- });
- }
- });
-
- $(document).on('click', '#delete_fwdhosts', function(e) {
- e.preventDefault();
- var id = $(this).closest("form").attr('data-id');
- if (typeof multi_data[id] == "undefined") return;
- data_array = multi_data[id];
- if (Object.keys(data_array).length !== 0) {
- $(document).on('show.bs.modal','#ConfirmDeleteModal', function () {
- $("#ItemsToDelete").empty();
- for (var i in data_array) {
- $("#ItemsToDelete").append("<li>" + data_array[i] + "</li>");
- }
- })
- $('#ConfirmDeleteModal').modal({
- backdrop: 'static',
- keyboard: false
- })
- .one('click', '#IsConfirmed', function(e) {
- $.ajax({
- type: "POST",
- dataType: "json",
- data: { "forwardinghost": JSON.stringify(data_array) },
- url: '/api/v1/delete/fwdhost',
- jsonp: false,
- complete: function (data) {
- window.location.href = window.location.href;
- }
- });
- })
- .one('click', '#isCanceled', function(e) {
- $('#ConfirmDeleteModal').modal('hide');
- });;
- }
- });
- $(document).on('click', '#delete_dkim_key', function(e) {
- e.preventDefault();
- var dkim_domain = $(this).data('dkim-domain');
- var dkim_selector = $(this).data('dkim-selector');
- $(document).on('show.bs.modal','#ConfirmDeleteModal', function () {
- $("#ItemsToDelete").empty();
- $("#ItemsToDelete").append("<li>" + dkim_domain + ", " + dkim_selector + "</li>");
- })
- $('#ConfirmDeleteModal').modal({
- backdrop: 'static',
- keyboard: false
- })
- .one('click', '#IsConfirmed', function(e) {
- $.ajax({
- type: "POST",
- dataType: "json",
- data: { "domains": JSON.stringify(dkim_domain) },
- url: '/api/v1/delete/dkim',
- jsonp: false,
- complete: function (data) {
- mailcow_alert_box("warn", "asd");
- }
- });
- })
- .one('click', '#isCanceled', function(e) {
- $('#ConfirmDeleteModal').modal('hide');
- });;
- });
- $("#refresh_dovecot_log").on('click', function(e) {
- function unix_time_format(tm) {
- var date = new Date(tm ? tm * 1000 : 0);
- return date.toLocaleString();
- }
- e.preventDefault();
- if (typeof ft_dovecot_logs != 'undefined') {
- ft_dovecot_logs.destroy();
- }
- $.ajax({
- dataType: 'json',
- url: '/api/v1/get/logs/dovecot/1000',
- jsonp: false,
- error: function () {
- console.log('Cannot draw dovecot log table');
- },
- success: function (data) {
- $.each(data, function (i, item) {
- var danger_class = ["emerg", "alert", "crit"];
- var warning_class = ["warning"];
- var info_class = ["notice", "info", "debug"];
- if (jQuery.inArray(item.priority, danger_class) !== -1) {
- item.priority = '<span class="label label-danger">' + item.priority + '</span>';
- }
- else if (jQuery.inArray(item.priority, warning_class) !== -1) {
- item.priority = '<span class="label label-warning">' + item.priority + '</span>';
- }
- else if (jQuery.inArray(item.priority, info_class) !== -1) {
- item.priority = '<span class="label label-info">' + item.priority + '</span>';
- }
- });
- ft_dovecot_logs = FooTable.init("#dovecot_log", {
- "columns": [
- {"name":"time","formatter":function unix_time_format(tm) {var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
- {"name":"priority","title":lang.priority,"style":{"width":"80px"}},
- {"name":"message","title":lang.message},
- ],
- "rows": data,
- "empty": lang.empty,
- "paging": {
- "enabled": true,
- "limit": 5,
- "size": pagination_size
- },
- "filtering": {
- "enabled": true,
- "position": "left",
- "placeholder": lang.filter_table
- },
- "sorting": {
- "enabled": true
- }
- });
- }
- });
- });
- $("#refresh_postfix_log").on('click', function(e) {
- function unix_time_format(tm) {
- var date = new Date(tm ? tm * 1000 : 0);
- return date.toLocaleString();
- }
- e.preventDefault();
- if (typeof ft_postfix_logs != 'undefined') {
- ft_postfix_logs.destroy();
- }
- $.ajax({
- dataType: 'json',
- url: '/api/v1/get/logs/postfix/1000',
- jsonp: false,
- error: function () {
- console.log('Cannot draw postfix log table');
- },
- success: function (data) {
- $.each(data, function (i, item) {
- var danger_class = ["emerg", "alert", "crit"];
- var warning_class = ["warning"];
- var info_class = ["notice", "info", "debug"];
- if (jQuery.inArray(item.priority, danger_class) !== -1) {
- item.priority = '<span class="label label-danger">' + item.priority + '</span>';
- }
- else if (jQuery.inArray(item.priority, warning_class) !== -1) {
- item.priority = '<span class="label label-warning">' + item.priority + '</span>';
- }
- else if (jQuery.inArray(item.priority, info_class) !== -1) {
- item.priority = '<span class="label label-info">' + item.priority + '</span>';
- }
- });
- ft_postfix_logs = FooTable.init("#postfix_log", {
- "columns": [
- {"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
- {"name":"priority","title":lang.priority,"style":{"width":"80px"}},
- {"name":"message","title":lang.message},
- ],
- "rows": data,
- "empty": lang.empty,
- "paging": {
- "enabled": true,
- "limit": 5,
- "size": pagination_size
- },
- "filtering": {
- "enabled": true,
- "position": "left",
- "placeholder": lang.filter_table
- },
- "sorting": {
- "enabled": true
- }
- });
- }
- });
- });
- $("#refresh_dovecot_log").trigger('click');
- $("#refresh_postfix_log").trigger('click');
- });
|