/** empty log object (if querystring contains debug=xxx, then this variable will be overwritten by debug.ascx) **/ var log = { trace: function () { }, debug: function () { }, info: function () { }, warn: function () { }, error: function () { }, fatal: function () { } }; if (!window.console) console = {log: function() {}}; var EQuIS = new Object(); EQuIS.addFilters = function (sender, filter, fire) { // sub function that will fire the filter event into all applicable iframe contexts // FB.116299 - this event needs to fire in each applicable iframe context function fireAllFrames(sender, filter, filters, win) { // first fire for current window/iframe context (note that I have to use the current windows's jquery and also EQuIS objects) if (typeof win.EQuIS != 'undefined' || typeof win.$ != 'undefined') { // don't procede with this window if the EQuIS or jQuery objects are not defined. win.$(win.EQuIS).trigger('filter', [sender, filter, filters]); // then fire for any other applicable iframe contexts for (var i = 0; i < win.frames.length; i++) { // recurse on any applicable child iframes if (window != win.frames[i]) { // don't recurse on itself. // put in try/catch block because trying to access frame properties that are cross-origin can be blocked throwing an exception try { fireAllFrames(sender, filter, filters, win.frames[i]); } catch(ex){} } } } } try { var filters = EQuIS.getFilters(); if (!filters) return; $.extend(filters, filter); EQuIS.setFilters(filters); if (fire != false) { fireAllFrames(sender, filter, filters, top); } } catch (ex) { console.error(ex.message); } }; // Clears all filters for the current tab EQuIS.clearFilters = function (options) { try { var filters = EQuIS.getFilters(); var facilityId = filters.facility_id; sessionStorage.removeItem("equis-filters"); if (options && options.facility_id == false) { EQuIS.addFilters(EQuIS, { facility_id: facilityId }, false); } } catch (ex) { console.error(ex.message); } }; // Gets the filters object for the current tab EQuIS.getFilters = function () { try { // TODO: allow user to choose localStorage instead of sessionStorage? if (!sessionStorage) return null; var filters = sessionStorage.getItem("equis-filters"); if (filters) { filters = JSON.parse(filters); } else { filters = {}; } return filters; } catch (ex) { console.error(ex.message); return null; } } // Gets the filters object for the current tab EQuIS.setFilters = function (filters) { try { if (!sessionStorage) return null; sessionStorage.setItem("equis-filters", JSON.stringify(filters)); } catch (ex) { console.error(ex.message); return null; } } EQuIS.beginRequestHandler = function (sender, args) { try { var headers = args.get_request().get_headers(); headers["equis-filters"] = JSON.stringify(EQuIS.getFilters()); } catch (ex) { console.error(ex.message); } } EQuIS.endRequestHandler = function (sender, args) { try { if (EQuIS.refreshQueue.length > 0) { isDashboardAjaxCall = false; // this needs to be set false so the widget command can be added and not cancelled. var widgetId = EQuIS.refreshQueue.shift(); EQuIS.refreshWidget(widgetId); } } catch (ex) { console.error(ex.message); } } EQuIS.setupRequestHandlers = function() { try { //FB.93599: dashboard filters var prm = Sys.WebForms.PageRequestManager.getInstance(); if (prm !== null) { prm.add_beginRequest(EQuIS.beginRequestHandler); prm.add_endRequest(EQuIS.endRequestHandler); } $.ajaxSetup({ beforeSend: function (xhr, settings) { xhr.setRequestHeader("equis-filters", JSON.stringify(EQuIS.getFilters())); } }); } catch (ex) { console.error(ex.message); } } EQuIS.refreshQueue = []; EQuIS.refreshWidget = function (widgetId) { try { var id = widgetId.toString(); if (!id.startsWith("DashboardSurface_db_")) id = "DashboardSurface_db_" + id; // queue refresh request. (don't add if already in queue). if (EQuIS.refreshQueue.indexOf(id) == -1) { EQuIS.refreshQueue.push(id); } // don't send command if already dashboard ajax. if (isDashboardAjaxCall) { return; } // only send command if in queue var index = EQuIS.refreshQueue.indexOf(id); if (index > -1) { // remove from queue EQuIS.refreshQueue.splice(index, 1); // send refresh command doWidgetCmd(null, { "widgetId": id, "commandName": "refresh", "commandArg": {} }, null, null); } } catch (ex) { console.error(ex.message, ex); } }; EQuIS.dashboardId = function () { try { return $('[id$=DashboardInstanceKey]').val(); } catch (ex) { console.error(ex.message); return null; } }; EQuIS.facilityId = function (id) { try { var el = $('[id$=FacilityChooser_SelectedValue]'); if (typeof (id) === "undefined" || id == null) { return el.val(); } else { var scope = el.scope(); scope.generic.set_value(id); } } catch (ex) { console.error(ex.message); return null; } }; EQuIS.localizeDates = function (selector) { try { $(selector).each(function (i, el) { console.log('localizeDates: ' + selector); try { if (!$.isNumeric($(el).text())) return; var ticks = parseInt($(el).text()); //if (isNaN(ticks)) return; var dt = new Date(ticks); if (dt.getUTCFullYear() < 2000) return; //FB.95382 - fix to weed out erroneus dates from being displayed. //dt.toLocaleString() behaves differently on different browsers ... var str = $.datepicker.formatDate("yy-mm-dd ", dt) + dt.toLocaleTimeString(); $(el).text(str); } catch (ex) { console.log(ex.message); } }); } catch (ex) { console.log(ex.message); } }; EQuIS.showMask = function (message) { try { // always hide any existing mask before showing a new mask EQuIS.hideMask(); // use default message if not provided if (!message) message = 'Please wait ...'; // get mask target var maskTarget = document.getElementById('DashboardSurface'); if (maskTarget == null) return; setLoadMask(maskTarget, message); // this will prevent Kalitte's EndRequestHandler from automatically hiding the mask window.currentMask = null; ShowMasks(); } catch (ex) { console.error("showMask: " + ex.message); } }; EQuIS.hideMask = function () { try { KillMask('DashboardSurface'); } catch (ex) { console.debug("hideMask: " + ex.message); } }; EQuIS.submitDownload = function (action, data, outputType, callback, showMaskOpt) { if (typeof (showMaskOpt) === 'undefined') showMaskOpt = true; // FB.93039 need to call submitDownload without having the loading mask. so this sets a default value. try { //FB.95035,953836 show the mask while waiting for the download (FB.93039 - but don't show if called with showMaskOpt set to false). if (showMaskOpt) EQuIS.showMask(); // set the form data $('#download_data').val(data); $('#output_type').val(outputType); $('#equis-filters').val(JSON.stringify(EQuIS.getFilters())); // clear the download cookie try { document.cookie = "download=;expires=" + new Date(1000).toUTCString() + ";path=/"; $($('#downloadFrame').contents()[0].documentElement).empty(); } catch (ex) { console.debug("error clearing download info: " + ex.message); } // set action and submit var form = $('#download'); //form.attr('action', action); form.submit(); // start polling for download completion (inspired by http://johnculviner.com/jquery-file-download-plugin-for-ajax-like-feature-rich-file-downloads/) var interval = 100; setTimeout(function () { EQuIS.checkDownload(0, interval, callback); }, interval); } catch (ex) { log.error('submitDownload: ' + ex.message); EQuIS.hideMask(); } }; // This value corresponds to Web.config/system.web/httpRuntime/executiontimeout // and is the number of seconds that checkDownload will wait before removing the wait mask. // This value will be overwritten by default.aspx based on the current setting in Web.config EQuIS.ExecutionTimeout = 240; EQuIS.checkDownload = function (counter, interval, callback) { try { // check for download cookie (set by download.aspx.cs) that indicates the download has completed if (document.cookie.indexOf("download=ok") != -1) { // invoke the callback if (typeof (callback) == 'function') { callback.call(); } // clear the download cookie document.cookie = "download=;expires=" + new Date(1000).toUTCString() + ";path=/"; // remove the mask EQuIS.hideMask(); return; } // check iframe for error message try { var contents = $('#downloadFrame').contents(); if (contents.length > 0 && contents[0].readyState == "complete") { var text = $(contents[0].documentElement).text().trim(); if (text.length > 0) { alert(text); // remove the mask EQuIS.hideMask(); return; } } } catch (ex) { console.debug(ex.message); } // check for counter expiration (interval is in milliseconds; ExecutionTimeout is in seconds) if (counter > ((1000 / interval) * EQuIS.ExecutionTimeout)) { // remove the mask EQuIS.hideMask(); return; } // if we get here, the download is not ready yet setTimeout(function () { EQuIS.checkDownload(++counter, interval, callback); }, interval); } catch (ex) { log.error('checkDownload: ' + ex.message); EQuIS.hideMask(); } }; EQuIS.echo = function(filename, mimetype, content) { try { var data = { 'filename': filename, 'mimetype': mimetype, 'content': content }; var action = 'explorer/echo'; this.submitDownload(action, JSON.stringify(data)); } catch(ex) { log.error('echo: ' + ex.message); } }; EQuIS.deleteDashboard = function () { try { if (confirm('Are you sure you want to delete the current dashboard and all of its sections, columns, and widgets?')) { return true; } else { return false; } } catch (ex) { log.error('deleteDashboard: ' + ex.message); } }; EQuIS.editDashboard = function () { try { var dashboardID = $('[id$=DashboardInstanceKey]').val(); var widget = { 'widgetConfig': { 'instanceKey': '$' + dashboardID} }; var props = { 'commandArg': { 'width': 0, 'height': 0, 'title': 'Dashboard Editor'} }; //asynchronously displays the window editorWindow(null, props, widget); } catch (ex) { log.error('editDashboard: ' + ex.message); } }; EQuIS.openDialog = function (options) { try { if (options == null || options.dialog == null || options.dialog.length == 0) return; var html = document.documentElement; var dialogHeight = html.clientHeight - 100; var dialogWidth = html.clientWidth - 100; if (options.width && options.width > 0) dialogWidth = options.width; if (options.height && options.height > 0) dialogHeight = options.height; var frameHeight = dialogHeight - 76.0; var frameWidth = dialogWidth - 36.0; // append the dialog dimensions to url var url = "dialog.aspx?dialog=" + encodeURIComponent(options.dialog) + "&h=" + frameHeight.toString() + "&w=" + frameWidth.toString(); // append filters var filters = EQuIS.getFilters(); if (Object.getOwnPropertyNames(filters).length > 0) url = url + "&equis-filters=" + encodeURIComponent(JSON.stringify(filters)); // create the IFRAME var iframe = $("