Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function _manage_buttons( dt ) {
  2.     dt = DT.get_api( dt );
  3.  
  4.     // Name of the filename when exported (except for extension)
  5.     var export_filename = 'SASSET-Assets-' + tools.date( '%d-%M-%Y' );
  6.  
  7.     // Configure Export Buttons
  8.     new $.fn.dataTable.Buttons( dt, {
  9.         buttons: [
  10.             {
  11.                 text: '<i class="fa fa-lg fa-clipboard"></i>',
  12.                 extend: 'copy',
  13.                 className: 'btn btn-xs btn-primary p-5 m-0 width-35 assets-export-btn export-copy ttip',
  14.                 exportOptions: {
  15.                     columns: function ( idx, data, node ) {
  16.                         // Always export the 4th colum (status)
  17.                         return idx === 4 || dt.column( idx ).visible();
  18.                     },
  19.                     rows: function ( idx, data, node ) {
  20.                         // If rows are selected, export those, if not, export all
  21.                         if(assets.selected_ids( dt ).length > 0)
  22.                             return $.inArray(parseInt(data.asset_id), assets.selected_ids( dt )) !== -1;
  23.  
  24.                         return true;
  25.                     }
  26.                 }
  27.             }, {
  28.                 text: '<i class="fa fa-lg fa-file-text-o"></i>',
  29.                 extend: 'csv',
  30.                 className: 'btn btn-xs btn-primary p-5 m-0 width-35 assets-export-btn export-csv ttip',
  31.                 title: export_filename,
  32.                 extension: '.csv',
  33.                 exportOptions: {
  34.                     columns: function ( idx, data, node ) {
  35.                         // Always export the 4th colum (status)
  36.                         return idx === 4 || dt.column( idx ).visible();
  37.                     },
  38.                     rows: function ( idx, data, node ) {
  39.                         // If rows are selected, export those, if not, export all
  40.                         if(assets.selected_ids( dt ).length > 0)
  41.                             return $.inArray(parseInt(data.asset_id), assets.selected_ids( dt )) !== -1;
  42.  
  43.                         return true;
  44.                     }
  45.                 }
  46.             }, {
  47.                 text: '<i class="fa fa-lg fa-file-excel-o"></i>',
  48.                 extend: 'excel',
  49.                 className: 'btn btn-xs btn-primary p-5 m-0 width-35 assets-export-btn export-xls ttip',
  50.                 title: export_filename,
  51.                 extension: '.xls',
  52.                 exportOptions: {
  53.                     columns: function ( idx, data, node ) {
  54.                         // Always export the 4th colum (status)
  55.                         return idx === 4 || dt.column( idx ).visible();
  56.                     },
  57.                     rows: function ( idx, data, node ) {
  58.                         // If rows are selected, export those, if not, export all
  59.                         if(assets.selected_ids( dt ).length > 0)
  60.                             return $.inArray(parseInt(data.asset_id), assets.selected_ids( dt )) !== -1;
  61.  
  62.                         return true;
  63.                     }
  64.                 }
  65.             }, {
  66.                 text: '<i class="fa fa-lg fa-file-pdf-o"></i>',
  67.                 extend: 'pdf',
  68.                 className: 'btn btn-xs btn-primary p-5 m-0 width-35 assets-export-btn export-pdf ttip',
  69.                 title: export_filename,
  70.                 extension: '.pdf',
  71.                 exportOptions: {
  72.                     columns: function ( idx, data, node ) {
  73.                         // Always export the 4th colum (status)
  74.                         return idx === 4 || dt.column( idx ).visible();
  75.                     },
  76.                     rows: function ( idx, data, node ) {
  77.                         // If rows are selected, export those, if not, export all
  78.                         if(assets.selected_ids( dt ).length > 0)
  79.                             return $.inArray(parseInt(data.asset_id), assets.selected_ids( dt )) !== -1;
  80.  
  81.                         return true;
  82.                     }
  83.                 }
  84.             }
  85.         ]
  86.     } );
  87.  
  88.     // Add the Export buttons to the toolbox
  89.     dt.buttons( 0, null ).container().appendTo( '#export-assets' );
  90.  
  91.  
  92.     // Configure Print Button
  93.     new $.fn.dataTable.Buttons( dt, {
  94.         buttons: [
  95.             {
  96.                 text: '<i class="fa fa-lg fa-print"></i> Print Assets',
  97.                 autoPrint: false,
  98.                 customize: function ( win ) {
  99.                     var ci_config = app.setting( 'sasset', 'print_css' );
  100.  
  101.                     $( win.document.body )
  102.                         .addClass('asset-print-body')
  103.                         .prepend( $( '<img />' )
  104.                             .attr('src','https://sasset.io/wp-content/uploads/2015/08/sasset_logo-300x87.png')
  105.                             .addClass('asset-print-img')
  106.                     );
  107.  
  108.                     $( win.document.body )
  109.                         .find( 'table' )
  110.                         .addClass( 'compact' )
  111.                         .css( ci_config );
  112.                 },
  113.                 extend: 'print',
  114.                 className: 'btn btn-primary btn-sm m-5 width-140 assets-select-btn export-print',
  115.                 exportOptions: {
  116.                     columns: function ( idx, data, node ) {
  117.                         // Always export the 4th colum (status)
  118.                         return idx === 4 || dt.column( idx ).visible();
  119.                     },
  120.                     rows: function ( idx, data, node ) {
  121.                         // If rows are selected, export those, if not, export all
  122.                         if(assets.selected_ids( dt ).length > 0)
  123.                             return $.inArray(parseInt(data.asset_id), assets.selected_ids( dt )) !== -1;
  124.  
  125.                         return true;
  126.                     }
  127.                 }
  128.             }
  129.         ]
  130.     } );
  131.  
  132.     // Add the Print button to the toolbox
  133.     dt.buttons( 1, null ).container().appendTo( '#print-assets' );
  134.  
  135.  
  136.     // Select Buttons
  137.     new $.fn.dataTable.Buttons( dt, {
  138.         buttons: [
  139.             {
  140.                 extend: 'selectAll',
  141.                 className: 'btn btn-xs btn-primary p-5 m-0 width-70 assets-select-btn'
  142.             }, {
  143.                 extend: 'selectNone',
  144.                 className: 'btn btn-xs btn-primary p-5 m-0 width-70 assets-select-btn'
  145.             }
  146.         ]
  147.     } );
  148.  
  149.     // Add the Select buttons to the toolbox
  150.     dt.buttons( 2, null ).container().appendTo( '#select-assets' );
  151.  
  152.  
  153.     // Configure Selected Assets Buttons (delete, timeline, etc)
  154.     new $.fn.dataTable.Buttons( dt, {
  155.         buttons: [
  156.             {
  157.                 text: 'Delete Selected',
  158.                 action: function () {
  159.                     assets.delete_from_list(dt, assets.selected_ids( dt ) );
  160.                 },
  161.                 className: 'btn btn-primary btn-sm m-5 width-140 assets-select-btn toolbox-delete-selected'
  162.             }, {
  163.                 text: 'View Timeline',
  164.                 action: function () {
  165.                     console.log(assets.selected_ids( dt ));
  166.                 },
  167.                 className: 'btn btn-primary btn-sm m-5 width-140 assets-select-btn'
  168.             }
  169.         ]
  170.     } );
  171.  
  172.     // Add the selected assets buttons to the toolbox
  173.     dt.buttons( 3, null ).container().appendTo( '#selected-assets-btn-group' );
  174.  
  175.  
  176.     // Configure Select Columns
  177.     new $.fn.dataTable.Buttons( dt, {
  178.         buttons: [
  179.             {
  180.                 extend: 'collection',
  181.                 text: 'Select Columns',
  182.                 buttons: [ {
  183.                     extend: 'columnsToggle',
  184.                     columns: ':not([data-visible="false"])'
  185.                 } ],
  186.                 className: 'btn btn-primary btn-sm m-5 width-140 assets-select-btn'
  187.             }
  188.         ],
  189.         fade: true
  190.     } );
  191.  
  192.     // Add the select columns button to the toolbox
  193.     dt.buttons( 4, null ).container().appendTo( '#toolbox-column-visibility' );
  194.  
  195.     // Add the tooltips to any buttons that have icons
  196.     $('a.assets-export-btn.export-copy').attr('title', 'Export to clipboard');
  197.     $('a.assets-export-btn.export-csv' ).attr('title', 'Export to CSV');
  198.     $('a.assets-export-btn.export-xls' ).attr('title', 'Export to XLS');
  199.     $('a.assets-export-btn.export-pdf' ).attr('title', 'Export to PDF');
  200.  
  201.     template.ttip();
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement