Skip to content

Commit

Permalink
Adding AJAX call and handler update. Need to generate and output the …
Browse files Browse the repository at this point in the history
…CSV.
  • Loading branch information
ideadude committed Sep 18, 2024
1 parent 6a053d3 commit 1430ef8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
23 changes: 19 additions & 4 deletions assets/js/llms-admin-tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
self.export( $table, $( this ) );
} );

// The export button might be in the tablenav below the table.
$table.parent().find( '.tablenav button[name="llms-table-export"]' ).on( 'click', function( e ) {
e.preventDefault();
self.export( $table, $( this ) );
} );

$table.on( 'click', 'a.llms-sortable', function( e ) {
e.preventDefault();
self.change_order( $table, $( this ) );
Expand Down Expand Up @@ -141,20 +147,29 @@
this.export = function( $table, $btn, filename ) {

var self = this,
$msg = $table.find( '.llms-table-export .llms-table-export-msg' ),
$progress = $table.find( '.llms-table-export .llms-table-progress' );
$msg = $table.parent().find( '.llms-table-export .llms-table-export-msg' ),
$progress = $table.parent().find( '.llms-table-export .llms-table-progress' );

function activate_button() {
LLMS.Spinner.stop( $btn, 'small' );
$btn.removeAttr( 'disabled' );
}

// Figure out if the data-handler and args are on the table or button.
if ( ! $table.attr( 'data-handler' ) ) {
$data_handler = $btn.attr( 'data-handler' );
$data_args = $btn.attr( 'data-args' );
} else {
$data_handler = $table.attr( 'data-handler' );
$data_args = $table.attr( 'data-args' );
}

LLMS.Ajax.call( {
data: $.extend( {
action: 'export_admin_table',
handler: $table.attr( 'data-handler' ),
handler: $data_handler,
filename: filename,
}, JSON.parse( $table.attr( 'data-args' ) ) ),
}, JSON.parse( $data_args ) ),
beforeSend: function() {

if ( ! $btn.attr( 'disabled' ) ) {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/llms-admin-tables.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,27 @@ public function add_csv_export_button( $which ) {
}
?>
<div class="llms-table-export">
<button class="llms-button-primary small" name="llms-table-export">
<button class="llms-button-primary small" name="llms-table-export" type="button" data-handler="Orders" data-args="{}">
<span class="dashicons dashicons-download"></span> <?php _e( 'Export', 'lifterlms' ); ?>
</button>
<?php //echo $this->get_progress_bar_html( 0 ); ?>
<em><small class="llms-table-export-msg"></small></em>
</div>
<?php
}

/**
* Export orders CSV.
*/
public static function export( $request = null ) {
// Get the data.

// Format it.

// Output it.

return;
}
}

return new LLMS_Admin_Post_Table_Orders();
6 changes: 5 additions & 1 deletion includes/class.llms.ajax.handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,15 @@ protected static function get_admin_table_instance( $handler ) {
* @return array
*/
public static function export_admin_table( $request ) {

if ( ! current_user_can( 'view_lifterlms_reports' ) || empty( $request['handler'] ) ) {
return false;
}

// Orders export has a special handler.
if ( ! empty( $request['handler'] ) && 'Orders' === $request['handler'] ) {
return LLMS_Admin_Post_Table_Orders::export( $request );
}

$table = self::get_admin_table_instance( $request['handler'] );
if ( ! $table ) {
return false;
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1430ef8

Please sign in to comment.