Include thumbnail on saved templates, add another sample template
This commit is contained in:
@ -47,20 +47,36 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Module.saveTemplate = function(options) {
|
|
||||||
return MailPoet.Ajax.post({
|
|
||||||
endpoint: 'newsletterTemplates',
|
|
||||||
action: 'save',
|
|
||||||
data: _.extend(options || {}, {
|
|
||||||
body: App.getBody(),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Module.getThumbnail = function(element, options) {
|
Module.getThumbnail = function(element, options) {
|
||||||
return html2canvas(element, options || {});
|
return html2canvas(element, options || {});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Module.saveTemplate = function(options) {
|
||||||
|
var that = this,
|
||||||
|
promise = jQuery.Deferred();
|
||||||
|
|
||||||
|
promise.then(function(thumbnail) {
|
||||||
|
var data = _.extend(options || {}, {
|
||||||
|
thumbnail: thumbnail.toDataURL('image/jpeg'),
|
||||||
|
body: App.getBody(),
|
||||||
|
});
|
||||||
|
|
||||||
|
return MailPoet.Ajax.post({
|
||||||
|
endpoint: 'newsletterTemplates',
|
||||||
|
action: 'save',
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
Module.getThumbnail(
|
||||||
|
jQuery('#mailpoet_editor_content > .mailpoet_block').get(0)
|
||||||
|
).then(function(thumbnail) {
|
||||||
|
promise.resolve(thumbnail);
|
||||||
|
});
|
||||||
|
|
||||||
|
return promise;
|
||||||
|
};
|
||||||
|
|
||||||
Module.exportTemplate = function(options) {
|
Module.exportTemplate = function(options) {
|
||||||
var that = this;
|
var that = this;
|
||||||
return Module.getThumbnail(
|
return Module.getThumbnail(
|
||||||
|
@ -1,164 +1,166 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Config;
|
namespace MailPoet\Config;
|
||||||
|
|
||||||
use MailPoet\Config\PopulatorData\Templates\SampleTemplate;
|
use MailPoet\Config\PopulatorData\Templates\FranksRoastHouseTemplate;
|
||||||
use \MailPoet\Models\Segment;
|
use MailPoet\Config\PopulatorData\Templates\BlankTemplate;
|
||||||
use \MailPoet\Segments\WP;
|
use \MailPoet\Models\Segment;
|
||||||
|
use \MailPoet\Segments\WP;
|
||||||
if (!defined('ABSPATH')) exit;
|
|
||||||
|
if (!defined('ABSPATH')) exit;
|
||||||
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
|
||||||
|
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
||||||
class Populator {
|
|
||||||
function __construct() {
|
class Populator {
|
||||||
$this->prefix = Env::$db_prefix;
|
function __construct() {
|
||||||
$this->models = array(
|
$this->prefix = Env::$db_prefix;
|
||||||
'newsletter_option_fields',
|
$this->models = array(
|
||||||
'newsletter_templates',
|
'newsletter_option_fields',
|
||||||
);
|
'newsletter_templates',
|
||||||
}
|
);
|
||||||
|
}
|
||||||
function up() {
|
|
||||||
global $wpdb;
|
function up() {
|
||||||
|
global $wpdb;
|
||||||
$_this = $this;
|
|
||||||
|
$_this = $this;
|
||||||
$populate = function($model) use($_this, $wpdb) {
|
|
||||||
$fields = $_this->$model();
|
$populate = function($model) use($_this, $wpdb) {
|
||||||
$table = $_this->prefix . $model;
|
$fields = $_this->$model();
|
||||||
|
$table = $_this->prefix . $model;
|
||||||
array_map(function($field) use ($wpdb, $table) {
|
|
||||||
$column_conditions = array_map(function($key) use ($field) {
|
array_map(function($field) use ($wpdb, $table) {
|
||||||
return $key . '=' . $field[$key];
|
$column_conditions = array_map(function($key) use ($field) {
|
||||||
}, $field);
|
return $key . '=' . $field[$key];
|
||||||
if ($wpdb->get_var("SELECT COUNT(*) FROM " . $table . " WHERE " . implode(' AND ', $column_conditions)) === 0) {
|
}, $field);
|
||||||
$wpdb->insert(
|
if ($wpdb->get_var("SELECT COUNT(*) FROM " . $table . " WHERE " . implode(' AND ', $column_conditions)) === 0) {
|
||||||
$table,
|
$wpdb->insert(
|
||||||
$field
|
$table,
|
||||||
);
|
$field
|
||||||
}
|
);
|
||||||
}, $fields);
|
}
|
||||||
};
|
}, $fields);
|
||||||
|
};
|
||||||
array_map(array($this, 'populate'), $this->models);
|
|
||||||
|
array_map(array($this, 'populate'), $this->models);
|
||||||
$this->createDefaultSegments();
|
|
||||||
}
|
$this->createDefaultSegments();
|
||||||
|
}
|
||||||
private function createDefaultSegments() {
|
|
||||||
// WP Users segment
|
private function createDefaultSegments() {
|
||||||
$wp_users_segment = Segment::getWPUsers();
|
// WP Users segment
|
||||||
|
$wp_users_segment = Segment::getWPUsers();
|
||||||
if($wp_users_segment === false) {
|
|
||||||
// create the wp users list
|
if($wp_users_segment === false) {
|
||||||
$wp_users_segment = Segment::create();
|
// create the wp users list
|
||||||
$wp_users_segment->hydrate(array(
|
$wp_users_segment = Segment::create();
|
||||||
'name' => __('WordPress Users'),
|
$wp_users_segment->hydrate(array(
|
||||||
'description' =>
|
'name' => __('WordPress Users'),
|
||||||
__('The list containing all of your WordPress users.'),
|
'description' =>
|
||||||
'type' => 'wp_users'
|
__('The list containing all of your WordPress users.'),
|
||||||
));
|
'type' => 'wp_users'
|
||||||
$wp_users_segment->save();
|
));
|
||||||
}
|
$wp_users_segment->save();
|
||||||
|
}
|
||||||
// Synchronize WP Users
|
|
||||||
WP::synchronizeUsers();
|
// Synchronize WP Users
|
||||||
|
WP::synchronizeUsers();
|
||||||
// Default segment
|
|
||||||
if(Segment::where('type', 'default')->count() === 0) {
|
// Default segment
|
||||||
$default_segment = Segment::create();
|
if(Segment::where('type', 'default')->count() === 0) {
|
||||||
$default_segment->hydrate(array(
|
$default_segment = Segment::create();
|
||||||
'name' => __('My First List'),
|
$default_segment->hydrate(array(
|
||||||
'description' =>
|
'name' => __('My First List'),
|
||||||
__('The list created automatically on install of MailPoet')
|
'description' =>
|
||||||
));
|
__('The list created automatically on install of MailPoet')
|
||||||
$default_segment->save();
|
));
|
||||||
}
|
$default_segment->save();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
function newsletter_option_fields() {
|
|
||||||
return array(
|
function newsletter_option_fields() {
|
||||||
array(
|
return array(
|
||||||
'name' => 'event',
|
array(
|
||||||
'newsletter_type' => 'welcome',
|
'name' => 'event',
|
||||||
),
|
'newsletter_type' => 'welcome',
|
||||||
array(
|
),
|
||||||
'name' => 'segment',
|
array(
|
||||||
'newsletter_type' => 'welcome',
|
'name' => 'segment',
|
||||||
),
|
'newsletter_type' => 'welcome',
|
||||||
array(
|
),
|
||||||
'name' => 'role',
|
array(
|
||||||
'newsletter_type' => 'welcome',
|
'name' => 'role',
|
||||||
),
|
'newsletter_type' => 'welcome',
|
||||||
array(
|
),
|
||||||
'name' => 'afterTimeNumber',
|
array(
|
||||||
'newsletter_type' => 'welcome',
|
'name' => 'afterTimeNumber',
|
||||||
),
|
'newsletter_type' => 'welcome',
|
||||||
array(
|
),
|
||||||
'name' => 'afterTimeType',
|
array(
|
||||||
'newsletter_type' => 'welcome',
|
'name' => 'afterTimeType',
|
||||||
),
|
'newsletter_type' => 'welcome',
|
||||||
|
),
|
||||||
array(
|
|
||||||
'name' => 'intervalType',
|
array(
|
||||||
'newsletter_type' => 'notification',
|
'name' => 'intervalType',
|
||||||
),
|
'newsletter_type' => 'notification',
|
||||||
array(
|
),
|
||||||
'name' => 'timeOfDay',
|
array(
|
||||||
'newsletter_type' => 'notification',
|
'name' => 'timeOfDay',
|
||||||
),
|
'newsletter_type' => 'notification',
|
||||||
array(
|
),
|
||||||
'name' => 'weekDay',
|
array(
|
||||||
'newsletter_type' => 'notification',
|
'name' => 'weekDay',
|
||||||
),
|
'newsletter_type' => 'notification',
|
||||||
array(
|
),
|
||||||
'name' => 'monthDay',
|
array(
|
||||||
'newsletter_type' => 'notification',
|
'name' => 'monthDay',
|
||||||
),
|
'newsletter_type' => 'notification',
|
||||||
array(
|
),
|
||||||
'name' => 'nthWeekDay',
|
array(
|
||||||
'newsletter_type' => 'notification',
|
'name' => 'nthWeekDay',
|
||||||
),
|
'newsletter_type' => 'notification',
|
||||||
);
|
),
|
||||||
}
|
);
|
||||||
|
}
|
||||||
private function newsletter_templates() {
|
|
||||||
return array(
|
private function newsletter_templates() {
|
||||||
(new SampleTemplate(Env::$assets_url))->get(),
|
return array(
|
||||||
);
|
(new FranksRoastHouseTemplate(Env::$assets_url))->get(),
|
||||||
}
|
(new BlankTemplate(Env::$assets_url))->get(),
|
||||||
|
);
|
||||||
private function populate($model) {
|
}
|
||||||
$rows = $this->$model();
|
|
||||||
$table = $this->prefix . $model;
|
private function populate($model) {
|
||||||
$_this = $this;
|
$rows = $this->$model();
|
||||||
|
$table = $this->prefix . $model;
|
||||||
array_map(function($row) use ($_this, $table) {
|
$_this = $this;
|
||||||
if (!$_this->rowExists($table, $row)) {
|
|
||||||
$_this->insertRow($table, $row);
|
array_map(function($row) use ($_this, $table) {
|
||||||
}
|
if (!$_this->rowExists($table, $row)) {
|
||||||
}, $rows);
|
$_this->insertRow($table, $row);
|
||||||
}
|
}
|
||||||
|
}, $rows);
|
||||||
private function rowExists($table, $columns) {
|
}
|
||||||
global $wpdb;
|
|
||||||
|
private function rowExists($table, $columns) {
|
||||||
$conditions = array_map(function($key) use ($columns) {
|
global $wpdb;
|
||||||
return $key . '=%s';
|
|
||||||
}, array_keys($columns));
|
$conditions = array_map(function($key) use ($columns) {
|
||||||
|
return $key . '=%s';
|
||||||
return $wpdb->get_var($wpdb->prepare(
|
}, array_keys($columns));
|
||||||
"SELECT COUNT(*) FROM $table WHERE " . implode(' AND ', $conditions),
|
|
||||||
array_values($columns)
|
return $wpdb->get_var($wpdb->prepare(
|
||||||
)) > 0;
|
"SELECT COUNT(*) FROM $table WHERE " . implode(' AND ', $conditions),
|
||||||
}
|
array_values($columns)
|
||||||
|
)) > 0;
|
||||||
private function insertRow($table, $row) {
|
}
|
||||||
global $wpdb;
|
|
||||||
|
private function insertRow($table, $row) {
|
||||||
return $wpdb->insert(
|
global $wpdb;
|
||||||
$table,
|
|
||||||
$row
|
return $wpdb->insert(
|
||||||
);
|
$table,
|
||||||
}
|
$row
|
||||||
}
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
214
lib/Config/PopulatorData/Templates/BlankTemplate.php
Normal file
214
lib/Config/PopulatorData/Templates/BlankTemplate.php
Normal file
File diff suppressed because one or more lines are too long
349
lib/Config/PopulatorData/Templates/FranksRoastHouseTemplate.php
Normal file
349
lib/Config/PopulatorData/Templates/FranksRoastHouseTemplate.php
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -96,7 +96,13 @@ define([
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('triggers template saving when clicked on save as template button', function() {
|
it('triggers template saving when clicked on save as template button', function() {
|
||||||
var mock = sinon.mock({ post: function() {} }).expects('post').once().returns(jQuery.Deferred());
|
var mock = sinon.mock({ post: function() {} }).expects('post').once().returns(jQuery.Deferred()),
|
||||||
|
html2canvasMock = jQuery.Deferred();
|
||||||
|
|
||||||
|
html2canvasMock.resolve({
|
||||||
|
toDataURL: function() { return 'somedataurl'; },
|
||||||
|
});
|
||||||
|
|
||||||
EditorApplication.getBody = sinon.stub();
|
EditorApplication.getBody = sinon.stub();
|
||||||
var module = SaveInjector({
|
var module = SaveInjector({
|
||||||
'mailpoet': {
|
'mailpoet': {
|
||||||
@ -105,6 +111,7 @@ define([
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
'newsletter_editor/App': EditorApplication,
|
'newsletter_editor/App': EditorApplication,
|
||||||
|
'html2canvas': function() { return html2canvasMock; },
|
||||||
});
|
});
|
||||||
var view = new (module.SaveView)();
|
var view = new (module.SaveView)();
|
||||||
view.render();
|
view.render();
|
||||||
|
Reference in New Issue
Block a user