$(function(){
var initDatetimePicker = function() {
$('#datetimepicker1').datetimepicker();
$('#datetimepicker2').datetimepicker();
}
// $(document).on("click", "#po_submit_form", function() {
// html2canvas($("#canvas-signature"), {
// onrendered: function(canvas) {
// var imgsrc = canvas.toDataURL("image/png");
// console.log('img src',imgsrc);
// $("#newimg").attr('value', imgsrc);
// $("#img").show();
// var dataURL = canvas.toDataURL();
// $.ajax({
// type: "POST",
// url: base_url + "staff/probation/sign",
// dataType:'JSON',
// data: {
// imgBase64: dataURL,
// filename : imgsrc
// }
// }).done(function(data) {
// if(data.filepath !=""){
// $("#file-paths").val(data.signname);
// submit_probation_form();
// }
// });
// }
// });
// return false;
// });
/**
* This function handles button click to open probation form
*/
$(document).on('click', '.js-probation', function() {
var id = $(this).data('id');
if(id != null) {
// loadProbationList(id);
var pageURL = base_url + "staff/probation/request-probation-form/" +id ;
var pageTitle = "iCourtApp::Probation";
var myWindow = newWindow.createPopupWin(pageURL, pageTitle, 800, 'auto');
// var myWindow = window.open(base_url+, "", "width='auto',height='auto',directories=0,titlebar=0,toolbar=0,location=0,status=0,menubar=0");
}
else {
var pageURL = base_url + "staff/probation/request-probation-form" ;
var pageTitle = "iCourtApp::Probation";
var myWindow = newWindow.createPopupWin(pageURL, pageTitle, 800, 'auto');
// var myWindow = window.open(base_url+"staff/probation/request-probation-form", "", "width='auto',height='auto',directories=0,titlebar=0,toolbar=0,location=0,status=0,menubar=0");
// $.get(base_url + "staff/probation/request-probation-form", function(data) {
// $('.new-tab-wrap').find('.active').removeClass('active')
// $('#myTabContent').find('.show.active').removeClass('show active')
// $('#new-probation-tab').parent('li').show()
// $('#new-probation-tab').text('Probation')
// $('#new-probation-tab').addClass('active')
// $('#new-probation').addClass('show active')
// $("#probation_section").empty();
// $("#probation_section").append(data);
// $('#probation-form').hide()
// if($('#probation-form').is(':hidden')){
// $('#probation-list').show()
// }
// });
}
});
/**
* This function handles button click to delete probation form from table
*/
$(document).on('click', '.js-delete-probation-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/probation/request-probation-form-delete/"+id, function(data) {
var msg = atob(data.message)
switch(data.status){
case "delete":
$.get(base_url + "staff/probation/show-form", function (data) {
$("#probation_section").empty();
$("#probation_section").append(data);
$("#new_probation_message").append(msg);
});
break;
case "error":
// lawa
$.get(base_url + "staff/probation/show-form", function (data) {
$("#probation_section").empty();
$("#probation_section").append(data);
$("#new_probation_message").append(msg);
});
break;
}
})
}
});
})
// var loadProbationList = function(id){
// $.get(base_url + "staff/probation/request-probation-form/" +id, function(data) {
// $('.new-tab-wrap').find('.active').removeClass('active')
// $('#myTabContent').find('.show.active').removeClass('show active')
// $('#new-probation-tab').parent('li').show()
// $('#new-probation-tab').text('Probation')
// $('#new-probation-tab').addClass('active')
// $('#new-probation').addClass('show active')
// $("#probation_section").empty();
// $("#probation_section").append(data);
// $('#probation-list').hide()
// if($('#payment_list').is(':hidden')){
// $('#probation-form').show()
// }
// // document.querySelector('#probation_officer_form').scrollIntoView({behavior: 'smooth'});
// });
// }
// var submit_probation_form = function(){
// $.post($("#probation_officer_form").attr('action'), $("#probation_officer_form").serialize(), function(data) {
// if(data.status.localeCompare("success")==0){
// var responseMsg = atob(data.message);
// $.get(base_url + "staff/probation/request-probation-form", function(data) {
// $('.new-tab-wrap').find('.active').removeClass('active')
// $('#myTabContent').find('.show.active').removeClass('show active')
// $('#new-probation-tab').parent('li').show()
// $('#new-probation-tab').text('Probation')
// $('#new-probation-tab').addClass('active')
// $('#new-probation').addClass('show active')
// $("#probation_section").empty();
// $("#probation_section").append(data);
// $('#probation_msg').html(responseMsg);
// $('#probation-form').hide()
// if($('#probation-form').is(':hidden')){
// $('#probation-list').show()
// }
// });
// }
// if(data.status.localeCompare("validation_failed") ==0){
// $("#po_choose_error").html(atob(data.po_choose));
// $("#offense_error").html(atob(data.offense));
// $("#citation_error").html(atob(data.citation));
// $("#po_fine_error").html(atob(data.po_fine));
// $("#po_supervision_fee_error").html(atob(data.po_supervision_fee));
// $("#sign_error").html(atob(data.sign));
// if(data.months){
// $("#po-month").addClass("makeRed");
// var input = document.getElementById ("po-month");
// input.placeholder = "Required";
// }
// if(data.fine_per_month){
// $("#fine_per_month").addClass("makeRed");
// var input = document.getElementById ("fine_per_month");
// input.placeholder = "Required";
// }
// }
// }, 'json');
// }
/**
* This function handles submit button of probation form and adds the data to the table
*/
var probationAction = {
submit: function() {
$.get(base_url + "staff/probation/show-form", function (data) {
$('.new-tab-wrap').find('.active').removeClass('active')
$('#myTabContent').find('.show.active').removeClass('show active')
$('#new-probation-tab').parent('li').show()
$('#new-probation-tab').text('Probation')
$('#new-probation-tab').addClass('active')
$('#new-probation').addClass('show active')
$("#probation_section").empty();
$("#probation_section").append(data);
$('#probation-form').hide();
// initDatepicker();
});
}
}