<commit_before>/**
 * this infowindow is shown in the map when user clicks on a feature
 */

(function() {

  var MapInfowindow = cdb.geo.ui.Infowindow.extend({
    _TEXTS: {
      _NO_FIELDS_SELECTED: "You haven’t selected any <br/>infowindow fields."
    },

    events: cdb.core.View.extendEvents({
      'click .edit_data': '_editData',
      'click .edit_geo':  '_editGeom',
      'click .remove':    '_removeGeom'
    }),

    initialize: function() {
      var self = this;
      _.bindAll(this, '_removeGeom');
      this.table = this.options.table;
      this.model.set({ content: 'loading...' });
      // call parent
      this.constructor.__super__.initialize.apply(this);
      this.model.set('offset', [28, 0]);
      this.model.bind('change:fields', function() {
        if(!this.hasChanged('content') && self.row) {
          self.renderInfo();
        }
      });

      // Create a help dialog for the infowindows with images
      if (this._containsCover) this._createHelpDialog();

      // Set live tipsy when geom is enabled or disabled
      this.$el.find("div.cartodb-edit-buttons a.button").tipsy({
        live:true,
        fade:true,
        gravity: 's',
        offset: -2,
        className: function(){
          return $(this).closest(".cartodb-popup").hasClass('dark') ? 'dark' : ''
        },
        title: function(ev){
          var enabled = !$(this).hasClass("disabled");
          if (enabled) {
            return $(this).text()
          } else {
            return 'Not available in SQL view'
          }
        }
      })
    },

    _createHelpDialog: function() {

      var HelpDialog = cdb.admin.BaseDialog.extend({
        render_content: function() {
          return "<p>This template allows you to add an image to your infowindow.</p><p>The image URLs will need to be stored as a column in your table. Next, you will need to drag the URL field to the top of your infowindow.</p>";
        },
      });

      this.helpDialog = new HelpDialog({
        title: 'Adding images to your infowindows',
        ok_title: 'Ok, close',
        cancel_title: '',
        ok_button_classes: "button grey",
        modal_type: "compressed",
        width: 500
      });

      this.addView(this.helpDialog);

    },

    setFeatureInfo: function(cartodb_id) {
      // Set cartodb_id
      this.cartodb_id = cartodb_id;

      // Get row data and show the content
      if(this.row) {
        this.row.unbind(null, null, this);
      }
      this.row = this.table.data().getRow(cartodb_id);

      this.row
        .bind('change', this.renderInfo, this)
        .fetch();

      // trigger renderInfo now to render the actual contents
      this.renderInfo();

      return this;
    },

    /**
     * renders the infowindows adding some editing features
     */
    render: function() {

      var self = this;

      // render original
      cdb.geo.ui.Infowindow.prototype.render.call(this);

      // render edit and remove buttons
      if(this.model.toJSON().fields && !this.model.toJSON().fields.length) {

        // Add empty fields to the infowindow
        this.$el.find('.cartodb-popup').addClass("no_fields");

        // Check if the infowindow has header or not
        if (this.$('.cartodb-popup-header').length > 0) {
          this.$('.cartodb-popup-header').html('<h4>' + this._TEXTS._NO_FIELDS_SELECTED + '</h4>');
        } else {
          this.$('.cartodb-popup-content').html('<h4>' + this._TEXTS._NO_FIELDS_SELECTED + '</h4>');
        }
      } else {
        this.$el.find('.cartodb-popup').removeClass("no_fields");
      }

      var cartodb_id = '';

      if(this.row) {
        cartodb_id = this.row.attributes['cartodb_id'];
        cartodb_id = cartodb_id? '#'+cartodb_id : '';
      }

      this.$('.cartodb-popup-content-wrapper')
        .append(this.getTemplate('table/views/infowindow_footer')({"cartodb_id": cartodb_id}));

      if(this.table.data().isReadOnly()) {
        this.$('.cartodb-popup-content-wrapper').find('a.remove, a.edit_data, a.edit_geo').addClass('disabled');
      }

      if (this._containsCover()) { // bind the help link to the helpDialog
        this.$el.find(".image_not_found a.help").off("click");
        this.$el.find(".image_not_found a.help").on("click", function() {
          $('body').append(self.helpDialog.render().el);
          self.helpDialog.open();
        });
      }

    },

    renderInfo: function() {
      var self = this;
      var fields = _(this.row.attributes).map(function(v, k) {

        // Don't rendering cartodb_id field from the beginning
        // although back is answering us with it

        if (self.model.containsField(k) && !_.contains(self.model.SYSTEM_COLUMNS, k)) {

          var h = {
            title: k,
            value: v,
            position: self.model.getFieldPos(k)
          };

          return h;
        }

        return null;

      });

      // sort<commit_msg>bug when title is deselected and still appears in the popups<commit_after>/**
 * this infowindow is shown in the map when user clicks on a feature
 */

(function() {

  var MapInfowindow = cdb.geo.ui.Infowindow.extend({
    _TEXTS: {
      _NO_FIELDS_SELECTED: "You haven’t selected any <br/>infowindow fields."
    },

    events: cdb.core.View.extendEvents({
      'click .edit_data': '_editData',
      'click .edit_geo':  '_editGeom',
      'click .remove':    '_removeGeom'
    }),

    initialize: function() {
      var self = this;
      _.bindAll(this, '_removeGeom');
      this.table = this.options.table;
      this.model.set({ content: 'loading...' });
      // call parent
      this.constructor.__super__.initialize.apply(this);
      this.model.set('offset', [28, 0]);
      this.model.bind('change:fields', function() {
        if(!this.hasChanged('content') && self.row) {
          self.renderInfo();
        }
      });

      // Create a help dialog for the infowindows with images
      if (this._containsCover) this._createHelpDialog();

      // Set live tipsy when geom is enabled or disabled
      this.$el.find("div.cartodb-edit-buttons a.button").tipsy({
        live:true,
        fade:true,
        gravity: 's',
        offset: -2,
        className: function(){
          return $(this).closest(".cartodb-popup").hasClass('dark') ? 'dark' : ''
        },
        title: function(ev){
          var enabled = !$(this).hasClass("disabled");
          if (enabled) {
            return $(this).text()
          } else {
            return 'Not available in SQL view'
          }
        }
      })
    },

    _createHelpDialog: function() {

      var HelpDialog = cdb.admin.BaseDialog.extend({
        render_content: function() {
          return "<p>This template allows you to add an image to your infowindow.</p><p>The image URLs will need to be stored as a column in your table. Next, you will need to drag the URL field to the top of your infowindow.</p>";
        },
      });

      this.helpDialog = new HelpDialog({
        title: 'Adding images to your infowindows',
        ok_title: 'Ok, close',
        cancel_title: '',
        ok_button_classes: "button grey",
        modal_type: "compressed",
        width: 500
      });

      this.addView(this.helpDialog);

    },

    setFeatureInfo: function(cartodb_id) {
      // Set cartodb_id
      this.cartodb_id = cartodb_id;

      // Get row data and show the content
      if(this.row) {
        this.row.unbind(null, null, this);
      }
      this.row = this.table.data().getRow(cartodb_id);

      this.row
        .bind('change', this.renderInfo, this)
        .fetch();

      // trigger renderInfo now to render the actual contents
      this.renderInfo();

      return this;
    },

    /**
     * renders the infowindows adding some editing features
     */
    render: function() {

      var self = this;

      // render original
      cdb.geo.ui.Infowindow.prototype.render.call(this);

      // render edit and remove buttons
      if(this.model.toJSON().fields && !this.model.toJSON().fields.length) {

        // Add empty fields to the infowindow
        this.$el.find('.cartodb-popup').addClass("no_fields");

        // Check if the infowindow has header or not
        if (this.$('.cartodb-popup-header').length > 0) {
          this.$('.cartodb-popup-header').html('<h4>' + this._TEXTS._NO_FIELDS_SELECTED + '</h4>');
        } else {
          this.$('.cartodb-popup-content').html('<h4>' + this._TEXTS._NO_FIELDS_SELECTED + '</h4>');
        }
      } else {
        this.$el.find('.cartodb-popup').removeClass("no_fields");
      }

      var cartodb_id = '';

      if(this.row) {
        cartodb_id = this.row.attributes['cartodb_id'];
        cartodb_id = cartodb_id? '#'+cartodb_id : '';
      }

      this.$('.cartodb-popup-content-wrapper')
        .append(this.getTemplate('table/views/infowindow_footer')({"cartodb_id": cartodb_id}));

      if(this.table.data().isReadOnly()) {
        this.$('.cartodb-popup-content-wrapper').find('a.remove, a.edit_data, a.edit_geo').addClass('disabled');
      }

      if (this._containsCover()) { // bind the help link to the helpDialog
        this.$el.find(".image_not_found a.help").off("click");
        this.$el.find(".image_not_found a.help").on("click", function() {
          $('body').append(self.helpDialog.render().el);
          self.helpDialog.open();
        });
      }

    },

    renderInfo: function() {
      var self = this;
      var fields = _(this.row.attributes).map(function(v, k) {

        // Don't rendering cartodb_id field from the beginning
        // although back is answering us with it

        if (self.model.containsField(k) && !_.contains(self.model.SYSTEM_COLUMNS, k)) {
          
          var h = {
            title: self.model.getFieldProperty(k, 'title') ? k : null,
            value: v,
            position: self.model.getFieldPos(k)
          };

          return h;
        }

        return null;

      });

      // sort
{'fraction_non_alphanumeric': 0.14716489681426567, 'fraction_numerical': 0.0024043277900220395, 'mean_word_length': 2.139308176100629, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 23, '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': '3012329', 'n_tokens_mistral': 3124, 'n_tokens_neox': 2983, 'n_words': 678}