2011-04-23 15:13:54 +00:00
|
|
|
/* Ensure a Collection is fetched and has entries before running a block of code. */
|
|
|
|
|
|
|
|
_.extend(Backbone.Collection.prototype, {
|
|
|
|
ensureFetched: function(callback) {
|
2011-05-03 19:43:19 +00:00
|
|
|
if (this._alreadyEnsureFetched) {
|
2011-04-23 15:13:54 +00:00
|
|
|
var _this = this;
|
|
|
|
var _refresher = function() {
|
|
|
|
_this.unbind('refresh', _refresher);
|
|
|
|
callback.apply(_this);
|
|
|
|
_this._alreadyEnsureFetched = true;
|
|
|
|
};
|
|
|
|
this.bind('refresh', _refresher);
|
|
|
|
this.fetch();
|
|
|
|
} else {
|
|
|
|
callback.apply(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-05-03 19:43:19 +00:00
|
|
|
_.extend(Backbone.View.prototype, {
|
|
|
|
attributes: function() {
|
|
|
|
var attrs = {};
|
|
|
|
var _this = this;
|
|
|
|
_.each(this.attributeFields, function(field) {
|
|
|
|
attrs[field] = _this.$('input[name="' + field + '"]').val();
|
|
|
|
});
|
|
|
|
return attrs;
|
|
|
|
}
|
|
|
|
});
|