* actioncable needs puma not webrick * add framework * remove the old way * send events from server to client * get all events working * clean up receivable * map is polymorphic on message * add the moved event * make todo comments clear * verify before streaming from map channel * rubocop fixes * wasn't set up correctly for nodejs realtime
63 lines
1.9 KiB
JavaScript
63 lines
1.9 KiB
JavaScript
/* global $ */
|
|
|
|
import _ from 'lodash'
|
|
import Backbone from 'backbone'
|
|
try { Backbone.$ = window.$ } catch (err) {}
|
|
|
|
import Active from '../Active'
|
|
import InfoBox from '../Map/InfoBox'
|
|
import Mapper from '../Mapper'
|
|
import Realtime from '../Realtime'
|
|
|
|
const Map = Backbone.Model.extend({
|
|
urlRoot: '/maps',
|
|
blacklist: ['created_at', 'updated_at', 'created_at_clean', 'updated_at_clean', 'user_name', 'contributor_count', 'topic_count', 'synapse_count', 'topics', 'synapses', 'mappings', 'mappers'],
|
|
toJSON: function(options) {
|
|
return _.omit(this.attributes, this.blacklist)
|
|
},
|
|
initialize: function() {
|
|
this.on('changeByOther', this.updateView)
|
|
},
|
|
authorizeToEdit: function(mapper) {
|
|
if (mapper && (
|
|
this.get('permission') === 'commons' ||
|
|
(this.get('collaborator_ids') || []).includes(mapper.get('id')) ||
|
|
this.get('user_id') === mapper.get('id'))) {
|
|
return true
|
|
} else {
|
|
return false
|
|
}
|
|
},
|
|
authorizePermissionChange: function(mapper) {
|
|
if (mapper && this.get('user_id') === mapper.get('id')) {
|
|
return true
|
|
} else {
|
|
return false
|
|
}
|
|
},
|
|
getUser: function() {
|
|
return Mapper.get(this.get('user_id'))
|
|
},
|
|
updateView: function() {
|
|
var map = Active.Map
|
|
var isActiveMap = this.id === map.id
|
|
if (isActiveMap) {
|
|
InfoBox.updateNameDescPerm(this.get('name'), this.get('desc'), this.get('permission'))
|
|
this.updateMapWrapper()
|
|
// mobile menu
|
|
$('#header_content').html(this.get('name'))
|
|
document.title = this.get('name') + ' | Metamaps'
|
|
}
|
|
},
|
|
updateMapWrapper: function() {
|
|
var map = Active.Map
|
|
var isActiveMap = this.id === map.id
|
|
var authorized = map && map.authorizeToEdit(Active.Mapper) ? 'canEditMap' : ''
|
|
var commonsMap = map && map.get('permission') === 'commons' ? 'commonsMap' : ''
|
|
if (isActiveMap) {
|
|
$('.wrapper').removeClass('canEditMap commonsMap').addClass(authorized + ' ' + commonsMap)
|
|
}
|
|
}
|
|
})
|
|
|
|
export default Map
|