function show_loader(){
jQuery('.ajax-loader').css("visibility", "visible");
}
function hide_loader(){
jQuery('.ajax-loader').css("visibility", "hidden");
jQuery(".alert").hide();
}
function redirect_to(url)
{
window.location.href = url;
}
function raj_alert(msg,type)
{
hide_loader();
jQuery("."+type+"AjaxMsg").html(msg);
jQuery("."+type+"Ajax").show();
jQuery('html, body').animate({
scrollTop: jQuery("body").offset().top
}, 200);
}
function display_content(content)
{
jQuery("#auto_servies_page").fadeOut(function() {
jQuery(".alert").hide();
jQuery("#auto_servies_div").html(content);
jQuery('html, body').animate({
scrollTop: jQuery("body").offset().top
}, 200);
}).fadeIn(function() {
hide_loader();
jQuery(".raj_alert").hide();
});
}
function fixer_rendez_vous(id_product,url)
{
jQuery.ajax({
type: "GET",
beforeSend: function(){
show_loader();
},
url: url,
data: "add-to-cart="+id_product,
success: function(msg){
document.location=url+"/checkout/";
}
});
}
function submit_quote()
{
data=jQuery("#ct_RequestQuote").serialize();
jQuery.ajax({
type: "POST",
beforeSend: function(){
show_loader();
},
url: my_ajax_url,
data: "action=actions&action_to_do=submit_quote&"+data+"&site_name="+site_name,
success: function(msg){
json=check_valide_request(msg)
if(json!=false)
raj_alert("Votre demande a bien été envoyée ","success") ;
}
});
}
function change_model_selet()
{
jQuery.ajax({
type: "GET",
beforeSend: function(){
show_loader();
},
url: my_ajax_url,
data: "action=actions&action_to_do=get_models_select_json&make_id="+jQuery("#make_masse").val(),
success: function(msg){
hide_loader();
try
{
var json = JSON.parse(msg);
if(!json.hasOwnProperty("Error"))
{
raj_alert("Field 'Frror' doesn't exist in json :"+ content,"error") ;
return false
}
if(json["Error"])
{
raj_alert(json["Messages"],"error") ;
return false;
}
jQuery("#model_masse").html(ejs.render(json.template,json));
}
catch(e)
{
raj_alert(e+"
"+msg,"error") ;
return false;
}
}
});
}
function show_makes()
{
jQuery.ajax({
type: "POST",
beforeSend: function(){
show_loader();
},
url: my_ajax_url,
data: "action=actions&action_to_do=get_makes&plugin_url="+encodeURIComponent(plugin_url)+"&user_id="+user_id+"&my_site_url="+encodeURIComponent(my_site_url),
success: function(msg){
json=check_valide_request(msg)
if(json!=false)
display_content(affect_to_template(json));
}
});
}
function show_contact(slug_car)
{
jQuery.ajax({
type: "POST",
beforeSend: function(){
show_loader();
},
url: my_ajax_url,
data: "action=actions&action_to_do=show_contact&slug_car="+slug_car+"&plugin_url="+encodeURIComponent(plugin_url)+"&user_id="+user_id+"&my_site_url="+encodeURIComponent(my_site_url),
success: function(msg){
json=check_valide_request(msg)
if(json!=false)
display_content(affect_to_template(json));
}
});
}
var is_submit=false;
var current_id=0;
function list_admin(module)
{
//var data="search="+jQuery( "#user-search-input" ).val();
var data=jQuery( "#my_form_list" ).serialize();
jQuery.ajax({
beforeSend: function(){
show_loader();
},
type: "POST",
url: my_ajax_url,
data: "action=actions&action_to_do=get_list&module="+module+"&"+data+"&plugin_url="+encodeURIComponent(plugin_url)+"&user_id="+user_id+"&my_site_url="+encodeURIComponent(my_site_url),
success: function(msg){
display_content(msg);
if(is_submit)
{
if(current_id==0)
raj_alert("New item added",'success');
else
raj_alert("Item edited",'success');
}
is_submit=false;
current_id=0;
}
});
}
function search_by_cat(module,cat_id)
{
//var data="search="+jQuery( "#user-search-input" ).val();
var data=jQuery( "#my_form_list" ).serialize();
jQuery.ajax({
beforeSend: function(){
show_loader();
},
type: "POST",
url: my_ajax_url,
data: "action=actions&action_to_do=get_list&module="+module+"&"+data+"&plugin_url="+encodeURIComponent(plugin_url)+"&user_id="+user_id+"&my_site_url="+encodeURIComponent(my_site_url)+"&cat_id="+cat_id,
success: function(msg){
display_content(msg);
is_submit=false;
current_id=0;
}
});
}
function apply_action(module)
{
act=jQuery("#bulk-action-selector-top").val();
raj_do_action(module,act,0);
}
function raj_do_action(module,act,id)
{
if(id!=0)
{
jQuery('input[name="rows[]"]').attr("checked",false);
jQuery("#raj_row_"+id).attr("checked",true);
}
data="task="+act+"&agr_id="+jQuery("#template_raj").val();
jQuery('input[name="rows[]"').each(function () {
if(this.checked)
{
if(data!="")
data+="&";
data += "rows[]="+jQuery(this).val();
}
});
if(act=="delete")
{
if( confirm( 'Are you sure that you want to delete the selected items?' ) ) {
post_list_actions(module,id,data,act);
}
}
else
post_list_actions(module,id,data,act);
}
function post_list_actions(module,id,data,act)
{
jQuery.ajax({
beforeSend: function(){
show_loader();
},
type: "POST",
url: my_ajax_url,
data: "action=actions&action_to_do=apply_actions&module="+module+"&id="+id+"&plugin_url="+encodeURIComponent(plugin_url)+"&user_id="+user_id+"&my_site_url="+encodeURIComponent(my_site_url)+"&"+data,
success: function(msg){
hide_loader();
if(msg=="done")
{
raj_alert("The action "+act+" applied successfully","success");
setTimeout(function(){ list_admin(module); }, 1000);
}
else
raj_alert(msg,"error");
}
});
}
function submit_admin_form(module)
{
current_id=jQuery("#"+module+"_id" ).val();
var form = jQuery("#"+module+"_add_form" );
var formData = new FormData(form[0]);
is_submit=true;
jQuery.ajax({
beforeSend: function(){
show_loader();
},
type: "POST",
url: my_ajax_url,
data: formData,
contentType: false,
processData: false,
success: function(msg){
hide_loader();
if(msg=="done")
{
if(jQuery("#action_to_do" ).val()=="edit_price")
raj_alert("Les prix sont modifiés",'success');
else
{
if(jQuery("#action_to_do" ).val()=="edit_settings")
raj_alert("Valeurs modifiées",'success');
else
list_admin(module);
}
}
else
raj_alert(msg,'error');
}
});
}
function add_item_admin(module,id)
{
var data=jQuery( "#my_form_list" ).serialize();
jQuery.ajax({
beforeSend: function(){
show_loader();
},
type: "POST",
url: my_ajax_url,
data: "action=actions&action_to_do=add_item&"+data+"&plugin_url="+encodeURIComponent(plugin_url)+"&user_id="+user_id+"&my_site_url="+encodeURIComponent(my_site_url)+"&module="+module+"&id="+id,
success: function(msg){
display_content(msg);
}
});
}
function quick_edit_list(module,id)
{
current_id=id;
var form = jQuery("#quick_form_"+id );
var formData = new FormData(form[0]);
is_submit=true;
jQuery.ajax({
beforeSend: function(){
jQuery(".spinner").css('visibility', 'hidden');
jQuery("#loader_quick_"+id).css('visibility', 'visible');
},
type: "POST",
url: my_ajax_url,
data: formData,
contentType: false,
processData: false,
success: function(msg){
hide_loader();
if(msg=="done")
{
/*jQuery('.quick_edit_tr').hide();
jQuery('.post_tr').show(); */
var data=jQuery( "#my_form_list" ).serialize();
jQuery.ajax({
beforeSend: function(){
//show_loader();
},
type: "POST",
url: my_ajax_url,
data: "action=actions&action_to_do=get_list&module="+module+"&"+data+"&plugin_url="+encodeURIComponent(plugin_url)+"&user_id="+user_id+"&my_site_url="+encodeURIComponent(my_site_url),
success: function(msg){
jQuery("#auto_servies_div").html(msg);
}
});
}
else
{
jQuery("#error_"+id+" .error").html(msg);
jQuery("#error_"+id+"").show();
}
}
});
}
function raj_import_file(module)
{
show_loader();
jQuery(".raj_notice").hide();
var formData = new FormData();
formData.append('file', jQuery('#import_file')[0].files[0]);
formData.append("module", module);
formData.append("action_to_do", "import");
formData.append("action", "functions");
jQuery.ajax({
url: my_ajax_url,
type : 'POST',
data : formData,
processData: false, // tell jQuery not to process the data
contentType: false, // tell jQuery not to set contentType
success : function(data) {
hide_loader();
var tab= data.split("success:");
if(tab.length>1)
{
raj_alert(tab[1],"success");
setTimeout(function(){ list_admin(module); }, 1000);
}
else
{
raj_alert(data,"error");
}
}
});
}
function raj_alert(msg,type)
{
hide_loader();
jQuery(".raj_notice").hide();
jQuery("#"+type+"_raj p").html(msg);
jQuery("#"+type+"_raj").show();
jQuery('html, body').animate({
scrollTop: jQuery("body").offset().top
}, 200);
}
function affect_to_template(json)
{
return ejs.render(json.template,json);
if(!json.hasOwnProperty("template"))
{
raj_alert("json param is missing: template ","error");
return false;
}
var templ=json.template;
tot_chars=templ.length
var content="";
found_mostache=false;
for (var i = 0; i < tot_chars; i++) {
c=templ.charAt(i);
if(c=="{" && i