cartodb/lib/assets/javascripts/builder/components/apply-button/apply-button-view.js
2020-06-15 10:58:47 +08:00

43 lines
822 B
JavaScript
Executable File

var CoreView = require('backbone/core-view');
var template = require('./apply-button.tpl');
var checkAndBuildOpts = require('builder/helpers/required-opts');
var REQUIRED_OPTS = [
'onApplyClick',
'overlayModel'
];
module.exports = CoreView.extend({
events: {
'click .js-apply': '_onClick'
},
initialize: function (opts) {
checkAndBuildOpts(opts, REQUIRED_OPTS, this);
this._initBinds();
},
render: function () {
this.$el.html(template({
disabled: this._isDisabled()
}));
return this;
},
_initBinds: function () {
this.listenTo(this._overlayModel, 'change:visible', this.render);
},
_isDisabled: function () {
return this._overlayModel.get('visible');
},
_onClick: function () {
if (this._isDisabled()) return;
this._onApplyClick();
}
});