Skip to content

Commit

Permalink
Default template: fix deleting email address after renaming (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
buschmann23 committed Jun 27, 2017
1 parent 8a05fdc commit a60c6cf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 60 deletions.
98 changes: 41 additions & 57 deletions templates/default/assets/js/manageemailaddresses.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
/*
* Skaffari - a mail account administration web interface based on Cutelyst
* Copyright (C) 2017 Matthias Fehring <kontakt@buschmann23.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

function skaffariRemoveAddress(e) {
var btn = $(e.target);
var row = btn.parents('tr').first();
var quest = $('#addressesTable').data('removequestion');
var address = btn.data('address');
var address = row.data('address');
quest = quest.replace("$1", address)
if (confirm(quest)) {
$('.alert').alert('close');
Expand All @@ -12,7 +31,7 @@ function skaffariRemoveAddress(e) {

$.ajax({
type: 'post',
url: '/account/' + btn.data('domainid') + '/' + btn.data('accountid') + '/remove_email/' + address,
url: '/account/' + row.data('domainid') + '/' + row.data('accountid') + '/remove_email/' + address,
data: {email: address},
dataType: 'json'
}).always(function() {
Expand All @@ -22,23 +41,20 @@ function skaffariRemoveAddress(e) {
if (($('#addressesTableBody tr').length - 1) <= 1) {
$('.remove-address-btn').prop('disabled', true);
}
var tr = btn.parents('tr').first();
tr.hide(300, function() {
tr.remove();
row.hide(300, function() {
row.remove();
});
}).fail(function(jqXHR) {
btn.prop('disabled', false);
skaffariCreateAlert('warning', jqXHR.responseJSON.error_msg, '#messages-container', 'mt-13');
// $('#messages-container').append('<div class="row"><div class="col"><div class="alert alert-warning alert-dismissible fade show mt-3" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' + jqXHR.responseJSON.error_msg + '</div></div></div>');
// $('.alert').alert();
});
}
}

function skaffariEditAddress(e) {
var btn = $(e.target);
$('#addressForm').attr('action', '/account/' + btn.data('domainid') + '/' + btn.data('accountid') + '/email/' + btn.data('address'));
var parts = btn.data('address').split('@');
var row = $(e.target).parents('tr').first();
$('#addressForm').attr('action', '/account/' + row.data('domainid') + '/' + row.data('accountid') + '/email/' + row.data('address'));
var parts = row.data('address').split('@');
$('#newlocalpart').val(parts[0]);
$('#newmaildomain').val(parts[1]);
var am = $('#addressModal');
Expand All @@ -54,23 +70,6 @@ function skaffariAddAddress(e) {
am.modal('show');
}

/*
* Skaffari - a mail account administration web interface based on Cutelyst
* Copyright (C) 2017 Matthias Fehring <kontakt@buschmann23.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

$(function() {
var addressModal = $('#addressModal');
Expand Down Expand Up @@ -132,24 +131,32 @@ $(function() {
var newAddress = data.address;

var newRow = $('<tr>');
newRow.attr({
"data-domainid": data.domain_id,
"data-accountid": data.account_id,
"data-address": newAddress
});
newRow.data({
domainid: data.domain_id,
accountid: data.account_id,
address: newAddress
});
var td1 = $('<td>');

var btnGrp = $('<div>');
btnGrp.addClass('btn-group btn-group-sm');
btnGrp.attr({role: "group", "aria-label": data.actions_btn_label});

var btn1 = $('<button>');
btn1.attr({type: 'button', title: data.edit_btn_label, "data-address": newAddress});
btn1.attr({type: 'button', title: data.edit_btn_label});
btn1.addClass('btn btn-primary edit-address-btn');
btn1.data({address: newAddress, domainid: data.domain_id, accountid: data.account_id});
btn1.append('<i class="fa fa-edit fa-fw"></i>');
btn1.click(skaffariEditAddress);
btnGrp.append(btn1);

var btn2 = $('<button>');
btn2.attr({type: 'button', title: data.delete_btn_label});
btn2.addClass('btn btn-danger remove-address-btn');
btn2.data({address: newAddress, domainid: data.domain_id, accountid: data.account_id});
btn2.append('<i class="fa fa-trash fa-fw"></i>');
btn2.click(skaffariRemoveAddress);
btnGrp.append(btn2);
Expand Down Expand Up @@ -185,39 +192,16 @@ $(function() {
}

} else if (actionType === "edit") {
var oa = data.old_address;
var orgRow = $('tr[data-address="' + data.old_address + '"]');
var na = data.new_address;
var orgBtn = $('button[data-address="' + oa + '"]');
orgBtn.data('address', na);
orgBtn.attr('data-address', na);
var row = orgBtn.parents('tr').first();
var td = row.children('td').last();
td.text(na);
orgRow.attr('data-address', na);
orgRow.data('address', na);
orgRow.children('td').last().text(na);
}

}).fail(function(jqXHR) {
if (jqXHR.responseJSON.error_msg) {
skaffariCreateAlert('warning', jqXHR.responseJSON.error_msg, '#modal-message-container', 'mt-1');
// var warnDiv = $('<div>');
// warnDiv.addClass('alert alert-warning alert-dismissible fade show mt-1');
// warnDiv.attr('role', 'alert');
// var warnDivCb = $('<button>');
// warnDivCb.attr({type: "button", "aria-label": "Close"});
// warnDivCb.addClass('close');
// warnDivCb.data('dismiss', 'alert');
// warnDivCb.click(function() {
// warnDiv.alert('close');
// });
// var warnDivSpan = $('<span>');
// warnDivSpan.attr('aria-hidden', 'true');
// warnDivSpan.html('&times;')
// warnDivCb.append(warnDivSpan);
// warnDiv.append(warnDivCb);
// warnDiv.append(jqXHR.responseJSON.error_msg);
// warnDiv.hide();
// $('#modal-message-container').append(warnDiv);
// warnDiv.show(300);
// warnDiv.alert();
}
});

Expand Down
6 changes: 3 additions & 3 deletions templates/default/site/account/addresses.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ <h2><i class="fa fa-envelope"></i> {{ _("Email addresses") }} <small class="text
</thead>
<tbody id="addressesTableBody">
{% for address in account.addresses %}
<tr>
<tr data-domainid="{{ domain.id }}" data-accountid="{{ account.id }}" data-address="{{ address }}">
<td>
<div class="btn-group btn-group-sm" role="group" aria-label="{{ _("Email address actions") }}">
<button type="button" class="btn btn-primary edit-address-btn" title="{{ _("Edit address") }}" data-address="{{ address }}" data-domainid="{{ domain.id }}" data-accountid="{{ account.id }}"><i class="fa fa-edit fa-fw"></i></button>
<button type="button" class="btn btn-danger remove-address-btn" title="{{ _("Delete address") }}" data-address="{{ address }}" data-domainid="{{ domain.id }}" data-accountid="{{ account.id }}"{%if account.addresses.count <= 1 %} disabled{% endif %}><i class="fa fa-trash fa-fw"></i></button>
<button type="button" class="btn btn-primary edit-address-btn" title="{{ _("Edit address") }}"><i class="fa fa-edit fa-fw"></i></button>
<button type="button" class="btn btn-danger remove-address-btn" title="{{ _("Delete address") }}" {%if account.addresses.count <= 1 %} disabled{% endif %}><i class="fa fa-trash fa-fw"></i></button>
</div>
</td>
<td>{{ address }}</td>
Expand Down

0 comments on commit a60c6cf

Please sign in to comment.