// reload all charts on the page function reloadCharts() { // exit if this is not firefox if (navigator.userAgent.toLowerCase().indexOf('firefox') === -1) { return false; } // for each iframe that is about to be activated $('.ui-widget-content [aria-expanded="false"]').find('iframe').each(function() { // get the src of the iframe var iframe_src = $(this).attr('src'); // if this is a chart if (iframe_src.indexOf('charts') !== -1) { // hide the chart $(this).hide(); // reload the src $(this).attr('src', iframe_src); // show the chart $(this).show(); } }); } // update the chart with all the textbox values function openDialogCenter(element) { element.dialog("open"); var sizeArr = getDimensions( element.parent() ); element.dialog({position:[ sizeArr[0], sizeArr[1] ] }); } function getDimensions(element) { var sizeArr = new Array(2); sizeArr[0] = $(window).width()/2 - element.width()/2; sizeArr[1] = $(window).height()/2 - element.height()/2; return sizeArr; } function updateChart(index, postUpdate, width, height, channelId, newOptionsSave) { // default width and height var width = width; var height = height; // get old src var iframe = $('#iframe' + index).attr("default_src"); if (!iframe) { iframe = $('#iframe' + index).attr('src'); } src = iframe.split('?')[0]; // if bar or column chart, a timeslice should be present or set timescale=30 if ($('#type_' + index).val() === 'bar' || $('#type_' + index).val() === 'column') { if ($('#timescale_' + index).val().length == 0 && $('#average_' + index).val().length == 0 && $('#median_' + index).val().length == 0 && $('#sum_' + index).val().length == 0) { $('#timescale_' + index).val(30); } } // add inputs to array var inputs = []; $('.chart_options' + index).each(function() { var v = $(this).val(); var id = $(this).attr('id'); var tag = id.split("_")[0]; if (v.length > 0) { inputs.push([tag, v]); } }); // create querystring var qs = ''; while (inputs.length > 0) { var p = inputs.pop(); if (p[0] == 'width') { width = parseInt(p[1]); } if (p[0] == 'height') { height = parseInt(p[1]); } // don't add type=line to querystring, it's the default value if (!(p[0] == 'type' && p[1] == 'line')) { qs += '&' + p[0] + '=' + encodeURIComponent(p[1]); } } // if querystring exists, add it to src if (qs.length > 0) { src += '?' + qs.substring(1); } // save chart options to database if (postUpdate && index > 0 && newOptionsSave) { $.update("/channels/" + channelId + "/charts/" + index, { newOptions : { options: qs } } ); } else if (postUpdate && index > 0) { $.update("/channels/" + channelId + "/charts/" + index, { options: qs } ); } // set embed code $('#embed' + index).val(''); // set new src $('#iframe' + index).attr('src', src); $('#iframe' + index).attr('width', width); $('#iframe' + index).attr('height', height); } function updateSelectValues() { selectedValue = $(this).val(); $(".mutuallyexclusive"+index).each(function () { $(this).val(""); }); $(this).val(selectedValue); } function setupChartForm(channelIndex) { return function(index, value) { if (value.length > 0) { $('#' + value.split('=')[0] + "_" + channelIndex).val(decodeURIComponent(value.split('=')[1])); } }; } function setupColumns(current_user, channel_id) { $( sortColumnSetup(current_user, channel_id) ); $( ".column" ).disableSelection(); } function createWindowsWithData (data, current_user, channel_id, colName) { for (var i in data) { //each array element has a single chart object as an associative array with the type as the key // so I need to iterate over a array with size=1 to get a string with the window type for (var type in data[i]) { var wtype = type; } if (data[i].chart_window) window = data[i].chart_window; if (data[i].plugin_window) window = data[i].plugin_window; if (data[i].portlet_window) window = data[i].portlet_window; if (window == "undefined") var window = (data[i].portlet_window) ? data[i].portlet_window : data[i].chart_window; colId = window.col; title = window.title; var content = window.html; if (data[i].chart_window) { var windowId = window.id; $("body").append("
"); } var portlet = addWindow(colName, colId, window.id, wtype, title, content); portlet.each ( decoratePortlet(current_user) ) ; portlet.find( ".ui-toggle" ).click( uiToggleClick ); portlet.find( ".ui-view" ).click( uiViewClick (channel_id) ); portlet.find( ".ui-edit" ).click( uiEditClick (channel_id) ); portlet.find( ".ui-close" ).click( uiCloseClick (channel_id) ); } } var createWindows = function (current_user, channel_id, colName) { return function(data) { createWindowsWithData(data, current_user, channel_id, colName); }; } function addWindow(colName, colId, windowId, wtype, title, content) { $("#"+colName+"_dialog"+colId).append('