app/assets/javascripts/pageflow/editor/models/entry.js in pageflow-0.9.2 vs app/assets/javascripts/pageflow/editor/models/entry.js in pageflow-0.10.0
- old
+ new
@@ -17,10 +17,12 @@
this.configuration = new pageflow.EntryConfiguration(this.get('configuration') || {});
this.configuration.parent = this;
this.files = options.files || pageflow.files;
+ this.storylines = options.storylines || pageflow.storylines;
+ this.storylines.parentModel = this;
this.chapters = options.chapters || pageflow.chapters;
this.chapters.parentModel = this;
this.pages = pageflow.pages;
this.imageFiles = pageflow.imageFiles;
@@ -29,10 +31,14 @@
pageflow.editor.fileTypes.each(function(fileType) {
this.watchFileCollection(fileType.collectionName, this.getFileCollection(fileType));
}, this);
+ this.listenTo(this.storylines, 'sort', function() {
+ this.pages.sort();
+ });
+
this.listenTo(this.chapters, 'sort', function() {
this.pages.sort();
});
this.listenTo(this.configuration, 'change', function() {
@@ -47,19 +53,40 @@
location.reload();
});
});
},
- addChapter: function(params) {
+ addStoryline: function(attributes) {
+ var storyline = this.buildStoryline(attributes);
+ storyline.save();
+
+ return storyline;
+ },
+
+ buildStoryline: function(attributes) {
var defaults = {
- entry_id: this.get('id'),
title: '',
- position: this.chapters.length
};
- return this.chapters.create(_.extend(defaults, params));
+
+ return this.storylines.addAndReturnModel(_.extend(defaults, attributes));
},
+ scaffoldStoryline: function(options) {
+ var scaffold = new pageflow.StorylineScaffold(this, options);
+ scaffold.create();
+
+ return scaffold;
+ },
+
+ addChapterInNewStoryline: function(options) {
+ return this.scaffoldStoryline(_.extend({depth: 'chapter'}, options)).chapter;
+ },
+
+ addPageInNewStoryline: function(options) {
+ return this.scaffoldStoryline(_.extend({depth: 'page'}, options)).page;
+ },
+
addFileUpload: function(upload) {
var fileType = pageflow.editor.fileTypes.findByUpload(upload);
var file = new fileType.model({
state: 'uploading',
file_name: upload.name
@@ -76,9 +103,11 @@
});
fileUsages.createForFile(file, { success: function(usage) {
file.set('usage_id', usage.get('id'));
this.getFileCollection(file.fileType()).add(file);
+
+ this.trigger('use:file', file);
}.bind(this)});
},
getFileCollection: function(fileType) {
return this.files[fileType.collectionName];