');
// Copy back in the current page title moved to the new page
if ( putbacktitle && reportico_page_title_display == "topofallpages" ) {
reportico_jquery(thispage).prepend(putbacktitle);
}
// Copy back in the current page headers moved to the new page
if ( putbackheaders )
reportico_jquery(thispage).prepend(putbackheaders);
if ( putbackheaders )
reportico_jquery(thispage).prepend(putbackheaders);
newpage.append(reportico_jquery(removed));
// Copy back in the current page footers moved to the new page
if ( putbackfooters ) {
var footer = putbackfooters.clone();
newpage.append(footer);
}
if ( newtable ) {
if ( reportico_jquery(newtable).find("tbody tr").length > 0 ) {
reportico_jquery(newpage).append(newtable);
}
}
// Prepend the snipped page before the current but only if there are chidren that were snipped
// else we have snipped everything from the main page so delete current, this wil be then the
// last iteration through
if ( children.length > 0 ) {
reportico_jquery(thispage).before(newpage);
var datawidth = pagewidth - rightMargin - leftMargin;
var remaining = maxrowwidth - datawidth;
if ( remaining > 0 )
horizontalPageSplit(newpage, thispage, datawidth)
/*
while ( remaining > 0 ) {
contained = true;
spreadpage = newpage.clone();
newpage.find(".reportico-page:first").each(function(){
cols = reportico_jquery(this).find("tbody tr:first td").length;
var colptr = 0;
var contained = 0;
reportico_jquery(thispage).before(spreadpage);
while ( colptr < cols ) {
colwidth = reportico_jquery(this).find("tbody tr td:eq(" + colptr + ")").outerWidth();
contained = spreadpage.find(".reportico-page:first").outerWidth();
if (colptr == 0 || contained > datawidth) {
//spreadpage.find("tr td.eq(" + colptr + "),tr th.eq(" + colptr + ")").remove();
spreadpage.find("tr").find("td:eq(0),th:eq(0)").remove();
//spreadpage.find("tbody tr td:eq(" + colptr + "),thead th:eq(" + colptr + ")").remove();
}
else
break;
colptr++;
//contained += colwidth;
}
spreadcols = spreadpage.find("tbody tr td:first-child").length;
console.log("Chopped " + spreadcols)
remaining = remaining - contained;
contained = 0;
var colremoveptr = colptr;
while ( colremoveptr < cols ) {
colwidth = reportico_jquery(this).find("tbody tr td:eq(" + colptr + ")").outerWidth();
//if ( contained + colwidth < datawidth) {
//newpage.find("tbody tr td:eq(" + colptr + "),thead th:eq(" + colptr + ")").remove();
newpage.find("tr").find("td:eq(" + colptr + "),th:eq(" + colptr + ")").remove();
//}
//else
//break;
colremoveptr++;
//contained += colwidth;
}
spreadcols = spreadpage.find("tbody tr td:first-child").length;
newcols = newpage.find("tbody tr td:first-child").length;
console.log("Chopped and prefixed " + spreadcols + "/" + newcols)
//contained += colwidth
//if ( contained < datawidth ){
//newpage.find("tbody tr:first td").outerWidth();
//}
reportico_jquery(thispage).before(spreadpage);
//reportico_jquery(thispage).before(newpage);
})
contained = newpage.find(".reportico-page:first").outerWidth();
remaining = contained - datawidth;
}
*/
}
else {
if ( removed.length > 0 )
reportico_jquery(thispage).before(newpage);
reportico_jquery(thispage).remove();
}
children.unshift(child);
break;
}
else
{
reportico_jquery(child).detach(); // JQuery Method detach() removes the "child" element from DOM for the current page
long = nextlong;
}
removed.push(child);
}
if (newpage) {
pagination_page_no++;
splitPage.call(thispage); // Recursively call myself to adjust the remainder of the pages
} else {
// We are down to the last page. If anything that was not a header or footer was detached from the page we have been snipping
// then it justifies being put back
nonbody=0;
for(j = 0; j < removed.length; j++){
x = removed[j];
if ( reportico_jquery(x).hasClass("reportico-page-header-block") || reportico_jquery(x).hasClass("reportico-page-footer-block") )
nonbody++;
}
if ( removed.length > nonbody ) {
// There are report body items
reportico_jquery(thispage).append(removed);
//Split to fit horizontally the final block
var datawidth = pagewidth - rightMargin - leftMargin;
maxrowwidth = thispage.find(".reportico-page:first").width();
var remaining = maxrowwidth - datawidth;
if ( remaining > 0 )
horizontalPageSplit(thispage, thispage, datawidth)
} else {
// No report body items remove the last blank page
reportico_jquery(thispage).remove();
}
}
}
function horizontalPageSplit(newpage, thispage, datawidth) {
remaining = 1
//Freeze the set number of columns for when splitting horizontally
if ( reportico_jquery.type(reportico_page_freeze_columns) === 'undefined' )
reportico_page_freeze_columns = 0;
while ( remaining > 0 ) {
contained = true;
spreadpage = newpage.clone();
newpage.find(".reportico-page:first").each(function(){
cols = reportico_jquery(this).find("tbody tr:first td").length;
var colptr = 0;
var contained = 0;
reportico_jquery(newpage).after(spreadpage);
while ( colptr < cols ) {
colwidth = reportico_jquery(this).find("tbody tr td:eq(" + colptr + ")").outerWidth();
//contained = spreadpage.find(".reportico-page:first").outerWidth();
contained += colwidth;
if (colptr headerheight )
//headerheight = imgheight;
});
var margintop = parseInt(reportico_jquery(this).css("margin-top"));
var marginbottom = parseInt(reportico_jquery(this).css("margin-bottom"));
headerheight += margintop + marginbottom;
if ( headerheight > maxheight )
maxheight = headerheight;
});
reportico_jquery(this).css("height", maxheight + "px");
});
// Resize Custom Headers
reportico_jquery(".reportico-custom-header-block,.reportico-custom-trailer-block").each(function() {
var parenty = reportico_jquery(this).position().top;
var maxheight = 0;
var divcount = 0;
reportico_jquery(this).find("div").each(function() {
var headerheight = reportico_jquery(this).outerHeight();
reportico_jquery(this).find("img").each(function() {
var imgheight = reportico_jquery(this).prop("height");
if ( imgheight > headerheight )
headerheight = imgheight;
});
var margintop = parseInt(reportico_jquery(this).css("margin-top"));
var marginbottom = parseInt(reportico_jquery(this).css("margin-bottom"));
headerheight += margintop + marginbottom;
if ( headerheight > maxheight )
maxheight = headerheight;
divcount++;
});
if ( divcount > 0 )
reportico_jquery(this).css("height", maxheight + "px");
});
}
/*
* Where multiple data tables exist due to graphs
* resize the columns of all tables to match the first
*/
function resizeTables()
{
var tableArr = reportico_jquery('.reportico-page');
if ( tableArr.length == 0 )
return;
var tableDataRow = reportico_jquery('.reportico-row:first');
var cellWidths = new Array();
reportico_jquery(tableDataRow).each(function() {
for( var j = 0; j < reportico_jquery(this)[0].cells.length; j++){
var cell = reportico_jquery(this)[0].cells[j];
if(!cellWidths[j] || cellWidths[j] < cell.clientWidth) cellWidths[j] = cell.clientWidth;
}
});
var tablect = 0;
reportico_jquery(tableArr).each(function() {
tablect++;
if ( tablect == 1 )
return;
reportico_jquery(this).find(".reportico-row:first").each(function() {
for( var j = 0; j < reportico_jquery(this)[0].cells.length; j++){
reportico_jquery(this)[0].cells[j].style.width = cellWidths[j]+'px';
}
});
});
}
//reportico_jquery(document).on('click', '.reportico-show-criteria', function(event)
//reportico_jquery(document).on('click', '.reportico-hide-criteria', function(event)
function showCriteriaBlock()
{
// On manual paginate add class to trigger pagination
reportico_jquery(".reportico-show-criteria").hide();
reportico_jquery(".reportico-hide-criteria").show();
reportico_jquery("#criteria-block").show();
return false;
}
function hideCriteriaBlock()
{
// On manual paginate add class to trigger pagination
reportico_jquery(".reportico-hide-criteria").hide();
reportico_jquery(".reportico-show-criteria").show();
reportico_jquery("#criteria-block").hide();
return false;
};
reportico_jquery(document).on('click', '.reportico-paginate-button-link', function(event)
{
// On manual paginate add class to trigger pagination
reportico_jquery(".reportico-paginated").addClass("autopaginate");
paginate();
return false;
});
reportico_jquery(document).on('click', '.reportico-lookup-button', function(event) {
executeExpand(this);
})
reportico_jquery(document).on('click', 'a.reportico-dropdown-item, ul li.r1eportico-dropdown a, ul li ul.reportico-dropdown li a, ul.jd_menu li a, ul.jd_menu li ul li a', function(event)
{
if ( reportico_jquery.type(reportico_ajax_mode) === 'undefined' || !reportico_ajax_mode)
{
return true;
}
var url = reportico_jquery(this).prop('href');
var reportico_container = reportico_jquery(this).closest("#reportico-container");
runreport(url, this);
event.preventDefault();
return false;
});
/* Load Date Pickers */
reportico_jquery(document).ready(function()
{
setupWidgets("init");
//setupDatePickers();
setupTooltips();
setupDropMenu();
resizeHeaders();
resizeTables();
setupDynamicGrids();
//setupCriteriaItems();
setupCheckboxes();
paginate();
});
function reportico_initialise_page()
{
//setupDatePickers();
setupTooltips();
setupDropMenu();
resizeHeaders();
resizeTables();
setupDynamicGrids();
//setupCriteriaItems();
};
reportico_jquery(document).on('click', '.reportico-notice-modal-close,.reportico-notice-modal-button', function(event)
{
reportico_jquery("#reporticoModalBody").html("");
reportico_jquery('#reporticoNoticeModal').hide();
});
reportico_jquery(document).on('click', '.reportico-edit-linkSubmit,.reportico-bootstrap-modal-close,.reportico-modal-close', function(event)
{
if ( reportico_bootstrap_modal )
var loadpanel = reportico_jquery("#reporticoModal .modal-dialog .modal-content .modal-header");
else
var loadpanel = reportico_jquery("#reporticoModal .reportico-modal-dialog .reportico-modal-content .reportico-modal-header");
var expandpanel = reportico_jquery('#reportico-prepare-expand-cell');
//var expandpanel = reportico_jquery('.reportico-prepare-crit-output-options');
loadSpinner(false, true);
forms = reportico_jquery(this).closest('#reportico-container').find(".reportico-edit-link-form");
if ( forms.length == 0 ) {
forms = reportico_jquery(this).closest('#reportico-container').find(".reportico-prepare-form");
}
if ( forms.length == 0 ) {
forms = reportico_jquery(this).closest('#reportico-container').find(".reportico-form");
}
if ( reportico_jquery.type(reportico_ajax_script) === 'undefined' )
{
var ajaxaction = reportico_jquery(forms).prop("action");
}
else
{
ajaxaction = reportico_ajax_script;
}
params = forms.serialize();
params += "&" + reportico_jquery(this).prop("name") + "=1";
params += "&reportico_ajax_called=1";
params += "&execute_mode=PREPARE";
ajaxaction += getYiiAjaxURL();
params += getCSRFURLParams();
headers = getCSRFHeaders();
var cont = this;
reportico_jquery.ajax({
type: 'POST',
headers: headers,
url: ajaxaction,
data: params,
dataType: 'html',
success: function(data, status)
{
loadSpinner(false, false);
reportico_jquery(loadpanel).removeClass("modal-loading");
if ( reportico_bootstrap_modal && typeof(reportico_jquery('#reporticoModal').modal) != "undefined" )
{
reportico_jquery('#reporticoModal').modal('hide');
reportico_jquery('.modal-backdrop').remove();
reportico_jquery('#reportico-container').closest('body').removeClass('modal-open');
// Weird behaviour after moda open causes right padding to be added to body - remove it
reportico_jquery('#reportico-container').closest('body').css('padding-right', "0px");
}
else
reportico_jquery('#reporticoModal').hide();
reportico_jquery("#reporticoModalBody").html("");
criteriabodyshowing = reportico_jquery("#criteria-block").is(":visible");
fillDialog(data, cont);
if ( !criteriabodyshowing ) {
reportico_jquery("#criteria-block").hide();
reportico_jquery(".reportico-show-criteria").show();
reportico_jquery(".reportico-hide-criteria").hide();
}
},
error: function(xhr, desc, err) {
reportico_jquery("#reporticoModalBody").html("");
reportico_jquery('#reporticoModal').modal('hide');
reportico_jquery('.modal-backdrop').remove();
loadSpinner(false, false);
reportico_jquery(loadpanel).removeClass("modal-loading");
reportico_jquery(loadpanel).prop('innerHTML',"Ajax Error: " + xhr + "\nTextStatus: " + desc + "\nErrorThrown: " + err);
}
});
return false;
});
/*
** Trigger AJAX request for reportico button/link press if running in AJAX mode
** AJAX mode is in place when reportico session ("reportico_ajax_script") is set
** will generate full reportico output to replace the reportico-container tag
*/
function popupEditLink(sourceWidget) {
var expandpanel = reportico_jquery(sourceWidget).closest('#reportico-form').find('#reportico-prepare-expand-cell');
//var expandpanel = reportico_jquery(sourceWidget).closest('#reportico-form').find('.reportico-prepare-crit-output-options');
var reportico_container = reportico_jquery(sourceWidget).closest("#reportico-container");
loadSpinner(sourceWidget, true);
forms = reportico_jquery(sourceWidget).closest('.reportico-form,.reportico-prepare-save-form,form');
if ( reportico_jquery.type(reportico_ajax_script) === 'undefined' )
{
var ajaxaction = reportico_jquery(forms).prop("action");
}
else
{
ajaxaction = reportico_ajax_script;
}
reportico_jquery(".reportico-modal-title").html(reportico_jquery(sourceWidget).prop("title"));
reportico_jquery("#reporticoModalLabel").html(reportico_jquery(sourceWidget).prop("title"));
var maintainButton = reportico_jquery(sourceWidget).prop("name");
var bits = maintainButton.split("_");
var params = forms.serialize();
params += "&execute_mode=MAINTAIN&partialMaintain=" + maintainButton + "&partial_template=mini&submit_" + bits[0] + "_SHOW=1";
params += "&reportico_ajax_called=1";
ajaxaction += getYiiAjaxURL();
params += getCSRFURLParams();
headers = getCSRFHeaders();
reportico_jquery.ajax({
type: 'POST',
headers: headers,
url: ajaxaction,
data: params,
dataType: 'html',
success: function(data, status)
{
loadSpinner(sourceWidget, false);
if ( reportico_bootstrap_modal && typeof(reportico_jquery('#reporticoModal').modal) != "undefined" )
setupModals();
else
reportico_jquery("#reporticoModal").show();
reportico_jquery("#reporticoModalBody").html(data);
x = reportico_jquery(".reportico-maintain-button").prop("name");
reportico_jquery(".reportico-edit-linkSubmit").prop("id", x);
},
error: function(xhr, desc, err) {
loadSpinner(sourceWidget, false);
reportico_jquery(expandpanel).prop('innerHTML',"Ajax Error: " + xhr + "\nTextStatus: " + desc + "\nErrorThrown: " + err);
}
});
return false;
}
function saveReport(sourceWidget)
{
var expandpanel = reportico_jquery(sourceWidget).closest('#reportico-form').find('#reportico-prepare-expand-cell');
var reportico_container = reportico_jquery(sourceWidget).closest("#reportico-container");
loadSpinner(sourceWidget, true);
if ( reportico_jquery.type(reportico_ajax_script) === 'undefined' )
{
var ajaxaction = reportico_jquery(forms).prop("action");
}
else
{
ajaxaction = reportico_ajax_script;
}
filename = reportico_jquery("#reportico-prepare-save-file").prop("value");
var forms = reportico_jquery(sourceWidget).closest('.reportico-form,.reportico-prepare-save-form,form');
params = forms.serialize();
params += "&execute_mode=MAINTAIN&submit_xxx_PREPARESAVE=1&errorsInModal=1&xmlout=" + filename;
params += "&reportico_ajax_called=1";
ajaxaction += getYiiAjaxURL();
params += getCSRFURLParams();
headers = getCSRFHeaders();
reportico_jquery.ajax({
type: 'POST',
headers: headers,
url: ajaxaction,
data: params,
dataType: 'html',
success: function(data, status)
{
loadSpinner(sourceWidget, false);
//alert(data);
},
error: function(xhr, desc, err) {
loadSpinner(sourceWidget, false);
showNoticeModal(xhr.responseText);
}
});
return false;
}
/*
* For printing reports hide everything surrounding the report container
* so only the report output container is visible
*/
function hideSurroundingBlocks(block)
{
parent = block.parent();
if ( parent && parent.length > 0 ){
parent.addClass('compact-printable');
parent.siblings().addClass('non-printable');
hideSurroundingBlocks(parent)
}
}
/*reportico_jquery(document).on('click', '.reportico-admin-button, .reportico-admin-button2, .reportico-menu-item-link, .reportico-prepare-submit, .reportico-ajax-link, .reportico-ajax-link2, .reportico-link-menu2, .reportico-submit', function(event) */
reportico_jquery(document).on('click', '.reportico-menu-item-link, .reportico-submit, .reportico-ajax-link', function(event) {
// For print button hide surrounding text
hideSurroundingBlocks(reportico_jquery("#reportico-container"));
submitAjaxLink(this)
return false;
})
/*
** Trigger AJAX request for reportico button/link press if running in AJAX mode
** AJAX mode is in place when reportico session ("reportico_ajax_script") is set
** will generate full reportico output to replace the reportico-container tag
*/
/*reportico_jquery(document).on('click', '.reportico-admin-button, .reportico-admin-button2, .reportico-menu-item-link, .reportico-prepare-submit, .reportico-ajax-link, .reportico-ajax-link2, .reportico-link-menu2, .reportico-submit', function(event) */
function submitAjaxLink(sourceWidget, url = false)
{
if ( reportico_jquery(sourceWidget).hasClass("reportico-no-submit" ) )
{
return false;
}
if ( reportico_jquery(sourceWidget).parents("#reporticoModalBody").length == 1 )
{
var expandpanel = reportico_jquery(sourceWidget).closest('#reportico-form').find('#reportico-prepare-expand-cell');
//var expandpanel = reportico_jquery(sourceWidget).closest('#reportico-form').find('.reportico-prepare-crit-output-options');
if ( reportico_bootstrap_modal )
var loadpanel = reportico_jquery("#reporticoModal .modal-dialog .modal-content .modal-header");
else
var loadpanel = reportico_jquery("#reporticoModal .reportico-modal-dialog .reportico-modal-content .reportico-modal-header");
var reportico_container = reportico_jquery(sourceWidget).closest("#reportico-container");
loadSpinner(sourceWidget);
forms = reportico_jquery(sourceWidget).closest('.reportico-edit-link-form');
if ( reportico_jquery.type(reportico_ajax_script) === 'undefined' )
{
var ajaxaction = reportico_jquery(forms).prop("action");
}
else
{
ajaxaction = reportico_ajax_script;
}
params = forms.serialize();
maintainButton = reportico_jquery(sourceWidget).prop("name");
params += "&execute_mode=MAINTAIN&partial_template=mini";
params += "&" + reportico_jquery(sourceWidget).prop("name") + "=1";
params += "&reportico_ajax_called=1";
params += getFilterGroupState();
ajaxaction += getYiiAjaxURL();
params += getCSRFURLParams();
headers = getCSRFHeaders();
reportico_jquery.ajax({
type: 'POST',
headers: headers,
url: ajaxaction,
data: params,
dataType: 'html',
success: function(data, status)
{
loadSpinner(sourceWidget, false);
//reportico_jquery(loadpanel).removeClass("modal-loading");
if ( reportico_bootstrap_modal )
setupModals();
reportico_jquery("#reporticoModalBody").html(data);
x = reportico_jquery(".reportico-maintain-button").prop("name");
reportico_jquery(".reportico-edit-linkSubmit").prop("id", x);
},
error: function(xhr, desc, err) {
loadSpinner(sourceWidget, false);
//reportico_jquery(loadpanel).removeClass("modal-loading");
reportico_jquery(expandpanel).prop('innerHTML',"Ajax Error: " + xhr + "\nTextStatus: " + desc + "\nErrorThrown: " + err);
}
});
return false;
}
if ( reportico_jquery(sourceWidget).parent().hasClass("reportico-print-button" ) )
{
//var data = reportico_jquery(sourceWidget).closest("#reportico-container").html();
//html_print(data);
window.print();
return false;
}
if ( reportico_jquery.type(reportico_ajax_mode) === 'undefined' || !reportico_ajax_mode)
{
return true;
}
var expandpanel = reportico_jquery(sourceWidget).closest('#reportico-form').find('#reportico-prepare-expand-cell');
var expandpanel = reportico_jquery(sourceWidget).closest('#reportico-form').find('.reportico-prepare-crit-output-options');
var reportico_container = reportico_jquery(sourceWidget).closest("#reportico-container");
if ( !url && reportico_jquery(sourceWidget).prop("href") )
url = reportico_jquery(sourceWidget).prop("href");
if ( !url )
{
loadSpinner(sourceWidget, true);
forms = reportico_jquery(sourceWidget).closest('.reportico-form,form');
if ( reportico_jquery.type(reportico_ajax_script) === 'undefined' )
{
var ajaxaction = reportico_jquery(forms).prop("action");
}
else
{
ajaxaction = reportico_ajax_script;
}
params = forms.serialize();
params += "&" + reportico_jquery(sourceWidget).prop("name") + "=1";
params += "&reportico_ajax_called=1";
ajaxaction += getYiiAjaxURL();
params += getCSRFURLParams();
headers = getCSRFHeaders();
params += getFilterGroupState();
csvpdfoutput = false;
if ( reportico_jquery(sourceWidget).prop("name") != "submit_design_mode" )
reportico_jquery(reportico_container).find("input:radio").each(function() {
d = 0;
nm = reportico_jquery(sourceWidget).prop("value");
chk = reportico_jquery(sourceWidget).prop("checked");
if ( chk && ( nm == "PDF" || nm == "CSV" ) )
csvpdfoutput = true;
});
if ( csvpdfoutput )
{
if (typeof reportico_pdf_delivery_mode == 'undefined'
|| !reportico_pdf_delivery_mode || reportico_pdf_delivery_mode != "DOWNLOAD_SAME_WINDOW"
)
{
loadSpinner(sourceWidget, false);
var windowSizeArray = [ "width=200,height=200",
"width=300,height=400,scrollbars=yes" ];
var url = ajaxaction +"?" + params;
var windowName = "popUp";//reportico_jquery(sourceWidget).prop("name");
var windowSize = windowSizeArray[reportico_jquery(sourceWidget).prop("rel")];
window.open(url, windowName, "width=400,height=400").focus();
loadSpinner(sourceWidget, false);
window.focus();
}
else
{
loadSpinner(sourceWidget, false);
var buttonName = reportico_jquery(sourceWidget).prop("name");
var formparams = forms.serializeObject();
formparams['reportico_ajax_called'] = '1';
formparams[buttonName] = '1';
// Download pdf/csv from within current window
ajaxFileDownload(ajaxaction, formparams, expandpanel, sourceWidget);
}
return false;
}
var cont = sourceWidget;
reportico_jquery.ajax({
type: 'POST',
headers: headers,
url: ajaxaction,
data: params,
dataType: 'html',
success: function(data, status)
{
loadSpinner(sourceWidget, false);
fillDialog(data, reportico_container);
},
error: function(xhr, desc, err) {
loadSpinner(sourceWidget, false);
reportico_jquery(expandpanel).prop('innerHTML',"Ajax Error: " + xhr + "\nTextStatus: " + desc + "\nErrorThrown: " + err);
}
});
return false;
}
else
{
runreport(url, sourceWidget);
}
return false;
}
/*
* Use ajax to return pdf or csv output and download to file.
* For pdf, output is received in base64.
*/
function ajaxFileDownload(url, data, expandpanel, sourceWidget) {
ajaxextra = getYiiAjaxURL();
if ( ajaxextra != "" ) {
url += ajaxextra
url += "&reportico_padding=1";
}
else
url += "?reportico_padding=1";
url += getCSRFURLParams();
headers = getCSRFHeaders();
reportico_jquery.ajax({
type: 'POST',
headers: headers,
url: url,
data: data,
dataType: 'html',
success: function(data, status, request) {
loadSpinner(sourceWidget, false);
// PDF and CSV files are received in base64
var contenttype = request.getResponseHeader('Content-Type');
if ( contenttype == "application/pdf" )
{
var saveto = request.getResponseHeader('Content-Disposition');
saveto = saveto.replace(/attachment;filename=/,"");
objurl = "data:application/pdf;base64," + data;
download(objurl, saveto, "application/pdf");
}
if ( contenttype == "application/octet-stream" )
{
var saveto = request.getResponseHeader('Content-Disposition');
saveto = saveto.replace(/attachment;filename=/,"");
objurl = "data:application/octet-stream;base64," + data;
download(objurl, saveto, "application/pdf");
}
},
error: function(xhr, desc, err) {
loadSpinner(sourceWidget, false);
try {
// a try/catch is recommended as the error handler
// could occur in many events and there might not be
// a JSON response from the server
var errstatus = reportico_jquery.parseJSON(xhr.responseText);
var msg = errstatus.errmsg;
//reportico_jquery(expandpanel).prop('innerHTML', msg);
showNoticeModal(msg);
} catch(e) {
showNoticeModal(xhr.responseText);
}
}
});
}
//general serializeObject function - e.g. turn a form's fields into an object
reportico_jquery.fn.serializeObject = function() {
var arrayData, objectData;
arrayData = this.serializeArray();
objectData = {};
reportico_jquery.each(arrayData, function() {
var value;
if (this.value != null) {
value = this.value;
} else {
value = '';
}
if (objectData[this.name] != null) {
if (!objectData[this.name].push) {
objectData[this.name] = [objectData[this.name]];
}
objectData[this.name].push(value);
} else {
objectData[this.name] = value;
}
});
return objectData;
};
// ---------------------------------
/*
** Called when used presses ok in expand mode to
** refresh middle prepare mode section with non expand mode
** text
*/
reportico_jquery(document).on('click', '#returnFromExpand', function() {
var critform = reportico_jquery(this).closest('#reportico-form');
var expandpanel = reportico_jquery(this).closest('#reportico-form').find('#reportico-prepare-expand-cell');
var expandpanel = reportico_jquery(this).closest('#reportico-form').find('.reportico-prepare-crit-output-options');
loadSpinner(sourceWidget, true);
var params = reportico_jquery(critform).serialize();
params += "&execute_mode=PREPARE";
params += "&partial_template=critbody";
params += "&" + reportico_jquery(this).prop("name") + "=1";
params += getFilterGroupState();
ajaxaction += getYiiAjaxURL();
params += getCSRFURLParams();
headers = getCSRFHeaders();
forms = reportico_jquery(this).closest('.reportico-form,form');
ajaxaction = reportico_ajax_script;
fillPoint = reportico_jquery(this).closest('#reportico-form').find('#criteria-block');
reportico_jquery.ajax({
type: 'POST',
headers: headers,
url: ajaxaction,
data: params,
dataType: 'html',
success: function(data, status) {
loadSpinner(sourceWidget, false);
reportico_jquery(fillPoint).html(data);
setupWidgets();
//setupDatePickers();
setupTooltips();
setupDropMenu();
//setupCriteriaItems();
setupCheckboxes();
},
error: function(xhr, desc, err) {
loadSpinner(sourceWidget, false);
reportico_jquery(fillPoint).prop('innerHTML',"Ajax Error: " + xhr + "\nTextStatus: " + desc + "\nErrorThrown: " + err);
}
});
return false;
});
function executeExpand(sourceWidget) {
forms = reportico_jquery(sourceWidget).closest('.reportico-form,form');
var ajaxaction = reportico_jquery(forms).prop("action");
var critform = reportico_jquery(sourceWidget).closest('#reportico-form');
ajaxaction = reportico_ajax_script;
var params = reportico_jquery(critform).serialize();
params += "&execute_mode=PREPARE";
params += "&partial_template=expand";
params += "&" + reportico_jquery(sourceWidget).prop("name") + "=1";
params += getFilterGroupState();
var fillPoint = reportico_jquery(sourceWidget).closest('#reportico-form').find('#reportico-prepare-expand-cell');
loadSpinner(sourceWidget, true);
ajaxaction += getYiiAjaxURL();
params += getCSRFURLParams();
headers = getCSRFHeaders();
params += "&reportico_ajax_called=1";
reportico_jquery.ajax({
type: 'POST',
headers: headers,
url: ajaxaction,
data: params,
dataType: 'html',
success: function(data, status) {
loadSpinner(sourceWidget, false);
reportico_jquery(fillPoint).html(data);
setupWidgets();
//setupDatePickers();
setupTooltips();
setupDropMenu();
//setupCriteriaItems();
setupCheckboxes();
},
error: function(xhr, desc, err) {
loadSpinner(sourceWidget, false);
reportico_jquery(fillPoint).prop('innerHTML',"Ajax Error: " + xhr + "\nTextStatus: " + desc + "\nErrorThrown: " + err);
}
});
return false;
}
function executeReport(sourceWidget, format ) {
var reportico_container = reportico_jquery(sourceWidget).closest("#reportico-container");
var expandpanel = reportico_jquery(sourceWidget).closest('#reportico-form').find('#reportico-prepare-expand-cell');
//var expandpanel = reportico_jquery(sourceWidget).closest('#reportico-form').find('.reportico-prepare-crit-output-options');
var critform = reportico_jquery(sourceWidget).closest('#reportico-form');
loadSpinner(sourceWidget, true);
params = reportico_jquery(critform).serialize();
params += "&execute_mode=EXECUTE";
params += "&" + reportico_jquery(sourceWidget).prop("name") + "=1";
params += getCSRFURLParams();
headers = getCSRFHeaders();
forms = reportico_jquery(sourceWidget).closest('.reportico-form,form');
if ( jQuery.type(reportico_ajax_script) === 'undefined' || !reportico_ajax_script )
{
var ajaxaction = reportico_jquery(forms).prop("action");
}
else
{
ajaxaction = reportico_ajax_script;
}
var csvpdfoutput = false;
if ( format == "pdf" || format == "csv" )
csvpdfoutput = true;
if ( csvpdfoutput )
{
if (typeof reportico_pdf_delivery_mode == 'undefined'
|| !reportico_pdf_delivery_mode || reportico_pdf_delivery_mode != "DOWNLOAD_SAME_WINDOW"
)
{
var windowSizeArray = [ "width=200,height=200",
"width=300,height=400,scrollbars=yes" ];
if ( format == "pdf" )
params += "&target_format=PDF";
else
params += "&target_format=CSV";
var url = ajaxaction +"?" + params;
var windowName = "popUp";//reportico_jquery(sourceWidget).prop("name");
var windowSize = windowSizeArray[reportico_jquery(sourceWidget).prop("rel")];
window.open(url, windowName, "width=400,height=400").focus();
loadSpinner(sourceWidget, false);
window.focus();
}
else
{
// Download pdf/csv from within current window
var buttonName = reportico_jquery(sourceWidget).prop("name");
var formparams = reportico_jquery(critform).serializeObject();
if ( format == "pdf" )
formparams["target_format"] = "PDF";
else
formparams["target_format"] = "CSV";
formparams['execute_mode'] = 'EXECUTE';
formparams[buttonName] = '1';
formparams['reportico_ajax_called'] = '1';
ajaxFileDownload(ajaxaction, formparams, expandpanel, sourceWidget);
}
return false;
}
if ( format == "html-new-window" )
params += "&printable_html=1&new_reportico_window=1";
else
params += "&reportico_ajax_called=1";
ajaxaction += getYiiAjaxURL();
params += getCSRFURLParams();
headers = getCSRFHeaders();
var cont = sourceWidget;
reportico_jquery.ajax({
type: 'POST',
headers: headers,
url: ajaxaction,
data: params,
dataType: 'html',
success: function(data, status) {
loadSpinner(sourceWidget, false);
if ( format == "html-new-window" )
{
html_print(reportico_report_title, data);
}
else
fillReportOutputArea(data);
},
error: function(xhr, desc, err) {
loadSpinner(sourceWidget, false);
try {
// a try/catch is recommended as the error handler
// could occur in many events and there might not be
// a JSON response from the server
var errstatus = reportico_jquery.parseJSON(xhr.responseText);
var msg = errstatus.errmsg;
//reportico_jquery(expandpanel).prop('innerHTML', msg);
showNoticeModal(msg);
} catch(e) {
showNoticeModal(xhr.responseText);
}
}
});
return false;
}
/*
* Shows modal window containing the passed text
*/
function showNoticeModal(content)
{
reportico_jquery("#reporticoNoticeModalBody").html("");
if ( reportico_bootstrap_modal )
{
reportico_jquery('#reporticoNoticeModal').modal({});
}
else
reportico_jquery("#reporticoNoticeModal").show();
reportico_jquery("#reporticoNoticeModalBody").html(content);
}
/*
* Shows modal window containing the passed text from within a child iframe
*/
function showParentNoticeModal(content)
{
reportico_jquery("#reporticoNoticeModalBody",window.parent.document).html("");
if ( reportico_bootstrap_modal )
{
reportico_jquery('#reporticoNoticeModal',window.parent.document).modal({});
}
else
reportico_jquery("#reporticoNoticeModal",window.parent.document).show();
reportico_jquery("#reporticoNoticeModalBody",window.parent.document).html(content);
}
/*
** Runs an AJAX reportico request from a link
*/
function runreport(url, container)
{
params = "";
params += getCSRFURLParams();
headers = getCSRFHeaders();
url += "&reportico_template=";
url += "&reportico_ajax_called=1";
sourceWidget = container;
loadSpinner(sourceWidget, true);
reportico_jquery.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
headers: headers,
data: params,
url: url,
dataType: "html",
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert ("Ajax Error: " + XMLHttpRequest.responseText + "\nTextStatus: " + textStatus + "\nErrorThrown: " + errorThrown);
},
success: function(data, status) {
loadSpinner(sourceWidget, false);
fillDialog(data,container);
}
});
}
function fillReportOutputArea(results) {
reportico_jquery(".reportico-show-criteria").show();
reportico_jquery(".reportico-hide-criteria").hide();
reportico_jquery("#criteria-block").hide();
reportico_jquery("#reportico-report-output").html(results);
reportico_jquery(".reportico-back-button").hide();
resizeTables();
resizeHeaders();
setupDynamicGrids();
paginate();
}
function fillDialog(results, cont) {
//x = reportico_jquery(cont).closest("#reportico-container");
reportico_jquery(cont).closest("#reportico-container").replaceWith(results);
setupWidgets();
//setupDatePickers();
setupTooltips();
setupDropMenu();
setupDynamicGrids();
resizeHeaders();
//setupCriteriaItems();
setupCheckboxes();
resizeTables();
paginate();
}
var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;
/*
** Shows and hides a block of design items fields
*/
function toggleCriteria(id) {
if ( reportico_jquery(".displayGroup" + id ).css("display") == "none" )
{
reportico_jquery(".displayGroup" + id ).show();
reportico_jquery("#reportico-toggleCriteria" + id ).html("-");
}
else
{
reportico_jquery("#reportico-toggleCriteria" + id ).html("+");
reportico_jquery(".displayGroup" + id ).hide();
}
}
/*
** Shows and hides a block of design items fields
*/
function toggleLine(id) {
var a = this;
var nm = a.id;
var togbut = document.getElementById(id);
var ele = document.getElementById("toggleText");
var elems = document.getElementsByTagName('*'),i;
for (var i in elems)
{
if ( ie7 )
{
if((" "+elems[i].className+" ").indexOf(" "+id+" ") > -1)
{
if(elems[i].style.display == "inline") {
elems[i].style.display = "none";
togbut.innerHTML = "+";
}
else {
togbut.innerHTML = "-";
elems[i].style.display = "";
elems[i].style.display = "inline";
}
}
}
else
{
if((" "+elems[i].className+" ").indexOf(" "+id+" ") > -1)
{
if(elems[i].style.display == "table-row") {
elems[i].style.display = "none";
togbut.innerHTML = "+";
}
else {
togbut.innerHTML = "-";
elems[i].style.display = "";
elems[i].style.display = "table-row";
}
}
}
}
}
reporticohtmlwindow = null;
function html_div_print(data)
{
var reporticohtmlwindow = window.open('oooo', reportico_report_title, 'height=600,width=800');
reporticohtmlwindow.document.write('' + reportico_report_title + '');
reporticohtmlwindow.document.write('');
reporticohtmlwindow.document.write('');
reporticohtmlwindow.document.write(data);
reporticohtmlwindow.document.write('');
reporticohtmlwindow.print();
reporticohtmlwindow.close();
return true;
}
function html_print(title, data)
{
if (navigator.userAgent.indexOf('Chrome/') > 0) {
if (reporticohtmlwindow) {
reporticohtmlwindow.close();
reporticohtmlwindow = null;
}
}
reporticohtmlwindow = window.open('', "reportico_print", 'location=no,scrollbars=yes,status=no,height=600,width=800');
d = reporticohtmlwindow.document.open("text/html","replace");
reporticohtmlwindow.document.write(data);
reporticohtmlwindow.document.close();
setTimeout(html_print_fix,200);
reporticohtmlwindow.focus();
reporticohtmlwindow.focus();
return true;
}
function html_print_fix()
{
if(!reporticohtmlwindow.resizeOutputTables)
{
setTimeout(html_print_fix,1000);
}
else
{
reporticohtmlwindow.resizeOutputTables(reporticohtmlwindow);
}
}
// For laravel HTTP headers need to include a X-CSRF-TOKEN field to place the CSRF-TOKEN
function getCSRFHeaders() {
headers = false;
if (typeof reportico_csrf_token != 'undefined' && reportico_ajax_mode == "laravel" ) {
headers = { 'X-CSRF-TOKEN': reportico_csrf_token };
}
if (typeof reportico_csrf_token != 'undefined' && reportico_ajax_mode == "october" ) {
headers = { 'X-CSRF-TOKEN': reportico_csrf_token, 'X-OCTOBER-REQUEST-HANDLER': ajax_event_handler, 'X-OCTOBER-REQUEST-PARTIALS':'' };
}
return headers;
}
// For Yii with nonclean URLs add the reportico ajax call as a separate URP Param
// For Yii with clean URLS the ajax call is implied in the main url
function getCSRFURLParams() {
params = "";
if (typeof reportico_ajax_mode === 'undefined' || !reportico_ajax_mode)
return params;
if (typeof reportico_csrf_token != 'undefined'
&& ( reportico_ajax_mode == "yii-ugly-url" || reportico_ajax_mode == "yii-pretty-url" ) ) {
params = "&YII_CSRF_TOKEN=" + reportico_csrf_token;
}
if ( reportico_ajax_mode == "joomla" ) {
params += '&option=com_reportico';
params += '&format=raw';
params += '&' + reportico_csrf_token + "=1";
}
return params;
}
function showSpinner(widget, show = true){
if ( widget && reportico_jquery(widget).is("button")) {
if ( show ) {
reportico_jquery(widget).prop("disabled", true);
reportico_jquery(widget).append(
""
)
} else {
reportico_jquery(widget).prop("disabled", false);
reportico_jquery("#reportico-inline-spinner").remove();
}
} else {
if (show) {
reportico_jquery("#reportico-full-page-spinner").html(
"
Loading...
"
)
reportico_jquery("#reportico-spinner-overlay").show();
}
else {
reportico_jquery("#reportico-full-page-spinner").html("");
reportico_jquery("#reportico-spinner-overlay").hide();
}
}
}
function loadSpinner(widget, show = true){
if (typeof showSpinner === "function") {
// safe to use the function
showSpinner(widget, show)
}
}
// For Yii with nonclean URLs add the reportico ajax call as a separate URP Param
// For Yii with clean URLS the ajax call is implied in the main url
function getYiiAjaxURL() {
ajaxaction = "";
if (typeof reportico_ajax_mode === 'undefined' || !reportico_ajax_mode)
return ajaxaction;
if ( reportico_ajax_mode == "yii-ugly-url" )
ajaxaction = "?r=reportico/reportico/ajax";
return ajaxaction;
}