From 86bd6b719afa3928dd3164f0dcb6f75486e16fc5 Mon Sep 17 00:00:00 2001 From: nathangray Date: Mon, 28 Sep 2020 10:51:30 -0600 Subject: [PATCH] Addressbook: Delete contacts over AJAX to avoid refresh --- addressbook/inc/class.addressbook_ui.inc.php | 27 ++++++++++++++++++++ addressbook/js/app.js | 22 ++++++++++++++++ addressbook/js/app.ts | 25 ++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index 3aaed02dcd..57d06f6072 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -804,6 +804,7 @@ class addressbook_ui extends addressbook_bo 'confirm_multiple' => 'Delete these entries', 'group' => $group, 'disableClass' => 'rowNoDelete', + 'onExecute' => 'javaScript:app.addressbook.action', ); } if ($this->grants[0] & Acl::DELETE) @@ -1131,6 +1132,32 @@ class addressbook_ui extends addressbook_bo Api\Cache::setSession('addressbook', 'advanced_search', false); } + /** + * Apply an action to multiple events, but called via AJAX instead of submit + * + * @param string $action + * @param string[] $selected + * @param bool $all_selected All entries are selected, not just what's in $selected + * @param bool $skip_notification + */ + public function ajax_action($action, $selected, $all_selected, $skip_notification = false) + { + $success = 0; + $failed = 0; + $action_msg = ''; + $session_name = 'index'; + + if($this->action($action, $selected, $all_selected, $success, $failed, $action_msg, $session_name, $msg, $skip_notification)) + { + $msg = lang('%1 event(s) %2',$success,$action_msg); + } + elseif(is_null($msg)) + { + $msg .= lang('%1 event(s) %2, %3 failed because of insufficient rights !!!',$success,$action_msg,$failed); + } + Api\Json\Response::get()->message($msg); + } + /** * apply an action to multiple contacts * diff --git a/addressbook/js/app.js b/addressbook/js/app.js index 4adc0d33d1..ac01850987 100644 --- a/addressbook/js/app.js +++ b/addressbook/js/app.js @@ -372,6 +372,28 @@ var AddressbookApp = /** @class */ (function (_super) { } nm_action(_action, _senders); }; + /** + * Actions via ajax + * + * @param {egwAction} _action + * @param {egwActionObject[]} _selected + */ + AddressbookApp.prototype.action = function (_action, _selected) { + var _a, _b; + var all = (_a = _action.parent.data.nextmatch) === null || _a === void 0 ? void 0 : _a.getSelection().all; + var no_notifications = ((_b = _action.parent.getActionById("no_notifications")) === null || _b === void 0 ? void 0 : _b.checked) || false; + var ids = []; + // Loop so we get just the app's ID + for (var i = 0; i < _selected.length; i++) { + var id = _selected[i].id; + ids.push(id.split("::").pop()); + } + switch (_action.id) { + case 'delete': + egw.json("addressbook.addressbook_ui.ajax_action", [_action.id, ids, all, no_notifications]).sendRequest(true); + break; + } + }; /** * [More...] in phones clicked: copy allways shown phone numbers to phone popup * diff --git a/addressbook/js/app.ts b/addressbook/js/app.ts index 58f62cc1f8..b2d281131d 100644 --- a/addressbook/js/app.ts +++ b/addressbook/js/app.ts @@ -442,6 +442,31 @@ class AddressbookApp extends EgwApp nm_action(_action, _senders); } + /** + * Actions via ajax + * + * @param {egwAction} _action + * @param {egwActionObject[]} _selected + */ + action(_action : egwAction, _selected : egwActionObject[]) + { + let all = _action.parent.data.nextmatch?.getSelection().all; + let no_notifications = _action.parent.getActionById("no_notifications")?.checked || false; + let ids = []; + // Loop so we get just the app's ID + for(var i = 0; i < _selected.length; i++) + { + var id = _selected[i].id; + ids.push(id.split("::").pop()); + } + switch(_action.id) + { + case 'delete': + egw.json("addressbook.addressbook_ui.ajax_action",[_action.id, ids, all, no_notifications]).sendRequest(true); + break; + } + } + /** * [More...] in phones clicked: copy allways shown phone numbers to phone popup *