<commit_before>var cdb = require('cartodb.js');
var _ = require('underscore');
var Utils = require('cdb.Utils');


/**
 *  Edit visualization (dataset or map) dialog
 *
 */
module.exports = cdb.core.View.extend({

  options: {
    maxLength: 200
  },

  events: {
    'keydown .js-name': '_onNameKeyDown',
    'click .js-privacy': '_showPrivacy',
    'submit': '_onSubmit'
  },

  initialize: function() {
    this.template = cdb.templates.getTemplate('common/dialogs/edit_vis_metadata/edit_vis_form');
    this._initBinds();
  },

  render: function() {
    this.clearSubViews();
    this._destroyTags();
    this.$el.html(
      this.template({
        visType: this.model.getVisType(),
        visValue: this.model.get('name'),
        visDescription: this.model.get('description'),
        visPrivacy: this.model.get('privacy').toLowerCase(),
        isNameEditable: this.model.isNameEditable(),
        isMetadataEditable: this.model.isMetadataEditable(),
        maxLength: this.options.maxLength
      })
    );
    this._initViews();
    return this;
  },

  _initBinds: function() {
    this.model.bind('error', this._setFields, this);
    this.model.bind('valid', this._setFields, this);
  },

  _initViews: function() {
    var self = this;

    // Markdown tooltip
    this.addView(
      new cdb.common.TipsyTooltip({
        el: this.$('.js-markdown'),
        html: true,
        title: function(e) {
          return $(this).data('title');
        }
      })
    );

    // Name error tooltip
    this.addView(
      new cdb.common.TipsyTooltip({
        el: this.$('.js-name'),
        title: function(e) {
          return self.model.getError();
        }
      })
    );

    // Tags
    _.each(this.model.get('tags'), function(li) {
      this.$(".js-tagsList").append("<li>" + li + "</li>");
    }, this);

    var tagsPlaceholder = (!this.model.isMetadataEditable() && this.model.get('tags').length === 0) ? 'No tags' : 'Add tags';

    this.$(".js-tagsList").tagit({
      allowSpaces: true,
      placeholderText: tagsPlaceholder,
      readOnly: !this.model.isMetadataEditable(),
      onBlur: function() {
        if (self.model.isMetadataEditable()) {
          self.$('.js-tags').removeClass('is-focus')
        }
      },
      onFocus: function() {
        if (self.model.isMetadataEditable()) {
          self.$('.js-tags').addClass('is-focus')
        }
      },
      onSubmitTags: function(ev, tagList) {
        ev.preventDefault();
        self._onSubmit();
        return false;
      }
    });
  },

  _setFields: function() {
    // for the moment only name input is required
    this.$('.js-name')[ this.model.getError() ? 'addClass' : 'removeClass' ]('is-invalid');
  },
<commit_msg>Sanitise tag items<commit_after>var cdb = require('cartodb.js');
var _ = require('underscore');
var Utils = require('cdb.Utils');


/**
 *  Edit visualization (dataset or map) dialog
 *
 */
module.exports = cdb.core.View.extend({

  options: {
    maxLength: 200
  },

  events: {
    'keydown .js-name': '_onNameKeyDown',
    'click .js-privacy': '_showPrivacy',
    'submit': '_onSubmit'
  },

  initialize: function() {
    this.template = cdb.templates.getTemplate('common/dialogs/edit_vis_metadata/edit_vis_form');
    this._initBinds();
  },

  render: function() {
    this.clearSubViews();
    this._destroyTags();
    this.$el.html(
      this.template({
        visType: this.model.getVisType(),
        visValue: this.model.get('name'),
        visDescription: this.model.get('description'),
        visPrivacy: this.model.get('privacy').toLowerCase(),
        isNameEditable: this.model.isNameEditable(),
        isMetadataEditable: this.model.isMetadataEditable(),
        maxLength: this.options.maxLength
      })
    );
    this._initViews();
    return this;
  },

  _initBinds: function() {
    this.model.bind('error', this._setFields, this);
    this.model.bind('valid', this._setFields, this);
  },

  _initViews: function() {
    var self = this;

    // Markdown tooltip
    this.addView(
      new cdb.common.TipsyTooltip({
        el: this.$('.js-markdown'),
        html: true,
        title: function(e) {
          return $(this).data('title');
        }
      })
    );

    // Name error tooltip
    this.addView(
      new cdb.common.TipsyTooltip({
        el: this.$('.js-name'),
        title: function(e) {
          return self.model.getError();
        }
      })
    );

    // Tags
    _.each(this.model.get('tags'), function(li) {
      this.$(".js-tagsList").append("<li>" + cdb.core.sanitize.html(li) + "</li>");
    }, this);

    var tagsPlaceholder = (!this.model.isMetadataEditable() && this.model.get('tags').length === 0) ? 'No tags' : 'Add tags';

    this.$(".js-tagsList").tagit({
      allowSpaces: true,
      placeholderText: tagsPlaceholder,
      readOnly: !this.model.isMetadataEditable(),
      onBlur: function() {
        if (self.model.isMetadataEditable()) {
          self.$('.js-tags').removeClass('is-focus')
        }
      },
      onFocus: function() {
        if (self.model.isMetadataEditable()) {
          self.$('.js-tags').addClass('is-focus')
        }
      },
      onSubmitTags: function(ev, tagList) {
        ev.preventDefault();
        self._onSubmit();
        return false;
      }
    });
  },

  _setFields: function() {
    // for the moment only name input is required
    this.$('.js-name')[ this.model.getError() ? 'addClass' : 'removeClass' ]('is-invalid');
  },

{'fraction_non_alphanumeric': 0.17290487493153187, 'fraction_numerical': 0.001460653642505021, 'mean_word_length': 2.4714828897338403, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5898172', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1746, 'n_words': 300}