<commit_before>var $ = require('jquery');
var _ = require('underscore');
var CoreView = require('backbone/core-view');
var AssetItemView = require('./asset-item-view');
var checkAndBuildOpts = require('../../../../../../helpers/required-opts');
var Backbone = require('backbone');
var loadingView = require('../../../../../loading/render-loading');
var AssetHeaderView = require('./asset-header-view');

var ErrorView = require('../../../../../error/error-view');
var errorTemplate = require('./upload-assets-error.tpl');
var template = require('./user-assets-list-view.tpl');

var REQUIRED_OPTS = [
  'assetsCollection',
  'selectedAsset'
];

var KIND = 'custom-marker';
var ASSET_HEIGHT = 48;

module.exports = CoreView.extend({
  initialize: function (opts) {
    checkAndBuildOpts(opts, REQUIRED_OPTS, this);

    this._initModels();
    this._initBinds();
  },

  render: function () {
    this.clearSubViews();
    this.$el.html(template);

    if (this._isLoading()) {
      this._renderLoading();
    } else if (this._hasError()) {
      this._renderError();
    } else {
      this._renderRegularView();
    }

    return this;
  },

  _addHeaderView: function () {
    this._assetHeaderView = new AssetHeaderView({
      editable: true,
      title: this.options.title,
      assetsCollection: this._assetsCollection
    });

    this.addView(this._assetHeaderView);
    this.$('.js-nav').append(this._assetHeaderView.render().el);

    this._assetHeaderView.bind('select-all', this._selectAllAssets, this);
    this._assetHeaderView.bind('deselect-all', this._deselectAllAssets, this);
    this._assetHeaderView.bind('remove', this._removeSelectedAssets, this);
  },

  _renderRegularView: function () {
    this._addHeaderView();
    this._renderAddButton();
    this._assetsCollection.each(this._renderAsset, this);
  },

  _renderAddButton: function () {
    var addAssetButton = new AssetItemView({
      model: new Backbone.Model({
        type: 'text',
        name: '+'
      }),
      assetHeight: ASSET_HEIGHT
    });

    addAssetButton.bind('selected', function () {
      this.trigger('init-upload');
    }, this);

    this.addView(addAssetButton);
    this.$('.js-assets').append(addAssetButton.render().$el);
  },

  _initModels: function () {
    this._stateModel = new Backbone.Model();
    this.add_related_model(this._stateModel);
  },

  _initBinds: function () {
    this._keyDown = this._onKeyDown.bind(this);
    $(document).on('keydown', this._keyDown);

    this._keyUp = this._onKeyUp.bind(this);
    $(document).on('keyup', this._keyUp);

    this.listenTo(this._stateModel, 'change:status', this.render);
    this.listenTo(this._assetsCollection, 'change', this._onChangeAssets);
  },

  _getSelectedAsset: function () {
    var selectedAssets = this._assetsCollection.where({ state: 'selected' });
    return selectedAssets && selectedAssets[0];
  },

  _getSelectedAssetsCount: function () {
    var selectedAssets = this._assetsCollection.where({ state: 'selected' });
    return selectedAssets ? selectedAssets.length : 0;
  },

  _onKeyDown: function (ev) {
    this._shiftKeyPressed = ev.shiftKey;
  },

  _onKeyUp: function (ev) {
    this._shiftKeyPressed = ev.shiftKey;
  },

  _onClickBack: function (e) {
    this.killEvent(e);
    this._stateModel.set('status', '');
  },

  _renderAsset: function (assetModel) {
    var assetItemView = new AssetItemView({
      model: assetModel,
      assetHeight: ASSET_HEIGHT,
      selectedAsset: this._selectedAsset
    });

    if (assetModel.get('public_url') === this.model.get('image')) {
      assetModel.set('state', 'selected');
    }

    assetItemView.bind('selected', this._selectAsset, this);

    this.$('.js-assets').append(assetItemView.render().el);<commit_msg>uses unset<commit_after>var $ = require('jquery');
var _ = require('underscore');
var CoreView = require('backbone/core-view');
var AssetItemView = require('./asset-item-view');
var checkAndBuildOpts = require('../../../../../../helpers/required-opts');
var Backbone = require('backbone');
var loadingView = require('../../../../../loading/render-loading');
var AssetHeaderView = require('./asset-header-view');

var ErrorView = require('../../../../../error/error-view');
var errorTemplate = require('./upload-assets-error.tpl');
var template = require('./user-assets-list-view.tpl');

var REQUIRED_OPTS = [
  'assetsCollection',
  'selectedAsset'
];

var KIND = 'custom-marker';
var ASSET_HEIGHT = 48;

module.exports = CoreView.extend({
  initialize: function (opts) {
    checkAndBuildOpts(opts, REQUIRED_OPTS, this);

    this._initModels();
    this._initBinds();
  },

  render: function () {
    this.clearSubViews();
    this.$el.html(template);

    if (this._isLoading()) {
      this._renderLoading();
    } else if (this._hasError()) {
      this._renderError();
    } else {
      this._renderRegularView();
    }

    return this;
  },

  _addHeaderView: function () {
    this._assetHeaderView = new AssetHeaderView({
      editable: true,
      title: this.options.title,
      assetsCollection: this._assetsCollection
    });

    this.addView(this._assetHeaderView);
    this.$('.js-nav').append(this._assetHeaderView.render().el);

    this._assetHeaderView.bind('select-all', this._selectAllAssets, this);
    this._assetHeaderView.bind('deselect-all', this._deselectAllAssets, this);
    this._assetHeaderView.bind('remove', this._removeSelectedAssets, this);
  },

  _renderRegularView: function () {
    this._addHeaderView();
    this._renderAddButton();
    this._assetsCollection.each(this._renderAsset, this);
  },

  _renderAddButton: function () {
    var addAssetButton = new AssetItemView({
      model: new Backbone.Model({
        type: 'text',
        name: '+'
      }),
      assetHeight: ASSET_HEIGHT
    });

    addAssetButton.bind('selected', function () {
      this.trigger('init-upload');
    }, this);

    this.addView(addAssetButton);
    this.$('.js-assets').append(addAssetButton.render().$el);
  },

  _initModels: function () {
    this._stateModel = new Backbone.Model();
    this.add_related_model(this._stateModel);
  },

  _initBinds: function () {
    this._keyDown = this._onKeyDown.bind(this);
    $(document).on('keydown', this._keyDown);

    this._keyUp = this._onKeyUp.bind(this);
    $(document).on('keyup', this._keyUp);

    this.listenTo(this._stateModel, 'change:status', this.render);
    this.listenTo(this._assetsCollection, 'change', this._onChangeAssets);
  },

  _getSelectedAsset: function () {
    var selectedAssets = this._assetsCollection.where({ state: 'selected' });
    return selectedAssets && selectedAssets[0];
  },

  _getSelectedAssetsCount: function () {
    var selectedAssets = this._assetsCollection.where({ state: 'selected' });
    return selectedAssets ? selectedAssets.length : 0;
  },

  _onKeyDown: function (ev) {
    this._shiftKeyPressed = ev.shiftKey;
  },

  _onKeyUp: function (ev) {
    this._shiftKeyPressed = ev.shiftKey;
  },

  _onClickBack: function (e) {
    this.killEvent(e);
    this._stateModel.unset('status');
  },

  _renderAsset: function (assetModel) {
    var assetItemView = new AssetItemView({
      model: assetModel,
      assetHeight: ASSET_HEIGHT,
      selectedAsset: this._selectedAsset
    });

    if (assetModel.get('public_url') === this.model.get('image')) {
      assetModel.set('state', 'selected');
    }

    assetItemView.bind('selected', this._selectAsset, this);

    this.$('.js-assets').append(assetItemView.render().el);
{'fraction_non_alphanumeric': 0.16562624518528357, 'fraction_numerical': 0.0010625581086465667, 'mean_word_length': 3.5608721986674743, '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': '6967387', 'n_tokens_mistral': 2373, 'n_tokens_neox': 2309, 'n_words': 388}