2014-07-30 03:18:43 +00:00
|
|
|
|
Metamaps.Backbone = {};
|
|
|
|
|
Metamaps.Backbone.Map = Backbone.Model.extend({
|
|
|
|
|
urlRoot: '/maps',
|
2014-08-10 17:06:58 +00:00
|
|
|
|
blacklist: ['created_at', 'updated_at', 'map', 'topics', 'synapses', 'mappings', 'mappers'],
|
2014-07-30 03:18:43 +00:00
|
|
|
|
toJSON: function (options) {
|
|
|
|
|
return _.omit(this.attributes, this.blacklist);
|
|
|
|
|
},
|
|
|
|
|
authorizeToEdit: function (mapper) {
|
|
|
|
|
if (mapper && (this.get('permission') === "commons" || this.get('user_id') === mapper.get('id'))) return true;
|
|
|
|
|
else return false;
|
2014-08-10 17:06:58 +00:00
|
|
|
|
},
|
|
|
|
|
getUser: function () {
|
|
|
|
|
return Metamaps.Mapper.get(this.get('user_id'));
|
|
|
|
|
},
|
|
|
|
|
getTopics: function () {
|
|
|
|
|
if (!this.get('topics')) {
|
|
|
|
|
this.fetch({async: false});
|
|
|
|
|
}
|
|
|
|
|
return this.get('topics');
|
|
|
|
|
},
|
|
|
|
|
getSynapses: function () {
|
|
|
|
|
if (!this.get('synapses')) {
|
|
|
|
|
this.fetch({async: false});
|
|
|
|
|
}
|
|
|
|
|
return this.get('synapses');
|
|
|
|
|
},
|
|
|
|
|
attrForCards: function () {
|
|
|
|
|
var obj = {
|
|
|
|
|
id: this.id,
|
|
|
|
|
name: this.get('name'),
|
|
|
|
|
desc: this.get('desc'),
|
|
|
|
|
username: this.getUser().get('name'),
|
|
|
|
|
mkPermission: this.get("permission").substring(0, 2),
|
|
|
|
|
editPermission: this.authorizeToEdit(Metamaps.Active.Mapper) ? 'canEdit' : 'cannotEdit',
|
|
|
|
|
topicCount: this.getTopics().length,
|
|
|
|
|
synapseCount: this.getSynapses().length,
|
|
|
|
|
createdAt: this.get('created_at')
|
|
|
|
|
};
|
|
|
|
|
return obj;
|
2014-07-30 03:18:43 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
Metamaps.Backbone.MapsCollection = Backbone.Collection.extend({
|
|
|
|
|
model: Metamaps.Backbone.Map,
|
2014-08-10 17:06:58 +00:00
|
|
|
|
initialize: function(models, options) {
|
|
|
|
|
this.id = options.id;
|
|
|
|
|
this.sortBy = options.sortBy;
|
|
|
|
|
},
|
|
|
|
|
url: function() {
|
|
|
|
|
return '/explore/' + this.id + '.json';
|
|
|
|
|
},
|
|
|
|
|
comparator: function (a, b) {
|
|
|
|
|
a = a.get(this.sortBy);
|
|
|
|
|
b = b.get(this.sortBy);
|
|
|
|
|
if (this.sortBy === 'name') {
|
|
|
|
|
a = a.toLowerCase();
|
|
|
|
|
b = b.toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
return a > b ? 1 : a < b ? -1 : 0;
|
|
|
|
|
},
|
|
|
|
|
getMaps: function () {
|
|
|
|
|
|
|
|
|
|
Metamaps.Loading.loader.show();
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
this.fetch({
|
|
|
|
|
reset: true,
|
|
|
|
|
success: function (collection, response, options) {
|
|
|
|
|
// you can pass additional options to the event you trigger here as well
|
|
|
|
|
self.trigger('successOnFetch');
|
|
|
|
|
},
|
|
|
|
|
error: function (collection, response, options) {
|
|
|
|
|
// you can pass additional options to the event you trigger here as well
|
|
|
|
|
self.trigger('errorOnFetch');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-07-30 03:18:43 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Metamaps.Backbone.Mapper = Backbone.Model.extend({
|
|
|
|
|
urlRoot: '/users',
|
|
|
|
|
blacklist: ['created_at', 'updated_at'],
|
|
|
|
|
toJSON: function (options) {
|
|
|
|
|
return _.omit(this.attributes, this.blacklist);
|
|
|
|
|
},
|
2014-08-04 16:20:16 +00:00
|
|
|
|
prepareLiForFilter: function () {
|
|
|
|
|
var li = '';
|
|
|
|
|
li += '<li data-id="' + this.id.toString() + '">';
|
|
|
|
|
li += '<img src="/assets/icons/person.png" data-id="' + this.id.toString() + '"';
|
|
|
|
|
li += ' alt="' + this.get('name') + '" />';
|
|
|
|
|
li += '<p>' + this.get('name') + '</p></li>';
|
|
|
|
|
return li;
|
|
|
|
|
}
|
2014-07-30 03:18:43 +00:00
|
|
|
|
});
|
|
|
|
|
Metamaps.Backbone.MapperCollection = Backbone.Collection.extend({
|
|
|
|
|
model: Metamaps.Backbone.Mapper,
|
|
|
|
|
url: '/users'
|
2014-07-31 01:10:10 +00:00
|
|
|
|
});
|