List selection & subscribe

- fixed list selection widget (form editor & rendered form)
- ajax subscription works (minus sending the confirmation email)
- bug fixes / polishing / refactoring / cleanup
This commit is contained in:
Jonathan Labreuille
2015-11-05 14:16:44 +01:00
parent a31dce6226
commit 5473f94e24
16 changed files with 287 additions and 405 deletions

View File

@ -402,7 +402,10 @@ var WysijaForm = {
});
// hide list selection if a list widget has been dragged into the editor
$('mailpoet_settings_segment_selection')[(($$('#' + WysijaForm.options.editor + ' [wysija_field="segment"]').length > 0) === true) ? 'hide' : 'show']();
$('mailpoet_settings_segment_selection')[
(($$('#' + WysijaForm.options.editor + ' [wysija_field="segments"]').length > 0) === true)
? 'hide' : 'show'
]();
},
setBlockPositions: function(event, target) {
// release dragging lock
@ -865,11 +868,10 @@ WysijaForm.Block.create = function(block, target) {
if(block.type === 'segment') {
if(block.params.values === undefined) {
var settings_segments = jQuery('#mailpoet_form_segments').val();
if(settings_segments.length > 0){
mailpoet_segments.filter(function(segment) {
if(settings_segments !== null && settings_segments.length > 0){
block.params.values = mailpoet_segments.filter(function(segment) {
return (settings_segments.indexOf(segment.id) !== -1);
});
block.params.values = mailpoet_segments;
}
}
}

View File

@ -505,7 +505,7 @@ define(
MailPoet.Ajax.post({
endpoint: this.props.endpoint,
action: 'bulk_action',
action: 'bulkAction',
data: data
}).done(function(response) {
this.getItems();

View File

@ -8,31 +8,12 @@ define('public', ['mailpoet', 'jquery', 'jquery-validation'],
return (window.location.hostname === link.hostname);
}
function formatData(raw) {
var data = {};
$.each(raw, function(index, value) {
if(value.name.endsWith('[]')) {
var value_name = value.name.substr(0, value.name.length - 2);
// it's an array
if(data[value_name] === undefined) {
data[value_name] = [];
}
data[value_name].push(value.value);
} else {
data[value.name] = value.value;
}
});
return data;
}
$(function() {
// setup form validation
$('form.mailpoet_form').each(function() {
$(this).validate({
submitHandler: function(form) {
var data = $(form).serializeArray() || {};
var data = $(form).serializeObject() || {};
// clear messages
$(form).find('.mailpoet_message').html('');
@ -47,12 +28,12 @@ define('public', ['mailpoet', 'jquery', 'jquery-validation'],
url: MailPoetForm.ajax_url,
token: MailPoetForm.token,
endpoint: 'subscribers',
action: 'save',
data: formatData(data),
action: 'subscribe',
data: data,
onSuccess: function(response) {
if(response !== true) {
if(response.result !== true) {
// errors
$.each(response, function(index, error) {
$.each(response.errors, function(index, error) {
$(form)
.find('.mailpoet_message')
.append('<p class="mailpoet_validate_error">'+