Remove resources from calendar sidebox, new calendar owner widget covers it all

(Also avoids the layout / sidebox size bug  on macs)
This commit is contained in:
Nathan Gray 2016-03-01 20:40:49 +00:00
parent c0ac30c1cd
commit 96ba38dbf8
2 changed files with 0 additions and 213 deletions

View File

@ -101,10 +101,6 @@ class resources_hooks
'type' => 'r',// one char type-identifiy for this resources 'type' => 'r',// one char type-identifiy for this resources
'icon' => 'calicon',//icon 'icon' => 'calicon',//icon
'participants_header' => lang('resources'), // header of participants from this type 'participants_header' => lang('resources'), // header of participants from this type
'cal_sidebox' => array(
'menu_title' => lang('Select resources'),
'file' => 'resources.resources_ui.get_calendar_sidebox'
)
); );
} }

View File

@ -574,214 +574,5 @@ class resources_ui
return $this->tmpl->exec('resources.resources_ui.edit',$content,$sel_options,$read_only,$preserv,2); return $this->tmpl->exec('resources.resources_ui.edit',$content,$sel_options,$read_only,$preserv,2);
} }
/**
* get_calendar_sidebox
* get data für calendar sidebox
*
* @author Lukas Weiss <wnz_gh05t@users.sourceforge.net>
* @param array $param with keys menuaction, owner and optional date and return_array
* @return array with: label=>link or array with text
*/
function get_calendar_sidebox($param)
{
$cats = $this->bo->acl->get_cats(EGW_ACL_CALREAD);
if (!$cats) return array();
if(array_key_exists('return_array', $param))
{
$return_array = $param['return_array'];
unset($param['return_array']);
}
$owners = explode(',',$param['owner']);
$res_cats = $selected = array();
// add already selected single resources to the selectbox, eg. call of the resource-calendar from the resources app
$resources = array();
$res_ids = array();
foreach($owners as $key => $owner)
{
if ($owner{0} == 'r')
{
$res_ids[] = (int) substr($owner,1);
$selected[] = $owner;
}
}
$content = array('owner' => $selected);
$sel_options['owner'] = self::tree_data('/',$root,$selected);
if(!isset($return_array))
{
$et2 = new etemplate_new('resources.calendar_sidebox');
$et2->exec('calendar.calendar_ui.sidebox_etemplate', $content, $sel_options);
$tree = '<span id="calendar-resources-et2_target" />';
return array(
array(
'text' => $tree,
'no_lang' => True,
'link' => False
)
);
}
else
{
return array_merge($resources,$res_cats);
}
}
/**
* Autoload tree from $_GET['id'] on
*/
public static function ajax_tree()
{
etemplate_widget_tree::send_quote_json(self::tree_data(!empty($_GET['id']) ? $_GET['id'] : '/'));
}
public static function tree_data($root = '/', &$_parent = null, $open = array())
{
//error_log(__METHOD__ . "($root,".($_parent ? 'true,' : ',').array2string($open).')');
if(!$_parent)
{
$tree = array('id' => $root === '/' ? 0 : $root, 'item' => array(), 'child' => 1);
}
else
{
$tree =& $_parent;
}
$bo = new resources_bo();
if($root == '/')
{
// Start with categories
$cats = $bo->acl->get_cats(EGW_ACL_CALREAD);
foreach($cats as $cat_id => $cat_name)
{
if(categories::id2name($cat_id, 'parent')) continue;
$child = array(
etemplate_widget_tree::ID => trim(str_replace(' / ','/', $root.categories::id2name( $cat_id ,'path'))),
etemplate_widget_tree::LABEL => trim(str_replace('&nbsp;','',$cat_name))
);
self::tree_data($child[etemplate_widget_tree::ID],$child,$open);
$tree[etemplate_widget_tree::CHILDREN][] = $child;
}
}
else if ($root[0] == 'r')
{
// Fetch resources for a given category
$list = array();
$resources = array();
if ($root[0] == 'r')
{
$tree['id'] = $root;
$resource = $bo->read(substr($root,1));
$tree['text'] = $resource['name'];
$tree['im0'] = $tree['im1'] = $tree['im2'] = etemplate_widget_tree::imagePath($bo->get_picture($resource['res_id']));
$tree['item'] = array();
if(in_array($tree['id'], $open))
{
$tree[etemplate_widget_tree::OPEN] = true;
}
$list =& $tree['item'];
$query = array('filter2' => substr($root,1),'csv_export' => true);
if($bo->get_rows($query,$resources,$readonlys))
{
foreach($resources as $res)
{
if(!$res['res_id']) continue;
$data = array();
$data['id'] = 'r'.$res['res_id'];
self::tree_data($data[etemplate_widget_tree::ID],$data,$open);
$list[] = $data;
}
}
}
}
else
{
$cat_id = $bo->cats->name2id(trim(array_pop(explode('/',$root))));
$tree[etemplate_widget_tree::ID] = $root;
$tree[etemplate_widget_tree::LABEL] = categories::id2name($cat_id,'name');
$tree[etemplate_widget_tree::TOOLTIP] = lang(categories::id2name($cat_id,'description'));
$tree[etemplate_widget_tree::CHILDREN] = array();
$cat_data = categories::id2name($cat_id, 'data');
if(is_array($cat_data) && $cat_data['icon'])
{
$tree['im0'] = $tree['im1'] = $tree['im2'] = etemplate_widget_tree::imagePath(egw::link('/phpgwapi/images/'.$cat_data['icon'],array(),false));
}
$query = array('filter' => $cat_id,'filter2' => -1,'csv_export' => true);
$list =& $tree['item'];
$resources = array();
// Only continue if the category has resources
// The get_rows call considers child categories too
if($bo->get_rows($query,$resources,$readonlys))
{
$tree[etemplate_widget_tree::AUTOLOAD_CHILDREN] = 1;
$cats = $bo->acl->get_cats(EGW_ACL_CALREAD, $cat_id);
foreach($cats as $sub_cat_id => $sub_cat_name)
{
$child = array(
etemplate_widget_tree::ID => trim(str_replace(' / ','/', categories::id2name( $sub_cat_id ,'path'))),
etemplate_widget_tree::LABEL => trim(str_replace('&nbsp;','',$sub_cat_name))
);
// Give child a chance (it might have a selected resource, but do not add it if it has no children
if(!$_parent || $tree[etemplate_widget_tree::OPEN])
{
self::tree_data($child[etemplate_widget_tree::ID],$child,$open);
if($child[etemplate_widget_tree::CHILDREN] || $child[etemplate_widget_tree::AUTOLOAD_CHILDREN])
{
$list[] = $child;
}
}
}
foreach($resources as $res)
{
if(!$res['res_id']) continue;
if(in_array('r'.$res['res_id'],$open))
{
$tree[etemplate_widget_tree::OPEN] = true;
}
if($res['cat_id'] != $cat_id) continue;
$data = array();
$data[etemplate_widget_tree::ID] = 'r'.$res['res_id'];
$data[etemplate_widget_tree::LABEL] = $res['name'];
$data[etemplate_widget_tree::AUTOLOAD_CHILDREN] = $res['acc_count'];
if(!$_parent)
{
self::tree_data($data[etemplate_widget_tree::ID],$data,$open);
$list[] = $data;
}
}
}
}
if($_parent) return;
self::strip_item_keys($tree['item']);
return $tree;
}
/**
* Attribute 'item' has to be an array
*
* @param array $items
*/
private static function strip_item_keys(array &$items)
{
$items = array_values($items);
foreach($items as &$item)
{
if (is_array($item) && isset($item['item']))
{
self::strip_item_keys($item['item']);
}
}
}
} }