var FlowyDocModel = Backbone.Collection.extend({
initialize: function(options) {
options = _.defaults({}, options, flowyDocDefaults);
- this.id = options.id;
- this.default = options.default;
this.rootId = options.rootId;
},
model: TodoModel,
localStorage: new Backbone.LocalStorage("todos-backbone"),
- fetch: function(options) { // TODO: Move to base class as default behavior for localStorage
- // If during the initial fetch, the collection is not present, instead populate it using this.default
- options = options ? _.clone(options) : {};
- var error = options.error;
- var collection = this;
- options.error = function(_, resp, __) {
- if (resp ==="Record Not Found" && collection.default) {
- var method = options.reset ? 'reset' : 'set';
- collection[method](collection.default);
- }
- if (error) error(collection, resp, options);
- };
- Backbone.Collection.prototype.fetch.call(this, options);
- },
nextOrder: function() {
if (!this.length) return 1;
return this.last().get('order') + 1;
*/
var todos = new FlowyDocModel({
+ /*
id: "master",
default: [
new TodoModel({
text: "Save California",
}),
],
+ */
});
var appDefaults = { list: todos };
options = _.defaults({}, options, appDefaults);
this.listenTo(todos, 'add', this.addOne);
this.listenTo(todos, 'reset', this.addAll);
- this.list = options.list;
+ this.list = options.list || new FlowDocModel();
this.views = {}; // A list of views for each element in the collection
this.list.fetch();
},
var FlowyDocModel = Backbone.Collection.extend({
initialize: function(options) {
options = _.defaults({}, options, flowyDocDefaults);
- this.id = options.id;
- this.default = options.default;
this.rootId = options.rootId;
},
model: TodoModel,
localStorage: new Backbone.LocalStorage("todos-backbone"),
- fetch: function(options) { // TODO: Move to base class as default behavior for localStorage
- // If during the initial fetch, the collection is not present, instead populate it using this.default
- options = options ? _.clone(options) : {};
- var error = options.error;
- var collection = this;
- options.error = function(_, resp, __) {
- if (resp ==="Record Not Found" && collection.default) {
- var method = options.reset ? 'reset' : 'set';
- collection[method](collection.default);
- }
- if (error) error(collection, resp, options);
- };
- Backbone.Collection.prototype.fetch.call(this, options);
- },
nextOrder: function() {
if (!this.length) return 1;
return this.last().get('order') + 1;
*/
var todos = new FlowyDocModel({
+ /*
id: "master",
default: [
new TodoModel({
text: "Save California",
}),
],
+ */
});
var appDefaults = { list: todos };
options = _.defaults({}, options, appDefaults);
this.listenTo(todos, 'add', this.addOne);
this.listenTo(todos, 'reset', this.addAll);
- this.list = options.list;
+ this.list = options.list || new FlowDocModel();
this.views = {}; // A list of views for each element in the collection
this.list.fetch();
},
var FlowyDocModel = Backbone.Collection.extend({
initialize: function(options) {
options = _.defaults({}, options, flowyDocDefaults);
- this.id = options.id;
- this.default = options.default;
this.rootId = options.rootId;
},
model: TodoModel,
localStorage: new Backbone.LocalStorage("todos-backbone"),
- fetch: function(options) { // TODO: Move to base class as default behavior for localStorage
- // If during the initial fetch, the collection is not present, instead populate it using this.default
- options = options ? _.clone(options) : {};
- var error = options.error;
- var collection = this;
- options.error = function(_, resp, __) {
- if (resp ==="Record Not Found" && collection.default) {
- var method = options.reset ? 'reset' : 'set';
- collection[method](collection.default);
- }
- if (error) error(collection, resp, options);
- };
- Backbone.Collection.prototype.fetch.call(this, options);
- },
nextOrder: function() {
if (!this.length) return 1;
return this.last().get('order') + 1;
*/
var todos = new FlowyDocModel({
+ /*
id: "master",
default: [
new TodoModel({
text: "Save California",
}),
],
+ */
});
var appDefaults = { list: todos };
options = _.defaults({}, options, appDefaults);
this.listenTo(todos, 'add', this.addOne);
this.listenTo(todos, 'reset', this.addAll);
- this.list = options.list;
+ this.list = options.list || new FlowDocModel();
this.views = {}; // A list of views for each element in the collection
this.list.fetch();
},