mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-25 16:18:57 +01:00
Change admin column selection to allow setting / clearing / forcing column selection
This commit is contained in:
parent
08850841b6
commit
5e84ddd935
@ -118,10 +118,11 @@ class etemplate_widget_nextmatch extends etemplate_widget
|
||||
|
||||
$send_value = $value;
|
||||
|
||||
list($app) = explode('.',$value['get_rows']);
|
||||
|
||||
// Check for a favorite in URL
|
||||
if($_GET['favorite'] && $value['favorites'])
|
||||
{
|
||||
list($app) = explode('.',$value['get_rows']);
|
||||
$safe_name = preg_replace('/[^A-Za-z0-9-_]/','_',strip_tags($_GET['favorite']));
|
||||
$pref_name = "favorite_" .$safe_name;
|
||||
|
||||
@ -209,6 +210,14 @@ class etemplate_widget_nextmatch extends etemplate_widget
|
||||
unset($value['rows']['sel_options']);
|
||||
}
|
||||
|
||||
// If column selection preference is forced, set a flag to turn off UI
|
||||
$pref_name = 'nextmatch-' . (isset($value['columnselection_pref']) ? $value['columnselection_pref'] : $this->attrs['template']);
|
||||
$value['no_columnselection'] = $value['no_columnselection'] || (
|
||||
$GLOBALS['egw']->preferences->forced[$app][$pref_name] &&
|
||||
// Need to check admin too, or it will be impossible to turn off
|
||||
!$GLOBALS['egw_info']['user']['apps']['admin']
|
||||
);
|
||||
|
||||
// todo: no need to store rows in request, it's enought to send them to client
|
||||
|
||||
//error_log(__METHOD__."() $this: total=$value[total]");
|
||||
@ -809,26 +818,43 @@ class etemplate_widget_nextmatch extends etemplate_widget
|
||||
}
|
||||
|
||||
|
||||
// Save current column settings as default (admins only)
|
||||
if($value['as_default'])
|
||||
// Save current column settings as default, clear, or force (admins only)
|
||||
if($GLOBALS['egw_info']['user']['apps']['admin'] && $app)
|
||||
{
|
||||
unset($value['as_default']);
|
||||
if($GLOBALS['egw_info']['user']['apps']['admin'] && $app)
|
||||
$pref_name = 'nextmatch-' . (isset($value['columnselection_pref']) ? $value['columnselection_pref'] : $this->attrs['template']);
|
||||
$refresh_pref_name = $pref_name.'-autorefresh';
|
||||
$pref_level = $value['nm_col_preference'] == 'force' ? 'forced' : 'default';
|
||||
|
||||
// Clear forced pref before setting default
|
||||
if($pref_level != 'forced')
|
||||
{
|
||||
$pref_name = 'nextmatch-' . (isset($value['columnselection_pref']) ? $value['columnselection_pref'] : $this->attrs['template']);
|
||||
// Columns already saved to user's preferences, use from there
|
||||
$prefs = $GLOBALS['egw']->preferences->read();
|
||||
$cols = $prefs[$app][$pref_name];
|
||||
$GLOBALS['egw']->preferences->add($app,$pref_name,is_array($cols) ? implode(',',$cols) : $cols,'default');
|
||||
$GLOBALS['egw']->preferences->delete($app,$pref_name,'forced');
|
||||
$GLOBALS['egw']->preferences->delete($app,$refresh_pref_name,'forced');
|
||||
$GLOBALS['egw']->preferences->save_repository(false,'forced');
|
||||
}
|
||||
|
||||
// Autorefresh
|
||||
$refresh = $prefs[$app][$pref_name."-autorefresh"];
|
||||
$GLOBALS['egw']->preferences->add($app,$pref_name."-autorefresh",(int)$refresh,'default');
|
||||
// Set columns + refresh as default for all users
|
||||
|
||||
$GLOBALS['egw']->preferences->save_repository(false,'default');
|
||||
$prefs = $GLOBALS['egw']->preferences->read();
|
||||
// Columns already saved to current user's preferences, use from there
|
||||
$prefs = $GLOBALS['egw']->preferences->read();
|
||||
$cols = $prefs[$app][$pref_name];
|
||||
$GLOBALS['egw']->preferences->add($app,$pref_name,is_array($cols) ? implode(',',$cols) : $cols, $pref_level);
|
||||
|
||||
// Autorefresh
|
||||
$refresh = $prefs[$app][$refresh_pref_name];
|
||||
$GLOBALS['egw']->preferences->add($app,$refresh_pref_name,(int)$refresh,$pref_level);
|
||||
|
||||
$GLOBALS['egw']->preferences->save_repository(false,$pref_level);
|
||||
$prefs = $GLOBALS['egw']->preferences->read();
|
||||
|
||||
if($value['nm_col_preference'] == 'reset')
|
||||
{
|
||||
// Clear column + refresh preference so users go back to default
|
||||
$GLOBALS['egw']->preferences->delete_preference($app,$pref_name);
|
||||
}
|
||||
}
|
||||
unset($value['nm_col_preference']);
|
||||
|
||||
$validated[$form_name] = $value;
|
||||
}
|
||||
|
||||
|
@ -731,10 +731,19 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput],
|
||||
self.iterateOver(function(widget) {widget.resize();}, self, et2_IResizeable);
|
||||
};
|
||||
|
||||
// Register handler for column selection popup
|
||||
this.dataview.selectColumnsClick = function(event) {
|
||||
self._selectColumnsClick(event);
|
||||
};
|
||||
// Register handler for column selection popup, or disable
|
||||
if(this.options.settings.no_columnselection)
|
||||
{
|
||||
this.dataview.selectColumnsClick = function() {return false;};
|
||||
$j('span.selectcols',this.dataview.headTr).hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
$j('span.selectcols',this.dataview.headTr).show();
|
||||
this.dataview.selectColumnsClick = function(event) {
|
||||
self._selectColumnsClick(event);
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
_parseDataRow: function(_row, _rowData, _colData) {
|
||||
@ -920,9 +929,13 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput],
|
||||
});
|
||||
autoRefresh.set_value(this._get_autorefresh());
|
||||
|
||||
var defaultCheck = et2_createWidget("checkbox", {}, this);
|
||||
defaultCheck.set_id('as_default');
|
||||
defaultCheck.set_label(this.egw().lang("As default"));
|
||||
var defaultCheck = et2_createWidget("select", {"empty_label":"Preference"}, this);
|
||||
defaultCheck.set_id('nm_col_preference');
|
||||
defaultCheck.set_select_options({
|
||||
'default': {label: 'Default',title:'Set these columns as the default'},
|
||||
'reset': {label: 'Reset', title:"Reset all user's column preferences"},
|
||||
'force': {label: 'Force', title:'Force column preference so users cannot change it'}
|
||||
});
|
||||
|
||||
var okButton = et2_createWidget("buttononly", {}, this);
|
||||
okButton.set_label(this.egw().lang("ok"));
|
||||
@ -971,6 +984,8 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput],
|
||||
}
|
||||
}
|
||||
columnMgr.setColumnVisibilitySet(visibility);
|
||||
|
||||
// Hide popup
|
||||
self.selectPopup.toggle();
|
||||
|
||||
self.dataview.updateColumns();
|
||||
@ -979,7 +994,7 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput],
|
||||
self._set_autorefresh(autoRefresh.get_value());
|
||||
|
||||
// Set default?
|
||||
if(defaultCheck.get_value() == "true")
|
||||
if(defaultCheck.get_value())
|
||||
{
|
||||
self.getInstanceManager().submit();
|
||||
}
|
||||
|
@ -188,10 +188,6 @@ class preferences
|
||||
return $prefs;
|
||||
}
|
||||
|
||||
/**************************************************************************\
|
||||
* These are the standard $this->account_id specific functions *
|
||||
\**************************************************************************/
|
||||
|
||||
/**
|
||||
* parses a notify and replaces the substitutes
|
||||
*
|
||||
@ -658,6 +654,55 @@ class preferences
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Completely delete the specified preference name from all users
|
||||
*
|
||||
* @param string $app Application name
|
||||
* @param string $name Preference name
|
||||
* @param string $type='user' of preference to set: forced, default, user
|
||||
*/
|
||||
public function delete_preference($app, $name, $type='user')
|
||||
{
|
||||
$GLOBALS['egw']->db->transaction_begin();
|
||||
$where = array(
|
||||
'preference_app' => $app,
|
||||
'preference_value ' . $this->db->capabilities[egw_db::CAPABILITY_CASE_INSENSITIV_LIKE].' ' .
|
||||
$this->db->quote("%$name%")
|
||||
);
|
||||
switch($type)
|
||||
{
|
||||
case 'forced':
|
||||
$where['preference_owner'] = self::FORCED_ID;
|
||||
break;
|
||||
case 'default':
|
||||
$where['preference_owner'] = self::DEFAULT_ID;
|
||||
break;
|
||||
case 'user':
|
||||
$where[] = 'preference_owner > 0';
|
||||
break;
|
||||
}
|
||||
foreach($this->db->select($this->table,'*',$where,__LINE__,__FILE__) as $row)
|
||||
{
|
||||
$value = unserialize($row['preference_value']);
|
||||
if($value[$name])
|
||||
{
|
||||
unset($value[$name]);
|
||||
$this->quote($value); // this quote-ing is for serialize, not for the db
|
||||
$GLOBALS['egw']->db->insert($this->table,array(
|
||||
'preference_value' => serialize($value),
|
||||
),array(
|
||||
'preference_owner' => $row['preference_owner'],
|
||||
'preference_app' => $row['preference_app'],
|
||||
),__LINE__,__FILE__);
|
||||
}
|
||||
}
|
||||
$GLOBALS['egw']->db->transaction_commit();
|
||||
}
|
||||
|
||||
/**************************************************************************\
|
||||
* These are the standard $this->account_id specific functions *
|
||||
\**************************************************************************/
|
||||
|
||||
/**
|
||||
* add complex array data preference to $app_name a particular app
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user