Addressbook: Delete contacts over AJAX to avoid refresh

This commit is contained in:
nathangray 2020-09-28 10:51:30 -06:00
parent ba7cbc5d5a
commit 86bd6b719a
3 changed files with 74 additions and 0 deletions

View File

@ -804,6 +804,7 @@ class addressbook_ui extends addressbook_bo
'confirm_multiple' => 'Delete these entries', 'confirm_multiple' => 'Delete these entries',
'group' => $group, 'group' => $group,
'disableClass' => 'rowNoDelete', 'disableClass' => 'rowNoDelete',
'onExecute' => 'javaScript:app.addressbook.action',
); );
} }
if ($this->grants[0] & Acl::DELETE) if ($this->grants[0] & Acl::DELETE)
@ -1131,6 +1132,32 @@ class addressbook_ui extends addressbook_bo
Api\Cache::setSession('addressbook', 'advanced_search', false); 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 * apply an action to multiple contacts
* *

View File

@ -372,6 +372,28 @@ var AddressbookApp = /** @class */ (function (_super) {
} }
nm_action(_action, _senders); 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 * [More...] in phones clicked: copy allways shown phone numbers to phone popup
* *

View File

@ -442,6 +442,31 @@ class AddressbookApp extends EgwApp
nm_action(_action, _senders); 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 * [More...] in phones clicked: copy allways shown phone numbers to phone popup
* *