fixed selectAll in listings
This commit is contained in:
@@ -1,2 +1,16 @@
|
|||||||
.mailpoet_listing_loading tbody tr
|
.mailpoet_listing_loading tbody tr
|
||||||
opacity: 0.2;
|
opacity: 0.2;
|
||||||
|
|
||||||
|
.widefat tfoot td.mailpoet_check_column,
|
||||||
|
.widefat thead td.mailpoet_check_column
|
||||||
|
padding-top: 10px;
|
||||||
|
|
||||||
|
.widefat tbody th.mailpoet_check_column,
|
||||||
|
.widefat tfoot td.mailpoet_check_column,
|
||||||
|
.widefat thead td.mailpoet_check_column
|
||||||
|
padding: 11px 0 0 3px;
|
||||||
|
|
||||||
|
.widefat .mailpoet_check_column
|
||||||
|
padding: 6px 0 25px;
|
||||||
|
vertical-align: top;
|
||||||
|
width: 2.2em;
|
@@ -14,7 +14,7 @@ define('bulk_actions', ['react'], function(React) {
|
|||||||
var action = this.getSelectedAction();
|
var action = this.getSelectedAction();
|
||||||
|
|
||||||
if(action !== null && action['onApply'] !== undefined) {
|
if(action !== null && action['onApply'] !== undefined) {
|
||||||
action.onApply(this.props.selected);
|
action.onApply();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getSelectedAction: function() {
|
getSelectedAction: function() {
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
define('groups', ['react', 'classnames'], function(React, classNames) {
|
define('groups', ['react', 'classnames'], function(React, classNames) {
|
||||||
var ListingGroups = React.createClass({
|
var ListingGroups = React.createClass({
|
||||||
handleSelect: function(group) {
|
handleSelect: function(group) {
|
||||||
return this.props.onSelect(group);
|
return this.props.onSelectGroup(group);
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
var count = this.props.groups.length;
|
var count = this.props.groups.length;
|
||||||
|
@@ -2,7 +2,7 @@ define('header', ['react', 'classnames'], function(React, classNames) {
|
|||||||
/*
|
/*
|
||||||
props:
|
props:
|
||||||
onSort: callback(sort_by, sort_order)
|
onSort: callback(sort_by, sort_order)
|
||||||
onSelectAll: callback(is_checked)
|
onSelectItems: callback(is_checked)
|
||||||
sort_by: (string) field name
|
sort_by: (string) field name
|
||||||
columns -> (array)
|
columns -> (array)
|
||||||
column -> {
|
column -> {
|
||||||
@@ -13,9 +13,9 @@ define('header', ['react', 'classnames'], function(React, classNames) {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
var ListingHeader = React.createClass({
|
var ListingHeader = React.createClass({
|
||||||
handleSelectAll: function() {
|
handleSelectItems: function() {
|
||||||
return this.props.onSelectAll(
|
return this.props.onSelectItems(
|
||||||
this.refs.select_all.getDOMNode().checked
|
this.refs.toggle.getDOMNode().checked
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
@@ -32,14 +32,15 @@ define('header', ['react', 'classnames'], function(React, classNames) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<tr>
|
<tr>
|
||||||
<td className="manage-column column-cb check-column" id="cb">
|
<td className="manage-column column-cb mailpoet_check_column">
|
||||||
<label className="screen-reader-text">
|
<label className="screen-reader-text">
|
||||||
{ 'Select All' }
|
{ 'Select All' }
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
ref="select_all"
|
ref="toggle"
|
||||||
onChange={this.handleSelectAll} />
|
checked={ this.props.selected }
|
||||||
|
onChange={ this.handleSelectItems } />
|
||||||
</td>
|
</td>
|
||||||
{columns}
|
{columns}
|
||||||
</tr>
|
</tr>
|
||||||
|
@@ -25,10 +25,10 @@ define(
|
|||||||
ListingFilters
|
ListingFilters
|
||||||
) {
|
) {
|
||||||
var ListingItem = React.createClass({
|
var ListingItem = React.createClass({
|
||||||
handleSelect: function(e) {
|
handleSelectItem: function(e) {
|
||||||
var is_checked = jQuery(e.target).is(':checked');
|
var is_checked = jQuery(e.target).is(':checked');
|
||||||
|
|
||||||
this.props.onSelect(
|
this.props.onSelectItem(
|
||||||
parseInt(e.target.value, 10),
|
parseInt(e.target.value, 10),
|
||||||
is_checked
|
is_checked
|
||||||
);
|
);
|
||||||
@@ -38,14 +38,14 @@ define(
|
|||||||
render: function() {
|
render: function() {
|
||||||
return (
|
return (
|
||||||
<tr>
|
<tr>
|
||||||
<th className="check-column" scope="row">
|
<th className="mailpoet_check_column" scope="row">
|
||||||
<label className="screen-reader-text">
|
<label className="screen-reader-text">
|
||||||
{ 'Select ' + this.props.item.email }</label>
|
{ 'Select ' + this.props.item.email }</label>
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
defaultValue={ this.props.item.id }
|
defaultValue={ this.props.item.id }
|
||||||
defaultChecked={ this.props.item.selected }
|
checked={ this.props.item.selected }
|
||||||
onChange={ this.handleSelect } />
|
onChange={ this.handleSelectItem } />
|
||||||
</th>
|
</th>
|
||||||
{ this.props.onRenderItem(this.props.item) }
|
{ this.props.onRenderItem(this.props.item) }
|
||||||
</tr>
|
</tr>
|
||||||
@@ -76,11 +76,13 @@ define(
|
|||||||
return (
|
return (
|
||||||
<tbody>
|
<tbody>
|
||||||
{this.props.items.map(function(item) {
|
{this.props.items.map(function(item) {
|
||||||
item.selected = (this.props.selected.indexOf(item.id) !== -1);
|
item.id = parseInt(item.id, 10);
|
||||||
|
item.selected = (this.props.selected_ids.indexOf(item.id) !== -1);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ListingItem
|
<ListingItem
|
||||||
columns={ this.props.columns }
|
columns={ this.props.columns }
|
||||||
onSelect={ this.props.onSelect }
|
onSelectItem={ this.props.onSelectItem }
|
||||||
onRenderItem={ this.props.onRenderItem }
|
onRenderItem={ this.props.onRenderItem }
|
||||||
key={ 'item-' + item.id }
|
key={ 'item-' + item.id }
|
||||||
item={ item } />
|
item={ item } />
|
||||||
@@ -106,7 +108,8 @@ define(
|
|||||||
groups: [],
|
groups: [],
|
||||||
group: 'all',
|
group: 'all',
|
||||||
filters: [],
|
filters: [],
|
||||||
selected: []
|
selected_ids: [],
|
||||||
|
selected: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
@@ -131,18 +134,37 @@ define(
|
|||||||
this.getItems();
|
this.getItems();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
handleSelect: function(id, is_checked) {
|
handleSelectItem: function(id, is_checked) {
|
||||||
var selected = this.state.selected;
|
var selected_ids = this.state.selected_ids;
|
||||||
|
|
||||||
if(is_checked) {
|
if(is_checked) {
|
||||||
selected = jQuery.merge(selected, [ id ]);
|
selected_ids = jQuery.merge(selected_ids, [ id ]);
|
||||||
} else {
|
} else {
|
||||||
selected.splice(selected.indexOf(id), 1);
|
selected_ids.splice(selected_ids.indexOf(id), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
selected: selected
|
selected: false,
|
||||||
|
selected_ids: selected_ids
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
handleSelectItems: function(is_checked) {
|
||||||
|
if(is_checked === false) {
|
||||||
|
this.setState({
|
||||||
|
selected_ids: [],
|
||||||
|
selected: false
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
var selected_ids = this.state.items.map(function(item) {
|
||||||
|
return ~~item.id;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
selected_ids: selected_ids,
|
||||||
|
selected: 'page'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
handleGroup: function(group) {
|
handleGroup: function(group) {
|
||||||
// reset search
|
// reset search
|
||||||
jQuery('#search_input').val('');
|
jQuery('#search_input').val('');
|
||||||
@@ -150,26 +172,14 @@ define(
|
|||||||
this.setState({
|
this.setState({
|
||||||
group: group,
|
group: group,
|
||||||
filters: [],
|
filters: [],
|
||||||
selected: [],
|
selected: false,
|
||||||
|
selected_ids: [],
|
||||||
search: '',
|
search: '',
|
||||||
page: 1
|
page: 1
|
||||||
}, function() {
|
}, function() {
|
||||||
this.getItems();
|
this.getItems();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
handleSelectAll: function(is_checked) {
|
|
||||||
if(is_checked === false) {
|
|
||||||
this.setState({ selected: [] });
|
|
||||||
} else {
|
|
||||||
var selected = this.state.items.map(function(item) {
|
|
||||||
return ~~item.id;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.setState({
|
|
||||||
selected: selected
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
handleSetPage: function(page) {
|
handleSetPage: function(page) {
|
||||||
this.setState({ page: page }, function() {
|
this.setState({ page: page }, function() {
|
||||||
this.getItems();
|
this.getItems();
|
||||||
@@ -201,14 +211,13 @@ define(
|
|||||||
<ListingGroups
|
<ListingGroups
|
||||||
groups={ this.state.groups }
|
groups={ this.state.groups }
|
||||||
selected={ this.state.group }
|
selected={ this.state.group }
|
||||||
onSelect={ this.handleGroup } />
|
onSelectGroup={ this.handleGroup } />
|
||||||
<ListingSearch
|
<ListingSearch
|
||||||
onSearch={ this.handleSearch }
|
onSearch={ this.handleSearch }
|
||||||
search={ this.state.search } />
|
search={ this.state.search } />
|
||||||
<div className="tablenav top clearfix">
|
<div className="tablenav top clearfix">
|
||||||
<ListingBulkActions
|
<ListingBulkActions
|
||||||
actions={ this.props.actions }
|
actions={ this.props.actions } />
|
||||||
selected={ this.state.selected } />
|
|
||||||
<ListingFilters filters={ this.state.filters } />
|
<ListingFilters filters={ this.state.filters } />
|
||||||
<ListingPages
|
<ListingPages
|
||||||
count={ this.state.count }
|
count={ this.state.count }
|
||||||
@@ -220,7 +229,8 @@ define(
|
|||||||
<thead>
|
<thead>
|
||||||
<ListingHeader
|
<ListingHeader
|
||||||
onSort={ this.handleSort }
|
onSort={ this.handleSort }
|
||||||
onSelectAll={ this.handleSelectAll }
|
onSelectItems={ this.handleSelectItems }
|
||||||
|
selected={ this.state.selected }
|
||||||
sort_by={ this.state.sort_by }
|
sort_by={ this.state.sort_by }
|
||||||
sort_order={ this.state.sort_order }
|
sort_order={ this.state.sort_order }
|
||||||
columns={ this.props.columns } />
|
columns={ this.props.columns } />
|
||||||
@@ -229,15 +239,16 @@ define(
|
|||||||
<ListingItems
|
<ListingItems
|
||||||
onRenderItem={ this.handleRenderItem }
|
onRenderItem={ this.handleRenderItem }
|
||||||
columns={ this.props.columns }
|
columns={ this.props.columns }
|
||||||
selected={ this.state.selected }
|
onSelectItem={ this.handleSelectItem }
|
||||||
onSelect={ this.handleSelect }
|
selected_ids={ this.state.selected_ids }
|
||||||
loading= { this.state.loading }
|
loading= { this.state.loading }
|
||||||
items={ items } />
|
items={ items } />
|
||||||
|
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<ListingHeader
|
<ListingHeader
|
||||||
onSort={ this.handleSort }
|
onSort={ this.handleSort }
|
||||||
onSelectAll={ this.handleSelectAll }
|
onSelectItems={ this.handleSelectItems }
|
||||||
|
selected={ this.state.selected }
|
||||||
sort_by={ this.state.sort_by }
|
sort_by={ this.state.sort_by }
|
||||||
sort_order={ this.state.sort_order }
|
sort_order={ this.state.sort_order }
|
||||||
columns={ this.props.columns } />
|
columns={ this.props.columns } />
|
||||||
@@ -246,8 +257,7 @@ define(
|
|||||||
</table>
|
</table>
|
||||||
<div className="tablenav bottom">
|
<div className="tablenav bottom">
|
||||||
<ListingBulkActions
|
<ListingBulkActions
|
||||||
actions={ this.props.actions }
|
actions={ this.props.actions } />
|
||||||
selected={ this.state.selected } />
|
|
||||||
<ListingPages
|
<ListingPages
|
||||||
count={ this.state.count }
|
count={ this.state.count }
|
||||||
page={ this.state.page }
|
page={ this.state.page }
|
||||||
|
Reference in New Issue
Block a user