List selection fix
This commit is contained in:
@ -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,37 +91,33 @@ function(
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
if((this.props.item !== undefined && this.props.item.id === undefined)) {
|
var options = this.state.items.map(function(item, index) {
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
var options = this.state.items.map(function(item, index) {
|
|
||||||
return (
|
|
||||||
<option
|
|
||||||
key={ item.id }
|
|
||||||
value={ item.id }
|
|
||||||
>
|
|
||||||
{ item.name }
|
|
||||||
</option>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
var default_value = (
|
|
||||||
(this.props.item !== undefined && this.props.field.name !== undefined)
|
|
||||||
? this.props.item[this.props.field.name]
|
|
||||||
: null
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<select
|
<option
|
||||||
id={ this.props.field.id || this.props.field.name }
|
key={ item.id }
|
||||||
ref="select"
|
value={ item.id }
|
||||||
placeholder={ this.props.field.placeholder }
|
>
|
||||||
multiple={ this.props.field.multiple }
|
{ item.name }
|
||||||
onChange={ this.handleChange }
|
</option>
|
||||||
defaultValue={ default_value }
|
|
||||||
>{ options }</select>
|
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|
||||||
|
var default_value = (
|
||||||
|
(this.props.item !== undefined && this.props.field.name !== undefined)
|
||||||
|
? this.props.item[this.props.field.name]
|
||||||
|
: null
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<select
|
||||||
|
id={ this.props.field.id || this.props.field.name }
|
||||||
|
ref="select"
|
||||||
|
placeholder={ this.props.field.placeholder }
|
||||||
|
multiple={ this.props.field.multiple }
|
||||||
|
onChange={ this.handleChange }
|
||||||
|
defaultValue={ default_value }
|
||||||
|
>{ options }</select>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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,23 +94,20 @@ 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.Ajax.post({
|
||||||
$('.mailpoet_form_new').on('click', function() {
|
endpoint: 'forms',
|
||||||
MailPoet.Ajax.post({
|
action: 'create'
|
||||||
endpoint: 'forms',
|
}).done(function(response) {
|
||||||
action: 'create'
|
if(response !== false) {
|
||||||
}).done(function(response) {
|
window.location = response;
|
||||||
if(response !== false) {
|
}
|
||||||
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) {
|
||||||
|
@ -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()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -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()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -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()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -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()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user