From 0a58e4c952b0b104adde60bc142a940f195ab4fd Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 23 Feb 2019 15:36:06 -0500 Subject: [PATCH] Improve contactgroupChangeMember() javascript function - Add usage of new /group/123/add|remove/123 URL - Add checkbox revert in case of error --- view/js/main.js | 20 +++++++++++++++++--- view/templates/group_side.tpl | 2 +- view/theme/frio/templates/group_side.tpl | 2 +- view/theme/quattro/templates/group_side.tpl | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/view/js/main.js b/view/js/main.js index 3370d7ccd3..cd09de0143 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -793,11 +793,25 @@ function profChangeMember(gid,cid) { }); } -function contactgroupChangeMember(gid,cid) { +function contactgroupChangeMember(checkbox, gid, cid) { + let url; + // checkbox.checked is the checkbox state after the click + if (checkbox.checked) { + url = 'group/' + gid + '/add/' + cid; + } else { + url = 'group/' + gid + '/remove/' + cid; + } $('body').css('cursor', 'wait'); - $.get('contactgroup/' + gid + '/' + cid, function(data) { - $('body').css('cursor', 'auto'); + $.post(url) + .error(function () { + // Restores previous state in case of error + checkbox.checked = !checkbox.checked; + }) + .always(function() { + $('body').css('cursor', 'auto'); }); + + return true; } function checkboxhighlight(box) { diff --git a/view/templates/group_side.tpl b/view/templates/group_side.tpl index 5796bb735c..31b9287ba8 100644 --- a/view/templates/group_side.tpl +++ b/view/templates/group_side.tpl @@ -9,7 +9,7 @@ {{if $group.cid}} {{/if}} diff --git a/view/theme/frio/templates/group_side.tpl b/view/theme/frio/templates/group_side.tpl index 947ae974e8..75983b36ee 100644 --- a/view/theme/frio/templates/group_side.tpl +++ b/view/theme/frio/templates/group_side.tpl @@ -28,7 +28,7 @@ diff --git a/view/theme/quattro/templates/group_side.tpl b/view/theme/quattro/templates/group_side.tpl index 620d2de75a..18a6105a6e 100644 --- a/view/theme/quattro/templates/group_side.tpl +++ b/view/theme/quattro/templates/group_side.tpl @@ -17,7 +17,7 @@ {{if $group.cid}} {{/if}} -- 2.39.5