<div class="modal fade" id="add_edit_product_note_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="modal-title bold"> <?php echo CommonLanguage::getMessage('product_note'); ?></h5>
            </div>
            <div class="modal-body">
                <form id="product_note_form" method="POST" onsubmit="return false">
                    <div class="row">
                        <?php echo Forms::AlertDiv('product_note_list'); ?>
                        <input type='hidden' name='note_id' id='note_id'/>
                    </div>
                    <div class="row form-group m-t-10">
                        <div class="col-md-12">
                            <label><?php print CommonLanguage::getMessage('note'); ?></label>
                            <input type="text"  placeholder="<?php print CommonLanguage::getMessage('note'); ?>" id="note_title" name="note_title" class="form-control " autocomplete="off" required>
                        </div>
                    </div>
                    <div class="row form-group m-t-10">
                        <div class="col-md-12">
                            <div class="checkbox check-primary ">
                                <input type="checkbox" id="note_is_linked" name="note_is_linked" >
                                <label for="note_is_linked"><?php print CommonLanguage::getMessage('product_link'); ?></label>
                            </div>
                        </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_product_note"><?php print CommonLanguage::getMessage('Save'); ?></button>
            </div>
            <?php echo Forms::ModalLoader('productNoteLoader'); ?>
        </div>
    </div>
</div>
<script>
    $(function () {
        $(".add_product_note").on("click", function () {
            $("#note_id").val(0);
        });
        $("#tableWithSearch").on("click", ".edit", function () {
            var note_id = $(this).parents('div.Action').attr('data-id');
            $("#note_id").val(note_id);
            $("input[name=note_is_linked]").prop('checked',$('span.is_linked',$(this).parents('tr')).attr('data-type') == "1" ? true : false); 
            $("#note_title").val($(this).parents('tr').find('td:eq(0)').html());
        });
        $("#submit_product_note").on("click", function () {
            if (!$("#product_note_form").valid())
                return;
            $("#productNoteLoader").removeClass('hidden');
            var Data = new FormData(document.getElementById("product_note_form"));
            Data.append('is_linked',$('#note_is_linked').is(':checked') ? 1 : 0)
            $.ajax({
                url: "InventoryAjax/submitProductNote",
                method: "POST",
                data: Data,
                processData: false,
                contentType: false,
                dataType: "JSON",
                complete: function (jqXHR, status) {
                    if (status == 'success') {
                        if (jqXHR.responseJSON[1] == "success") {
                            RebuildDataTable(title, [0], 'InventoryAjax/product_note_list',1);
                            hideModalAlert('add_edit_product_note_modal', 'product_note_list');
                        }
                        AddAlert("#product_note_list", jqXHR.responseJSON[0], jqXHR.responseJSON[1]);
                    }
                    $("#productNoteLoader").addClass('hidden');
                }
            });
        });
    });
</script>