creating new ALC block and widget

This commit is contained in:
Amine Ben hammou
2018-05-23 07:37:34 +00:00
parent 4dd17e47ad
commit 0a298f5fad
11 changed files with 845 additions and 18 deletions

View File

@@ -53,7 +53,8 @@ $three-column-width = ($newsletter-width / 3) - (2 * $column-margin)
// More than one column
& > .mailpoet_container_block > .mailpoet_container > .mailpoet_container_block > .mailpoet_container_horizontal,
& > .mailpoet_container_block > .mailpoet_container > .mailpoet_posts_block > .mailpoet_posts_container > .mailpoet_container_block > .mailpoet_container > .mailpoet_container_block > .mailpoet_container_horizontal
& > .mailpoet_container_block > .mailpoet_container > .mailpoet_posts_block > .mailpoet_posts_container > .mailpoet_container_block > .mailpoet_container > .mailpoet_container_block > .mailpoet_container_horizontal,
& > .mailpoet_container_block > .mailpoet_container .mailpoet_automated_latest_content_block_posts .mailpoet_container_horizontal
// Column number detection technique found here:
// http://stackoverflow.com/questions/8720931/can-css-detect-the-number-of-children-an-element-has

View File

@@ -74,6 +74,7 @@ define([
defaults: function () {
return this._getDefaults({
type: 'automatedLatestContent',
withLayout: false,
amount: '5',
contentType: 'post', // 'post'|'page'|'mailpoet_page'
terms: [], // List of category and tag objects
@@ -385,12 +386,6 @@ define([
blockModel: Module.AutomatedLatestContentBlockModel,
blockView: Module.AutomatedLatestContentBlockView
});
BeforeStartApp.registerWidget({
name: 'automatedLatestContent',
widgetView: Module.AutomatedLatestContentWidgetView,
priority: 97
});
});
App.on('start', function (StartApp) {

View File

@@ -0,0 +1,400 @@
/* eslint-disable func-names */
/**
* Automated latest content block with image alignment.
*/
define([
'newsletter_editor/App',
'newsletter_editor/blocks/base',
'newsletter_editor/blocks/button',
'newsletter_editor/blocks/divider',
'newsletter_editor/components/communication',
'mailpoet',
'backbone.supermodel',
'underscore',
'jquery'
], function (
App,
BaseBlock,
ButtonBlock,
DividerBlock,
CommunicationComponent,
MailPoet,
SuperModel,
_,
jQuery
) {
'use strict';
var Module = {};
var base = BaseBlock;
Module.ALCLayoutSupervisor = SuperModel.extend({
initialize: function () {
var DELAY_REFRESH_FOR_MS = 500;
this.listenTo(
App.getChannel(),
'automatedLatestContentLayoutRefresh',
_.debounce(this.refresh, DELAY_REFRESH_FOR_MS)
);
},
refresh: function () {
var blocks;
var models = App.findModels(function (model) {
return model.get('type') === 'automatedLatestContentLayout';
}) || [];
if (models.length === 0) return;
blocks = _.map(models, function (model) {
return model.toJSON();
});
CommunicationComponent.getBulkTransformedPosts({
blocks: blocks
}).then(_.partial(this.refreshBlocks, models));
},
refreshBlocks: function (models, renderedBlocks) {
_.each(
_.zip(models, renderedBlocks),
function (args) {
var model = args[0];
var contents = args[1];
model.trigger('refreshPosts', contents);
}
);
}
});
Module.AutomatedLatestContentLayoutBlockModel = base.BlockModel.extend({
stale: ['_container'],
defaults: function () {
return this._getDefaults({
type: 'automatedLatestContentLayout',
withLayout: true,
amount: '5',
contentType: 'post', // 'post'|'page'|'mailpoet_page'
terms: [], // List of category and tag objects
inclusionType: 'include', // 'include'|'exclude'
displayType: 'excerpt', // 'excerpt'|'full'|'titleOnly'
titleFormat: 'h1', // 'h1'|'h2'|'h3'|'ul'
titleAlignment: 'left', // 'left'|'center'|'right'
titleIsLink: false, // false|true
imageFullWidth: false, // true|false
featuredImagePosition: 'centered', // 'centered'|'left'|'right'|'alternate'|'none'
showAuthor: 'no', // 'no'|'aboveText'|'belowText'
authorPrecededBy: 'Author:',
showCategories: 'no', // 'no'|'aboveText'|'belowText'
categoriesPrecededBy: 'Categories:',
readMoreType: 'button', // 'link'|'button'
readMoreText: 'Read more', // 'link'|'button'
readMoreButton: {
text: 'Read more',
url: '[postLink]'
},
sortBy: 'newest', // 'newest'|'oldest',
showDivider: true, // true|false
divider: {},
_container: new (App.getBlockTypeModel('container'))()
}, App.getConfig().get('blockDefaults.automatedLatestContentLayout'));
},
relations: function () {
return {
readMoreButton: App.getBlockTypeModel('button'),
divider: App.getBlockTypeModel('divider'),
_container: App.getBlockTypeModel('container')
};
},
initialize: function () {
base.BlockView.prototype.initialize.apply(this, arguments);
this.on('change:amount change:contentType change:terms change:inclusionType change:displayType change:titleFormat change:featuredImagePosition change:titleAlignment change:titleIsLink change:imageFullWidth change:showAuthor change:authorPrecededBy change:showCategories change:categoriesPrecededBy change:readMoreType change:readMoreText change:sortBy change:showDivider', this._handleChanges, this);
this.listenTo(this.get('readMoreButton'), 'change', this._handleChanges);
this.listenTo(this.get('divider'), 'change', this._handleChanges);
this.on('add remove update reset', this._handleChanges);
this.on('refreshPosts', this.updatePosts, this);
},
updatePosts: function (posts) {
this.get('_container.blocks').reset(posts, { parse: true });
},
/**
* Batch more changes during a specific time, instead of fetching
* ALC posts on each model change
*/
_handleChanges: function () {
this._updateDefaults();
App.getChannel().trigger('automatedLatestContentLayoutRefresh');
}
});
Module.AutomatedLatestContentLayoutBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_automated_latest_content_block mailpoet_droppable_block',
initialize: function () {
function replaceButtonStylesHandler(data) {
this.model.set({ readMoreButton: data });
}
App.getChannel().on('replaceAllButtonStyles', replaceButtonStylesHandler.bind(this));
},
getTemplate: function () { return window.templates.automatedLatestContentLayoutBlock; },
regions: {
toolsRegion: '.mailpoet_tools',
postsRegion: '.mailpoet_automated_latest_content_block_posts'
},
modelEvents: _.extend(
_.omit(base.BlockView.prototype.modelEvents, 'change'),
{
postsChanged: 'render'
}),
events: _.extend(base.BlockView.prototype.events, {
'click .mailpoet_automated_latest_content_block_overlay': 'showSettings'
}),
onDragSubstituteBy: function () { return Module.AutomatedLatestContentLayoutWidgetView; },
onRender: function () {
var ContainerView = App.getBlockTypeView('container');
var renderOptions = {
disableTextEditor: true,
disableDragAndDrop: true,
emptyContainerMessage: MailPoet.I18n.t('noPostsToDisplay')
};
this.toolsView = new Module.AutomatedLatestContentLayoutBlockToolsView({ model: this.model });
this.showChildView('toolsRegion', this.toolsView);
this.showChildView('postsRegion', new ContainerView({ model: this.model.get('_container'), renderOptions: renderOptions }));
}
});
Module.AutomatedLatestContentLayoutBlockToolsView = base.BlockToolsView.extend({
getSettingsView: function () { return Module.AutomatedLatestContentLayoutBlockSettingsView; }
});
// Sidebar view container
Module.AutomatedLatestContentLayoutBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function () { return window.templates.automatedLatestContentLayoutBlockSettings; },
events: function () {
return {
'click .mailpoet_automated_latest_content_hide_display_options': 'toggleDisplayOptions',
'click .mailpoet_automated_latest_content_show_display_options': 'toggleDisplayOptions',
'click .mailpoet_automated_latest_content_select_button': 'showButtonSettings',
'click .mailpoet_automated_latest_content_select_divider': 'showDividerSettings',
'change .mailpoet_automated_latest_content_read_more_type': 'changeReadMoreType',
'change .mailpoet_automated_latest_content_display_type': 'changeDisplayType',
'change .mailpoet_automated_latest_content_title_format': 'changeTitleFormat',
'change .mailpoet_automated_latest_content_title_as_links': _.partial(this.changeBoolField, 'titleIsLink'),
'change .mailpoet_automated_latest_content_show_divider': _.partial(this.changeBoolField, 'showDivider'),
'input .mailpoet_automated_latest_content_show_amount': _.partial(this.changeField, 'amount'),
'change .mailpoet_automated_latest_content_content_type': _.partial(this.changeField, 'contentType'),
'change .mailpoet_automated_latest_content_include_or_exclude': _.partial(this.changeField, 'inclusionType'),
'change .mailpoet_automated_latest_content_title_alignment': _.partial(this.changeField, 'titleAlignment'),
'change .mailpoet_automated_latest_content_image_full_width': _.partial(this.changeBoolField, 'imageFullWidth'),
'change .mailpoet_automated_latest_content_featured_image_position': _.partial(this.changeField, 'featuredImagePosition'),
'change .mailpoet_automated_latest_content_show_author': _.partial(this.changeField, 'showAuthor'),
'input .mailpoet_automated_latest_content_author_preceded_by': _.partial(this.changeField, 'authorPrecededBy'),
'change .mailpoet_automated_latest_content_show_categories': _.partial(this.changeField, 'showCategories'),
'input .mailpoet_automated_latest_content_categories': _.partial(this.changeField, 'categoriesPrecededBy'),
'input .mailpoet_automated_latest_content_read_more_text': _.partial(this.changeField, 'readMoreText'),
'change .mailpoet_automated_latest_content_sort_by': _.partial(this.changeField, 'sortBy'),
'click .mailpoet_done_editing': 'close'
};
},
onRender: function () {
var that = this;
// Dynamically update available post types
CommunicationComponent.getPostTypes().done(_.bind(this._updateContentTypes, this));
this.$('.mailpoet_automated_latest_content_categories_and_tags').select2({
multiple: true,
allowClear: true,
placeholder: MailPoet.I18n.t('categoriesAndTags'),
ajax: {
data: function (params) {
return {
term: params.term
};
},
transport: function (options, success, failure) {
var taxonomies;
var termsPromise;
var promise = CommunicationComponent.getTaxonomies(
that.model.get('contentType')
).then(function (tax) {
taxonomies = tax;
// Fetch available terms based on the list of taxonomies already fetched
termsPromise = CommunicationComponent.getTerms({
search: options.data.term,
taxonomies: _.keys(taxonomies)
}).then(function (terms) {
return {
taxonomies: taxonomies,
terms: terms
};
});
return termsPromise;
});
promise.then(success);
promise.fail(failure);
return promise;
},
processResults: function (data) {
// Transform taxonomies and terms into select2 compatible format
return {
results: _.map(
data.terms,
function (item) {
return _.defaults({
text: data.taxonomies[item.taxonomy].labels.singular_name + ': ' + item.name,
id: item.term_id
}, item);
}
)
};
}
}
}).on({
'select2:select': function (event) {
var terms = that.model.get('terms');
terms.add(event.params.data);
// Reset whole model in order for change events to propagate properly
that.model.set('terms', terms.toJSON());
},
'select2:unselect': function (event) {
var terms = that.model.get('terms');
terms.remove(event.params.data);
// Reset whole model in order for change events to propagate properly
that.model.set('terms', terms.toJSON());
}
}).trigger('change');
},
toggleDisplayOptions: function () {
var el = this.$('.mailpoet_automated_latest_content_display_options');
var showControl = this.$('.mailpoet_automated_latest_content_show_display_options');
if (el.hasClass('mailpoet_closed')) {
el.removeClass('mailpoet_closed');
showControl.addClass('mailpoet_hidden');
} else {
el.addClass('mailpoet_closed');
showControl.removeClass('mailpoet_hidden');
}
},
showButtonSettings: function () {
var buttonModule = ButtonBlock;
(new buttonModule.ButtonBlockSettingsView({
model: this.model.get('readMoreButton'),
renderOptions: {
displayFormat: 'subpanel',
hideLink: true,
hideApplyToAll: true
}
})).render();
},
showDividerSettings: function () {
var dividerModule = DividerBlock;
(new dividerModule.DividerBlockSettingsView({
model: this.model.get('divider'),
renderOptions: {
displayFormat: 'subpanel',
hideApplyToAll: true
}
})).render();
},
changeReadMoreType: function (event) {
var value = jQuery(event.target).val();
if (value === 'link') {
this.$('.mailpoet_automated_latest_content_read_more_text').removeClass('mailpoet_hidden');
this.$('.mailpoet_automated_latest_content_select_button').addClass('mailpoet_hidden');
} else if (value === 'button') {
this.$('.mailpoet_automated_latest_content_read_more_text').addClass('mailpoet_hidden');
this.$('.mailpoet_automated_latest_content_select_button').removeClass('mailpoet_hidden');
}
this.changeField('readMoreType', event);
},
changeDisplayType: function (event) {
var value = jQuery(event.target).val();
if (value === 'titleOnly') {
this.$('.mailpoet_automated_latest_content_title_as_list').removeClass('mailpoet_hidden');
this.$('.mailpoet_automated_latest_content_image_full_width_option').addClass('mailpoet_hidden');
this.$('.mailpoet_automated_latest_content_image_separator').addClass('mailpoet_hidden');
} else {
this.$('.mailpoet_automated_latest_content_title_as_list').addClass('mailpoet_hidden');
this.$('.mailpoet_automated_latest_content_image_full_width_option').removeClass('mailpoet_hidden');
this.$('.mailpoet_automated_latest_content_image_separator').removeClass('mailpoet_hidden');
// Reset titleFormat if it was set to List when switching away from displayType=titleOnly
if (this.model.get('titleFormat') === 'ul') {
this.model.set('titleFormat', 'h1');
this.$('.mailpoet_automated_latest_content_title_format').val(['h1']);
this.$('.mailpoet_automated_latest_content_title_as_link').removeClass('mailpoet_hidden');
}
}
if (value === 'excerpt') {
this.$('.mailpoet_automated_latest_content_featured_image_position_container').removeClass('mailpoet_hidden');
} else {
this.$('.mailpoet_automated_latest_content_featured_image_position_container').addClass('mailpoet_hidden');
}
this.changeField('displayType', event);
},
changeTitleFormat: function (event) {
var value = jQuery(event.target).val();
if (value === 'ul') {
this.$('.mailpoet_automated_latest_content_non_title_list_options').addClass('mailpoet_hidden');
this.model.set('titleIsLink', true);
this.$('.mailpoet_automated_latest_content_title_as_link').addClass('mailpoet_hidden');
this.$('.mailpoet_automated_latest_content_title_as_links').val(['true']);
} else {
this.$('.mailpoet_automated_latest_content_non_title_list_options').removeClass('mailpoet_hidden');
this.$('.mailpoet_automated_latest_content_title_as_link').removeClass('mailpoet_hidden');
}
this.changeField('titleFormat', event);
},
_updateContentTypes: function (postTypes) {
var select = this.$('.mailpoet_automated_latest_content_content_type');
var selectedValue = this.model.get('contentType');
select.find('option').remove();
_.each(postTypes, function (type) {
select.append(jQuery('<option>', {
value: type.name,
text: type.label
}));
});
select.val(selectedValue);
}
});
Module.AutomatedLatestContentLayoutWidgetView = base.WidgetView.extend({
className: base.WidgetView.prototype.className + ' mailpoet_droppable_layout_block',
getTemplate: function () { return window.templates.automatedLatestContentLayoutInsertion; },
behaviors: {
DraggableBehavior: {
cloneOriginal: true,
drop: function () {
return new Module.AutomatedLatestContentLayoutBlockModel({}, { parse: true });
},
onDrop: function (options) {
options.droppedView.triggerMethod('showSettings');
}
}
}
});
App.on('before:start', function (BeforeStartApp) {
BeforeStartApp.registerBlockType('automatedLatestContentLayout', {
blockModel: Module.AutomatedLatestContentLayoutBlockModel,
blockView: Module.AutomatedLatestContentLayoutBlockView
});
BeforeStartApp.registerWidget({
name: 'automatedLatestContentLayout',
widgetView: Module.AutomatedLatestContentLayoutWidgetView,
priority: 97
});
});
App.on('start', function (StartApp) {
var Application = StartApp;
Application._ALCLayoutSupervisor = new Module.ALCLayoutSupervisor();
Application._ALCLayoutSupervisor.refresh();
});
return Module;
});

View File

@@ -11,15 +11,17 @@ if(!defined('ABSPATH')) exit;
class PostTransformer {
private $args;
private $withLayout;
private $imagePosition;
function __construct($args) {
$this->args = $args;
$this->withLayout = (bool)filter_var($args['withLayout'], FILTER_VALIDATE_BOOLEAN);
$this->imagePosition = 'left';
}
function getDivider() {
if (empty($this->args['withLayout'])) {
if(empty($this->withLayout)) {
return $this->args['divider'];
}
return LayoutHelper::row(array(
@@ -28,13 +30,13 @@ class PostTransformer {
}
function transform($post) {
if (empty($this->args['withLayout'])) {
return $this->getOldStructure($post);
if(empty($this->withLayout)) {
return $this->getStructure($post);
}
return $this->getNewStructure($post);
return $this->getStructureWithLayout($post);
}
private function getOldStructure($post) {
private function getStructure($post) {
$content = $this->getContent($post);
$title = $this->getTitle($post);
$featured_image = $this->getFeaturedImage($post);
@@ -45,7 +47,7 @@ class PostTransformer {
array_unshift($content, $title, $featured_image);
} else {
if($content[0]['type'] === 'text') {
$content[0]['text'] .= $title['text'];
$content[0]['text'] = $title['text'] . $content[0]['text'];
} else {
array_unshift($content, $title);
}
@@ -57,7 +59,7 @@ class PostTransformer {
return $content;
}
private function getNewStructure($post) {
private function getStructureWithLayout($post) {
$content = $this->getContent($post);
$title = $this->getTitle($post);
$featured_image = $this->getFeaturedImage($post);

View File

@@ -64,16 +64,20 @@ class Renderer {
return $block_class::render($block, $column_count);
}
function processAutomatedLatestContent($args, $column_count) {
function automatedLatestContentTransformedPosts($args) {
$posts_to_exclude = $this->getPosts();
$ALC_posts = $this->ALC->getPosts($args, $posts_to_exclude);
foreach($ALC_posts as $post) {
$posts_to_exclude[] = $post->ID;
}
$transformed_posts = array(
'blocks' => $this->ALC->transformPosts($args, $ALC_posts)
);
$this->setPosts($posts_to_exclude);
return $this->ALC->transformPosts($args, $ALC_posts);
}
function processAutomatedLatestContent($args, $column_count) {
$transformed_posts = array(
'blocks' => $this->automatedLatestContentTransformedPosts($args)
);
$transformed_posts = StylesHelper::applyTextAlignment($transformed_posts);
$rendered_posts = $this->render($transformed_posts, $column_count);
return $rendered_posts;

View File

@@ -48,6 +48,7 @@ class Renderer {
$content = $this->addMailpoetLogoContentBlock($content, $styles);
}
$content = $this->prepare($content);
$rendered_body = $this->renderBody($content);
$rendered_styles = $this->renderStyles($styles);
@@ -70,6 +71,26 @@ class Renderer {
$rendered_newsletter;
}
function prepare($content) {
$blocks = array();
$content_blocks = (array_key_exists('blocks', $content))
? $content['blocks']
: array();
foreach($content_blocks as $block) {
if($block['type'] === 'automatedLatestContentLayout') {
$blocks = array_merge(
$blocks,
$this->blocks_renderer->automatedLatestContentTransformedPosts($block)
);
} else {
$blocks[] = $block;
}
}
$content['blocks'] = $blocks;
return $content;
}
function renderBody($content) {
$blocks = (array_key_exists('blocks', $content))
? $content['blocks']

View File

@@ -17,6 +17,18 @@
'newsletter_editor_template_automated_latest_content_settings',
'newsletter/templates/blocks/automatedLatestContent/settings.hbs'
) %>
<%= partial(
'newsletter_editor_template_automated_latest_content_layout_block',
'newsletter/templates/blocks/automatedLatestContentLayout/block.hbs'
) %>
<%= partial(
'newsletter_editor_template_automated_latest_content_layout_widget',
'newsletter/templates/blocks/automatedLatestContentLayout/widget.hbs'
) %>
<%= partial(
'newsletter_editor_template_automated_latest_content_layout_settings',
'newsletter/templates/blocks/automatedLatestContentLayout/settings.hbs'
) %>
<%= partial(
'newsletter_editor_template_button_block',
'newsletter/templates/blocks/button/block.hbs'
@@ -522,6 +534,16 @@
jQuery('#newsletter_editor_template_automated_latest_content_settings').html()
),
automatedLatestContentLayoutBlock: Handlebars.compile(
jQuery('#newsletter_editor_template_automated_latest_content_layout_block').html()
),
automatedLatestContentLayoutInsertion: Handlebars.compile(
jQuery('#newsletter_editor_template_automated_latest_content_layout_widget').html()
),
automatedLatestContentLayoutBlockSettings: Handlebars.compile(
jQuery('#newsletter_editor_template_automated_latest_content_layout_settings').html()
),
postsBlock: Handlebars.compile(
jQuery('#newsletter_editor_template_posts_block').html()
),
@@ -963,6 +985,7 @@
blockDefaults: {
automatedLatestContent: {
amount: '5',
withLayout: false,
contentType: 'post', // 'post'|'page'|'mailpoet_page'
inclusionType: 'include', // 'include'|'exclude'
displayType: 'excerpt', // 'excerpt'|'full'|'titleOnly'
@@ -1015,6 +1038,61 @@
backgroundColor: '#ffffff',
backgroundColorAlternate: '#eeeeee',
},
automatedLatestContentLayout: {
amount: '5',
withLayout: true,
contentType: 'post', // 'post'|'page'|'mailpoet_page'
inclusionType: 'include', // 'include'|'exclude'
displayType: 'excerpt', // 'excerpt'|'full'|'titleOnly'
titleFormat: 'h1', // 'h1'|'h2'|'h3'|'ul'
titleAlignment: 'left', // 'left'|'center'|'right'
titleIsLink: false, // false|true
imageFullWidth: false, // true|false
featuredImagePosition: 'centered', // 'centered'|'left'|'right'|'alternate'|'none',
showAuthor: 'no', // 'no'|'aboveText'|'belowText'
authorPrecededBy: '<%= __('Author:') | escape('js') %>',
showCategories: 'no', // 'no'|'aboveText'|'belowText'
categoriesPrecededBy: '<%= __('Categories:') | escape('js') %>',
readMoreType: 'button', // 'link'|'button'
readMoreText: '<%= __('Read more') | escape('js') %>',
readMoreButton: {
text: '<%= __('Read more') | escape('js') %>',
url: '[postLink]',
context: 'automatedLatestContentLayout.readMoreButton',
styles: {
block: {
backgroundColor: '#2ea1cd',
borderColor: '#0074a2',
borderWidth: '1px',
borderRadius: '5px',
borderStyle: 'solid',
width: '180px',
lineHeight: '40px',
fontColor: '#ffffff',
fontFamily: 'Verdana',
fontSize: '18px',
fontWeight: 'normal',
textAlign: 'center',
}
}
},
sortBy: 'newest', // 'newest'|'oldest',
showDivider: true, // true|false
divider: {
context: 'automatedLatestContentLayout.divider',
styles: {
block: {
backgroundColor: 'transparent',
padding: '13px',
borderStyle: 'solid',
borderWidth: '3px',
borderColor: '#aaaaaa',
},
},
},
backgroundColor: '#ffffff',
backgroundColorAlternate: '#eeeeee',
},
button: {
text: '<%= __('Button') | escape('js') %>',
url: '',
@@ -1086,6 +1164,7 @@
},
posts: {
amount: '10',
withLayout: true,
contentType: 'post', // 'post'|'page'|'mailpoet_page'
postStatus: 'publish', // 'draft'|'pending'|'private'|'publish'|'future'
inclusionType: 'include', // 'include'|'exclude'

View File

@@ -0,0 +1,6 @@
<div class="mailpoet_tools"></div>
<div class="mailpoet_content">
<div class="mailpoet_automated_latest_content_block_overlay"></div>
<div class="mailpoet_automated_latest_content_block_posts"></div>
</div>
<div class="mailpoet_block_highlight"></div>

View File

@@ -0,0 +1,313 @@
<h3><%= __('Post selection') %></h3>
<div class="mailpoet_form_field">
<div class="mailpoet_form_field_title mailpoet_form_field_title_inline"><%= __('Show:') %></div>
<div class="mailpoet_form_field_input_option">
<input type="text" class="mailpoet_input mailpoet_input_small mailpoet_automated_latest_content_show_amount" value="{{ model.amount }}" maxlength="2" size="2" />
<select class="mailpoet_select mailpoet_select_large mailpoet_automated_latest_content_content_type">
<option value="post" {{#ifCond model.contentType '==' 'post'}}SELECTED{{/ifCond}}><%= __('Posts') %></option>
<option value="page" {{#ifCond model.contentType '==' 'page'}}SELECTED{{/ifCond}}><%= __('Pages') %></option>
<option value="mailpoet_page" {{#ifCond model.contentType '==' 'mailpoet_page'}}SELECTED{{/ifCond}}><%= __('MailPoet pages') %></option>
</select>
</div>
</div>
<div class="mailpoet_form_field">
<div class="mailpoet_form_field_select_option">
<select class="mailpoet_select mailpoet_automated_latest_content_categories_and_tags" multiple="multiple">
{{#each model.terms}}
<option value="{{ id }}" selected="selected">{{ text }}</option>
{{/each}}
</select>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_include_or_exclude" class="mailpoet_automated_latest_content_include_or_exclude" value="include" {{#ifCond model.inclusionType '==' 'include'}}CHECKED{{/ifCond}}/>
<%= __('Include') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_include_or_exclude" class="mailpoet_automated_latest_content_include_or_exclude" value="exclude" {{#ifCond model.inclusionType '==' 'exclude'}}CHECKED{{/ifCond}} />
<%= __('Exclude') %>
</label>
</div>
</div>
<hr class="mailpoet_separator" />
<div class="mailpoet_form_field">
<a href="javascript:;" class="mailpoet_automated_latest_content_show_display_options"><%= __('Display options') %></a>
</div>
<div class="mailpoet_automated_latest_content_display_options mailpoet_closed">
<div class="mailpoet_form_field">
<a href="javascript:;" class="mailpoet_automated_latest_content_hide_display_options"><%= __('Hide display options') %></a>
</div>
<div class="mailpoet_form_field">
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_display_type" class="mailpoet_automated_latest_content_display_type" value="excerpt" {{#ifCond model.displayType '==' 'excerpt'}}CHECKED{{/ifCond}}/>
<%= __('Excerpt') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_display_type" class="mailpoet_automated_latest_content_display_type" value="full" {{#ifCond model.displayType '==' 'full'}}CHECKED{{/ifCond}}/>
<%= __('Full post') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_display_type" class="mailpoet_automated_latest_content_display_type" value="titleOnly" {{#ifCond model.displayType '==' 'titleOnly'}}CHECKED{{/ifCond}} />
<%= __('Title only') %>
</label>
</div>
</div>
<div class="mailpoet_form_field">
<div class="mailpoet_form_field_title"><%= __('Title Format') %></div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_title_format" class="mailpoet_automated_latest_content_title_format" value="h1" {{#ifCond model.titleFormat '==' 'h1'}}CHECKED{{/ifCond}}/>
<%= __('Heading 1') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_title_format" class="mailpoet_automated_latest_content_title_format" value="h2" {{#ifCond model.titleFormat '==' 'h2'}}CHECKED{{/ifCond}}/>
<%= __('Heading 2') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_title_format" class="mailpoet_automated_latest_content_title_format" value="h3" {{#ifCond model.titleFormat '==' 'h3'}}CHECKED{{/ifCond}}/>
<%= __('Heading 3') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option mailpoet_automated_latest_content_title_as_list {{#ifCond model.displayType '!=' 'titleOnly'}}mailpoet_hidden{{/ifCond}}">
<label>
<input type="radio" name="mailpoet_automated_latest_content_title_format" class="mailpoet_automated_latest_content_title_format" value="ul" {{#ifCond model.titleFormat '==' 'ul'}}CHECKED{{/ifCond}}/>
<%= __('Show as list') %>
</label>
</div>
</div>
<div class="mailpoet_form_field">
<div class="mailpoet_form_field_title"><%= __('Title Alignment') %></div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_title_alignment" class="mailpoet_automated_latest_content_title_alignment" value="left" {{#ifCond model.titleAlignment '==' 'left'}}CHECKED{{/ifCond}} />
<%= __('Left') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_title_alignment" class="mailpoet_automated_latest_content_title_alignment" value="center" {{#ifCond model.titleAlignment '==' 'center'}}CHECKED{{/ifCond}} />
<%= __('Center') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_title_alignment" class="mailpoet_automated_latest_content_title_alignment" value="right" {{#ifCond model.titleAlignment '==' 'right'}}CHECKED{{/ifCond}} />
<%= __('Right') %>
</label>
</div>
</div>
<div class="mailpoet_form_field mailpoet_automated_latest_content_title_as_link {{#ifCond model.titleFormat '===' 'ul'}}mailpoet_hidden{{/ifCond}}">
<div class="mailpoet_form_field_title"><%= __('Title as links') %></div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_title_as_links" class="mailpoet_automated_latest_content_title_as_links" value="true" {{#if model.titleIsLink}}CHECKED{{/if}}/>
<%= __('Yes') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_title_as_links" class="mailpoet_automated_latest_content_title_as_links" value="false" {{#unless model.titleIsLink}}CHECKED{{/unless}}/>
<%= __('No') %>
</label>
</div>
</div>
<hr class="mailpoet_separator mailpoet_automated_latest_content_image_separator {{#ifCond model.displayType '===' 'titleOnly'}}mailpoet_hidden{{/ifCond}}" />
<div class="mailpoet_form_field mailpoet_automated_latest_content_featured_image_position_container {{#ifCond model.displayType '!==' 'excerpt'}}mailpoet_hidden{{/ifCond}}">
<div class="mailpoet_form_field_title"><%= __('Featured image position') %></div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_featured_image_position" class="mailpoet_automated_latest_content_featured_image_position" value="centered" {{#ifCond model.featuredImagePosition '==' 'centered' }}CHECKED{{/ifCond}}/>
<%= __('Centered') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_featured_image_position" class="mailpoet_automated_latest_content_featured_image_position" value="left" {{#ifCond model.featuredImagePosition '==' 'left' }}CHECKED{{/ifCond}}/>
<%= __('Left') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_featured_image_position" class="mailpoet_automated_latest_content_featured_image_position" value="right" {{#ifCond model.featuredImagePosition '==' 'right' }}CHECKED{{/ifCond}}/>
<%= __('Right') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_featured_image_position" class="mailpoet_automated_latest_content_featured_image_position" value="alternate" {{#ifCond model.featuredImagePosition '==' 'alternate' }}CHECKED{{/ifCond}}/>
<%= __('Alternate') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_featured_image_position" class="mailpoet_automated_latest_content_featured_image_position" value="none" {{#ifCond model.featuredImagePosition '==' 'none' }}CHECKED{{/ifCond}}/>
<%= __('None') %>
</label>
</div>
</div>
<div class="mailpoet_automated_latest_content_non_title_list_options {{#ifCond model.displayType '==' 'titleOnly'}}{{#ifCond model.titleFormat '==' 'ul'}}mailpoet_hidden{{/ifCond}}{{/ifCond}}">
<div class="mailpoet_form_field mailpoet_automated_latest_content_image_full_width_option {{#ifCond model.displayType '==' 'titleOnly'}}mailpoet_hidden{{/ifCond}}">
<div class="mailpoet_form_field_title"><%= __('Image width') %></div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="imageFullWidth" class="mailpoet_automated_latest_content_image_full_width" value="true" {{#if model.imageFullWidth}}CHECKED{{/if}}/>
<%= __('Full width') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="imageFullWidth" class="mailpoet_automated_latest_content_image_full_width" value="false" {{#unless model.imageFullWidth}}CHECKED{{/unless}}/>
<%= __('Padded') %>
</label>
</div>
</div>
<hr class="mailpoet_separator" />
<div class="mailpoet_form_field">
<div class="mailpoet_form_field_title"><%= __('Show author') %></div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_show_author" class="mailpoet_automated_latest_content_show_author" value="no" {{#ifCond model.showAuthor '==' 'no'}}CHECKED{{/ifCond}}/>
<%= __('No') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_show_author" class="mailpoet_automated_latest_content_show_author" value="aboveText" {{#ifCond model.showAuthor '==' 'aboveText'}}CHECKED{{/ifCond}}/>
<%= __('Above text') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_show_author" class="mailpoet_automated_latest_content_show_author" value="belowText" {{#ifCond model.showAuthor '==' 'belowText'}}CHECKED{{/ifCond}}/>
<%= __('Below text') %><br />
</label>
</div>
<div class="mailpoet_form_field_title mailpoet_form_field_title_small"><%= __('Preceded by:') %></div>
<div class="mailpoet_form_field_input_option mailpoet_form_field_block">
<input type="text" class="mailpoet_input mailpoet_input_full mailpoet_automated_latest_content_author_preceded_by" value="{{ model.authorPrecededBy }}" />
</div>
</div>
<div class="mailpoet_form_field">
<div class="mailpoet_form_field_title"><%= __('Show categories') %></div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_show_categories" class="mailpoet_automated_latest_content_show_categories" value="no" {{#ifCond model.showCategories '==' 'no'}}CHECKED{{/ifCond}}/>
<%= __('No') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_show_categories" class="mailpoet_automated_latest_content_show_categories" value="aboveText" {{#ifCond model.showCategories '==' 'aboveText'}}CHECKED{{/ifCond}}/>
<%= __('Above text') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_show_categories" class="mailpoet_automated_latest_content_show_categories" value="belowText" {{#ifCond model.showCategories '==' 'belowText'}}CHECKED{{/ifCond}}/>
<%= __('Below text') %>
</label>
</div>
<div class="mailpoet_form_field_title mailpoet_form_field_title_small"><%= __('Preceded by:') %></div>
<div class="mailpoet_form_field_input_option mailpoet_form_field_block">
<input type="text" class="mailpoet_input mailpoet_input_full mailpoet_automated_latest_content_categories" value="{{ model.categoriesPrecededBy }}" />
</div>
</div>
<hr class="mailpoet_separator" />
<div class="mailpoet_form_field">
<div class="mailpoet_form_field_title mailpoet_form_field_title_small"><%= __('"Read more" text') %></div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_read_more_type" class="mailpoet_automated_latest_content_read_more_type" value="link" {{#ifCond model.readMoreType '==' 'link'}}CHECKED{{/ifCond}}/>
<%= __('Link') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_read_more_type" class="mailpoet_automated_latest_content_read_more_type" value="button" {{#ifCond model.readMoreType '==' 'button'}}CHECKED{{/ifCond}}/>
<%= __('Button') %>
</label>
</div>
<div class="mailpoet_form_field_input_option mailpoet_form_field_block">
<input type="text" class="mailpoet_input mailpoet_input_full mailpoet_automated_latest_content_read_more_text {{#ifCond model.readMoreType '!=' 'link'}}mailpoet_hidden{{/ifCond}}" value="{{ model.readMoreText }}" />
</div>
<div class="mailpoet_form_field_input_option mailpoet_form_field_block">
<a href="javascript:;" class="mailpoet_automated_latest_content_select_button {{#ifCond model.readMoreType '!=' 'button'}}mailpoet_hidden{{/ifCond}}"><%= __('Design a button') %></a>
</div>
</div>
<hr class="mailpoet_separator" />
</div>
<div class="mailpoet_form_field">
<div class="mailpoet_form_field_title mailpoet_form_field_title_small"><%= __('Sort by') %></div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_sort_by" class="mailpoet_automated_latest_content_sort_by" value="newest" {{#ifCond model.sortBy '==' 'newest'}}CHECKED{{/ifCond}}/>
<%= __('Newest') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_sort_by" class="mailpoet_automated_latest_content_sort_by" value="oldest" {{#ifCond model.sortBy '==' 'oldest'}}CHECKED{{/ifCond}}/>
<%= __('Oldest') %>
</label>
</div>
</div>
<div class="mailpoet_automated_latest_content_non_title_list_options {{#ifCond model.displayType '==' 'titleOnly'}}{{#ifCond model.titleFormat '==' 'ul'}}mailpoet_hidden{{/ifCond}}{{/ifCond}}">
<div class="mailpoet_form_field">
<div class="mailpoet_form_field_title mailpoet_form_field_title_small"><%= __('Show divider between posts') %></div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_show_divider"class="mailpoet_automated_latest_content_show_divider" value="true" {{#if model.showDivider}}CHECKED{{/if}}/>
<%= __('Yes') %>
</label>
</div>
<div class="mailpoet_form_field_radio_option">
<label>
<input type="radio" name="mailpoet_automated_latest_content_show_divider"class="mailpoet_automated_latest_content_show_divider" value="false" {{#unless model.showDivider}}CHECKED{{/unless}}/>
<%= __('No') %>
</label>
</div>
<div>
<a href="javascript:;" class="mailpoet_automated_latest_content_select_divider"><%= __('Select divider') %></a>
</div>
</div>
</div>
</div>
<div class="mailpoet_form_field">
<input type="button" class="button button-primary mailpoet_done_editing" value="<%= __('Done') | escape('html_attr') %>" />
</div>

View File

@@ -0,0 +1,4 @@
<div class="mailpoet_widget_icon">
<%= source('newsletter/templates/svg/block-icons/auto-post.svg') %>
</div>
<div class="mailpoet_widget_title"><%= __('Automatic Latest Content') %></div>

View File

@@ -272,6 +272,7 @@ var adminConfig = {
'newsletter_editor/blocks/footer.js',
'newsletter_editor/blocks/header.js',
'newsletter_editor/blocks/automatedLatestContent.js',
'newsletter_editor/blocks/automatedLatestContentLayout.js',
'newsletter_editor/blocks/posts.js',
'newsletter_editor/blocks/social.js'
]
@@ -375,6 +376,7 @@ var testConfig = {
'newsletter_editor/blocks/footer.js',
'newsletter_editor/blocks/header.js',
'newsletter_editor/blocks/automatedLatestContent.js',
'newsletter_editor/blocks/automatedLatestContentLayout.js',
'newsletter_editor/blocks/posts.js',
'newsletter_editor/blocks/social.js',