<commit_before># Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/


$ ->
	$('.party-info-container').show() if $('#booking_party').prop('checked')
	$('.location-container').on 'change', 'input[type="radio"]', ->
		fest = $(@).data 'fest'
		$('.party-container').toggle fest

		# Disable booking_fest if not festrum
		$('#booking_party').attr('checked', false) unless fest

		$('#booking_party').trigger('change')
		# $('.party-info-container').toggle fest
	$('#booking_party').on 'change', (e) ->
		$('.party-info-container').toggle @checked
	if window.location.href.match /new/
		for name, value of JSON.parse(localStorage.getItem 'bookITStorage')
			$elem = $("\##{name}")
			if $elem.val().length == 0
				$elem.val(value)
	$('form').on 'submit', (e) ->
		return unless window.localStorage
		store = {}
		$('input').each ->
			$this = $(@)
			if $this.data 'persist'
				store[$this.attr('id')] = $this.val() if $this.val().length > 0
		localStorage.setItem 'bookITStorage', JSON.stringify store<commit_msg>ux improvemets on booking<commit_after># Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/


$ ->
	$('.party-info-container').show() if $('#booking_party').prop('checked')
	setFormValues($('.location-container input[type="radio"]:checked').first())



	$('.location-container').on 'change', 'input[type="radio"]', ->
		setFormValues(@)


	$('#booking_party').on 'change', (e) ->
		$('.party-info-container').toggle @checked
	if window.location.href.match /new/
		for name, value of JSON.parse(localStorage.getItem 'bookITStorage')
			$elem = $("\##{name}")
			if $elem.val().length == 0
				$elem.val(value)


	$('form').on 'submit', (e) ->
		return unless window.localStorage
		store = {}
		$('input').each ->
			$this = $(@)
			if $this.data 'persist'
				store[$this.attr('id')] = $this.val() if $this.val().length > 0
		localStorage.setItem 'bookITStorage', JSON.stringify store


	# dis amount of UX... changes end_date to begin_date if end_date > begin_date
	$('.booking-dates-container').on 'change', 'input', ->
		$this = $(@)
		$other = $('.booking-dates-container input').not($this)
		begin_date = $('#booking_begin_date')
		end_date = $('#booking_end_date')
		if begin_date.val() > end_date.val()
			if $this.is(begin_date)
				end_date.val(begin_date.val())
			else
				begin_date.val(end_date.val())

setFormValues = (activeRadio) ->
	fest = $(activeRadio).data 'fest'
	$('.party-container').toggle fest
	options = $('option', '#booking_group')
	options.first().attr('disabled', fest)

	# prevents a person to book rooms only to be booked by groups
	if options.length > 1
		$('#booking_group').val(options[1].value)
	else
	$('#booking_group')[0].setCustomValidity('Lokalen kan ej bokas som privatperson')


	# Disable booking_fest if not festrum
	$('#booking_party').attr('checked', false) unless fest


	$('#booking_party').trigger('change')
	# $('.party-info-container').toggle fest
{'fraction_non_alphanumeric': 0.18877867327960324, 'fraction_numerical': 0.0021698698078115313, 'mean_word_length': 4.4144295302013425, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, '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': '5988800', 'n_tokens_mistral': 1128, 'n_tokens_neox': 1041, 'n_words': 253}