$(document).ready(function(){
// initialize datepicker
var initDatepicker = function() {
$('.datepicker').datepicker({
todayHighlight: true,
autoclose: true,
format: 'yyyy-mm-dd',
});
}
/**
* This function handles button click to open payment acknowledgement 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);
});
}
});
/**
* This function handles submit button of invite staff form
*/
$(document).on('click', '#invite_staff_form_submit', function() {
$.post($("#staff_invite_form").attr('action'), $("#staff_invite_form").serialize(), function(data) {
switch(data.status){
case "success":
var msg = render_invite(data.invite);
$("#invite_staff_section").html(msg);
break;
case "fail":
break;
}
}, 'json');
return false;
});
/**
* This function shows the confirmation box whether to accept the staff's invitation or not
*/
var accept = function(){
$.confirm({
title: 'You have been invited to join a session. Do you want to accept the invitation?',
columnClass: 'col-md-6 col-md-offset-2',
content: '',
buttons: {
cancel: {
btnClass: 'btn btn-danger mr-3',
},
ok: {
text: "Ok",
btnClass: 'btn btn-success',
keys: ['enter'],
action: function () {
$.post(base_url + "staff/invite/accept", function (data) {
if (data.status.localeCompare("success") == 0) {
//TODO: Start video
}
}, 'json');
}
}
}
})
}
})
/**
* This function returns the sentence depending on the staff invitation's status
* @param {object} invite - Object containing basic information about invitee staff
*/
var render_invite = function(invite){
console.log(invite.status);
switch(invite.status){
case "invited":
return "waiting for the response of "+invite.fname +" " +invite.lname + "(" + invite.title + ")" ;
break;
case "active":
return "Your invitation has been accpeted by "+invite.fname +" " +invite.lname + "(" + invite.title + ")" ;
break;
case "inactive":
return "Your invitation has been rejected by"+invite.fname +" " +invite.lname + "(" + invite.title + ")";
break;
case "defer":
return "Waiting for the response for your invitation by "+invite.fname +" " +invite.lname + "(" + invite.title + ")";
break;
}
}
/**
* This function shows the invitation list section on staff's dashboard if there are any staff's invitations
*/
var getInvitations = function(){
// return;
//alert('invitation pull');
$.get(base_url + "staff/get-invitations", function(data) {
$("#list_invitation").empty()
$("#list_invitation").append(data);
});
}
// to be deleted
var conference_numbers;
var getCallers = function(){
// return;
//alert('invitation pull');
$.get(base_url + "staff/get-callers", function(data) {
$("#list_callers").empty()
// $("#list_callers").append(data);
conference_numbers = data;
});
}