Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Pass a supportedLayout object to the showDropZones method defined in the editorOriginView so that only the appropriate drop zones are displayed when dragging a component from one block to another.
  • Loading branch information
danielstorey committed May 11, 2017
1 parent ee49ab2 commit 9a79f7f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
25 changes: 22 additions & 3 deletions frontend/src/core/editor/global/views/editorOriginView.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,32 @@ define(function(require){
type && $('.paste-zone-' + type).removeClass('display-none');
},

showDropZones: function () {
showDropZones: function (supportedLayout) {
// Purposeful global selector here
$('.paste-zone').addClass('display-none');
// Hide the links within the dropzone
$('.add-control').addClass('display-none');
$('.paste-zone-'+ this.model.get('_type') + ' a').addClass('display-none');
$('.paste-zone-'+ this.model.get('_type')).addClass('paste-zone-available').removeClass('display-none');

// Components may be restricted to either full or half width so
// make sure only the appropriate paste zones are displayed
var type = this.model.get('_type');
var pasteZoneSelector = '.paste-zone-'+ type;
var $pasteZones;

if (type === 'component') {
$pasteZones = $();
if (supportedLayout.full) {
$pasteZones = $pasteZones.add('.paste-zone-component-full');
}
if (supportedLayout.half) {
$pasteZones = $pasteZones.add('.paste-zone-component-left, .paste-zone-component-right');
}
} else {
$pasteZones = $(pasteZoneSelector);
}

$(pasteZoneSelector + ' a').addClass('display-none');
$pasteZones.addClass('paste-zone-available').removeClass('display-none');
this.$el.parent().children('.drop-only').removeClass('display-none');
},

Expand Down
25 changes: 18 additions & 7 deletions frontend/src/core/editor/page/views/editorComponentView.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ define(function(require){
view.offsetTopFromWindow = view.$el.offset().top - $(window).scrollTop();
// This is in the helper method because the height needs to be
// manipulated before the drag start method due to adding drop zones
view.showDropZones();
// Passing the supported layout as a parameter allows the method to
// determine which drop zones should be displayed
var supportedLayout = view.getSupportedLayout();
view.showDropZones(supportedLayout);
$(this).attr('data-component-id', view.model.get('_id'));
$(this).attr('data-block-id', view.model.get('_parentId'));
return $('<div class="drag-helper">' + view.model.get('title') + '</div>');
Expand Down Expand Up @@ -144,15 +147,23 @@ define(function(require){
});
},

evaluateLayout: function() {

getSupportedLayout: function() {
var componentType = _.find(Origin.editor.data.componentTypes.models, function(type){
return type.get('component') == this.model.get('_component');
return type.get('component') === this.model.get('_component');
}, this);

var supportedLayout = componentType.get("properties")._supportedLayout;
var isFullWidthSupported = _.indexOf(supportedLayout.enum, "full-width") > -1;
var isHalfWidthSupported = _.indexOf(supportedLayout.enum, "half-width") > -1;
var supportedLayout = componentType.get('properties')._supportedLayout;

return {
full: _.indexOf(supportedLayout.enum, 'full-width') > -1,
half: _.indexOf(supportedLayout.enum, 'half-width') > -1
}
},

evaluateLayout: function() {
var supportedLayout = this.getSupportedLayout();
var isFullWidthSupported = supportedLayout.full;
var isHalfWidthSupported = supportedLayout.half;

var movePositions = {
left: false,
Expand Down

0 comments on commit 9a79f7f

Please sign in to comment.