avoid second full refresh by sending delete action via ajax

This commit is contained in:
Ralf Becker 2020-07-24 14:43:34 +02:00
parent 56376465f2
commit 6d4aaade1b
7 changed files with 128 additions and 52 deletions

View File

@ -1029,7 +1029,6 @@ class infolog_ui
if (!isset($this->bo->grants[$group])) unset($sel_options['info_type'][$type]);
}
return $this->tmpl->exec('infolog.infolog_ui.index',$values,$sel_options,$readonlys,$persist,$return_html ? -1 : 0);
}
@ -1333,6 +1332,33 @@ class infolog_ui
return $actions;
}
/**
* Apply an action to multiple events, but called via AJAX instead of submit
*
* @param string $action
* @param string[] $selected
* @param bool $all_selected All events are selected, not just what's in $selected
*/
public function ajax_action($action, $selected, $all_selected)
{
$success = 0;
$failed = 0;
$action_msg = '';
$session_name = 'calendar_list';
if($this->action($action, $selected, $all_selected, $success, $failed, $action_msg, [], $msg))
{
$msg = lang('%1 entries %2',$success,$action_msg);
}
elseif(is_null($msg))
{
$msg = lang('%1 entries %2, %3 failed because of insufficent rights !!!',$success,$action_msg,$failed);
}
$app = Api\Json\Push::onlyFallback() || $all_selected ? 'infolog' : 'msg-only-push-refresh';
Api\Json\Response::get()->call('egw.refresh', $msg, $app, $selected[0], $all_selected || count($selected) > 1 ? null :
$action === 'delete' ? 'delete' : 'edit', $app, null, null, $failed ? 'error' : 'success');
}
/**
* Handles actions on multiple infologs
*

View File

@ -30,7 +30,6 @@ require("jqueryui");
require("../jsapi/egw_global");
require("../etemplate/et2_types");
var egw_app_1 = require("../../api/js/jsapi/egw_app");
var et2_widget_dialog_1 = require("../../api/js/etemplate/et2_widget_dialog");
var etemplate2_1 = require("../../api/js/etemplate/etemplate2");
var et2_extension_nextmatch_1 = require("../../api/js/etemplate/et2_extension_nextmatch");
/**
@ -46,8 +45,12 @@ var InfologApp = /** @class */ (function (_super) {
* @memberOf app.infolog
*/
function InfologApp() {
var _this =
// call parent
return _super.call(this, 'infolog', 'info_datemodified') || this;
_super.call(this, 'infolog', 'info_datemodified') || this;
_this._action_ids = [];
_this._action_all = false;
return _this;
}
/**
* Destructor
@ -352,24 +355,6 @@ var InfologApp = /** @class */ (function (_super) {
(show) ? $select.each(function (i, e) { jQuery(e).hide(); }) : $select.each(function (i, e) { jQuery(e).show(); });
}
};
InfologApp.prototype.confirm_delete_2 = function (_action, _senders) {
var children = false;
var child_button = jQuery('#delete_sub').get(0) || jQuery('[id*="delete_sub"]').get(0);
if (child_button) {
for (var i = 0; i < _senders.length; i++) {
if (jQuery(_senders[i].iface.node).hasClass('infolog_rowHasSubs')) {
children = true;
break;
}
}
child_button.style.display = children ? 'block' : 'none';
}
var callbackDeleteDialog = function (button_id) {
if (button_id == et2_widget_dialog_1.et2_dialog.YES_BUTTON) {
}
};
et2_widget_dialog_1.et2_dialog.show_dialog(callbackDeleteDialog, this.egw.lang("Do you really want to DELETE this Rule"), this.egw.lang("Delete"), {}, et2_widget_dialog_1.et2_dialog.BUTTONS_YES_NO_CANCEL, et2_widget_dialog_1.et2_dialog.WARNING_MESSAGE);
};
/**
* Confirm delete
* If entry has children, asks if you want to delete children too
@ -378,10 +363,14 @@ var InfologApp = /** @class */ (function (_super) {
*@param _senders
*/
InfologApp.prototype.confirm_delete = function (_action, _senders) {
var _a;
var children = false;
var child_button = jQuery('#delete_sub').get(0) || jQuery('[id*="delete_sub"]').get(0);
this._action_all = (_a = _action.parent.data.nextmatch) === null || _a === void 0 ? void 0 : _a.getSelection().all;
this._action_ids = [];
if (child_button) {
for (var i = 0; i < _senders.length; i++) {
this._action_ids.push(_senders[i].id.split("::").pop());
if (jQuery(_senders[i].iface.getDOMNode()).hasClass('infolog_rowHasSubs')) {
children = true;
break;
@ -391,6 +380,14 @@ var InfologApp = /** @class */ (function (_super) {
}
nm_open_popup(_action, _senders);
};
/**
* Callback for action using ids set(!) in this._action_ids and this._action_all
*
* @param _action
*/
InfologApp.prototype.actionCallback = function (_action) {
egw.json("infolog.infolog_ui.ajax_action", [_action, this._action_ids, this._action_all]).sendRequest(true);
};
/**
* Add email from addressbook
*

View File

@ -397,32 +397,6 @@ class InfologApp extends EgwApp
}
}
confirm_delete_2(_action, _senders)
{
var children = false;
var child_button = jQuery('#delete_sub').get(0) || jQuery('[id*="delete_sub"]').get(0);
if(child_button)
{
for(var i = 0; i < _senders.length; i++)
{
if (jQuery(_senders[i].iface.node).hasClass('infolog_rowHasSubs'))
{
children = true;
break;
}
}
child_button.style.display = children ? 'block' : 'none';
}
var callbackDeleteDialog = function (button_id)
{
if (button_id == et2_dialog.YES_BUTTON )
{
}
};
et2_dialog.show_dialog(callbackDeleteDialog, this.egw.lang("Do you really want to DELETE this Rule"),this.egw.lang("Delete"), {},et2_dialog.BUTTONS_YES_NO_CANCEL, et2_dialog.WARNING_MESSAGE);
}
/**
* Confirm delete
* If entry has children, asks if you want to delete children too
@ -432,12 +406,16 @@ class InfologApp extends EgwApp
*/
confirm_delete(_action, _senders)
{
var children = false;
var child_button = jQuery('#delete_sub').get(0) || jQuery('[id*="delete_sub"]').get(0);
let children = false;
let child_button = jQuery('#delete_sub').get(0) || jQuery('[id*="delete_sub"]').get(0);
this._action_all = _action.parent.data.nextmatch?.getSelection().all;
this._action_ids = [];
if(child_button)
{
for(var i = 0; i < _senders.length; i++)
for(let i = 0; i < _senders.length; i++)
{
this._action_ids.push(_senders[i].id.split("::").pop());
if (jQuery(_senders[i].iface.getDOMNode()).hasClass('infolog_rowHasSubs'))
{
children = true;
@ -449,6 +427,19 @@ class InfologApp extends EgwApp
nm_open_popup(_action, _senders);
}
private _action_ids = [];
private _action_all = false;
/**
* Callback for action using ids set(!) in this._action_ids and this._action_all
*
* @param _action
*/
actionCallback(_action)
{
egw.json("infolog.infolog_ui.ajax_action",[_action, this._action_ids, this._action_all]).sendRequest(true);
}
/**
* Add email from addressbook
*

View File

@ -177,8 +177,8 @@
<description value="Delete" class="promptheader"/>
<description value="Delete selected entries?" id="delete_prompt"/>
<hbox>
<button label="Yes - Delete" id="delete" onclick="nm_submit_popup(this); return false;" image="check" background_image="true"/>
<button label="Yes - Delete including sub-entries" id="delete_sub" onclick="nm_popup_action.id = 'delete_sub'; nm_submit_popup(this); return false;" image="check" background_image="true"/>
<button label="Yes - Delete" id="delete" onclick="app.infolog.actionCallback('delete'); return false;" image="check" background_image="true"/>
<button label="Yes - Delete including sub-entries" id="delete_sub" onclick="app.infolog.actionCallback('delete_sub'); return false;" image="check" background_image="true"/>
<button label="No - Cancel" id="delete_cancel" onclick="nm_hide_popup(this,'delete_popup');" image="cancelled" background_image="true"/>
</hbox>
</vbox>

View File

@ -1058,6 +1058,7 @@ class timesheet_ui extends timesheet_bo
'children' => $this->get_status_labels(),
'prefix' => 'to_status_',
'enabled' => (boolean)$this->get_status_labels(),
'onExecute' => 'javaScript:app.timesheet.ajax_action',
),
);
@ -1087,6 +1088,7 @@ class timesheet_ui extends timesheet_bo
'confirm_multiple' => 'Delete these entries',
'group' => ++$group,
'disableClass' => 'rowNoDelete',
'onExecute' => 'javaScript:app.timesheet.ajax_action',
),
);
if ($query['col_filter']['ts_status'] == self::DELETED_STATUS)
@ -1098,6 +1100,7 @@ class timesheet_ui extends timesheet_bo
'icon' => 'revert',
'group' => $group,
'disableClass' => 'rowNoUndelete',
'onExecute' => 'javaScript:app.timesheet.ajax_action',
);
}
// enable additonal edit check for following actions, if they are generally available
@ -1112,6 +1115,33 @@ class timesheet_ui extends timesheet_bo
return $actions;
}
/**
* Apply an action to multiple events, but called via AJAX instead of submit
*
* @param string $action
* @param string[] $selected
* @param bool $all_selected All events are selected, not just what's in $selected
*/
public function ajax_action($action, $selected, $all_selected)
{
$success = 0;
$failed = 0;
$action_msg = '';
$session_name = 'index';
if($this->action($action, $selected, $all_selected, $success, $failed, $action_msg, $session_name, $msg))
{
$msg .= lang('%1 timesheets(s) %2',$success,$action_msg);
}
elseif(empty($msg))
{
$msg = lang('%1 timesheets(s) %2, %3 failed because of insufficent rights !!!',$success,$action_msg,$failed);
}
$app = Api\Json\Push::onlyFallback() || $all_selected ? 'timesheet' : 'msg-only-push-refresh';
Api\Json\Response::get()->call('egw.refresh', $msg, $app, $selected[0], $all_selected || count($selected) > 1 ? null :
$action === 'delete' ? 'delete' : 'edit', $app, null, null, $failed ? 'error' : 'success');
}
/**
* apply an action to multiple timesheets
*

View File

@ -209,6 +209,21 @@ var TimesheetApp = /** @class */ (function (_super) {
}
etemplate2_1.etemplate2.app_refresh("", pushData.app, pushData.id, pushData.type);
};
/**
* Run action via ajax
*
* @param _action
* @param _senders
*/
TimesheetApp.prototype.ajax_action = function (_action, _senders) {
var _a;
var all = (_a = _action.parent.data.nextmatch) === null || _a === void 0 ? void 0 : _a.getSelection().all;
var ids = [];
for (var i = 0; i < _senders.length; i++) {
ids.push(_senders[i].id.split("::").pop());
}
egw.json("timesheet.timesheet_ui.ajax_action", [_action.id, ids, all]).sendRequest(true);
};
return TimesheetApp;
}(egw_app_1.EgwApp));
app.classes.timesheet = TimesheetApp;

View File

@ -242,6 +242,23 @@ class TimesheetApp extends EgwApp
}
etemplate2.app_refresh("",pushData.app, pushData.id, pushData.type);
}
/**
* Run action via ajax
*
* @param _action
* @param _senders
*/
ajax_action(_action, _senders)
{
let all = _action.parent.data.nextmatch?.getSelection().all;
let ids = [];
for(let i = 0; i < _senders.length; i++)
{
ids.push(_senders[i].id.split("::").pop());
}
egw.json("timesheet.timesheet_ui.ajax_action",[_action.id, ids, all]).sendRequest(true);
}
}
app.classes.timesheet = TimesheetApp;