96 lines
2.2 KiB
JavaScript
96 lines
2.2 KiB
JavaScript
|
$(function() {
|
||
|
function updateAliasesList() {
|
||
|
$.ajax({
|
||
|
type: 'POST',
|
||
|
url: '/?_task=settings&_action=plugin.aliasmanager-get-alias-list',
|
||
|
success: function(response) {
|
||
|
if (response.success) {
|
||
|
$('[name=alias_new_name]').val('');
|
||
|
|
||
|
// Clear table
|
||
|
$('.alias-list').html('');
|
||
|
|
||
|
// Make template
|
||
|
let template = $('template#alias-list-row').html();
|
||
|
|
||
|
for (let i = 0; i < response.data.alias_list.length; i++) {
|
||
|
const row = response.data.alias_list[i];
|
||
|
|
||
|
let tpl = template.replaceAll('{i}', i);
|
||
|
tpl = tpl.replaceAll('{email}', row.email);
|
||
|
tpl = tpl.replaceAll('{active}', row.active == 1);
|
||
|
tpl = tpl.replaceAll('{checked}', row.active == 1 ? 'checked' : '');
|
||
|
$('.alias-list').append(tpl);
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
dataType: 'json'
|
||
|
});
|
||
|
}
|
||
|
|
||
|
$(document).on('click', '.btn-aliasmanager-add-alias', function() {
|
||
|
const email = $('[name=alias_new_name]').val();
|
||
|
if (!/[a-z0-9]/.test(email)) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
$.ajax({
|
||
|
type: 'POST',
|
||
|
url: '/?_task=settings&_action=plugin.aliasmanager-add-alias',
|
||
|
data: {
|
||
|
email: email,
|
||
|
},
|
||
|
success: function(response) {
|
||
|
if (response.success) {
|
||
|
$('[name=alias_new_name]').val('');
|
||
|
|
||
|
updateAliasesList();
|
||
|
}
|
||
|
},
|
||
|
dataType: 'json'
|
||
|
});
|
||
|
})
|
||
|
|
||
|
$(document).on('change', '.btn-aliasmanager-toggle-alias', function() {
|
||
|
const email = $(this).attr('data-email');
|
||
|
const isOn = $(this).is(':checked');
|
||
|
|
||
|
$.ajax({
|
||
|
type: 'POST',
|
||
|
url: '/?_task=settings&_action=plugin.aliasmanager-toggle-alias',
|
||
|
data: {
|
||
|
state: isOn,
|
||
|
email: email,
|
||
|
},
|
||
|
success: function(response) {
|
||
|
if (response.success) {
|
||
|
updateAliasesList();
|
||
|
}
|
||
|
},
|
||
|
dataType: 'json'
|
||
|
});
|
||
|
})
|
||
|
|
||
|
$(document).on('click', '.btn-aliasmanager-delete-alias', function() {
|
||
|
const email = $(this).attr('data-email');
|
||
|
|
||
|
if (confirm('You really want to delete ' + email + '?')) {
|
||
|
$.ajax({
|
||
|
type: 'POST',
|
||
|
url: '/?_task=settings&_action=plugin.aliasmanager-delete-alias',
|
||
|
data: {
|
||
|
email: email,
|
||
|
},
|
||
|
success: function(response) {
|
||
|
if (response.success) {
|
||
|
updateAliasesList();
|
||
|
}
|
||
|
},
|
||
|
dataType: 'json'
|
||
|
});
|
||
|
}
|
||
|
})
|
||
|
|
||
|
// Init
|
||
|
updateAliasesList()
|
||
|
});
|