
<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"> <?php print $title; ?></div>
            <?php
            if ($permissions->hasPermission('add_subscription_category')) {
                echo Forms::FloatingAddButton('4c0870', '#subscription_category_modal', CommonLanguage::getMessage('add_subscription_category'), 'add_subscription_category_btn');
            }
            ?>
        </div>
        <div class="panel-body">
            <div class=" row   ">
                <div class="col-md-12 table-responsive">
                    <table class="table table-bordered  inventory" id="tableWithSearch" >
                        <thead>
                            <tr>
                                <th class="text-center" style="width:15%" ><?php print CommonLanguage::getMessage('category_name'); ?></th> 
                                <th class="text-center" style="width:15%" ><?php print CommonLanguage::getMessage('sort_order'); ?></th>
                                <th class="text-center no-print" style="width:15%"><?php print CommonLanguage::getMessage('Action'); ?></th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="subscription_category_modal" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header text-left">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="pg-close fs-20"></i>
                </button>
                <h5 class="add-label bold hidden h-labels"><?php echo CommonLanguage::getMessage('add_subscription_category'); ?></h5>
                <h5 class="edit-label bold hidden h-labels"><?php echo CommonLanguage::getMessage('edit_subscription_category'); ?></h5>
            </div>
            <div class="modal-body">
                <form id="subscription_category_form" method="POST" onsubmit="return false">
                    <input type='hidden' name='category_id' id='category_id'/>
                    <div class="row">
                        <?php echo Forms::AlertDiv('subscription_category_alert'); ?>
                    </div>
                    <div class="row form-group">
                        <div class="col-md-12">
                            <label><?php echo CommonLanguage::getMessage('category_name'); ?></label> 
                            <span class="red-star">*</span>
                            <input type="text"  placeholder="<?php print CommonLanguage::getMessage('category_name'); ?>" id="category_name" name="category_name" class="form-control " required>
                        </div>
                    </div>
                    <div class="row form-group">
                        <div class="col-md-12">
                            <label><?php echo CommonLanguage::getMessage('sort_order'); ?></label> 
                            <input type="text"  placeholder="<?php print CommonLanguage::getMessage('sort_order'); ?>" id="sort_order" name="sort_order" class="form-control ">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal"><?php print CommonLanguage::getMessage('Close'); ?></button>
                <button class="btn btn-primary" id="submit_subscription_category"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
            <?php echo Forms::ModalLoader('subscription_category_loader'); ?>
        </div>
    </div>
</div>
<script>
    $(function () {
        RebuildDataTable($('.panel-heading .panel-title').html(), [0, 1], "InventoryAjax/subscription_category_list");
        $('#tableWithSearch').on('click', '.delete_subscription_category', function () {
            var category_id = $(this).parents('div.Action').attr('data-id');
            IncludeDeleteModal(common_delete_modal, {entry_value: category_id}, function () {
                RebuildDataTable($('.panel-heading .panel-title').html(), [0, 1], 'InventoryAjax/subscription_category_list');
            }, "InventoryAjax/delete_subscription_category");
        });
        $(".add_subscription_category_btn").on("click", function () {
            $("#category_id").val('');
            $('#subscription_category_modal .add-label').removeClass('hidden');
        });
        $("#tableWithSearch").on("click", ".edit_subscription_category", function () {
            var category_id = $(this).parents('div.Action').attr('data-id');
            $('#subscription_category_modal .edit-label').removeClass('hidden');
            $("#category_id").val(category_id);
            $("#category_name").val($(this).parents('tr').find('td:eq(0)').html());
            $("#sort_order").val($(this).parents('tr').find('td:eq(1)').html());
        });
        $("#submit_subscription_category").on("click", function () {
            if (!$("#subscription_category_form").valid())
                return;
            $("#subscription_category_loader").removeClass('hidden');
            var Data = new FormData(document.getElementById("subscription_category_form"));
            $.ajax({
                url: "InventoryAjax/submit_subscription_category",
                method: "POST",
                data: Data,
                processData: false,
                contentType: false,
                dataType: "JSON",
                complete: function (jqXHR, status) {
                    if (status == 'success') {
                        if (jqXHR.responseJSON[1] == "success") {
                            RebuildDataTable($('.panel-heading .panel-title').html(), [0,1], 'InventoryAjax/subscription_category_list');
                            hideModalAlert('subscription_category_modal', 'subscription_category_alert');
                        }
                        AddAlert("#subscription_category_alert", jqXHR.responseJSON[0], jqXHR.responseJSON[1]);
                    }
                    $("#subscription_category_loader").addClass('hidden');
                }
            });
        });
    });
</script>