2014-11-11 19:00:29 +01:00
|
|
|
/**
|
|
|
|
* eGroupware Framework browser object
|
|
|
|
* @package framework
|
|
|
|
* @author Hadi Nategh <hn@stylite.de>
|
|
|
|
* @copyright Stylite AG 2014
|
|
|
|
* @description Framework browser object, is implementation of browser class in order to display application content
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*egw:uses
|
2016-06-06 17:38:20 +02:00
|
|
|
vendor.bower-asset.jquery.dist.jquery;
|
2016-03-02 19:04:47 +01:00
|
|
|
egw_action.egw_action_common;
|
2014-11-11 19:00:29 +01:00
|
|
|
egw_inheritance.js;
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constants definition
|
|
|
|
*/
|
|
|
|
EGW_BROWSER_TYPE_NONE = 0;
|
|
|
|
EGW_BROWSER_TYPE_IFRAME = 1;
|
|
|
|
EGW_BROWSER_TYPE_DIV = 2;
|
2015-03-18 10:56:11 +01:00
|
|
|
|
2016-02-29 16:50:24 +01:00
|
|
|
var fw_browser = (function(){ "use strict"; return Class.extend(
|
|
|
|
{
|
2014-11-11 19:00:29 +01:00
|
|
|
/**
|
|
|
|
* @param {string} _app
|
|
|
|
* @param {function} _heightCallback
|
|
|
|
* Framework browser class constructor
|
|
|
|
*/
|
|
|
|
init: function (_app, _heightCallback){
|
|
|
|
//Create a div which contains both, the legacy iframe and the contentDiv
|
|
|
|
this.baseDiv = document.createElement('div');
|
|
|
|
this.type = EGW_BROWSER_TYPE_NONE;
|
|
|
|
this.iframe = null;
|
|
|
|
this.contentDiv = null;
|
|
|
|
this.heightCallback = _heightCallback;
|
|
|
|
this.app = _app;
|
|
|
|
this.currentLocation = '';
|
2015-03-10 21:12:30 +01:00
|
|
|
this.ajaxLoaderDiv = null;
|
|
|
|
this.loadingDeferred = null;
|
2014-11-11 19:00:29 +01:00
|
|
|
},
|
2015-03-18 10:56:11 +01:00
|
|
|
|
2014-11-11 19:00:29 +01:00
|
|
|
/**
|
|
|
|
* Triggers resize event on window
|
|
|
|
*/
|
|
|
|
callResizeHandler: function()
|
|
|
|
{
|
|
|
|
var wnd = window;
|
|
|
|
if (this.iframe)
|
|
|
|
{
|
|
|
|
wnd = this.iframe.contentWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call the resize handler (we have to use the jquery object of the iframe!)
|
2016-06-02 16:51:15 +02:00
|
|
|
if (wnd && typeof wnd.jQuery != "undefined")
|
2014-11-11 19:00:29 +01:00
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
wnd.jQuery(wnd).trigger("resize");
|
2014-11-11 19:00:29 +01:00
|
|
|
}
|
|
|
|
},
|
2015-03-18 10:56:11 +01:00
|
|
|
|
2014-11-11 19:00:29 +01:00
|
|
|
/**
|
|
|
|
* Resizes both, the contentDiv and the iframe to the size returned from the heightCallback
|
|
|
|
*/
|
|
|
|
resize: function()
|
|
|
|
{
|
|
|
|
var height = this.heightCallback.call(this.iframe) + 'px';
|
|
|
|
|
|
|
|
//Set the height of the content div or the iframe
|
|
|
|
if (this.contentDiv)
|
|
|
|
{
|
|
|
|
this.contentDiv.style.height = height;
|
|
|
|
}
|
|
|
|
if (this.iframe)
|
|
|
|
{
|
|
|
|
this.iframe.style.height = height;
|
|
|
|
}
|
|
|
|
},
|
2015-03-18 10:56:11 +01:00
|
|
|
|
2014-11-11 19:00:29 +01:00
|
|
|
/**
|
|
|
|
* Sets browser type either DIV or IFRAME
|
2015-03-18 10:56:11 +01:00
|
|
|
*
|
2014-11-11 19:00:29 +01:00
|
|
|
* @param {int} _type
|
|
|
|
*/
|
|
|
|
setBrowserType: function(_type)
|
|
|
|
{
|
|
|
|
//Only do anything if the browser type has changed
|
|
|
|
if (_type != this.type)
|
|
|
|
{
|
|
|
|
//Destroy the iframe and/or the contentDiv
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this.baseDiv).empty();
|
2014-11-11 19:00:29 +01:00
|
|
|
this.iframe = null;
|
|
|
|
this.contentDiv = null;
|
2015-03-10 21:12:30 +01:00
|
|
|
if(this.loadingDeferred && this.type)
|
|
|
|
{
|
|
|
|
this.loadingDeferred.reject();
|
|
|
|
}
|
2014-11-11 19:00:29 +01:00
|
|
|
|
|
|
|
switch (_type)
|
|
|
|
{
|
|
|
|
//Create the div for displaying the content
|
|
|
|
case EGW_BROWSER_TYPE_DIV:
|
|
|
|
this.contentDiv = document.createElement('div');
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this.contentDiv).addClass('egw_fw_content_browser_div');
|
|
|
|
jQuery(this.baseDiv).append(this.contentDiv);
|
2014-11-11 19:00:29 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EGW_BROWSER_TYPE_IFRAME:
|
|
|
|
//Create the iframe
|
|
|
|
this.iframe = document.createElement('iframe');
|
|
|
|
this.iframe.style.width = "100%";
|
|
|
|
this.iframe.style.borderWidth = 0;
|
|
|
|
this.iframe.frameBorder = 0;
|
|
|
|
this.iframe.name = 'egw_app_iframe_' + this.app.appName;
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this.iframe).addClass('egw_fw_content_browser_iframe');
|
|
|
|
jQuery(this.baseDiv).append(this.iframe);
|
2014-11-11 19:00:29 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.resize();
|
|
|
|
this.type = _type;
|
|
|
|
}
|
|
|
|
},
|
2015-03-18 10:56:11 +01:00
|
|
|
|
2014-11-11 19:00:29 +01:00
|
|
|
/**
|
|
|
|
* Sets url to browse and load the content in proper content browser
|
|
|
|
* @param {string} _url
|
2015-03-10 21:12:30 +01:00
|
|
|
* @return {Deferred} Returns a Deferred promise object
|
2014-11-11 19:00:29 +01:00
|
|
|
*/
|
|
|
|
browse: function(_url)
|
|
|
|
{
|
|
|
|
// check if app has its own linkHandler and it accepts the link (returns true), or returns different url instead
|
2016-03-17 19:12:36 +01:00
|
|
|
if (typeof app == 'object' && typeof app[this.app.appName] == 'object' &&
|
|
|
|
typeof app[this.app.appName].linkHandler == 'function')
|
2014-11-11 19:00:29 +01:00
|
|
|
{
|
2016-03-17 19:12:36 +01:00
|
|
|
var ret = app[this.app.appName].linkHandler.call(app[this.app.appName], _url);
|
2014-11-11 19:00:29 +01:00
|
|
|
{
|
2015-09-21 22:27:07 +02:00
|
|
|
if (ret === true) return this.loadingDeferred.promise();
|
2014-11-11 19:00:29 +01:00
|
|
|
if (typeof ret === 'string')
|
|
|
|
{
|
|
|
|
_url = ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var useIframe = true;
|
|
|
|
var targetUrl = _url;
|
2015-03-10 21:12:30 +01:00
|
|
|
if(_url == this.currentLocation && this.loadingDeferred != null)
|
|
|
|
{
|
|
|
|
// Still loading
|
|
|
|
return this.loadingDeferred.promise();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show loader div, start blocking
|
|
|
|
var self = this;
|
2015-12-07 10:08:09 +01:00
|
|
|
this.ajaxLoaderDiv = egw.loading_prompt(this.app.appName,true,egw.lang('please wait...'),this.baseDiv, egwIsMobile()?'horizental':'spinner');
|
2015-03-10 21:12:30 +01:00
|
|
|
this.loadingDeferred = new jQuery.Deferred();
|
2015-10-07 11:32:22 +02:00
|
|
|
|
2015-05-13 18:21:50 +02:00
|
|
|
// Try to escape from infinitive not resolved loadingDeferred
|
|
|
|
// At least user can close the broken tab and work with the others.
|
|
|
|
// Define a escape timeout for 5 sec
|
|
|
|
this.ajaxLoaderDivTimeout = setTimeout(function(){
|
2015-10-07 11:32:22 +02:00
|
|
|
(self.ajaxLoaderDiv || jQuery('div.loading')).hide().remove();
|
2015-12-07 10:08:09 +01:00
|
|
|
self.ajaxLoaderDiv = egw.loading_prompt(self.app.appName,false);
|
2015-05-13 18:21:50 +02:00
|
|
|
},5000);
|
2015-10-07 11:32:22 +02:00
|
|
|
|
2015-03-10 21:12:30 +01:00
|
|
|
this.loadingDeferred.always(function() {
|
|
|
|
if(self.ajaxLoaderDiv)
|
|
|
|
{
|
2016-02-29 16:50:24 +01:00
|
|
|
|
2015-12-07 10:08:09 +01:00
|
|
|
self.ajaxLoaderDiv = egw.loading_prompt(self.app.appName,false);
|
2015-05-13 18:21:50 +02:00
|
|
|
// Remove escape timeout
|
|
|
|
clearTimeout(self.ajaxLoaderDivTimeout);
|
2015-03-10 21:12:30 +01:00
|
|
|
}
|
2016-02-29 16:50:24 +01:00
|
|
|
|
|
|
|
|
2015-03-10 21:12:30 +01:00
|
|
|
});
|
2015-10-07 11:32:22 +02:00
|
|
|
|
2014-11-11 19:00:29 +01:00
|
|
|
// Check whether the given url is a pseudo url which should be executed
|
|
|
|
// by calling the ajax_exec function
|
|
|
|
// we now send whole url back to server, so apps can use $_GET['ajax']==='true'
|
|
|
|
// to detect app-icon was clicked and eg. further reset filters
|
|
|
|
var matches = _url.match(/\/index.php\?menuaction=([A-Za-z0-9_\.]*.*&ajax=true.*)$/);
|
|
|
|
if (matches) {
|
|
|
|
// Matches[1] contains the menuaction which should be executed - replace
|
|
|
|
// the given url with the following line. This will be evaluated by the
|
|
|
|
// jdots_framework ajax_exec function which will be called by the code
|
|
|
|
// below as we set useIframe to false.
|
|
|
|
targetUrl = "index.php?menuaction=" + matches[1];
|
|
|
|
useIframe = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy application js
|
2016-03-17 19:12:36 +01:00
|
|
|
if(app[this.app.appName] && app[this.app.appName].destroy)
|
2014-11-11 19:00:29 +01:00
|
|
|
{
|
2016-03-17 19:12:36 +01:00
|
|
|
app[this.app.appName].destroy();
|
2014-11-11 19:00:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unload etemplate2, if there
|
|
|
|
if(typeof etemplate2 == "function")
|
|
|
|
{
|
|
|
|
// Clear all etemplates on this tab, regardless of application, by using DOM nodes
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('.et2_container',this.contentDiv||this.baseDiv).each(function() {
|
2014-11-11 19:00:29 +01:00
|
|
|
var et = etemplate2.getById(this.id);
|
|
|
|
if(et !== null)
|
|
|
|
{
|
|
|
|
et.clear();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else if(this.iframe && typeof this.iframe.contentWindow.etemplate2 == "function")
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if(typeof this.iframe.contentWindow.etemplate2 == "function")
|
|
|
|
{
|
|
|
|
// Clear all etemplates on this tab, regardless of application, by using DOM nodes
|
|
|
|
var content = this.iframe.contentWindow;
|
2017-10-05 19:17:42 +02:00
|
|
|
jQuery('.et2_container',this.iframe.contentDocument).each(function() {
|
2014-11-11 19:00:29 +01:00
|
|
|
var et = content.etemplate2.getById(this.id);
|
|
|
|
if(et !== null)
|
|
|
|
{
|
|
|
|
et.clear();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(e) {} // catch error if eg. SiteMgr runs a different origin, otherwise tab cant be closed
|
|
|
|
}
|
|
|
|
|
2015-03-18 10:56:11 +01:00
|
|
|
// Save the actual url which has been passed as parameter
|
|
|
|
this.currentLocation = _url;
|
|
|
|
|
2014-11-11 19:00:29 +01:00
|
|
|
//Set the browser type
|
|
|
|
if (useIframe)
|
|
|
|
{
|
|
|
|
this.setBrowserType(EGW_BROWSER_TYPE_IFRAME);
|
|
|
|
|
|
|
|
//Postpone the actual "navigation" - gives some speedup with internet explorer
|
|
|
|
//as it does no longer blocks the complete page until all frames have loaded.
|
|
|
|
window.setTimeout(function() {
|
|
|
|
//Load the iframe content
|
|
|
|
self.iframe.src = _url;
|
|
|
|
|
|
|
|
//Set the "_legacy_iframe" flag to allow link handlers to easily determine
|
|
|
|
//the type of the link source
|
|
|
|
if (self.iframe && self.iframe.contentWindow) {
|
|
|
|
try {
|
|
|
|
self.iframe.contentWindow._legacy_iframe = true;
|
|
|
|
|
|
|
|
// Focus the iframe of the current application
|
|
|
|
if (self.app == framework.activeApp)
|
|
|
|
{
|
|
|
|
self.iframe.contentWindow.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
// ignoer SecurityError: Blocked a frame ..., caused by different origin
|
|
|
|
}
|
|
|
|
}
|
2015-03-10 21:12:30 +01:00
|
|
|
|
|
|
|
if(self.loadingDeferred)
|
|
|
|
{
|
|
|
|
self.loadingDeferred.resolve();
|
2015-03-23 15:30:53 +01:00
|
|
|
self.loadingDeferred = null;
|
2015-03-10 21:12:30 +01:00
|
|
|
}
|
2014-11-11 19:00:29 +01:00
|
|
|
}, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.setBrowserType(EGW_BROWSER_TYPE_DIV);
|
|
|
|
|
|
|
|
//Special treatement of "about:blank"
|
|
|
|
if (targetUrl == "about:blank")
|
|
|
|
{
|
|
|
|
if (this.app.sidemenuEntry)
|
|
|
|
this.app.sidemenuEntry.hideAjaxLoader();
|
|
|
|
|
|
|
|
egw_widgetReplace(this.app.appName, this.contentDiv, '');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Perform an AJAX request loading application output
|
|
|
|
if (this.app.sidemenuEntry)
|
|
|
|
this.app.sidemenuEntry.showAjaxLoader();
|
|
|
|
this.data = "";
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this.contentDiv).empty();
|
2014-11-11 19:00:29 +01:00
|
|
|
var self_egw = egw(this.app.appName);
|
|
|
|
var req = self_egw.json(
|
2019-12-14 12:09:22 +01:00
|
|
|
this.app.getMenuaction('ajax_exec', targetUrl),
|
2014-11-11 19:00:29 +01:00
|
|
|
[targetUrl], this.browse_callback,this, true, this
|
|
|
|
);
|
|
|
|
req.sendRequest();
|
|
|
|
}
|
|
|
|
}
|
2015-03-10 21:12:30 +01:00
|
|
|
return this.loadingDeferred.promise();
|
2014-11-11 19:00:29 +01:00
|
|
|
},
|
2015-03-18 10:56:11 +01:00
|
|
|
|
2014-11-11 19:00:29 +01:00
|
|
|
/**
|
2015-03-18 10:56:11 +01:00
|
|
|
*
|
2014-11-11 19:00:29 +01:00
|
|
|
* @param {type} _data
|
|
|
|
* @return {undefined} return undefined if data is not from the right response
|
|
|
|
*/
|
|
|
|
browse_callback: function(_data)
|
|
|
|
{
|
|
|
|
// Abort if data is from wrong kind of response - only 'data'
|
|
|
|
if(!_data || _data.type != undefined) return;
|
|
|
|
|
|
|
|
this.data = _data[0];
|
|
|
|
this.browse_finished();
|
|
|
|
},
|
2015-03-18 10:56:11 +01:00
|
|
|
|
2014-11-11 19:00:29 +01:00
|
|
|
/**
|
|
|
|
* Get call via browse_callback in order to attaching nodes to the DOM
|
|
|
|
*/
|
|
|
|
browse_finished: function()
|
|
|
|
{
|
|
|
|
if (this.app.sidemenuEntry)
|
|
|
|
this.app.sidemenuEntry.hideAjaxLoader();
|
|
|
|
// egw_widgetReplace(this.app.appName, this.contentDiv, this.data);
|
2016-02-29 16:50:24 +01:00
|
|
|
var content = {
|
2014-11-11 19:00:29 +01:00
|
|
|
html: this.data,
|
|
|
|
js: ''
|
|
|
|
};
|
|
|
|
|
|
|
|
if (this.app == framework.activeApp)
|
|
|
|
{
|
|
|
|
window.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
egw_seperateJavaScript(content);
|
|
|
|
|
|
|
|
// Insert the content
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this.contentDiv).append(content.html);
|
2014-11-11 19:00:29 +01:00
|
|
|
|
|
|
|
// Run the javascript code
|
|
|
|
//console.log(content.js);
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this.contentDiv).append(content.js);
|
2015-03-10 21:12:30 +01:00
|
|
|
|
|
|
|
if(this.loadingDeferred)
|
|
|
|
{
|
|
|
|
this.loadingDeferred.resolve();
|
|
|
|
}
|
2014-11-11 19:00:29 +01:00
|
|
|
},
|
2015-03-18 10:56:11 +01:00
|
|
|
|
2014-11-11 19:00:29 +01:00
|
|
|
/**
|
|
|
|
* REload the content of the browser object
|
|
|
|
*/
|
|
|
|
reload: function()
|
|
|
|
{
|
|
|
|
switch (this.type)
|
|
|
|
{
|
|
|
|
case EGW_BROWSER_TYPE_DIV:
|
|
|
|
this.browse(this.currentLocation);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EGW_BROWSER_TYPE_IFRAME:
|
|
|
|
//Do a simple reload in the iframe case
|
|
|
|
this.iframe.contentWindow.location.reload();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
2015-03-18 10:56:11 +01:00
|
|
|
|
2014-11-11 19:00:29 +01:00
|
|
|
/**
|
2015-03-18 10:56:11 +01:00
|
|
|
*
|
2014-11-11 19:00:29 +01:00
|
|
|
*/
|
|
|
|
blank: function()
|
|
|
|
{
|
|
|
|
this.browse('about:blank', this.type == EGW_BROWSER_TYPE_IFRAME);
|
|
|
|
}
|
2016-02-29 16:50:24 +01:00
|
|
|
});}).call(this);
|