<commit_before>var cdb = require('cartodb.js');
var WidgetLoaderView = require('./widget-loader-view');
var WidgetErrorView = require('./widget-error-view');

/**
 * Default widget view
 * The model is a expected to be widget model
 */
module.exports = cdb.core.View.extend({
  className: 'CDB-Widget CDB-Widget--light',

  options: {
    columns_title: []
  },

  initialize: function () {
    if (this.model.dataviewModel) {
      this.model.dataviewModel.layer.bind('change:visible', this._onChangeLayerVisible, this);
      this.listenTo(this.model, 'destroy', this.clean);
    }
  },

  render: function () {
    var dataviewModel = this.model.dataviewModel;
    if (dataviewModel) {
      this._appendView(new WidgetLoaderView({
        model: dataviewModel
      }));

      this._appendView(new WidgetErrorView({
        model: dataviewModel
      }));
    }

    this._appendView(this.options.contentView);

    return this;
  },

  _appendView: function (view) {
    this.$el.append(view.render().el);
    this.addView(view);
  },

  _onChangeLayerVisible: function (layer) {
    // !! to force a boolean value, so only a true value actually shows the view
    this.$el.toggle(!!layer.get('visible'));
  }
});<commit_msg>Hides/shows widgets depending on the layer visibility<commit_after>var cdb = require('cartodb.js');
var WidgetLoaderView = require('./widget-loader-view');
var WidgetErrorView = require('./widget-error-view');

/**
 * Default widget view
 * The model is a expected to be widget model
 */
module.exports = cdb.core.View.extend({
  className: 'CDB-Widget CDB-Widget--light',

  options: {
    columns_title: []
  },

  initialize: function () {
    if (this.model.dataviewModel) {
      this.model.dataviewModel.layer.bind('change:visible', this._onChangeLayerVisible, this);
      this.listenTo(this.model, 'destroy', this.clean);
    }
  },

  render: function () {
    var dataviewModel = this.model.dataviewModel;
    if (dataviewModel) {
      this._appendView(new WidgetLoaderView({
        model: dataviewModel
      }));

      this._appendView(new WidgetErrorView({
        model: dataviewModel
      }));
    }

    this._appendView(this.options.contentView);

    // Show or hide the widget depending on the layer visibility
    this._setVisible(this.model.dataviewModel.layer.get('visible'));

    return this;
  },

  _appendView: function (view) {
    this.$el.append(view.render().el);
    this.addView(view);
  },

  _setVisible: function (visible) {
    this.$el.toggle(visible);
  },

  _onChangeLayerVisible: function (layer) {
    // !! to force a boolean value, so only a true value actually shows the view
    this._setVisible(!!layer.get('visible'));
  }
});
{'fraction_non_alphanumeric': 0.14132841328413284, 'fraction_numerical': 0.0, 'mean_word_length': 3.303174603174603, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7028435', 'n_tokens_mistral': 850, 'n_tokens_neox': 841, 'n_words': 179}