- Automatically add 'Select All' action with Ctrl+A shortcut after first action group

- Implement Select All into selection controller so it works even if all rows aren't loaded
This commit is contained in:
Nathan Gray 2013-10-24 17:29:11 +00:00
parent 2f0f2ae303
commit 7c7d6391ab
4 changed files with 49 additions and 10 deletions

View File

@ -621,12 +621,34 @@ class etemplate_widget_nextmatch extends etemplate_widget
//echo "actions="; _debug_array($actions);
$egw_actions = array();
$n = 1;
$group = false;
foreach((array)$actions as $id => $action)
{
// in case it's only selectbox id => label pairs
if (!is_array($action)) $action = array('caption' => $action);
if ($default_attrs) $action += $default_attrs;
// Add 'Select All' after first group
if ($first_level && $group !== false && $action['group'] != $group && !$egw_actions[$prefix.'select_all'])
{
$egw_actions[$prefix.'select_all'] = array(
'caption' => 'Select all',
//'checkbox' => true,
'hint' => 'Select all entries',
'enabled' => true,
'shortcut' => array(
'keyCode' => 65, // A
'ctrl' => true,
'caption' => 'Ctrl+A'
),
'group' => $action['group'],
);
$action_links[] = $prefix.'select_all';
}
$group = $action['group'];
if (!$first_level && $n == $max_length && count($actions) > $max_length)
{
$id = 'more_'.count($actions); // we need a new unique id
@ -680,7 +702,7 @@ class etemplate_widget_nextmatch extends etemplate_widget
}
$egw_actions[$prefix.$id] = $action;
if (!$first_level && $n++ == $max_length) break;
}
//echo "egw_actions="; _debug_array($egw_actions);

View File

@ -62,6 +62,7 @@ var et2_dataview_selectionManager = Class.extend(
this._registeredRows = {};
this._focusedEntry = null;
this._invertSelection = false;
this._selectAll = false;
this._inUpdate = false;
this._total = 0;
this._children = [];
@ -160,6 +161,8 @@ var et2_dataview_selectionManager = Class.extend(
resetSelection: function () {
this._invertSelection = false;
this._selectAll = false;
this._actionObjectManager.setAllSelected(false);
for (var key in this._registeredRows)
{
@ -168,6 +171,7 @@ var et2_dataview_selectionManager = Class.extend(
},
setSelected: function (_uid, _selected) {
this._selectAll = false;
var entry = this._getRegisteredRowsEntry(_uid);
this._updateEntryState(entry,
egwSetBit(entry.state, EGW_AO_STATE_SELECTED, _selected));
@ -196,9 +200,11 @@ var et2_dataview_selectionManager = Class.extend(
// Reset the selection
this.resetSelection();
// Set the "invert selection" flag
this._invertSelection = true;
this._selectAll = true;
// Tell action manager to do all
this._actionObjectManager.setAllSelected(true);
// Update the selection
for (var key in this._registeredRows)
{
@ -225,11 +231,10 @@ var et2_dataview_selectionManager = Class.extend(
}
// Return an array containing those ids
// RB: we are currently NOT using "inverted" (selectAll is not bound/called),
// but an all attribute comming from objectManager, if Ctrl-A was pressed and nothing deselected later
// RB: we are currently NOT using "inverted"
return {
//"inverted": this._invertSelection,
"all": this._actionObjectManager.getAllSelected(),
"all": this._selectAll,
"ids": ids
};
},
@ -363,8 +368,11 @@ var et2_dataview_selectionManager = Class.extend(
_updateEntryState: function (_entry, _state) {
if (this._invertSelection)
if (this._selectAll)
{
_state |= EGW_AO_STATE_SELECTED;
}
else if (this._invertSelection)
{
_state ^= EGW_AO_STATE_SELECTED;
}

View File

@ -2435,7 +2435,7 @@ var et2_nextmatch_entryheader = et2_link_entry.extend(et2_INextmatchHeader,
} else {
delete (this.nextmatch.activeFilters["col_filter"][this.id]);
}
this.nextmatch.applyFilters();
this.nextmatch.applyFilters.call(this.nextmatch);
},
/**

View File

@ -151,6 +151,15 @@ var et2_nextmatch_controller = et2_dataview_controller.extend(et2_IDataProvider,
// Call the nm_action function with the ids
nm_action(_action, _senders, _target, ids);
});
// Set the 'Select All' handler
var select_all = this._actionManager.getActionById('select_all');
if(select_all)
{
select_all.set_onExecute(jQuery.proxy(function(action, selected) {
this._selectionMgr.selectAll();
}, this));
}
// Initialize the object manager
var gom = egw_getObjectManager(this.egw.appName);