2015-01-20 10:25:10 +00:00
|
|
|
define([
|
|
|
|
'underscore',
|
|
|
|
'backbone',
|
2016-03-09 12:54:33 +00:00
|
|
|
'common',
|
2015-01-20 10:25:10 +00:00
|
|
|
'app/models/repo'
|
2016-03-09 12:54:33 +00:00
|
|
|
], function(_, Backbone, Common, Repo) {
|
2015-01-20 10:25:10 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var RepoCollection = Backbone.Collection.extend({
|
|
|
|
model: Repo,
|
2015-02-04 13:57:26 +00:00
|
|
|
type: 'mine',
|
2015-01-20 10:25:10 +00:00
|
|
|
|
2016-03-09 12:54:33 +00:00
|
|
|
url: function() {
|
|
|
|
return Common.getUrl({name: 'repos'});
|
|
|
|
},
|
|
|
|
|
2015-02-04 13:57:26 +00:00
|
|
|
initialize: function(options) {
|
2015-02-01 06:15:00 +00:00
|
|
|
//console.log('init RepoCollection');
|
2015-02-04 13:57:26 +00:00
|
|
|
if (options) {
|
|
|
|
this.type = options.type ? options.type : 'mine';
|
|
|
|
}
|
2015-01-31 05:17:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
fetch: function(options) {
|
|
|
|
// override default fetch url
|
|
|
|
options = options ? _.clone(options) : {};
|
2016-03-09 12:54:33 +00:00
|
|
|
options.url = this.url() + '?type=' + this.type;
|
2015-01-31 05:17:47 +00:00
|
|
|
|
|
|
|
//call Backbone's fetch
|
|
|
|
return Backbone.Collection.prototype.fetch.call(this, options);
|
2015-03-20 05:48:40 +00:00
|
|
|
},
|
2015-01-20 10:25:10 +00:00
|
|
|
|
2015-03-20 05:48:40 +00:00
|
|
|
create: function(model, options) {
|
|
|
|
// override default create url
|
|
|
|
options = options ? _.clone(options) : {};
|
2016-03-19 02:36:18 +00:00
|
|
|
options.url = this.url() + '?from=web';
|
2015-03-20 05:48:40 +00:00
|
|
|
|
|
|
|
//call Backbone's create
|
|
|
|
return Backbone.Collection.prototype.create.call(this, model, options);
|
|
|
|
}
|
2015-01-20 10:25:10 +00:00
|
|
|
});
|
|
|
|
|
2015-02-01 06:15:00 +00:00
|
|
|
return RepoCollection;
|
2015-01-20 10:25:10 +00:00
|
|
|
});
|