Segment actions
- added duplicate - added view subscribers
This commit is contained in:
@@ -79,7 +79,7 @@ define(
|
||||
item_actions = custom_actions.map(function(action, index) {
|
||||
return (
|
||||
<span key={ 'action-'+index } className={ action.name }>
|
||||
{ action.link(this.props.item.id) }
|
||||
{ action.link(this.props.item) }
|
||||
{(index < (custom_actions.length - 1)) ? ' | ' : ''}
|
||||
</span>
|
||||
);
|
||||
@@ -522,7 +522,6 @@ define(
|
||||
var bulk_actions = this.props.bulk_actions || [];
|
||||
|
||||
if(this.state.group === 'trash') {
|
||||
|
||||
bulk_actions = [
|
||||
{
|
||||
name: 'restore',
|
||||
@@ -574,6 +573,9 @@ define(
|
||||
groups = false;
|
||||
}
|
||||
|
||||
// filters
|
||||
var filter = this.state.filter;
|
||||
|
||||
return (
|
||||
<div>
|
||||
{ groups }
|
||||
@@ -586,7 +588,7 @@ define(
|
||||
onBulkAction={ this.handleBulkAction } />
|
||||
<ListingFilters
|
||||
filters={ this.state.filters }
|
||||
filter={ this.state.filter }
|
||||
filter={ filter }
|
||||
onSelectFilter={ this.handleFilter } />
|
||||
<ListingPages
|
||||
count={ this.state.count }
|
||||
|
@@ -3,13 +3,15 @@ define(
|
||||
'react',
|
||||
'react-router',
|
||||
'listing/listing.jsx',
|
||||
'classnames'
|
||||
'classnames',
|
||||
'mailpoet'
|
||||
],
|
||||
function(
|
||||
React,
|
||||
Router,
|
||||
Listing,
|
||||
classNames
|
||||
classNames,
|
||||
MailPoet
|
||||
) {
|
||||
var columns = [
|
||||
{
|
||||
@@ -49,10 +51,10 @@ define(
|
||||
var count = ~~response.segments;
|
||||
var message = null;
|
||||
|
||||
if(count === 1) {
|
||||
if(count === 1 || response === true) {
|
||||
message = (
|
||||
'1 segment was moved to the trash.'
|
||||
).replace('%$1d', count);
|
||||
);
|
||||
} else if(count > 1) {
|
||||
message = (
|
||||
'%$1d segments were moved to the trash.'
|
||||
@@ -67,10 +69,10 @@ define(
|
||||
var count = ~~response.segments;
|
||||
var message = null;
|
||||
|
||||
if(count === 1) {
|
||||
if(count === 1 || response === true) {
|
||||
message = (
|
||||
'1 segment was permanently deleted.'
|
||||
).replace('%$1d', count);
|
||||
);
|
||||
} else if(count > 1) {
|
||||
message = (
|
||||
'%$1d segments were permanently deleted.'
|
||||
@@ -85,10 +87,10 @@ define(
|
||||
var count = ~~response.segments;
|
||||
var message = null;
|
||||
|
||||
if(count === 1) {
|
||||
if(count === 1 || response === true) {
|
||||
message = (
|
||||
'1 segment has been restored from the trash.'
|
||||
).replace('%$1d', count);
|
||||
);
|
||||
} else if(count > 1) {
|
||||
message = (
|
||||
'%$1d segments have been restored from the trash.'
|
||||
@@ -101,6 +103,48 @@ define(
|
||||
}
|
||||
};
|
||||
|
||||
var Link = Router.Link;
|
||||
var item_actions = [
|
||||
{
|
||||
name: 'edit',
|
||||
link: function(item) {
|
||||
return (
|
||||
<Link to={ `/edit/${item.id}` }>Edit</Link>
|
||||
);
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'duplicate_segment',
|
||||
link: function(item) {
|
||||
return (
|
||||
<a
|
||||
href="javascript:;"
|
||||
onClick={ this.onDuplicate.bind(null, item) }
|
||||
>Duplicate</a>
|
||||
);
|
||||
},
|
||||
onDuplicate: function(item) {
|
||||
MailPoet.Ajax.post({
|
||||
endpoint: 'segments',
|
||||
action: 'duplicate',
|
||||
data: item.id
|
||||
}).done(function() {
|
||||
MailPoet.Notice.success(
|
||||
('List "%$1s" has been duplicated.').replace('%$1s', item.name)
|
||||
);
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'view_subscribers',
|
||||
link: function(item) {
|
||||
return (
|
||||
<a href={ item.subscribers_url }>View subscribers</a>
|
||||
);
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
var bulk_actions = [
|
||||
{
|
||||
name: 'trash',
|
||||
@@ -164,7 +208,9 @@ define(
|
||||
endpoint="segments"
|
||||
onRenderItem={ this.renderItem }
|
||||
columns={ columns }
|
||||
bulk_actions={ bulk_actions } />
|
||||
bulk_actions={ bulk_actions }
|
||||
item_actions={ item_actions }
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@@ -258,8 +258,6 @@ define(
|
||||
return segment.name;
|
||||
}).join(', ');
|
||||
|
||||
var row_actions = false;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<td className={ row_classes }>
|
||||
|
@@ -9,7 +9,7 @@ let history = createHashHistory({ queryKey: false })
|
||||
|
||||
const App = React.createClass({
|
||||
render() {
|
||||
return this.props.children
|
||||
return this.props.children;
|
||||
}
|
||||
});
|
||||
|
||||
|
@@ -21,6 +21,37 @@ class Segment extends Model {
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
static function duplicate($id) {
|
||||
$segment = self::findOne($id)->asArray();
|
||||
|
||||
if($segment !== false) {
|
||||
unset($segment['id']);
|
||||
$new_segment = self::create();
|
||||
$new_segment->hydrate($segment);
|
||||
|
||||
$new_segment->set(
|
||||
'name',
|
||||
sprintf(__('Copy of %s'), $new_segment->name)
|
||||
);
|
||||
$new_segment->set_expr('created_at', 'NOW()');
|
||||
$new_segment->set_expr('updated_at', 'NOW()');
|
||||
$new_segment->save();
|
||||
|
||||
$relations = SubscriberSegment::select('subscriber_id')
|
||||
->where('segment_id', $id)
|
||||
->findResultSet();
|
||||
|
||||
foreach($relations as $relation) {
|
||||
$new_relation = SubscriberSegment::create();
|
||||
$new_relation->set('subscriber_id', $relation->subscriber_id);
|
||||
$new_relation->set('segment_id', $new_segment->id());
|
||||
$new_relation->save();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function subscribers() {
|
||||
return $this->has_many_through(
|
||||
__NAMESPACE__.'\Subscriber',
|
||||
|
@@ -56,6 +56,10 @@ class Segments {
|
||||
->findOne()->asArray();
|
||||
|
||||
$item = array_merge($item, $stats);
|
||||
|
||||
$item['subscribers_url'] = admin_url(
|
||||
'admin.php?page=mailpoet-subscribers#segment='.$item['id']
|
||||
);
|
||||
}
|
||||
|
||||
wp_send_json($listing_data);
|
||||
@@ -80,7 +84,7 @@ class Segments {
|
||||
$segment = Segment::findOne($id);
|
||||
if($segment !== false) {
|
||||
$segment->set_expr('deleted_at', 'NULL');
|
||||
$result = array('segments' => (int)$segment->save());
|
||||
$result = $segment->save();
|
||||
} else {
|
||||
$result = false;
|
||||
}
|
||||
@@ -93,10 +97,10 @@ class Segments {
|
||||
if($segment !== false) {
|
||||
if($confirm_delete) {
|
||||
$segment->delete();
|
||||
$result = array('segments' => 1);
|
||||
$result = true;
|
||||
} else {
|
||||
$segment->set_expr('deleted_at', 'NOW()');
|
||||
$result = array('segments' => (int)$segment->save());
|
||||
$result = $segment->save();
|
||||
}
|
||||
} else {
|
||||
$result = false;
|
||||
@@ -104,6 +108,11 @@ class Segments {
|
||||
wp_send_json($result);
|
||||
}
|
||||
|
||||
function duplicate($id) {
|
||||
$result = Segment::duplicate($id);
|
||||
wp_send_json($result);
|
||||
}
|
||||
|
||||
function bulk_action($data = array()) {
|
||||
$bulk_action = new Listing\BulkAction(
|
||||
'\MailPoet\Models\Segment',
|
||||
|
Reference in New Issue
Block a user