mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-27 09:09:04 +01:00
first take on preferences with et2, not yet working!
This commit is contained in:
parent
5eede4a8ef
commit
c9bfdcab5c
@ -446,6 +446,8 @@ class preferences_hooks
|
||||
}
|
||||
$file['common preferences'] = $GLOBALS['egw']->link('/index.php','menuaction=preferences.uisettings.index&appname=preferences');
|
||||
|
||||
$file['new settings'] = $GLOBALS['egw']->link('/index.php','menuaction=preferences.preferences_settings.index&appname=preferences');
|
||||
|
||||
display_section('preferences',$file);
|
||||
}
|
||||
|
||||
|
205
preferences/inc/class.preferences_settings.inc.php
Normal file
205
preferences/inc/class.preferences_settings.inc.php
Normal file
@ -0,0 +1,205 @@
|
||||
<?php
|
||||
/**
|
||||
* EGroupware: Preferences app UI for settings/preferences
|
||||
*
|
||||
* @link http://www.egroupware.org
|
||||
* @author Ralf Becker <rb@stylite.de>
|
||||
* @package preferences
|
||||
* @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 settings / preferences
|
||||
*/
|
||||
class preferences_settings
|
||||
{
|
||||
/**
|
||||
* Methods callable via menuaction
|
||||
* @var array
|
||||
*/
|
||||
public $public_functions = array(
|
||||
'index' => true,
|
||||
);
|
||||
/**
|
||||
* App we work on
|
||||
* @var string
|
||||
*/
|
||||
public $appname = 'preferences';
|
||||
/**
|
||||
* Preferences read by call_hook
|
||||
* @var array
|
||||
*/
|
||||
public $settings = array();
|
||||
|
||||
/**
|
||||
* Edit preferences
|
||||
*
|
||||
* @param array $content=null
|
||||
* @param string $msg=''
|
||||
*/
|
||||
function index(array $content=null, $msg='')
|
||||
{
|
||||
$tpl = new etemplate_new('preferences.settings');
|
||||
if (!is_array($content))
|
||||
{
|
||||
$appname = isset($_GET['appname']) ? $_GET['appname'] : 'preferences';
|
||||
if (!$this->call_hook($appname))
|
||||
{
|
||||
throw new egw_exception_wrong_parameter("Could not find settings for application: ".$_GET['appname']);
|
||||
}
|
||||
//_debug_array($this->settings); exit;
|
||||
$sel_options = $readonlys = $content = $tabs = array();
|
||||
// disable all but first tab and name current tab "tab1", for apps not using sections
|
||||
$tab = 'tab1';
|
||||
$readonlys['tabs'] = array(
|
||||
'tab2' => true,
|
||||
'tab3' => true,
|
||||
'tab4' => true,
|
||||
'tab5' => true,
|
||||
);
|
||||
|
||||
foreach($this->settings as $setting)
|
||||
{
|
||||
if (!is_array($setting)) continue;
|
||||
switch($setting['type'])
|
||||
{
|
||||
case 'section':
|
||||
$tabs[] = $setting['title'];
|
||||
$tab = 'tab'.count($tabs);
|
||||
$tpl->setElementAttribute($tab, 'label', $setting['title']);
|
||||
$readonlys['tabs'][$tab] = false;
|
||||
// fall through
|
||||
case 'subsection': // is in old code, but never seen it used
|
||||
continue 2;
|
||||
|
||||
case 'input':
|
||||
$setting['type'] = 'textbox';
|
||||
break;
|
||||
case 'check':
|
||||
$setting['type'] = 'select';
|
||||
$setting['values'] = array('no', 'yes');
|
||||
break;
|
||||
case 'multiselect':
|
||||
$setting['type'] = 'select';
|
||||
break;
|
||||
case 'color':
|
||||
$setting['type'] = 'colorpicker';
|
||||
break;
|
||||
}
|
||||
// move values/options to sel_options array
|
||||
if (isset($setting['values']) && is_array($setting['values']))
|
||||
{
|
||||
// need to call fix_encoded_options manually, as id is not matching because of autorepeat
|
||||
etemplate_widget_menupopup::fix_encoded_options($setting['values']);
|
||||
$sel_options[$tab][count($content[$tab]).'[value]'] = $setting['values'];
|
||||
unset($setting['values']);
|
||||
}
|
||||
$content[$tab][] = $setting;
|
||||
}
|
||||
//_debug_array($content); exit;
|
||||
//_debug_array($sel_options); exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->appname = $content['appname'];
|
||||
}
|
||||
$tpl->exec('preferences.preferences_settings.index', $content, $sel_options, $readonlys, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get preferences by calling various hooks to supply them
|
||||
*
|
||||
* Sets $this->appname and $this->settings
|
||||
*
|
||||
* @param string $appname
|
||||
* @return boolean
|
||||
*/
|
||||
protected function call_hook($appname)
|
||||
{
|
||||
$this->appname = $appname;
|
||||
|
||||
translation::add_app($this->appname);
|
||||
if($this->appname != 'preferences')
|
||||
{
|
||||
translation::add_app('preferences'); // we need the prefs translations too
|
||||
}
|
||||
|
||||
// calling app specific settings hook
|
||||
$settings = $GLOBALS['egw']->hooks->single('settings',$this->appname);
|
||||
// it either returns the settings or save it in $GLOBALS['settings'] (deprecated!)
|
||||
if (isset($settings) && is_array($settings) && $settings)
|
||||
{
|
||||
$this->settings = array_merge($this->settings,$settings);
|
||||
}
|
||||
elseif(isset($GLOBALS['settings']) && is_array($GLOBALS['settings']) && $GLOBALS['settings'])
|
||||
{
|
||||
$this->settings = array_merge($this->settings,$GLOBALS['settings']);
|
||||
}
|
||||
else
|
||||
{
|
||||
return False; // no settings returned
|
||||
}
|
||||
|
||||
// calling settings hook all apps can answer (for a specific app)
|
||||
foreach($GLOBALS['egw']->hooks->process('settings_'.$this->appname,$this->appname,true) as $app => $settings)
|
||||
{
|
||||
if (isset($settings) && is_array($settings) && $settings)
|
||||
{
|
||||
$this->settings = array_merge($this->settings,$settings);
|
||||
}
|
||||
}
|
||||
/* Remove ui-only settings */
|
||||
if($this->xmlrpc)
|
||||
{
|
||||
foreach($this->settings as $key => $valarray)
|
||||
{
|
||||
if(!$valarray['xmlrpc'])
|
||||
{
|
||||
unset($this->settings[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Here we include the settings hook file for the current template, if it exists.
|
||||
This is not handled by the hooks class and is only valid if not using xml-rpc.
|
||||
*/
|
||||
$tmpl_settings = EGW_SERVER_ROOT.$GLOBALS['egw']->framework->template_dir.'/hook_settings.inc.php';
|
||||
if($this->appname == 'preferences' && file_exists($tmpl_settings))
|
||||
{
|
||||
include($tmpl_settings);
|
||||
$this->settings = array_merge($this->settings,$GLOBALS['settings']);
|
||||
}
|
||||
}
|
||||
// check if we have a default/forced value from the settings hook,
|
||||
// which is NOT stored as default currently
|
||||
// --> store it as default, to allow to propagate defaults to existing installations
|
||||
if ($appname == 'preferences') $appname = 'common';
|
||||
foreach ($this->settings as $name => $data)
|
||||
{
|
||||
// only set not yet set default prefs, so user is able to unset it again with ""
|
||||
// (only works with type vfs_*, other types delete empty values!)
|
||||
if (!isset($GLOBALS['egw']->preferences->default[$appname][$name]) &&
|
||||
((string)$data['default'] !== '' || (string)$data['forced'] !== ''))
|
||||
{
|
||||
$default = (string)$data['forced'] !== '' ? $data['forced'] : $data['default'];
|
||||
//echo "<p>".__METHOD__."($appname) $this->appname/$appname/$name=$default NOT yet set!</p>\n";
|
||||
$GLOBALS['egw']->preferences->default[$appname][$name] = $default;
|
||||
$need_update = true;
|
||||
}
|
||||
}
|
||||
if ($need_update)
|
||||
{
|
||||
$GLOBALS['egw']->preferences->save_repository(false,'default',true);
|
||||
}
|
||||
if($this->debug)
|
||||
{
|
||||
_debug_array($this->settings);
|
||||
}
|
||||
return True;
|
||||
}
|
||||
}
|
33
preferences/templates/default/app.css
Normal file
33
preferences/templates/default/app.css
Normal file
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* EGroupware - CSS Styles used by preferences app
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @package preferences
|
||||
* @link http://www.egroupware.org
|
||||
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
table.prefTable {
|
||||
width: 100%;
|
||||
}
|
||||
tr.prefRow {
|
||||
position: relative;
|
||||
}
|
||||
td.prefName, td.prefValue {
|
||||
width: 50%;
|
||||
}
|
||||
.prefHelp {
|
||||
position: absolute;
|
||||
display: none;
|
||||
width: 98%;
|
||||
background-color: lightyellow;
|
||||
border: 1px solid black;
|
||||
border-radius: 10px;
|
||||
padding: 5px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
tr.prefRow:hover .prefHelp {
|
||||
display: block;
|
||||
z-index: 10; /* FF: displays it under next prefName without */
|
||||
}
|
113
preferences/templates/default/settings.xet
Normal file
113
preferences/templates/default/settings.xet
Normal file
@ -0,0 +1,113 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- $Id$ -->
|
||||
<overlay>
|
||||
<template id="preferences.settings.tab1" template="" lang="" group="0" version="1.9.001">
|
||||
<grid width="100%" class="prefTable egwGridView_grid">
|
||||
<columns>
|
||||
<column width="50%"/>
|
||||
<column/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row class="prefRow">
|
||||
<box class="prefName">
|
||||
<description id="${row}[label]"/>
|
||||
<description id="${row}[help]" class="prefHelp"/>
|
||||
</box>
|
||||
<widget type="@${row}[type]" id="${row}[value]" size="@${row}[size]" class="prefValue"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</template>
|
||||
<template id="preferences.settings.tab2" template="" lang="" group="0" version="1.9.001">
|
||||
<grid width="100%" class="prefTable egwGridView_grid">
|
||||
<columns>
|
||||
<column width="50%"/>
|
||||
<column/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row class="prefRow">
|
||||
<box class="prefName">
|
||||
<description id="${row}[label]"/>
|
||||
<description id="${row}[help]" class="prefHelp"/>
|
||||
</box>
|
||||
<widget type="@${row}[type]" id="${row}[value]" size="@${row}[size]" class="prefValue"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</template>
|
||||
<template id="preferences.settings.tab3" template="" lang="" group="0" version="1.9.001">
|
||||
<grid width="100%" class="prefTable egwGridView_grid">
|
||||
<columns>
|
||||
<column width="50%"/>
|
||||
<column/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row class="prefRow">
|
||||
<box class="prefName">
|
||||
<description id="${row}[label]"/>
|
||||
<description id="${row}[help]" class="prefHelp"/>
|
||||
</box>
|
||||
<widget type="@${row}[type]" id="${row}[value]" size="@${row}[size]" class="prefValue"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</template>
|
||||
<template id="preferences.settings.tab4" template="" lang="" group="0" version="1.9.001">
|
||||
<grid width="100%" class="prefTable egwGridView_grid">
|
||||
<columns>
|
||||
<column width="50%"/>
|
||||
<column/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row class="prefRow">
|
||||
<box class="prefName">
|
||||
<description id="${row}[label]"/>
|
||||
<description id="${row}[help]" class="prefHelp"/>
|
||||
</box>
|
||||
<widget type="@${row}[type]" id="${row}[value]" size="@${row}[size]" class="prefValue"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</template>
|
||||
<template id="preferences.settings.tab5" template="" lang="" group="0" version="1.9.001">
|
||||
<grid width="100%" class="prefTable egwGridView_grid">
|
||||
<columns>
|
||||
<column width="50%"/>
|
||||
<column/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row class="prefRow">
|
||||
<box class="prefName">
|
||||
<description id="${row}[label]"/>
|
||||
<description id="${row}[help]" class="prefHelp"/>
|
||||
</box>
|
||||
<widget type="@${row}[type]" id="${row}[value]" size="@${row}[size]" class="prefValue"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</template>
|
||||
<template id="preferences.settings" template="" lang="" group="0" version="1.9.001">
|
||||
<description id="msg" class="redItalic"/>
|
||||
<tabbox id="tabs">
|
||||
<tabs>
|
||||
<tab id="tab1" label="Tab 1"/>
|
||||
<tab id="tab2" label="Tab 2"/>
|
||||
<tab id="tab3" label="Tab 3"/>
|
||||
<tab id="tab4" label="Tab 4"/>
|
||||
<!-- tab id="tab5" label="Tab 5"/ -->
|
||||
</tabs>
|
||||
<tabpanels>
|
||||
<template id="preferences.settings.tab1" content="tab1"/>
|
||||
<template id="preferences.settings.tab2" content="tab2"/>
|
||||
<template id="preferences.settings.tab3" content="tab3"/>
|
||||
<template id="preferences.settings.tab4" content="tab4"/>
|
||||
<!-- template id="preferences.settings.tab4" content="tab5"/ -->
|
||||
</tabpanels>
|
||||
</tabbox>
|
||||
<hbox>
|
||||
<button label="Save" id="button[save]"/>
|
||||
<button label="Apply" id="button[apply]"/>
|
||||
<button label="Cancel" id="button[cancel]"/>
|
||||
</hbox>
|
||||
</template>
|
||||
</overlay>
|
Loading…
Reference in New Issue
Block a user