Merge pull request #582 from mailpoet/custom_field_fix
Custom field fix
This commit is contained in:
@ -127,37 +127,12 @@ define([
|
||||
return;
|
||||
}
|
||||
|
||||
const dateType = this.props.field.params.date_type;
|
||||
const dateParts = value.split('-');
|
||||
let year = '';
|
||||
let month = '';
|
||||
let day = '';
|
||||
|
||||
switch(dateType) {
|
||||
case 'year_month_day':
|
||||
year = ~~(dateParts[0]);
|
||||
month = ~~(dateParts[1]);
|
||||
day = ~~(dateParts[2]);
|
||||
break;
|
||||
|
||||
case 'year_month':
|
||||
year = ~~(dateParts[0]);
|
||||
month = ~~(dateParts[1]);
|
||||
break;
|
||||
|
||||
case 'month':
|
||||
month = ~~(dateParts[0]);
|
||||
break;
|
||||
|
||||
case 'year':
|
||||
year = ~~(dateParts[0]);
|
||||
break;
|
||||
}
|
||||
const dateTime = Moment(value);
|
||||
|
||||
this.setState({
|
||||
year: year,
|
||||
month: month,
|
||||
day: day
|
||||
year: dateTime.format('YYYY'),
|
||||
month: dateTime.format('M'),
|
||||
day: dateTime.format('D')
|
||||
});
|
||||
}
|
||||
formatValue() {
|
||||
@ -228,7 +203,7 @@ define([
|
||||
|
||||
const fields = dateSelects.map(type => {
|
||||
switch(type) {
|
||||
case 'yyyy':
|
||||
case 'YYYY':
|
||||
return (<FormFieldDateYear
|
||||
onValueChange={ this.onValueChange.bind(this) }
|
||||
ref={ 'year' }
|
||||
@ -239,7 +214,7 @@ define([
|
||||
/>);
|
||||
break;
|
||||
|
||||
case 'mm':
|
||||
case 'MM':
|
||||
return (<FormFieldDateMonth
|
||||
onValueChange={ this.onValueChange.bind(this) }
|
||||
ref={ 'month' }
|
||||
@ -251,7 +226,7 @@ define([
|
||||
/>);
|
||||
break;
|
||||
|
||||
case 'dd':
|
||||
case 'DD':
|
||||
return (<FormFieldDateDay
|
||||
onValueChange={ this.onValueChange.bind(this) }
|
||||
ref={ 'day' }
|
||||
|
@ -158,7 +158,7 @@ define(
|
||||
window.location.href = response.data.exportFileURL;
|
||||
}
|
||||
})
|
||||
.error(function (error) {
|
||||
.fail(function (error) {
|
||||
MailPoet.Modal.loading(false);
|
||||
MailPoet.Notice.error(
|
||||
MailPoet.I18n.t('serverError') + error.statusText.toLowerCase() + '.'
|
||||
|
@ -51,6 +51,12 @@ define(
|
||||
* STEP 1 (upload or copy/paste)
|
||||
*/
|
||||
router.on('route:step1', function () {
|
||||
// set or reset temporary validation rule on all columns
|
||||
mailpoetColumns = jQuery.map(mailpoetColumns, function (column, columnIndex) {
|
||||
column.validation_rule = false;
|
||||
return column;
|
||||
});
|
||||
|
||||
if (typeof (importData.step1) !== 'undefined') {
|
||||
showCurrentStep();
|
||||
return;
|
||||
@ -211,7 +217,7 @@ define(
|
||||
}
|
||||
}
|
||||
MailPoet.Modal.loading(false);
|
||||
}).error(function (error) {
|
||||
}).fail(function (error) {
|
||||
MailPoet.Modal.loading(false);
|
||||
MailPoet.Notice.error(
|
||||
MailPoet.I18n.t('serverError') + error.statusText.toLowerCase() + '.'
|
||||
@ -242,7 +248,7 @@ define(
|
||||
MailPoet.Notice.error(response.errors);
|
||||
}
|
||||
MailPoet.Modal.loading(false);
|
||||
}).error(function () {
|
||||
}).fail(function () {
|
||||
MailPoet.Modal.loading(false);
|
||||
MailPoet.Notice.error(
|
||||
MailPoet.I18n.t('serverError') + result.statusText.toLowerCase() + '.'
|
||||
@ -455,7 +461,7 @@ define(
|
||||
null,
|
||||
new Array(subscribers.subscribers[0].length)
|
||||
).map(String.prototype.valueOf, filler),
|
||||
fillterPosition;
|
||||
fillerPosition;
|
||||
|
||||
showCurrentStep();
|
||||
|
||||
@ -631,7 +637,7 @@ define(
|
||||
);
|
||||
}
|
||||
})
|
||||
.error(function (error) {
|
||||
.fail(function (error) {
|
||||
MailPoet.Modal.close();
|
||||
MailPoet.Notice.error(
|
||||
MailPoet.I18n.t('serverError') + error.statusText.toLowerCase() + '.'
|
||||
@ -707,7 +713,7 @@ define(
|
||||
// display filler data (e.g., ellipsis) if we've reached the maximum number of rows and
|
||||
// subscribers count is greater than the maximum number of rows we're displaying
|
||||
if (index === maxRowsToShow && subscribers.subscribersCount > (maxRowsToShow + 1)) {
|
||||
fillterPosition = index;
|
||||
fillerPosition = index;
|
||||
return filler;
|
||||
}
|
||||
// if we're on the last line, show the total count of subscribers data
|
||||
@ -745,70 +751,31 @@ define(
|
||||
.on('select2:selecting', function (selectEvent) {
|
||||
var selectElement = this,
|
||||
selectedOptionId = selectEvent.params.args.data.id;
|
||||
// CREATE CUSTOM FIELD
|
||||
if (selectedOptionId === 'create') {
|
||||
selectEvent.preventDefault();
|
||||
jQuery(selectElement).select2('close');
|
||||
MailPoet.Modal.popup({
|
||||
title: MailPoet.I18n.t('addNewColumn'),
|
||||
template: jQuery('#new_column_template').html()
|
||||
title: MailPoet.I18n.t('addNewField'),
|
||||
template: jQuery('#form_template_field_form').html()
|
||||
});
|
||||
jQuery('#new_column_name').keypress(function (e) {
|
||||
if (e.which == 13) {
|
||||
jQuery('#new_column_process').click();
|
||||
}
|
||||
});
|
||||
jQuery('#new_column_process').click(function () {
|
||||
var name = jQuery('#new_column_name').val().trim(),
|
||||
type = jQuery('#new_column_type').val().trim(),
|
||||
columnNames = mailpoetColumns.map(function (el) {
|
||||
return el.name.toLowerCase();
|
||||
});
|
||||
isDuplicateColumnName =
|
||||
(name && columnNames.indexOf(name.toLowerCase()) > -1)
|
||||
? true
|
||||
: false;
|
||||
if (name === '') {
|
||||
jQuery('.mailpoet_validation_error[data-error="name_required"]')
|
||||
.show();
|
||||
} else {
|
||||
jQuery('.mailpoet_validation_error[data-error="name_required"]')
|
||||
.hide();
|
||||
}
|
||||
if (type === '') {
|
||||
jQuery('.mailpoet_validation_error[data-error="type_required"]')
|
||||
.show();
|
||||
} else {
|
||||
jQuery('.mailpoet_validation_error[data-error="type_required"]')
|
||||
.hide();
|
||||
}
|
||||
if (isDuplicateColumnName) {
|
||||
jQuery('.mailpoet_validation_error[data-error="name_not_unique"]')
|
||||
.show();
|
||||
} else {
|
||||
jQuery('.mailpoet_validation_error[data-error="name_not_unique"]')
|
||||
.hide();
|
||||
}
|
||||
// create new field
|
||||
if (name && type && !isDuplicateColumnName) {
|
||||
MailPoet.Modal
|
||||
.close()
|
||||
.loading(true);
|
||||
MailPoet.Ajax
|
||||
.post({
|
||||
endpoint: 'ImportExport',
|
||||
action: 'addCustomField',
|
||||
data: {
|
||||
name: name,
|
||||
type: type
|
||||
}
|
||||
})
|
||||
.done(function (response) {
|
||||
if (response.result === true) {
|
||||
jQuery('#form_field_new').parsley().on('form:submit', function(parsley) {
|
||||
// get data
|
||||
var data = jQuery(this.$element).serializeObject();
|
||||
|
||||
// save custom field
|
||||
MailPoet.Ajax.post({
|
||||
endpoint: 'customFields',
|
||||
action: 'save',
|
||||
data: data
|
||||
}).done(function(response) {
|
||||
if(response.result === true) {
|
||||
var new_column_data = {
|
||||
'id': response.customField.id,
|
||||
'name': name,
|
||||
'type': type,
|
||||
'custom': true,
|
||||
'id': response.field.id,
|
||||
'name': response.field.name,
|
||||
'type': response.field.type,
|
||||
'params': response.field.params,
|
||||
'custom': true
|
||||
};
|
||||
// if this is the first custom column, create an "optgroup"
|
||||
if (mailpoetColumnsSelect2.length === 2) {
|
||||
@ -836,23 +803,20 @@ define(
|
||||
})
|
||||
});
|
||||
jQuery(selectElement).data('column-id', new_column_data.id);
|
||||
jQuery(selectElement).data('validation-rule', false);
|
||||
filterSubscribers();
|
||||
// close popup
|
||||
MailPoet.Modal.close();
|
||||
}
|
||||
else {
|
||||
MailPoet.Notice.error(MailPoet.I18n.t('customFieldCreateError'));
|
||||
}
|
||||
MailPoet.Modal.loading(false);
|
||||
})
|
||||
.error(function (error) {
|
||||
MailPoet.Modal.loading(false);
|
||||
MailPoet.Notice.error(
|
||||
MailPoet.I18n.t('serverError') + error.statusText.toLowerCase() + '.'
|
||||
);
|
||||
if(response.errors.length > 0) {
|
||||
jQuery(response.errors).each(function(i, error) {
|
||||
MailPoet.Notice.error(error, {positionAfter: '#field_name'});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
jQuery('#new_column_cancel').click(function () {
|
||||
MailPoet.Modal.close();
|
||||
return false;
|
||||
});
|
||||
}
|
||||
// CHANGE COLUMN
|
||||
@ -890,22 +854,22 @@ define(
|
||||
.remove();
|
||||
var subscribersClone = jQuery.extend(true, {}, subscribers),
|
||||
preventNextStep = false,
|
||||
displayedColumnsIds = jQuery.map(
|
||||
jQuery('.mailpoet_subscribers_column_data_match'), function (data) {
|
||||
var columnId = jQuery(data).data('column-id');
|
||||
jQuery(data).val(columnId).trigger('change');
|
||||
return columnId;
|
||||
displayedColumns = jQuery.map(
|
||||
jQuery('.mailpoet_subscribers_column_data_match'), function (element, elementIndex) {
|
||||
var columnId = jQuery(element).data('column-id');
|
||||
var validationRule = jQuery(element).data('validation-rule');
|
||||
jQuery(element).val(columnId).trigger('change');
|
||||
return { id: columnId, index: elementIndex, validationRule: validationRule, element: element };
|
||||
});
|
||||
// iterate through the object of mailpoet columns
|
||||
jQuery.map(mailpoetColumns, function (column) {
|
||||
jQuery.map(mailpoetColumns, function (column, columnIndex) {
|
||||
// check if the column id matches the selected id of one of the
|
||||
// subscriber's data columns
|
||||
var matchedColumn = jQuery.inArray(column.id, displayedColumnsIds);
|
||||
|
||||
// EMAIL filter: if the last value in the column doesn't have a valid
|
||||
var matchedColumn = _.find(displayedColumns, function(data) { return data.id === column.id; });
|
||||
// EMAIL filter: if the first value in the column doesn't have a valid
|
||||
// email, hide the next button
|
||||
if (column.id === "email") {
|
||||
if (!emailRegex.test(subscribersClone.subscribers[0][matchedColumn])) {
|
||||
if (column.id === 'email') {
|
||||
if (!emailRegex.test(subscribersClone.subscribers[0][matchedColumn.index])) {
|
||||
preventNextStep = true;
|
||||
if (!jQuery('[data-id="notice_invalidEmail"]').length) {
|
||||
MailPoet.Notice.error(MailPoet.I18n.t('columnContainsInvalidElement'), {
|
||||
@ -921,35 +885,63 @@ define(
|
||||
}
|
||||
}
|
||||
// DATE filter: if column type is date, check if we can recognize it
|
||||
if (column.type === 'date' && matchedColumn !== -1) {
|
||||
jQuery.map(subscribersClone.subscribers, function (data, position) {
|
||||
var rowData = data[matchedColumn];
|
||||
if (position !== fillterPosition) {
|
||||
if (column.type === 'date' && matchedColumn) {
|
||||
var allowedDateFormats = [
|
||||
Moment.ISO_8601,
|
||||
'YYYY/MM/DD',
|
||||
'MM/DD/YYYY',
|
||||
'DD/MM/YYYY',
|
||||
'YYYY/MM/DD',
|
||||
'YYYY/DD/MM',
|
||||
'MM/YYYY',
|
||||
'YYYY/MM',
|
||||
'YYYY'
|
||||
];
|
||||
var firstRowData = subscribersClone.subscribers[0][matchedColumn.index];
|
||||
var validationRule = false;
|
||||
// check if date exists
|
||||
if (rowData.trim() === '') {
|
||||
data[matchedColumn] =
|
||||
if (firstRowData.trim() === '') {
|
||||
subscribersClone.subscribers[0][matchedColumn.index] =
|
||||
'<span class="mailpoet_data_match mailpoet_import_error" title="'
|
||||
+ MailPoet.I18n.t('noDateFieldMatch') + '">'
|
||||
+ MailPoet.I18n.t('emptyDate')
|
||||
+ MailPoet.I18n.t('emptyFirstRowDate')
|
||||
+ '</span>';
|
||||
preventNextStep = true;
|
||||
return;
|
||||
}
|
||||
// check if date is valid and is before today
|
||||
if (Moment(rowData).isValid() && Moment(rowData).isBefore(Moment())) {
|
||||
data[matchedColumn] +=
|
||||
'<span class="mailpoet_data_match" title="'
|
||||
+ MailPoet.I18n.t('verifyDateMatch') + '">'
|
||||
+ MailPoet.Date.format(rowData) + '</span>';
|
||||
}
|
||||
else {
|
||||
data[matchedColumn] +=
|
||||
for (var format in allowedDateFormats) {
|
||||
var testedFormat = allowedDateFormats[format]
|
||||
if (Moment(firstRowData, testedFormat, true).isValid()) {
|
||||
var validationRule = (typeof(testedFormat) === 'function') ?
|
||||
'datetime' :
|
||||
testedFormat
|
||||
// set validation on the column element
|
||||
jQuery(matchedColumn.element).data('validation-rule', validationRule);
|
||||
break;
|
||||
}
|
||||
if (validationRule === 'datetime') validationRule = Moment.ISO_8601;
|
||||
}
|
||||
}
|
||||
jQuery.map(subscribersClone.subscribers, function (data, index) {
|
||||
var rowData = data[matchedColumn.index];
|
||||
if (index === fillerPosition || rowData.trim() === '') return;
|
||||
var date = Moment(rowData, testedFormat, true);
|
||||
// validate date
|
||||
if (date.isValid()) {
|
||||
data[matchedColumn.index] +=
|
||||
'<span class="mailpoet_data_match" title="'
|
||||
+ MailPoet.I18n.t('verifyDateMatch') + '">'
|
||||
+ MailPoet.Date.format(date)
|
||||
+ '</span>';
|
||||
}
|
||||
else {
|
||||
data[matchedColumn.index] +=
|
||||
'<span class="mailpoet_data_match mailpoet_import_error" title="'
|
||||
+ MailPoet.I18n.t('noDateFieldMatch') + '">'
|
||||
+ MailPoet.I18n.t('dateMatchError') + '</span>';
|
||||
+ MailPoet.I18n.t('dateMatchError')
|
||||
+ '</span>';
|
||||
preventNextStep = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
if (preventNextStep && !jQuery('.mailpoet_invalidDate').length) {
|
||||
MailPoet.Notice.error(MailPoet.I18n.t('columnContainsInvalidDate'), {
|
||||
@ -1019,10 +1011,11 @@ define(
|
||||
_.each(jQuery('select.mailpoet_subscribers_column_data_match'),
|
||||
function (column, columnIndex) {
|
||||
var columnId = jQuery(column).data('column-id');
|
||||
var validationRule = jQuery(column).data('validation-rule');
|
||||
if (columnId === 'ignore') {
|
||||
return;
|
||||
}
|
||||
columns[columnId] = columnIndex;
|
||||
columns[columnId] = { index: columnIndex, validation_rule: validationRule };
|
||||
});
|
||||
|
||||
_.each(subscribers, function () {
|
||||
@ -1051,7 +1044,7 @@ define(
|
||||
}
|
||||
queue.run();
|
||||
})
|
||||
.error(function (error) {
|
||||
.fail(function (error) {
|
||||
importResults.errors.push(
|
||||
MailPoet.I18n.t('serverError') + error.statusText.toLowerCase() + '.'
|
||||
);
|
||||
|
@ -32,22 +32,6 @@ class ImportExport {
|
||||
);
|
||||
}
|
||||
|
||||
function addCustomField($data) {
|
||||
$customField = CustomField::create();
|
||||
$customField->hydrate($data);
|
||||
$result = $customField->save();
|
||||
return (
|
||||
($result) ?
|
||||
array(
|
||||
'result' => true,
|
||||
'customField' => $customField->asArray()
|
||||
) :
|
||||
array(
|
||||
'result' => false
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function processImport($data) {
|
||||
$import = new \MailPoet\Subscribers\ImportExport\Import\Import(
|
||||
json_decode($data, true)
|
||||
|
@ -379,7 +379,12 @@ class Menu {
|
||||
function import() {
|
||||
$import = new ImportExportFactory('import');
|
||||
$data = $import->bootstrap();
|
||||
$data['sub_menu'] = 'mailpoet-subscribers';
|
||||
$data = array_merge($data, array(
|
||||
'date_types' => Block\Date::getDateTypes(),
|
||||
'date_formats' => Block\Date::getDateFormats(),
|
||||
'month_names' => Block\Date::getMonthNames(),
|
||||
'sub_menu' => 'mailpoet-subscribers'
|
||||
));
|
||||
echo $this->renderer->render('subscribers/importExport/import.html', $data);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace MailPoet\Form\Block;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class Date extends Base {
|
||||
|
||||
static function render($block) {
|
||||
@ -65,19 +67,19 @@ class Date extends Base {
|
||||
}
|
||||
|
||||
foreach($date_selectors as $date_selector) {
|
||||
if($date_selector === 'dd') {
|
||||
if($date_selector === 'DD') {
|
||||
$block['selected'] = $day;
|
||||
$html .= '<select class="mailpoet_date_day" ';
|
||||
$html .= 'name="'.$field_name.'[day]" placeholder="'.__('Day').'">';
|
||||
$html .= static::getDays($block);
|
||||
$html .= '</select>';
|
||||
} else if($date_selector === 'mm') {
|
||||
} else if($date_selector === 'MM') {
|
||||
$block['selected'] = $month;
|
||||
$html .= '<select class="mailpoet_date_month" ';
|
||||
$html .= 'name="'.$field_name.'[month]" placeholder="'.__('Month').'">';
|
||||
$html .= static::getMonths($block);
|
||||
$html .= '</select>';
|
||||
} else if($date_selector === 'yyyy') {
|
||||
} else if($date_selector === 'YYYY') {
|
||||
$block['selected'] = $year;
|
||||
$html .= '<select class="mailpoet_date_year" ';
|
||||
$html .= 'name="'.$field_name.'[year]" placeholder="'.__('Year').'">';
|
||||
@ -100,10 +102,10 @@ class Date extends Base {
|
||||
|
||||
static function getDateFormats() {
|
||||
return array(
|
||||
'year_month_day' => array('mm/dd/yyyy', 'dd/mm/yyyy', 'yyyy/mm/dd'),
|
||||
'year_month' => array('mm/yyyy', 'yyyy/mm'),
|
||||
'year' => array('yyyy'),
|
||||
'month' => array('mm')
|
||||
'year_month_day' => array('MM/DD/YYYY', 'DD/MM/YYYY', 'YYYY/MM/DD'),
|
||||
'year_month' => array('MM/YYYY', 'YYYY/MM'),
|
||||
'year' => array('YYYY'),
|
||||
'month' => array('MM')
|
||||
);
|
||||
}
|
||||
static function getMonthNames() {
|
||||
@ -192,4 +194,85 @@ class Date extends Base {
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
static function convertDateToDatetime($date, $date_format) {
|
||||
$datetime = false;
|
||||
if($date_format === 'datetime') {
|
||||
$datetime = $date;
|
||||
} else {
|
||||
$parsed_date = explode('/', $date);
|
||||
$parsed_date_format = explode('/', $date_format);
|
||||
$year_position = array_search('YYYY', $parsed_date_format);
|
||||
$month_position = array_search('MM', $parsed_date_format);
|
||||
$day_position = array_search('DD', $parsed_date_format);
|
||||
if(count($parsed_date) === 3) {
|
||||
// create date from any combination of month, day and year
|
||||
$parsed_date = array(
|
||||
'year' => $parsed_date[$year_position],
|
||||
'month' => $parsed_date[$month_position],
|
||||
'day' => $parsed_date[$day_position]
|
||||
);
|
||||
} else if(count($parsed_date) === 2) {
|
||||
// create date from any combination of month and year
|
||||
$parsed_date = array(
|
||||
'year' => $parsed_date[$year_position],
|
||||
'month' => $parsed_date[$month_position],
|
||||
'day' => '01'
|
||||
);
|
||||
} else if($date_format === 'MM' && count($parsed_date) === 1) {
|
||||
// create date from month
|
||||
if((int)$parsed_date[$month_position] === 0) {
|
||||
$datetime = '';
|
||||
$parsed_date = false;
|
||||
} else {
|
||||
$parsed_date = array(
|
||||
'month' => $parsed_date[$month_position],
|
||||
'day' => '01',
|
||||
'year' => date('Y')
|
||||
);
|
||||
}
|
||||
} else if($date_format === 'YYYY' && count($parsed_date) === 1) {
|
||||
// create date from year
|
||||
if((int)$parsed_date[$year_position] === 0) {
|
||||
$datetime = '';
|
||||
$parsed_date = false;
|
||||
} else {
|
||||
$parsed_date = array(
|
||||
'year' => $parsed_date[$year_position],
|
||||
'month' => '01',
|
||||
'day' => '01'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$parsed_date = false;
|
||||
}
|
||||
if($parsed_date) {
|
||||
$year = $parsed_date['year'];
|
||||
$month = $parsed_date['month'];
|
||||
$day = $parsed_date['day'];
|
||||
// if all date parts are set to 0, date value is empty
|
||||
if((int)$year === 0 && (int)$month === 0 && (int)$day === 0) {
|
||||
$datetime = '';
|
||||
} else {
|
||||
if((int)$year === 0) $year = date('Y');
|
||||
if((int)$month === 0) $month = date('m');
|
||||
if((int)$day === 0) $day = date('d');
|
||||
$datetime = sprintf(
|
||||
'%s-%s-%s 00:00:00',
|
||||
$year,
|
||||
$month,
|
||||
$day
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if($datetime !== false && !empty($datetime)) {
|
||||
try {
|
||||
$datetime = Carbon::parse($datetime)->toDateTimeString();
|
||||
} catch(\Exception $e) {
|
||||
$datetime = false;
|
||||
}
|
||||
}
|
||||
return $datetime;
|
||||
}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace MailPoet\Models;
|
||||
|
||||
use MailPoet\Form\Block\Date;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class CustomField extends Model {
|
||||
@ -43,28 +45,27 @@ class CustomField extends Model {
|
||||
// format custom field data depending on type
|
||||
if(is_array($value) && $this->type === 'date' ) {
|
||||
$custom_field_data = $this->asArray();
|
||||
|
||||
$date_format = $custom_field_data['params']['date_format'];
|
||||
$date_type = (isset($custom_field_data['params']['date_type'])
|
||||
? $custom_field_data['params']['date_type']
|
||||
: 'year_month_day'
|
||||
);
|
||||
$date_parts = explode('_', $date_type);
|
||||
|
||||
switch($date_type) {
|
||||
case 'year_month_day':
|
||||
$value = sprintf(
|
||||
'%04d-%02d-%02d',
|
||||
$value['year'],
|
||||
'%s/%s/%s',
|
||||
$value['month'],
|
||||
$value['day']
|
||||
$value['day'],
|
||||
$value['year']
|
||||
);
|
||||
break;
|
||||
|
||||
case 'year_month':
|
||||
$value = sprintf(
|
||||
'%04d-%02d',
|
||||
$value['year'],
|
||||
$value['month']
|
||||
'%s/%s',
|
||||
$value['month'],
|
||||
$value['year']
|
||||
);
|
||||
break;
|
||||
|
||||
@ -73,12 +74,23 @@ class CustomField extends Model {
|
||||
$value = '';
|
||||
} else {
|
||||
$value = sprintf(
|
||||
'%02d',
|
||||
'%s',
|
||||
$value['month']
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'day':
|
||||
if((int)$value['day'] === 0) {
|
||||
$value = '';
|
||||
} else {
|
||||
$value = sprintf(
|
||||
'%s',
|
||||
$value['day']
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'year':
|
||||
if((int)$value['year'] === 0) {
|
||||
$value = '';
|
||||
@ -90,6 +102,10 @@ class CustomField extends Model {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(!empty($value)) {
|
||||
$value = Date::convertDateToDatetime($value, $date_format);
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace MailPoet\Subscribers\ImportExport\Import;
|
||||
|
||||
use MailPoet\Form\Block\Date;
|
||||
use MailPoet\Models\CustomField;
|
||||
use MailPoet\Models\Newsletter;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Models\SubscriberCustomField;
|
||||
@ -32,16 +34,32 @@ class Import {
|
||||
$this->subscriber_custom_fields = $this->getCustomSubscriberFields(
|
||||
array_keys($data['columns'])
|
||||
);
|
||||
$this->subscriber_fields_validation_rules = $this->getSubscriberFieldsValidationRules(
|
||||
$data['columns']
|
||||
);
|
||||
$this->subscribers_count = count(reset($this->subscribers_data));
|
||||
$this->created_at = date('Y-m-d H:i:s', (int)$data['timestamp']);
|
||||
$this->updated_at = date('Y-m-d H:i:s', (int)$data['timestamp'] + 1);
|
||||
$this->profiler_start = microtime(true);
|
||||
}
|
||||
|
||||
function getSubscriberFieldsValidationRules($subscriber_fields) {
|
||||
$validation_rules = array();
|
||||
foreach($subscriber_fields as $column => $field) {
|
||||
$validation_rules[$column] = (!empty($field['validation_rule'])) ?
|
||||
$field['validation_rule'] :
|
||||
false;
|
||||
}
|
||||
return $validation_rules;
|
||||
}
|
||||
|
||||
function process() {
|
||||
$subscriber_fields = $this->subscriber_fields;
|
||||
$subscriber_custom_fields = $this->subscriber_custom_fields;
|
||||
$subscribers_data = $this->subscribers_data;
|
||||
$subscribers_data = $this->validateSubscribersFields(
|
||||
$this->subscribers_data,
|
||||
$this->subscriber_fields_validation_rules
|
||||
);
|
||||
list ($subscribers_data, $subscriber_fields) =
|
||||
$this->filterSubscriberStatus($subscribers_data, $subscriber_fields);
|
||||
$this->deleteExistingTrashedSubscribers($subscribers_data);
|
||||
@ -98,9 +116,39 @@ class Import {
|
||||
);
|
||||
}
|
||||
|
||||
function validateSubscribersFields($subscribers_data, $validation_rules) {
|
||||
$invalid_records = array();
|
||||
foreach($subscribers_data as $column => &$data) {
|
||||
$validation_rule = $validation_rules[$column];
|
||||
// if this is a custom column
|
||||
if(in_array($column, $this->subscriber_custom_fields)) {
|
||||
$custom_field = CustomField::findOne($column);
|
||||
// validate date type
|
||||
if($custom_field->type === 'date') {
|
||||
$data = array_map(
|
||||
function($index, $date) use($validation_rule, &$invalid_records) {
|
||||
if (empty($date)) return $date;
|
||||
$date = Date::convertDateToDatetime($date, $validation_rule);
|
||||
if(!$date) {
|
||||
$invalid_records[] = $index;
|
||||
}
|
||||
return $date;
|
||||
}, array_keys($data), $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
if($invalid_records) {
|
||||
foreach($subscribers_data as $column => &$data) {
|
||||
$data = array_diff_key($data, array_flip($invalid_records));
|
||||
$data = array_values($data);
|
||||
}
|
||||
}
|
||||
return $subscribers_data;
|
||||
}
|
||||
|
||||
function transformSubscribersData($subscribers, $columns) {
|
||||
foreach($columns as $column => $index) {
|
||||
$transformed_subscribers[$column] = Helpers::arrayColumn($subscribers, $index);
|
||||
foreach($columns as $column => $data) {
|
||||
$transformed_subscribers[$column] = Helpers::arrayColumn($subscribers, $data['index']);
|
||||
}
|
||||
return $transformed_subscribers;
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ class ImportExportFactory {
|
||||
'id' => $field['id'],
|
||||
'name' => $field['name'],
|
||||
'type' => $field['type'],
|
||||
'params' => unserialize($field['params']),
|
||||
'custom' => true
|
||||
);
|
||||
}, $subscriber_custom_fields);
|
||||
|
57
tests/unit/Form/Block/DateTest.php
Normal file
57
tests/unit/Form/Block/DateTest.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
use MailPoet\Form\Block\Date;
|
||||
|
||||
class DateTest extends MailPoetTest {
|
||||
function testItCanConvertDateMonthYearFormatToDatetime() {
|
||||
$date = array(
|
||||
'MM/DD/YYYY' => '05/10/2016',
|
||||
'DD/MM/YYYY' => '10/05/2016',
|
||||
'YYYY/MM/DD' => '2016/05/10',
|
||||
'YYYY/DD/MM' => '2016/10/05'
|
||||
);
|
||||
foreach($date as $date_format => $date) {
|
||||
expect(Date::convertDateToDatetime($date, $date_format))
|
||||
->equals('2016-05-10 00:00:00');
|
||||
}
|
||||
}
|
||||
|
||||
function testItCanConvertMonthYearFormatToDatetime() {
|
||||
$date = array(
|
||||
'MM/YYYY' => '05/2016',
|
||||
'YYYY/MM' => '2016/05'
|
||||
);
|
||||
foreach($date as $date_format => $date) {
|
||||
expect(Date::convertDATEToDatetime($date, $date_format))
|
||||
->equals('2016-05-01 00:00:00');
|
||||
}
|
||||
}
|
||||
|
||||
function testItCanConvertMonthToDatetime() {
|
||||
expect(Date::convertDateToDatetime('05', 'MM'))
|
||||
->equals('2016-05-01 00:00:00');
|
||||
}
|
||||
|
||||
function testItCanConvertYearToDatetime() {
|
||||
expect(Date::convertDateToDatetime('2016', 'YYYY'))
|
||||
->equals('2016-01-01 00:00:00');
|
||||
}
|
||||
|
||||
function testItCanConvertDatetimeToDatetime() {
|
||||
expect(Date::convertDateToDatetime('2016-05-10 00:00:00', 'datetime'))
|
||||
->equals('2016-05-10 00:00:00');
|
||||
}
|
||||
|
||||
function testItCanClearDate() {
|
||||
expect(Date::convertDateToDatetime('0/10/5', 'YYYY/MM/DD'))
|
||||
->equals(date('Y') . '-10-05 00:00:00');
|
||||
expect(Date::convertDateToDatetime('0/0/5', 'YYYY/MM/DD'))
|
||||
->equals(date('Y') . '-' . date('m') . '-05 00:00:00');
|
||||
expect(Date::convertDateToDatetime('0/0/0', 'YYYY/MM/DD'))
|
||||
->equals('');
|
||||
expect(Date::convertDateToDatetime('0', 'YYYY'))
|
||||
->equals('');
|
||||
expect(Date::convertDateToDatetime('0', 'MM'))
|
||||
->equals('');
|
||||
}
|
||||
}
|
@ -169,7 +169,8 @@ class SubscriberTest extends MailPoetTest {
|
||||
'name' => 'Birthday',
|
||||
'type' => 'date',
|
||||
'params' => array(
|
||||
'date_type' => 'year_month_day'
|
||||
'date_type' => 'year_month_day',
|
||||
'date_format' => 'MM/DD/YYYY'
|
||||
)
|
||||
));
|
||||
|
||||
@ -177,7 +178,8 @@ class SubscriberTest extends MailPoetTest {
|
||||
'name' => 'Registered on',
|
||||
'type' => 'date',
|
||||
'params' => array(
|
||||
'date_type' => 'year_month'
|
||||
'date_type' => 'year_month',
|
||||
'date_format' => 'MM/YYYY'
|
||||
)
|
||||
));
|
||||
|
||||
@ -199,7 +201,7 @@ class SubscriberTest extends MailPoetTest {
|
||||
expect($subscriber->email)->equals('user.with.cf@mailpoet.com');
|
||||
expect($subscriber->{'cf_'.$custom_field->id})->equals('Paris');
|
||||
// date specified as array gets converted to string
|
||||
expect($subscriber->{'cf_'.$custom_field_2->id})->equals('1984-03-09');
|
||||
expect($subscriber->{'cf_'.$custom_field_2->id})->equals('1984-03-09 00:00:00');
|
||||
// date specified as string is stored as is
|
||||
expect($subscriber->{'cf_'.$custom_field_3->id})->equals('2013-07');
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use MailPoet\Models\CustomField;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Models\Segment;
|
||||
use MailPoet\Models\SubscriberCustomField;
|
||||
@ -9,6 +10,13 @@ use MailPoet\Util\Helpers;
|
||||
|
||||
class ImportTest extends MailPoetTest {
|
||||
function _before() {
|
||||
$custom_field = CustomField::create();
|
||||
$custom_field->name = 'country';
|
||||
$custom_field->type = 'text';
|
||||
$custom_field->save();
|
||||
$this->subscriber_custom_fields = array((string)$custom_field->id);
|
||||
$this->segment_1 = Segment::createOrUpdate(array('name' => 'Segment 1'));
|
||||
$this->segment_2 = Segment::createOrUpdate(array('name' => 'Segment 2'));
|
||||
$this->data = array(
|
||||
'subscribers' => array(
|
||||
array(
|
||||
@ -25,13 +33,13 @@ class ImportTest extends MailPoetTest {
|
||||
)
|
||||
),
|
||||
'columns' => array(
|
||||
'first_name' => 0,
|
||||
'last_name' => 1,
|
||||
'email' => 2,
|
||||
777 => 3
|
||||
'first_name' => array('index' => 0),
|
||||
'last_name' => array('index' => 1),
|
||||
'email' => array('index' => 2),
|
||||
(string)$custom_field->id => array('index' => 3)
|
||||
),
|
||||
'segments' => array(
|
||||
195
|
||||
$this->segment_1->id
|
||||
),
|
||||
'timestamp' => time(),
|
||||
'updateSubscribers' => true
|
||||
@ -41,10 +49,6 @@ class ImportTest extends MailPoetTest {
|
||||
'last_name',
|
||||
'email'
|
||||
);
|
||||
$this->segment_1 = Segment::createOrUpdate(array('name' => 'Segment 1'));
|
||||
$this->segment_2 = Segment::createOrUpdate(array('name' => 'Segment 2'));
|
||||
|
||||
$this->subscriber_custom_fields = array(777);
|
||||
$this->import = new Import($this->data);
|
||||
$this->subscribers_data = $this->import->transformSubscribersData(
|
||||
$this->data['subscribers'],
|
||||
@ -63,13 +67,14 @@ class ImportTest extends MailPoetTest {
|
||||
}
|
||||
|
||||
function testItCanTransformSubscribers() {
|
||||
$custom_field = $this->subscriber_custom_fields[0];
|
||||
expect($this->import->subscribers_data['first_name'][0])
|
||||
->equals($this->data['subscribers'][0][0]);
|
||||
expect($this->import->subscribers_data['last_name'][0])
|
||||
->equals($this->data['subscribers'][0][1]);
|
||||
expect($this->import->subscribers_data['email'][0])
|
||||
->equals($this->data['subscribers'][0][2]);
|
||||
expect($this->import->subscribers_data['777'][0])
|
||||
expect($this->import->subscribers_data[$custom_field][0])
|
||||
->equals($this->data['subscribers'][0][3]);
|
||||
}
|
||||
|
||||
@ -242,6 +247,7 @@ class ImportTest extends MailPoetTest {
|
||||
|
||||
function testItCanCreateOrUpdateCustomFields() {
|
||||
$subscribers_data = $this->subscribers_data;
|
||||
$custom_field = $this->subscriber_custom_fields[0];
|
||||
$this->import->createOrUpdateSubscribers(
|
||||
'create',
|
||||
$subscribers_data,
|
||||
@ -266,8 +272,8 @@ class ImportTest extends MailPoetTest {
|
||||
$subscriber_custom_fields = SubscriberCustomField::findArray();
|
||||
expect(count($subscriber_custom_fields))->equals(2);
|
||||
expect($subscriber_custom_fields[0]['value'])
|
||||
->equals($subscribers_data[777][0]);
|
||||
$subscribers_data[777][1] = 'Rio';
|
||||
->equals($subscribers_data[$custom_field][0]);
|
||||
$subscribers_data[$custom_field][1] = 'Rio';
|
||||
$this->import->createOrUpdateCustomFields(
|
||||
'update',
|
||||
$db_subscribers,
|
||||
@ -276,7 +282,7 @@ class ImportTest extends MailPoetTest {
|
||||
);
|
||||
$subscriber_custom_fields = SubscriberCustomField::findArray();
|
||||
expect($subscriber_custom_fields[1]['value'])
|
||||
->equals($subscribers_data[777][1]);
|
||||
->equals($subscribers_data[$custom_field][1]);
|
||||
}
|
||||
|
||||
|
||||
@ -345,6 +351,7 @@ class ImportTest extends MailPoetTest {
|
||||
ORM::raw_execute('TRUNCATE ' . Subscriber::$_table);
|
||||
ORM::raw_execute('TRUNCATE ' . Segment::$_table);
|
||||
ORM::raw_execute('TRUNCATE ' . SubscriberSegment::$_table);
|
||||
ORM::raw_execute('TRUNCATE ' . CustomField::$_table);
|
||||
ORM::raw_execute('TRUNCATE ' . SubscriberCustomField::$_table);
|
||||
}
|
||||
}
|
102
views/form/custom_fields.html
Normal file
102
views/form/custom_fields.html
Normal file
@ -0,0 +1,102 @@
|
||||
<!-- date settings and block templates -->
|
||||
<%= partial('form_template_date_years',
|
||||
'form/templates/blocks/date_years.hbs',
|
||||
'_settings_date_years'
|
||||
) %>
|
||||
<%= partial('form_template_date_months',
|
||||
'form/templates/blocks/date_months.hbs',
|
||||
'_settings_date_months'
|
||||
) %>
|
||||
<%= partial('form_template_date_days',
|
||||
'form/templates/blocks/date_days.hbs',
|
||||
'_settings_date_days'
|
||||
) %>
|
||||
<%= partial('form_template_date', 'form/templates/blocks/date.hbs') %>
|
||||
|
||||
<!-- field settings -->
|
||||
<%= partial('form_template_field_settings', 'form/templates/settings/field.hbs') %>
|
||||
|
||||
<%= partial('field_settings_label',
|
||||
'form/templates/settings/label.hbs',
|
||||
'_settings_label'
|
||||
) %>
|
||||
<%= partial('field_settings_label_within',
|
||||
'form/templates/settings/label_within.hbs',
|
||||
'_settings_label_within'
|
||||
) %>
|
||||
<%= partial('field_settings_required',
|
||||
'form/templates/settings/required.hbs',
|
||||
'_settings_required'
|
||||
) %>
|
||||
<%= partial('field_settings_validate',
|
||||
'form/templates/settings/validate.hbs',
|
||||
'_settings_validate'
|
||||
) %>
|
||||
<%= partial('field_settings_values',
|
||||
'form/templates/settings/values.hbs',
|
||||
'_settings_values'
|
||||
) %>
|
||||
<%= partial('field_settings_date_default',
|
||||
'form/templates/settings/date_default.hbs',
|
||||
'_settings_date_default'
|
||||
) %>
|
||||
<%= partial('field_settings_submit',
|
||||
'form/templates/settings/submit.hbs',
|
||||
'_settings_submit'
|
||||
) %>
|
||||
|
||||
<%= partial('field_settings_values_item',
|
||||
'form/templates/settings/values_item.hbs') %>
|
||||
<%= partial(
|
||||
'field_settings_date_format',
|
||||
'form/templates/settings/date_formats.hbs',
|
||||
'_settings_date_format'
|
||||
) %>
|
||||
<%= partial(
|
||||
'field_settings_date_type',
|
||||
'form/templates/settings/date_types.hbs',
|
||||
'_settings_date_type'
|
||||
) %>
|
||||
<%= partial('field_settings_segment_selection_item',
|
||||
'form/templates/settings/segment_selection_item.hbs'
|
||||
) %>
|
||||
<%= partial('field_settings_segment_selection',
|
||||
'form/templates/settings/segment_selection.hbs',
|
||||
'_settings_segment_selection'
|
||||
) %>
|
||||
|
||||
<!-- custom field: new -->
|
||||
<%= partial('form_template_field_form',
|
||||
'form/templates/settings/field_form.hbs'
|
||||
) %>
|
||||
|
||||
<!-- field settings depending on field type -->
|
||||
<script id="form_template_field_text" type="text/x-handlebars-template">
|
||||
{{> _settings_required }}
|
||||
{{> _settings_validate }}
|
||||
</script>
|
||||
|
||||
<script id="form_template_field_textarea" type="text/x-handlebars-template">
|
||||
{{> _settings_required }}
|
||||
{{> _settings_validate }}
|
||||
</script>
|
||||
|
||||
<script id="form_template_field_radio" type="text/x-handlebars-template">
|
||||
{{> _settings_values }}
|
||||
{{> _settings_required }}
|
||||
</script>
|
||||
|
||||
<script id="form_template_field_checkbox" type="text/x-handlebars-template">
|
||||
{{> _settings_values }}
|
||||
{{> _settings_required }}
|
||||
</script>
|
||||
|
||||
<script id="form_template_field_select" type="text/x-handlebars-template">
|
||||
{{> _settings_values }}
|
||||
{{> _settings_required }}
|
||||
</script>
|
||||
|
||||
<script id="form_template_field_date" type="text/x-handlebars-template">
|
||||
{{> _settings_required }}
|
||||
{{> _settings_date_type }}
|
||||
</script>
|
@ -685,110 +685,12 @@
|
||||
<%= partial('form_template_checkbox', 'form/templates/blocks/checkbox.hbs') %>
|
||||
<%= partial('form_template_textarea', 'form/templates/blocks/textarea.hbs') %>
|
||||
<%= partial('form_template_html', 'form/templates/blocks/html.hbs') %>
|
||||
<%= partial('form_template_date_years',
|
||||
'form/templates/blocks/date_years.hbs',
|
||||
'_settings_date_years'
|
||||
) %>
|
||||
<%= partial('form_template_date_months',
|
||||
'form/templates/blocks/date_months.hbs',
|
||||
'_settings_date_months'
|
||||
) %>
|
||||
<%= partial('form_template_date_days',
|
||||
'form/templates/blocks/date_days.hbs',
|
||||
'_settings_date_days'
|
||||
) %>
|
||||
<%= partial('form_template_date', 'form/templates/blocks/date.hbs') %>
|
||||
|
||||
<!-- field settings -->
|
||||
<%= partial('form_template_field_settings', 'form/templates/settings/field.hbs') %>
|
||||
|
||||
<%= partial('field_settings_label',
|
||||
'form/templates/settings/label.hbs',
|
||||
'_settings_label'
|
||||
) %>
|
||||
<%= partial('field_settings_label_within',
|
||||
'form/templates/settings/label_within.hbs',
|
||||
'_settings_label_within'
|
||||
) %>
|
||||
<%= partial('field_settings_required',
|
||||
'form/templates/settings/required.hbs',
|
||||
'_settings_required'
|
||||
) %>
|
||||
<%= partial('field_settings_validate',
|
||||
'form/templates/settings/validate.hbs',
|
||||
'_settings_validate'
|
||||
) %>
|
||||
<%= partial('field_settings_values',
|
||||
'form/templates/settings/values.hbs',
|
||||
'_settings_values'
|
||||
) %>
|
||||
<%= partial('field_settings_date_default',
|
||||
'form/templates/settings/date_default.hbs',
|
||||
'_settings_date_default'
|
||||
) %>
|
||||
<%= partial('field_settings_submit',
|
||||
'form/templates/settings/submit.hbs',
|
||||
'_settings_submit'
|
||||
) %>
|
||||
|
||||
<%= partial('field_settings_values_item',
|
||||
'form/templates/settings/values_item.hbs') %>
|
||||
<%= partial(
|
||||
'field_settings_date_format',
|
||||
'form/templates/settings/date_formats.hbs',
|
||||
'_settings_date_format'
|
||||
) %>
|
||||
<%= partial(
|
||||
'field_settings_date_type',
|
||||
'form/templates/settings/date_types.hbs',
|
||||
'_settings_date_type'
|
||||
) %>
|
||||
<%= partial('field_settings_segment_selection_item',
|
||||
'form/templates/settings/segment_selection_item.hbs'
|
||||
) %>
|
||||
<%= partial('field_settings_segment_selection',
|
||||
'form/templates/settings/segment_selection.hbs',
|
||||
'_settings_segment_selection'
|
||||
) %>
|
||||
|
||||
<!-- custom field: new -->
|
||||
<%= partial('form_template_field_form',
|
||||
'form/templates/settings/field_form.hbs'
|
||||
) %>
|
||||
<!-- custom field settings and templates -->
|
||||
<% include 'form/custom_fields.html' %>
|
||||
|
||||
<!-- form preview -->
|
||||
<%= partial('mailpoet_form_preview_template',
|
||||
'form/templates/preview.hbs'
|
||||
) %>
|
||||
|
||||
<!-- field settings depending on field type -->
|
||||
<script id="form_template_field_text" type="text/x-handlebars-template">
|
||||
{{> _settings_required }}
|
||||
{{> _settings_validate }}
|
||||
</script>
|
||||
|
||||
<script id="form_template_field_textarea" type="text/x-handlebars-template">
|
||||
{{> _settings_required }}
|
||||
{{> _settings_validate }}
|
||||
</script>
|
||||
|
||||
<script id="form_template_field_radio" type="text/x-handlebars-template">
|
||||
{{> _settings_values }}
|
||||
{{> _settings_required }}
|
||||
</script>
|
||||
|
||||
<script id="form_template_field_checkbox" type="text/x-handlebars-template">
|
||||
{{> _settings_values }}
|
||||
{{> _settings_required }}
|
||||
</script>
|
||||
|
||||
<script id="form_template_field_select" type="text/x-handlebars-template">
|
||||
{{> _settings_values }}
|
||||
{{> _settings_required }}
|
||||
</script>
|
||||
|
||||
<script id="form_template_field_date" type="text/x-handlebars-template">
|
||||
{{> _settings_required }}
|
||||
{{> _settings_date_type }}
|
||||
</script>
|
||||
<% endblock %>
|
@ -22,5 +22,7 @@
|
||||
.find('option:selected')
|
||||
.data('format'));
|
||||
});
|
||||
// set default format
|
||||
$('select[name="params[date_type]"]').trigger('change');
|
||||
});
|
||||
<{{!}}/script>
|
@ -43,8 +43,9 @@
|
||||
</select>
|
||||
</p>
|
||||
<p>
|
||||
<label><%= __("Field name:") %></label>
|
||||
<label for="field_name"><%= __("Field name:") %></label>
|
||||
<input
|
||||
id="field_name"
|
||||
type="text"
|
||||
name="name"
|
||||
value="{{ name }}"
|
||||
@ -100,7 +101,7 @@
|
||||
} else {
|
||||
if(response.errors.length > 0) {
|
||||
$(response.errors).each(function(i, error) {
|
||||
MailPoet.Notice.error(error);
|
||||
MailPoet.Notice.error(error, {positionAfter: '#field_name'});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,7 @@
|
||||
'showDetails': __('Show more details'),
|
||||
'segmentSelectionRequired': __('Please select at least one list'),
|
||||
'addNewList': __('Add new list'),
|
||||
'addNewField': __('Add new field'),
|
||||
'addNewColumuserColumnsn': __('Add new list'),
|
||||
'userColumns': __('User fields'),
|
||||
'selectedValueAlreadyMatched': __('The selected value is already matched to another field'),
|
||||
@ -65,7 +66,7 @@
|
||||
'november': __('November'),
|
||||
'december': __('December'),
|
||||
'noDateFieldMatch': __("Do not match as a 'date field' if most of the rows for that field return the same error"),
|
||||
'emptyDate': __('Date cannot be empty'),
|
||||
'emptyFirstRowDate': __('First row date cannot be empty'),
|
||||
'verifyDateMatch': __('Verify that the date in blue matches the original date'),
|
||||
'pm': __('PM'),
|
||||
'am': __('AM'),
|
||||
|
@ -92,7 +92,7 @@
|
||||
{{#show_and_match_columns .}}
|
||||
{{#.}}
|
||||
<th>
|
||||
<select class="mailpoet_subscribers_column_data_match" id="{{column_id}}" data-column-id="{{column_id}}" id="column_{{@index}}">
|
||||
<select class="mailpoet_subscribers_column_data_match" data-column-id="{{column_id}}" data-validation-rule="false" id="column_{{@index}}">
|
||||
</th>
|
||||
{{/.}}
|
||||
{{/show_and_match_columns}}
|
||||
@ -157,57 +157,7 @@
|
||||
</form>
|
||||
</script>
|
||||
|
||||
<!-- New column template -->
|
||||
<script id="new_column_template" type="text/x-handlebars-template">
|
||||
<p>
|
||||
<label><%= __('Field type') %>:</label>
|
||||
<select id="new_column_type" name="type">
|
||||
<option value="">--</option>
|
||||
<option value="input">
|
||||
<%= __('Text Input') %>
|
||||
</option>
|
||||
<option value="textarea">
|
||||
<%= __('Text Area') %>
|
||||
</option>
|
||||
<option value="radio">
|
||||
<%= __('Radio buttons') %>
|
||||
</option>
|
||||
<option value="checkbox">
|
||||
<%= __('Checkbox') %>
|
||||
</option>
|
||||
<option value="select">
|
||||
<%= __('Select') %>
|
||||
</option>
|
||||
<option value="date">
|
||||
<%= __('Date') %>
|
||||
</option>
|
||||
</select>
|
||||
</p>
|
||||
<p class="mailpoet_validation_error" data-error="type_required">
|
||||
<%= __('Please select a type') %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label><%= __('Field name') %>:</label>
|
||||
<input id="new_column_name" type="text" name="name" value="{{ name }}"/>
|
||||
</p>
|
||||
<p class="mailpoet_validation_error" data-error="name_required">
|
||||
<%= __('Please specify a name') %>
|
||||
</p>
|
||||
<p class="mailpoet_validation_error" data-error="name_not_unique">
|
||||
<%= __('This name is already taken') %>
|
||||
</p>
|
||||
|
||||
<hr/>
|
||||
|
||||
<p class="mailpoet_align_right">
|
||||
<input type="submit" value="<%= __('Done') %>" id="new_column_process"
|
||||
class="button-primary "/>
|
||||
<input type="submit" value="<%= __('Cancel') %>" id="new_column_cancel"
|
||||
class="button-primary"/>
|
||||
</p>
|
||||
|
||||
</form>
|
||||
</script>
|
||||
<!-- New custom field logic -->
|
||||
<% include 'form/custom_fields.html' %>
|
||||
</div>
|
||||
</div>
|
Reference in New Issue
Block a user