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
|
|
|
*
|
2014-02-07 15:04:12 +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
|
2015-02-02 20:54:53 +01:00
|
|
|
* @param {boolean} _need_clone _data need to be cloned, as it is from different window context
|
|
|
|
* and therefore will be inaccessible in IE, after that window is closed
|
2012-03-01 17:24:29 +01:00
|
|
|
*/
|
2015-02-02 20:54:53 +01:00
|
|
|
set_preferences: function(_data, _app, _need_clone)
|
2012-03-01 17:24:29 +01:00
|
|
|
{
|
|
|
|
if (typeof _app == 'undefined')
|
|
|
|
{
|
2015-02-02 20:54:53 +01:00
|
|
|
prefs = _need_clone ? jQuery.extend(true, {}, _data) : _data;
|
2012-03-01 17:24:29 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-02 20:54:53 +01:00
|
|
|
prefs[_app] = jQuery.extend(true, {}, _data); // we always clone here, as call can come from this.preferences!
|
2012-03-01 17:24:29 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
*
|
2014-02-07 15:04:12 +01:00
|
|
|
* @param {string} _name name of the preference, eg. 'dateformat', or '*' to get all the application's preferences
|
|
|
|
* @param {string} _app default 'common'
|
2012-03-01 17:24:29 +01:00
|
|
|
* @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] = {};
|
|
|
|
}
|
2015-01-15 21:11:23 +01:00
|
|
|
if (_name == "*") return typeof prefs[_app] ==='object' ? jQuery.extend({},prefs[_app]) : prefs[_app];
|
2013-02-27 19:08:03 +01:00
|
|
|
|
2015-01-15 21:11:23 +01:00
|
|
|
return typeof prefs[_app][_name] === 'object' && prefs[_app][_name] !== null ?
|
|
|
|
jQuery.extend({},prefs[_app][_name]) : prefs[_app][_name];
|
2012-03-01 17:24:29 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
*
|
2014-02-07 15:04:12 +01:00
|
|
|
* @param {string} _app application name or "common"
|
|
|
|
* @param {string} _name name of the pref
|
2015-01-08 14:13:02 +01:00
|
|
|
* @param {string} _val value of the pref, null, undefined or "" to unset it
|
2014-07-08 05:34:05 +02:00
|
|
|
* @param {function} _callback Function passed along to the queue, called after preference is set server-side
|
2012-03-01 17:24:29 +01:00
|
|
|
*/
|
2014-07-08 05:34:05 +02:00
|
|
|
set_preference: function(_app, _name, _val, _callback)
|
2012-03-01 17:24:29 +01:00
|
|
|
{
|
2015-01-08 14:13:02 +01:00
|
|
|
// if there is no change, no need to submit it to server
|
|
|
|
if (typeof prefs[_app] != 'undefined' && prefs[_app][_name] === _val) return;
|
|
|
|
|
2014-07-08 05:34:05 +02:00
|
|
|
this.jsonq('home.egw_framework.ajax_set_preference.template',[_app, _name, _val], _callback);
|
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!)
|
2015-01-08 14:13:02 +01:00
|
|
|
if (typeof prefs[_app] != 'undefined')
|
|
|
|
{
|
|
|
|
if (_val === undefined || _val === "" || _val === null)
|
|
|
|
{
|
|
|
|
delete prefs[_app][_name];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prefs[_app][_name] = _val;
|
|
|
|
}
|
|
|
|
}
|
2014-02-07 15:04:12 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call context / open app specific preferences function
|
|
|
|
*
|
|
|
|
* @param {string} name type 'acl', 'prefs', or 'cats'
|
|
|
|
* @param {(array|object)} apps array with apps allowing to call that type, or object/hash with app and boolean or hash with url-params
|
|
|
|
*/
|
|
|
|
show_preferences: function (name, apps)
|
|
|
|
{
|
|
|
|
var current_app = this.app_name();
|
2014-04-01 17:49:08 +02:00
|
|
|
var query = {current_app: current_app};
|
2014-02-07 15:04:12 +01:00
|
|
|
// give warning, if app does not support given type, but all apps link to common prefs, if they dont support prefs themselfs
|
|
|
|
if ($j.isArray(apps) && $j.inArray(current_app, apps) == -1 && name != 'prefs' ||
|
|
|
|
!$j.isArray(apps) && (typeof apps[current_app] == 'undefined' || !apps[current_app]))
|
|
|
|
{
|
|
|
|
egw_message(egw.lang('Not supported by current application!'), 'warning');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var url = '/index.php';
|
|
|
|
switch(name)
|
|
|
|
{
|
|
|
|
case 'prefs':
|
|
|
|
query.menuaction ='preferences.preferences_settings.index';
|
|
|
|
if ($j.inArray(current_app, apps) != -1) query.appname=current_app;
|
2014-04-01 17:49:08 +02:00
|
|
|
egw.open_link(egw.link(url, query), '_blank', '900x450');
|
2014-02-07 15:04:12 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'acl':
|
|
|
|
query.menuaction='preferences.preferences_acl.index';
|
|
|
|
query.acl_app=current_app;
|
2014-04-01 17:49:08 +02:00
|
|
|
egw.open_link(egw.link(url, query), '_blank', '900x450');
|
2014-02-07 15:04:12 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'cats':
|
|
|
|
if (typeof apps[current_app] == 'object')
|
|
|
|
{
|
|
|
|
for(var key in apps[current_app])
|
|
|
|
{
|
|
|
|
query[key] = encodeURIComponent(apps[current_app][key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
query.menuaction='preferences.preferences_categories_ui.index';
|
|
|
|
query.cats_app=current_app;
|
|
|
|
}
|
2014-04-01 17:49:08 +02:00
|
|
|
egw.link_handler(egw.link(url, query), current_app);
|
2014-02-07 15:04:12 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-01 17:24:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|