Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1631 #1632

Merged
merged 8 commits into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,33 @@ define(function(require) {

renderComponentList: function() {
Origin.trigger('editorComponentListView:removeSubviews');
// _.each(this.collection, function(componentType) {

this.collection.each(function(componentType) {
var properties = componentType.get('properties');
if (properties && properties.hasOwnProperty('._supportedLayout')) {
var supportedLayout = properties.hasOwnProperty('._supportedLayout').enum;
var availablePositions = _.clone(this.availablePositions);

if (properties && properties.hasOwnProperty('_supportedLayout')) {
var supportedLayout = properties._supportedLayout.enum;

// Prune the available positions
if (_.indexOf(supportedLayout, 'half-width') == -1) {
this.availablePositions.left = false;
this.availablePositions.right = false;
availablePositions.left = false;
availablePositions.right = false;
}

if (_.indexOf(supportedLayout, 'full-width') == -1) {
this.availablePositions.full = false;
availablePositions.full = false;
}
}

this.$('.editor-component-list-sidebar-list').append(new EditorPageComponentListItemView({
model: componentType,
availablePositions: this.availablePositions,
_parentId: this.model.get('_parentId'),
$parentElement: this.$parentElement,
parentView: this.parentView,
searchTerms: componentType.get('displayName').toLowerCase()
}).$el);
model: componentType,
availablePositions: availablePositions,
_parentId: this.model.get('_parentId'),
$parentElement: this.$parentElement,
parentView: this.parentView,
searchTerms: componentType.get('displayName').toLowerCase()
}).$el);
}, this);
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ define(function(require){

this.on('contextMenu:component:edit', this.loadComponentEdit);
this.on('contextMenu:component:copy', this.onCopy);
this.on('contextMenu:component:copyID', this.onCopyID),
this.on('contextMenu:component:copyID', this.onCopyID);
this.on('contextMenu:component:cut', this.onCut);
this.on('contextMenu:component:delete', this.deleteComponentPrompt);
},
Expand Down Expand Up @@ -93,7 +93,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 @@ -133,29 +136,49 @@ define(function(require){
});
},

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

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,
right: false,
full: false
};

var siblings = this.model.getSiblings();
var showFull = !siblings.length;
var type = this.model.get('_layout');
switch (type) {
case 'left':
movePositions.right = true;
movePositions.full = showFull;
break;
case 'right':
movePositions.left = true;
movePositions.full = showFull;
break;
case 'full':
movePositions.left = true;
movePositions.right = true;
break
if (isHalfWidthSupported) {
var siblings = this.model.getSiblings();
var showFull = !siblings.length && isFullWidthSupported;
var type = this.model.get('_layout');

switch (type) {
case 'left':
movePositions.right = true;
movePositions.full = showFull;
break;
case 'right':
movePositions.left = true;
movePositions.full = showFull;
break;
case 'full':
movePositions.left = true;
movePositions.right = true;
break
}
}

this.model.set('_movePositions', movePositions);
Expand Down
23 changes: 21 additions & 2 deletions frontend/src/modules/editor/global/views/editorOriginView.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,31 @@ define(function(require){
$('.add-control').removeClass('display-none');
},

showDropZones: function() {
showDropZones: function (supportedLayout) {
$('.paste-zone').addClass('display-none');
$('.add-control').addClass('display-none');
$('.paste-zone-'+ this.model.get('_type') + ' a').addClass('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');

$('.paste-zone-'+ this.model.get('_type'))
$pasteZones
.addClass('paste-zone-available')
.removeClass('display-none');

Expand Down