<?php
use yii\widgets\ActiveForm;
use yii\helpers\Html;
?>

<?php $form = ActiveForm::begin(['id'=>'form-pdf-setting']); ?>

<?= $form->field($model,'paper_size')->dropDownList([
    'A4'=>'A4',
    'A5'=>'A5',
    'thermal'=>'Thermal 58mm',
    'thermal80'=>'Thermal 80mm',
]) ?>

<?= $form->field($model,'orientation')->dropDownList([
    'portrait'=>'Portrait',
    'landscape'=>'Landscape'
]) ?>

<div class="row">
    <div class="col"><?= $form->field($model,'margin_top') ?></div>
    <div class="col"><?= $form->field($model,'margin_bottom') ?></div>
    <div class="col"><?= $form->field($model,'margin_left') ?></div>
    <div class="col"><?= $form->field($model,'margin_right') ?></div>
</div>

<?= $form->field($model,'show_logo')->checkbox() ?>

<?= $form->field($model,'header_text')->textarea() ?>
<?= $form->field($model,'footer_text')->textarea() ?>

<div class="text-right mt-3">
    <?= Html::submitButton('Simpan', ['class'=>'btn btn-primary', 'id'=>'btn-save-pdf']) ?>
</div>

<?php ActiveForm::end(); ?>


<script>
$(document).off('click','#btn-save-pdf').on('click','#btn-save-pdf', function(e){

    e.preventDefault();

    var form = $('#form-pdf-setting');

    var csrfParam = $('meta[name=csrf-param]').attr('content');
    var csrfToken = $('meta[name=csrf-token]').attr('content');

    swal({
        title: "Menyimpan...",
        text: "Silakan tunggu",
        buttons: false,
        closeOnClickOutside: false,
        closeOnEsc: false,
        icon: "info"
    });

    $.post(form.attr('action'), form.serialize(), function(res){

        swal.close();

        if(res.success){

            $('#modal-pdf').modal('hide');

            pdfTable.ajax.reload(null,false);

            swal("Berhasil!", res.message, "success");

        } else {

            swal("Gagal!", res.message || "Gagal menyimpan", "error");

        }

    }).fail(function(){

        swal("Error!", "Kesalahan server", "error");

    });

});

</script>