Step 3 sender and reply to per newsletter

- added sender_address/sender_name/reply_to_address/reply_to_name
- added validation on all form fields (except checkbox and radio)
This commit is contained in:
Jonathan Labreuille
2015-12-04 12:29:11 +01:00
parent da6e154642
commit 1950d6661f
9 changed files with 45 additions and 26 deletions

View File

@ -23,7 +23,9 @@ function(
name={ this.props.field.name }
id={ 'field_'+this.props.field.name }
value={ this.props.item[this.props.field.name] }
onChange={ this.props.onValueChange }>
onChange={ this.props.onValueChange }
{...this.props.field.validation}
>
{options}
</select>
);

View File

@ -123,6 +123,7 @@ function(
placeholder={ this.props.field.placeholder }
multiple={ this.props.field.multiple }
defaultValue={ default_value }
{...this.props.field.validation}
>{ options }</select>
);
}

View File

@ -6,6 +6,8 @@ function(
) {
var FormFieldText = React.createClass({
render: function() {
var value = this.props.item[this.props.field.name];
if(!value) { value = null; }
return (
<input
type="text"
@ -17,7 +19,7 @@ function(
}
name={ this.props.field.name }
id={ 'field_'+this.props.field.name }
value={ this.props.item[this.props.field.name] }
value={ value }
placeholder={ this.props.field.placeholder }
defaultValue={ this.props.field.defaultValue }
onChange={ this.props.onValueChange }

View File

@ -15,7 +15,9 @@ function(
value={ this.props.item[this.props.field.name] }
placeholder={ this.props.field.placeholder }
defaultValue={ this.props.field.defaultValue }
onChange={ this.props.onValueChange } />
onChange={ this.props.onValueChange }
{...this.props.field.validation}
/>
);
}
});

View File

@ -68,12 +68,25 @@ define(
handleSubmit: function(e) {
e.preventDefault();
// handle validation
if(this.props.isValid !== undefined) {
if(this.props.isValid() === false) {
return;
}
}
this.setState({ loading: true });
// only get values from displayed fields
item = {};
var item = {};
this.props.fields.map(function(field) {
if(field['fields'] !== undefined) {
field.fields.map(function(subfield) {
item[subfield.name] = this.state.item[subfield.name];
}.bind(this));
} else {
item[field.name] = this.state.item[field.name];
}
}.bind(this));
// set id if specified

View File

@ -45,7 +45,7 @@ define(
tip: "Name & email of yourself or your company.",
fields: [
{
name: 'from_name',
name: 'sender_name',
type: 'text',
placeholder: 'John Doe',
defaultValue: (settings.sender !== undefined) ? settings.sender.name : '',
@ -54,7 +54,7 @@ define(
}
},
{
name: 'from_email',
name: 'sender_address',
type: 'text',
placeholder: 'john.doe@email.com',
defaultValue: (settings.sender !== undefined) ? settings.sender.address : '',
@ -75,12 +75,14 @@ define(
{
name: 'reply_to_name',
type: 'text',
placeholder: 'John Doe'
placeholder: 'John Doe',
defaultValue: (settings.reply_to !== undefined) ? settings.reply_to.name : '',
},
{
name: 'reply_to_email',
name: 'reply_to_address',
type: 'text',
placeholder: 'john.doe@email.com'
placeholder: 'john.doe@email.com',
defaultValue: (settings.reply_to !== undefined) ? settings.reply_to.address : ''
},
]
}
@ -135,6 +137,9 @@ define(
jQuery('#mailpoet_newsletter').parsley();
}
},
isValid: function() {
return (jQuery('#mailpoet_newsletter').parsley().validate());
},
render: function() {
return (
<div>
@ -147,7 +152,8 @@ define(
endpoint="newsletters"
fields={ fields }
params={ this.props.params }
messages={ messages }>
messages={ messages }
isValid={ this.isValid }>
<p className="submit">
<input

View File

@ -320,8 +320,6 @@ class Menu {
}
function newsletters() {
add_filter('heartbeat_received', array($this, 'getQueueStatus'), 10, 3);
global $wp_roles;
$data = array();
@ -332,15 +330,6 @@ class Menu {
echo $this->renderer->render('newsletters.html', $data);
}
function getQueueStatus($response, $data, $screen_id) {
if(isset($data['mailpoet'])) {
$response['mailpoet'] = array(
'hello' => 'world'
);
}
return $response;
}
function newletterEditor() {
$data = array();
wp_enqueue_media();

View File

@ -84,6 +84,10 @@ class Migrator {
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'subject varchar(250) NOT NULL,',
'type varchar(20) NOT NULL DEFAULT "standard",',
'sender_address varchar(150) NOT NULL,',
'sender_name varchar(150) NOT NULL,',
'reply_to_address varchar(150) NOT NULL,',
'reply_to_name varchar(150) NOT NULL,',
'preheader varchar(250) NOT NULL,',
'body longtext,',
'created_at TIMESTAMP NOT NULL DEFAULT 0,',

View File

@ -67,13 +67,13 @@
<label for="settings[notification_reply_name]"><%= __('Reply-to') %></label>
<input type="text"
id="settings[notification_reply_name]"
name="notification[reply_to][name]"
value="<%= settings.notification.reply_to.name %>"
name="reply_to[name]"
value="<%= settings.reply_to.name %>"
placeholder="<%= __('Your name') %>" />
<input type="text"
id="settings[notification_reply_email]"
name="notification[reply_to][address]"
value="<%= settings.notification.reply_to.address %>"
name="reply_to[address]"
value="<%= settings.reply_to.address %>"
placeholder="info@mydomain.com" />
</p>
</td>