// JS Librairies for product /* * * @needs : array_intersect (jquery.custom.js) */ function getSlave(slave_id) { for (var slave in product.slaves) { if (product.slaves[slave].id==slave_id) return product.slaves[slave]; } return null; } /* * * @param {type} attributeGroups([{ group : x, attribute : x }],[{ group : y, attribute : y }]); * @returns {Boolean} */ function findSlave(attributeGroups) { var slavesFound=[]; for (var groups in attributeGroups) { slaves=findGroupAttribute(attributeGroups[groups]); if (slaves.length==0) return false; if (slavesFound.length>1) { slaves=$.array_intersect(slavesFound,slaves); if (slaves.length==0) return false; } else slavesFound=slaves; } return slaves[0]; } /* * * @param {type} attributeGroupToFind({ group : 1, attribute : 2 } ); * @returns {Array} */ function findGroupAttribute(attributeGroupToFind) { var slavesFound=[]; for (var slave in product.slaves) { for (var group in product.slaves[slave].groups) { if (product.slaves[slave].groups[group].attribute.id==attributeGroupToFind.attribute && product.slaves[slave].groups[group].id==attributeGroupToFind.group ) { slavesFound.push(product.slaves[slave].id); } } } return slavesFound; } /* * @param {type} attributeGroupToFind({ group : couleur, attribute : rouge } ); * @returns {Array} */ function findGroupAttributeByValues(attributeGroupToFind) { } /* version n attributes by group function findGroupAttribute(attributeGroupToFind) { var slavesFound=[]; for (var slave in product.slaves) { for (var group in product.slaves[slave].groups) { for (var attribut in product.slaves[slave].groups[group].attributes) { if (product.slaves[slave].groups[group].attributes[attribut].id==attributeGroupToFind.attribute && product.slaves[slave].groups[group].id==attributeGroupToFind.group ) { slavesFound.push(product.slaves[slave].id); } } } } return slavesFound; } */ function findSlaveByUrl(url) { for (var slave in product.slaves) { if (product.slaves[slave].url==url) return product.slaves[slave]; } return null; } function SetSlaveRequestedByUrl() { if (slave_url=document.location.hash.substring(1)) { if (slave_request=findSlaveByUrl(slave_url)) { SlaveToHtml(slave_request); SelectAttributesFromGroups(slave_request.groups); } } } /* * group : { id:"4", type:"radio", attribute: { id:"15", ...} } */ function SelectAttributesFromGroups(groups) { for (var group_to_find in groups) { group=groups[group_to_find]; if (group.type=='radio') { $(".radio_group[id="+group.attribute.id+"][name="+group.id+"]").attr('checked',true); } } }