<script>
function add_page(){
    myModal = new bootstrap.Modal(document.getElementById('addPageModal'), {
       focus:true
   });
   myModal.show();
}
$(document).ready(function (e) {
    $("#addPageForm").submit(function(e) {


        e.preventDefault();
        var name_en = $('#name_en').val();
        var name_ar = $('#name_ar').val();
            if(name_ar == "" || name_en == ""){
                swal('Page Name is required ...','error');
            return;
        }
        loading();
        for ( instance in CKEDITOR.instances ) {
            CKEDITOR.instances[instance].updateElement();
            }
        var form_data = new FormData(this);
        $.ajax({
            url: '<?php echo e(url("/pages/add")); ?>',
            type: 'POST',
            data: form_data,
            processData: false,
            contentType: false,
            dataType:'json'
        })
        .done(function (response) {
            $('#addPageForm')[0].reset();
           table.ajax.reload();
           swal(response.text,response.cls);

        })
        .fail(function (response) {
            console.log("error ",response);

        }).always(function(){
        	loading("stop");
        });
    });

});

$(document).on('change', '.state_switch', function(event) {
        event.preventDefault();
        loading();
        var cid = $(this).val();
        $.ajax({
            url: '<?php echo e(url("/pages/status")); ?>',
            type: 'post',
            dataType:'json',
            data: {_token: '<?php echo csrf_token(); ?>', id: cid}
        })
        .done(function (response) {
            swal(response.text,response.cls);
        })
        .fail(function () {
            console.log("error");

        }).always(function(){
            loading("stop");
        });
    });

    $(document).on('click', '.btn-delete', function(event) {
        event.preventDefault();
        loading();
        let id = $(this).val();

        $.ajax({
            url: '<?php echo e(url("/pages/destroy")); ?>',
            type: 'post',
            dataType:'json',
            data: {_token: '<?php echo csrf_token(); ?>', id: id}
        })
        .done(function(response) {
            swal(response.text,response.cls);
            setTimeout(function(){
                window.location.reload();
            }, 1000);
        })
        .fail(function() {
            console.log("error");
        })
        .always(function() {
            loading("stop");
        });

    });
</script>
<?php /**PATH D:\HomesteadStuff\code\manage_sarfapp\resources\views/admin/manage_pages/script_js.blade.php ENDPATH**/ ?>