2011-08-23 16:29:56 +02: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";
|
|
|
|
|
2012-03-01 17:24:29 +01:00
|
|
|
/*egw:uses
|
|
|
|
egw_core;
|
2012-03-05 16:02:00 +01:00
|
|
|
egw_debug;
|
2012-03-01 17:24:29 +01:00
|
|
|
egw_preferences;
|
|
|
|
egw_lang;
|
|
|
|
egw_links;
|
2012-03-28 14:37:03 +02:00
|
|
|
egw_open;
|
2012-03-01 17:24:29 +01:00
|
|
|
egw_user;
|
|
|
|
egw_config;
|
|
|
|
egw_images;
|
|
|
|
egw_jsonq;
|
2012-03-05 14:07:38 +01:00
|
|
|
egw_files;
|
2012-03-05 16:02:00 +01:00
|
|
|
egw_json;
|
2012-03-06 14:22:01 +01:00
|
|
|
egw_tooltip;
|
2012-03-07 15:04:25 +01:00
|
|
|
egw_css;
|
2012-03-08 12:29:46 +01:00
|
|
|
egw_calendar;
|
2012-03-09 16:32:29 +01:00
|
|
|
egw_ready;
|
2012-03-20 13:05:31 +01:00
|
|
|
egw_data;
|
2013-04-09 10:45:59 +02:00
|
|
|
egw_inheritance;
|
2012-03-12 13:05:14 +01:00
|
|
|
// egw_jquery;
|
2013-04-09 10:45:59 +02:00
|
|
|
app_base;
|
2012-03-01 17:24:29 +01:00
|
|
|
*/
|
2011-08-23 16:29:56 +02:00
|
|
|
|
2013-07-19 10:45:26 +02:00
|
|
|
(function(){
|
|
|
|
var debug = false;
|
|
|
|
var egw_script = document.getElementById('egw_script_id');
|
|
|
|
window.egw_webserverUrl = egw_script.getAttribute('data-url');
|
|
|
|
window.egw_appName = egw_script.getAttribute('data-app');
|
|
|
|
|
|
|
|
// check if egw object was injected by window open
|
|
|
|
if (typeof window.egw == 'undefined')
|
|
|
|
{
|
|
|
|
// try finding it in top or opener's top
|
|
|
|
if (window.opener && typeof window.opener.top.egw != 'undefined')
|
|
|
|
{
|
|
|
|
window.egw = window.opener.top.egw;
|
|
|
|
if (typeof window.opener.top.framework != 'undefined') window.framework = window.opener.top.framework;
|
|
|
|
if (debug) console.log('found egw object in opener');
|
|
|
|
}
|
|
|
|
else if (window.top && typeof window.top.egw != 'undefined')
|
|
|
|
{
|
|
|
|
window.egw = window.top.egw;
|
|
|
|
if (typeof window.top.framework != 'undefined') window.framework = window.top.framework;
|
|
|
|
if (debug) console.log('found egw object in top');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window.egw = {
|
|
|
|
prefsOnly: true,
|
|
|
|
webserverUrl: egw_webserverUrl
|
|
|
|
};
|
|
|
|
if (debug) console.log('creating new egw object');
|
|
|
|
}
|
|
|
|
}
|
2013-07-19 17:22:37 +02:00
|
|
|
else if (debug) console.log('found injected egw object');
|
2013-07-19 10:45:26 +02:00
|
|
|
|
|
|
|
// check for a framework object
|
|
|
|
if (typeof window.framework == 'undefined')
|
|
|
|
{
|
|
|
|
// try finding it in top or opener's top
|
|
|
|
if (window.opener && typeof window.opener.top.framework != 'undefined')
|
|
|
|
{
|
|
|
|
window.framework = window.opener.top.framework;
|
|
|
|
if (debug) console.log('found framework object in opener top');
|
|
|
|
}
|
|
|
|
else if (window.top && typeof window.top.framework != 'undefined')
|
|
|
|
{
|
|
|
|
window.framework = window.top.framework;
|
|
|
|
if (debug) console.log('found framework object in top');
|
|
|
|
}
|
|
|
|
// if framework not found, but requested to check for it, redirect to cd=yes to create it
|
|
|
|
else if (egw_script.getAttribute('data-check-framework'))
|
|
|
|
{
|
|
|
|
window.location.search += window.location.search ? "&cd=yes" : "?cd=yes";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.egw_LAB = $LAB.setOptions({AlwaysPreserveOrder:true,BasePath:window.egw_webserverUrl+'/'});
|
|
|
|
var include = JSON.parse(egw_script.getAttribute('data-include'));
|
|
|
|
|
|
|
|
// remove this script from include, until server-side no longer requires it
|
|
|
|
for(var i=0; i < include.length; ++i)
|
|
|
|
{
|
|
|
|
if (include[i].match(/^phpgwapi\/js\/jsapi\/egw\.js/))
|
|
|
|
{
|
|
|
|
include.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
window.egw_LAB.script(include).wait(function(){
|
2013-07-20 15:42:23 +02:00
|
|
|
var data = egw_script.getAttribute('data-etemplate');
|
2013-07-19 10:45:26 +02:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
data = JSON.parse(data) || {};
|
2013-07-20 15:42:23 +02:00
|
|
|
// Initialize application js
|
|
|
|
var callback = null;
|
|
|
|
// Only initialize once
|
|
|
|
if(typeof app[window.egw_appName] == "function")
|
2013-07-19 10:45:26 +02:00
|
|
|
{
|
2013-07-20 15:42:23 +02:00
|
|
|
(function() { new app[window.egw_appName]();}).call();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
egw.debug("warn", "Did not load '%s' JS object",window.egw_appName);
|
|
|
|
}
|
|
|
|
if(typeof app[window.egw_appName] == "object")
|
|
|
|
{
|
2013-08-06 20:24:30 +02:00
|
|
|
callback = function(et2) {app[window.egw_appName].et2_ready(et2);};
|
2013-07-20 15:42:23 +02:00
|
|
|
}
|
|
|
|
var node = document.getElementById(data.DOMNodeID);
|
|
|
|
if(!node)
|
|
|
|
{
|
|
|
|
egw.debug("error", "Could not find target node %s", data.DOMNodeID);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-06 20:24:30 +02:00
|
|
|
var et2 = new etemplate2(node, "etemplate_new::ajax_process_content");
|
2013-07-20 15:42:23 +02:00
|
|
|
et2.load(data.name,data.url,data.data,callback);
|
2013-07-19 10:45:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (data = egw_script.getAttribute('data-user'))
|
|
|
|
{
|
|
|
|
window.egw.set_user(JSON.parse(data));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})();
|