Change server returned newsletter body to be a json object, not a string
This commit is contained in:
@ -44,10 +44,10 @@ define([
|
||||
};
|
||||
|
||||
Module.getBody = function() {
|
||||
return JSON.stringify({
|
||||
return {
|
||||
content: App._contentContainer.toJSON(),
|
||||
globalStyles: App.getGlobalStyles().toJSON(),
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
Module.toJSON = function() {
|
||||
@ -73,8 +73,7 @@ define([
|
||||
});
|
||||
|
||||
App.on('start', function(options) {
|
||||
// TODO: Other newsletter information will be needed as well.
|
||||
var body = JSON.parse(options.newsletter.body);
|
||||
var body = options.newsletter.body;
|
||||
App._contentContainer = new (App.getBlockTypeModel('container'))(body.content, {parse: true});
|
||||
App._contentContainerView = new (App.getBlockTypeView('container'))({
|
||||
model: App._contentContainer,
|
||||
|
@ -72,7 +72,7 @@ define([
|
||||
|
||||
App.getAvailableStyles = Module.getAvailableStyles;
|
||||
|
||||
var body = JSON.parse(options.newsletter.body);
|
||||
var body = options.newsletter.body;
|
||||
this.setGlobalStyles(body.globalStyles);
|
||||
});
|
||||
|
||||
|
@ -15,16 +15,25 @@ class NewsletterTemplates {
|
||||
if($template === false) {
|
||||
wp_send_json(false);
|
||||
} else {
|
||||
$template->body = json_decode($template->body);
|
||||
wp_send_json($template->asArray());
|
||||
}
|
||||
}
|
||||
|
||||
function getAll() {
|
||||
$collection = NewsletterTemplate::findArray();
|
||||
$collection = array_map(function($item) {
|
||||
$item['body'] = json_decode($item['body']);
|
||||
return $item;
|
||||
}, $collection);
|
||||
wp_send_json($collection);
|
||||
}
|
||||
|
||||
function save($data = array()) {
|
||||
if (isset($data['body'])) {
|
||||
$data['body'] = json_encode($data['body']);
|
||||
}
|
||||
|
||||
$result = NewsletterTemplate::createOrUpdate($data);
|
||||
if($result !== true) {
|
||||
wp_send_json($result);
|
||||
|
@ -33,6 +33,7 @@ class Newsletters {
|
||||
return $segment['id'];
|
||||
}, $segments);
|
||||
$newsletter['options'] = $options;
|
||||
$newsletter['body'] = json_decode($newsletter['body']);
|
||||
|
||||
wp_send_json($newsletter);
|
||||
}
|
||||
@ -40,6 +41,10 @@ class Newsletters {
|
||||
|
||||
function getAll() {
|
||||
$collection = Newsletter::findArray();
|
||||
$collection = array_map(function($item) {
|
||||
$item['body'] = json_decode($item['body']);
|
||||
return $item;
|
||||
}, $collection);
|
||||
wp_send_json($collection);
|
||||
}
|
||||
|
||||
@ -54,6 +59,10 @@ class Newsletters {
|
||||
unset($data['options']);
|
||||
}
|
||||
|
||||
if (isset($data['body'])) {
|
||||
$data['body'] = json_encode($data['body']);
|
||||
}
|
||||
|
||||
$errors = array();
|
||||
$result = false;
|
||||
|
||||
@ -282,6 +291,7 @@ class Newsletters {
|
||||
}
|
||||
}
|
||||
}
|
||||
$newsletter->body = json_decode($newsletter->body);
|
||||
wp_send_json($newsletter->asArray());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user