// Data table
//*****************************************************************************
$(document).ready(function() {
$("form").attr('autocomplete', 'off');
$(document).on('click', '.add_click', function(e) {
var value="formadd"; $('#current_form_status_add').val(value);
var value2=$('#formstatus').val(); $('#current_form_status').val(value2);
$('.field8_class').css('display','none');
$('.field21_class').css('display','none');
$('.reset-field').val(''); $('.submit_button_new').show();
$('.submit_button').html('Save');
$('.changelabel').html('Add');
});
$(document).on('click', '.edit_model', function(e) {
var value="formedit";
$('#current_form_status_add').val(value);
var value2=$('#formstatus').val();
$('#current_form_status').val(value2);
$('.submit_button').html('Update');
$('.changelabel').html('Update'); $('.submit_button_new').hide();
});
});
$('#panel-modal').modal({
backdrop: 'static',
keyboard: false,
show: false
});
// add function @start
//*****************************************************************************
$(document).on('submit', '#form_add', function(e) {
$('.submit_button').attr('disabled', true);
var form_add = $('#current_form_status_add').val();
var form_status = $('#current_form_status').val();
var edit_id = $('#popup_editid').val();
var form = $(this);
var formdata = false;
if (window.FormData) {
formdata = new FormData(form[0]);
}
var formAction = form.attr('action');
if(form_add=="formadd")
{
$.ajax({
type: 'POST',
url: 'security/common_add.php?dragan_plugin_status_add='+form_status,
cache: false,
data: formdata ? formdata : form.serialize(),
contentType: false,
processData: false,
success: function(res) {
//alert(res);
if($.trim(res)=="yes") {
$('#summernote').summernote('reset');
$('#form_add')[0].reset();
$('.submit_button').attr('disabled', false);
$('#common-message-box').modal('show');
$('.commonmessagebox').html(" Created Successfully ");
}
else if($.trim(res)=="aboutus") {
$('.submit_button').attr('disabled', false);
$('#common-message-box').modal('show');
$('.commonmessagebox').html(" Created Successfully ");
}
else
{
var row = res;
$('.submit_button').attr('disabled', false);
$('#common-message-box').modal('show');
$('.commonmessagebox').html(" Added Successfully ");
$('#form_add')[0].reset();
$('#panel-model').modal('hide');
$('#example').DataTable().row.add($(row));
$('#example').DataTable().order([0, 'desc']).draw();
}
},
error: function(jqXHR, exception) {
$('#prefixaddmodal').modal('hide');
$('#common-message-box').modal('show');
if (jqXHR.status === 0) {
$(".commonmessagebox").html("Internet Not connected - Please Verify Network !");
} else if (jqXHR.status == 404) {
$(".commonmessagebox").html("Requested page not found. [404] !");
} else if (jqXHR.status == 500) {
$(".commonmessagebox").html("Internal Server Error [500] !");
} else if (exception === 'parsererror') {
$(".commonmessagebox").html("Requested JSON parse failed !");
} else if (exception === 'timeout') {
$(".commonmessagebox").html("Time out error !");
} else if (exception === 'abort') {
$(".commonmessagebox").html("Ajax request aborted !");
} else {
$(".commonmessagebox").html("Uncaught Error" + jqXHR.responseText + "");
}
}
});
e.preventDefault();
}
else if(form_add=="formedit")
{
$.ajax({
type: 'POST',
url: 'security/common_edit.php?dragan_plugin_status_add='+form_status,
cache: false,
data: formdata ? formdata : form.serialize(),
contentType: false,
processData: false,
success: function(res) {
//alert(res);
if($.trim(res)=="yes")
{
$('.submit_button').attr('disabled', false);
$('#common-message-box').modal('show');
$('.commonmessagebox').html(" Updated Successfully ");
}
else if($.trim(res)=="aboutus" || $.trim(res)=="contact" ) {
$('.submit_button').attr('disabled', false);
$('#common-message-box').modal('show');
$('.commonmessagebox').html(" Updated Successfully ");
}
else
{
var row = res;
$('.submit_button').attr('disabled', false);
$('#common-message-box').modal('show');
$('.commonmessagebox').html(" Updated Successfully ");
$('#panel-model').modal('hide');
$('#example').DataTable().row($("#row"+edit_id)).remove();
$('#example').DataTable().row.add($(row));
$('#example').DataTable().order([0, 'desc']).draw(false);
}
},
error: function(jqXHR, exception) {
$('#prefixaddmodal').modal('hide');
$('#common-message-box').modal('show');
if (jqXHR.status === 0) {
$(".commonmessagebox").html("Internet Not connected - Please Verify Network !");
} else if (jqXHR.status == 404) {
$(".commonmessagebox").html("Requested page not found. [404] !");
} else if (jqXHR.status == 500) {
$(".commonmessagebox").html("Internal Server Error [500] !");
} else if (exception === 'parsererror') {
$(".commonmessagebox").html("Requested JSON parse failed !");
} else if (exception === 'timeout') {
$(".commonmessagebox").html("Time out error !");
} else if (exception === 'abort') {
$(".commonmessagebox").html("Ajax request aborted !");
} else {
$(".commonmessagebox").html("Uncaught Error" + jqXHR.responseText + "");
}
}
});
e.preventDefault();
}
});
$(document).on('submit', '#form_delete', function(e) {
var form_delete = $('#current_form_status_delete').val();
var form = $(this);
var formdata = false;
if (window.FormData) {
formdata = new FormData(form[0]);
}
var formAction = form.attr('action');
//table primary id
var delete_id = $('#popup_delete_id').val();
$.ajax({
type: 'POST',
url: 'security/common_delete.php?dragan_plugin_status_delete='+form_delete,
cache: false,
data: formdata ? formdata : form.serialize(),
contentType: false,
processData: false,
success: function(res) {
var row = res;
if($.trim(res)=="yes") {
$('#common-message-box').modal('show');
$('.commonmessagebox').html(" Delete Successfully ");
$('#delete_popup').modal('hide');
$('#example').DataTable().row($("#row" + delete_id)).remove();
$('#example').DataTable().order([0, 'desc']).draw(false);
}
else if($.trim(res)=="yess") {
$('#common-message-box').modal('show');
$('.commonmessagebox').html(" Updated Successfully. ");
$('#delete_popup').modal('hide');
$('#example').DataTable().row($("#row" + delete_id)).remove();
$('#example').DataTable().order([0, 'desc']).draw(false);
}
else
{
$('#common-message-box').modal('show');
$('.commonmessagebox').html(" Delete Successfully ");
$('#delete_popup').modal('hide');
$('#example').DataTable().row($("#row" + delete_id)).remove();
$('#example').DataTable().row.add($(row));
$('#example').DataTable().order([0, 'desc']).draw(false);
}
},
error: function(jqXHR, exception) {
$('#common-message-box').modal('show');
if (jqXHR.status === 0) {
$(".commonmessagebox").html("Internet Not connected - Please Verify Network !");
} else if (jqXHR.status == 404) {
$(".commonmessagebox").html("Requested page not found. [404] !");
} else if (jqXHR.status == 500) {
$(".commonmessagebox").html("Internal Server Error [500] !");
} else if (exception === 'parsererror') {
$(".commonmessagebox").html("Requested JSON parse failed !");
} else if (exception === 'timeout') {
$(".commonmessagebox").html("Time out error !");
} else if (exception === 'abort') {
$(".commonmessagebox").html("Ajax request aborted !");
} else {
$(".commonmessagebox").html("Uncaught Error" + jqXHR.responseText + "");
}
}
});
e.preventDefault();
});
$(document).on('submit', '#form_undo_delete', function(e) {
var form_delete = $('#current_form_status_undo_delete').val();
var form = $(this);
var formdata = false;
if (window.FormData) {
formdata = new FormData(form[0]);
}
var formAction = form.attr('action');
//table primary id
var delete_id = $('#popup_undo_delete_id').val();
$.ajax({
type: 'POST',
url: 'security/common_delete.php?dragan_plugin_status_delete='+form_delete,
cache: false,
data: formdata ? formdata : form.serialize(),
contentType: false,
processData: false,
success: function(res) {
var row = res;
$('#example').DataTable().row($("#row" + delete_id)).remove();
$('#example').DataTable().row.add($(row));
$('#example').DataTable().order([0, 'desc']).draw(false);
$('#delete_undo_popup').modal('hide');
$('#common-message-box').modal('show');
$('.commonmessagebox').html("Undo Delete Successfully ");
},
error: function(jqXHR, exception) {
$('#prefixaddmodal').modal('hide');
$('#Common_messagebox').modal('show');
if (jqXHR.status === 0) {
$(".commonmessagebox").html("Internet Not connected - Please Verify Network !");
} else if (jqXHR.status == 404) {
$(".commonmessagebox").html("Requested page not found. [404] !");
} else if (jqXHR.status == 500) {
$(".commonmessagebox").html("Internal Server Error [500] !");
} else if (exception === 'parsererror') {
$(".commonmessagebox").html("Requested JSON parse failed !");
} else if (exception === 'timeout') {
$(".commonmessagebox").html("Time out error !");
} else if (exception === 'abort') {
$(".commonmessagebox").html("Ajax request aborted !");
} else {
$(".commonmessagebox").html("Uncaught Error" + jqXHR.responseText + "");
}
}
});
e.preventDefault();
});
// undo delete function @end
//*****************************************************************************
$('.validation').on( 'change', function() {
myfile = $( this ).val();
var ext = myfile.split('.').pop();
if(ext=="pdf" || ext=="doc" || ext=="docx" || ext=="ppt" || ext=="txt")
{
if(this.files[0].size < (1024 * 1024 * 2))
{
$('.submit_button').attr('disabled', false);
$('#error_msg').html('');
}
else
{
$('.submit_button').attr('disabled', true);
$('#error_msg').html("The file uploaded is larger than 2 MB");
}
}
else
{
$('.submit_button').attr('disabled', true);
$('#error_msg').html(" Upload only doc/docx, text, pdf and ppt formats only");
}
});