aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/main/webapp/WEB-INF/app/views/bulk_deletion/index.html.erb
blob: 29d2118ae521c6b3e268f862c17327354631175e (plain)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<h1 class="marginbottom10"><%= message('bulk_deletion.page') -%></h1>

<ul class="tabs">
<% @tabs.each do |tab| %>
  <li>
    <a href="<%= url_for :action => 'index', :resource_type => tab %>" <%= "class='selected'" if @selected_tab==tab -%> id="tab-<%= u tab -%>"><%= message('qualifiers.' + tab) -%></a>
  </li>
<% end %>
  <li>
    <a href="<%= url_for :action => 'ghosts' %>" id="tab-ghosts"><%= message('bulk_deletion.ghosts') -%></a>
  </li>
</ul>

<div class="tabs-panel marginbottom10">

<%
  found_resources_count = @resources.size
  found_resources_ids = @resources.map {|r| r.id.to_s}.join(',')
  page_size = (params[:page_size] && params[:page_size].to_i) || 20
%>

  <% form_tag( {:action => 'index'}, :method => :get ) do %>
    <%= message('bulk_deletion.resource_name_filter_by_name') -%> <input type="text" id="resource_filter" name="name_filter" size="40px" value="<%= h params[:name_filter] -%>"/>
    <input type="hidden" name="resource_type" value="<%= @selected_tab -%>"/>
    <%= submit_tag message('bulk_deletion.filter'), :id => 'filter_resources' %>
  <% end %>

  <% if @resources.empty? %>
    <br/>
    <%= message('no_results') -%>
  <% else %>

    <% form_remote_tag( :url => {:action => 'delete_resources'}, :loading => "window.location='#{url_for :action => 'pending_deletions', :resource_type => @selected_tab}';") do %>

    <table class="data" id="resources-to-delete">
      <tfoot>
        <tr>
          <td colspan="2"><%= paginate @resources, {:page_size => page_size} %></td>
        </tr>
        <tr>
          <td colspan="2">
            <input id="delete_resources" class="action red-button" type="submit" value="<%= message('delete') -%>" onclick="return checkBeforeDeleting();" name="commit">
          </td>
        </tr>
      </tfoot>
      <thead>
        <tr>
          <th><input id="r-all" type="checkbox" onclick="selectOrDeselect()"></th>
          <th>
            <span>&laquo; <%= message('bulk_deletion.select_all') -%></span>
            <% if found_resources_count - @resources.size > 0 %>
              <a id="select_all_action" style="padding-left: 10px; font-weight: normal; display: none"
                 href="#" onclick="handleSelectAllAction(); return false;"><%= message('bulk_deletion.select_all_x_resources', :params => found_resources_count) -%></a>
              <input type="hidden" id="all_resources" name="all_resources" value=""/>
            <% end %>
          </th>
          <th></th>
        </tr>
      </thead>
      <tbody>
      <% @resources.each_with_index do |resource, index| %>
        <tr class="<%= cycle 'even', 'odd' -%>">
          <td class="thin">
            <input id="r-<%= index -%>" type="checkbox" value="<%= resource.id -%>" name="resources[]">
          </td>
          <td>
            <%= h resource.name -%>
          </td>
          <td>
            <span class="small gray"><%= h resource.key -%></span></td>
          </td>
        </tr>
      <% end %>
      </tbody>
    </table>

    <% end %>

    <script>
      function checkBeforeDeleting() {
        var resource_selected = false;
        $$("#resources-to-delete input[type='checkbox']").each(function(input) {
          if (input.checked) resource_selected =  true;
        });
        if (!resource_selected) {
          alert("<%= message('bulk_deletion.please_select_at_least_one_resource') -%>");
          return false;
        }

        if (!confirm("<%= message('bulk_deletion.sure_to_delete_the_resources') -%>")) {
          return false;
        }

        return true;
      }

      function selectOrDeselect() {
        var status = $('r-all').checked;
        $$('tbody input').each(function(input) {
          input.checked = status;
        });
        <% if found_resources_count - @resources.size > 0 %>
        selectNotAllResources();
        if (status) {
          $('select_all_action').show();
        } else {
          $('select_all_action').hide();
        }
        <% end %>
      }

      function handleSelectAllAction() {
        if ($('all_resources').value=='') {
          selectAllResources();
        } else {
          $('r-all').checked = false;
          selectOrDeselect();
        }
      }

      function selectAllResources() {
        $('all_resources').value = '<%= found_resources_ids -%>';
        $('select_all_action').innerHTML = '<%= message('bulk_deletion.clear_selection', :params => found_resources_count) -%>';
      }

      function selectNotAllResources() {
        $('all_resources').value = '';
        $('select_all_action').innerHTML = '<%= message('bulk_deletion.select_all_x_resources', :params => found_resources_count) -%>';
      }
    </script>

  <% end %>

</div>