_form_delete_files.html.erb 2.08 KB
Newer Older
ira.maier's avatar
ira.maier committed
1
<%=form_with model: @sample do |f| %>
2
  <% if @sample.files.attached? %>
ira.maier's avatar
ira.maier committed
3
4
5
6
    <div style="text-align: left">
    <%= f.check_box :delete_files, :id => "sample_delete_files"%>
    <%= f.label :delete_files, "All", :for => "sample_delete_files"%>
    </div>
7
    <%= f.collection_check_boxes :delete_file, @sample.files, :id, :filename do |b| %>
ira.maier's avatar
ira.maier committed
8
      <div style="text-align: left">
9
10
        <%= b.check_box%>
        <%= link_to b.label, rails_blob_path(b.object, disposition: 'attachment'), {:class=>"download_label", :tooltip=>" Download"}%>
ira.maier's avatar
ira.maier committed
11
      </div>
12
13
    <% end %>

ira.maier's avatar
ira.maier committed
14
    <%= f.submit "Delete Files", data: { confirm: "Are you sure?" }, class: "file_storage_button"%>
ira.maier's avatar
ira.maier committed
15
  <% end %>
16
17
<% end %>

ira.maier's avatar
ira.maier committed
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
<script>
    let selectAllCheckbox = document.querySelector('#sample_delete_files');
    let filenameCheckboxes = document.querySelectorAll('[name="sample[delete_file][]"]');

    function shiftToSelect() {
        let lastChecked;

        function handleCheck(e) {
            // Check if shift key is down and check if checkbox is checked
            let inBetween = false;
            if (e.shiftKey && this.checked) {
                filenameCheckboxes.forEach(checkbox => {
                    if (checkbox === this || checkbox === lastChecked) {
                        inBetween = !inBetween;
                    }

                    if (inBetween) {
                        checkbox.checked = true;
                    }
                });
            }
            lastChecked = this;
        }

        filenameCheckboxes.forEach(checkbox => checkbox.addEventListener('click', handleCheck, false));
    }

    function handleSelectAll(e) {
        if (selectAllCheckbox.checked === true) {
            filenameCheckboxes.forEach(checkbox => {
                checkbox.checked = true;
            })
        } else {
            filenameCheckboxes.forEach(checkbox => {
                checkbox.checked = false;
            })
        }
    }

    if (selectAllCheckbox) {
        selectAllCheckbox.addEventListener('click', handleSelectAll, false);
    }
    if(filenameCheckboxes){
        shiftToSelect();
    }
</script>

65
66
67
68