Switch Container block view to use methods defined by base view

This commit is contained in:
Tautvidas Sipavičius
2017-04-15 01:43:05 +03:00
parent 592f11bd5f
commit 167a605658

View File

@@ -95,29 +95,22 @@ define([
} }
}); });
Module.ContainerBlockView = Marionette.View.extend({ Module.ContainerBlockView = base.BlockView.extend({
regions: { regions: _.extend({}, base.BlockView.prototype.regions, {
blocks: { blocks: {
el: '> .mailpoet_container', el: '> .mailpoet_container',
replaceElement: true replaceElement: true
}, },
toolsRegion: '> .mailpoet_tools', }),
},
className: 'mailpoet_block mailpoet_container_block mailpoet_droppable_block mailpoet_droppable_layout_block', className: 'mailpoet_block mailpoet_container_block mailpoet_droppable_block mailpoet_droppable_layout_block',
getTemplate: function() { return templates.containerBlock; }, getTemplate: function() { return templates.containerBlock; },
modelEvents: { events: _.extend({}, base.BlockView.prototype.events, {
'change': 'render',
'delete': 'deleteBlock',
},
events: {
"mouseenter": "showTools",
"mouseleave": "hideTools",
"click .mailpoet_newsletter_layer_selector": "toggleEditingLayer", "click .mailpoet_newsletter_layer_selector": "toggleEditingLayer",
}, }),
ui: { ui: {
tools: '> .mailpoet_tools' tools: '> .mailpoet_tools'
}, },
behaviors: { behaviors: _.extend({}, base.BlockView.prototype.behaviors, {
ContainerDropZoneBehavior: {}, ContainerDropZoneBehavior: {},
DraggableBehavior: { DraggableBehavior: {
cloneOriginal: true, cloneOriginal: true,
@@ -146,8 +139,7 @@ define([
return view.renderOptions.depth === 1; return view.renderOptions.depth === 1;
}, },
}, },
HighlightEditingBehavior: {} }),
},
onDragSubstituteBy: function() { onDragSubstituteBy: function() {
// For two and three column layouts display their respective widgets, // For two and three column layouts display their respective widgets,
// otherwise always default to one column layout widget // otherwise always default to one column layout widget
@@ -159,17 +151,11 @@ define([
}, },
initialize: function(options) { initialize: function(options) {
base.BlockView.prototype.initialize.apply(this, arguments);
this.renderOptions = _.defaults(options.renderOptions || {}, {}); this.renderOptions = _.defaults(options.renderOptions || {}, {});
}, },
templateContext: function() {
return {
model: this.model.toJSON(),
viewCid: this.cid,
};
},
onRender: function() { onRender: function() {
this.$el.addClass('mailpoet_editor_view_' + this.cid);
this.toolsView = new Module.ContainerBlockToolsView({ this.toolsView = new Module.ContainerBlockToolsView({
model: this.model, model: this.model,
tools: { tools: {
@@ -227,45 +213,6 @@ define([
} }
event.stopPropagation(); event.stopPropagation();
}, },
getDropFunc: function() {
return function() {
return this.model.clone();
}.bind(this);
},
deleteBlock: function() {
this.transitionOut().done(function() {
this.model.destroy();
}.bind(this));
},
transitionIn: function() {
return this._transition('slideDown', 'fadeIn', 'easeIn');
},
transitionOut: function() {
return this._transition('slideUp', 'fadeOut', 'easeOut');
},
_transition: function(slideDirection, fadeDirection, easing) {
var promise = jQuery.Deferred();
this.$el.velocity(
slideDirection,
{
duration: 250,
easing: easing,
complete: function() {
promise.resolve();
}.bind(this),
}
).velocity(
fadeDirection,
{
duration: 250,
easing: easing,
queue: false, // Do not enqueue, trigger animation in parallel
}
);
return promise;
},
}); });
Module.ContainerBlockEmptyView = Marionette.View.extend({ Module.ContainerBlockEmptyView = Marionette.View.extend({