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