Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions css/fieldmanager.css
Original file line number Diff line number Diff line change
Expand Up @@ -680,3 +680,10 @@ a.fm-delete:hover {
margin-bottom: 0;
}
}

.fm-bulk-actions {
border-bottom: 1px solid #dfdfdf;
margin-bottom: 10px;
max-width: 200px;
padding-bottom: 10px;
}
20 changes: 20 additions & 0 deletions js/fieldmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,26 @@ var fm_init = function () {
init_sortable();

$document.on( 'fm_activate_tab', init_sortable );

fm.init_bulk_checkboxes_actions = function() {
var $this = $( this );
var $bulk_toggle = $this.find( '.fm-bulk-action' );
var $checkboxes = $this.siblings().find( 'input:checkbox' );
var all_checked;
$bulk_toggle.change( function() {
var is_checked = $bulk_toggle.prop( 'checked' );
$checkboxes.prop( 'checked', is_checked );
all_checked = is_checked;
} );
$checkboxes.change( function() {
var is_checked = $( this ).prop( 'checked' );
if ( all_checked && !is_checked ) {
all_checked = false;
$bulk_toggle.prop( 'checked', false );
}
} );
};
$( '.fm-bulk-actions' ).each( fm.init_bulk_checkboxes_actions );
};

fmLoadModule( fm_init );
Expand Down
28 changes: 27 additions & 1 deletion php/class-fieldmanager-checkboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ class Fieldmanager_Checkboxes extends Fieldmanager_Options {
*/
public $multiple = true;

/**
* Add a "select all" bulk action to the list of checkboxes.
*
* @var boolean
*/
public $bulk_actions = true;

/**
* Render form element.
*
Expand All @@ -37,12 +44,31 @@ class Fieldmanager_Checkboxes extends Fieldmanager_Options {
*/
public function form_element( $value = array() ) {
return sprintf(
'<div class="fm-checkbox-group" id="%s">%s</div>',
'<div class="fm-checkbox-group" id="%s">%s%s</div>',
esc_attr( $this->get_element_id() ),
$this->bulk_actions ? $this->add_bulk_actions() : '',
$this->form_data_elements( $value )
);
}

/**
* Get the HTML for the bulk actions.
*
* @return string
*/
public function add_bulk_actions() {
return sprintf(
'<div class="fm-bulk-actions">
<label for="%1$s">
<input type="checkbox" id="%1$s" class="fm-bulk-action" />
%2$s
</label>
</div>' . "\n",
esc_attr( $this->get_element_id() . '-bulk-action' ),
esc_html__( 'Select all', 'fieldmanager' )
);
}

/**
* Override function to allow all boxes to be checked by default.
*
Expand Down