<commit_before>#= require sugar
#= require jquery-specializer
#= require gmaps

map = undefined

geocode_location = (callback) ->
  voivodeship = $('form.suggestion').data('voivodeship')
  district = $('form.suggestion').data('district')
  commune = $('form.suggestion').data('commune')
  city = $('#place_name_viewer').val()
  street = $('#suggestion_street').val()

  jQuery.get geocoder_search_path, {voivodeship, district, commune, city, street}, (result) ->
    if result.length > 0
      $('#suggestion_latitude').val(result[0].latitude.round(7))
      $('#suggestion_longitude').val(result[0].longitude.round(7))
      callback(result[0].latitude.round(7), result[0].longitude.round(7)) if callback?
    else
      callback() if callback?

$.fn.specialize

  '.step':

    input: -> this.find("input[type='text']")
    action: -> this.find("#" + this.input().attr('id') + '_action')

    switchViewClass: (klass) ->
      this.saveLocalHistory()
      this.removeClass('step-done step-skipped step-confirmed step-edited step-view step-edit')
      this.addClass(klass)
      $(".help-content").removeClass('active')
      $('.step').removeClass('step-current')
      this.addClass('step-current')
      this.action().val('skip')

    view: ->
      this.switchViewClass('step-view')
      this.find('button.edit').focus()

      this

    edit: ->
      this.switchViewClass('step-edit')
      this.input().edit()

      if this.data('autoscroll')?
        document.location.hash = this.data('autoscroll')

      this

    submit: ->
      if this.hasClass('step-simple') && this.input().val() == ""
        alert("Nie możesz pozostawić pustego pola.")
        return false

      this.switchViewClass('step-view step-done step-edited')
      this.action().val('edit')
      this.input().save()
      this.done()
      this

    confirm: ->
      this.switchViewClass('step-view step-done step-confirmed')
      this.action().val('confirm')
      this.done()
      this

    skip: ->
      this.switchViewClass('step-view step-done step-skipped')
      this.action().val('skip')
      this.done()
      this

    cancel: ->
      this.restoreHistory()
      this.input().save()
      this.view()
      this.saveLocalHistory()
      this

    done: ->
      $('.step').removeClass('step-current')
      this.addClass('step-done').removeClass("step-current")
      next_step = $('.step:not(.step-done):first')
      setHeight = next_step.offset().top - (($(window).height() / 2) - (next_step.height() / 2)) + 100

      setTimeout ->
        $('html,body').animate scrollTop: setHeight, 400, ->
          next_step.view()
      , 300
      this

    back: ->
      if $('.step-current').input().hasChanged()
        alert('Najpierw musisz skończyć edytować bieżące pole.')
      else
        if $('.step-current').hasClass('step-edit')
          $('.step-current').cancel()

        current_step = $('.step-current')

        if this.hasClass('step-edited') && !this.hasClass('step-current')
          this.edit()
        else
          this.view()

        current_step.restoreLocalHistory()

      this

    saveHistory: ->
      this.input().saveHistory()
      this.action().saveHistory()
      this

    restoreHistory: ->
      this.input().restoreHistory()
      this.action().restoreHistory()
      this

    saveLocalHistory: ->
      this.data('class', this.attr('class'))
      this.input().saveLocalHistory()
      this.action().saveLocalHistory()

    restoreLocalHistory: ->
      this.action().restoreLocalHistory()
      this.input().restoreLocalHistory()
      this.attr('class', this.data('class'))
      this.removeClass('step-current')

    restoreLocalState: ->
      this.input().restoreLocalState()

    hasChanged: ->
      this.input().hasChanged()

  # place step have select field instead of text
  '.step-place':

    input: -> $("#suggestion_place_id")

    edit: ->
      this.switchViewClass('step-edit')
      $('#suggestion_place_id').focus()
      this

    submit: ->
      this.find('#place_name_viewer').val(this.find('#suggestion_place_id option:selected').text())
      this.switchViewClass('step-view step-done step-edited')
      this.action().val('edit')
      this.done()
      geocode_location ->
        $('#map_canvas').auto_zoom()

      this

    cancel: ->
      this.restoreHistory()
      this.input().save()
      this.find('#suggestion_place_id').val(this.input().val())
      this.find('#place_name_viewer').val(this.find('#suggestion_place_id option:selected').text())
      this.view()
      this.saveLocalHistory()
      this

  '.step-street':

    submit: ->
      if this.hasClass('step-simple') && this.input().val() == ""
        alert("Nie możesz pozostawić pustego pola.")
        return false
      this.switchViewClass('step-view step-done step-edited')
      this.action().val('edit')
      this.input().save()
      this.done()
      geocode_location ->
        $('#map_canvas').auto_zoom()
      this

  # place step have select field instead of text
  '.step-tags':

    input: -> this.find("input[type='checkbox']")

    view: ->
      this.switchViewClass('step-view')
      this

    skip: ->
      this.cancel()
      this.find('.tag-names:first').val("nie wybrano żadnych określeń")
      this.switchViewClass('step-view step-done step-skipped')
      this.action().val('skip')
      this.done()
      this


  '.step-gps':

    input: -> $('#suggestion_latitude, #suggestion_longitude')<commit_msg>fix tags action hidden input<commit_after>#= require sugar
#= require jquery-specializer
#= require gmaps

map = undefined

geocode_location = (callback) ->
  voivodeship = $('form.suggestion').data('voivodeship')
  district = $('form.suggestion').data('district')
  commune = $('form.suggestion').data('commune')
  city = $('#place_name_viewer').val()
  street = $('#suggestion_street').val()

  jQuery.get geocoder_search_path, {voivodeship, district, commune, city, street}, (result) ->
    if result.length > 0
      $('#suggestion_latitude').val(result[0].latitude.round(7))
      $('#suggestion_longitude').val(result[0].longitude.round(7))
      callback(result[0].latitude.round(7), result[0].longitude.round(7)) if callback?
    else
      callback() if callback?

$.fn.specialize

  '.step':

    input: -> this.find("input[type='text']")
    action: -> this.find("#" + this.input().attr('id') + '_action')

    switchViewClass: (klass) ->
      this.saveLocalHistory()
      this.removeClass('step-done step-skipped step-confirmed step-edited step-view step-edit')
      this.addClass(klass)
      $(".help-content").removeClass('active')
      $('.step').removeClass('step-current')
      this.addClass('step-current')
      this.action().val('skip')

    view: ->
      this.switchViewClass('step-view')
      this.find('button.edit').focus()

      this

    edit: ->
      this.switchViewClass('step-edit')
      this.input().edit()

      if this.data('autoscroll')?
        document.location.hash = this.data('autoscroll')

      this

    submit: ->
      if this.hasClass('step-simple') && this.input().val() == ""
        alert("Nie możesz pozostawić pustego pola.")
        return false

      this.switchViewClass('step-view step-done step-edited')
      this.action().val('edit')
      this.input().save()
      this.done()
      this

    confirm: ->
      this.switchViewClass('step-view step-done step-confirmed')
      this.action().val('confirm')
      this.done()
      this

    skip: ->
      this.switchViewClass('step-view step-done step-skipped')
      this.action().val('skip')
      this.done()
      this

    cancel: ->
      this.restoreHistory()
      this.input().save()
      this.view()
      this.saveLocalHistory()
      this

    done: ->
      $('.step').removeClass('step-current')
      this.addClass('step-done').removeClass("step-current")
      next_step = $('.step:not(.step-done):first')
      setHeight = next_step.offset().top - (($(window).height() / 2) - (next_step.height() / 2)) + 100

      setTimeout ->
        $('html,body').animate scrollTop: setHeight, 400, ->
          next_step.view()
      , 300
      this

    back: ->
      if $('.step-current').input().hasChanged()
        alert('Najpierw musisz skończyć edytować bieżące pole.')
      else
        if $('.step-current').hasClass('step-edit')
          $('.step-current').cancel()

        current_step = $('.step-current')

        if this.hasClass('step-edited') && !this.hasClass('step-current')
          this.edit()
        else
          this.view()

        current_step.restoreLocalHistory()

      this

    saveHistory: ->
      this.input().saveHistory()
      this.action().saveHistory()
      this

    restoreHistory: ->
      this.input().restoreHistory()
      this.action().restoreHistory()
      this

    saveLocalHistory: ->
      this.data('class', this.attr('class'))
      this.input().saveLocalHistory()
      this.action().saveLocalHistory()

    restoreLocalHistory: ->
      this.action().restoreLocalHistory()
      this.input().restoreLocalHistory()
      this.attr('class', this.data('class'))
      this.removeClass('step-current')

    restoreLocalState: ->
      this.input().restoreLocalState()

    hasChanged: ->
      this.input().hasChanged()

  # place step have select field instead of text
  '.step-place':

    input: -> $("#suggestion_place_id")

    edit: ->
      this.switchViewClass('step-edit')
      $('#suggestion_place_id').focus()
      this

    submit: ->
      this.find('#place_name_viewer').val(this.find('#suggestion_place_id option:selected').text())
      this.switchViewClass('step-view step-done step-edited')
      this.action().val('edit')
      this.done()
      geocode_location ->
        $('#map_canvas').auto_zoom()

      this

    cancel: ->
      this.restoreHistory()
      this.input().save()
      this.find('#suggestion_place_id').val(this.input().val())
      this.find('#place_name_viewer').val(this.find('#suggestion_place_id option:selected').text())
      this.view()
      this.saveLocalHistory()
      this

  '.step-street':

    submit: ->
      if this.hasClass('step-simple') && this.input().val() == ""
        alert("Nie możesz pozostawić pustego pola.")
        return false
      this.switchViewClass('step-view step-done step-edited')
      this.action().val('edit')
      this.input().save()
      this.done()
      geocode_location ->
        $('#map_canvas').auto_zoom()
      this

  # place step have select field instead of text
  '.step-tags':

    input: -> this.find("input[type='checkbox']")
    action: -> this.find('#suggestion_tags_action')

    view: ->
      this.switchViewClass('step-view')
      this

    skip: ->
      this.cancel()
      this.find('.tag-names:first').val("nie wybrano żadnych określeń")
      this.switchViewClass('step-view step-done step-skipped')
      this.action().val('skip')
      this.done()
      this


  '.step-gps':

    input: -> $('#suggestion_latitude, #suggestion_longitude')
{'fraction_non_alphanumeric': 0.1727891156462585, 'fraction_numerical': 0.0036281179138321997, 'mean_word_length': 2.7099596231493943, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 70, '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': '7642012', 'n_tokens_mistral': 3494, 'n_tokens_neox': 3362, 'n_words': 537}