<?php
/*
 * *************************************************
 * Copyright (C) 2021 Earworks.                    *
 * Codeigniter Project Template Modification       *
 * Please contact our email for more information : *
 * contact@earworks.co.id                          *
 * *************************************************
 */

defined('BASEPATH') OR exit('No direct script access allowed');
?>
<?= form_open(current_url() . '?redir=' . $redir, ['class' => 'form-horizontal']) ?>
<div class="row">
    <div class="col-sm-8">
        <div class="form-group">
            <?= lang('souvenir', [], 'souvenir', ['class' => 'col-sm-3 control-label']) ?>
            <div class="col-sm-9">
                <?= form_input('souvenir', $data['souvenir'], ['class' => 'form-control']) ?>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-9 col-sm-offset-3">
                <?= form_submit('submit', 'Submit', ['class' => 'btn blue']) ?>
            </div>
        </div>
    </div>

</div>
<?= form_close() ?>
<script type="text/javascript">

</script>
<?php
Ci::set_style('../plugins/select2/css/select2.min.css', 'plugin');
Ci::set_style('../plugins/select2/css/select2-bootstrap.min.css', 'plugin');
Ci::set_script('../plugins/select2/js/select2.min.js', 'plugin');
$syarat_form_url = base_url('absen/ajax-syarat-form/');
$syarat_modal_url = base_url('absen/ajax-syarat-modal/');
Ci::set_style(<<<CSS
    .select2-container {width:100% !important;}
CSS
        , 'embed');
Ci::set_script(<<<EOD
    var page_script = function () {
        var the;
        var syarat_form = '{$syarat_form_url}';
        return {
            init: function () {
                the = this;
                $('.select2').select2();
            },
            add_syarat: function (value) {
                var id = $('.syarat_item').length;
                $.ajax({
                    url: syarat_form + id, type: 'POST', dataType: 'HTML',
                    data: {value: value}, success: function (res) {
                        $('#syarat_list').append(res);
                    }
                });
            },
            fill_syarat: function (obj) {
                var target = $(obj).data('target');
                var target_title = target + 1;
                the.ajaxlink('{$syarat_modal_url}' + target, 'Isi syarat ' + target_title);
            },
            generate_syarat: function (id) {
                var text_syarat = '';
                $('input[name="syarat_absen"]:checked').each(function () {
                    text_syarat += this.value.trim() + '|';
                });
                $('[name="syarat[' + id + ']"]').val(text_syarat.replace(/^\|+|\|+$/g, ''));
                $('#metronic-modal').modal('hide');
            },
            remove_syarat: function (obj) {
                var target = $(obj).data('target');
                $('#syarat_'+target).remove();
            },
            ajaxlink: function (url, title) {
                $('#metronic-modal').modal('show');
                $.ajax({
                    url: url, type: 'GET', dataType: 'HTML',
                    success: function (res) {
                        $('#modal-title').empty().html(title);
                        $('#modal-body').empty().html(res);
                    }
                });
            },
        };
    }();
    $(document).ready(function () {
        page_script.init();
    });
EOD
        , 'embed');
