423 lines
13 KiB
JavaScript
423 lines
13 KiB
JavaScript
/*
|
|
var selected = {};
|
|
var inputs = {};
|
|
|
|
function formCatalogFilter(props)
|
|
{
|
|
console.log("props???");
|
|
console.log(props);
|
|
selected = props;
|
|
$(".filter_header .tabs .tab").on("click", function()
|
|
{
|
|
$(".filter_header .tabs .tab").removeClass("active");
|
|
$(this).addClass("active");
|
|
});
|
|
}
|
|
|
|
function updateCounter(parameters)
|
|
{
|
|
console.log("updateCounter", parameters);
|
|
|
|
$("#catalog_filter_spinner").show();
|
|
$("#catalog_filter_search_button_counter").hide();
|
|
|
|
var params = {};
|
|
for(let i in parameters)
|
|
{
|
|
if(parameters[i] !== undefined) { params[i] = parameters[i]; }
|
|
}
|
|
|
|
$.get("/api/catalog/count/", params, function(response)
|
|
{
|
|
$("#catalog_filter_spinner").hide();
|
|
$("#catalog_filter_search_button_counter").text("Показать "+response.total+" вариантов").show();
|
|
}, "json");
|
|
}
|
|
|
|
function loadModels(uid)
|
|
{
|
|
$.post("/api/catalog/models/",
|
|
{
|
|
BRAND_UID: uid
|
|
}, function(response)
|
|
{
|
|
console.log("loadModels", selected['MODEL_ID'], selected['MODEL']);
|
|
|
|
$("#small_filter_models").empty();
|
|
$("#filter_models").empty();
|
|
|
|
if(selected['MODEL_ID'] !== undefined)
|
|
{
|
|
$("#small_filter_models").append("<option value=''>Любая</option>");
|
|
$("#filter_models").append("<option value=''>Любая</option>");
|
|
}
|
|
else
|
|
{
|
|
if(selected['MODEL'] !== undefined)
|
|
{
|
|
$("#small_filter_models").append("<option value=''>Любая</option>");
|
|
$("#filter_models").append("<option value=''>Любая</option>");
|
|
}
|
|
else
|
|
{
|
|
$("#small_filter_models").append("<option value='' disabled>Модель</option>");
|
|
$("#filter_models").append("<option value='' disabled>Модель</option>");
|
|
}
|
|
}
|
|
$("#small_filter_models")[0].selectedIndex = 0;
|
|
$("#filter_models")[0].selectedIndex = 0;
|
|
|
|
for(let i in response.models)
|
|
{
|
|
$("#small_filter_models").append("<option value='"+response.models[i]['CODE']+"' data-id='"+response.models[i]['ID']+"' data-uid='"+response.models[i]['UID']+"'>"+response.models[i]['NAME']+"</option>");
|
|
$("#filter_models").append("<option value='"+response.models[i]['CODE']+"' data-id='"+response.models[i]['ID']+"' data-uid='"+response.models[i]['UID']+"'>"+response.models[i]['NAME']+"</option>");
|
|
}
|
|
|
|
if(selected['MODEL'] !== undefined)
|
|
{
|
|
$("#small_filter_models").val(selected['MODEL']);
|
|
$("#filter_models").val(selected['MODEL']);
|
|
|
|
let id = $("#filter_models").find(':selected').data('id');
|
|
selected['MODEL_ID'] = id;
|
|
|
|
updateCounter(selected);
|
|
}
|
|
else
|
|
{
|
|
updateCounter(selected);
|
|
}
|
|
}, "json");
|
|
}
|
|
|
|
$(function()
|
|
{
|
|
$.get("/api/catalog/brands/",
|
|
{
|
|
params: {},
|
|
}, function(response)
|
|
{
|
|
console.log("selected", selected);
|
|
//$("#small_filter_brands").empty();
|
|
//$("#small_filter_brands").find("option").first().text("Любая").attr("disabled", false);
|
|
//$("#filter_brands").find("option").first().text("Любая").attr("disabled", false);
|
|
|
|
for(let i in response.brands)
|
|
{
|
|
$("#small_filter_brands").append("<option value='"+response.brands[i]['CODE']+"' data-id='"+response.brands[i]['ID']+"' data-uid='"+response.brands[i]['UID']+"'>"+response.brands[i]['NAME']+"</option>");
|
|
$("#filter_brands").append("<option value='"+response.brands[i]['CODE']+"' data-id='"+response.brands[i]['ID']+"' data-uid='"+response.brands[i]['UID']+"'>"+response.brands[i]['NAME']+"</option>");
|
|
}
|
|
|
|
if(selected['BRAND'] !== undefined)
|
|
{
|
|
$("#small_filter_brands").find("option").first().text("Любая").attr("disabled", false).val('');
|
|
$("#filter_brands").find("option").first().text("Любая").attr("disabled", false).val('');
|
|
|
|
$("#small_filter_brands").val(selected['BRAND']);
|
|
$("#filter_brands").val(selected['BRAND']);
|
|
|
|
let uid = $("#filter_brands").find(':selected').data('uid');
|
|
let id = $("#filter_brands").find(':selected').data('id');
|
|
selected['BRAND_ID'] = id;
|
|
|
|
loadModels(uid);
|
|
}
|
|
else
|
|
{
|
|
updateCounter(selected);
|
|
}
|
|
}, "json");
|
|
|
|
$("#small_filter_brands").on("change", function(event)
|
|
{
|
|
$("#filter_brands").val(event.target.value);
|
|
selected['MODEL'] = undefined;
|
|
selected['MODEL_ID'] = undefined;
|
|
|
|
if($(this).val() === "")
|
|
{
|
|
$("#small_filter_brands").find("option").first().text("Марка").attr("disabled", "disabled");
|
|
$("#small_filter_models").empty();
|
|
$("#small_filter_models").append("<option value='' disabled selected>Модель</option>");
|
|
$("#filter_brands").find("option").first().text("Марка").attr("disabled", "disabled");
|
|
$("#filter_models").empty();
|
|
$("#filter_models").append("<option value='' disabled selected>Модель</option>");
|
|
}
|
|
else
|
|
{
|
|
let uid = $(this).find(':selected').data('uid');
|
|
let id = $(this).find(':selected').data('id');
|
|
selected['BRAND_ID'] = id;
|
|
|
|
$("#small_filter_brands").find("option").first().text("Любая").attr("disabled", false);
|
|
$("#filter_brands").find("option").first().text("Любая").attr("disabled", false);
|
|
|
|
loadModels(uid);
|
|
}
|
|
});
|
|
|
|
$("#small_filter_models").on("change", function(event)
|
|
{
|
|
if($(this).val() === "")
|
|
{
|
|
$("#filter_models").val();
|
|
|
|
selected['MODEL'] = undefined;
|
|
selected['MODEL_ID'] = undefined;
|
|
|
|
$("#small_filter_models").find("option").first().text("Модель").attr("disabled", "disabled");
|
|
$("#filter_models").find("option").first().text("Модель").attr("disabled", "disabled");
|
|
}
|
|
else
|
|
{
|
|
let id = $(this).find(':selected').data('id');
|
|
$("#filter_models").val(event.target.value);
|
|
|
|
selected['MODEL'] = id;
|
|
selected['MODEL_ID'] = id;
|
|
|
|
$("#small_filter_models").find("option").first().text("Любая").attr("disabled", false);
|
|
$("#filter_models").find("option").first().text("Любая").attr("disabled", false);
|
|
}
|
|
});
|
|
|
|
$("#filter_brands").on("change", function(event)
|
|
{
|
|
console.log("BBBBB", $(this).val());
|
|
if($(this).val() === '')
|
|
{
|
|
selected['BRAND'] = undefined;
|
|
selected['BRAND_ID'] = undefined;
|
|
selected['MODEL'] = undefined;
|
|
selected['MODEL_ID'] = undefined;
|
|
|
|
$("#small_filter_brands").find("option").first().text("Марка").attr("disabled", "disabled");
|
|
$("#small_filter_models").empty();
|
|
$("#small_filter_models").append("<option disabled selected>Модель</option>");
|
|
$("#filter_brands").find("option").first().text("Марка").attr("disabled", "disabled");
|
|
$("#filter_models").empty();
|
|
$("#filter_models").append("<option disabled selected>Модель</option>");
|
|
|
|
updateCounter(selected);
|
|
}
|
|
else
|
|
{
|
|
let id = $(this).find(':selected').data('id');
|
|
let uid = $(this).find(':selected').data('uid');
|
|
selected['BRAND'] = $(this).val();
|
|
selected['BRAND_ID'] = id;
|
|
selected['MODEL'] = undefined;
|
|
selected['MODEL_ID'] = undefined;
|
|
|
|
$("#small_filter_brands").find("option").first().text("Любая").attr("disabled", false);
|
|
$("#filter_brands").find("option").first().text("Любая").attr("disabled", false);
|
|
|
|
loadModels(uid);
|
|
}
|
|
});
|
|
|
|
$("#filter_models").on("change", function(event)
|
|
{
|
|
if($(this).val() === "")
|
|
{
|
|
selected['MODEL'] = undefined;
|
|
selected['MODEL_ID'] = undefined;
|
|
|
|
$("#filter_models").find("option").first().text("Модель").attr("disabled", "disabled");
|
|
}
|
|
else
|
|
{
|
|
let id = $(this).find(':selected').data('id');
|
|
selected['MODEL_ID'] = id;
|
|
|
|
$("#filter_models").find("option").first().text("Любая").attr("disabled", false);
|
|
}
|
|
|
|
updateCounter(selected);
|
|
});
|
|
|
|
$("#catalog_small_form").on("submit", function(e)
|
|
{
|
|
e.preventDefault();
|
|
});
|
|
|
|
$("#catalog_small_find").on("click", function()
|
|
{
|
|
var path = "/catalog";
|
|
|
|
if($("#small_filter_brands").val() !== "")
|
|
{
|
|
path = path+"/"+$("#small_filter_brands").val();
|
|
}
|
|
if($("#small_filter_models").val() !== "")
|
|
{
|
|
path = path+"/"+$("#small_filter_models").val();
|
|
}
|
|
|
|
path = path+"/";
|
|
|
|
window.location.href = path;
|
|
//$("#catalog_small_form").submit();
|
|
});
|
|
|
|
$("#rich_filter_toggle").on("click", function()
|
|
{
|
|
updateCounter(selected);
|
|
$("#filter").addClass("visible");
|
|
$("#catalog_small_filter").addClass("hidden");
|
|
});
|
|
|
|
$.get("/api/catalog/parameters/",
|
|
{
|
|
params: {},
|
|
}, function(response)
|
|
{
|
|
for(let i in response.bodies)
|
|
{
|
|
$("#filter_bodies").append("<option value='"+response.bodies[i]+"'>"+response.bodies[i]+"</option>");
|
|
}
|
|
if(selected['BODY'] !== undefined && selected['BODY'] !== null && selected['BODY'] !== "")
|
|
{
|
|
$("#filter_bodies").val(selected['BODY']);
|
|
$("#filter_bodies").find("option").first().text("Любой").attr("disabled", false);
|
|
}
|
|
|
|
for(let i in response.gears)
|
|
{
|
|
$("#filter_gears").append("<option value='"+response.gears[i]+"'>"+response.gears[i]+"</option>");
|
|
}
|
|
if(selected['GEAR'] !== undefined && selected['GEAR'] !== null && selected['GEAR'] !== "")
|
|
{
|
|
$("#filter_gears").val(selected['GEAR']);
|
|
$("#filter_gears").find("option").first().text("Любая").attr("disabled", false);
|
|
}
|
|
|
|
for(let i in response.engine_fuels)
|
|
{
|
|
$("#filter_engine_fuels").append("<option value='"+response.engine_fuels[i]+"'>"+response.engine_fuels[i]+"</option>");
|
|
}
|
|
if(selected['ENGINE_FUEL'] !== undefined && selected['ENGINE_FUEL'] !== null && selected['ENGINE_FUEL'] !== "")
|
|
{
|
|
$("#filter_engine_fuels").val(selected['ENGINE_FUEL']);
|
|
$("#filter_engine_fuels").find("option").first().text("Любой").attr("disabled", false);
|
|
}
|
|
|
|
for(let i in response.drives)
|
|
{
|
|
$("#filter_drives").append("<option value='"+response.drives[i]+"'>"+response.drives[i]+"</option>");
|
|
}
|
|
if(selected['DRIVE'] !== undefined && selected['DRIVE'] !== null && selected['DRIVE'] !== "")
|
|
{
|
|
$("#filter_drives").val(selected['DRIVE']);
|
|
$("#filter_drives").find("option").first().text("Любой").attr("disabled", false);
|
|
}
|
|
|
|
if(selected['ENGINE_VOLUME_FROM'] !== undefined && selected['ENGINE_VOLUME_FROM'] !== null && selected['ENGINE_VOLUME_FROM'] !== "")
|
|
{
|
|
$("#filter_engine_volume_from").val(selected['ENGINE_VOLUME_FROM']);
|
|
$("#filter_engine_volume_from").find("option").first().text("Любой").attr("disabled", false);
|
|
}
|
|
|
|
if(selected['ENGINE_VOLUME_TO'] !== undefined && selected['ENGINE_VOLUME_TO'] !== null && selected['ENGINE_VOLUME_TO'] !== "")
|
|
{
|
|
$("#filter_engine_volume_to").val(selected['ENGINE_VOLUME_TO']);
|
|
$("#filter_engine_volume_to").find("option").first().text("Любой").attr("disabled", false);
|
|
}
|
|
|
|
console.log("response", response);
|
|
}, "json");
|
|
|
|
$("#filter_bodies").on("change", function()
|
|
{
|
|
if($(this).val() !== "")
|
|
{ $(this).find("option").first().text("Любой").attr("disabled", false); }
|
|
else
|
|
{ $(this).find("option").first().text("Кузов").attr("disabled", "disabled"); }
|
|
|
|
selected['BODY'] = $(this).val();;
|
|
updateCounter(selected);
|
|
});
|
|
|
|
$("#filter_drives").on("change", function()
|
|
{
|
|
if($(this).val() !== "")
|
|
{ $(this).find("option").first().text("Любой").attr("disabled", false); }
|
|
else
|
|
{ $(this).find("option").first().text("Привод").attr("disabled", "disabled"); }
|
|
|
|
selected['DRIVE'] = $(this).val();;
|
|
updateCounter(selected);
|
|
});
|
|
|
|
$("#filter_engine_fuels").on("change", function()
|
|
{
|
|
if($(this).val() !== "")
|
|
{ $(this).find("option").first().text("Любой").attr("disabled", false); }
|
|
else
|
|
{ $(this).find("option").first().text("Двигатель").attr("disabled", "disabled"); }
|
|
|
|
selected['ENGINE_FUEL'] = $(this).val();;
|
|
updateCounter(selected);
|
|
});
|
|
|
|
$("#filter_gears").on("change", function()
|
|
{
|
|
if($(this).val() !== "")
|
|
{ $(this).find("option").first().text("Любая").attr("disabled", false); }
|
|
else
|
|
{ $(this).find("option").first().text("Коробка").attr("disabled", "disabled"); }
|
|
|
|
selected['GEAR'] = $(this).val();;
|
|
updateCounter(selected);
|
|
});
|
|
|
|
$("#catalog_filter_search_button").on("click", function(e)
|
|
{
|
|
e.preventDefault();
|
|
var path = "/catalog";
|
|
|
|
if($("#filter_brands").val() !== undefined && $("#filter_brands").val() !== null && $("#filter_brands").val() !== "")
|
|
{
|
|
path = path+"/"+$("#filter_brands").val();
|
|
}
|
|
if($("#filter_models").val() !== undefined && $("#filter_models").val() !== null && $("#filter_models").val() !== "")
|
|
{
|
|
path = path+"/"+$("#filter_models").val();
|
|
}
|
|
|
|
var p = {};
|
|
for(let i in selected)
|
|
{
|
|
if(i !== "BRAND" && i !== "BRAND_ID" && i !== "MODEL" && i !== "MODEL_ID")
|
|
{
|
|
p[i] = selected[i];
|
|
}
|
|
}
|
|
|
|
path = path+"/?"+$.param(p);
|
|
window.location.href = path;
|
|
});
|
|
|
|
$("#filter_engine_volume_from").on("change", function()
|
|
{
|
|
if($(this).val() !== "")
|
|
{ $(this).find("option").first().text("Любой").attr("disabled", false); }
|
|
else
|
|
{ $(this).find("option").first().text("Объем, от").attr("disabled", "disabled"); }
|
|
|
|
selected['ENGINE_VOLUME_FROM'] = $(this).val();;
|
|
updateCounter(selected);
|
|
});
|
|
|
|
$("#filter_engine_volume_to").on("change", function()
|
|
{
|
|
if($(this).val() !== "")
|
|
{ $(this).find("option").first().text("Любой").attr("disabled", false); }
|
|
else
|
|
{ $(this).find("option").first().text("Объем, до").attr("disabled", "disabled"); }
|
|
|
|
selected['ENGINE_VOLUME_TO'] = $(this).val();;
|
|
updateCounter(selected);
|
|
});
|
|
});
|
|
*/ |