2016-10-02 09:58:37 +00:00
|
|
|
import _ from 'lodash'
|
|
|
|
import Backbone from 'backbone'
|
2016-10-03 00:32:37 +00:00
|
|
|
try { Backbone.$ = window.$ } catch (err) {}
|
2016-10-02 09:58:37 +00:00
|
|
|
import outdent from 'outdent'
|
|
|
|
|
|
|
|
const Mapper = Backbone.Model.extend({
|
|
|
|
urlRoot: '/users',
|
2017-03-07 03:49:46 +00:00
|
|
|
blacklist: ['created_at', 'updated_at', 'follows'],
|
2016-11-07 20:25:08 +00:00
|
|
|
toJSON: function(options) {
|
2016-10-02 09:58:37 +00:00
|
|
|
return _.omit(this.attributes, this.blacklist)
|
|
|
|
},
|
2016-11-07 20:25:08 +00:00
|
|
|
prepareLiForFilter: function() {
|
2016-10-02 09:58:37 +00:00
|
|
|
return outdent`
|
|
|
|
<li data-id="${this.id}">
|
|
|
|
<img src="${this.get('image')}" data-id="${this.id}" alt="${this.get('name')}" />
|
|
|
|
<p>${this.get('name')}</p>
|
|
|
|
</li>`
|
2017-03-07 03:49:46 +00:00
|
|
|
},
|
|
|
|
followMap: function(id) {
|
|
|
|
this.get('follows').maps.push(id)
|
|
|
|
},
|
|
|
|
unfollowMap: function(id) {
|
|
|
|
const idIndex = this.get('follows').maps.indexOf(id)
|
|
|
|
if (idIndex > -1) this.get('follows').maps.splice(idIndex, 1)
|
|
|
|
},
|
|
|
|
followTopic: function(id) {
|
|
|
|
this.get('follows').topics.push(id)
|
|
|
|
},
|
|
|
|
unfollowTopic: function(id) {
|
|
|
|
const idIndex = this.get('follows').topics.indexOf(id)
|
|
|
|
if (idIndex > -1) this.get('follows').topics.splice(idIndex, 1)
|
2016-10-02 09:58:37 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
export default Mapper
|