Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function _manage_buttons( dt ) {
- dt = DT.get_api( dt );
- // Name of the filename when exported (except for extension)
- var export_filename = 'SASSET-Assets-' + tools.date( '%d-%M-%Y' );
- // Configure Export Buttons
- new $.fn.dataTable.Buttons( dt, {
- buttons: [
- {
- text: '<i class="fa fa-lg fa-clipboard"></i>',
- extend: 'copy',
- className: 'btn btn-xs btn-primary p-5 m-0 width-35 assets-export-btn export-copy ttip',
- exportOptions: {
- columns: function ( idx, data, node ) {
- // Always export the 4th colum (status)
- return idx === 4 || dt.column( idx ).visible();
- },
- rows: function ( idx, data, node ) {
- // If rows are selected, export those, if not, export all
- if(assets.selected_ids( dt ).length > 0)
- return $.inArray(parseInt(data.asset_id), assets.selected_ids( dt )) !== -1;
- return true;
- }
- }
- }, {
- text: '<i class="fa fa-lg fa-file-text-o"></i>',
- extend: 'csv',
- className: 'btn btn-xs btn-primary p-5 m-0 width-35 assets-export-btn export-csv ttip',
- title: export_filename,
- extension: '.csv',
- exportOptions: {
- columns: function ( idx, data, node ) {
- // Always export the 4th colum (status)
- return idx === 4 || dt.column( idx ).visible();
- },
- rows: function ( idx, data, node ) {
- // If rows are selected, export those, if not, export all
- if(assets.selected_ids( dt ).length > 0)
- return $.inArray(parseInt(data.asset_id), assets.selected_ids( dt )) !== -1;
- return true;
- }
- }
- }, {
- text: '<i class="fa fa-lg fa-file-excel-o"></i>',
- extend: 'excel',
- className: 'btn btn-xs btn-primary p-5 m-0 width-35 assets-export-btn export-xls ttip',
- title: export_filename,
- extension: '.xls',
- exportOptions: {
- columns: function ( idx, data, node ) {
- // Always export the 4th colum (status)
- return idx === 4 || dt.column( idx ).visible();
- },
- rows: function ( idx, data, node ) {
- // If rows are selected, export those, if not, export all
- if(assets.selected_ids( dt ).length > 0)
- return $.inArray(parseInt(data.asset_id), assets.selected_ids( dt )) !== -1;
- return true;
- }
- }
- }, {
- text: '<i class="fa fa-lg fa-file-pdf-o"></i>',
- extend: 'pdf',
- className: 'btn btn-xs btn-primary p-5 m-0 width-35 assets-export-btn export-pdf ttip',
- title: export_filename,
- extension: '.pdf',
- exportOptions: {
- columns: function ( idx, data, node ) {
- // Always export the 4th colum (status)
- return idx === 4 || dt.column( idx ).visible();
- },
- rows: function ( idx, data, node ) {
- // If rows are selected, export those, if not, export all
- if(assets.selected_ids( dt ).length > 0)
- return $.inArray(parseInt(data.asset_id), assets.selected_ids( dt )) !== -1;
- return true;
- }
- }
- }
- ]
- } );
- // Add the Export buttons to the toolbox
- dt.buttons( 0, null ).container().appendTo( '#export-assets' );
- // Configure Print Button
- new $.fn.dataTable.Buttons( dt, {
- buttons: [
- {
- text: '<i class="fa fa-lg fa-print"></i> Print Assets',
- autoPrint: false,
- customize: function ( win ) {
- var ci_config = app.setting( 'sasset', 'print_css' );
- $( win.document.body )
- .addClass('asset-print-body')
- .prepend( $( '<img />' )
- .attr('src','https://sasset.io/wp-content/uploads/2015/08/sasset_logo-300x87.png')
- .addClass('asset-print-img')
- );
- $( win.document.body )
- .find( 'table' )
- .addClass( 'compact' )
- .css( ci_config );
- },
- extend: 'print',
- className: 'btn btn-primary btn-sm m-5 width-140 assets-select-btn export-print',
- exportOptions: {
- columns: function ( idx, data, node ) {
- // Always export the 4th colum (status)
- return idx === 4 || dt.column( idx ).visible();
- },
- rows: function ( idx, data, node ) {
- // If rows are selected, export those, if not, export all
- if(assets.selected_ids( dt ).length > 0)
- return $.inArray(parseInt(data.asset_id), assets.selected_ids( dt )) !== -1;
- return true;
- }
- }
- }
- ]
- } );
- // Add the Print button to the toolbox
- dt.buttons( 1, null ).container().appendTo( '#print-assets' );
- // Select Buttons
- new $.fn.dataTable.Buttons( dt, {
- buttons: [
- {
- extend: 'selectAll',
- className: 'btn btn-xs btn-primary p-5 m-0 width-70 assets-select-btn'
- }, {
- extend: 'selectNone',
- className: 'btn btn-xs btn-primary p-5 m-0 width-70 assets-select-btn'
- }
- ]
- } );
- // Add the Select buttons to the toolbox
- dt.buttons( 2, null ).container().appendTo( '#select-assets' );
- // Configure Selected Assets Buttons (delete, timeline, etc)
- new $.fn.dataTable.Buttons( dt, {
- buttons: [
- {
- text: 'Delete Selected',
- action: function () {
- assets.delete_from_list(dt, assets.selected_ids( dt ) );
- },
- className: 'btn btn-primary btn-sm m-5 width-140 assets-select-btn toolbox-delete-selected'
- }, {
- text: 'View Timeline',
- action: function () {
- console.log(assets.selected_ids( dt ));
- },
- className: 'btn btn-primary btn-sm m-5 width-140 assets-select-btn'
- }
- ]
- } );
- // Add the selected assets buttons to the toolbox
- dt.buttons( 3, null ).container().appendTo( '#selected-assets-btn-group' );
- // Configure Select Columns
- new $.fn.dataTable.Buttons( dt, {
- buttons: [
- {
- extend: 'collection',
- text: 'Select Columns',
- buttons: [ {
- extend: 'columnsToggle',
- columns: ':not([data-visible="false"])'
- } ],
- className: 'btn btn-primary btn-sm m-5 width-140 assets-select-btn'
- }
- ],
- fade: true
- } );
- // Add the select columns button to the toolbox
- dt.buttons( 4, null ).container().appendTo( '#toolbox-column-visibility' );
- // Add the tooltips to any buttons that have icons
- $('a.assets-export-btn.export-copy').attr('title', 'Export to clipboard');
- $('a.assets-export-btn.export-csv' ).attr('title', 'Export to CSV');
- $('a.assets-export-btn.export-xls' ).attr('title', 'Export to XLS');
- $('a.assets-export-btn.export-pdf' ).attr('title', 'Export to PDF');
- template.ttip();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement