// parent window functions and global vars
var env_page_target_window = "portal-target-pagemode";
var env_page_target_width = 960;
var env_windowtargets_list = [];
var env_current_window_target;
$(window).resize(function ()
{
ResizeAllWindowHeights();
ToggleDragCursorIcons();
});
function InitWindow(windowtargetid, windowurl, windowtitle, windowicon, closeclickevents, windowwidth, ignorecache)
{
var lang_window = {
close: "Close" || "Close",
//loading: "Loading Content
Please Wait" || "Loading Content
Please Wait",
loading: "Loading
" + windowtitle + "
Please Wait" || "Loading Content
Please Wait",
};
//nip problematic urls in the bud
if (windowurl.indexOf("undefined") > 1) return false;
var scrollx = 0;
var newwindow = true;
var window_target_id = (env_portal_mode == "page") ? env_page_target_window : windowtargetid;
env_current_window_target = (env_portal_mode == "page") ? env_page_target_window : windowtargetid;
var $winobj = [], $winload = [], $winarea = []; //Window object, loading and areas
// default window width if parameter is empty
var win_width = parseInt(windowwidth) || ((env_portal_mode == "page") ? env_page_target_width : 700);
// only execute if the panel doesn't exist
if (!$('#' + window_target_id).length)
{
// new window
newwindow = true;
env_windowtargets_list.push($('#' + window_target_id));
// get the current width of the window container
var wincontainerwidth = $("#env-dashboard-windows-content").width();
var datawindowicon = windowicon ? " data-window-icon=\"" + windowicon + "\"" : "";
// add the containers where the content will be inserted
var beginningwrapper = "
";
var loadingwrapper = "
";
var areawrapper = "
";
var endingwrapper = "
";
$("#env-dashboard-windows-content").append(beginningwrapper + loadingwrapper + areawrapper + endingwrapper);
// put the new target in a jquery object
$winobj = $("#" + window_target_id);
$winload = $winobj.children("div.portal-window-loading");
$winarea = $winobj.children("div.portal-window-area");
//Bind the close event to the temporary close button
if (env_portal_mode != "page")
{
$winload.find("a.portal-window-loading-close").click(function ()
{
RemoveWindow("#" + window_target_id);
eval(closeclickevents);
});
//Re-calibrate iscroll
RecalibrateScroll();
//Calculate offset of the new window in the container
var t = CalculateWidth(win_width);
var ww = $(window).width();
var a = 0; //$("#env-aside").width();
//If panel window is bigger than browser window, have it scroll to the left edge instead of the right edge
scrollx = (win_width > (ww - a)) ? t - ww - (a / 2) : t - ww + a;
//add this window to the window list
UpdateWindowList();
// add this window to the user's open window cache list
if (!ignorecache == true)
$.post("/Cache/OpenWindows/SaveOpenWindowReference", { targetid: escape(windowtargetid), url: escape(windowurl), title: escape(windowtitle), icon: escape(windowicon), closeevents: escape(closeclickevents), width: win_width });
}
else
$("div.portal-window-loading a.portal-ui-close").addClass("hide");
}
else
{
// not new window
newwindow = false;
// put the new target in a jquery object
$winobj = $("#" + window_target_id);
$winload = $winobj.children("div.portal-window-loading");
$winarea = $winobj.children("div.portal-window-area");
var scrollarea = $("div.portal-dashboard-scroll-belt");
if (env_portal_mode != "page")
{
//Re-calibrate iscroll
RecalibrateScroll();
//Calculate offset of the new window in the container
var t = CalculateWidth(win_width);
var ww = $(window).width();
var a = $("#env-aside").width();
scrollx = $winobj.isOnScreen(1, 0) ? null : $winobj.position().left - 130;
}
else
{
$winobj.width(win_width);
$winarea.width(win_width);
}
// remove current window content and replace with loading message
$winload.css("display", "block");
$winarea.css("display", "none");
}
// check if drag icons are necessary
ToggleDragCursorIcons();
// close the panel
ClosePanel();
// scroll to the window area (only if the window isn't fully visible)
if (env_portal_mode != "page")
{
if (scrollx)
ScrollToElement(scrollx);
}
// fade in the window
$winobj.fadeIn();
//load in the partial
$.ajax({
url: windowurl,
success: function (html)
{
// append the content if new
if (newwindow) $winarea.append(html);
else $winarea.empty().html(html);
// set the title
$winarea.find("h2.window-title").html(windowtitle);
// set the header buttons
if (env_portal_mode != "page") {
//Get the pin hooked up (if there is one) or dim it out if a tile already exists.
var $winpin = $winarea.find("a.window-action-pin");
if ($winpin.length > 0) {
$winpin.click(function () {
if (!$(this).hasClass("disabled")) {
// move to pins
ScrollToElement(0);
// save pin
var pinform = $winarea.find("form.portal-pinform");
dashboardplugin.layoutdashboard('tilesplugin').pintiles('savepin', "/Pins/Tiles/SavePinAsTile", $(pinform).serialize(), window_target_id);
}
});
}
// set the close window click
$winarea.find("a.window-action-close").click(function ()
{
RemoveWindow("#" + window_target_id);
eval(closeclickevents);
});
// set the refresh button click
$winarea.find("a.window-action-refresh").click(function ()
{
InitWindow(window_target_id, windowurl, windowtitle, windowicon, closeclickevents, win_width);
});
// set the documentation button click
$winarea.find("a.window-action-documentation").click(function ()
{
var $infobtn = $(this);
var doctitle = $infobtn.data("title");
var docpartial = $infobtn.data("partial");
$("#WindowHeaderDocumentationPopup").empty();
$.colorbox({
inline: true, overlayClose: false, width: 600, height: "90%", maxWidth: "95%", maxHeight: "90%", title: doctitle, href: "#WindowHeaderDocumentationPopup",
onComplete: function ()
{
$("#WindowHeaderDocumentationPopup").append("");
$("#WindowHeaderDocumentationPopup").load("/Documentation/Documentation/OpenDocument/" + docpartial);
}
});
});
}
else
CachePageWindow(windowtargetid, windowurl, windowtitle, windowicon, closeclickevents, windowwidth);
// set the report button click
$winarea.find("a.window-action-chart").click(function () {
ToggleReportOverlay(this);
});
//add this window to the window list (and activate the pin if tile doesn't exist)
UpdateWindowList();
//Time to show the content
$winload.fadeOut(250, function ()
{
$winarea.fadeIn(250, function ()
{
//As soon as content is visible, see if a scrollbar needs to be added
if (use_iscroll)
{
var name = "panelwindow_" + window_target_id;
var winscroll = "#" + $(this).find("div.portal-window-wrapper").attr("id");
window[name] = new IScroll(winscroll, { scrollX: false, scrollY: true, scrollbars: true }); //iScroll
}
//Set the window's fixed height
CalibrateWindowHeight($winobj, false);
});
});
}
});
}
function ExpandToolbarStatus(obj, msgHtml, className)
{
var $obj = $(obj);
var $win = $obj.closest(".portal-window-content") || $obj.find(".portal-window-content");
var $toolbar = $win.children(".portal-window-toolbar");
var delay = closeDelay == 0 ? 0 : (closeDelay || 5000);
//Does status already exist
var status_exists = $toolbar.find(".portal-window-toolbar-status").length > 0;
var $status = status_exists ? $toolbar.find(".portal-window-toolbar-status") : $("");
//Render message
msgHtml = msgHtml.length > 0 ? msgHtml : "Message goes here
";
msgHtml = msgHtml.indexOf(" -1 ? msgHtml : "
" + msgHtml + "
";
$status.html(msgHtml).addClass(className);
if (status_exists) {
$status.css("style", "");
} else {
var $a_close_status = $("");
$a_close_status.on("click", function () { CollapseToolbarStatus(this); });
$status.append($a_close_status);
$toolbar.append($status);
}
$status.find("p").css({ "height": $toolbar.outerHeight() });
$status.animate({ "left": "0%" }, function () {
if (delay > 0) setTimeout(function () { CollapseToolbarStatus($a_close_status); }, delay);
});
}
function CollapseToolbarStatus(obj) {
var $obj = $(obj);
var $win = $obj.closest(".portal-window-content") || $obj.find(".portal-window-content");
var $toolbar = $win.children(".portal-window-toolbar");
var $status = $toolbar.children(".portal-window-toolbar-status");
$status.animate({ "left": "-100%" }, function () {
$status.remove();
});
}
function RemoveWindow(window)
{
//Remove the scrolling instance first
if (use_iscroll)
{
var name = "panelwindow_" + $(window).attr("id");
if (window[name]) window[name].destroy(); //iScroll
}
//Now lose the window
$(window).width(0); //Animate it closed
$(window).fadeOut(500, function ()
{
$(window).remove();
var tilewidth = $("#env-dashboard-tiles-container").width();
var winwidth = $("#env-dashboard-windows-container").width();
$("#env-dashboard-scroll-belt").animate({ width: tilewidth + winwidth }, function () { CalculateWidth(); });
// remove this window from the user's open window cache list
$.post("/Cache/OpenWindows/DeleteOpenWindowReference", { targetid: escape(window.replace('#', '')) });
//redo the window list
UpdateWindowList();
});
}
function CalculateWidth(newwindowwidth)
{
var tilewidth = $("#env-dashboard-tiles-container").width();
var winwidth = $("#env-dashboard-windows-container").width();
var newwinwidth = newwindowwidth === undefined ? 0 : newwindowwidth;
var total = tilewidth + winwidth + newwinwidth + 70;
$("#env-dashboard-scroll-belt").width(total + 1); //The +1 is in case there are sub-pixel widths in any of the containers getting truncated by JQuery
//$("#env-debug-container").append(tilewidth + " " + winwidth + " " + newwinwidth + " : " + total + "
");
RecalibrateScroll();
ToggleDragCursorIcons();
return total;
}
function RecalibrateScroll(win)
{
if (use_iscroll)
{
var targetscroll = win || bodyscroll;
setTimeout(function () { if (targetscroll) targetscroll.refresh(); }, 0); //iScroll
}
}
function RecalibrateWindowScroll(obj)
{
var $that = ConvertToJQueryObject(obj);
var windowname = "panelwindow_" + ($that.hasClass("portal-window") ? $that.attr("id") : $that.closest(".portal-window").attr("id"));
if (obj) RecalibrateScroll(window[windowname]);
}
function RecalibrateBucketScroll(obj)
{
var $that = ConvertToJQueryObject(obj);
var bucketname = "bucket_" + ($that.hasClass("portal-bucket-inner") ? $that.attr("id") : $that.closest(".portal-bucket-inner").attr("id"));
if (obj) RecalibrateScroll(window[bucketname]);
}
function RecalibrateFilmstripScroll(obj)
{
var $that = ConvertToJQueryObject(obj);
//var fsname = "filmstrip_" + ($that.hasClass("portal-bucket-inner") ? $that.attr("id") : $that.closest(".portal-bucket-inner").attr("id"));
//if (obj) RecalibrateScroll(window[fsname]);
}
function ScrollToElement(x)
{
if (use_iscroll)
{
if (bodyscroll)
bodyscroll.scrollTo(-x, 0, 500); //iScroll
}
else
$(bodyscroll).animate({ scrollLeft: x }, 500);
}
function ResizeAllWindowHeights()
{
var windowHeight = $("#env-dashboard-windows-content").innerHeight();
var allWindows = $(".portal-window");
$(allWindows).each(function (i, o)
{
CalibrateWindowHeight(o);
});
}
function CalibrateWindowHeight(obj, resizing)
{
var resize = (resizing !== undefined) ? resizing : true;
var winHeight = $(".portal-dashboard-windows-content").innerHeight();
var parentWin = !$(obj).hasClass("portal-window") ? $(obj).closest(".portal-window") : $(obj);
var headerHeight = $(parentWin).find(".portal-window-header").outerHeight();
var toolbarHeight = $(parentWin).find(".portal-window-toolbar").outerHeight();
var footerHeight = $(parentWin).find(".portal-window-footer").outerHeight();
var retroHeader = $("body.page-mode aside").outerHeight() || 0;
var portalWindowContent = $(parentWin).find(".portal-window-content");
var portalWindowWrapper = $(parentWin).find(".portal-window-wrapper");
var portalWindowActiveBucket = $(parentWin).find(".portal-bucket.active");
var portalWindowContentHeight = winHeight - headerHeight - footerHeight;
var portalWindowWrapperHeight = portalWindowContentHeight - toolbarHeight;
var portalWindowActiveBucketHeight = portalWindowWrapperHeight - 24;
$(portalWindowContent).height(portalWindowContentHeight);
$(portalWindowWrapper).height(portalWindowWrapperHeight);
if (portalWindowActiveBucket.length > 0) $(portalWindowActiveBucket).height(portalWindowActiveBucketHeight);
//Adjust all flex elements
$(".flex-height").each(function (i,e) {
var $flex = $(e);
var offsettop = $flex.offset().top;
var flexheight = portalWindowContentHeight - offsettop + 30 + retroHeader;
$flex.height(flexheight);
});
//Since iScroll already auto-resizes on window resize, only fire this for height changes within the local window
if (!resize && use_iscroll) { RecalibrateWindowScroll($(parentWin)); }
//$("#env-debug-container").html("Window: " + winHeight + "
" + "Header: " + headerHeight + "
" + "Footer: " + footerHeight);
}
function ToggleReportOverlay(jqForm)
{
var $parent = $(jqForm).closest(".portal-window-container");
var $chart_container = $parent.find(".portal-window-report-container");
var $chart = $chart_container.children(".portal-window-report");
var $chart_close = $chart.find("a.portal-window-report-close");
if ($chart_container.hasClass("closed")) $chart_container.animate({ top: 0 }, function () {
$(this).removeClass("closed").addClass("open");
$chart_close.on("click", function () { ToggleReportOverlay(jqForm); });
});
else if ($chart_container.hasClass("open")) $chart_container.animate({ top: "-100%" }, function () { $(this).removeClass("open").addClass("closed"); $chart_close.off(); })
}
function CachePageWindow(windowtargetid, windowurl, windowtitle, windowicon, closeclickevents, windowwidth)
{
pagecacheplugin.pagewindows("addpagehistory", windowtargetid, windowurl, windowtitle, windowicon, closeclickevents, windowwidth);
}
function UpdateWindowList() {
//Set language
var lang_windowlist = {
reorder: "Re-order this window" || "Re-order this window",
move: "Move" || "Move",
pinned: "Window is currently pinned" || "Window is currently pinned",
pin: "Pin" || "Pin",
pinthis: "Pin this window to your dashboard" || "Pin this window to your dashboard.",
closewin: "Close this window" || "Close this window",
close: "Close" || "Close",
closing: "Closing window" || "Closing Window",
loading: "Loading Window Content" || "Loading Window Content",
empty: "There are currently no active windows open." || "There are currently no active windows open."
};
//Get all the open windows
var $windowobj = $("div.portal-sidemenu-windows-list");
var $windowlist = $("div.portal-window");
var $windowlistul = $windowobj.find("ul");
if ($windowlist.length > 0)
{
//Remove the last one
$windowlistul.remove();
//Create a new list
var html = "";
$windowobj.append(html);
//Bind events to the buttons
$windowlistgoto = $("a.window-item-title");
$windowlistpin = $("a.window-item-action.portal-ui-pin");
$windowlistclose = $("a.window-item-action.portal-ui-close");
$windowlistdrag = $("a.window-item-action.portal-ui-drag");
$.each($windowlistgoto, function (i, e) {
$(e).on("click", function () { WindowListGoTo(e); });
});
$.each($windowlistpin, function (i, e) {
$(e).on("click", function () { WindowListPin(e); })
});
$.each($windowlistclose, function (i,e) {
$(e).on("click", function () { WindowListClose(e, lang_windowlist.closing); });
});
$("ul.portal-sidemenu-windows-list-items").sortable({
handle: $windowlistdrag,
axis: "y",
update: function (i,e) { WindowReorder(e); }
});
} else {
$windowlistul.html("" + lang_windowlist.empty + "");
}
}
function CheckForPinIcon(obj) {
var $win = $(obj);
var $pin = $win.find(".window-action-pin");
return $pin.length > 0;
}
function CheckForExistingPin(wid) {
if (wid) {
var $tiles = $("div#tile_sortable").children();
var $tile = $tiles.filter('[data-window-target-id="' + wid + '"]');
return $tile.length > 0;
} else
return false;
}
function WindowListPin(obj) {
var $obj = $(obj);
var $li = $obj.closest("li");
var $win = $("#" + $li.data("window-id"));
var $pin = $win.find("a.window-action-pin");
if ($pin.length > 0) $pin.trigger("click");
else $pin.remove();
}
function WindowListClose(obj, message) {
var $obj = $(obj);
var $li = $obj.closest("li");
$li.addClass("portal-ui-animate-loading").html(message || "Closing Window");
var $win = $("#" + $li.data("window-id"));
var $close = $win.find("a.window-action-close");
$close.trigger("click");
}
function WindowListGoTo(obj) {
var $obj = $(obj);
var $li = $obj.closest("li");
var $win = $("#" + $li.data("window-id"));
var scrollx = $win.isOnScreen(1, 0) ? null : $win.position().left - 130;
if (scrollx) ScrollToElement(scrollx);
}
function WindowReorder(obj) {
var listitem = obj.item;
var windowid = listitem.data("window-id");
var windowindex = listitem.index();
if (windowid)
{
var $win = $("#" + windowid);
WindowAnimatePositions($win, windowindex, listitem);
}
}
function WindowAnimatePositions(targetWin, targetWinIndex, targetItem) {
var $parent = $("div.portal-dashboard-windows-content");
var $orderlist = $("ul.portal-sidemenu-windows-list-items li");
var $windows = $("div.portal-window");
var $winpositionold = [];
var $winpositionnew = [];
var $winwidth = [];
//So iPad doesn't shrink the parent to 0 width
$parent.width($parent.width());
//Capture windows position and width
$windows.each(function (i, e) {
var $e = $(e);
$winpositionold.push($e.position().left);
$winwidth.push($e.outerWidth());
$e.css({ "left": $e.position().left });
});
$windows.css({ "position": "absolute" });
$winpositionnew.push($winpositionold[0]); //Set the first new position to the same as the old
//Move the elements in the DOM
if (targetWinIndex == 0) {
var $first = $windows.first();
if ($first.length > 0) $(targetWin).insertBefore($first);
} else {
var $adjacent = $(targetItem).prev();
if ($adjacent.length > 0) {
var $adj = $("#" + $adjacent.data("window-id"));
if ($adj.length > 0) $(targetWin).insertAfter($adj);
}
}
//Assign new position coordinates for all the windows
$orderlist.each(function (i, e) {
var $e = $(e);
var $winobj = $("#" + $e.data("window-id"));
if ($winobj.length > 0) {
if (i < $orderlist.length - 1) //set the position for the following window by getting the width for the previous one
$winpositionnew.push($winpositionnew[i] + $winobj.outerWidth(true));
//Animate windows to their new position
$winobj.animate({ left: $winpositionnew[i] }, function () { if (i == $orderlist.length - 1) $windows.css({ "position": "", "left": "" }); $parent.removeAttr("style"); });
}
});
}