vigiboard / vigiboard / public / js / silence_form.js @ c94dc931
History | View | Annotate | Download (3.51 KB)
1 | d5a41c9b | Vincent QUEMENER | /*
|
---|---|---|---|
2 | * Vigiboard
|
||
3 | *
|
||
4 | c94dc931 | Francois POIROTTE | * Copyright (C) 2009-2020 CS-SI
|
5 | d5a41c9b | Vincent QUEMENER | */
|
6 | |||
7 | // Appelé au chargement de la page
|
||
8 | window.addEvent('domready', function (){ |
||
9 | |||
10 | // Ajout de l'auto-complétion sur le champ 'host'
|
||
11 | host_autocompleter = add_autocompleter( |
||
12 | $('host'), 'host', app_path + '/autocomplete/host'); |
||
13 | |||
14 | // Ajout de l'auto-complétion sur le champ 'service'
|
||
15 | service_autocompleter = add_autocompleter( |
||
16 | $('service'), 'service', app_path + '/autocomplete/service', |
||
17 | {'host': $('host').get('value')}, false); |
||
18 | |||
19 | // On lie l'auto-complétion sur le service à celle concernant l'hôte :
|
||
20 | // lorsque le champ 'host' est modifié, on vide le champ 'service', et on
|
||
21 | // modifie le paramètre 'host' de l'auto-compléteur du service
|
||
22 | host_autocompleter.addEvent("selection", function(element, selected, value, input) { |
||
23 | $('service').set('value',''); |
||
24 | service_autocompleter.options.postData.set('host', value);
|
||
25 | }); |
||
26 | |||
27 | // En fonction du remplissage du champ 'service', on adapte la nature du
|
||
28 | // champ 'states'
|
||
29 | adapt_states_field(); |
||
30 | service_autocompleter.addEvent("selection", function(event) { |
||
31 | adapt_states_field(); |
||
32 | }); |
||
33 | $('service').addEvent("change", function(event) { |
||
34 | adapt_states_field(); |
||
35 | }); |
||
36 | |||
37 | // On appelle la fonction 'submit_form' lorsque l'utilisateur valide le
|
||
38 | // formulaire
|
||
39 | $('silence_form').addEvent("submit", function(event) { |
||
40 | submit_form(); |
||
41 | }); |
||
42 | |||
43 | // On place le focus sur le champ 'host' pour faciliter la saisie
|
||
44 | $('host').setAttribute('tabIndex', 0); |
||
45 | $('host').focus(); |
||
46 | }); |
||
47 | |||
48 | // Fonction ajoutant l'auto-complétion sur un champ du formulaire
|
||
49 | function add_autocompleter(elem, varname, url, postData, forceSelect) { |
||
50 | if (!$defined(forceSelect)) |
||
51 | forceSelect = true;
|
||
52 | var autocompleter = new Autocompleter.Request.VigiloJSON(elem, url, { |
||
53 | 'minLength': 1, // Attendre 1 caractère avant l'envoi de la requête |
||
54 | 'selectMode': 'pick', |
||
55 | 'postVar' : varname,
|
||
56 | 'zIndex' : 2000, // Limite le risque qu'un dialogue ne masque |
||
57 | // l'encadré d'auto-complétion.
|
||
58 | 'overflow': true, // Overflow for more entries |
||
59 | 'postData' : new Hash({'partial': true}).combine(postData), |
||
60 | 'forceSelect' : forceSelect
|
||
61 | }); |
||
62 | elem.store("autocompleter", autocompleter);
|
||
63 | return autocompleter;
|
||
64 | } |
||
65 | |||
66 | // Fonction adaptant le champ "states" du formulaire en fonction de la nature
|
||
67 | // du supitem sur lequel porte la règle de mise en silence
|
||
68 | function adapt_states_field() { |
||
69 | // Si le champ 'service' est vide, on cache les états spécifiques aux
|
||
70 | // services et on affiche les états d'hôtes
|
||
71 | 173d37e2 | Francois POIROTTE | if ($('service').get('value') === '') { |
72 | d5a41c9b | Vincent QUEMENER | $('service_states').hide(); |
73 | $('host_states').show(); |
||
74 | // Si le champ 'service' n'est pas vide, on affiche les états spécifiques
|
||
75 | // aux services et on masque les états d'hôtes
|
||
76 | } else {
|
||
77 | $('service_states').show(); |
||
78 | $('host_states').hide(); |
||
79 | } |
||
80 | |||
81 | } |
||
82 | |||
83 | // Fonction appelée suite à la validation du formulaire
|
||
84 | function submit_form() { |
||
85 | // Traitement des règles portant sur les hôtes
|
||
86 | 173d37e2 | Francois POIROTTE | if ($('service').get('value') === '') { |
87 | d5a41c9b | Vincent QUEMENER | $('states').set('value', $$('#host_states input').get('value')[0]); |
88 | $('host_states').destroy(); |
||
89 | $('service_states').destroy(); |
||
90 | // Traitement des règles portant sur les services
|
||
91 | } else {
|
||
92 | $('states').set('value', $$('#service_states select').get('value')); |
||
93 | $('host_states').destroy(); |
||
94 | $('service_states').destroy(); |
||
95 | } |
||
96 | return true; |
||
97 | } |