/*
$Revision$
$Id$
File: FcltMgr.js
Description: FcltMgr is de manager van Facilitor die voornamelijk twee containers biedt
A) Een menu container
B) Een functie container (de tabjes rechts)
*/
function L(lcl)
{
return FcltMgr.L(lcl);
}
var FcltMgr =
{
_pageManager: null, // defaultManager of tabbedManager
globalData: [],
reload: function ()
{ // met (door jquery tabs toegevoegd) fragment identifier werkt onderstaand anders niet
var hrefBase = window.location.href.split( "#" )[ 0 ];
// nooit collapsed herladen?
hrefBase = hrefBase.replace(/&collapsed=1/gi, "");
if (hrefBase.indexOf("no_autoscroll") == -1)
hrefBase = hrefBase + (hrefBase.indexOf("?")>0?"&":"?") + "no_autoscroll=1";
window.location.href = hrefBase;
},
defaultManager :
{
name: "defaultManager",
openDetail: function(url, titel, params)
{
params = params || {};
titel = titel || "";
if (url.indexOf("hmac=") < 0)
{
url += (url.indexOf("?")<0)?"?":"&";
url += "_titel_=" + escape(titel);
}
if (params.forcedeep)
window.open("../../?JumpTo=" + escape(params.orgurl));
else
window.open(url);
// FcltMgr.resized(window, params);
},
closeDetail: function(thiswindow, params)
{
window.close();
},
setTitle: function (title, params)
{
if (title)
window.document.title = title;
}
},
tabbedManager :
{
name: "tabbedManager",
_counter: 0,
openDetail: function(url, titel, params)
{
FcltMgr._pageManager._openTab(url, titel, params);
},
closeDetail: function(thiswindow, params)
{
var active = this._$tabshost.tabs('option', 'active');
var tab = $(this._$tabshost.find( ".ui-tabs-nav li" )[active]);
FcltMgr._pageManager._closeTab(tab);
return;
},
setTitle: function (title, params)
{
var orgtitle = null;
if (title && title.length > 25)
{
orgtitle = title;
title = title.substr(0, 20) + "...";
}
// FcltMgr heeft voor ons params al met windowname gevuld.
params = params || {};
var tab = this._$tabshost.find( ".ui-tabs-nav li[aria-controls='"+params.windowname+"']" );
if (title)
tab.find("span:first").text(title);
if (orgtitle)
tab.find("span:first").attr('title', orgtitle);
if (params.hot)
{
tab.find(".tabclose").addClass('hot');
}
else
{
tab.find(".tabclose").removeClass('hot');
}
},
// Sluit alle tabbladen behalve de huidige en behalve _editactive
closeAll: function (zelf)
{
var active = this._$tabshost.tabs('option', 'active');
$(".ui-tabs-nav li", this._$tabshost).each(function(i,j)
{
if (i > 0 && i != active && !FcltMgr._pageManager._panelHot(this))
{
FcltMgr._pageManager._closeTab(this, { noRefresh: true });
}
});
this._$tabshost.tabs( "refresh" ); // Allemaal tegelijk is veel sneller in IE8
},
// 'Pin' het huidige tabje of geef deze juist vrij
saveTab: function (zelf)
{
if (zelf)
{
var li = $(zelf).parents('li:eq(0)')[0];
var active = $('li', this._$tabshost).index(li);
}
else
{
var active = this._$tabshost.tabs('option', 'active');
if (active == 0 || FcltMgr._pageManager._panelHot(active))
{
alert(L("lcl_tabs_nosave"));
return;
}
}
var tab = $(this._$tabshost.find( ".ui-tabs-nav li" )[active]);
var a = $(tab).find("a");
if (a.length)
{
var href = $( a ).attr( "href" );
var ttl = $( a ).find("span:first").text();
if (href.indexOf("#" > 0))
href = "#" + href.split("#")[1];
var panel = $(href);
// hmac beschermde pagina's zijn toch al heel snel invalid. Silent ignore.
if (panel.length &&
panel[0].getAttribute("reusesrc").indexOf("&hmac=") < 0 &&
!panel[0].getAttribute("is_extern")) // externen is ook te complex
{
var frm = window.frames[panel[0].id];
var filters = null;
if (FcltMgr._frmaccessible(frm))
{
filters = frm.iface.formToString(frm.$("form[name=u2]"));
}
var url = panel[0].getAttribute("reusesrc");
if (url.indexOf("&fcltfilters=") > 0)
url = url.substr(0, url.indexOf("&fcltfilters="));
//ttl = prompt("Geef titel", ttl);
$.post(rooturl + "/appl/fac/fac_current_tab_save.asp",
{ autoopenurl: url,
autoopenttl: ttl,
filters: filters,
nowarning: (zelf?1:0)
},
FcltCallbackAndThen(function (data)
{
if (data.saved)
{
var html = "
";
$(tab).find(".tabclose").before($(html));
}
else
$(tab).find(".tabpinned").remove();
}),
"json");
}
else
alert(L("lcl_tabs_nosave"));
}
},
init: function (tabs_id)
{
this._tabshost = tabs_id;
this._$tabshost = $("#"+tabs_id);
var $tabs = this._$tabshost.tabs(
{
beforeActivate: function(event, ui)
{
var ofrm = ui.oldPanel;
if (ofrm.length)
{
var frm = window.frames[ofrm[0].id];
if (FcltMgr._frmaccessible(frm))
frm.wasScroll = $(frm).scrollTop(); // IE11/Win8 onthoudt dit erg slecht
}
},
activate: function(event, ui)
{
var ofrm = ui.oldPanel;
if (ofrm.length)
{
var frm = window.frames[ofrm[0].id];
if (FcltMgr._frmaccessible(frm) && frm.fcltontabhide)
{
frm.fcltontabhide();
}
}
var ifrm = ui.newPanel;
if (ifrm.length)
{
var frm = window.frames[ifrm[0].id];
if (FcltMgr._frmaccessible(frm))
{
$(frm).scrollTop(frm.wasScroll);
if (frm.fcltontabshow)
{
frm.fcltontabshow();
}
// Als door 'autoopen' veel tabjes tegelijk zijn geladen
// dan is de iframeLoaded niet goed afgegaan. Doe dat alsnog.
$("iframe" ,frm.document).each(function()
{
if ($(this).height() == 0)
FcltMgr.iframeLoaded(this);
})
}
FcltMgr._pageManager._timedResizeActiveTab();
}
}
});
$tabs.find( ".ui-tabs-nav" ).sortable({
items: "li:not([aria-controls='ID1'])", // Eerste tab ('mijn Facilitor') niet verplaatsen
axis: "x",
distance: 25,
stop: function() {
$tabs.tabs( "refresh" );
}
});
this._$tabshost.resize(function (){
FcltMgr._pageManager._timedResizeActiveTab();
});
},
// Internal to tabbedManager
_tabshost: null,
_$tabshost: null,
// Open een nieuwe tab 'url' in een iframe en 'Titel' als label
_openTab: function (url, titel, params)
{
params = params || {};
var openerId = '';
var prev_active = this._$tabshost.tabs('option', 'active');
var xx = $('a', this._$tabshost)[prev_active];
if (xx)
openerId = xx.id;
if (params.reuse) // try to find previous tab
{
var found = -1;
var thePanel;
var nohmac = url;
if (nohmac.indexOf("&hmac=") > 0)
nohmac = nohmac.substr(0, url.indexOf("&hmac="))
$('a', this._$tabshost).each(function(i,j)
{
var href = $( this ).attr( "href" );
if (href.indexOf("#" > 0))
href = "#" + href.split("#")[1];
var panel = $(href);
var nohmac2 = panel[0].getAttribute("reusesrc");
if (nohmac2.indexOf("&hmac=") > 0)
nohmac2 = nohmac2.substr(0, nohmac2.indexOf("&hmac="))
if (panel.length && nohmac == nohmac2)
{
found = i;
thePanel = panel;
}
});
if (found >= 0)
{
this._$tabshost.tabs('option', 'active', found);
if (!FcltMgr._pageManager._panelHot(found)) // niet als hot
{
thePanel[0].src = url; // Wel de nieuwe url met nieuwste hmac gebruiken
}
return;
}
}
this._counter++;
var theId = "ID"+this._counter;
titel = titel ||L("lcl_shared_loading");
var telang = false;
if (titel.length > 25)
{
titel = titel.substr(0, 20);
telang = true;
}
// Titel HTML safe maken
var newDiv = document.createElement("div"); // wordt wel door Garbage Collect opgeruimd.
if (typeof newDiv.innerText != 'undefined')
newDiv.innerText = titel
else
newDiv.textContent = titel;
titel = newDiv.innerHTML;
if (telang)
titel += "…";
var tpl = "
":"")
+ (params.noclose?"":" X")
+ "