I have a Newsletter which can be represented by the following JSON model. I'd like to build a newsletter editor which allows drag/drop moving of entries (articles), as well as the ability to add new entries. Ultimately, the JSON will be saved via an API into a database.
var newsletter = new Newsletter({
id : 1,
title : 'Newsletter 1',
date : '17.08.2014',
sections : [
{ title : 'Lorem ipsum dolor sit amet',
color : '831b12',
subsections : [
{ title : 'Lorem ipsum dolor sit amet',
entries : [
{ title : 'Lorem ipsum dolor sit amet',
intro : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce lacus mi, ullamcorper id mi non, dign...',
url : '#'
},
{ title : 'Lorem ipsum dolor sit amet',
intro : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce lacus mi, ullamcorper id mi non, dign...',
url : '#'
}
]
},
{ title : 'Lorem ipsum dolor sit amet',
entries : [
{ title : 'Lorem ipsum dolor sit amet',
intro : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce lacus mi, ullamcorper id mi non, dign...',
url : '#'
},
{ title : 'Lorem ipsum dolor sit amet',
intro : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce lacus mi, ullamcorper id mi non, dign...',
url : '#'
},
{ title : 'Lorem ipsum dolor sit amet',
intro : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce lacus mi, ullamcorper id mi non, dign...',
url : '#'
}
]
}
]
}
]
});
I am unclear whether I require a single Backbone model, Newsletter, or whether I would need models for each 'layer' (i.e. newsletter, section, subsection, entry) and then to model the relationship somehow? I have seen links to Backbone Relational which sounds promising but I wasn't sure whether it was necessary for this application.
Most of the tutorial that I've seen so far seem to focus on todo-style apps with a single layer of todo items, in a collection. I suppose that a newsletter could be considered a collection of sections, a section a collection of subsections etc. Is that the correct path to be following?
Thanks :)
Just for the record, I ended up building this in Knockout.JS and it handled it beautifully.
I was able to write chunks of HTML that were generated for each json element type (sections, subsections and entries) which formed the basis of the newsletter. I then used the Knockout Sortable plugin to allow elements to be reordered within parent objects whilst keeping the hierachy intact (i.e. subsections could be moved within their own section, or moved to another section).
Hopefully someone will find this useful.