<div class="row" id="DodajSzablonFormContainer">
	<div class="col-xs-12">
		<div class="box box-danger">
			<?php echo $this->Form->create(null, ['templates' => ['submitContainer' => '{{content}}',], 'id' => 'bSzablonOceny', 'name' => 'bSzablonOceny', 'class' => 'form-horizontal']); ?>
			<?php echo $this->Form->input('bGid', array('type' => 'hidden', 'id' => 'gid-szablon')); ?>
			<?php echo $this->Form->input('bDataUtworzenia', array('type' => 'hidden', 'id' => 'init-szablon')); ?>
			<div class="box-body">
				<h3 style="margin-left: 0.5em;">Dane podstawowe</h3>
				<div class="form-group">
					<label class="col-xs-12 col-md-2 control-label">Nazwa</label>
					<div class="col-xs-12 col-md-9">
						<?php echo $this->Form->input('bNazwa', array('required' => 'required', 'class' => 'form-control', 'div' => false, 'label' => false)); ?>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-md-2 control-label">Data Od</label>
					<div class="col-xs-12 col-md-2 ">
						<?php echo $this->Form->input('bDataOd', array('autocomplete' => 'off', 'class' => 'form-control datepicker-from input-125', 'div' => false, 'label' => false, 'required' => '')); ?>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-md-2 control-label">Data Do</label>
					<div class="col-xs-12 col-md-2">
						<?php echo $this->Form->input('bDataDo', array('autocomplete' => 'off', 'class' => 'form-control datepicker-to input-125', 'div' => false, 'label' => false, 'required' => '')); ?>
					</div>
				</div>
				<h3 style="margin-left: 0.5em;">Lista kryteriów</h3>
				<div class="form-group">
					<div class="col-xs-12 col-md-12" id="criteria-search-holder">
						<div class="input-group">
							<div class="input-group-addon ac-search-trigger" id="criteria-search-trigger"><i
									class="fa fa-search"></i>&nbsp;dostępne kryteria</div>
						</div>
					</div>
				</div>
				<div class="path-rows-criteria" id="criteria-rows">
					<?php foreach ($bSzablonOceny['bKryteriaOcenyLista'] as $key => $criteria) :
						$lp = $key+1;
						if ($criteria['bRodzaj'] === 'Grupa') {
							$grey = 'style="color: grey;"';
						} else {
							$grey = '';
						}
						?>
						<div class="row path-row" id="criteria-<?php echo $key; ?>">
							<input type="hidden" class="criteria-gid" name="data[bKryteriumOceny][<?php echo $key; ?>][dat:Gid]" value="<?php echo $criteria['bGid']; ?>">
							<input type="hidden" class="criteria-name" name="data[bKryteriumOceny][<?php echo $key; ?>][dat:Nazwa]" value="<?php echo $criteria['bNazwa']; ?>">
							<input type="hidden" class="criteria-kind" name="data[bKryteriumOceny][<?php echo $key; ?>][dat:Rodzaj]" value="<?php echo $criteria['bRodzaj']; ?>">
							<div class="col-xs-2 path-index"><?php echo $lp; ?></div>
							<div class="col-xs-3" <?php echo $grey;?> ><?php echo $criteria['bNazwa']; ?></div>
							<div class="col-xs-2" <?php echo $grey;?> ><?php echo $criteria['bRodzaj']; ?></div>
							<div class="col-xs-2">
								<?php if (empty($grey)) : ?>
									<input type="checkbox" class="criteria-req" name="data[bKryteriumOceny][<?php echo $key; ?>][dat:CzyObowiazkowe]" value="1" <?php echo $criteria['bCzyObowiazkowe'] === "true" ? "checked='checked'" : ""?> > Wymagane </input>
								<?php endif; ?>
							</div>
							<div class="col-xs-3">
								<a href="#" class="delete-criteria-element btn btn-flat btn-danger pull-right"><i class="fa fa-trash"></i></a>
							</div>
						</div>
					<?php endforeach; ?>
				</div>
				<h3 style="margin-left: 0.5em;">Lista wniosków</h3>
				<div class="form-group">
					<div class="col-xs-12 col-md-12" id="wniosek-search-holder">
						<div class="input-group">
							<div class="input-group-addon ac-search-trigger" id="wniosek-search-trigger"><i
									class="fa fa-search"></i>&nbsp;szukaj wniosek</div>
						</div>
					</div>
				</div>
				<div class="path-rows-wniosek" id="wniosek-rows">
					<?php foreach ($bSzablonOceny['bWnioskiOcenyLista'] as $key => $wniosek) :
						$lp = $key+1; ?>
						<div class="row path-row" id="wniosek-<?php echo $key; ?>">
							<input type="hidden" class="wniosek-gid" name="data[bWniosekOceny][<?php echo $key; ?>][dat:Gid]" value="<?php echo $wniosek['bGid']; ?>">
							<input type="hidden" class="wniosek-gid" name="data[bWniosekOceny][<?php echo $key; ?>][dat:Nazwa]" value="<?php echo $wniosek['bNazwa']; ?>">
							<div class="col-xs-2 path-index"><?php echo $lp; ?></div>
							<div class="col-xs-7"><?php echo $wniosek['bNazwa']; ?></div>
							<div class="col-xs-3">
								<a href="#" class="delete-wniosek-element btn btn-flat btn-danger pull-right"><i class="fa fa-trash"></i></a>
							</div>
						</div>
					<?php endforeach; ?>
				</div>
				<h3 style="margin-left: 0.5em;">Stosuje się do</h3>
				<div class="form-group">
					<label class="col-xs-12 col-md-2 control-label">Uprawniony</label>
					<div class="col-xs-12 col-md-10">
						<div class="col-xs-12 input-group">
							<?php echo $this->Form->input('bNumeryEwidencyjne', array('autocomplete' => 'off', 'class' => 'form-control', 'div' => false, 'label' => false)); ?>
							<a href="#" class="input-group-addon workers-modal-trigger">
								<i class="fa fa-search"></i>
							</a>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-md-2 control-label">Wykluczony</label>
					<div class="col-xs-12 col-md-10">
						<div class="col-xs-12 input-group">
							<?php echo $this->Form->input('bNumeryEwidencyjneWykluczone', array('autocomplete' => 'off', 'class' => 'form-control', 'div' => false, 'label' => false)); ?>
							<a href="#" class="input-group-addon workers-modal-trigger">
								<i class="fa fa-search"></i>
							</a>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-md-2 control-label">Komórek</label>
					<div class="col-xs-12 col-md-10">
						<div class="col-xs-12 input-group">
							<?php echo $this->Form->input('bKomorki', array('autocomplete' => 'off', 'class' => 'form-control', 'div' => false, 'label' => false)); ?>
							<a href="#" data-code-list-number="2" class="input-group-addon codes-modal-trigger">
								<i class="fa fa-search"></i>
							</a>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-md-2 control-label">Stanowisk</label>
					<div class="col-xs-12 col-md-10">
						<div class="col-xs-12 input-group">
							<?php echo $this->Form->input('bStanowiska', array('autocomplete' => 'off', 'class' => 'form-control', 'div' => false, 'label' => false)); ?>
							<a href="#" data-code-list-number="5" class="input-group-addon codes-modal-trigger">
								<i class="fa fa-search"></i>
							</a>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-md-2 control-label">Płatników</label>
					<div class="col-xs-12 col-md-10">
						<div class="col-xs-12 input-group">
							<?php echo $this->Form->input('bPlatnicy', array('autocomplete' => 'off', 'class' => 'form-control', 'div' => false, 'label' => false)); ?>
							<a href="#" data-code-list-number="52" class="input-group-addon codes-modal-trigger">
								<i class="fa fa-search"></i>
							</a>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-md-2 control-label">Pionów</label>
					<div class="col-xs-12 col-md-10">
						<div class="col-xs-12 input-group">
							<?php echo $this->Form->input('bPiony', array('autocomplete' => 'off', 'class' => 'form-control', 'div' => false, 'label' => false)); ?>
							<a href="#" data-code-list-number="53" class="input-group-addon codes-modal-trigger">
								<i class="fa fa-search"></i>
							</a>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-md-2 control-label">Regionów</label>
					<div class="col-xs-12 col-md-10">
						<div class="col-xs-12 input-group">
							<?php echo $this->Form->input('bRegiony', array('autocomplete' => 'off', 'class' => 'form-control', 'div' => false, 'label' => false)); ?>
							<a href="#" data-code-list-number="54" class="input-group-addon codes-modal-trigger">
								<i class="fa fa-search"></i>
							</a>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-md-2 control-label">Miejsc</label>
					<div class="col-xs-12 col-md-10">
						<div class="col-xs-12 input-group">
							<?php echo $this->Form->input('bMiejscaWykonywaniaPracy', array('autocomplete' => 'off', 'class' => 'form-control', 'div' => false, 'label' => false)); ?>
							<a href="#" data-code-list-number="125" class="input-group-addon codes-modal-trigger">
								<i class="fa fa-search"></i>
							</a>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-md-2 control-label">Charakterów pracy</label>
					<div class="col-xs-12 col-md-10">
						<div class="col-xs-12 input-group">
							<?php echo $this->Form->input('bCharakteryPracy', array('autocomplete' => 'off', 'class' => 'form-control', 'div' => false, 'label' => false)); ?>
							<a href="#" data-code-list-number="24" class="input-group-addon codes-modal-trigger">
								<i class="fa fa-search"></i>
							</a>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-md-2 control-label">&nbsp;</label>
					<div class="col-xs-12 col-md-10">
						<a style="margin-right: 20px;" data-menu-action="/szablon/szablony_oceny_pracownika" href="/szablon/szablony_oceny_pracownika" <?php /*onclick="history.go(-1)"*/ ?> class="btn btn-default pull-left">Anuluj</a>
						<?php echo $this->Form->submit('Zapisz', array('name' => 'data[action]', 'div' => false, 'class' => 'btn btn-success')); ?>
					</div>
				</div>
			</div>
			<?php echo $this->Form->end(); ?>
		</div>
	</div>
</div>
<div class="modal fade" id="criteria-list-modal">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title">Wybierz kryteria</h4>
			</div>
			<div class="modal-body" id="criteria-list-body">
				<div class="row">
					<div class="loader-holder" id="criteria-list-loader">
						<div class="loader"></div>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
				<button type="button" class="btn btn-success" id="criteria-list-submit">Wybierz</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<div class="modal fade" id="wniosek-list-modal">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title">Wybierz wnioski</h4>
			</div>
			<div class="modal-body" id="wniosek-list-body">
				<div class="row">
					<div class="loader-holder" id="wniosek-list-loader">
						<div class="loader"></div>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">Anuluj</button>
				<button type="button" class="btn btn-success" id="wniosek-list-submit">Wybierz</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<div class="modal fade" id="code-list-modal">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title">Wybierz kody</h4>
			</div>
			<div class="modal-body" id="code-list-body">
				<div class="row">
					<div class="loader-holder" id="code-list-loader">
						<div class="loader"></div>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">Zamknij</button>
				<button type="button" class="btn btn-success" id="code-list-submit">Zapisz</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<div class="modal fade" id="workers-list-modal">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title">Wybierz pracowników</h4>
			</div>
			<div class="modal-body" id="workers-list-body">
				<div class="row">
					<div class="loader-holder" id="workers-list-loader">
						<div class="loader"></div>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">Zamknij</button>
				<button type="button" class="btn btn-success" id="workers-list-submit">Zapisz</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script type="text/javascript" src="<?php echo $local_url; ?>js/template.js"></script>
<script type="text/javascript" src="<?php echo $local_url; ?>js/paths.js"></script>

<script>
    $(document).ready(function () {

        datepickerFromToInit();

        $("#DodajSzablonFormContainer form").validate({
            submitHandler: function (form) {
                var formData = $(form).serializeArray();
                var formAction = '<?php echo $local_url; ?>szablon/dodaj_szablon_oceny'

                $.ajax({
                    type: 'POST',
                    url: formAction,
                    data: formData
                }).done(function (response) {
                    response = JSON.parse(response);
                    console.log(response);
                    if(response['error'] != undefined) {
                        showError(response['error']);
                    } else {
                        hideMessages();
                        showSuccess(response['message']);
                        loadAjaxView('/szablon/szablony_oceny_pracownika');
                    }
                });
            }
        });
    });
</script>

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