<commit_before>define [
  'Backbone'
  'jst/content_migrations/subviews/ChooseMigrationFile'
], (Backbone, template) -> 
  class ChooseMigrationFile extends Backbone.View
    template: template

    els: 
      '#migrationFileUpload' : '$migrationFileUpload'

    events: 
      'change #migrationFileUpload' : 'setAttributes'

    @optionProperty 'fileSizeLimit'

    setAttributes: (event) -> 
      filename = event.target.value.replace(/^.*\\/, '')
      fileElement = @$migrationFileUpload[0]

      @model.set('pre_attachment', {file_size: @fileSize(fileElement), name: filename, fileElement: fileElement})
    
    # TODO 
    #   Handle cases for file size from IE browsers
    # @api private

    fileSize: (fileElement) -> fileElement.files[0].size

    # Validates this form element. This validates method is a convention used 
    # for all sub views.
    # ie:
    #   error_object = {fieldName:[{type:'required', message: 'This is wrong'}]}
    # -----------------------------------------------------------------------
    # @expects void
    # @returns void | object (error)
    # @api private

    validations: -> 
      errors = {}
      preAttachment = @model.get('pre_attachment')
      fileErrors = []
      fileElement = preAttachment?.fileElement

      unless preAttachment?.name && fileElement
        fileErrors.push
                    type: "required"
                    message: "You must select a file to import content from"

      if fileElement?.files[0].size > @fileSizeLimit
        fileErrors.push
                    type: "upload_limit_exceeded"
                    message: "You're migration cannot exceed #{@humanReadableSize(@fileSizeLimit)}"

      errors.file = fileErrors if fileErrors.length
      errors

    # Converts a size to a human readible string. "size" should be in
    # bytes to stay consistent with the javascript files api. 
    # --------------------------------------------------------------
    # @expects size (bytes | string(in bytes))
    # @returns readableString (string)
    # @api private

    humanReadableSize: (size) -> 
      size = parseFloat size #Ensure we are working with a number
      units = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
      i = 0<commit_msg>fix content migration file select for IE<commit_after>define [
  'Backbone'
  'jst/content_migrations/subviews/ChooseMigrationFile'
], (Backbone, template) -> 
  class ChooseMigrationFile extends Backbone.View
    template: template

    els: 
      '#migrationFileUpload' : '$migrationFileUpload'

    events: 
      'change #migrationFileUpload' : 'setAttributes'

    @optionProperty 'fileSizeLimit'

    setAttributes: (event) -> 
      filename = event.target.value.replace(/^.*\\/, '')
      fileElement = @$migrationFileUpload[0]

      @model.set('pre_attachment', {file_size: @fileSize(fileElement), name: filename, fileElement: fileElement})
    
    # TODO 
    #   Handle cases for file size from IE browsers
    # @api private

    fileSize: (fileElement) -> fileElement.files?[0].size

    # Validates this form element. This validates method is a convention used 
    # for all sub views.
    # ie:
    #   error_object = {fieldName:[{type:'required', message: 'This is wrong'}]}
    # -----------------------------------------------------------------------
    # @expects void
    # @returns void | object (error)
    # @api private

    validations: -> 
      errors = {}
      preAttachment = @model.get('pre_attachment')
      fileErrors = []
      fileElement = preAttachment?.fileElement

      unless preAttachment?.name && fileElement
        fileErrors.push
                    type: "required"
                    message: "You must select a file to import content from"

      if @fileSize(fileElement) > @fileSizeLimit
        fileErrors.push
                    type: "upload_limit_exceeded"
                    message: "You're migration cannot exceed #{@humanReadableSize(@fileSizeLimit)}"

      errors.file = fileErrors if fileErrors.length
      errors

    # Converts a size to a human readible string. "size" should be in
    # bytes to stay consistent with the javascript files api. 
    # --------------------------------------------------------------
    # @expects size (bytes | string(in bytes))
    # @returns readableString (string)
    # @api private

    humanReadableSize: (size) -> 
      size = parseFloat size #Ensure we are working with a number
      units = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
      i = 0
{'fraction_non_alphanumeric': 0.16350397175639894, 'fraction_numerical': 0.0015445719329214476, 'mean_word_length': 2.172148355493352, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4827288', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1202, 'n_words': 351}