include mixins

form(class="form-horizontal subroot", role="form", id="form", method="POST", action="#{away_href}/commit")
	.new_flex_zero
		.container-fluid(style="margin-bottom: 20px;")
			button(class="btn btn-success btn-sm", type="submit") 
				span(class="glyphicon glyphicon-ok", aria-hidden="true")
				span 
				span Übernehmen
			
			+messageview(messages.other)
	
	.new_flex_one
		.container-fluid
		
			.form-group
				label(for='edit_kontext', class="col-sm-2 control-label") Kontext
				.col-sm-10
					.input-group
						input(id="edit_kontext_dn", type="hidden", name="punit_dn", value="#{away.punit.dn}")
						input(id="edit_kontext", type="text", name="punit_name", class="form-control", value="#{away.punit.name}", readonly)
						span(class="input-group-btn")
							button(class="btn btn-default", type="button", onclick="save_and_goto('select_pastoralunit', {})") Ändern

			.form-group
				label(for='edit_name', class="col-sm-2 control-label") Abwesende Person
				.col-sm-10
					.input-group
						input(id="edit_involveddb_id", type="hidden", name="involveddb_id", value="#{away.involveddb_id}")
						input(id="edit_name", type="text", name="edit_name", class="form-control noDirectInput", value="#{away.name}", required)
						span(class="input-group-btn")
							button(class="btn btn-default", type="button", onclick="save_and_goto('add_actor', {role: '', actual_actor_id: '#{away.involveddb_id}', actual_actor_name : '#{away.name}'})") Ändern
					.help-block.with-errors
			#messageview_involved_primary
				if messages.involved.primary.length > 0
					+messageview(messages.involved.primary)

			.form-group
				label(for='edit_reason', class="col-sm-2 control-label") Grund
				.col-sm-10
					input(id='edit_reason', type="text", class="form-control noEnterSubmit", name="edit_reason", value="#{away.reason}", required)
					.help-block.with-errors
	

	script.
		$('.noEnterSubmit').keydown(function(e){
			if ( e.which == 13 ) e.preventDefault();
		});
		
		$('.noDirectInput').keydown(function(e) {
			var target = $(e.currentTarget);
			var form_group = target.closest('.form-group');
			var help_block = form_group.find('.with-errors');
			if(! form_group.hasClass('has-error'))
			{
				target.closest('.form-group').addClass('has-error');
			}
			if(! help_block.hasClass('has-halieus-error')) {
				help_block.addClass('has-halieus-error');
				help_block.append("<ul class='list-unstyled'><li>Sie müssen den 'Ändern'-Button benutzen!</li></ul>");
			}
			
			e.preventDefault();
		});
		$('.noDirectInput').keyup(function(e) { e.preventDefault(); });
		$('.noDirectInput').keypress(function(e) { e.preventDefault(); });
		
		$('.noDirectInput').focusout(function(e) {
			var target = $(e.currentTarget);
			var form_group = target.closest('.form-group');
			var help_block = form_group.find('.with-errors');
			help_block.empty();
			help_block.removeClass('has-halieus-error');
		});
		
		$('#form').validator().on('invalid.bs.validator', function (e) {
			console.log("INVALID");
			console.log(e);
		}).on('valid.bs.validator', function (e) {
			console.log("VALID");
			console.log(e);
		});
		
