cartodb-4.42/lib/assets/javascripts/cartodb/table/watching_notifier_view.js

55 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-04-06 13:25:13 +08:00
/**
* Displays which users are editing/viewing the
* current visualization.
*
* - It needs the watching notifier model and the user model.
*/
cdb.admin.WatchingNotifierView = cdb.core.View.extend({
className: 'watching-notifier',
tagName: 'div',
initialize: function() {
this.user = this.options.user;
this._initBinds();
this.template = cdb.templates.getTemplate('table/views/watching_notifier');
},
render: function() {
var users = this._removeCurrentUser( this.model.get('users') ) || [];
this.$el.html(this.template({ users: users }));
return this;
},
_initBinds: function() {
this.model.bind('change', this._onModelChange, this);
},
_onModelChange: function() {
var users = this._removeCurrentUser( this.model.get('users') ) || [];
if (users.length > 0) {
this
.render()
.show();
} else {
this.hide();
}
},
_removeCurrentUser: function(users) {
var self = this;
return _.reject(users, function(name) { return name === self.user.get('username') })
},
show: function() {
this.$el.addClass('active')
},
hide: function() {
this.$el.removeClass('active')
}
});