<div class="row">
	<div class="col-xs-12">
		<?php if($uprawnienia['ModulRejestruSzablonowOceny']['bCzyUruchamianie'] == 'true') : ?>
		<a href="#" data-active="0" data-action="/szablon/daj_szablony_oceny" data-single="1" data-value="szablony" data-title="Szablony"
		   class="btn btn-tile btn-danger">
			<i class="fa fa-sticky-note"></i>
			<span>Szablony</span>
		</a>
		<?php endif; ?>
		<?php if($uprawnienia['ModulProfesjonalnejOcenyPracownika']['bCzyUruchamianie'] == 'true') : ?>
		<a href="#" data-active="0" data-action="/szablon/daj_oceny_pracownika" data-single="1" data-value="oceny" data-title="Oceny"
		   class="btn btn-tile btn-danger">
			<i class="fa fa-list-alt"></i>
			<span>Oceny</span>
		</a>
		<?php endif; ?>
	</div>
</div>
<div class="row">
	<div class="col-xs-12">
		<div class="box box-danger with-border">
			<div class="pull-right" id="btn_dodaj_szablon_oceny">
				<a class="btn btn-success btn-flat" data-menu-action="dodaj_szablon_oceny" href="/dodaj_szablon_oceny">
					<span style="margin-right: 10px;"><i class="fa fa-plus"></i> Dodaj</span>
					<label class="switch"></label>
				</a>
			</div>
			<?php //echo $this->Element('table_loading'); ?>
			<div class="box-body table-responsive table-fixed-height" data-container="table" style="position: relative; width: 100%;">
				<div class="no-data">
					<p>Brak danych</p>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="modal fade" id="generuj-ocena-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">Generuj oceny z szablonu</h4>
			</div>
			<div class="modal-body" id="generuj-ocena-body" style="height: 500px;">
				<div class="row form-horizontal">
					<input name="data[bGenerujOceny][Gid]" type="hidden" id="bGenerujOcenyGid">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="col-xs-12 col-md-2 control-label">Nazwa</label>
							<div class="col-xs-12 col-md-8">
								<input name="data[bGenerujOceny][Nazwa]" required="required" class="form-control" type="text" id="bGenerujOcenyNazwa" aria-required="true">
							</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 ">
								<input name="data[bGenerujOceny][DataOd]" autocomplete="off" class="form-control datepicker-from input-125" type="text" id="bGenerujOcenyDataOd" style="">
							</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">
								<input name="data[bGenerujOceny][DataDo]" autocomplete="off" class="form-control datepicker-to input-125 valid" type="text" id="bGenerujOcenyDataDo" aria-invalid="false" style="">
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="modal-header">
						<h4 class="modal-title">Pracownicy (opcjonalnie)</h4>
						<div>
							<div id="ocena_pracownika_pracownicy"></div>
						</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="generuj-ocena-submit">Generuj</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div><!-- /.modal -->

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

        datepickerFromToInit();

        $('#generuj-ocena-submit').click(function(){

            var formData = {};
            var modalGeneruj = $('#generuj-ocena-modal');

            formData.bGenerujOcenyGid = $('#bGenerujOcenyGid').val();
            formData.bGenerujOcenyNazwa = $('#bGenerujOcenyNazwa').val();
            formData.bGenerujOcenyDataOd = $('#bGenerujOcenyDataOd').val();
            formData.bGenerujOcenyDataDo = $('#bGenerujOcenyDataDo').val();

            var counter = 0;
            var workersList = '';
            var checkedWorkers = modalGeneruj.find('input[type=checkbox]:checked');
            $.each(checkedWorkers, function (index) {
                var $this = $(this);
                if($this.attr('id') != 'ALL') {
                    if (counter > 0) {
                        workersList += ';' + $this.attr('id');
                    } else {
                        workersList += $this.attr('id');
                    }
                    counter++;
                }
            });

            formData.bGenerujOcenyDataWorkers = workersList;

            $.ajax({
                type: 'POST',
                url: '<?php echo $local_url; ?>generuj_oceny',
                data: formData
            }).done(function (response) {
                modalGeneruj.modal('hide');
                response = JSON.parse(response);
                console.log(response);
                if(response['error'] != undefined) {
                    showError(response['error']);
                } else {
                    hideMessages();
                    showSuccess(response['message']);
                }
            });

		});

        $('[data-value="szablony"]').click();

    });
</script>
