Merge pull request #348 from mailpoet/page_reviews

Page reviews
This commit is contained in:
mrcasual
2016-02-12 13:36:47 -05:00
12 changed files with 139 additions and 68 deletions

View File

@@ -74,10 +74,11 @@ define(
);
}
var custom_actions = this.props.item_actions;
var item_actions = false;
const custom_actions = this.props.item_actions;
let item_actions = false;
if(custom_actions.length > 0) {
let is_first = true;
item_actions = custom_actions.map(function(action, index) {
if(action.display !== undefined) {
if(action.display(this.props.item) === false) {
@@ -85,10 +86,12 @@ define(
}
}
let custom_action = null;
if(action.name === 'trash') {
return (
custom_action = (
<span key={ 'action-'+index } className="trash">
{(index > 0) ? ' | ' : ''}
{(!is_first) ? ' | ' : ''}
<a
href="javascript:;"
onClick={ this.handleTrashItem.bind(
@@ -100,27 +103,27 @@ define(
</span>
);
} else if(action.refresh) {
return (
custom_action = (
<span
onClick={ this.props.onRefreshItems }
key={ 'action-'+index } className={ action.name }>
{(index > 0) ? ' | ' : ''}
{(!is_first) ? ' | ' : ''}
{ action.link(this.props.item) }
</span>
);
} else if(action.link) {
return (
custom_action = (
<span
key={ 'action-'+index } className={ action.name }>
{(index > 0) ? ' | ' : ''}
{(!is_first) ? ' | ' : ''}
{ action.link(this.props.item) }
</span>
);
} else {
return (
custom_action = (
<span
key={ 'action-'+index } className={ action.name }>
{(index > 0) ? ' | ' : ''}
{(!is_first) ? ' | ' : ''}
<a href="javascript:;" onClick={
(action.onClick !== undefined)
? action.onClick.bind(null,
@@ -132,6 +135,12 @@ define(
</span>
);
}
if(custom_action !== null && is_first === true) {
is_first = false;
}
return custom_action;
}.bind(this));
} else {
item_actions = (

View File

@@ -12,7 +12,7 @@ define(
Form
) {
var fields = [
let fields = [
{
name: 'name',
label: 'Name',
@@ -25,7 +25,7 @@ define(
}
];
var messages = {
const messages = {
onUpdate: function() {
MailPoet.Notice.success('Segment successfully updated!');
},
@@ -34,7 +34,7 @@ define(
}
};
var SegmentForm = React.createClass({
const SegmentForm = React.createClass({
mixins: [
Router.History
],

View File

@@ -96,6 +96,9 @@ const item_actions = [
return (
<Link to={ `/edit/${item.id}` }>Edit</Link>
);
},
display: function(segment) {
return (segment.type !== 'wp_users');
}
},
{

View File

@@ -13,9 +13,11 @@ class Renderer {
return $html;
}
static function renderStyles($form = array()) {
static function renderStyles($form = array(), $prefix = null) {
$styles = new Util\Styles(static::getStyles($form));
$html = '<style type="text/css">';
$html .= static::getStyles($form);
$html .= $styles->render($prefix);
$html .= '</style>';
return $html;

View File

@@ -111,7 +111,6 @@ EOL;
private function setStyles($styles) {
$this->_styles = $styles;
return $this;
}

View File

@@ -154,12 +154,14 @@ class Widget extends \WP_Widget {
$output = '';
if(!empty($body)) {
$form_id = $this->id_base.'_'.$this->number;
$data = array(
'form_id' => $this->id_base.'_'.$this->number,
'form_id' => $form_id,
'form_type' => $form_type,
'form' => $form,
'title' => $title,
'styles' => FormRenderer::renderStyles($form),
'styles' => FormRenderer::renderStyles($form, '#'.$form_id),
'html' => FormRenderer::renderHTML($form),
'before_widget' => (!empty($before_widget) ? $before_widget : ''),
'after_widget' => (!empty($after_widget) ? $after_widget : ''),

View File

@@ -41,7 +41,24 @@ class Model extends \Sudzy\ValidModel {
} catch(\Sudzy\ValidationException $e) {
$this->setError($e->getValidationErrors());
} catch(\PDOException $e) {
switch($e->getCode()) {
case 23000:
preg_match("/for key \'(.*?)\'/i", $e->getMessage(), $matches);
if(isset($matches[1])) {
$column = $matches[1];
$this->setError(
sprintf(
__('Another record already exists. Please specify a different "%1$s".'),
$column
)
);
} else {
$this->setError($e->getMessage());
}
break;
default:
$this->setError($e->getMessage());
}
} catch(\Exception $e) {
$this->setError($e->getMessage());
}

View File

@@ -122,6 +122,7 @@ class Segment extends Model {
->group_by(self::$_table.'.id')
->group_by(self::$_table.'.name')
->where(self::$_table.'.type', 'default')
->whereNull(self::$_table.'.deleted_at')
->findArray();
}

View File

@@ -56,7 +56,9 @@ class SegmentCest {
$errors = $result->getErrors();
expect(is_array($errors))->true();
expect($errors[0])->contains('Duplicate');
expect($errors[0])->equals(
'Another record already exists. Please specify a different "name".'
);
}
function itCanHaveDescription() {

View File

@@ -61,7 +61,9 @@ class SegmentsCest {
$router = new Segments();
$response = $router->save($duplicate_entry);
expect($response['result'])->false();
expect($response['errors'][0])->contains('Duplicate');
expect($response['errors'][0])->equals(
'Another record already exists. Please specify a different "name".'
);
}
function itCanRestoreASegment() {

View File

@@ -50,6 +50,8 @@
name="segments"
data-placeholder="<%= __('Choose a list') %>"
multiple
data-parsley-required="true"
data-parsley-required-message="<%= __('You need to select a list.') %>"
>
<% for segment in segments %>
<option value="<%= segment.id %>"><%= segment.name %></option>
@@ -303,19 +305,46 @@
);
// toolbar sections
$(document).on('click', '.mailpoet_toolbar_section.closed', function() {
$(document).on(
'click',
'.mailpoet_toolbar_section.closed',
mailpoet_toolbar_tab
);
function mailpoet_toolbar_tab(tab, callback) {
var section = null;
if($.type(tab) === 'string') {
section = $('.mailpoet_toolbar_section[data-section="'+tab+'"]');
} else {
section = $(this);
}
var current_section = $('.mailpoet_toolbar_section:not(.closed)');
if(current_section.data('section') === section.data('section')) {
if(callback !== undefined && $.type(callback) === 'function') {
callback();
}
} else {
// close currently opened section
$('.mailpoet_toolbar_section:not(.closed)').addClass('closed');
// open selected section after a mini delay
setTimeout(function() {
$(this).removeClass('closed');
}.bind(this), 250);
$(section).removeClass('closed');
if(callback !== undefined && $.type(callback) === 'function') {
setTimeout(function() {
callback();
}, 151);
}
}.bind(this), 150);
}
return false;
});
}
// toolbar: open default section
$('.mailpoet_toolbar_section[data-section="fields"]')
.removeClass('closed');
mailpoet_toolbar_tab('settings');
// form: edit name (in place editor)
$('#mailpoet_form_edit_name').on('click', function() {
@@ -328,7 +357,7 @@
mailpoet_edit_form_name();
return false;
}
})
});
function mailpoet_edit_form_name() {
var is_editing = $('#mailpoet_form_name')
@@ -433,6 +462,11 @@
var form = WysijaForm.save();
form.id = $('#mailpoet_form_id').val();
if(jQuery('#mailpoet_form_settings').parsley().isValid() === false) {
mailpoet_toolbar_tab('settings', function() {
jQuery('#mailpoet_form_settings').parsley().validate();
});
} else {
MailPoet.Ajax.post({
endpoint: 'forms',
action: 'saveEditor',
@@ -474,6 +508,7 @@
}
});
}
}
window.mailpoet_form_save = mailpoet_form_save;
// toolbar: on success toggle
@@ -546,7 +581,7 @@
var name = $(this).siblings('.mailpoet_form_field').attr('wysija_name');
if(window.confirm(
"<%= __('Deleting this field here will delete the data associated to it for all you users. Confirm you want to delete.') %>"
"<%= __('Delete this field for all your subscribers?') %>"
)) {
MailPoet.Ajax.post({
endpoint: 'customFields',

View File

@@ -5,10 +5,9 @@
<h2 class="widget-title"><%= title | raw %></h2>
<% endif %>
<div class="mailpoet_form mailpoet_form_<%= form_type %>">
<div id="<%= form_id %>" class="mailpoet_form mailpoet_form_<%= form_type %>">
<%= styles | raw %>
<form
id="<%= form_id %>"
method="post"
<#
action="<%= admin_url('admin-post.php?action=mailpoet_form_subscribe') | raw %>"