Unify naming (post => product), remove unused code

[MAILPOET-1843]
This commit is contained in:
Ján Mikláš
2019-04-08 16:06:11 +02:00
committed by Rostislav Wolný
parent 47b264406f
commit fa61a24caa
5 changed files with 38 additions and 44 deletions

View File

@@ -95,7 +95,7 @@ Module.PostsBlockModel = base.BlockModel.extend({
this.fetchAvailablePosts(); this.fetchAvailablePosts();
this.on('change', this._updateDefaults, this); this.on('change', this._updateDefaults, this);
this.on('change:amount change:contentType change:terms change:inclusionType change:postStatus change:search change:sortBy', refreshAvailablePosts); this.on('change:contentType change:terms change:postStatus change:search', refreshAvailablePosts);
this.on('loadMorePosts', this._loadMorePosts, this); this.on('loadMorePosts', this._loadMorePosts, this);
this.listenTo(this.get('_selectedPosts'), 'add remove reset', refreshTransformedPosts); this.listenTo(this.get('_selectedPosts'), 'add remove reset', refreshTransformedPosts);
@@ -480,9 +480,7 @@ PostsDisplayOptionsSettingsView = base.BlockSettingsView.extend({
'change .mailpoet_posts_title_format': 'changeTitleFormat', 'change .mailpoet_posts_title_format': 'changeTitleFormat',
'change .mailpoet_posts_title_as_links': _.partial(this.changeBoolField, 'titleIsLink'), 'change .mailpoet_posts_title_as_links': _.partial(this.changeBoolField, 'titleIsLink'),
'change .mailpoet_posts_show_divider': _.partial(this.changeBoolField, 'showDivider'), 'change .mailpoet_posts_show_divider': _.partial(this.changeBoolField, 'showDivider'),
'input .mailpoet_posts_show_amount': _.partial(this.changeField, 'amount'),
'change .mailpoet_posts_content_type': _.partial(this.changeField, 'contentType'), 'change .mailpoet_posts_content_type': _.partial(this.changeField, 'contentType'),
'change .mailpoet_posts_include_or_exclude': _.partial(this.changeField, 'inclusionType'),
'change .mailpoet_posts_title_alignment': _.partial(this.changeField, 'titleAlignment'), 'change .mailpoet_posts_title_alignment': _.partial(this.changeField, 'titleAlignment'),
'change .mailpoet_posts_image_full_width': _.partial(this.changeBoolField, 'imageFullWidth'), 'change .mailpoet_posts_image_full_width': _.partial(this.changeBoolField, 'imageFullWidth'),
'change .mailpoet_posts_featured_image_position': _.partial(this.changeField, 'featuredImagePosition'), 'change .mailpoet_posts_featured_image_position': _.partial(this.changeField, 'featuredImagePosition'),
@@ -491,7 +489,6 @@ PostsDisplayOptionsSettingsView = base.BlockSettingsView.extend({
'change .mailpoet_posts_show_categories': _.partial(this.changeField, 'showCategories'), 'change .mailpoet_posts_show_categories': _.partial(this.changeField, 'showCategories'),
'input .mailpoet_posts_categories': _.partial(this.changeField, 'categoriesPrecededBy'), 'input .mailpoet_posts_categories': _.partial(this.changeField, 'categoriesPrecededBy'),
'input .mailpoet_posts_read_more_text': _.partial(this.changeField, 'readMoreText'), 'input .mailpoet_posts_read_more_text': _.partial(this.changeField, 'readMoreText'),
'change .mailpoet_posts_sort_by': _.partial(this.changeField, 'sortBy'),
'change .mailpoet_automated_latest_content_title_position': _.partial(this.changeField, 'titlePosition'), 'change .mailpoet_automated_latest_content_title_position': _.partial(this.changeField, 'titlePosition'),
}; };
}, },

View File

@@ -91,7 +91,7 @@ Module.ProductsBlockModel = base.BlockModel.extend({
this.fetchAvailableProducts(); this.fetchAvailableProducts();
this.on('change', this._updateDefaults, this); this.on('change', this._updateDefaults, this);
this.on('change:amount change:terms change:inclusionType change:postStatus change:search change:sortBy', refreshAvailableProducts); this.on('change:terms change:postStatus change:search', refreshAvailableProducts);
this.on('loadMoreProducts', this._loadMoreProducts, this); this.on('loadMoreProducts', this._loadMoreProducts, this);
this.listenTo(this.get('_selectedProducts'), 'add remove reset', refreshTransformedProducts); this.listenTo(this.get('_selectedProducts'), 'add remove reset', refreshTransformedProducts);
@@ -282,7 +282,7 @@ Module.ProductsBlockSettingsView = base.BlockSettingsView.extend({
}); });
ProductSelectionCollectionView = Marionette.CollectionView.extend({ ProductSelectionCollectionView = Marionette.CollectionView.extend({
className: 'mailpoet_post_scroll_container', className: 'mailpoet_products_scroll_container',
childView: function childView() { return SingleProductSelectionSettingsView; }, childView: function childView() { return SingleProductSelectionSettingsView; },
emptyView: function emptyView() { return EmptyProductSelectionSettingsView; }, emptyView: function emptyView() { return EmptyProductSelectionSettingsView; },
childViewOptions: function childViewOptions() { childViewOptions: function childViewOptions() {
@@ -297,8 +297,8 @@ ProductSelectionCollectionView = Marionette.CollectionView.extend({
scroll: 'onProductsScroll', scroll: 'onProductsScroll',
}, },
onProductsScroll: function onProductsScroll(event) { onProductsScroll: function onProductsScroll(event) {
var $postsBox = jQuery(event.target); var $productsBox = jQuery(event.target);
if ($postsBox.scrollTop() + $postsBox.innerHeight() >= $postsBox[0].scrollHeight) { if ($productsBox.scrollTop() + $productsBox.innerHeight() >= $productsBox[0].scrollHeight) {
// Load more posts if scrolled to bottom // Load more posts if scrolled to bottom
this.blockModel.trigger('loadMoreProducts'); this.blockModel.trigger('loadMoreProducts');
} }
@@ -322,7 +322,7 @@ ProductSelectionSettingsView = Marionette.View.extend({
'change:offset': function changeOffset(model, value) { 'change:offset': function changeOffset(model, value) {
// Scroll posts view to top if settings are changed // Scroll posts view to top if settings are changed
if (value === 0) { if (value === 0) {
this.$('.mailpoet_post_scroll_container').scrollTop(0); this.$('.mailpoet_products_scroll_container').scrollTop(0);
} }
}, },
loadingMoreProducts: function loadingMoreProducts() { loadingMoreProducts: function loadingMoreProducts() {
@@ -461,21 +461,18 @@ ProductsDisplayOptionsSettingsView = base.BlockSettingsView.extend({
}, },
events: function events() { events: function events() {
return { return {
'click .mailpoet_posts_select_button': 'showButtonSettings', 'click .mailpoet_products_select_button': 'showButtonSettings',
'click .mailpoet_posts_select_divider': 'showDividerSettings', 'click .mailpoet_products_select_divider': 'showDividerSettings',
'change .mailpoet_posts_read_more_type': 'changeReadMoreType', 'change .mailpoet_products_read_more_type': 'changeReadMoreType',
'change .mailpoet_products_display_type': 'changeDisplayType', 'change .mailpoet_products_display_type': 'changeDisplayType',
'change .mailpoet_products_title_format': 'changeTitleFormat', 'change .mailpoet_products_title_format': 'changeTitleFormat',
'change .mailpoet_products_title_as_links': _.partial(this.changeBoolField, 'titleIsLink'), 'change .mailpoet_products_title_as_links': _.partial(this.changeBoolField, 'titleIsLink'),
'change .mailpoet_posts_show_divider': _.partial(this.changeBoolField, 'showDivider'), 'change .mailpoet_products_show_divider': _.partial(this.changeBoolField, 'showDivider'),
'input .mailpoet_posts_show_amount': _.partial(this.changeField, 'amount'),
'change .mailpoet_posts_include_or_exclude': _.partial(this.changeField, 'inclusionType'),
'change .mailpoet_products_title_alignment': _.partial(this.changeField, 'titleAlignment'), 'change .mailpoet_products_title_alignment': _.partial(this.changeField, 'titleAlignment'),
'change .mailpoet_products_image_full_width': _.partial(this.changeBoolField, 'imageFullWidth'), 'change .mailpoet_products_image_full_width': _.partial(this.changeBoolField, 'imageFullWidth'),
'change .mailpoet_products_featured_image_position': _.partial(this.changeField, 'featuredImagePosition'), 'change .mailpoet_products_featured_image_position': _.partial(this.changeField, 'featuredImagePosition'),
'change .mailpoet_products_price_position': _.partial(this.changeField, 'pricePosition'), 'change .mailpoet_products_price_position': _.partial(this.changeField, 'pricePosition'),
'input .mailpoet_posts_read_more_text': _.partial(this.changeField, 'readMoreText'), 'input .mailpoet_products_read_more_text': _.partial(this.changeField, 'readMoreText'),
'change .mailpoet_posts_sort_by': _.partial(this.changeField, 'sortBy'),
'change .mailpoet_products_title_position': _.partial(this.changeField, 'titlePosition'), 'change .mailpoet_products_title_position': _.partial(this.changeField, 'titlePosition'),
}; };
}, },
@@ -508,11 +505,11 @@ ProductsDisplayOptionsSettingsView = base.BlockSettingsView.extend({
changeReadMoreType: function changeReadMoreType(event) { changeReadMoreType: function changeReadMoreType(event) {
var value = jQuery(event.target).val(); var value = jQuery(event.target).val();
if (value === 'link') { if (value === 'link') {
this.$('.mailpoet_posts_read_more_text').removeClass('mailpoet_hidden'); this.$('.mailpoet_products_read_more_text').removeClass('mailpoet_hidden');
this.$('.mailpoet_posts_select_button').addClass('mailpoet_hidden'); this.$('.mailpoet_products_select_button').addClass('mailpoet_hidden');
} else if (value === 'button') { } else if (value === 'button') {
this.$('.mailpoet_posts_read_more_text').addClass('mailpoet_hidden'); this.$('.mailpoet_products_read_more_text').addClass('mailpoet_hidden');
this.$('.mailpoet_posts_select_button').removeClass('mailpoet_hidden'); this.$('.mailpoet_products_select_button').removeClass('mailpoet_hidden');
} }
this.changeField('readMoreType', event); this.changeField('readMoreType', event);
}, },

View File

@@ -114,9 +114,9 @@ class EditorProductsCest {
// Multiple result for category // Multiple result for category
$I->selectOptionInSelect2(self::CATEGORY_MULTIPLE_RESULTS); $I->selectOptionInSelect2(self::CATEGORY_MULTIPLE_RESULTS);
$I->waitForElementNotVisible('.mailpoet_post_scroll_container > div:nth-child(' . (self::PRODUCTS_COUNT + 1) . ')'); $I->waitForElementNotVisible('.mailpoet_products_scroll_container > div:nth-child(' . (self::PRODUCTS_COUNT + 1) . ')');
$I->waitForText(self::PRODUCT_PREFIX_CATEGORY, 10, '.mailpoet_post_scroll_container'); $I->waitForText(self::PRODUCT_PREFIX_CATEGORY, 10, '.mailpoet_products_scroll_container');
$I->seeNumberOfElements('.mailpoet_post_scroll_container > div', self::PRODUCTS_COUNT); $I->seeNumberOfElements('.mailpoet_products_scroll_container > div', self::PRODUCTS_COUNT);
$this->clearCategories($I); $this->clearCategories($I);
// Click select2 to hide results // Click select2 to hide results
@@ -128,9 +128,9 @@ class EditorProductsCest {
// Multiple result for keyword // Multiple result for keyword
$I->fillField('.mailpoet_products_search_term', self::KEYWORD_MULTIPLE_RESULTS); $I->fillField('.mailpoet_products_search_term', self::KEYWORD_MULTIPLE_RESULTS);
$I->waitForElementNotVisible('.mailpoet_post_scroll_container > div:nth-child(' . (self::PRODUCTS_COUNT + 1) . ')'); $I->waitForElementNotVisible('.mailpoet_products_scroll_container > div:nth-child(' . (self::PRODUCTS_COUNT + 1) . ')');
$I->waitForText(self::KEYWORD_MULTIPLE_RESULTS, 10, '.mailpoet_post_scroll_container'); $I->waitForText(self::KEYWORD_MULTIPLE_RESULTS, 10, '.mailpoet_products_scroll_container');
$I->seeNumberOfElements('.mailpoet_post_scroll_container > div', self::PRODUCTS_COUNT); $I->seeNumberOfElements('.mailpoet_products_scroll_container > div', self::PRODUCTS_COUNT);
// Searching for existing post should return zero results // Searching for existing post should return zero results
$I->fillField('.mailpoet_products_search_term', self::POST_TITLE); $I->fillField('.mailpoet_products_search_term', self::POST_TITLE);
@@ -138,11 +138,11 @@ class EditorProductsCest {
// Product is clickable // Product is clickable
$I->fillField('.mailpoet_products_search_term', self::PRODUCT_NAME); $I->fillField('.mailpoet_products_search_term', self::PRODUCT_NAME);
$I->waitForText(self::PRODUCT_NAME, 10, '.mailpoet_post_scroll_container'); $I->waitForText(self::PRODUCT_NAME, 10, '.mailpoet_products_scroll_container');
$I->waitForElementVisible('#mailpoet_select_post_0'); $I->waitForElementVisible('#mailpoet_select_product_0');
$I->click('#mailpoet_select_post_0'); $I->click('#mailpoet_select_product_0');
$I->seeCheckboxIsChecked('#mailpoet_select_post_0'); $I->seeCheckboxIsChecked('#mailpoet_select_product_0');
$I->click('#mailpoet_select_post_1'); $I->click('#mailpoet_select_product_1');
$I->waitForElement(self::EDITOR_PRODUCT_SELECTOR); $I->waitForElement(self::EDITOR_PRODUCT_SELECTOR);
} }
@@ -193,11 +193,11 @@ class EditorProductsCest {
// Test "Buy now" button // Test "Buy now" button
$I->see('Buy now', self::EDITOR_PRODUCT_SELECTOR . ' .mailpoet_wp_post + p'); $I->see('Buy now', self::EDITOR_PRODUCT_SELECTOR . ' .mailpoet_wp_post + p');
$I->fillField('.mailpoet_posts_read_more_text', 'Go Shopping'); $I->fillField('.mailpoet_products_read_more_text', 'Go Shopping');
$this->waitForChange($I); $this->waitForChange($I);
$I->dontSee('Buy now', self::EDITOR_PRODUCT_SELECTOR . ' .mailpoet_wp_post + p'); $I->dontSee('Buy now', self::EDITOR_PRODUCT_SELECTOR . ' .mailpoet_wp_post + p');
$I->see('Go Shopping', self::EDITOR_PRODUCT_SELECTOR . ' .mailpoet_wp_post + p'); $I->see('Go Shopping', self::EDITOR_PRODUCT_SELECTOR . ' .mailpoet_wp_post + p');
$I->clickLabelWithInput('mailpoet_posts_read_more_type', 'button'); $I->clickLabelWithInput('mailpoet_products_read_more_type', 'button');
$this->waitForChange($I); $this->waitForChange($I);
$I->dontSeeElementInDOM(self::EDITOR_PRODUCT_SELECTOR . ' .mailpoet_wp_post + p'); $I->dontSeeElementInDOM(self::EDITOR_PRODUCT_SELECTOR . ' .mailpoet_wp_post + p');
$I->seeElementInDOM(self::EDITOR_PRODUCT_SELECTOR . ' .mailpoet_editor_button'); $I->seeElementInDOM(self::EDITOR_PRODUCT_SELECTOR . ' .mailpoet_editor_button');
@@ -205,12 +205,12 @@ class EditorProductsCest {
// Test "Divider" // Test "Divider"
$I->seeElementInDOM(self::EDITOR_PRODUCTS_SELECTOR . ' .mailpoet_divider_block'); $I->seeElementInDOM(self::EDITOR_PRODUCTS_SELECTOR . ' .mailpoet_divider_block');
$I->assertAttributeContains(self::EDITOR_PRODUCTS_SELECTOR . ' .mailpoet_divider', 'style', '3px'); $I->assertAttributeContains(self::EDITOR_PRODUCTS_SELECTOR . ' .mailpoet_divider', 'style', '3px');
$I->click('.mailpoet_posts_select_divider'); $I->click('.mailpoet_products_select_divider');
$I->fillField('.mailpoet_field_divider_border_width_input', 10); $I->fillField('.mailpoet_field_divider_border_width_input', 10);
$this->waitForChange($I); $this->waitForChange($I);
$I->click('.mailpoet_done_editing'); $I->click('.mailpoet_done_editing');
$I->assertAttributeContains(self::EDITOR_PRODUCTS_SELECTOR . ' .mailpoet_divider', 'style', '10px'); $I->assertAttributeContains(self::EDITOR_PRODUCTS_SELECTOR . ' .mailpoet_divider', 'style', '10px');
$I->clickLabelWithInput('mailpoet_posts_show_divider', 'false'); $I->clickLabelWithInput('mailpoet_products_show_divider', 'false');
$this->waitForChange($I); $this->waitForChange($I);
$I->dontSeeElementInDOM(self::EDITOR_PRODUCTS_SELECTOR . ' .mailpoet_divider_block'); $I->dontSeeElementInDOM(self::EDITOR_PRODUCTS_SELECTOR . ' .mailpoet_divider_block');

View File

@@ -182,23 +182,23 @@
<div class="mailpoet_form_field_title mailpoet_form_field_title_small"><%= __('"Buy now" text') %></div> <div class="mailpoet_form_field_title mailpoet_form_field_title_small"><%= __('"Buy now" text') %></div>
<div class="mailpoet_form_field_radio_option"> <div class="mailpoet_form_field_radio_option">
<label> <label>
<input type="radio" name="mailpoet_posts_read_more_type" class="mailpoet_posts_read_more_type" value="link" {{#ifCond model.readMoreType '==' 'link'}}CHECKED{{/ifCond}}/> <input type="radio" name="mailpoet_products_read_more_type" class="mailpoet_products_read_more_type" value="link" {{#ifCond model.readMoreType '==' 'link'}}CHECKED{{/ifCond}}/>
<%= __('Link') %> <%= __('Link') %>
</label> </label>
</div> </div>
<div class="mailpoet_form_field_radio_option"> <div class="mailpoet_form_field_radio_option">
<label> <label>
<input type="radio" name="mailpoet_posts_read_more_type" class="mailpoet_posts_read_more_type" value="button" {{#ifCond model.readMoreType '==' 'button'}}CHECKED{{/ifCond}}/> <input type="radio" name="mailpoet_products_read_more_type" class="mailpoet_products_read_more_type" value="button" {{#ifCond model.readMoreType '==' 'button'}}CHECKED{{/ifCond}}/>
<%= __('Button') %> <%= __('Button') %>
</label> </label>
</div> </div>
<div class="mailpoet_form_field_input_option mailpoet_form_field_block"> <div class="mailpoet_form_field_input_option mailpoet_form_field_block">
<input type="text" class="mailpoet_input mailpoet_input_full mailpoet_posts_read_more_text {{#ifCond model.readMoreType '!=' 'link'}}mailpoet_hidden{{/ifCond}}" value="{{ model.readMoreText }}" /> <input type="text" class="mailpoet_input mailpoet_input_full mailpoet_products_read_more_text {{#ifCond model.readMoreType '!=' 'link'}}mailpoet_hidden{{/ifCond}}" value="{{ model.readMoreText }}" />
</div> </div>
<div class="mailpoet_form_field_input_option mailpoet_form_field_block"> <div class="mailpoet_form_field_input_option mailpoet_form_field_block">
<a href="javascript:;" class="mailpoet_posts_select_button {{#ifCond model.readMoreType '!=' 'button'}}mailpoet_hidden{{/ifCond}}"><%= __('Design a button') %></a> <a href="javascript:;" class="mailpoet_products_select_button {{#ifCond model.readMoreType '!=' 'button'}}mailpoet_hidden{{/ifCond}}"><%= __('Design a button') %></a>
</div> </div>
</div> </div>
@@ -208,18 +208,18 @@
<div class="mailpoet_form_field_title mailpoet_form_field_title_small mailpoet_form_field_title_inline"><%= __('Show divider between posts') %></div> <div class="mailpoet_form_field_title mailpoet_form_field_title_small mailpoet_form_field_title_inline"><%= __('Show divider between posts') %></div>
<div class="mailpoet_form_field_radio_option"> <div class="mailpoet_form_field_radio_option">
<label> <label>
<input type="radio" name="mailpoet_posts_show_divider" class="mailpoet_posts_show_divider" value="true" {{#if model.showDivider}}CHECKED{{/if}}/> <input type="radio" name="mailpoet_products_show_divider" class="mailpoet_products_show_divider" value="true" {{#if model.showDivider}}CHECKED{{/if}}/>
<%= __('Yes') %> <%= __('Yes') %>
</label> </label>
</div> </div>
<div class="mailpoet_form_field_radio_option"> <div class="mailpoet_form_field_radio_option">
<label> <label>
<input type="radio" name="mailpoet_posts_show_divider"class="mailpoet_posts_show_divider" value="false" {{#unless model.showDivider}}CHECKED{{/unless}}/> <input type="radio" name="mailpoet_products_show_divider"class="mailpoet_products_show_divider" value="false" {{#unless model.showDivider}}CHECKED{{/unless}}/>
<%= __('No') %> <%= __('No') %>
</label> </label>
</div> </div>
<div class="mailpoet_form_field_input_option"> <div class="mailpoet_form_field_input_option">
<a href="javascript:;" class="mailpoet_posts_select_divider"><%= __('Select divider') %></a> <a href="javascript:;" class="mailpoet_products_select_divider"><%= __('Select divider') %></a>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -1,6 +1,6 @@
<div class="mailpoet_settings_products_single_product"> <div class="mailpoet_settings_products_single_product">
<label> <label>
<input id="mailpoet_select_post_{{ index }}" class="mailpoet_select_product_checkbox" type="checkbox" class="checkbox" value="" name="post_selection"> <input id="mailpoet_select_product_{{ index }}" class="mailpoet_select_product_checkbox" type="checkbox" class="checkbox" value="" name="post_selection">
{{#ellipsis model.post_title 40 '...'}}{{/ellipsis}} {{#ellipsis model.post_title 40 '...'}}{{/ellipsis}}
</label> </label>
</div> </div>