Bonjour,

encore une fois je suis sur l'application de tickets d'incidents. Et je rencontre un nouveau problème. Je voudrais mettre en place une checkbox qui, lorsque on la clique, il s'affiche les tickets cloturés(qui ne s'affichent pas par défaut)
En gros il existe plusieurs états pour les tickets, dont (cloturés et non cloturés)
J'ai déjà fait une méthode pour n'afficher que les non cloturés comme ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
module IncidentsHelper
  def is_clotured?(incident)
      incident.evenement_type_id == 5
  end
end
Dont evenement_type_id correspond au différents états où 5 vaut cloturé.


J'ai pensé à AJAX mais je ne l'ai jamais utilisé. Il y a aussi observe_field mais qui ne fonctionne plus depuis rails 2 apparement ...

Voici la vue dans la quelle je voudrais implémenter ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<p id="notice"><%= notice %></p>
<h1>Liste des incidents de <%= @user.name %> <%= @user.surname%></h1>
<% if !is_tech?%>
<table>
  <thead>
    <tr>
      <th>Titre</th>
      <th>Contenu</th>
      <th>Utilisateur</th>
      <th>Technicien</th>
      <th>Categorie</th>
      <th>Date de l'évènement</th>
      <th colspan="3"></th>
    </tr>
  </thead>
  <tbody>
 
    <% @user.incidents.each do |user| %>
    <% if !is_clotured?(user) %>
      <tr>
        <td><%= user.title %></td>
        <td><%= user.content %></td>
        <td><%= @user.name %></td>
        <td><%= User.find_by_sql("SELECT `users`.* FROM `users` WHERE `id` = #{user.techuser_id}").collect{ |u| [u.surname, u.name]}.join(" ") %></td>
        <td><%= user.category.name %></td>
        <td><%= user.date_evenement %></td>
 
        <td><%= link_to 'Voir le détail d\'incident', incident_path(user) %></td>
        <td><%= link_to "cloturer", clotured_incident_path(user), method: :put%></td>
 
        <% if is_tech? %>
        <td><%= link_to 'Editer l\'incident', edit_incident_path(user) %></td>
        <td><%= link_to 'Effacer l\'incident', incident_path(user), method: :delete, data: { confirm: 'Êtes vous sûr ?' } %></td>
 
        <% end %>
      </tr>
      <% end %>
    <% end %>
  </tbody>
</table>
<%end%>
<!--#FOR TECH BOTTOM !-->
<% if is_tech?%>
<table>
  <thead>
    <tr>
      <th>Titre</th>
      <th>Contenu</th>
      <th>Date</th>
      <th>Utilisateur</th>
      <th>Technicien</th>
      <th>Categorie</th>
 
      <th colspan="3"></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <% User.find_by_sql("SELECT `incidents`.* FROM `incidents` WHERE `techuser_id` = #{@user.id}").each do |incident|%>
  <td><%= incident.title %></td>
  <td><%= incident.content %></td>
  <td><%= incident.created_at %></td>
  <td><%= User.find_by_sql("SELECT `users`.* FROM `users` WHERE `id` = #{incident.user_id}").collect{|u| [u.name, u.surname]}.join(" ") %></td>
  <td><%= current_user.name %><%= current_user.surname %></td>
  <td><%= User.find_by_sql("SELECT `categories`.* FROM `categories` WHERE `id` = #{incident.category_id}").collect{|u| u.name}.join(" ") %></td>
 
  <td><%= link_to 'Voir le détail d\'incident', incident_path(incident) %></td>
  <td><%= link_to 'Editer l\'incident', edit_incident_path(incident) %></td>
  <td><%= link_to 'Effacer l\'incident', incident_path(incident), method: :delete, data: { confirm: 'Êtes vous sûr ?' } %></td>
 
</tr>
<% end %>
</tbody>
</table>
 
<%= link_to "Tous les incidents", incidents_path %>
<%= link_to 'Editer l\'utilisateur', edit_user_path(@user) %> |
<%= link_to 'Retour à la liste des utilisateurs', users_path %>
<% end %>
Merci !