/home/hdwebsolution/www/sareenn/assets/admin/js/lifeclave.js
// Switch Activation



function lc_switch_activation(table, id, column, value, label, set_value_id) {

    var base_url = $('#base_url').val();

    var set_value = '';

    $.ajax({

        type: "POST",

        url: base_url + 'admin/ajax/switch',

        data: { 'id': id, 'value': value, 'table': table, 'column': column },

        dataType: 'JSON',

        success: function(data) {

            if (data.response == 1) {

                if (value == 0) {

                    set_value = 1;

                    $('#' + label).html('Yes');

                    $(function() {

                        const Toast = Swal.mixin({

                            toast: true,

                            position: 'top-end',

                            showConfirmButton: false,

                            timer: 3000,

                            background: '#eeeeee'

                        });

                        Toast.fire({

                            type: 'success',

                            title: 'Activated!',

                            icon: 'success',

                        })

                    });

                }

                if (value == 1) {

                    set_value = 0;

                    $('#' + label).html('No');

                    $(function() {

                        const Toast = Swal.mixin({

                            toast: true,

                            position: 'top-end',

                            showConfirmButton: false,

                            timer: 3000,

                            background: '#eeeeee'

                        });

                        Toast.fire({

                            type: 'info',

                            title: 'Disabled!',

                            icon: 'info',

                        })

                    });

                }

                $('#' + set_value_id).val(set_value);



            }

        },

        error: function() {

            $(function() {

                const Toast = Swal.mixin({

                    toast: true,

                    position: 'top-end',

                    showConfirmButton: false,

                    timer: 3000,

                    background: '#eeeeee'

                });

                Toast.fire({

                    type: 'error',

                    title: 'Error in Updating!',

                    icon: 'error',

                })

            });

        },

    });

}


// Document Ready Functions

$(document).ready(function() {

    // Set Base URL

    var base_url = $('#base_url').val();


    // Call the dataTables jQuery plugin

    $("#dataTable").DataTable({

        pageLength: 50,

        order: [

            [0, "desc"]

        ],

    });

    $("#lc-default-dt").DataTable({

        pageLength: 50,

        order: [

            [0, "asc"]

        ],

    });


    // Products Page functions

    $('#lc_product_has_variants_select').on('change', function() {
        var value = this.value;
        if (value == 0) {
            $('.lc_product_has_variants').css("display", "none");
            $("#lc_product_variant_name").attr("required", "false");
            $("#lc_product_parent_id_select").attr("required", "false");
        }
        if (value == 1) {
            $('.lc_product_has_variants').css("display", "block");
            $("#lc_product_variant_name").attr("required", "true");
            $("#lc_product_parent_id_select").attr("required", "true");
        }
    });

});


$(document).ready(function() {

    // Set Table Bordered
    $("table").attr("class", "table table-bordered");
});

$(document).ready(function(e) {
    var base_url = $('#base_url').val();
    $('#variant-sortable').sortable({
        handle: '#variant_sort_handle',
        placeholder: "ui-state-highlight",
        //opacity: 0.9,
        update: function() {
            var order = $('#variant-sortable').sortable('toArray', {
                attribute: 'lc_variant_sort_id'
            });
            console.log(order.join(','));
            sortOrder = order.join(',');
            $.post(
                base_url + 'admin/ajax/sort_variant', {
                    'action': 'updateSortedRows',
                    'sortOrder': sortOrder
                },
                function(data) {
                    var a = data.split('|***|');
                    if (a[1] == "update") {
                        $('#ajax-msg').html(a[0]);
                    }
                }
            );
        }
    });
    $("#variant-sortable").disableSelection();

    $('[data-toggle="tooltip"]').tooltip();
});