Skip to content

Commit a317ee5

Browse files
authored
Merge pull request #1632 from danielstorey/issue/1631
Fixes #1631
2 parents eddc103 + e8ffd1b commit a317ee5

3 files changed

Lines changed: 77 additions & 33 deletions

File tree

frontend/src/modules/editor/contentObject/views/editorPageComponentListView.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,31 +78,33 @@ define(function(require) {
7878

7979
renderComponentList: function() {
8080
Origin.trigger('editorComponentListView:removeSubviews');
81-
// _.each(this.collection, function(componentType) {
81+
8282
this.collection.each(function(componentType) {
8383
var properties = componentType.get('properties');
84-
if (properties && properties.hasOwnProperty('._supportedLayout')) {
85-
var supportedLayout = properties.hasOwnProperty('._supportedLayout').enum;
84+
var availablePositions = _.clone(this.availablePositions);
85+
86+
if (properties && properties.hasOwnProperty('_supportedLayout')) {
87+
var supportedLayout = properties._supportedLayout.enum;
8688

8789
// Prune the available positions
8890
if (_.indexOf(supportedLayout, 'half-width') == -1) {
89-
this.availablePositions.left = false;
90-
this.availablePositions.right = false;
91+
availablePositions.left = false;
92+
availablePositions.right = false;
9193
}
9294

9395
if (_.indexOf(supportedLayout, 'full-width') == -1) {
94-
this.availablePositions.full = false;
96+
availablePositions.full = false;
9597
}
9698
}
9799

98100
this.$('.editor-component-list-sidebar-list').append(new EditorPageComponentListItemView({
99-
model: componentType,
100-
availablePositions: this.availablePositions,
101-
_parentId: this.model.get('_parentId'),
102-
$parentElement: this.$parentElement,
103-
parentView: this.parentView,
104-
searchTerms: componentType.get('displayName').toLowerCase()
105-
}).$el);
101+
model: componentType,
102+
availablePositions: availablePositions,
103+
_parentId: this.model.get('_parentId'),
104+
$parentElement: this.$parentElement,
105+
parentView: this.parentView,
106+
searchTerms: componentType.get('displayName').toLowerCase()
107+
}).$el);
106108
}, this);
107109
},
108110

frontend/src/modules/editor/contentObject/views/editorPageComponentView.js

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ define(function(require){
2525

2626
this.on('contextMenu:component:edit', this.loadComponentEdit);
2727
this.on('contextMenu:component:copy', this.onCopy);
28-
this.on('contextMenu:component:copyID', this.onCopyID),
28+
this.on('contextMenu:component:copyID', this.onCopyID);
2929
this.on('contextMenu:component:cut', this.onCut);
3030
this.on('contextMenu:component:delete', this.deleteComponentPrompt);
3131
},
@@ -93,7 +93,10 @@ define(function(require){
9393
view.offsetTopFromWindow = view.$el.offset().top - $(window).scrollTop();
9494
// This is in the helper method because the height needs to be
9595
// manipulated before the drag start method due to adding drop zones
96-
view.showDropZones();
96+
// Passing the supported layout as a parameter allows the method to
97+
// determine which drop zones should be displayed
98+
var supportedLayout = view.getSupportedLayout();
99+
view.showDropZones(supportedLayout);
97100
$(this).attr('data-component-id', view.model.get('_id'));
98101
$(this).attr('data-block-id', view.model.get('_parentId'));
99102
return $('<div class="drag-helper">' + view.model.get('title') + '</div>');
@@ -133,29 +136,49 @@ define(function(require){
133136
});
134137
},
135138

139+
getSupportedLayout: function() {
140+
var componentType = _.find(Origin.editor.data.componenttypes.models, function(type){
141+
return type.get('component') === this.model.get('_component');
142+
}, this);
143+
144+
var supportedLayout = componentType.get('properties')._supportedLayout;
145+
146+
return {
147+
full: _.indexOf(supportedLayout.enum, 'full-width') > -1,
148+
half: _.indexOf(supportedLayout.enum, 'half-width') > -1
149+
}
150+
},
151+
136152
evaluateLayout: function() {
153+
var supportedLayout = this.getSupportedLayout();
154+
var isFullWidthSupported = supportedLayout.full;
155+
var isHalfWidthSupported = supportedLayout.half;
156+
137157
var movePositions = {
138158
left: false,
139159
right: false,
140160
full: false
141161
};
142162

143-
var siblings = this.model.getSiblings();
144-
var showFull = !siblings.length;
145-
var type = this.model.get('_layout');
146-
switch (type) {
147-
case 'left':
148-
movePositions.right = true;
149-
movePositions.full = showFull;
150-
break;
151-
case 'right':
152-
movePositions.left = true;
153-
movePositions.full = showFull;
154-
break;
155-
case 'full':
156-
movePositions.left = true;
157-
movePositions.right = true;
158-
break
163+
if (isHalfWidthSupported) {
164+
var siblings = this.model.getSiblings();
165+
var showFull = !siblings.length && isFullWidthSupported;
166+
var type = this.model.get('_layout');
167+
168+
switch (type) {
169+
case 'left':
170+
movePositions.right = true;
171+
movePositions.full = showFull;
172+
break;
173+
case 'right':
174+
movePositions.left = true;
175+
movePositions.full = showFull;
176+
break;
177+
case 'full':
178+
movePositions.left = true;
179+
movePositions.right = true;
180+
break
181+
}
159182
}
160183

161184
this.model.set('_movePositions', movePositions);

frontend/src/modules/editor/global/views/editorOriginView.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,31 @@ define(function(require){
6464
$('.add-control').removeClass('display-none');
6565
},
6666

67-
showDropZones: function() {
67+
showDropZones: function (supportedLayout) {
6868
$('.paste-zone').addClass('display-none');
6969
$('.add-control').addClass('display-none');
7070
$('.paste-zone-'+ this.model.get('_type') + ' a').addClass('display-none');
71+
// Components may be restricted to either full or half width so
72+
// make sure only the appropriate paste zones are displayed
73+
var type = this.model.get('_type');
74+
var pasteZoneSelector = '.paste-zone-'+ type;
75+
var $pasteZones;
76+
77+
if (type === 'component') {
78+
$pasteZones = $();
79+
if (supportedLayout.full) {
80+
$pasteZones = $pasteZones.add('.paste-zone-component-full');
81+
}
82+
if (supportedLayout.half) {
83+
$pasteZones = $pasteZones.add('.paste-zone-component-left, .paste-zone-component-right');
84+
}
85+
} else {
86+
$pasteZones = $(pasteZoneSelector);
87+
}
88+
89+
$(pasteZoneSelector + ' a').addClass('display-none');
7190

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

0 commit comments

Comments
 (0)