2012-03-01 17:24:29 +01:00
|
|
|
/**
|
|
|
|
* EGroupware clientside API object
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Andreas Stöckel (as AT stylite.de)
|
|
|
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*egw:uses
|
|
|
|
egw_core;
|
|
|
|
*/
|
|
|
|
|
2012-03-05 14:07:38 +01:00
|
|
|
egw.extend('preferences', egw.MODULE_GLOBAL, function() {
|
2012-03-01 17:24:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Object holding the prefences as 2-dim. associative array, use
|
|
|
|
* egw.preference(name[,app]) to access it.
|
|
|
|
*
|
|
|
|
* @access: private, use egw.preferences() or egw.set_perferences()
|
|
|
|
*/
|
2014-01-15 18:39:07 +01:00
|
|
|
var prefs = {};
|
2012-03-01 17:24:29 +01:00
|
|
|
|
|
|
|
// Return the actual extension
|
|
|
|
return {
|
|
|
|
/**
|
|
|
|
* Setting prefs for an app or 'common'
|
2014-01-15 18:39:07 +01:00
|
|
|
*
|
2012-03-01 17:24:29 +01:00
|
|
|
* @param object _data object with name: value pairs to set
|
|
|
|
* @param string _app application name, 'common' or undefined to prefes of all apps at once
|
|
|
|
*/
|
|
|
|
set_preferences: function(_data, _app)
|
|
|
|
{
|
|
|
|
if (typeof _app == 'undefined')
|
|
|
|
{
|
|
|
|
prefs = _data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prefs[_app] = _data;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query an EGroupware user preference
|
2014-01-15 18:39:07 +01:00
|
|
|
*
|
2012-03-01 17:24:29 +01:00
|
|
|
* If a prefernce is not already loaded (only done for "common" by default), it is synchroniosly queryed from the server!
|
2014-01-15 18:39:07 +01:00
|
|
|
*
|
2013-02-27 19:08:03 +01:00
|
|
|
* @param string _name name of the preference, eg. 'dateformat', or '*' to get all the application's preferences
|
2012-03-01 17:24:29 +01:00
|
|
|
* @param string _app='common'
|
|
|
|
* @return string preference value
|
|
|
|
* @todo add a callback to query it asynchron
|
|
|
|
*/
|
2014-01-15 18:39:07 +01:00
|
|
|
preference: function(_name, _app)
|
2012-03-01 17:24:29 +01:00
|
|
|
{
|
|
|
|
if (typeof _app == 'undefined') _app = 'common';
|
|
|
|
|
|
|
|
if (typeof prefs[_app] == 'undefined')
|
|
|
|
{
|
2014-01-18 18:43:15 +01:00
|
|
|
var request = this.json('home.egw_framework.ajax_get_preference.template', [_app]);
|
|
|
|
request.sendRequest(false, 'GET'); // use synchronous (cachable) GET request
|
2012-03-01 17:24:29 +01:00
|
|
|
if (typeof prefs[_app] == 'undefined') prefs[_app] = {};
|
|
|
|
}
|
2013-02-27 19:08:03 +01:00
|
|
|
if(_name == "*") return prefs[_app];
|
|
|
|
|
2012-03-01 17:24:29 +01:00
|
|
|
return prefs[_app][_name];
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a preference and sends it to the server
|
2014-01-15 18:39:07 +01:00
|
|
|
*
|
2012-03-01 17:24:29 +01:00
|
|
|
* Server will silently ignore setting preferences, if user has no right to do so!
|
2014-01-15 18:39:07 +01:00
|
|
|
*
|
2012-03-01 17:24:29 +01:00
|
|
|
* @param string _app application name or "common"
|
|
|
|
* @param string _name name of the pref
|
|
|
|
* @param string _val value of the pref
|
|
|
|
*/
|
|
|
|
set_preference: function(_app, _name, _val)
|
|
|
|
{
|
2013-06-12 00:48:27 +02:00
|
|
|
this.jsonq('home.egw_framework.ajax_set_preference.template',[_app, _name, _val]);
|
2012-03-01 17:24:29 +01:00
|
|
|
|
|
|
|
// update own preference cache, if _app prefs are loaded (dont update otherwise, as it would block loading of other _app prefs!)
|
|
|
|
if (typeof prefs[_app] != 'undefined') prefs[_app][_name] = _val;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|
|
|
|
|