<commit_before>(function() {

  // @todo: This should be moved to a common library
  /**
   *  String prototype extend to represent property table size
   */
  String.prototype.bytesToSize = function() {
    var bytes = parseInt(this.toString())
      , sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
    if (bytes == 0) return '0 KB';
    var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
    var value = (bytes / Math.pow(1024, i)).toFixed(2);

    if (value % 1 == 0) {
      value = parseInt(value)
    }

    return value + " " + sizes[i];
  }



  /**
   * Single table item in dashboard list
   *
   * Usage example:
   *
      var li = new TableView({
        model: model*,
        limitation: !this.options.user.get("private_tables")
      });

      * It needs a table model to run correctly.
   *
   */
  var TableView = cdb.core.View.extend({

    tagName: 'li',

    events: {
      "click a.status": "_addPrivacySelector",
      "click a.delete:not(.disabled)": "_confirmAndDelete",
      "removeTag .tags a": "removeTag"
    },


    initialize: function() {
      _.bindAll(this, "render", "deleting", "deleted", "_addPrivacySelector", "removeTag", "_confirmAndDelete");

      _.defaults(this.options, this.default_options);

      this.template = cdb.templates.getTemplate('dashboard/views/table_list_item');

      this.retrigger('saving', this.model);
      this.retrigger('saved', this.model);

      this.model.bind('change', this.render);
      this.bind("clean", this._reClean, this);
    },


    render: function() {
      var self = this;
      this.cleanTooltips();
      this.$el.html(this.template(this.model.toJSON()));
      this.$el.addClass('tableRow')
      this.$el.droppable({
        hoverClass: "drop",
        drop: function( ev, ui ) {
          var tag = $(ui.helper).text()
            , tags = self.model.get("tags").split(",")
            , included = false;

          if (tags.indexOf(tag) < 0) {
            $.when(self.model.save({tags: tags + "," + tag})).done(function() {
              self.render();
              self.model.trigger('change:tags');
            });
          }
          self.$el.removeClass('alreadyContainsTag').find('.right.tags a').removeClass('exists');
        },
        over: function(ev, ui) {
          var tag = $(ui.helper).text();
          self.$('.right.tags a').map(function(i,e) {
            var $element = $(e);
            if($element.html() == tag) {
              alreadyInserted = true;
              $element.addClass('exists');
              self.$el.addClass('alreadyContainsTag');
            }
          });
        },
        out: function() {
          self.$el.removeClass('alreadyContainsTag').find('.right.tags a').removeClass('exists');
        }
      });

      this.assignDraggables();
      return this;
    },

    assignDraggables: function() {
        this.$('span.tags a').draggable({
        zIndex:9999,
        opacity: 1,
        helper: function(ev) {
          return $( "<a class='tag' href='#'>" + $(ev.currentTarget).html() + "</a>" );
        },
        start: function() {
          $('.removeTags').animate({opacity:1, height:"18px", padding:"10px 10px 10px 10px", borderWidth:"1px"},50);
        },
        stop: function() {
          $('.removeTags').animate({opacity:0, height:"0px", padding:"0px 0px 0px 10px", borderWidth:0},50);
        }
      });
    },

    removeTag: function(ev) {
      var self = this;
      var tag = $(ev.currentTarget).html();
      var tags = this.model.get("tags").split(",");
      var position = tags.indexOf(tag);
      if(position > -1) {
        tags.splice(position, 1)
      }
      $.when(this.model.save({tags: tags.join(',')}, {wait: true})).done(function() {
        self.model.trigger('change:tags');
      });

    },

    clean: function() {
      this.trigger('clean');
      this.elder('clean');
    },

    /**
     * Create the privacy selector after a "privacy link" clicked
     */
    _addPrivacySelector: function(ev) {
      ev && (ev.preventDefault());
      this.trigger('change:privacy');

      this.privacy && this.privacy.clean();

      // this.options.limitation = true
      // Add privacy selector
      var privacy = this.privacy = new cdb.admin.PrivacySelector({
        model: this.model,
        limitation: this.options.limitation,
        upgrade_url: '/account/'+username+'/upgrade'<commit_msg>upgrade link for changing table privacy fixed<commit_after>(function() {

  // @todo: This should be moved to a common library
  /**
   *  String prototype extend to represent property table size
   */
  String.prototype.bytesToSize = function() {
    var bytes = parseInt(this.toString())
      , sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
    if (bytes == 0) return '0 KB';
    var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
    var value = (bytes / Math.pow(1024, i)).toFixed(2);

    if (value % 1 == 0) {
      value = parseInt(value)
    }

    return value + " " + sizes[i];
  }



  /**
   * Single table item in dashboard list
   *
   * Usage example:
   *
      var li = new TableView({
        model: model*,
        limitation: !this.options.user.get("private_tables")
      });

      * It needs a table model to run correctly.
   *
   */
  var TableView = cdb.core.View.extend({

    tagName: 'li',

    events: {
      "click a.status": "_addPrivacySelector",
      "click a.delete:not(.disabled)": "_confirmAndDelete",
      "removeTag .tags a": "removeTag"
    },


    initialize: function() {
      _.bindAll(this, "render", "deleting", "deleted", "_addPrivacySelector", "removeTag", "_confirmAndDelete");

      _.defaults(this.options, this.default_options);

      this.template = cdb.templates.getTemplate('dashboard/views/table_list_item');

      this.retrigger('saving', this.model);
      this.retrigger('saved', this.model);

      this.model.bind('change', this.render);
      this.bind("clean", this._reClean, this);
    },


    render: function() {
      var self = this;
      this.cleanTooltips();
      this.$el.html(this.template(this.model.toJSON()));
      this.$el.addClass('tableRow')
      this.$el.droppable({
        hoverClass: "drop",
        drop: function( ev, ui ) {
          var tag = $(ui.helper).text()
            , tags = self.model.get("tags").split(",")
            , included = false;

          if (tags.indexOf(tag) < 0) {
            $.when(self.model.save({tags: tags + "," + tag})).done(function() {
              self.render();
              self.model.trigger('change:tags');
            });
          }
          self.$el.removeClass('alreadyContainsTag').find('.right.tags a').removeClass('exists');
        },
        over: function(ev, ui) {
          var tag = $(ui.helper).text();
          self.$('.right.tags a').map(function(i,e) {
            var $element = $(e);
            if($element.html() == tag) {
              alreadyInserted = true;
              $element.addClass('exists');
              self.$el.addClass('alreadyContainsTag');
            }
          });
        },
        out: function() {
          self.$el.removeClass('alreadyContainsTag').find('.right.tags a').removeClass('exists');
        }
      });

      this.assignDraggables();
      return this;
    },

    assignDraggables: function() {
        this.$('span.tags a').draggable({
        zIndex:9999,
        opacity: 1,
        helper: function(ev) {
          return $( "<a class='tag' href='#'>" + $(ev.currentTarget).html() + "</a>" );
        },
        start: function() {
          $('.removeTags').animate({opacity:1, height:"18px", padding:"10px 10px 10px 10px", borderWidth:"1px"},50);
        },
        stop: function() {
          $('.removeTags').animate({opacity:0, height:"0px", padding:"0px 0px 0px 10px", borderWidth:0},50);
        }
      });
    },

    removeTag: function(ev) {
      var self = this;
      var tag = $(ev.currentTarget).html();
      var tags = this.model.get("tags").split(",");
      var position = tags.indexOf(tag);
      if(position > -1) {
        tags.splice(position, 1)
      }
      $.when(this.model.save({tags: tags.join(',')}, {wait: true})).done(function() {
        self.model.trigger('change:tags');
      });

    },

    clean: function() {
      this.trigger('clean');
      this.elder('clean');
    },

    /**
     * Create the privacy selector after a "privacy link" clicked
     */
    _addPrivacySelector: function(ev) {
      ev && (ev.preventDefault());
      this.trigger('change:privacy');

      this.privacy && this.privacy.clean();

      // this.options.limitation = true
      // Add privacy selector
      var privacy = this.privacy = new cdb.admin.PrivacySelector({
        model: this.model,
        limitation: this.options.limitation,
        upgrade_url: 'https://' + config.account_host + "/account/" + username + "/upgrade"
{'fraction_non_alphanumeric': 0.17434395765288885, 'fraction_numerical': 0.010136276607726095, 'mean_word_length': 2.240875912408759, 'pattern_counts': {'":': 6, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, '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': '2364650', 'n_tokens_mistral': 2769, 'n_tokens_neox': 2659, 'n_words': 535}