script.js
3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* 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="<option value=\"\">"+emptyOptionName+"</option>"+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_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 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;
}