var Rayon = { /* Paramètre par défaut */ ajaxurl: "10-10_Ajaxrecherche.asp", // Servlet executée ajax current_request: null, // Requete en cours numPage: 1, // Numero de la page ttPage: 1, // Nombre de page totale rows: "", // Nombre de réponse par page sortField: "", // Champs de trie des produits sort: "", // Ordre de trie des produits filter: [], // Tableau des filtre utilisateur search: "", // Mot moteur de recherche divPagination: null, // Zone de pagination divFacettes: null, // Zone de facettes divProduits: null, // Zone des produits pathImg: "/Kiabi-data/000-COMMUN/", // Path des images de facettes load: function(options){ $.extend(this, options); this.Facette.events(); this.Page.events(); }, // Action sur la page action: function (param, value) { switch (param) { case "page": var newPage = parseInt(value, 10); if ((newPage < 1 || newPage > this.ttPage) && newPage != -1) return; this.numPage = newPage; break; case "sort": if(this.numPage != -1) this.numPage = 1; var tabValues = value.split(":"); this.sortField = tabValues[0]; this.sort = (tabValues[1] != undefined) ? tabValues[1] : ""; break; case "rows": this.numPage = 1; this.rows = value; break; case "filter": if(this.numPage != -1) this.numPage = 1; this.getFilter(value); break; case "remove": if(this.numPage != -1) this.numPage = 1; this.removeFilter(value); break; default: // Si action inconnu alors rien return; } Rayon.maj(); }, maj: function () { var params = { Recherche: this.search, NbArticle: this.rows, Page: this.numPage, sortField: this.sortField, sort: this.sort, RayonID: 0, FamilleID: 0, MatiereID: 0, Filtrage_TailleID: 0, Filtrage_CouleurID: 0, TranchePrixID: 0 }; $.extend(params, this.filter); if (this.current_request != null && this.current_request.readyState != 0) { this.current_request.abort(); } this.current_request = $.ajax({ url: this.ajaxurl, data: params, dataType: "xml", error: this.error, success: this.display }); }, error: function (e) { alert(e + "Une erreur technique est survenue"); }, display: function (data) { var xml = $(data.documentElement); var content = xml.find("content").text(); var facet = xml.find("facet"); if(content=="error"){ alert("Une erreur est survenue, veuillez réessayer ultérieurement"); }else{ $(Rayon.divProduits).html(content); Rayon.Facette.display(facet); Rayon.Page.events(); loadAchatExpress(); } }, // Filtre par facettes getFilter: function (link) { var id = $(link).attr("rel"); var name = $(link).parents("ul").attr("rel") || $(link).parents(".detail").attr("rel"); this.filter[name] = id; }, removeFilter: function(link) { var name = $(link).parents(".detail").attr("rel"); this.filter[name] = undefined; var idFacetRayon = Rayon.Facette.data.rayonFacet.id; var idFacetFamille = Rayon.Facette.data.familleFacet.id; var idFacetSsFamille = Rayon.Facette.data.sousFamilleFacet.id; var idFacetTaille = Rayon.Facette.data.tailleFacet.id; if (idFacetRayon == name) { this.filter[idFacetFamille] = undefined; this.filter[idFacetSsFamille] = undefined; this.filter[idFacetTaille] = undefined; } else if (idFacetFamille == name) { this.filter[idFacetSsFamille] = undefined; } } }; Rayon.Facette = { data: { rayonFacet:{id:"RayonID",label:"PAR RAYON",type:"list"}, familleFacet:{id:"FamilleID",label:"PAR CATEGORIE",type:"list"}, sousFamilleFacet:{id:"SousFamilleID",label:"PAR CATEGORIE",type:"list"}, tailleFacet:{id:"Filtrage_TailleID",label:"PAR TAILLE",type:"taille"}, pointureFacet:{id:"PointureID",label:"PAR POINTURE",type:"taille"}, couleurFacet:{id:"Filtrage_CouleurID",label:"PAR COULEUR",type:"couleur"}, tranchePrixFacet:{id:"TranchePrixID",label:"PAR PRIX",type:"list"}, matiereFacet:{id:"MatiereID",label:"PAR MATIERE",type:"list"}, vitrineFacet:{id:"VitrineID",label:"AUTRES CRITERES",type:"list"} }, isRayonSelected: false, // Si un rayon selectionne = true listXml: null, // Affiche les facettes display: function(xml) { this.listXml = xml.find("lst"); var facetRayon = this.listXml.filter("[name=rayonFacet]"); var valuesRayon = facetRayon.find("value"); this.isRayonSelected = (Rayon.filter[this.data.rayonFacet.id] != undefined || valuesRayon.length <= 1); $(Rayon.divFacettes).empty(); $.each(this.listXml, function(index, facet) { Rayon.Facette.add(facet); }); this.events(); }, // Gestionnaire d'evenement faceting events: function(){ var menuFacette = $(Rayon.divFacettes); $("a[rel]", menuFacette).click(function () { Rayon.action("filter", this); return false; }); $("div[rel=TranchePrixID] a.special", menuFacette).click(function(){ Rayon.action("sort", "prixActuel:asc"); return false; }); }, // Ajoute une facettes a afficher add: function(facet){ var name = $(facet).attr("name"); var isVisible = ((name == "familleFacet" && this.isRayonSelected) || (name != "familleFacet" && name != "sousFamilleFacet")); if(isVisible == true){ var idName = Rayon.Facette.data[name].id; var values = $(facet).find("value"); if(values.length > 1 || Rayon.filter[idName] != undefined) { var label = this.data[name].label; var titre = $('
').text(label); var detail = this.value.display(name, values); $(Rayon.divFacettes).append(titre).append(detail); } } }, value : { // Affiche les valeurs display: function(name, values){ var idName = Rayon.Facette.data[name].id; var type = Rayon.Facette.data[name].type; var isFacetSecond = (type == "taille" || name == "vitrineFacet"); var isValuesVisible = ((isFacetSecond && Rayon.Facette.isRayonSelected) || !isFacetSecond); var LibelleRayon; var detail = $('
').attr("rel", idName); var idFacetFamille = Rayon.Facette.data.familleFacet.id; var idFacetSsFamille = Rayon.Facette.data.sousFamilleFacet.id; if( Rayon.filter[idFacetSsFamille] != undefined && idName == idFacetFamille){ detail.attr("rel", idFacetSsFamille); } // Selectionner un rayon avant d'afficher les tailles if (isValuesVisible == false) { if ("FR_FR" =="FR_FR"){LibelleRayon="Sélectionnez d'abord un rayon"} if ("FR_FR" =="ES_ES"){LibelleRayon="Mejorar la búsquedad"} if ("FR_FR" =="IT_IT"){LibelleRayon="Migliora la ricerca"} return detail.text(LibelleRayon); } // Voir du -cher au + cher if(name == "tranchePrixFacet") { detail.append(this.sortPrix()); } // Initialise la liste de valeurs var items = detail; var self = this; if(type == "list") {items = $("