List selection fix
This commit is contained in:
@ -20,7 +20,17 @@ function(
|
||||
this.loadCachedItems();
|
||||
this.setupSelect2();
|
||||
},
|
||||
componentDidUpdate: function() {
|
||||
componentDidUpdate: function(prevProps, prevState) {
|
||||
if(
|
||||
(this.props.item !== undefined && prevProps.item !== undefined)
|
||||
&& (this.props.item.id !== prevProps.item.id)
|
||||
) {
|
||||
jQuery('#'+this.refs.select.id).select2(
|
||||
'val',
|
||||
this.props.item[this.props.field.name]
|
||||
);
|
||||
}
|
||||
|
||||
this.setupSelect2();
|
||||
},
|
||||
setupSelect2: function() {
|
||||
@ -81,9 +91,6 @@ function(
|
||||
return true;
|
||||
},
|
||||
render: function() {
|
||||
if((this.props.item !== undefined && this.props.item.id === undefined)) {
|
||||
return false;
|
||||
} else {
|
||||
var options = this.state.items.map(function(item, index) {
|
||||
return (
|
||||
<option
|
||||
@ -112,7 +119,6 @@ function(
|
||||
>{ options }</select>
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return Selection;
|
||||
|
@ -72,7 +72,7 @@ class Widget extends \WP_Widget {
|
||||
$selected_form = isset($instance['form']) ? (int)($instance['form']) : 0;
|
||||
|
||||
// get forms list
|
||||
$forms = Form::whereNull('deleted_at')->orderByAsc('name')->findArray();
|
||||
$forms = Form::getPublished()->orderByAsc('name')->findArray();
|
||||
?><p>
|
||||
<label for="<?php $this->get_field_id( 'title' ) ?>"><?php _e( 'Title:' ); ?></label>
|
||||
<input
|
||||
@ -94,12 +94,10 @@ class Widget extends \WP_Widget {
|
||||
</select>
|
||||
</p>
|
||||
<p>
|
||||
<a href="javascript:;" class="mailpoet_form_new"><?php _e("Create a new form"); ?></a>
|
||||
<a href="javascript:;" onClick="createSubscriptionForm()" class="mailpoet_form_new"><?php _e("Create a new form"); ?></a>
|
||||
</p>
|
||||
<script type="text/javascript">
|
||||
jQuery(function($) {
|
||||
$(function() {
|
||||
$('.mailpoet_form_new').on('click', function() {
|
||||
function createSubscriptionForm() {
|
||||
MailPoet.Ajax.post({
|
||||
endpoint: 'forms',
|
||||
action: 'create'
|
||||
@ -108,9 +106,8 @@ class Widget extends \WP_Widget {
|
||||
window.location = response;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
@ -134,7 +131,7 @@ class Widget extends \WP_Widget {
|
||||
);
|
||||
|
||||
// get form
|
||||
$form = Form::whereNull('deleted_at')->findOne($instance['form']);
|
||||
$form = Form::getPublished()->findOne($instance['form']);
|
||||
|
||||
// if the form was not found, return nothing.
|
||||
if($form === false) {
|
||||
|
@ -54,12 +54,12 @@ class Form extends Model {
|
||||
array(
|
||||
'name' => 'all',
|
||||
'label' => __('All'),
|
||||
'count' => Form::whereNull('deleted_at')->count()
|
||||
'count' => Form::getPublished()->count()
|
||||
),
|
||||
array(
|
||||
'name' => 'trash',
|
||||
'label' => __('Trash'),
|
||||
'count' => Form::whereNotNull('deleted_at')->count()
|
||||
'count' => Form::getTrashed()->count()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -106,12 +106,12 @@ class Newsletter extends Model {
|
||||
array(
|
||||
'name' => 'all',
|
||||
'label' => __('All'),
|
||||
'count' => Newsletter::whereNull('deleted_at')->count()
|
||||
'count' => Newsletter::getPublished()->count()
|
||||
),
|
||||
array(
|
||||
'name' => 'trash',
|
||||
'label' => __('Trash'),
|
||||
'count' => Newsletter::whereNotNull('deleted_at')->count()
|
||||
'count' => Newsletter::getTrashed()->count()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -76,12 +76,12 @@ class Segment extends Model {
|
||||
array(
|
||||
'name' => 'all',
|
||||
'label' => __('All'),
|
||||
'count' => Segment::whereNull('deleted_at')->count()
|
||||
'count' => Segment::getPublished()->count()
|
||||
),
|
||||
array(
|
||||
'name' => 'trash',
|
||||
'label' => __('Trash'),
|
||||
'count' => Segment::whereNotNull('deleted_at')->count()
|
||||
'count' => Segment::getTrashed()->count()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ class Subscriber extends Model {
|
||||
array(
|
||||
'name' => 'all',
|
||||
'label' => __('All'),
|
||||
'count' => Subscriber::whereNull('deleted_at')->count()
|
||||
'count' => Subscriber::getPublished()->count()
|
||||
),
|
||||
array(
|
||||
'name' => 'subscribed',
|
||||
@ -109,7 +109,7 @@ class Subscriber extends Model {
|
||||
array(
|
||||
'name' => 'trash',
|
||||
'label' => __('Trash'),
|
||||
'count' => Subscriber::whereNotNull('deleted_at')->count()
|
||||
'count' => Subscriber::getTrashed()->count()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user