Skip to content

Commit

Permalink
Amend contentModel._children to allow for arrays
Browse files Browse the repository at this point in the history
Fix #1719
  • Loading branch information
taylortom committed Oct 16, 2017
1 parent 4004e21 commit f54d501
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
3 changes: 2 additions & 1 deletion frontend/src/core/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,14 @@ define(function(require){
if (currentChildren.length == 0) {
containsAtLeastOneChild = false;

var children = _.isArray(model._children) ? model._children.join('/') : model._children;
alerts.push(
"There seems to be a "
+ model.get('_type')
+ " with the title - '"
+ model.get('title')
+ "' with no "
+ model._children
+ children
);

return;
Expand Down
26 changes: 21 additions & 5 deletions frontend/src/core/models/contentModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,28 @@ define(function(require) {
},

getChildren: function() {
if (Origin.editor.data[this._children]) {
var children = Origin.editor.data[this._children].where({ _parentId: this.get('_id') });
var childrenCollection = new Backbone.Collection(children);
return childrenCollection;
var self = this;
var getChildrenDelegate = function(type) {
if (Origin.editor.data[type]) {
var children = Origin.editor.data[type].where({ _parentId: self.get('_id') });
var childrenCollection = new Backbone.Collection(children);
return childrenCollection;
}
return null;
};
if(_.isArray(this._children)) {
var allChildren;
for(var i = 0, count = this._children.length; i < count; i++) {
var children = getChildrenDelegate(this._children[i]);
if(children) {
if(!allChildren) allChildren = children;
else allChildren.add(children.models);
}
}
return allChildren;
} else {
return getChildrenDelegate(this._children);
}
return null;
},

getParent: function() {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/core/models/contentObjectModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ define(function(require) {
var ContentObjectModel = ContentModel.extend({
urlRoot: '/api/content/contentobject',
_parent: 'contentObjects',
_siblings:'contentObjects',
_children: 'articles',
_siblings: 'contentObjects',
_children: ['contentObjects', 'articles'],

defaults: {
_isSelected: false,
Expand Down

0 comments on commit f54d501

Please sign in to comment.