<commit_before>var LoadableSelectView = Backbone.View.extend({
  events: {
    'change select[data-selectable-load]': 'toggleDisabled'
  },

  initialize: function(){
    _(this).bindAll()

    this.feedbackView = this.options.feedbackView
  },

  toggleDisabled: function (event) {
    var $changed = $(event.currentTarget),
        $child   = this.$($changed.data('selectable-load'))

    $child.val('').trigger('change')

    if ($changed.val() === '') {
      this.disableSelect($child)
    } else {
      this.$currentChild = $child
      this.loadSelectOptions($changed)
    }
  },

  disableSelect: function ($select) {
    var $selectDisable = this.$($select.data('selectable-load'))

    $select.addClass('disabled').prop('disabled', true)

    if ($selectDisable.length > 0) {
      this.disableSelect($selectDisable)
    }
  },

  loadSelectOptions: function ($select){
    this.$el.parent().loadingOverlay('show')

    $.ajax({
      url: $select.data('selectable-url'),
      data: this.loadData(),
      dataType: 'html',
      success: this.updateCurrentChild,
      error: this.loadError,
      complete: this.complete
    })
  },

  loadData: function () {
    return _(this.$('select[data-selectable-load]')).inject(function (memo, element) {
      var $element = $(element)
      memo[$element.attr('name')] = $element.val()
      return memo
    }, {})
  },

  updateCurrentChild: function (data) {
    this.$currentChild.html(data).prop('disabled', false).removeClass('disabled')
    this.$el.parent().loadingOverlay('hide')
  },

  loadError: function () {
    if (this.feedbackView) {
      this.feedbackView.render(this.$el.data('error-message'), 'alert-error', true)
    }
  },

  complete: function () {
    this.trigger('complete')
  }
})

var CRUDFormView = Backbone.View.extend({
  events: {
    'click [data-save-and-close]': 'markToClose',
    'click [data-close]': 'close',
    'toggled': 'toggled',

    'ajax:success': 'created',
    'ajax:error':   'failed',
    'submit form':  'submit',
  },

  initialize: function() {
    _(this).bindAll()

    this.feedbackView = this.options.feedbackView

    this.loadableSelectView = new LoadableSelectView({
      el: this.el,
      feedbackView: this.feedbackView
    })

    this.configureForm()
  },

  updateForm: function (data) {
    this.$('form').off().replaceWith(data)
    this.$('form').trigger('shown')
    this.$('.loading-overlay').remove()
    this.configureForm()
  },

  configureForm: function () {
    this.shouldClose = false

    this.$('[data-type=currency]').autoNumeric({
      aSep: '.',
      aDec: ',',
      vMax: '999999999999.99'
    })

    this.$('[data-type=integer]').autoNumeric({
      aSep: '',
      aDec: ',',
      mDec: 0,
      vMax: '999999999999'
    })

    this.$('[data-type=year]').autoNumeric({
      aSep: '',
      aDec: ',',
      mDec: 0,
      vMax: '9999'
    })

    this.$(".error .help-inline").tooltip({
      title: function () { return $(this).text() },
      placement: 'left'
    })

    this.focus()
  },

  markToClose: function () {
    this.shouldClose = true
  },

  created: function (event, data) {
    if (this.shouldClose) {
      this.close()
    }
<commit_msg>Changing `created` method name to `success` since CRUDFormView does handles both create and update actions<commit_after>var LoadableSelectView = Backbone.View.extend({
  events: {
    'change select[data-selectable-load]': 'toggleDisabled'
  },

  initialize: function(){
    _(this).bindAll()

    this.feedbackView = this.options.feedbackView
  },

  toggleDisabled: function (event) {
    var $changed = $(event.currentTarget),
        $child   = this.$($changed.data('selectable-load'))

    $child.val('').trigger('change')

    if ($changed.val() === '') {
      this.disableSelect($child)
    } else {
      this.$currentChild = $child
      this.loadSelectOptions($changed)
    }
  },

  disableSelect: function ($select) {
    var $selectDisable = this.$($select.data('selectable-load'))

    $select.addClass('disabled').prop('disabled', true)

    if ($selectDisable.length > 0) {
      this.disableSelect($selectDisable)
    }
  },

  loadSelectOptions: function ($select){
    this.$el.parent().loadingOverlay('show')

    $.ajax({
      url: $select.data('selectable-url'),
      data: this.loadData(),
      dataType: 'html',
      success: this.updateCurrentChild,
      error: this.loadError,
      complete: this.complete
    })
  },

  loadData: function () {
    return _(this.$('select[data-selectable-load]')).inject(function (memo, element) {
      var $element = $(element)
      memo[$element.attr('name')] = $element.val()
      return memo
    }, {})
  },

  updateCurrentChild: function (data) {
    this.$currentChild.html(data).prop('disabled', false).removeClass('disabled')
    this.$el.parent().loadingOverlay('hide')
  },

  loadError: function () {
    if (this.feedbackView) {
      this.feedbackView.render(this.$el.data('error-message'), 'alert-error', true)
    }
  },

  complete: function () {
    this.trigger('complete')
  }
})

var CRUDFormView = Backbone.View.extend({
  events: {
    'click [data-save-and-close]': 'markToClose',
    'click [data-close]': 'close',
    'toggled': 'toggled',

    'ajax:success': 'success',
    'ajax:error':   'failed',
    'submit form':  'submit',
  },

  initialize: function() {
    _(this).bindAll()

    this.feedbackView = this.options.feedbackView

    this.loadableSelectView = new LoadableSelectView({
      el: this.el,
      feedbackView: this.feedbackView
    })

    this.configureForm()
  },

  updateForm: function (data) {
    this.$('form').off().replaceWith(data)
    this.$('form').trigger('shown')
    this.$('.loading-overlay').remove()
    this.configureForm()
  },

  configureForm: function () {
    this.shouldClose = false

    this.$('[data-type=currency]').autoNumeric({
      aSep: '.',
      aDec: ',',
      vMax: '999999999999.99'
    })

    this.$('[data-type=integer]').autoNumeric({
      aSep: '',
      aDec: ',',
      mDec: 0,
      vMax: '999999999999'
    })

    this.$('[data-type=year]').autoNumeric({
      aSep: '',
      aDec: ',',
      mDec: 0,
      vMax: '9999'
    })

    this.$(".error .help-inline").tooltip({
      title: function () { return $(this).text() },
      placement: 'left'
    })

    this.focus()
  },

  markToClose: function () {
    this.shouldClose = true
  },

  success: function (event, data) {
    if (this.shouldClose) {
      this.close()
    }

{'fraction_non_alphanumeric': 0.18045112781954886, 'fraction_numerical': 0.010127359214362436, 'mean_word_length': 2.9053325344517673, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '1550017', 'n_tokens_mistral': 2177, 'n_tokens_neox': 2064, 'n_words': 350}