experimenting with new ideas for admin UI

This commit is contained in:
Ralf Becker 2013-05-12 13:44:46 +00:00
parent 8cebfe3339
commit 9454438a77
4 changed files with 207 additions and 3 deletions

View File

@ -40,7 +40,7 @@ class admin_prefs_sidebox_hooks
if ($GLOBALS['egw_info']['user']['apps']['admin'] && $location != 'admins')
{
$file['new admin'] = egw::link('/index.php', array('menuaction' => 'admin.admin_ui.index'));
if (! $GLOBALS['egw']->acl->check('site_config_access',1,'admin'))
{
$file['Site Configuration'] = egw::link('/index.php','menuaction=admin.uiconfig.index&appname=admin');
@ -54,7 +54,11 @@ class admin_prefs_sidebox_hooks
*/
if (! $GLOBALS['egw']->acl->check('account_access',1,'admin'))
{
$file['User Accounts'] = egw::link('/index.php','menuaction=admin.uiaccounts.list_users');
$file['User Accounts'] = array(
'id' => '/accounts',
'icon' => common::image('addressbook', 'accounts'),
'link' => egw::link('/index.php','menuaction=admin.uiaccounts.list_users'),
);
}
if (! $GLOBALS['egw']->acl->check('account_access',16,'admin'))
@ -64,7 +68,12 @@ class admin_prefs_sidebox_hooks
if (! $GLOBALS['egw']->acl->check('group_access',1,'admin'))
{
$file['User Groups'] = egw::link('/index.php','menuaction=admin.uiaccounts.list_groups');
$file['User Groups'] = array(
'id' => '/groups',
'icon' => common::image('addressbook', 'group'),
'child' => 1,
'link' => egw::link('/index.php','menuaction=admin.uiaccounts.list_groups'),
);
}
if (! $GLOBALS['egw']->acl->check('applications_access',1,'admin'))
@ -127,6 +136,7 @@ class admin_prefs_sidebox_hooks
}
else
{
foreach($file as &$url) if (is_array($url)) $url = $url['link'];
display_sidebox($appname,lang('Admin'),$file);
}
}

View File

@ -0,0 +1,184 @@
<?php
/**
* EGroupware: Admin app UI
*
* @link http://www.egroupware.org
* @author Ralf Becker <rb@stylite.de>
* @package admin
* @copyright (c) 2013 by Ralf Becker <rb@stylite.de>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
require_once EGW_INCLUDE_ROOT.'/etemplate/inc/class.etemplate.inc.php';
/**
* UI for admin
*/
class admin_ui
{
/**
* Methods callable via menuaction
* @var array
*/
public $public_functions = array(
'index' => true,
);
/**
* New index page
*
* @param array $content
* @param string $msg
*/
public function index(array $content=null, $msg='')
{
$tpl = new etemplate('admin.index');
$content = array();
$content['msg'] = 'Hi Ralf ;-)';
$sel_options['tree'] = $this->tree_data();
$tpl->exec('admin.admin_ui.index', $content, $sel_options);
}
/**
* Autoload tree from $_GET['id'] on
*/
public static function ajax_tree()
{
header('Content-Type: application/json; charset=utf-8');
echo json_encode(self::tree_data(!empty($_GET['id']) ? $_GET['id'] : '/'));
common::egw_exit();
}
/**
* Get data for navigation tree
*
* Example:
* array(
* 'id' => 0, 'item' => array(
* array('id' => '/INBOX', 'text' => 'INBOX', 'tooltip' => 'Your inbox', 'open' => 1, 'im1' => 'kfm_home.png', 'im2' => 'kfm_home.png', 'child' => '1', 'item' => array(
* array('id' => '/INBOX/sub', 'text' => 'sub', 'im0' => 'folderClosed.gif'),
* array('id' => '/INBOX/sub2', 'text' => 'sub2', 'im0' => 'folderClosed.gif'),
* )),
* array('id' => '/user', 'text' => 'user', 'child' => '1', 'item' => array(
* array('id' => '/user/birgit', 'text' => 'birgit', 'im0' => 'folderClosed.gif'),
* )),
* ));
*
* @param string $root='/'
* @return array
*/
public static function tree_data($root = '/')
{
$tree = array('id' => $root === '/' ? 0 : $root, 'item' => array(), 'child' => 1);
if ($root == '/')
{
$hook_data = self::call_hook();
foreach($hook_data as $app => $app_data)
{
foreach($app_data as $text => $data)
{
if (!is_array($data))
{
$data = array(
'link' => $data,
);
}
if (empty($data['text'])) $data['text'] = $text;
if (empty($data['id']))
{
$data['id'] = $root.($app == 'admin' ? 'admin' : 'apps/'.$app).'/';
$data['id'] .= preg_match('/menuaction=([^&]+)/', $data['link'], $matches) ? $matches[1] : md5($link);
}
if (!empty($data['icon']))
{
$icon = $data['icon'];
list(,$icon) = explode($GLOBALS['egw_info']['server']['webserver_url'], $icon);
$icon = '../../../../..'.$icon;
if ($data['child'] || $data['item'])
{
$data['im1'] = $data['im2'] = $icon;
}
else
{
$data['im0'] = $icon;
}
}
$parent =& $tree['item'];
$parts = explode('/', $data['id']);
if ($data['id'][0] == '/') array_shift($parts); // remove root
$last_part = array_pop($parts);
$path = '';
foreach($parts as $part)
{
$path .= ($path == '/' ? '' : '/').$part;
if (!isset($parent[$path]))
{
$icon = $part == 'apps' ? common::image('phpgwapi', 'home') : common::image($part, 'navbar');
list(,$icon) = explode($GLOBALS['egw_info']['server']['webserver_url'], $icon);
$icon = '../../../../..'.$icon;
$parent[$path] = array(
'id' => $path,
'text' => $part == 'apps' ? lang('Applications') : lang($part),
//'im0' => 'folderOpen.gif',
'im1' => $icon,
'im2' => $icon,
'item' => array(),
'child' => 1,
);
}
$parent =& $parent[$path]['item'];
}
$data['text'] = lang($data['text']);
if (!empty($data['title'])) $data['title'] = lang($data['title']);
$parent[$data['id']] = $data;
}
}
}
elseif ($root == '/groups')
{
$tree['item'][] = array(
'text' => 'Admins',
'id' => '/groups/Admins',
);
$tree['item'][] = array(
'text' => 'Default',
'id' => '/groups/Default',
);
}
self::strip_item_keys($tree['item']);
//_debug_array($tree); exit;
return $tree;
}
private static function strip_item_keys(&$items)
{
$items = array_values($items);
foreach($items as &$item)
{
if (is_array($item) && isset($item['item']))
{
self::strip_item_keys($item['item']);
}
}
}
public static $hook_data = array();
/**
* Return data from regular admin hook calling display_section() instead of returning it
*
* @return array appname => array of label => link/data pairs
*/
protected static function call_hook()
{
self::$hook_data = array();
function display_section($appname,$file,$file2=False)
{
admin_ui::$hook_data[$appname] = $file2 ? $file2 : $file;
error_log(__METHOD__."(".array2string(func_get_args()).")");
}
return array_merge($GLOBALS['egw']->hooks->process('admin', array('admin')), self::$hook_data);
}
}

View File

@ -86,6 +86,7 @@ function display_section($appname,$file,$file2=False)
while(list($text,$url) = each($file))
{
if (is_array($url)) $url = $url['link'];
// If user doesn't have application configuration access, then don't show the configuration links
if (strpos($url, 'admin.uiconfig') === False || !$GLOBALS['egw']->acl->check('site_config_access',1,'admin'))
{

View File

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<!-- $Id$ -->
<overlay>
<template id="admin.index" template="" lang="" group="0" version="1.9.001">
<tree autoloading="admin_ui::ajax_tree" id="tree"/><!-- onclick="app.admin.run(widget.event_args[0],widget);" parent_node="tree_target"/ -->
<html id="msg"/>
<!-- iframe frameborder="1" height="auto" id="iframe" scrolling="auto" width="100%"/ -->
</template>
</overlay>