List selection fix

This commit is contained in:
Jonathan Labreuille
2015-11-09 14:19:59 +01:00
parent e9110680ee
commit 893231e8e5
6 changed files with 57 additions and 54 deletions

View File

@ -20,7 +20,17 @@ function(
this.loadCachedItems(); this.loadCachedItems();
this.setupSelect2(); 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(); this.setupSelect2();
}, },
setupSelect2: function() { setupSelect2: function() {
@ -81,9 +91,6 @@ function(
return true; return true;
}, },
render: function() { render: function() {
if((this.props.item !== undefined && this.props.item.id === undefined)) {
return false;
} else {
var options = this.state.items.map(function(item, index) { var options = this.state.items.map(function(item, index) {
return ( return (
<option <option
@ -112,7 +119,6 @@ function(
>{ options }</select> >{ options }</select>
); );
} }
}
}); });
return Selection; return Selection;

View File

@ -72,7 +72,7 @@ class Widget extends \WP_Widget {
$selected_form = isset($instance['form']) ? (int)($instance['form']) : 0; $selected_form = isset($instance['form']) ? (int)($instance['form']) : 0;
// get forms list // get forms list
$forms = Form::whereNull('deleted_at')->orderByAsc('name')->findArray(); $forms = Form::getPublished()->orderByAsc('name')->findArray();
?><p> ?><p>
<label for="<?php $this->get_field_id( 'title' ) ?>"><?php _e( 'Title:' ); ?></label> <label for="<?php $this->get_field_id( 'title' ) ?>"><?php _e( 'Title:' ); ?></label>
<input <input
@ -94,12 +94,10 @@ class Widget extends \WP_Widget {
</select> </select>
</p> </p>
<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> </p>
<script type="text/javascript"> <script type="text/javascript">
jQuery(function($) { function createSubscriptionForm() {
$(function() {
$('.mailpoet_form_new').on('click', function() {
MailPoet.Ajax.post({ MailPoet.Ajax.post({
endpoint: 'forms', endpoint: 'forms',
action: 'create' action: 'create'
@ -108,9 +106,8 @@ class Widget extends \WP_Widget {
window.location = response; window.location = response;
} }
}); });
}); return false;
}); }
});
</script> </script>
<?php <?php
} }
@ -134,7 +131,7 @@ class Widget extends \WP_Widget {
); );
// get form // 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 the form was not found, return nothing.
if($form === false) { if($form === false) {

View File

@ -54,12 +54,12 @@ class Form extends Model {
array( array(
'name' => 'all', 'name' => 'all',
'label' => __('All'), 'label' => __('All'),
'count' => Form::whereNull('deleted_at')->count() 'count' => Form::getPublished()->count()
), ),
array( array(
'name' => 'trash', 'name' => 'trash',
'label' => __('Trash'), 'label' => __('Trash'),
'count' => Form::whereNotNull('deleted_at')->count() 'count' => Form::getTrashed()->count()
) )
); );
} }

View File

@ -106,12 +106,12 @@ class Newsletter extends Model {
array( array(
'name' => 'all', 'name' => 'all',
'label' => __('All'), 'label' => __('All'),
'count' => Newsletter::whereNull('deleted_at')->count() 'count' => Newsletter::getPublished()->count()
), ),
array( array(
'name' => 'trash', 'name' => 'trash',
'label' => __('Trash'), 'label' => __('Trash'),
'count' => Newsletter::whereNotNull('deleted_at')->count() 'count' => Newsletter::getTrashed()->count()
) )
); );
} }

View File

@ -76,12 +76,12 @@ class Segment extends Model {
array( array(
'name' => 'all', 'name' => 'all',
'label' => __('All'), 'label' => __('All'),
'count' => Segment::whereNull('deleted_at')->count() 'count' => Segment::getPublished()->count()
), ),
array( array(
'name' => 'trash', 'name' => 'trash',
'label' => __('Trash'), 'label' => __('Trash'),
'count' => Segment::whereNotNull('deleted_at')->count() 'count' => Segment::getTrashed()->count()
) )
); );
} }

View File

@ -89,7 +89,7 @@ class Subscriber extends Model {
array( array(
'name' => 'all', 'name' => 'all',
'label' => __('All'), 'label' => __('All'),
'count' => Subscriber::whereNull('deleted_at')->count() 'count' => Subscriber::getPublished()->count()
), ),
array( array(
'name' => 'subscribed', 'name' => 'subscribed',
@ -109,7 +109,7 @@ class Subscriber extends Model {
array( array(
'name' => 'trash', 'name' => 'trash',
'label' => __('Trash'), 'label' => __('Trash'),
'count' => Subscriber::whereNotNull('deleted_at')->count() 'count' => Subscriber::getTrashed()->count()
) )
); );
} }