refactoring the code

This commit is contained in:
Amine Ben hammou
2017-08-17 12:16:40 +00:00
parent 853f686dde
commit 09ed3d4fa6
3 changed files with 10 additions and 18 deletions

View File

@ -101,11 +101,6 @@ define([
} }
return null; return null;
}, },
isDisabled: function () {
return this.props.item.status == 'sending'
&& this.props.item.queue
&& this.props.item.queue.status == 'paused';
},
loadCachedItems: function () { loadCachedItems: function () {
if(typeof(window['mailpoet_'+this.props.field.endpoint]) !== 'undefined') { if(typeof(window['mailpoet_'+this.props.field.endpoint]) !== 'undefined') {
let items = window['mailpoet_'+this.props.field.endpoint]; let items = window['mailpoet_'+this.props.field.endpoint];
@ -185,7 +180,7 @@ define([
<select <select
id={ this.props.field.id || this.props.field.name } id={ this.props.field.id || this.props.field.name }
ref="select" ref="select"
disabled={this.isDisabled()} disabled={this.props.field.disabled}
data-placeholder={ this.props.field.placeholder } data-placeholder={ this.props.field.placeholder }
multiple={ this.props.field.multiple } multiple={ this.props.field.multiple }
defaultValue={ this.getSelectedValues() } defaultValue={ this.getSelectedValues() }

View File

@ -253,9 +253,12 @@ define(
const isPaused = this.state.item.status == 'sending' const isPaused = this.state.item.status == 'sending'
&& this.state.item.queue && this.state.item.queue
&& this.state.item.queue.status == 'paused'; && this.state.item.queue.status == 'paused';
// const fields = (!isPaused) const fields = this.state.fields.map((field) => {
// ? this.state.fields if (field.name == 'segments' || field.name == 'options') {
// : this.state.fields.filter(field => field.name != 'segments' && field.name != 'options'); field.disabled = isPaused;
}
return field;
});
return ( return (
<div> <div>
<h1>{MailPoet.I18n.t('finalNewsletterStep')}</h1> <h1>{MailPoet.I18n.t('finalNewsletterStep')}</h1>
@ -264,7 +267,7 @@ define(
<Form <Form
id="mailpoet_newsletter" id="mailpoet_newsletter"
fields={ this.state.fields } fields={ fields }
item={ this.state.item } item={ this.state.item }
loading={ this.state.loading } loading={ this.state.loading }
onChange={this.handleFormChange} onChange={this.handleFormChange}

View File

@ -286,11 +286,6 @@ define(
'data-parsley-errors-container': '#mailpoet_scheduling', 'data-parsley-errors-container': '#mailpoet_scheduling',
}; };
}, },
isDisabled: function () {
return this.props.item.status == 'sending'
&& this.props.item.queue
&& this.props.item.queue.status == 'paused';
},
render: function () { render: function () {
let schedulingOptions; let schedulingOptions;
@ -301,7 +296,7 @@ define(
name="scheduledAt" name="scheduledAt"
value={this._getCurrentValue().scheduledAt} value={this._getCurrentValue().scheduledAt}
onChange={this.handleValueChange} onChange={this.handleValueChange}
disabled={this.isDisabled()} disabled={this.props.field.disabled}
dateValidation={this.getDateValidation()} /> dateValidation={this.getDateValidation()} />
&nbsp; &nbsp;
<span> <span>
@ -310,7 +305,6 @@ define(
</span> </span>
); );
} }
return ( return (
<div> <div>
<input <input
@ -318,7 +312,7 @@ define(
type="checkbox" type="checkbox"
value="1" value="1"
checked={this.isScheduled()} checked={this.isScheduled()}
disabled={this.isDisabled()} disabled={this.props.field.disabled}
name="isScheduled" name="isScheduled"
onChange={this.handleCheckboxChange} /> onChange={this.handleCheckboxChange} />