<div class="row">
	<?php echo $this->Form->create(null, ['templates' => ['submitContainer' => '{{content}}',], 'id' => 'pSciezkaAkceptacji', 'name' => 'pSciezkaAkceptacji', 'class' => 'form-horizontal']); ?>
	<div class="col-xs-12">
		<div class="box box-danger with-border" style="min-height: 50vh; padding: 5px;">
			<div class="row">
				<div class="col-xs-12">
					<h2>Przekaż wniosek</h2>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-12">
					<?php echo $this->Element('sciezka_akceptacji'); ?>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-12">
					<a href="wnioski" data-menu-action="wnioski" style="margin-right: 10px;" class="btn btn-default btn-flat pull-left">Anuluj</a>
					<button class="btn btn-success btn-flat pull-left" id="przekaz_wniosek_submit">Przekaż</button>
				</div>
			</div>

		</div>
	</div>
	<?php echo $this->Form->end(); ?>
</div>










<?php echo $this->element('receivers-modal'); ?>

<script type="text/javascript" src="<?php echo $local_url; ?>js/paths.js"></script>

<script>
	$('#przekaz_wniosek_submit').on('click', function (e) {

		e.preventDefault();

		var formData = $('#pSciezkaAkceptacjiPrzekazWniosekForm').serializeArray();
		var formAction = $('#pSciezkaAkceptacjiPrzekazWniosekForm').attr('action');

		$.ajax({
			url: formAction,
			method: 'POST',
			data: formData,
			beforeSend: function () {
				$('#table-loading2[data-main-loader]').css('visibility', 'visible');
				$('#table-loading2[data-main-loader]').css('opacity', '1');
				$('#table-loading2[data-main-loader]').css('display', 'block');
			},
			success: function(data) {
				var response = JSON.parse(data);

				$('#table-loading2[data-main-loader]').css('visibility', 'hidden');
				$('#table-loading2[data-main-loader]').css('opacity', '0');
				$('#table-loading2[data-main-loader]').css('display', 'none');

				hideMessages();

				if(response['error'] != undefined) {
					showError(response['error']);
				} else {
					showSuccess(response['message']);
				}

				loadAjaxView('/wnioski');
			}
		});
	});
</script>

<script>
    const elemsData = document.querySelectorAll('[data-menu-action]')
    elemsData.forEach(elem => elem.onclick = testFun)

    function testFun(e) {
        e.preventDefault();

        $(this).parents('.sidebar').find('li.active:not(.treeview)').removeClass('active');
        $(this).parents('li').addClass('active');

        var url = $(this).data('menu-action');
        localStorage.setItem('menu_action', url);

        loadAjaxView(url);
    }
</script>
