Listing: Empty trash button

This commit is contained in:
Jonathan Labreuille
2016-02-06 15:15:07 +01:00
parent bbc4acb2a4
commit 7a04eeb650
7 changed files with 51 additions and 12 deletions

View File

@ -1,10 +1,12 @@
define([
'react',
'jquery'
'jquery',
'mailpoet'
],
function(
React,
jQuery
jQuery,
MailPoet
) {
var ListingFilters = React.createClass({
handleFilterAction: function() {
@ -14,6 +16,9 @@ function(
})
return this.props.onSelectFilter(filters);
},
handleEmptyTrash: function() {
return this.props.onEmptyTrash();
},
getAvailableFilters: function() {
let filters = this.props.filters;
@ -63,6 +68,7 @@ function(
if (available_filters.length > 0) {
button = (
<input
id="post-query-submit"
onClick={ this.handleFilterAction }
type="submit"
defaultValue="Filter"
@ -70,10 +76,23 @@ function(
);
}
let empty_trash = false;
if (this.props.group === 'trash') {
empty_trash = (
<input
onClick={ this.handleEmptyTrash }
type="submit"
value="Empty Trash"
className="button"
/>
);
}
return (
<div className="alignleft actions actions">
{ available_filters }
{ button }
{ empty_trash }
</div>
);
}

View File

@ -504,10 +504,21 @@ define(
this.getItems();
}.bind(this));
},
handleEmptyTrash: function() {
this.handleBulkAction('all', {
action: 'delete',
group: 'trash'
}, function(response) {
MailPoet.Notice.success(
MailPoetI18n.permanentlyDeleted.replace('%d', response)
);
});
},
handleBulkAction: function(selected_ids, params, callback) {
if(
this.state.selection === false
&& this.state.selected_ids.length === 0
&& selected_ids !== 'all'
) {
return;
}
@ -520,8 +531,10 @@ define(
limit: 0,
filter: this.state.filter,
group: this.state.group,
search: this.state.search,
selection: selected_ids
search: this.state.search
}
if(selected_ids !== 'all') {
data.listing.selection = selected_ids;
}
MailPoet.Ajax.post({
@ -715,7 +728,10 @@ define(
<ListingFilters
filters={ this.state.filters }
filter={ this.state.filter }
onSelectFilter={ this.handleFilter } />
group={ this.state.group }
onSelectFilter={ this.handleFilter }
onEmptyTrash={ this.handleEmptyTrash }
/>
<ListingPages
count={ this.state.count }
page={ this.state.page }

View File

@ -60,7 +60,7 @@ class Model extends \Sudzy\ValidModel {
}
static function bulkDelete($orm) {
$models = $orm->findMany();
$models = $orm->findResultSet();
$count = 0;
foreach($models as $model) {
$model->delete();

View File

@ -7,7 +7,8 @@
'pageTitle': __('Forms'),
'searchLabel': __('Search'),
'loadingItems': __('Loading forms...'),
'noItemsFound': __('No forms found.')
'noItemsFound': __('No forms found.'),
'permanentlyDeleted': __('%d forms permanently deleted.')
}) %>
<script type="text/javascript">

View File

@ -11,7 +11,8 @@
'selectAllLabel': __('All newsletters on this page are selected.'),
'selectedAllLabel': __('All %d newsletters are selected.'),
'selectAllLink': __('Select all pages.'),
'clearSelection': __('Clear selection.')
'clearSelection': __('Clear selection.'),
'permanentlyDeleted': __('%d newsletters permanently deleted.')
}) %>
<script type="text/javascript">

View File

@ -7,6 +7,7 @@
'pageTitle': __('Segments'),
'searchLabel': __('Search'),
'loadingItems': __('Loading segments...'),
'noItemsFound': __('No segments found.')
'noItemsFound': __('No segments found.'),
'permanentlyDeleted': __('%d segments permanently deleted.')
}) %>
<% endblock %>

View File

@ -11,7 +11,8 @@
'selectAllLabel': __('All subscribers on this page are selected.'),
'selectedAllLabel': __('All %d subscribers are selected.'),
'selectAllLink': __('Select all pages.'),
'clearSelection': __('Clear selection.')
'clearSelection': __('Clear selection.'),
'permanentlyDeleted': __('%d subscribers permanently deleted.')
}) %>
<script type="text/javascript">