<commit_before>{
  namespace,
  utils,
  ui: {progress},
  templates: {tpl},
  jQuery: $,
  locale: {t}
} = uploadcare

namespace 'uploadcare.widget.tabs', (ns) ->

  class ns.PreviewTabMultiple extends ns.BasePreviewTab

    # dpm — abbreviation of dialog-preview-multiple
    CLASS_PREFIX = 'uploadcare-dpm-'

    constructor: ->
      super

      @container.append(tpl('tab-preview-multiple'))
      @__fileTpl = $(tpl('tab-preview-multiple-file'))

      @fileListEl = @__find('file-list')
      @titleEl = @__find('title')
      @mobileTitleEl = @__find('mobile-title')
      @footerTextEl = @__find('footer-text')
      @doneBtnEl = @container.find('.uploadcare-dialog-preview-done')

      $.each @dialogApi.fileColl.get(), (i, file) =>
        @__fileAdded(file)
        file.then(
          (info) => @__fileDone(file, info),
          (info) => @__fileFailed(file, info),
          (info) => @__fileProgress(file, info)
        )
      @__updateContainerView()

      @dialogApi.fileColl.onAdd.add(@__fileAdded, @__updateContainerView)
      @dialogApi.fileColl.onRemove.add(@__fileRemoved, @__updateContainerView)

      @dialogApi.fileColl.onAnyDone.add(@__fileDone)
      @dialogApi.fileColl.onAnyFail.add(@__fileFailed)
      @dialogApi.fileColl.onAnyProgress.add(@__fileProgress)

      @dialogApi.fileColl.onReplace.add (oldFile, newFile) =>
        $(newFile).data('dpm-el', @__fileToEl(oldFile))

      @__setupSorting()

    __setupSorting: ->
      @fileListEl.uploadcareSortable(
        touch: false
        axis: 'y'
        start: (info) ->
          info.dragged.css('visibility', 'hidden')
        finish: (info) =>
          info.dragged.css('visibility', 'visible')
          elements = @__find('file-item')
          index = (file) =>
            elements.index(@__fileToEl(file))
          @dialogApi.fileColl.sort (a, b) ->
            index(a) - index(b)
      )

    __find: (s, context = @container) ->
      $('.' + CLASS_PREFIX + s, context)

    __updateContainerView: =>
      files = @dialogApi.fileColl.length()
      tooManyFiles = @settings.multipleMax != 0 and files > @settings.multipleMax
      tooFewFiles = files < @settings.multipleMin

      @doneBtnEl.toggleClass('uploadcare-disabled-el', tooManyFiles or tooFewFiles)

      title = t('dialog.tabs.preview.multiple.title')
        .replace('%files%', t('file', files))
      @titleEl.text(title)

      footer = if tooManyFiles
        t('dialog.tabs.preview.multiple.tooManyFiles')
          .replace('%max%', @settings.multipleMax)
      else if files and tooFewFiles
        t('dialog.tabs.preview.multiple.tooFewFiles')
          .replace('%min%', @settings.multipleMin)
          .replace('%files%', t('file', files))
      else
        t('dialog.tabs.preview.multiple.question')

      @footerTextEl
        .toggleClass('uploadcare-error', tooManyFiles or tooFewFiles)
        .text(footer)

      @mobileTitleEl
        .toggleClass('uploadcare-error', tooManyFiles or tooFewFiles)
        .text(if tooManyFiles or tooFewFiles then footer else title)

    __updateFileInfo: (fileEl, info) ->
      @__find('file-name', fileEl)
        .text(info.name or t('dialog.tabs.preview.unknownName'))

      @__find('file-size', fileEl)
        .text(utils.readableFileSize(info.size, '–'))

    __fileProgress: (file, progressInfo) =>
      fileEl = @__fileToEl(file)

      @__find('file-progressbar-value', fileEl)
        .css('width', Math.round(progressInfo.progress * 100) + '%')

      @__updateFileInfo(fileEl, progressInfo.incompleteFileInfo)

    __fileDone: (file, info) =>
      fileEl = @__fileToEl(file)
      fileEl.addClass(CLASS_PREFIX + 'uploaded')

      @__find('file-progressbar-value', fileEl)
        .css('width', '100%')
      @__updateFileInfo(fileEl, info)

      if info.isImage
        preview = @__find('file-preview-wrap', fileEl).html($('<img>')
          .attr('src', "#{info.cdnUrl}-/scale_crop/90x90/center/")
          .css(
            width: 'auto'
            height: 45
          )
        )
        if @settings.crop
          preview
            .addClass('uploadcare__zoomable')
            .on 'click', =>
              s = $.extend({}, @settings)
              s.multiple = false
              s.tabs = 'preview'
              uploadcare.openDialog(file, 'preview', s).done (newFile) =>
                @dialogApi.fileColl.replace(file, newFile)
                uploadcare.openDialog(@dialogApi.fileColl.get(), 'preview', @settings)
<commit_msg>open second dialog for crop<commit_after>{
  namespace,
  utils,
  ui: {progress},
  templates: {tpl},
  jQuery: $,
  locale: {t}
} = uploadcare

namespace 'uploadcare.widget.tabs', (ns) ->

  class ns.PreviewTabMultiple extends ns.BasePreviewTab

    # dpm — abbreviation of dialog-preview-multiple
    CLASS_PREFIX = 'uploadcare-dpm-'

    constructor: ->
      super

      @container.append(tpl('tab-preview-multiple'))
      @__fileTpl = $(tpl('tab-preview-multiple-file'))

      @fileListEl = @__find('file-list')
      @titleEl = @__find('title')
      @mobileTitleEl = @__find('mobile-title')
      @footerTextEl = @__find('footer-text')
      @doneBtnEl = @container.find('.uploadcare-dialog-preview-done')

      $.each @dialogApi.fileColl.get(), (i, file) =>
        @__fileAdded(file)
        file.then(
          (info) => @__fileDone(file, info),
          (info) => @__fileFailed(file, info),
          (info) => @__fileProgress(file, info)
        )
      @__updateContainerView()

      @dialogApi.fileColl.onAdd.add(@__fileAdded, @__updateContainerView)
      @dialogApi.fileColl.onRemove.add(@__fileRemoved, @__updateContainerView)

      @dialogApi.fileColl.onAnyDone.add(@__fileDone)
      @dialogApi.fileColl.onAnyFail.add(@__fileFailed)
      @dialogApi.fileColl.onAnyProgress.add(@__fileProgress)

      @dialogApi.fileColl.onReplace.add (oldFile, newFile) =>
        $(newFile).data('dpm-el', @__fileToEl(oldFile))

      @__setupSorting()

    __setupSorting: ->
      @fileListEl.uploadcareSortable(
        touch: false
        axis: 'y'
        start: (info) ->
          info.dragged.css('visibility', 'hidden')
        finish: (info) =>
          info.dragged.css('visibility', 'visible')
          elements = @__find('file-item')
          index = (file) =>
            elements.index(@__fileToEl(file))
          @dialogApi.fileColl.sort (a, b) ->
            index(a) - index(b)
      )

    __find: (s, context = @container) ->
      $('.' + CLASS_PREFIX + s, context)

    __updateContainerView: =>
      files = @dialogApi.fileColl.length()
      tooManyFiles = @settings.multipleMax != 0 and files > @settings.multipleMax
      tooFewFiles = files < @settings.multipleMin

      @doneBtnEl.toggleClass('uploadcare-disabled-el', tooManyFiles or tooFewFiles)

      title = t('dialog.tabs.preview.multiple.title')
        .replace('%files%', t('file', files))
      @titleEl.text(title)

      footer = if tooManyFiles
        t('dialog.tabs.preview.multiple.tooManyFiles')
          .replace('%max%', @settings.multipleMax)
      else if files and tooFewFiles
        t('dialog.tabs.preview.multiple.tooFewFiles')
          .replace('%min%', @settings.multipleMin)
          .replace('%files%', t('file', files))
      else
        t('dialog.tabs.preview.multiple.question')

      @footerTextEl
        .toggleClass('uploadcare-error', tooManyFiles or tooFewFiles)
        .text(footer)

      @mobileTitleEl
        .toggleClass('uploadcare-error', tooManyFiles or tooFewFiles)
        .text(if tooManyFiles or tooFewFiles then footer else title)

    __updateFileInfo: (fileEl, info) ->
      @__find('file-name', fileEl)
        .text(info.name or t('dialog.tabs.preview.unknownName'))

      @__find('file-size', fileEl)
        .text(utils.readableFileSize(info.size, '–'))

    __fileProgress: (file, progressInfo) =>
      fileEl = @__fileToEl(file)

      @__find('file-progressbar-value', fileEl)
        .css('width', Math.round(progressInfo.progress * 100) + '%')

      @__updateFileInfo(fileEl, progressInfo.incompleteFileInfo)

    __fileDone: (file, info) =>
      fileEl = @__fileToEl(file)
      fileEl.addClass(CLASS_PREFIX + 'uploaded')

      @__find('file-progressbar-value', fileEl)
        .css('width', '100%')
      @__updateFileInfo(fileEl, info)

      if info.isImage
        @__find('file-preview-wrap', fileEl).html($('<img>')
          .attr('src', "#{info.cdnUrl}-/scale_crop/90x90/center/")
          .css(
            width: 'auto'
            height: 45
          )
        ).on 'click', =>
          s = $.extend({}, @settings, {
            multiple: false
            tabs: 'preview'
          })
          uploadcare.openDialog(file, 'preview', s, true).done (newFile) =>
            @dialogApi.fileColl.replace(file, newFile)

{'fraction_non_alphanumeric': 0.1490280777537797, 'fraction_numerical': 0.0029555530294418553, 'mean_word_length': 2.6190867955573838, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 45, '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': '3438963', 'n_tokens_mistral': 2831, 'n_tokens_neox': 2725, 'n_words': 459}