Add 'None' category option to context menu for all apps using nextmatch::category_action()

This commit is contained in:
Nathan Gray 2012-10-15 17:57:58 +00:00
parent 6996efe50b
commit fc8a139f23
3 changed files with 23 additions and 5 deletions

View File

@ -437,13 +437,15 @@ class addressbook_ui extends addressbook_bo
'group' => $group,
'children' => array(
'cat_add' => nextmatch_widget::category_action(
'addressbook',$group,'Add category', 'cat_add_'
'addressbook',$group,'Add category', 'cat_add_',
true, 0,nextmatch_widget::DEFAULT_MAX_MENU_LENGTH,false
)+array(
'icon' => 'foldertree_nolines_plus',
'disableClass' => 'rowNoEdit',
),
'cat_del' => nextmatch_widget::category_action(
'addressbook',$group,'Delete category', 'cat_del_'
'addressbook',$group,'Delete category', 'cat_del_',
true, 0,nextmatch_widget::DEFAULT_MAX_MENU_LENGTH,false
)+array(
'icon' => 'foldertree_nolines_minus',
'disableClass' => 'rowNoEdit',

View File

@ -776,14 +776,23 @@ class nextmatch_widget
* @param boolean $globals=true application global categories too
* @param int $parent_id=0 only returns cats of a certain parent
* @param int $max_cats_flat=self::DEFAULT_MAX_MENU_LENGTH use hierarchical display if more cats
* @param boolean $none_option = true Include an option 'None' to clear category
* @return array like self::egw_actions
*/
public static function category_action($app, $group=0, $caption='Change category',
$prefix='cat_', $globals=true, $parent_id=0, $max_cats_flat=self::DEFAULT_MAX_MENU_LENGTH)
$prefix='cat_', $globals=true, $parent_id=0, $max_cats_flat=self::DEFAULT_MAX_MENU_LENGTH, $none_option = true)
{
$cat = new categories(null,$app);
$cats = $cat->return_sorted_array($start=0, $limit=false, $query='', $sort='ASC', $order='cat_name', $globals, $parent_id, $unserialize_data=true);
if($none_option)
{
array_unshift($cats, array(
'id' => '',
'name' => 'None'
));
}
// if more than max_length cats, switch automatically to hierarchical display
if (count($cats) > $max_cats_flat)
{

View File

@ -1377,8 +1377,15 @@ else
break;
case 'cat':
$cat_name = categories::id2name($settings);
$action_msg = lang('changed category to %1', $cat_name);
if($settings)
{
$cat_name = categories::id2name($settings);
$action_msg = lang('changed category to %1', $cat_name);
}
else
{
$action_msg = lang('removed category');
}
$entry['info_cat'] = $settings;
if($this->bo->write($entry, true,true,true,$skip_notifications))
{