Skip to content

Commit

Permalink
Merge pull request #51 from TheDMSGroup/ENG-393
Browse files Browse the repository at this point in the history
[ENG-393] Add export buttons to datatables on dashboard
  • Loading branch information
heathdutton authored Jul 12, 2018
2 parents 15a5d47 + ecc12ea commit 3cc2173
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 70 deletions.
6 changes: 6 additions & 0 deletions Assets/js/campaign-revenue.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ Mautic.loadCampaignRevenueWidget = function (params) {
],
'aaSorting': [],
'autoFill': true,
dom: '<<lBf>rtip>',
buttons: [
'excelHtml5',
'csvHtml5'
],
'footerCallback': function (row, data, start, end, display) {
// Add table footer if it doesnt exist
var container = mQuery('#campaign-revenue-table');
Expand Down Expand Up @@ -67,6 +72,7 @@ Mautic.loadCampaignRevenueWidget = function (params) {
}
} // FooterCallback
}); // datatable
mQuery('#campaign-revenue-table_wrapper .dt-buttons').css({float: "right", marginLeft: "10px"});
}); //getScriptsCachedOnce - fonteawesome css
});//getScriptsCachedOnce - datatables css
}); //getScriptsCachedOnce - datatables js
Expand Down
79 changes: 47 additions & 32 deletions Assets/js/global-revenue.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ Mautic.loadGlobalRevenueWidget = function () {
order: [[2, 'asc']],
bLengthChange: false,
lengthMenu: [[rowCount]],
dom: '<<lBf>rtip>',
buttons: [
'excelHtml5',
'csvHtml5'
],
columnDefs: [
{
render: function (data, type, row) {
Expand All @@ -47,7 +52,7 @@ Mautic.loadGlobalRevenueWidget = function () {
},
{
render: function (data, type, row) {
return data + '%';
return renderPercentage(row);
},
targets: 10
},
Expand Down Expand Up @@ -116,14 +121,14 @@ Mautic.loadGlobalRevenueWidget = function () {
}
} // FooterCallback
}); //.DataTables
mQuery('#global-revenue_wrapper .dt-buttons').css({float: "right", marginLeft: "10px"});
} //success
}); //ajax
}); //getScriptsCachedOnce - fonteawesome css
});//getScriptsCachedOnce - datatables css
}); //getScriptsCachedOnce - datatables js
});
}
}; //loadGlobalRevenueWidget

function renderPublishToggle (id, active) {
if (active == 1) {
Expand All @@ -142,6 +147,13 @@ Mautic.loadGlobalRevenueWidget = function () {
return '<a href="./campaigns/view/' + row[1] + '" class="campaign-name-link" title="' + row[2] + '">' + row[2] + '</a>';
}

function renderPercentage (row) {
if (Number(row[10]) != parseInt(Number(row[10]))){
return Number(row[10]).toFixed(2) + '%';
}
return row[10] + '%';
}

function FormatFooter (column, value, index) {
column = column.trim();
var numFormat = mQuery.fn.dataTable.render.number(',', '.', 0).display;
Expand All @@ -158,38 +170,41 @@ Mautic.loadGlobalRevenueWidget = function () {
}
return numFormat(value);
}
}; //loadGlobalRevenueWidget

// getScriptCachedOnce for faster page loads in the backend.
mQuery.getScriptCachedOnce = function (url, callback) {
if (
typeof window.getScriptCachedOnce !== 'undefined'
&& window.getScriptCachedOnce.indexOf(url) !== -1
) {
mQuery.getScriptCachedOnce = function (url, callback) {
if (
typeof window.getScriptCachedOnce !== 'undefined'
&& window.getScriptCachedOnce.indexOf(url) !== -1
) {
callback();
return mQuery(this);
}
else {
return mQuery.ajax({
url: url,
dataType: 'script',
cache: true
}).done(function () {
if (typeof window.getScriptCachedOnce === 'undefined') {
window.getScriptCachedOnce = [];
}
window.getScriptCachedOnce.push('url');
callback();
return mQuery(this);
}
else {
return mQuery.ajax({
url: url,
dataType: 'script',
cache: true
}).done(function () {
if (typeof window.getScriptCachedOnce === 'undefined') {
window.getScriptCachedOnce = [];
}
window.getScriptCachedOnce.push('url');
callback();
});
}
};
});
}
};

// getScriptCachedOnce for faster page loads in the backend.
mQuery.getCssOnce = function (url, callback) {
if (document.createStyleSheet) {
document.createStyleSheet(url);
}
else {
mQuery('head').append(mQuery('<link rel=\'stylesheet\' href=\'' + url + '\' type=\'text/css\' />'));
}
callback();
};
mQuery.getCssOnce = function (url, callback) {
if (document.createStyleSheet) {
document.createStyleSheet(url);
}
else {
mQuery('head').append(mQuery('<link rel=\'stylesheet\' href=\'' + url + '\' type=\'text/css\' />'));
}
callback();
};


89 changes: 55 additions & 34 deletions Assets/js/source-revenue.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ Mautic.loadSourceRevenueWidget = function () {
order: [[2, 'asc'], [4, 'asc']],
bLengthChange: false,
lengthMenu: [[rowCount]],
dom: '<<lBf>rtip>',
buttons: [
'excelHtml5',
'csvHtml5'
],
columnDefs: [
{
render: function (data, type, row) {
Expand Down Expand Up @@ -53,7 +58,8 @@ Mautic.loadSourceRevenueWidget = function () {
},
{
render: function (data, type, row) {
return data + '%';
//return 'foo';
return renderMarginPercentage(row);
},
targets: 12
},
Expand Down Expand Up @@ -122,53 +128,66 @@ Mautic.loadSourceRevenueWidget = function () {
console.log(e);
}
} // FooterCallback




}); //.DataTables
mQuery('#source-revenue_wrapper .dt-buttons').css({float: "right", marginLeft: "10px"});
} //success
});//ajax
}); //getScriptsCachedOnce - fonteawesome css
});//getScriptsCachedOnce - datatables css
}); //getScriptsCachedOnce - datatables js
});
}
}; //loadSourceRevenueWidget

function renderPublishToggle (id, active) {
if (active == 1) {
var icon = 'fa-toggle-on';
var status = 'published';
function renderPublishToggle (id, active) {
if (active == 1) {
var icon = 'fa-toggle-on';
var status = 'published';
}
else {
var icon = 'fa-toggle-off';
var status = 'unpublished';
}
var UpperStatus = status.charAt(0).toUpperCase() + status.substring(1);
return '<a data-toggle="ajax"><i title="' + UpperStatus + '"class="fa fa-fw fa-lg ' + icon + ' text-success has-click-event campaign-publish-icon' + id + '" data-toggle="tooltip" data-container="body" data-placement="right" data-status="' + status + '" onclick="Mautic.togglePublishStatus(event, \'.campaign-publish-icon' + id + '\', \'campaign\', ' + id + ', \'\', false);" data-original-title="' + UpperStatus + '"></i></a>';
}
else {
var icon = 'fa-toggle-off';
var status = 'unpublished';

function renderCampaignName (row) {
return '<a href="./campaigns/view/'+ row[1] +'" class="campaign-name-link" title="'+ row[2] + '">'+ row[2] + '</a>';
}
var UpperStatus = status.charAt(0).toUpperCase() + status.substring(1);
return '<a data-toggle="ajax"><i title="' + UpperStatus + '"class="fa fa-fw fa-lg ' + icon + ' text-success has-click-event campaign-publish-icon' + id + '" data-toggle="tooltip" data-container="body" data-placement="right" data-status="' + status + '" onclick="Mautic.togglePublishStatus(event, \'.campaign-publish-icon' + id + '\', \'campaign\', ' + id + ', \'\', false);" data-original-title="' + UpperStatus + '"></i></a>';
}

function renderCampaignName (row) {
return '<a href="./campaigns/view/'+ row[1] +'" class="campaign-name-link" title="'+ row[2] + '">'+ row[2] + '</a>';
}

function renderSourceName (row) {
return '<a href="./contactsource/view/'+ row[3] +'" class="campaign-name-link" title="'+ row[4] + '">'+ row[4] + '</a>';
}

function FormatFooter (column, value, index) {
column = column.trim();
var numFormat = mQuery.fn.dataTable.render.number(',', '.', 0).display;
var curFormat = mQuery.fn.dataTable.render.number(',', '.', 2, '$').display;
var curPreciseFormat = mQuery.fn.dataTable.render.number(',', '.', 4, '$').display;
if (column === 'Margin') {
return ' - ';

function renderMarginPercentage (row) {
if (Number(row[12]) != parseInt(Number(row[12]))){
return Number(row[12]).toFixed(2) + '%';
}
return row[12] + '%';
}
if (column === 'Revenue' || column === 'Cost' || column === 'GM') {
return curFormat(value);

function renderSourceName (row) {
return '<a href="./contactsource/view/'+ row[3] +'" class="campaign-name-link" title="'+ row[4] + '">'+ row[4] + '</a>';
}
if (column === 'eCPM') {
return curPreciseFormat(value);

function FormatFooter (column, value, index) {
column = column.trim();
var numFormat = mQuery.fn.dataTable.render.number(',', '.', 0).display;
var curFormat = mQuery.fn.dataTable.render.number(',', '.', 2, '$').display;
var curPreciseFormat = mQuery.fn.dataTable.render.number(',', '.', 4, '$').display;
if (column === 'Margin') {
return ' - ';
}
if (column === 'Revenue' || column === 'Cost' || column === 'GM') {
return curFormat(value);
}
if (column === 'eCPM') {
return curPreciseFormat(value);
}
return numFormat(value);
}
return numFormat(value);
}
}; //loadSourceRevenueWidget


// getScriptCachedOnce for faster page loads in the backend.
mQuery.getScriptCachedOnce = function (url, callback) {
Expand Down Expand Up @@ -205,3 +224,5 @@ mQuery.getCssOnce = function (url, callback) {
};




8 changes: 5 additions & 3 deletions Views/Widgets/revenue.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
?>

<?php
echo $view['assets']->includeScript('plugins/MauticContactLedgerBundle/Assets/js/global-revenue.js', 'loadGlobalRevenueWidget');

$params = $data['params'];
?>

Expand All @@ -29,4 +27,8 @@
<!--/ Revenue By Campaign -->
</div>
</div>
</div>
</div>

<?php
echo $view['assets']->includeScript('plugins/MauticContactLedgerBundle/Assets/js/global-revenue.js', 'loadGlobalRevenueWidget', 'loadGlobalRevenueWidget');
?>
5 changes: 4 additions & 1 deletion Views/Widgets/sourceRevenue.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/
?>
<?php
echo $view['assets']->includeScript('plugins/MauticContactLedgerBundle/Assets/js/source-revenue.js', 'loadSourceRevenueWidget');
$params = $data['params'];
?>

Expand All @@ -33,4 +32,8 @@
</div>
</div>

<?php
echo $view['assets']->includeScript('plugins/MauticContactLedgerBundle/Assets/js/source-revenue.js', 'loadSourceRevenueWidget', 'loadSourceRevenueWidget');
?>


0 comments on commit 3cc2173

Please sign in to comment.