Custom fields
- added listing of custom fields in form editor - ability to delete a custom field - mades changes to the form editor in order to accomodate for the new custom fields system - fix form editor bugs - cleanup
This commit is contained in:
@ -196,7 +196,7 @@ var WysijaHistory = {
|
||||
// check if the field is unique
|
||||
if(parseInt(clone.readAttribute('wysija_unique'), 10) === 1) {
|
||||
// check if the field is already in the queue
|
||||
$(WysijaHistory.container).select('[wysija_field="' + clone.readAttribute('wysija_field') + '"]').invoke('remove');
|
||||
$(WysijaHistory.container).select('[wysija_name="' + clone.readAttribute('wysija_name') + '"]').invoke('remove');
|
||||
}
|
||||
|
||||
// check history size
|
||||
@ -225,7 +225,7 @@ var WysijaHistory = {
|
||||
$(WysijaHistory.container).innerHTML = '';
|
||||
},
|
||||
remove: function(field) {
|
||||
$(WysijaHistory.container).select('[wysija_field="' + field + '"]').invoke('remove');
|
||||
$(WysijaHistory.container).select('[wysija_name="' + field + '"]').invoke('remove');
|
||||
}
|
||||
};
|
||||
|
||||
@ -376,8 +376,8 @@ var WysijaForm = {
|
||||
// get basic field data
|
||||
var data = {
|
||||
type: element.readAttribute('wysija_type'),
|
||||
field: element.readAttribute('wysija_field'),
|
||||
name: element.readAttribute('wysija_name'),
|
||||
id: element.readAttribute('wysija_id'),
|
||||
unique: parseInt(element.readAttribute('wysija_unique') || 0, 10),
|
||||
static: parseInt(element.readAttribute('wysija_static') || 0, 10),
|
||||
element: element,
|
||||
@ -394,16 +394,16 @@ var WysijaForm = {
|
||||
$$('a[wysija_unique="1"]').invoke('removeClassName', 'disabled');
|
||||
|
||||
// loop through each unique field already inserted in the editor and disable its toolbar equivalent
|
||||
$$('#' + WysijaForm.options.editor + ' [wysija_unique="1"]').each(function(element) {
|
||||
var field = $$('#' + WysijaForm.options.toolbar + ' [wysija_field="' + element.readAttribute('wysija_field') + '"]').first();
|
||||
if(field !== undefined) {
|
||||
field.addClassName('disabled');
|
||||
$$('#' + WysijaForm.options.editor + ' [wysija_unique="1"]').map(function(element) {
|
||||
var field = $$('#' + WysijaForm.options.toolbar + ' [wysija_id="' + element.readAttribute('wysija_id') + '"]');
|
||||
if(field.length > 0) {
|
||||
field.first().addClassName('disabled');
|
||||
}
|
||||
});
|
||||
|
||||
// hide list selection if a list widget has been dragged into the editor
|
||||
$('mailpoet_settings_segment_selection')[
|
||||
(($$('#' + WysijaForm.options.editor + ' [wysija_field="segments"]').length > 0) === true)
|
||||
(($$('#' + WysijaForm.options.editor + ' [wysija_id="segments"]').length > 0) === true)
|
||||
? 'hide' : 'show'
|
||||
]();
|
||||
},
|
||||
@ -958,12 +958,10 @@ WysijaForm.Widget = Class.create(WysijaForm.Block, {
|
||||
},
|
||||
getData: function() {
|
||||
var data = WysijaForm.getFieldData(this.element);
|
||||
|
||||
// decode params
|
||||
if(data.params.length > 0) {
|
||||
data.params = JSON.parse(data.params);
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
getControls: function() {
|
||||
|
@ -3,6 +3,7 @@ namespace MailPoet\Config;
|
||||
use \MailPoet\Models\Segment;
|
||||
use \MailPoet\Models\Setting;
|
||||
use \MailPoet\Models\Form;
|
||||
use \MailPoet\Form\Block;
|
||||
use \MailPoet\Form\Renderer as FormRenderer;
|
||||
use \MailPoet\Settings\Hosts;
|
||||
use \MailPoet\Settings\Pages;
|
||||
@ -214,7 +215,9 @@ class Menu {
|
||||
'form' => $form,
|
||||
'pages' => Pages::getAll(),
|
||||
'segments' => Segment::findArray(),
|
||||
'styles' => FormRenderer::getStyles($form)
|
||||
'styles' => FormRenderer::getStyles($form),
|
||||
'date_types' => Block\Date::getDateTypes(),
|
||||
'date_formats' => Block\Date::getDateFormats()
|
||||
);
|
||||
|
||||
echo $this->renderer->render('form/editor.html', $data);
|
||||
|
@ -125,7 +125,8 @@ class Migrator {
|
||||
'segment_id mediumint(9) NOT NULL,',
|
||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||
'PRIMARY KEY (id)'
|
||||
'PRIMARY KEY (id),',
|
||||
'UNIQUE KEY subscriber_segment (subscriber_id,segment_id)'
|
||||
);
|
||||
return $this->sqlify(__FUNCTION__, $attributes);
|
||||
}
|
||||
@ -137,7 +138,8 @@ class Migrator {
|
||||
'segment_id mediumint(9) NOT NULL,',
|
||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||
'PRIMARY KEY (id)'
|
||||
'PRIMARY KEY (id),',
|
||||
'UNIQUE KEY newsletter_segment (newsletter_id,segment_id)'
|
||||
);
|
||||
return $this->sqlify(__FUNCTION__, $attributes);
|
||||
}
|
||||
@ -147,6 +149,7 @@ class Migrator {
|
||||
'id mediumint(9) NOT NULL AUTO_INCREMENT,',
|
||||
'name varchar(90) NOT NULL,',
|
||||
'type varchar(90) NOT NULL,',
|
||||
'params longtext NOT NULL,',
|
||||
'created_at TIMESTAMP NOT NULL DEFAULT 0,',
|
||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||
'PRIMARY KEY (id),',
|
||||
|
@ -9,12 +9,12 @@ abstract class Base {
|
||||
protected static function getInputValidationRules($block) {
|
||||
$rules = array();
|
||||
|
||||
if($block['field'] === 'email') {
|
||||
if($block['name'] === 'email') {
|
||||
$rules[] = 'required';
|
||||
$rules[] = 'custom[email]';
|
||||
}
|
||||
|
||||
if($block['field'] === 'list') {
|
||||
if($block['name'] === 'list') {
|
||||
$rules[] = 'required';
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ abstract class Base {
|
||||
|
||||
// return field name depending on block data
|
||||
protected static function getFieldName($block = array()) {
|
||||
return $block['field'];
|
||||
return $block['id'];
|
||||
}
|
||||
|
||||
protected static function getFieldLabel($block = array()) {
|
||||
|
@ -18,7 +18,7 @@ class Export {
|
||||
// generate url to load iframe's content
|
||||
$iframe_url = add_query_arg(array(
|
||||
'mailpoet_page' => 'mailpoet_form_iframe',
|
||||
'mailpoet_form' => $form['form']
|
||||
'mailpoet_form' => $form['id']
|
||||
), site_url());
|
||||
|
||||
// generate iframe
|
||||
@ -30,7 +30,7 @@ class Export {
|
||||
'class="mailpoet_form_iframe" '.
|
||||
'vspace="0" '.
|
||||
'tabindex="0" '.
|
||||
//'style="position: static; top: 0pt; margin: 0px; border-style: none; height: 330px; left: 0pt; visibility: visible;" '. // TODO: need to find a solution for Height.
|
||||
'onload="javascript:(this.style.height = this.contentWindow.document.body.scrollHeight + \'px\');"'.
|
||||
'marginwidth="0" '.
|
||||
'marginheight="0" '.
|
||||
'hspace="0" '.
|
||||
@ -40,7 +40,7 @@ class Export {
|
||||
case 'php':
|
||||
$output = array(
|
||||
'$form_widget = new \MailPoet\Form\Widget();',
|
||||
'echo $form_widget->widget(array(\'form\' => '.(int)$form['form'].', \'form_type\' => \'php\'));'
|
||||
'echo $form_widget->widget(array(\'form\' => '.(int)$form['id'].', \'form_type\' => \'php\'));'
|
||||
);
|
||||
return join("\n", $output);
|
||||
break;
|
||||
@ -77,14 +77,14 @@ class Export {
|
||||
|
||||
$form_widget = new Widget();
|
||||
$output[] = $form_widget->widget(array(
|
||||
'form' => (int)$form['form'],
|
||||
'form' => (int)$form['id'],
|
||||
'form_type' => 'php'
|
||||
));
|
||||
return join("\n", $output);
|
||||
break;
|
||||
|
||||
case 'shortcode':
|
||||
return '[mailpoet_form id="'.(int)$form['form'].'"]';
|
||||
return '[mailpoet_form id="'.(int)$form['id'].'"]';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ use \MailPoet\Models\Segment;
|
||||
use \MailPoet\Models\Setting;
|
||||
use \MailPoet\Models\Subscriber;
|
||||
use \MailPoet\Form\Renderer as FormRenderer;
|
||||
use \MailPoet\Form\Util;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
@ -160,27 +161,27 @@ class Widget extends \WP_Widget {
|
||||
'title' => $title,
|
||||
'styles' => FormRenderer::renderStyles($form),
|
||||
'html' => FormRenderer::renderHTML($form),
|
||||
'before_widget' => $before_widget,
|
||||
'after_widget' => $after_widget,
|
||||
'before_title' => $before_title,
|
||||
'after_title' => $after_title
|
||||
'before_widget' => (!empty($before_widget) ? $before_widget : ''),
|
||||
'after_widget' => (!empty($after_widget) ? $after_widget : ''),
|
||||
'before_title' => (!empty($before_title) ? $before_title : ''),
|
||||
'after_title' => (!empty($after_title) ? $after_title : '')
|
||||
);
|
||||
|
||||
/*if(isset($_GET['mailpoet_form']) && (int)$_GET['mailpoet_form'] === $form['id']) {
|
||||
// form messages (success / error)
|
||||
$output .= '<div class="mailpoet_message">';
|
||||
// success message
|
||||
if(isset($_GET['mailpoet_success'])) {
|
||||
$output .= '<p class="mailpoet_validate_success">'.strip_tags(urldecode($_GET['mailpoet_success']), '<a><strong><em><br><p>').'</p>';
|
||||
}
|
||||
// error message
|
||||
if(isset($_GET['mailpoet_error'])) {
|
||||
$output .= '<p class="mailpoet_validate_error">'.strip_tags(urldecode($_GET['mailpoet_error']), '<a><strong><em><br><p>').'</p>';
|
||||
}
|
||||
$output .= '</div>';
|
||||
} else {
|
||||
$output .= '<div class="mailpoet_message"></div>';
|
||||
}*/
|
||||
// if(isset($_GET['mailpoet_form']) && (int)$_GET['mailpoet_form'] === $form['id']) {
|
||||
// // form messages (success / error)
|
||||
// $output .= '<div class="mailpoet_message">';
|
||||
// // success message
|
||||
// if(isset($_GET['mailpoet_success'])) {
|
||||
// $output .= '<p class="mailpoet_validate_success">'.strip_tags(urldecode($_GET['mailpoet_success']), '<a><strong><em><br><p>').'</p>';
|
||||
// }
|
||||
// // error message
|
||||
// if(isset($_GET['mailpoet_error'])) {
|
||||
// $output .= '<p class="mailpoet_validate_error">'.strip_tags(urldecode($_GET['mailpoet_error']), '<a><strong><em><br><p>').'</p>';
|
||||
// }
|
||||
// $output .= '</div>';
|
||||
// } else {
|
||||
// $output .= '<div class="mailpoet_message"></div>';
|
||||
// }
|
||||
|
||||
// render form
|
||||
$renderer = new Renderer();
|
||||
@ -226,7 +227,9 @@ if(isset($_GET['mailpoet_page']) && strlen(trim($_GET['mailpoet_page'])) > 0) {
|
||||
|
||||
if($form !== false) {
|
||||
// render form
|
||||
print FormRenderer::getExport('html', $form->asArray());
|
||||
$output = Util\Export::get('html', $form->asArray());
|
||||
// $output = do_shortcode($output);
|
||||
print $output;
|
||||
exit;
|
||||
}
|
||||
break;
|
||||
|
@ -16,6 +16,27 @@ class CustomField extends Model {
|
||||
));
|
||||
}
|
||||
|
||||
function asArray() {
|
||||
$model = parent::asArray();
|
||||
|
||||
$model['params'] = (
|
||||
is_serialized($this->params)
|
||||
? unserialize($this->params)
|
||||
: $this->params
|
||||
);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
function save() {
|
||||
$this->set('params', (
|
||||
is_serialized($this->params)
|
||||
? $this->params
|
||||
: serialize($this->params)
|
||||
));
|
||||
return parent::save();
|
||||
}
|
||||
|
||||
function subscribers() {
|
||||
return $this->has_many_through(
|
||||
__NAMESPACE__ . '\Subscriber',
|
||||
|
164
lib/Router/CustomFields.php
Normal file
164
lib/Router/CustomFields.php
Normal file
@ -0,0 +1,164 @@
|
||||
<?php
|
||||
namespace MailPoet\Router;
|
||||
use \MailPoet\Models\CustomField;
|
||||
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class CustomFields {
|
||||
function __construct() {
|
||||
}
|
||||
|
||||
function getAll() {
|
||||
$collection = CustomField::findMany();
|
||||
$custom_fields = array_map(function($custom_field) {
|
||||
return $custom_field->asArray();
|
||||
}, $collection);
|
||||
|
||||
wp_send_json($custom_fields);
|
||||
}
|
||||
|
||||
function delete($id) {
|
||||
$result = false;
|
||||
|
||||
$custom_field = CustomField::findOne($id);
|
||||
if($custom_field !== false) {
|
||||
$custom_field->delete();
|
||||
$result = true;
|
||||
}
|
||||
|
||||
wp_send_json($result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function get($id) {
|
||||
$custom_field = CustomField::findOne($id);
|
||||
if($custom_field === false) {
|
||||
wp_send_json(false);
|
||||
} else {
|
||||
$custom_field = $custom_field->asArray();
|
||||
wp_send_json($custom_field);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function create() {
|
||||
// create new form
|
||||
$custom_field_data = array(
|
||||
'name' => __('New form'),
|
||||
'body' => array(
|
||||
array(
|
||||
'name' => __('Email'),
|
||||
'type' => 'input',
|
||||
'field' => 'email',
|
||||
'static' => true,
|
||||
'params' => array(
|
||||
'label' => __('Email'),
|
||||
'required' => true
|
||||
)
|
||||
),
|
||||
array(
|
||||
'name' => __('Submit'),
|
||||
'type' => 'submit',
|
||||
'field' => 'submit',
|
||||
'static' => true,
|
||||
'params' => array(
|
||||
'label' => __('Subscribe!')
|
||||
)
|
||||
)
|
||||
),
|
||||
'settings' => array(
|
||||
'on_success' => 'message',
|
||||
'success_message' => __('Check your inbox or spam folder now to confirm your subscription.'),
|
||||
'segments' => null,
|
||||
'segments_selected_by' => 'admin'
|
||||
)
|
||||
);
|
||||
|
||||
$custom_field = CustomField::createOrUpdate($custom_field_data);
|
||||
|
||||
if($custom_field !== false && $custom_field->id()) {
|
||||
wp_send_json(
|
||||
admin_url('admin.php?page=mailpoet-form-editor&id='.$custom_field->id())
|
||||
);
|
||||
} else {
|
||||
wp_send_json(false);
|
||||
}
|
||||
}
|
||||
|
||||
function save($data = array()) {
|
||||
$custom_field = CustomField::createOrUpdate($data);
|
||||
|
||||
if($custom_field !== false && $custom_field->id()) {
|
||||
wp_send_json($custom_field->id());
|
||||
} else {
|
||||
wp_send_json($custom_field);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function restore($id) {
|
||||
$result = false;
|
||||
|
||||
$custom_field = CustomField::findOne($id);
|
||||
if($custom_field !== false) {
|
||||
$result = $custom_field->restore();
|
||||
}
|
||||
|
||||
wp_send_json($result);
|
||||
}
|
||||
|
||||
function trash($id) {
|
||||
$result = false;
|
||||
|
||||
$custom_field = CustomField::findOne($id);
|
||||
if($custom_field !== false) {
|
||||
$result = $custom_field->trash();
|
||||
}
|
||||
|
||||
wp_send_json($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -61,9 +61,9 @@ class Forms {
|
||||
'name' => __('New form'),
|
||||
'body' => array(
|
||||
array(
|
||||
'id' => 'email',
|
||||
'name' => __('Email'),
|
||||
'type' => 'input',
|
||||
'field' => 'email',
|
||||
'static' => true,
|
||||
'params' => array(
|
||||
'label' => __('Email'),
|
||||
@ -71,9 +71,9 @@ class Forms {
|
||||
)
|
||||
),
|
||||
array(
|
||||
'id' => 'submit',
|
||||
'name' => __('Submit'),
|
||||
'type' => 'submit',
|
||||
'field' => 'submit',
|
||||
'static' => true,
|
||||
'params' => array(
|
||||
'label' => __('Subscribe!')
|
||||
@ -109,27 +109,32 @@ class Forms {
|
||||
}
|
||||
}
|
||||
|
||||
function preview($id) {
|
||||
$form = Form::findOne($id);
|
||||
if($form === false) {
|
||||
wp_send_json(false);
|
||||
} else {
|
||||
$form = $form->asArray();
|
||||
|
||||
function previewEditor($data = array()) {
|
||||
// html
|
||||
$html = FormRenderer::renderHTML($form);
|
||||
$html = FormRenderer::renderHTML($data);
|
||||
|
||||
// convert shortcodes
|
||||
$html = do_shortcode($html);
|
||||
|
||||
// styles
|
||||
$css = new Util\Styles(FormRenderer::getStyles($form));
|
||||
$css = new Util\Styles(FormRenderer::getStyles($data));
|
||||
|
||||
wp_send_json(array(
|
||||
'html' => $html,
|
||||
'css' => $css->render()
|
||||
));
|
||||
}
|
||||
|
||||
function exportsEditor($id) {
|
||||
$exports = false;
|
||||
|
||||
$form = Form::findOne($id);
|
||||
|
||||
if($form !== false) {
|
||||
$exports = Util\Export::getAll($form->asArray());
|
||||
}
|
||||
|
||||
wp_send_json($exports);
|
||||
}
|
||||
|
||||
function saveEditor($data = array()) {
|
||||
@ -192,7 +197,7 @@ class Forms {
|
||||
'result' => ($form !== false),
|
||||
'is_widget' => $is_widget
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
function restore($id) {
|
||||
$result = false;
|
||||
@ -242,15 +247,6 @@ class Forms {
|
||||
wp_send_json($result);
|
||||
}
|
||||
|
||||
function itemAction($data = array()) {
|
||||
$item_action = new Listing\ItemAction(
|
||||
'\MailPoet\Models\Form',
|
||||
$data
|
||||
);
|
||||
|
||||
wp_send_json($item_action->apply());
|
||||
}
|
||||
|
||||
function bulkAction($data = array()) {
|
||||
$bulk_action = new Listing\BulkAction(
|
||||
'\MailPoet\Models\Form',
|
||||
|
@ -204,14 +204,6 @@ class Newsletters {
|
||||
wp_send_json($listing_data);
|
||||
}
|
||||
|
||||
function itemAction($data = array()) {
|
||||
$item_action = new Listing\ItemAction(
|
||||
'\MailPoet\Models\Newsletter',
|
||||
$data
|
||||
);
|
||||
wp_send_json($item_action->apply());
|
||||
}
|
||||
|
||||
function bulkAction($data = array()) {
|
||||
$bulk_action = new Listing\BulkAction(
|
||||
'\MailPoet\Models\Newsletter',
|
||||
|
@ -88,11 +88,14 @@ class Subscribers {
|
||||
$errors[] = __('You need to select a list');
|
||||
}
|
||||
|
||||
$subscriber = false;
|
||||
if(!empty($errors)) {
|
||||
wp_send_json(array('errors' => $errors));
|
||||
} else {
|
||||
if(!empty($data['email'])) {
|
||||
$subscriber = Subscriber::where('email', $data['email'])->findOne();
|
||||
}
|
||||
}
|
||||
|
||||
$signup_confirmation = Setting::getValue('signup_confirmation', array());
|
||||
|
||||
@ -180,14 +183,17 @@ class Subscribers {
|
||||
? unserialize($form->settings) : null
|
||||
);
|
||||
|
||||
if($subscriber !== null && empty($errors)) {
|
||||
$result = true;
|
||||
$message = $form_settings['success_message'];
|
||||
if(!empty($errors)) {
|
||||
wp_send_json(array(
|
||||
'result' => false,
|
||||
'errors' => $errors
|
||||
));
|
||||
} else {
|
||||
$result = false;
|
||||
$result = true;
|
||||
}
|
||||
|
||||
if($form_settings !== null) {
|
||||
$message = $form_settings['success_message'];
|
||||
|
||||
// url params for non ajax requests
|
||||
if($doing_ajax === false) {
|
||||
|
@ -121,8 +121,11 @@
|
||||
<div>
|
||||
<!-- Form export links -->
|
||||
<p>
|
||||
<%= __("You can easily add this form to your theme's in the %sWidgets area%s")
|
||||
| format('<a href="widgets.php" target="_blank">', '</a>')
|
||||
<%= __("You can easily add this form to your theme's in the [link]Widgets area[/link]")
|
||||
| replace({
|
||||
'[link]': '<a href="widgets.php" target="_blank">',
|
||||
'[/link]': '</a>'
|
||||
})
|
||||
| raw
|
||||
%>
|
||||
</p>
|
||||
@ -198,34 +201,26 @@
|
||||
var mailpoet_segments = <%= json_encode(segments) %>;
|
||||
|
||||
jQuery(function($) {
|
||||
function mailpoet_form_fields(data) {
|
||||
var template = Handlebars.compile(jQuery('#form_template_fields').html());
|
||||
|
||||
// render toolbar
|
||||
jQuery('#mailpoet_toolbar_fields').html(template(data));
|
||||
|
||||
// enable code mirror editor on styles textarea
|
||||
MailPoet.CodeEditor = CodeMirror.fromTextArea(document.getElementById('mailpoet_form_styles'), {
|
||||
lineNumbers: true,
|
||||
tabMode: "indent",
|
||||
matchBrackets: true,
|
||||
theme: 'neo',
|
||||
mode: 'css',
|
||||
mode: 'css'
|
||||
});
|
||||
}
|
||||
|
||||
// form editor: default fields
|
||||
var default_fields = [
|
||||
{
|
||||
id: 'divider',
|
||||
name: "<%= __('Divider') %>",
|
||||
field: 'divider',
|
||||
type: 'divider',
|
||||
multiple: true,
|
||||
readonly: true
|
||||
},
|
||||
{
|
||||
id: "first_name",
|
||||
name: "<%= __('First name') %>",
|
||||
field: 'first_name',
|
||||
type: 'input',
|
||||
params: {
|
||||
label: "<%= __('First name') %>"
|
||||
@ -233,8 +228,8 @@
|
||||
readonly: true
|
||||
},
|
||||
{
|
||||
id: "last_name",
|
||||
name: "<%= __('Last name') %>",
|
||||
field: 'last_name',
|
||||
type: 'input',
|
||||
params: {
|
||||
label: "<%= __('Last name') %>"
|
||||
@ -242,8 +237,8 @@
|
||||
readonly: true
|
||||
},
|
||||
{
|
||||
id: "segments",
|
||||
name: "<%= __('List selection') %>",
|
||||
field: 'segments',
|
||||
type: 'segment',
|
||||
params: {
|
||||
label: "<%= __('Select list(s):') %>"
|
||||
@ -251,8 +246,8 @@
|
||||
readonly: true
|
||||
},
|
||||
{
|
||||
id: 'html',
|
||||
name: "<%= __('Random text or HTML') %>",
|
||||
field: 'html',
|
||||
type: 'html',
|
||||
params: {
|
||||
text: "<%= __('Subscribe to our newsletter and join our [mailpoet_subscribers_count] subscribers.') %>"
|
||||
@ -262,6 +257,26 @@
|
||||
}
|
||||
];
|
||||
|
||||
function mailpoet_form_fields() {
|
||||
// form editor: default fields
|
||||
var template = Handlebars.compile(jQuery('#form_template_fields').html());
|
||||
|
||||
var data = {
|
||||
fields: default_fields
|
||||
};
|
||||
|
||||
return MailPoet.Ajax.post({
|
||||
endpoint: 'customFields',
|
||||
action: 'getAll',
|
||||
}).done(function(response) {
|
||||
if(response !== false) {
|
||||
data.fields = $.merge(response, data.fields);
|
||||
}
|
||||
// render toolbar
|
||||
jQuery('#mailpoet_toolbar_fields').html(template(data));
|
||||
});
|
||||
}
|
||||
|
||||
// toolbar sections
|
||||
$(document).on('click', '.mailpoet_toolbar_section.closed', function() {
|
||||
// close currently opened section
|
||||
@ -272,7 +287,8 @@
|
||||
});
|
||||
|
||||
// toolbar: open default section
|
||||
$('.mailpoet_toolbar_section[data-section="shortcodes"]').removeClass('closed');
|
||||
// TODO: data-section="settings"
|
||||
$('.mailpoet_toolbar_section[data-section="fields"]').removeClass('closed');
|
||||
|
||||
// form: edit name (in place editor)
|
||||
$('#mailpoet_form_edit_name').on('click', function() {
|
||||
@ -350,20 +366,22 @@
|
||||
// save form
|
||||
$('#mailpoet_form_save').on('click', function() {
|
||||
mailpoet_form_save();
|
||||
mailpoet_form_export();
|
||||
return false;
|
||||
});
|
||||
|
||||
// preview form
|
||||
$(document).on('click', '#mailpoet_form_preview', function() {
|
||||
mailpoet_form_save(mailpoet_form_preview);
|
||||
//mailpoet_form_save(mailpoet_form_preview);
|
||||
mailpoet_form_preview();
|
||||
return false;
|
||||
});
|
||||
|
||||
function mailpoet_form_preview() {
|
||||
MailPoet.Ajax.post({
|
||||
endpoint: 'forms',
|
||||
action: 'preview',
|
||||
data: $('#mailpoet_form_id').val()
|
||||
action: 'previewEditor',
|
||||
data: WysijaForm.save()
|
||||
}).done(function(response) {
|
||||
MailPoet.Modal.popup({
|
||||
title: "<%= __('Form preview') %>",
|
||||
@ -373,8 +391,6 @@
|
||||
})
|
||||
}
|
||||
|
||||
mailpoet_form_export(<%= exports | json_encode | raw %>);
|
||||
|
||||
function mailpoet_form_save(callback) {
|
||||
var form = WysijaForm.save();
|
||||
form.id = $('#mailpoet_form_id').val();
|
||||
@ -429,7 +445,7 @@
|
||||
var template = Handlebars.compile($('#form_template_exports').html());
|
||||
MailPoet.Ajax.post({
|
||||
endpoint: 'forms',
|
||||
action: 'getExports',
|
||||
action: 'exportsEditor',
|
||||
data: $('#mailpoet_form_id').val()
|
||||
}).done(function(response) {
|
||||
if(response !== false) {
|
||||
@ -437,6 +453,7 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
mailpoet_form_export();
|
||||
|
||||
$(document).on('click', '.mailpoet_form_export_toggle', function() {
|
||||
$('.mailpoet_form_export_output').hide();
|
||||
@ -487,27 +504,27 @@
|
||||
|
||||
// delete field
|
||||
$(document).on('click', '.mailpoet_form_field_delete', function() {
|
||||
var field = $(this).data('field');
|
||||
|
||||
if(window.confirm("<%= __('Do you really want to delete this custom field?') %>")) {
|
||||
// delete field
|
||||
console.log('TODO subscriber->meta->delete');
|
||||
/*mailpoet_post_json('subscriber_delete_meta.php', { field: field }, function(response) {
|
||||
var fields = (response.fields !== undefined) ? (response.fields || []) : [];
|
||||
var id = $(this).data('id');
|
||||
var item = $(this).parent();
|
||||
var name = $(this).siblings('.mailpoet_form_field').attr('wysija_name');
|
||||
|
||||
// refresh toolbar
|
||||
mailpoet_form_fields({
|
||||
fields: $.merge(fields, default_fields)
|
||||
});
|
||||
|
||||
// delete field in form
|
||||
// remove any instance of the field present in the form
|
||||
var blocks = $$('#mailpoet_form_body .mailpoet_form_block[wysija_field="'+field+'"]');
|
||||
if(blocks.length > 0) {
|
||||
var block = WysijaForm.get(blocks[0]);
|
||||
block.removeBlock();
|
||||
if(window.confirm(
|
||||
"<%= __('Do you really want to delete this custom field?') %>"
|
||||
)) {
|
||||
MailPoet.Ajax.post({
|
||||
endpoint: 'customFields',
|
||||
action: 'delete',
|
||||
data: id
|
||||
}).done(function(response) {
|
||||
if(response === true) {
|
||||
item.remove();
|
||||
mailpoet_form_fields();
|
||||
MailPoet.Notice.success(
|
||||
"<%= __('Removed custom field “"+name+"“') %>"
|
||||
);
|
||||
}
|
||||
});*/
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -516,11 +533,14 @@
|
||||
// pop last element off the history
|
||||
WysijaHistory.dequeue();
|
||||
|
||||
// init wysija form
|
||||
WysijaForm.init();
|
||||
return false;
|
||||
});
|
||||
|
||||
// get form fields
|
||||
mailpoet_form_fields().done(function() {
|
||||
WysijaForm.init();
|
||||
});
|
||||
|
||||
// toolbar: segment selection
|
||||
var selected_segments = <%= form.settings.segments | json_encode | raw %>;
|
||||
|
||||
@ -535,19 +555,6 @@
|
||||
}
|
||||
}
|
||||
}).select2('val', <%= form.settings.segments | json_encode | raw %>);
|
||||
|
||||
// subscriber meta fields
|
||||
var meta_fields = [
|
||||
// {"name":"CF text input (mandatory + numbers only)","field":"627e1c8d4fe97712836484e0f2377abd","type":"input","params":{"required":"1","validate":"onlyNumberSp","label":"CF text input (mandatory + numbers only)"}},
|
||||
// {"name":"CF text area (no validation)","field":"6607e6e447b89384c59adc124e979d6b","type":"textarea","params":{"required":"","validate":"","label":"CF text area (no validation)"}},
|
||||
// {"name":"CF text area (letters only)","field":"47a9cae88f8b3b3e23a16990922e7905","type":"textarea","params":{"required":"","validate":"onlyLetterSp","label":"CF text area (letters only)"}},
|
||||
// {"name":"CF radio (mandatory)","field":"5f01b4ccc146fdd6b889bab63dc1b5cd","type":"radio","params":{"values":[{"value":"un"},{"is_checked":"1","value":"deux"},{"value":"trois"}],"required":"1","label":"CF radio (mandatory)"}}
|
||||
];
|
||||
|
||||
// toolbar: fiels
|
||||
mailpoet_form_fields({
|
||||
fields: $.merge(meta_fields, default_fields)
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@ -586,8 +593,16 @@
|
||||
<%= 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_formats', 'form/templates/settings/date_formats.hbs') %>
|
||||
<%= partial('field_settings_date_type', 'form/templates/settings/date_types.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') %>
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
<div class="mailpoet_form_block"
|
||||
wysija_type="{{ type }}"
|
||||
wysija_field="{{ field }}"
|
||||
{{#if id}}wysija_id="{{ id }}"{{/if}}
|
||||
wysija_name="{{ name }}"
|
||||
wysija_unique="{{#if multiple}}0{{else}}1{{/if}}"
|
||||
wysija_unique="{{ unique }}"
|
||||
wysija_static="{{#ifCond static '==' 1}}1{{else}}0{{/ifCond}}"
|
||||
wysija_params="{{#if params}}{{ json_encode params }}{{/if}}">
|
||||
{{#ifCond type '!==' 'divider'}}
|
||||
|
@ -31,22 +31,10 @@
|
||||
</option>
|
||||
</select>
|
||||
</p>
|
||||
<p class="mailpoet_error" data-error="type_required">
|
||||
<%= __('You need to select a type.') %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label><%= __("Field's name:") %></label>
|
||||
<input type="text" name="name" value="{{ name }}" />
|
||||
</p>
|
||||
<p class="mailpoet_error" data-error="name_required">
|
||||
<%= __('You need to specify a name.') %>
|
||||
</p>
|
||||
|
||||
<p class="mailpoet_error" data-error="name_already_exists">
|
||||
<%= __('This name is already used.') %>
|
||||
</p>
|
||||
|
||||
<hr />
|
||||
|
||||
<div class="field_type_form"></div>
|
||||
@ -71,6 +59,8 @@
|
||||
$('.mailpoet_error').hide();
|
||||
|
||||
console.log(('TODO: subscriber->meta->edit'));
|
||||
|
||||
console.log(data);
|
||||
// mailpoet_post_json('subscriber_extend.php', data, function(response) {
|
||||
// if(response.error !== undefined) {
|
||||
// // there's an error!
|
||||
|
@ -1,8 +1,8 @@
|
||||
{{#each fields}}
|
||||
<li>
|
||||
<a class="mailpoet_form_field"
|
||||
wysija_field="{{ field }}"
|
||||
wysija_name="{{ name }}"
|
||||
{{#if id }}wysija_id="{{ id }}"{{/if}}
|
||||
wysija_unique="{{#if multiple}}0{{else}}1{{/if}}"
|
||||
wysija_type="{{ type }}"
|
||||
{{#if params}}wysija_params="{{ json_encode params }}"{{/if}}>
|
||||
@ -13,13 +13,13 @@
|
||||
<a class="mailpoet_form_field_edit settings"
|
||||
title="<%= __('Edit field') %>"
|
||||
href="javascript:;"
|
||||
data-field="{{ field }}">
|
||||
data-id="{{ id }}">
|
||||
<span class="dashicons dashicons-admin-generic"></span>
|
||||
</a>
|
||||
<a class="mailpoet_form_field_delete delete"
|
||||
title="<?php _e('Delete field'); ?>"
|
||||
title="<%= __('Delete field') %>"
|
||||
href="javascript:;"
|
||||
data-field="{{ field }}">
|
||||
data-id="{{ id }}">
|
||||
<span class="dashicons dashicons-dismiss"></span>
|
||||
</a>
|
||||
{{/unless}}
|
||||
|
@ -17,10 +17,11 @@
|
||||
|
||||
<input type="hidden" name="form_id" value="<%= form.id %>" />
|
||||
|
||||
<% if not(settings.segments_selected_by == 'user') %>
|
||||
<input type="hidden" name="segments" value="<%= settings.segments | join(',') %>" />
|
||||
<% if not(form.settings.segments_selected_by == 'user') %>
|
||||
<% for segment in form.settings.segments %>
|
||||
<input type="hidden" name="segments[]" value="<%= segment %>" />
|
||||
<% endfor %>
|
||||
<% endif %>
|
||||
|
||||
<%= html | raw %>
|
||||
</form>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user