Skip to content

Commit

Permalink
refactor(tools): add donations export functionality impress-org#2875
Browse files Browse the repository at this point in the history
  • Loading branch information
raftaar1191 committed Mar 30, 2018
1 parent 52a9789 commit 6fc520a
Show file tree
Hide file tree
Showing 8 changed files with 1,339 additions and 11 deletions.
123 changes: 123 additions & 0 deletions assets/src/js/admin/admin-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,127 @@ jQuery(document).ready(function ($) {
}
})
});

/**
* Ajax call to get donation fields.
*/
$( '.give-export_donations #give-export_donations-form #give_form_for_csv_export' ).chosen().change( function () {

$( '.give-export-donations-hide' ).addClass( 'give-hidden' );

var give_form_id;

// Check for form ID.
if ( ! (
give_form_id = $( this ).val()
) ) {
return false;

}

// Ajax.
$.ajax( {
type: 'POST',
url: ajaxurl,
data: {
form_id: give_form_id,
action: 'give_export_donations_get_custom_fields'
},
success: function ( response ) {

if ( response ) {
output_csv_toolbox_fields( response );

} else {
alert( 'An AJAX error occurred.' );
}
}
} );
} );


/**
* Outputs the custom field checkboxes.
*
* @param response
*/
function output_csv_toolbox_fields( response ) {

/**
* FFM Fields
*/
var ffm_fields = (
typeof response.ffm_fields !== 'undefined'
) ? response.ffm_fields : '';
var ffm_field_list = $( '.give-export-donations-ffm ul' );

if ( ffm_fields ) {

ffm_field_list.closest( 'tr' ).removeClass( 'give-hidden' );

// Loop through FFM fields & output
$( ffm_fields ).each( function ( index, value ) {

// Repeater sections.
var repeater_sections = (
typeof value.repeaters !== 'undefined'
) ? value.repeaters : '';

if ( repeater_sections ) {

var parent_title = '';
// Repeater section field.
$( repeater_sections ).each( function ( index, value ) {
if ( parent_title !== value.parent_title ) {
ffm_field_list.append( '<li class="repeater-section-title" data-parent-meta="' + value.parent_meta + '"><label for="give-csv-toolkit-ffm-field-' + value.parent_meta + '"><input type="checkbox" name="give_csv_toolbox_export_parent[' + value.parent_meta + ']" id="give-csv-toolkit-ffm-field-' + value.parent_meta + '">' + value.parent_title + '</label></li>' );
}
parent_title = value.parent_title;
ffm_field_list.append( '<li class="repeater-section repeater-section-' + value.parent_meta + '"><label for="give-csv-toolkit-ffm-field-' + value.subkey + '"><input type="checkbox" name="give_csv_toolbox_export_option[' + value.subkey + ']" id="give-csv-toolkit-ffm-field-' + value.subkey + '">' + value.label + '</label></li>' );
} );
}
// Repeater sections.
var single_repeaters = (
typeof value.single !== 'undefined'
) ? value.single : '';

if ( single_repeaters ) {
// Repeater section field.
$( single_repeaters ).each( function ( index, value ) {
ffm_field_list.append( '<li><label for="give-csv-toolkit-ffm-field-' + value.subkey + '"><input type="checkbox" name="give_csv_toolbox_export_option[' + value.metakey + ']" id="give-csv-toolkit-ffm-field-' + value.subkey + '">' + value.label + '</label> </li>' );
} );
}
} );

}

/**
* Standard Fields
*/
var standard_fields = (
typeof response.standard_fields !== 'undefined'
) ? response.standard_fields : '';
var standard_field_list = $( '.give-export-donations-standard-fields ul' );
if ( standard_fields.length > 0 ) {
standard_field_list.closest( 'tr' ).removeClass( 'give-hidden' );
// Loop through STANDARD fields & output
$( standard_fields ).each( function ( index, value ) {
standard_field_list.append( '<li><label for="give-csv-toolkit-standard-field-' + value + '"><input type="checkbox" name="give_csv_toolbox_export_option[' + value + ']" id="give-csv-toolkit-standard-field-' + value + '">' + value + '</label> </li>' );
} );
}

/**
* Hidden Fields
*/
var hidden_fields = response.hidden_fields ? response.hidden_fields : '';
var hidden_field_list = $( '.give-export-donations-hidden-fields ul' );

if ( hidden_fields ) {
hidden_field_list.closest( 'tr' ).removeClass( 'give-hidden' );

// Loop through HIDDEN fields & output.
$( hidden_fields ).each( function ( index, value ) {
hidden_field_list.append( '<li><label for="give-csv-toolkit-hidden-field-' + value + '"><input type="checkbox" name="give_csv_toolbox_export_option[' + value + ']" id="give-csv-toolkit-hidden-field-' + value + '">' + value + '</label> </li>' );
} );
}
}
});
1 change: 1 addition & 0 deletions give.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ private function includes() {
require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/export/class-export.php';
require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/export/export-actions.php';
require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/export/pdf-reports.php';
require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/export/give-export-donations-functions.php';

require_once GIVE_PLUGIN_DIR . 'includes/admin/reports/reports.php';
require_once GIVE_PLUGIN_DIR . 'includes/admin/reports/class-give-graph.php';
Expand Down
7 changes: 5 additions & 2 deletions includes/admin/tools/class-settings-export.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ public function __construct() {

parent::__construct();

add_action( 'give_admin_field_tools_export', array( $this, 'render_export_field' ), 10, 2 );
add_action( 'give_admin_field_tools_export', array( 'Give_Settings_Export', 'render_export_field' ), 10, 2 );

// Do not use main donor for this tab.
if( give_get_current_setting_tab() === $this->id ) {
add_action( 'give-tools_open_form', '__return_empty_string' );
add_action( 'give-tools_close_form', '__return_empty_string' );


require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/export/class-give-export-donations.php';
}
}

Expand Down Expand Up @@ -94,7 +97,7 @@ public function get_settings() {
* @param $field
* @param $option_value
*/
public function render_export_field( $field, $option_value ) {
public static function render_export_field( $field, $option_value ) {
include_once( 'views/html-admin-page-exports.php' );
}
}
Expand Down

0 comments on commit 6fc520a

Please sign in to comment.