/** * empty a SELECT field given its name and default option * call example : emptySelectOptions("#MaterielSousCategorieId","Choisir une sous-catégorie") * */ function emptySelectOptions(selectFieldId, defaultOption) { var newOptions = { "" : defaultOption }; //var selectedOption = "Choisir une sous-catégorie"; var select = $(selectFieldId); var options; if(select.prop) { options = select.prop("options"); } else { options = select.attr("options"); } $("option", select).remove(); $.each(newOptions, function(val, text) { options[options.length] = new Option(text, val); }); //select.val(selectedOption); } /** * Ajax request that updates a SELECT options (selectId) according to the selection made in another SELECT (otherSelectId) * For now, works only from Materiels VIEW (otherwise, replace "materiels" below with your view name) * * call example : * updateSelectOptionsFromAnother("#MaterielCategorieId", "#MaterielSurCategorieId", "Categories/getAll", "catégorie") * This would update the options of the SELECT named "MaterielCategorieId" from the selected value of the SELECT named MaterielSurCategorieId * */ function updateSelectOptionsFromAnother(selectId, otherSelectId, requestName, emptyOptionName) { var reg=new RegExp("(materiels).*$","g"); var currentURL = window.location.pathname; var newURL = currentURL.replace(reg, requestName); $.ajax({ async:true, data:$(otherSelectId).serialize(), dataType:"html", success:function (data, textStatus) { if (emptyOptionName == "") $(selectId).val(data); else { data=""+data; $(selectId).html(data); } }, type:"post", url:newURL }); } $(document).ready(function() { //Page index de matériel $('#t_informations').click(function() { $('#informations').toggle('fast'); toogleChevron('#i_informations'); }); $('#t_informations_admin').click(function() { $('#informations_admin').toggle('fast'); toogleChevron('#i_informations_admin'); }); $('#t_suivis').click(function() { $('#suivis').toggle('fast'); toogleChevron('#i_suivis'); }); $('#t_emprunts').click(function() { $('#emprunts').toggle('fast'); toogleChevron('#i_emprunts'); }); $('#t_fichiers').click(function() { $('#fichiers').toggle('fast'); toogleChevron('#i_fichiers'); }); //Page find de matériel $('#t_filter').click(function() { $('#filter').toggle('fast'); toogleChevron('#i_filter'); }); $('#t_result').click(function() { $('#result').toggle('fast'); toogleChevron('#i_result'); }); }); function toogleChevron(element) { if ($(element).hasClass('icon-chevron-down')) { $(element).removeClass('icon-chevron-down'); $(element).addClass('icon-chevron-up'); } else { $(element).removeClass('icon-chevron-up'); $(element).addClass('icon-chevron-down'); } } function emprunt_interne_externe() { $('#interne').toggle(); $('#externe').toggle(); } function display_ldap() { $('#ldap').toggle(); } function selectAll() { for(i = 0; i < document.getElementsByTagName("input").length; i++) document.getElementsByTagName("input")[i].checked = true; } function selectNone() { for(i = 0; i < document.getElementsByTagName("input").length; i++) document.getElementsByTagName("input")[i].checked = false; } function changeAdminEdit() { if (document.getElementById('eotp').disabled) { document.getElementById('eotp').disabled=false; document.getElementById('numero-commande').disabled=false; document.getElementById('code-comptable').disabled=false; document.getElementById('numero-inventaire-organisme').disabled=false; document.getElementById('numero-inventaire-old').disabled=false; document.getElementById('num_labo').disabled=false; } else { document.getElementById('eotp').disabled=true; document.getElementById('numero-commande').disabled=true; document.getElementById('code-comptable').disabled=true; document.getElementById('numero-inventaire-organisme').disabled=true; document.getElementById('numero-inventaire-old').disabled=true; document.getElementById('num_labo').disabled=true; } }