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) {
|
item_actions = custom_actions.map(function(action, index) {
|
||||||
return (
|
return (
|
||||||
<span key={ 'action-'+index } className={ action.name }>
|
<span key={ 'action-'+index } className={ action.name }>
|
||||||
{ action.link(this.props.item.id) }
|
{ action.link(this.props.item) }
|
||||||
{(index < (custom_actions.length - 1)) ? ' | ' : ''}
|
{(index < (custom_actions.length - 1)) ? ' | ' : ''}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
@@ -522,7 +522,6 @@ define(
|
|||||||
var bulk_actions = this.props.bulk_actions || [];
|
var bulk_actions = this.props.bulk_actions || [];
|
||||||
|
|
||||||
if(this.state.group === 'trash') {
|
if(this.state.group === 'trash') {
|
||||||
|
|
||||||
bulk_actions = [
|
bulk_actions = [
|
||||||
{
|
{
|
||||||
name: 'restore',
|
name: 'restore',
|
||||||
@@ -574,6 +573,9 @@ define(
|
|||||||
groups = false;
|
groups = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// filters
|
||||||
|
var filter = this.state.filter;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{ groups }
|
{ groups }
|
||||||
@@ -586,7 +588,7 @@ define(
|
|||||||
onBulkAction={ this.handleBulkAction } />
|
onBulkAction={ this.handleBulkAction } />
|
||||||
<ListingFilters
|
<ListingFilters
|
||||||
filters={ this.state.filters }
|
filters={ this.state.filters }
|
||||||
filter={ this.state.filter }
|
filter={ filter }
|
||||||
onSelectFilter={ this.handleFilter } />
|
onSelectFilter={ this.handleFilter } />
|
||||||
<ListingPages
|
<ListingPages
|
||||||
count={ this.state.count }
|
count={ this.state.count }
|
||||||
|
@@ -3,13 +3,15 @@ define(
|
|||||||
'react',
|
'react',
|
||||||
'react-router',
|
'react-router',
|
||||||
'listing/listing.jsx',
|
'listing/listing.jsx',
|
||||||
'classnames'
|
'classnames',
|
||||||
|
'mailpoet'
|
||||||
],
|
],
|
||||||
function(
|
function(
|
||||||
React,
|
React,
|
||||||
Router,
|
Router,
|
||||||
Listing,
|
Listing,
|
||||||
classNames
|
classNames,
|
||||||
|
MailPoet
|
||||||
) {
|
) {
|
||||||
var columns = [
|
var columns = [
|
||||||
{
|
{
|
||||||
@@ -49,10 +51,10 @@ define(
|
|||||||
var count = ~~response.segments;
|
var count = ~~response.segments;
|
||||||
var message = null;
|
var message = null;
|
||||||
|
|
||||||
if(count === 1) {
|
if(count === 1 || response === true) {
|
||||||
message = (
|
message = (
|
||||||
'1 segment was moved to the trash.'
|
'1 segment was moved to the trash.'
|
||||||
).replace('%$1d', count);
|
);
|
||||||
} else if(count > 1) {
|
} else if(count > 1) {
|
||||||
message = (
|
message = (
|
||||||
'%$1d segments were moved to the trash.'
|
'%$1d segments were moved to the trash.'
|
||||||
@@ -67,10 +69,10 @@ define(
|
|||||||
var count = ~~response.segments;
|
var count = ~~response.segments;
|
||||||
var message = null;
|
var message = null;
|
||||||
|
|
||||||
if(count === 1) {
|
if(count === 1 || response === true) {
|
||||||
message = (
|
message = (
|
||||||
'1 segment was permanently deleted.'
|
'1 segment was permanently deleted.'
|
||||||
).replace('%$1d', count);
|
);
|
||||||
} else if(count > 1) {
|
} else if(count > 1) {
|
||||||
message = (
|
message = (
|
||||||
'%$1d segments were permanently deleted.'
|
'%$1d segments were permanently deleted.'
|
||||||
@@ -85,10 +87,10 @@ define(
|
|||||||
var count = ~~response.segments;
|
var count = ~~response.segments;
|
||||||
var message = null;
|
var message = null;
|
||||||
|
|
||||||
if(count === 1) {
|
if(count === 1 || response === true) {
|
||||||
message = (
|
message = (
|
||||||
'1 segment has been restored from the trash.'
|
'1 segment has been restored from the trash.'
|
||||||
).replace('%$1d', count);
|
);
|
||||||
} else if(count > 1) {
|
} else if(count > 1) {
|
||||||
message = (
|
message = (
|
||||||
'%$1d segments have been restored from the trash.'
|
'%$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 = [
|
var bulk_actions = [
|
||||||
{
|
{
|
||||||
name: 'trash',
|
name: 'trash',
|
||||||
@@ -164,7 +208,9 @@ define(
|
|||||||
endpoint="segments"
|
endpoint="segments"
|
||||||
onRenderItem={ this.renderItem }
|
onRenderItem={ this.renderItem }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
bulk_actions={ bulk_actions } />
|
bulk_actions={ bulk_actions }
|
||||||
|
item_actions={ item_actions }
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -258,8 +258,6 @@ define(
|
|||||||
return segment.name;
|
return segment.name;
|
||||||
}).join(', ');
|
}).join(', ');
|
||||||
|
|
||||||
var row_actions = false;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<td className={ row_classes }>
|
<td className={ row_classes }>
|
||||||
|
@@ -9,7 +9,7 @@ let history = createHashHistory({ queryKey: false })
|
|||||||
|
|
||||||
const App = React.createClass({
|
const App = React.createClass({
|
||||||
render() {
|
render() {
|
||||||
return this.props.children
|
return this.props.children;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -21,6 +21,37 @@ class Segment extends Model {
|
|||||||
return parent::delete();
|
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() {
|
function subscribers() {
|
||||||
return $this->has_many_through(
|
return $this->has_many_through(
|
||||||
__NAMESPACE__.'\Subscriber',
|
__NAMESPACE__.'\Subscriber',
|
||||||
|
@@ -56,6 +56,10 @@ class Segments {
|
|||||||
->findOne()->asArray();
|
->findOne()->asArray();
|
||||||
|
|
||||||
$item = array_merge($item, $stats);
|
$item = array_merge($item, $stats);
|
||||||
|
|
||||||
|
$item['subscribers_url'] = admin_url(
|
||||||
|
'admin.php?page=mailpoet-subscribers#segment='.$item['id']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_send_json($listing_data);
|
wp_send_json($listing_data);
|
||||||
@@ -80,7 +84,7 @@ class Segments {
|
|||||||
$segment = Segment::findOne($id);
|
$segment = Segment::findOne($id);
|
||||||
if($segment !== false) {
|
if($segment !== false) {
|
||||||
$segment->set_expr('deleted_at', 'NULL');
|
$segment->set_expr('deleted_at', 'NULL');
|
||||||
$result = array('segments' => (int)$segment->save());
|
$result = $segment->save();
|
||||||
} else {
|
} else {
|
||||||
$result = false;
|
$result = false;
|
||||||
}
|
}
|
||||||
@@ -93,10 +97,10 @@ class Segments {
|
|||||||
if($segment !== false) {
|
if($segment !== false) {
|
||||||
if($confirm_delete) {
|
if($confirm_delete) {
|
||||||
$segment->delete();
|
$segment->delete();
|
||||||
$result = array('segments' => 1);
|
$result = true;
|
||||||
} else {
|
} else {
|
||||||
$segment->set_expr('deleted_at', 'NOW()');
|
$segment->set_expr('deleted_at', 'NOW()');
|
||||||
$result = array('segments' => (int)$segment->save());
|
$result = $segment->save();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$result = false;
|
$result = false;
|
||||||
@@ -104,6 +108,11 @@ class Segments {
|
|||||||
wp_send_json($result);
|
wp_send_json($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function duplicate($id) {
|
||||||
|
$result = Segment::duplicate($id);
|
||||||
|
wp_send_json($result);
|
||||||
|
}
|
||||||
|
|
||||||
function bulk_action($data = array()) {
|
function bulk_action($data = array()) {
|
||||||
$bulk_action = new Listing\BulkAction(
|
$bulk_action = new Listing\BulkAction(
|
||||||
'\MailPoet\Models\Segment',
|
'\MailPoet\Models\Segment',
|
||||||
|
Reference in New Issue
Block a user