jQuery(document).ready(function () {
jQuery(function () {
'use strict'
jQuery('[data-toggle="offcanvas"]').on('click', function () {
jQuery('.offcanvas-collapse').toggleClass('open')
})
});
jQuery('.signout').on('click', function(e) { //use on if jQuery 1.7+
e.preventDefault();
jQuery.post( window.location.href, { logout: "T" })
.then(function (data, status, headers, config) {
if (data) {
window.location.href = data;
}
});
});
jQuery( ".btn-toggle" ).click(function() {
if(jQuery(this).hasClass("active")) {
jQuery('.inactive-technican-group').collapse('hide');
jQuery('.active-technican-group').collapse('show');
} else {
jQuery('.inactive-technican-group').collapse('show');
jQuery('.active-technican-group').collapse('hide');
}
});
jQuery('.spinner-border').hide();
jQuery('#activetechform').on('submit', function(e) { //use on if jQuery 1.7+
e.preventDefault(); //prevent form from submitting
jQuery(this).find('.update-tech-submit').attr("disabled", true);
jQuery(this).find('.spinner-border').fadeIn();
var phone = jQuery(this).find(".activetechform-phone").val();
var email = jQuery(this).find(".activetechform-email").val();
var firstname = jQuery(this).find(".activetechform-firstname").val();
var lastname = jQuery(this).find(".activetechform-lastname").val();
var techstatus = jQuery(this).find("#activetechform-status").val();
var techid = jQuery(this).find(".activetechform-techid").val();
jQuery.post(window.location.href, {'postType': 'updatetech', 'techid' : techid, 'phone': phone, 'email': email, 'firstname' : firstname, 'lastname' : lastname, 'status': techstatus}, null, "json")
.then(function (data, status, headers, config) {
if (data) {
jQuery('.success-alert-top .alert').html('Successfully updated');
jQuery('.success-alert-top').fadeIn();
setTimeout(function(){
location.reload();
}, 2000);
}
});
});
jQuery('#inactivetechform').on('submit', function(e) { //use on if jQuery 1.7+
e.preventDefault(); //prevent form from submitting
jQuery(this).find('.update-tech-submit').attr("disabled", true);
jQuery(this).find('.spinner-border').fadeIn();
var phone = jQuery(this).find(".inactivetechform-phone").val();
var email = jQuery(this).find(".inactivetechform-email").val();
var firstname = jQuery(this).find(".inactivetechform-firstname").val();
var lastname = jQuery(this).find(".inactivetechform-lastname").val();
var techstatus = jQuery(this).find(".form-control").val();
var techid = jQuery(this).find(".inactivetechform-techid").val();
jQuery.post(window.location.href, {'postType': 'updatetech', 'techid' : techid, 'phone': phone, 'email': email, 'firstname' : firstname, 'lastname' : lastname, 'status': techstatus}, null, "json")
.then(function (data, status, headers, config) {
if (data) {
jQuery('.success-alert-top .alert').html('Successfully updated');
jQuery('.success-alert-top').fadeIn();
setTimeout(function(){
location.reload();
}, 2000);
}
});
});
jQuery('#addnewtechform').on('submit', function(e) { //use on if jQuery 1.7+
e.preventDefault(); //prevent form from submitting
jQuery(this).find('.addnewtechform-submit').attr("disabled", true);
jQuery(this).find('.spinner-border').fadeIn();
var phone = jQuery(this).find(".addnewtechform-phone").val();
var email = jQuery(this).find(".addnewtechform-email").val();
var firstname = jQuery(this).find(".addnewtechform-firstname").val();
var lastname = jQuery(this).find(".addnewtechform-lastname").val();
jQuery.post(window.location.href, {'postType': 'createtech', 'phone': phone, 'email': email, 'firstname' : firstname, 'lastname' : lastname}, null, "json")
.then(function (data, status, headers, config) {
if (data == 'success') {
jQuery('.success-alert-top .alert').html('New tech successfully created!');
jQuery('.success-alert-top').fadeIn();
setTimeout(function(){
location.reload();
}, 2000);
} else {
jQuery('.danger-alert-top .alert').html(data);
jQuery('.danger-alert-top').fadeIn();
setTimeout(function(){
location.reload();
}, 2000);
jQuery('#addnewtechform').find('.spinner-border').fadeOut();
jQuery('#addnewtechform').find('.addnewtechform-submit').attr("disabled", false);
}
});
});
});