2011-08-04 21:08:50 +02:00
|
|
|
/**
|
2013-04-13 21:00:13 +02:00
|
|
|
* EGroupware eTemplate2 - JS XML Code
|
2011-08-04 21:08:50 +02:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
* @copyright Stylite 2011
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-01-27 17:53:11 +01:00
|
|
|
* Loads the given URL asynchronously from the server
|
|
|
|
*
|
|
|
|
* We make the Ajax call through main-windows jQuery object, to ensure cached copy
|
|
|
|
* in main-windows etemplate2 prototype works in IE too!
|
|
|
|
*
|
|
|
|
* @param {string} _url
|
|
|
|
* @param {function} _callback function(_xml)
|
|
|
|
* @param {object} _context for _callback
|
2018-08-23 23:44:32 +02:00
|
|
|
* @param {function} _fail_callback function(_xml)
|
2011-08-04 21:08:50 +02:00
|
|
|
*/
|
2018-08-23 23:44:32 +02:00
|
|
|
function et2_loadXMLFromURL(_url, _callback, _context, _fail_callback)
|
2011-08-04 21:08:50 +02:00
|
|
|
{
|
|
|
|
if (typeof _context == "undefined")
|
|
|
|
{
|
|
|
|
_context = null;
|
|
|
|
}
|
|
|
|
|
2015-01-27 17:53:11 +01:00
|
|
|
// use window object from main window with same algorithm as for the template cache
|
|
|
|
var win;
|
|
|
|
try {
|
|
|
|
if (opener && opener.etemplate2)
|
2011-08-04 21:08:50 +02:00
|
|
|
{
|
2015-01-27 17:53:11 +01:00
|
|
|
win = opener;
|
2011-08-04 21:08:50 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-27 17:53:11 +01:00
|
|
|
catch (e) {
|
|
|
|
// catch security exception if opener is from a different domain
|
|
|
|
}
|
|
|
|
if (typeof win == "undefined")
|
2011-08-04 21:08:50 +02:00
|
|
|
{
|
2015-01-27 17:53:11 +01:00
|
|
|
win = top;
|
2011-08-04 21:08:50 +02:00
|
|
|
}
|
2015-01-27 17:53:11 +01:00
|
|
|
win.jQuery.ajax({
|
2019-11-14 15:19:58 +01:00
|
|
|
// we add the full url (protocol and domain) as sometimes just the path
|
|
|
|
// gives a CSP error interpreting it as file:///path
|
|
|
|
// (if there are a enough 404 errors in html content ...)
|
|
|
|
url: (_url[0]=='/' ? location.protocol+'//'+location.host : '')+_url,
|
2015-01-27 17:53:11 +01:00
|
|
|
context: _context,
|
|
|
|
type: 'GET',
|
|
|
|
dataType: 'xml',
|
|
|
|
success: function(_data, _status, _xmlhttp){
|
|
|
|
_callback.call(_context, _data.documentElement);
|
|
|
|
},
|
|
|
|
error: function(_xmlhttp, _err) {
|
2015-02-06 18:23:58 +01:00
|
|
|
egw().debug('error', 'Loading eTemplate from '+_url+' failed! '+_xmlhttp.status+' '+_xmlhttp.statusText);
|
2018-08-23 23:44:32 +02:00
|
|
|
if(typeof _fail_callback !== 'undefined')
|
|
|
|
{
|
2019-11-14 15:19:58 +01:00
|
|
|
_fail_callback.call(_context, _err);
|
2018-08-23 23:44:32 +02:00
|
|
|
}
|
2015-01-27 17:53:11 +01:00
|
|
|
}
|
|
|
|
});
|
2011-08-04 21:08:50 +02:00
|
|
|
}
|
|
|
|
|
2011-08-07 15:43:46 +02:00
|
|
|
function et2_directChildrenByTagName(_node, _tagName)
|
|
|
|
{
|
|
|
|
// Normalize the tag name
|
|
|
|
_tagName = _tagName.toLowerCase();
|
|
|
|
|
|
|
|
var result = [];
|
2015-08-20 16:57:18 +02:00
|
|
|
for (var i = 0; i < _node.childNodes.length; i++)
|
2011-08-07 15:43:46 +02:00
|
|
|
{
|
2015-08-20 16:57:18 +02:00
|
|
|
if (_tagName == _node.childNodes[i].nodeName.toLowerCase())
|
2011-08-07 15:43:46 +02:00
|
|
|
{
|
2015-08-20 16:57:18 +02:00
|
|
|
result.push(_node.childNodes[i]);
|
2011-08-07 15:43:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-08-06 16:36:44 +02:00
|
|
|
function et2_filteredNodeIterator(_node, _callback, _context)
|
|
|
|
{
|
2015-08-20 16:57:18 +02:00
|
|
|
for (var i = 0; i < _node.childNodes.length; i++)
|
2011-08-06 16:36:44 +02:00
|
|
|
{
|
2015-08-20 16:57:18 +02:00
|
|
|
var node = _node.childNodes[i];
|
|
|
|
var nodeName = node.nodeName.toLowerCase();
|
2011-08-06 16:36:44 +02:00
|
|
|
if (nodeName.charAt(0) != "#")
|
|
|
|
{
|
|
|
|
_callback.call(_context, node, nodeName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-10 16:36:31 +02:00
|
|
|
function et2_readAttrWithDefault(_node, _name, _default)
|
|
|
|
{
|
|
|
|
var val = _node.getAttribute(_name);
|
2015-08-20 16:57:18 +02:00
|
|
|
|
|
|
|
return (val === null) ? _default : val;
|
2011-08-10 16:36:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|