Source: fine.js

$(document).ready(function(){

    // initialize datepicker
    var initDatepicker = function() {
        $('.datepicker').datepicker({
            todayHighlight: true,
            autoclose: true,
            format: 'yyyy-mm-dd',
        });
    }


    // get payment form
    // $(document).on('click', '.js-payment', function() {
    //     var id = $(this).data('id');
    //     if(id != null) {
    //         $.get(base_url + "staff/fine/request-payment-form/" +id, function(data) {
    //             $("#action_section").empty()
    //             $("#action_section").append(data);
           

    //             // document.querySelector('#clerk_payment_form').scrollIntoView({behavior: 'smooth'});
    //         });
    //     }
    //     else {
    //        $.get(base_url + "staff/fine/request-payment-form", function(data) {
    //            $("#action_section").empty()
    //            $("#action_section").append(data);
            
    //        }); 
    //     }
    // });

 

    // $(document).on('click', '#payment_form_submit', function() {       
    //     $.post($("#payment_form").attr('action'), $("#payment_form").serialize(), function(data) {  
    //         var responseMsg = '';
    //         switch(data.status){

    //             case "success":
    //                 var responseMsg = atob(data.message);                    
    //             break;
    //             case "validation_failed":
    //                 $("#paymentAmountError").html(atob(data.message));
    //             break;
    //             case "error":
    //                 var responseMsg = atob(data.message);                    
    //             break;
    //         }

    //         if(responseMsg != '') {
    //             $('#payment_form').empty();
    //             $('#fine_msg_block').show();
    //             $('#fine_msg').html(responseMsg);

                
    //         }
           
            
    //     }, 'json');
    //     return false;
    // });

       // get payment form

       /**
       * This function handles button click to open payment acknowledgement form for editing
       */
       $(document).on('click', '.js-payment', function() {
        var id = $(this).data('id'); 

        var pageURL = base_url+"staff/fine/request-payment-form/" +id ; 
        var pageTitle = "iCourtApp::Fine Payment";
        var myWindow = newWindow.createPopupWin(pageURL, pageTitle, 800, 'auto');

       //var myWindow = window.open(base_url+"staff/fine/request-payment-form/" +id, "", "resizable=false, width=600,height=500,directories=0,titlebar=0,toolbar=0,location=0,status=0,menubar=0");
        
        

        
        // if(id != null) { 
        //     $.get(base_url + "staff/fine/request-payment-form/" +id, function(data) {
        //         $('.new-tab-wrap').find('.active').removeClass('active')
        //         $('#myTabContent').find('.show.active').removeClass('show active')
        //         $('#new-fine-tab').parent('li').show()
        //         $('#new-fine-tab').text('Payment')
        //         $('#new-fine-tab').addClass('active')
        //         $('#new-fine').addClass('show active')
        //         $("#fine_section").empty();
        //         $("#fine_section").append(data);
        //         $('#payment_list').hide()
        //         if($('#payment_list').is(':hidden')){
        //             $('#payment-form').show()
        //        }
                

        //         // document.querySelector('#clerk_payment_form').scrollIntoView({behavior: 'smooth'});
        //     });
        // }
        // else {
        //    $.get(base_url + "staff/fine/request-payment-form", function(data) {
        //        $('.new-tab-wrap').find('.active').removeClass('active')
        //        $('#myTabContent').find('.show.active').removeClass('show active')
        //        $('#new-fine-tab').parent('li').show()
        //        $('#new-fine-tab').text('Payment')
        //        $('#new-fine-tab').addClass('active')
        //        $('#new-fine').addClass('show active')
        //        $("#fine_section").empty();
        //        $("#fine_section").append(data);
        //        $('#payment-form').hide()
        //        if($('#payment-form').is(':hidden')){
        //             $('#payment_list').show()
        //        }
              
              
        //    }); 
        // }
    });

   /**
   * This function handles button click to delete payment acknowledgement form from table
   */
    $(document).on('click', '.js-delete-payment-form', function() {
        var answer = confirm('Are you sure you want to delete?')
        if(answer == true) {
            var id = $(this).data('id')
            var _this = $(this)
            $.get(base_url + "staff/fine/request-payment-form-delete/"+id, function(data) {

                var msg = atob(data.message)
                switch(data.status){
                    case "delete":                        
                        $.get(base_url + "staff/fine/show-form", function(data) {
                            $("#fine_section").empty();
                            $("#fine_section").append(data);
                            $("#new_fine_message").html(msg);
                        });
                    break;
                    case "error":
                        // lawa
                        $.get(base_url + "staff/fine/show-form", function(data) {
                            $("#fine_section").empty();
                            $("#fine_section").append(data);
                            $("#new_fine_message").html(msg);
                        });

                    break;
                }
            })
        }
    });

   /**
   * This function handles button click to open new payment acknowledgement form
   */
    $(document).on('click', '.js-add-payment', function() { 


        var pageURL = base_url+"staff/fine/request-payment-form" ;
        var pageTitle = "iCourtApp::Fine Payment";
        var myWindow = newWindow.createPopupWin(pageURL, pageTitle, 550,550);


       // var myWindow = window.open(base_url+"staff/fine/request-payment-form", "", "width=600,height=500,directories=0,titlebar=0,toolbar=0,location=0,status=0,menubar=0");
            // $.get(base_url + "staff/fine/request-payment-form/", function(data) {
            //     $('.new-tab-wrap').find('.active').removeClass('active')
            //     $('#myTabContent').find('.show.active').removeClass('show active')
            //     $('#new-fine-tab').parent('li').show()
            //     $('#new-fine-tab').text('Payment')
            //     $('#new-fine-tab').addClass('active')
            //     $('#new-fine').addClass('show active')
            //     $("#fine_section").empty();
            //     $("#fine_section").append(data);
            //     $('#payment_list').hide()
            //     if($('#payment_list').is(':hidden')){
            //         $('#payment-form').show()
            //    }
                

            //     // document.querySelector('#clerk_payment_form').scrollIntoView({behavior: 'smooth'});
            // });
       
    });




 


   
})

/**
* This function handles submit button of payment acknowledgement form and adds the data to the table
*/
var fineAction = {
    submit: function() {
        $.get(base_url + "staff/fine/show-form", function(data) {
            $('.new-tab-wrap').find('.active').removeClass('active')
            $('#myTabContent').find('.show.active').removeClass('show active')
            $('#new-fine-tab').parent('li').show()
            $('#new-fine-tab').text('Payment')
            $('#new-fine-tab').addClass('active')
            $('#new-fine').addClass('show active')
            $("#fine_section").empty();
            $("#fine_section").append(data);
            if($('#payment-form').is(':hidden')){
                $('#payment_list').show()
            } 
        });
    }
}