Add option to show settings on drop, set it up for ALC
This commit is contained in:
@ -335,7 +335,10 @@ define([
|
|||||||
cloneOriginal: true,
|
cloneOriginal: true,
|
||||||
drop: function() {
|
drop: function() {
|
||||||
return new Module.AutomatedLatestContentBlockModel({}, { parse: true });
|
return new Module.AutomatedLatestContentBlockModel({}, { parse: true });
|
||||||
}
|
},
|
||||||
|
onDrop: function(options) {
|
||||||
|
options.droppedView.triggerMethod('showSettings');
|
||||||
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -87,6 +87,9 @@ define([
|
|||||||
AugmentedView.apply(this, arguments);
|
AugmentedView.apply(this, arguments);
|
||||||
this.$el.addClass('mailpoet_editor_view_' + this.cid);
|
this.$el.addClass('mailpoet_editor_view_' + this.cid);
|
||||||
},
|
},
|
||||||
|
initialize: function() {
|
||||||
|
this.on('showSettings', this.showSettings);
|
||||||
|
},
|
||||||
showTools: function(_event) {
|
showTools: function(_event) {
|
||||||
if (!this.showingToolsDisabled) {
|
if (!this.showingToolsDisabled) {
|
||||||
this.$('> .mailpoet_tools').show();
|
this.$('> .mailpoet_tools').show();
|
||||||
@ -104,6 +107,9 @@ define([
|
|||||||
this.showingToolsDisabled = true;
|
this.showingToolsDisabled = true;
|
||||||
this.hideTools();
|
this.hideTools();
|
||||||
},
|
},
|
||||||
|
showSettings: function(options) {
|
||||||
|
this.toolsView.triggerMethod('showSettings', options);
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* Defines drop behavior of BlockView instance
|
* Defines drop behavior of BlockView instance
|
||||||
*/
|
*/
|
||||||
@ -141,6 +147,7 @@ define([
|
|||||||
|
|
||||||
// Automatically cancel deletion
|
// Automatically cancel deletion
|
||||||
this.on('hideTools', this.hideDeletionConfirmation, this);
|
this.on('hideTools', this.hideDeletionConfirmation, this);
|
||||||
|
this.on('showSettings', this.changeSettings);
|
||||||
},
|
},
|
||||||
templateHelpers: function() {
|
templateHelpers: function() {
|
||||||
return {
|
return {
|
||||||
@ -149,9 +156,9 @@ define([
|
|||||||
tools: this.tools,
|
tools: this.tools,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
changeSettings: function() {
|
changeSettings: function(options) {
|
||||||
var ViewType = this.getSettingsView();
|
var ViewType = this.getSettingsView();
|
||||||
(new ViewType({ model: this.model })).render();
|
(new ViewType(_.extend({ model: this.model }, options || {}))).render();
|
||||||
},
|
},
|
||||||
showDeletionConfirmation: function() {
|
showDeletionConfirmation: function() {
|
||||||
this.$('.mailpoet_delete_block').addClass('mailpoet_delete_block_activated');
|
this.$('.mailpoet_delete_block').addClass('mailpoet_delete_block_activated');
|
||||||
|
@ -35,9 +35,6 @@ define([
|
|||||||
Module.ImageBlockView = base.BlockView.extend({
|
Module.ImageBlockView = base.BlockView.extend({
|
||||||
className: "mailpoet_block mailpoet_image_block mailpoet_droppable_block",
|
className: "mailpoet_block mailpoet_image_block mailpoet_droppable_block",
|
||||||
getTemplate: function() { return templates.imageBlock; },
|
getTemplate: function() { return templates.imageBlock; },
|
||||||
initialize: function() {
|
|
||||||
this.on('showSettings', this.showSettings);
|
|
||||||
},
|
|
||||||
onDragSubstituteBy: function() { return Module.ImageWidgetView; },
|
onDragSubstituteBy: function() { return Module.ImageWidgetView; },
|
||||||
templateHelpers: function() {
|
templateHelpers: function() {
|
||||||
return {
|
return {
|
||||||
@ -56,29 +53,10 @@ define([
|
|||||||
this.$el.addClass('mailpoet_full_image');
|
this.$el.addClass('mailpoet_full_image');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
showSettings: function(options) {
|
|
||||||
this.toolsView.triggerMethod('showSettings', options);
|
|
||||||
},
|
|
||||||
onBeforeDestroy: function() {
|
|
||||||
this.off('showSettings');
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Module.ImageBlockToolsView = base.BlockToolsView.extend({
|
Module.ImageBlockToolsView = base.BlockToolsView.extend({
|
||||||
getSettingsView: function() { return Module.ImageBlockSettingsView; },
|
getSettingsView: function() { return Module.ImageBlockSettingsView; },
|
||||||
initialize: function() {
|
|
||||||
base.BlockToolsView.prototype.initialize.apply(this, arguments);
|
|
||||||
this.on('showSettings', this.changeSettings);
|
|
||||||
},
|
|
||||||
changeSettings: function(options) {
|
|
||||||
(new Module.ImageBlockSettingsView({
|
|
||||||
model: this.model,
|
|
||||||
showImageManager: (options.showImageManager === true),
|
|
||||||
})).render();
|
|
||||||
},
|
|
||||||
onBeforeDestroy: function() {
|
|
||||||
this.off('showSettings');
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Module.ImageBlockSettingsView = base.BlockSettingsView.extend({
|
Module.ImageBlockSettingsView = base.BlockSettingsView.extend({
|
||||||
|
@ -1,18 +1,29 @@
|
|||||||
define([
|
define([
|
||||||
'newsletter_editor/App',
|
'newsletter_editor/App',
|
||||||
'newsletter_editor/blocks/automatedLatestContent',
|
'newsletter_editor/blocks/automatedLatestContent',
|
||||||
|
'amd-inject-loader!newsletter_editor/blocks/automatedLatestContent',
|
||||||
'newsletter_editor/components/wordpress',
|
'newsletter_editor/components/wordpress',
|
||||||
], function(EditorApplication, AutomatedLatestContentBlock, WordpressComponent) {
|
], function(EditorApplication, AutomatedLatestContentBlock, AutomatedLatestContentInjector, WordpressComponent) {
|
||||||
|
|
||||||
describe('Automated latest content', function () {
|
describe('Automated latest content', function () {
|
||||||
describe('model', function () {
|
describe('model', function () {
|
||||||
var model;
|
var model, module;
|
||||||
|
|
||||||
|
before(function() {
|
||||||
|
module = AutomatedLatestContentInjector({
|
||||||
|
'newsletter_editor/components/wordpress': {
|
||||||
|
getTransformedPosts: function() {
|
||||||
|
return jQuery.Deferred();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
global.stubChannel(EditorApplication);
|
global.stubChannel(EditorApplication);
|
||||||
global.stubConfig(EditorApplication);
|
global.stubConfig(EditorApplication);
|
||||||
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.SuperModel);
|
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.SuperModel);
|
||||||
model = new (AutomatedLatestContentBlock.AutomatedLatestContentBlockModel)();
|
model = new (module.AutomatedLatestContentBlockModel)();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
@ -151,7 +162,7 @@ define([
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
var model = new (AutomatedLatestContentBlock.AutomatedLatestContentBlockModel)();
|
var model = new (module.AutomatedLatestContentBlockModel)();
|
||||||
|
|
||||||
expect(model.get('amount')).to.equal('17');
|
expect(model.get('amount')).to.equal('17');
|
||||||
expect(model.get('contentType')).to.equal('mailpoet_page');
|
expect(model.get('contentType')).to.equal('mailpoet_page');
|
||||||
@ -184,15 +195,25 @@ define([
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('block view', function () {
|
describe('block view', function () {
|
||||||
var model, view;
|
var model, view, module;
|
||||||
|
|
||||||
|
before(function() {
|
||||||
|
module = AutomatedLatestContentInjector({
|
||||||
|
'newsletter_editor/components/wordpress': {
|
||||||
|
getTransformedPosts: function() {
|
||||||
|
return jQuery.Deferred();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
global.stubChannel(EditorApplication);
|
global.stubChannel(EditorApplication);
|
||||||
global.stubConfig(EditorApplication);
|
global.stubConfig(EditorApplication);
|
||||||
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.Model);
|
EditorApplication.getBlockTypeModel = sinon.stub().returns(Backbone.Model);
|
||||||
EditorApplication.getBlockTypeView = sinon.stub().returns(Backbone.View);
|
EditorApplication.getBlockTypeView = sinon.stub().returns(Backbone.View);
|
||||||
model = new (AutomatedLatestContentBlock.AutomatedLatestContentBlockModel)();
|
model = new (module.AutomatedLatestContentBlockModel)();
|
||||||
view = new (AutomatedLatestContentBlock.AutomatedLatestContentBlockView)({model: model});
|
view = new (module.AutomatedLatestContentBlockView)({model: model});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
@ -206,7 +227,20 @@ define([
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('block settings view', function () {
|
describe('block settings view', function () {
|
||||||
var model, view;
|
var model, view, module;
|
||||||
|
|
||||||
|
before(function() {
|
||||||
|
module = AutomatedLatestContentInjector({
|
||||||
|
'newsletter_editor/components/wordpress': {
|
||||||
|
getTransformedPosts: function() {
|
||||||
|
return jQuery.Deferred();
|
||||||
|
},
|
||||||
|
getPostTypes: function() {
|
||||||
|
return jQuery.Deferred();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
before(function () {
|
before(function () {
|
||||||
WordpressComponent.getPostTypes = function() {
|
WordpressComponent.getPostTypes = function() {
|
||||||
@ -243,8 +277,8 @@ define([
|
|||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
model = new (AutomatedLatestContentBlock.AutomatedLatestContentBlockModel)();
|
model = new (module.AutomatedLatestContentBlockModel)();
|
||||||
view = new (AutomatedLatestContentBlock.AutomatedLatestContentBlockSettingsView)({model: model});
|
view = new (module.AutomatedLatestContentBlockSettingsView)({model: model});
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function () {
|
after(function () {
|
||||||
@ -257,8 +291,8 @@ define([
|
|||||||
|
|
||||||
describe('once rendered', function () {
|
describe('once rendered', function () {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
model = new (AutomatedLatestContentBlock.AutomatedLatestContentBlockModel)();
|
model = new (module.AutomatedLatestContentBlockModel)();
|
||||||
view = new (AutomatedLatestContentBlock.AutomatedLatestContentBlockSettingsView)({model: model});
|
view = new (module.AutomatedLatestContentBlockSettingsView)({model: model});
|
||||||
view.render();
|
view.render();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -367,8 +401,8 @@ define([
|
|||||||
describe('when "title only" display type is selected', function() {
|
describe('when "title only" display type is selected', function() {
|
||||||
var model, view;
|
var model, view;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
model = new (AutomatedLatestContentBlock.AutomatedLatestContentBlockModel)();
|
model = new (module.AutomatedLatestContentBlockModel)();
|
||||||
view = new (AutomatedLatestContentBlock.AutomatedLatestContentBlockSettingsView)({model: model});
|
view = new (module.AutomatedLatestContentBlockSettingsView)({model: model});
|
||||||
view.render();
|
view.render();
|
||||||
view.$('.mailpoet_automated_latest_content_display_type').val('titleOnly').change();
|
view.$('.mailpoet_automated_latest_content_display_type').val('titleOnly').change();
|
||||||
});
|
});
|
||||||
@ -380,8 +414,8 @@ define([
|
|||||||
describe('when "title as list" is selected', function() {
|
describe('when "title as list" is selected', function() {
|
||||||
var model, view;
|
var model, view;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
model = new (AutomatedLatestContentBlock.AutomatedLatestContentBlockModel)();
|
model = new (module.AutomatedLatestContentBlockModel)();
|
||||||
view = new (AutomatedLatestContentBlock.AutomatedLatestContentBlockSettingsView)({model: model});
|
view = new (module.AutomatedLatestContentBlockSettingsView)({model: model});
|
||||||
view.render();
|
view.render();
|
||||||
view.$('.mailpoet_automated_latest_content_display_type').val('titleOnly').change();
|
view.$('.mailpoet_automated_latest_content_display_type').val('titleOnly').change();
|
||||||
view.$('.mailpoet_automated_latest_content_title_format').val('ul').change();
|
view.$('.mailpoet_automated_latest_content_title_format').val('ul').change();
|
||||||
|
Reference in New Issue
Block a user