archiveManagement.html 9.04 KB
Newer Older
Prosper De Laure's avatar
Prosper De Laure committed
1
2
<div data-translate-catalog="recordsManagement/messages">
        <?hinclude recordsManagement/archive/modalArchiveInfo.html ?>
Alexandre Morin's avatar
Alexandre Morin committed
3
    <div class="modal fade bs-example-modal-lg" id="corruptedModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
Prosper De Laure's avatar
Prosper De Laure committed
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
        <div class="modal-dialog modal-lg">
            <div class="modal-content" id="container_corruptedModal">
            </div>
        </div>
    </div>

    <div class="hide">
        <span id="first_text">First</span>
        <span id="previous_text">Previous</span>
        <span id="next_text">Next</span>
        <span id="last_text">Last</span>
        <span id="show_text">Show</span>
        <span id="lengthMenu_text">Show _MENU_ entries</span>
    </div>
</div>

<div data-translate-catalog="recordsManagement/messages">
    <!-- MODALS -->
    <?hinclude recordsManagement/archive/modalModification.html ?>

    <div class="hide">
        <span id="preserved_text">preserved</span>
        <span id="disposable_text">disposable</span>
        <span id="frozen_text">frozen</span>
        <span id="errorEmptyNode">No archives selected.</span>
        <span id="errorWrongNodesSelection">This action is not relevant for the selection.</span>
        <span id="errorWrongNode">This action is not relevant for this archive.</span>
Jerome Boucher's avatar
Jerome Boucher committed
31
        <span id="addedToCollection">Archive added to collection.</span>
32
        <span id="removedFromCollection">Archive removed from collection.</span>
Prosper De Laure's avatar
Prosper De Laure committed
33
34
35
36
37
38
39
40
41
    </div>
</div>

<script>
/* ----------------------------------------------------------------------------------------------------*/
/* -- LIST BUTTON -- */

// view the document
$("#archiveList").on('click', ".viewDocument", function() {
Alexandre Morin's avatar
Alexandre Morin committed
42
    archiveDocumentViewer.load($(this).closest('tr').attr('archiveid'), $(this).closest('tr').attr('resid'));
Prosper De Laure's avatar
Prosper De Laure committed
43
44
45
});

// view the archive description
46
$('#archiveList').on('click', '.viewArchive', function () {
47
48
49
    if ($(this).closest('tr').attr('id') == undefined) {
        return;
    }
Alexandre Morin's avatar
Alexandre Morin committed
50
    archiveInfoModal.load($(this).closest('tr').attr('id'));
Alexandre Morin's avatar
Alexandre Morin committed
51
});
Prosper De Laure's avatar
Prosper De Laure committed
52
53
54
55
56

/* ----------------------------------------------------------------------------------------------------*/
/* -- LIST ACTIONS -- */
$('.multipleActionMenu').on('click', 'li', function() {
    var button = $(this);
Jerome Boucher's avatar
Jerome Boucher committed
57
    var type = button.data('type');
Prosper De Laure's avatar
Prosper De Laure committed
58
59
    var selection = ArchivesAction.getSelectedArchives(type);

60
61
62
    if (selection === false) {
        return;
    }
Jerome Boucher's avatar
Jerome Boucher committed
63
64
65
66
67
68
69
70
71
72
    switch (type) {
        case "checkHash":
            ArchivesAction.checkHash(selection['ids'].join("&archiveIds[]="));
            break;
        default:
            var transaction = false;
            $("#transaction").val() ? transaction = true : transaction = false;

            ModificationModal.loadMultiple(selection.selected, selection.relevant, selection.ids, selection.names,type, transaction);
            break;
Alexandre Morin's avatar
Alexandre Morin committed
73
74
    }
});
Prosper De Laure's avatar
Prosper De Laure committed
75

76
$('#archiveList').on('click', '.actionMenu li', function() {
Prosper De Laure's avatar
Prosper De Laure committed
77
78
79
80
81
82
    var button = $(this);
    var type = button.data('type');
    var tr = button.closest('tr');
    var id = tr.attr('id');
    var name = tr.attr('name');

Jerome Boucher's avatar
Jerome Boucher committed
83
84
85
86
87
88
89
90
91
92
    switch (type) {
        case "checkHash":
            ArchivesAction.checkHash(id);
            break;
        default:
            var transaction = false;
            $("#transaction").val() ? transaction = true : transaction = false;

            ModificationModal.load(id, name, type, transaction);
            break;
Prosper De Laure's avatar
Prosper De Laure committed
93
    }
Alexandre Morin's avatar
Alexandre Morin committed
94
});
Prosper De Laure's avatar
Prosper De Laure committed
95
96

var ArchivesAction = {
97
    actionsPossibility : {
98
99
100
101
102
103
104
105
106
        retentionRule        : ['preserved'],
        accessRule           : ['preserved'],
        freeze               : ['preserved', 'restituable', 'disposable', 'transferable'],
        unfreeze             : ['frozen'],
        flagForDestruction   : ['preserved'],
        cancelDestruction    : ['disposable'],
        checkHash            : ['preserved', 'frozen', 'restituable', 'disposable'],
        requestCommunication : ['preserved', 'frozen'],
        flagForRestitution   : ['preserved'],
Jerome Boucher's avatar
Jerome Boucher committed
107
        flagForTransfer      : ['preserved'],
108
109
        addToCollection      : ['preserved', 'frozen', 'restituable', 'disposable', 'transferable'],
        originatorOrg        : ['preserved']
Prosper De Laure's avatar
Prosper De Laure committed
110
111
112
    },

    getSelectedArchives : function(type) {
113
        var status = this.actionsPossibility[type];
Prosper De Laure's avatar
Prosper De Laure committed
114
115
116
117
118
        var dataSelector = [];
        var selector = [];
        var relevant = null;
        var ids = [];
        var names = [];
119
        var hasNoRightsCount = 0;
120

Prosper De Laure's avatar
Prosper De Laure committed
121
122
123
124
        if (status == '') {
            dataSelector.push('[data-archive-status]');
        } else {
            $.each(status, function (index, value) {
125
                if (type == "flagForDestruction") {
126
                    let additionalSelector = "[data-final-disposition='destruction']";
127
128
129
                    let additionalSelector2 = "[data-noretention='1']";
                    dataSelector.push('[data-archive-status="' + value + '"]'+additionalSelector);
                    dataSelector.push('[data-archive-status="' + value + '"]'+additionalSelector2);
Alexis Ragot's avatar
Alexis Ragot committed
130
131
132
                } else if (type == "flagForRestitution") {
                    let additionalSelector = "[data-restituable='1']";
                    dataSelector.push('[data-archive-status="' + value + '"]'+additionalSelector);
133
134
135
                } else {
                    dataSelector.push('[data-archive-status="' + value + '"]');
                }
Alexis Ragot's avatar
Alexis Ragot committed
136
            });
Prosper De Laure's avatar
Prosper De Laure committed
137
        }
Alexis Ragot's avatar
Alexis Ragot committed
138

Prosper De Laure's avatar
Prosper De Laure committed
139
140
        $.each(dataSelector, function (index, value) {
            selector.push('input' + value + ':checked');
Alexis Ragot's avatar
Alexis Ragot committed
141
        });
Dylan's avatar
Dylan committed
142

Prosper De Laure's avatar
Prosper De Laure committed
143
        relevant = $(selector.join(', '));
Alexis Ragot's avatar
Alexis Ragot committed
144
145
        if(!relevant) {
            relevant = [];
Dylan's avatar
Dylan committed
146
        }
Prosper De Laure's avatar
Prosper De Laure committed
147
148
149
150

        $.each(relevant, function () {
            ids.push($(this).val());
            id = '#'+ $(this).val();
151
152
153
            if ($(id).attr('data-hasRights') == 'false') {
                hasNoRightsCount++;
            }
Prosper De Laure's avatar
Prosper De Laure committed
154
            names.push($(id).attr('name'));
Alexis Ragot's avatar
Alexis Ragot committed
155
        });
Prosper De Laure's avatar
Prosper De Laure committed
156
157
158
159
160

        selectedArchives = {
            selected: $('input[data-archive-status]:checked').length,
            relevant: relevant.length,
            ids: ids,
161
162
            names: names,
            hasNoRightsCount: hasNoRightsCount
Alexis Ragot's avatar
Alexis Ragot committed
163
        };
Prosper De Laure's avatar
Prosper De Laure committed
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185

        if (selectedArchives.selected == 0) {
            gritter.show($('#errorEmptyNode').html(), false);
            return false;
        } else if (selectedArchives.relevant == 0) {
            gritter.show($('#errorWrongNodesSelection').html(), false);
            return false;
        }

        return selectedArchives;
    },

    checkHash : function(archives) {
        $.ajax({
            url: "/recordsManagement/verifyIntegrity?archiveIds[]=" + archives,
            type: "GET",
            dataType: 'html',
            success: function (response) {
                $("#container_corruptedModal").html(response);
                $("#corruptedModal").modal();
            }
        });
Jerome Boucher's avatar
Jerome Boucher committed
186
187
    },

188
    updateCollection: function(archives, isInUserCollection, htmlElement = null, collectionHtmlElement = null) {
Jerome Boucher's avatar
Jerome Boucher committed
189
        var collection = JSON.parse($('#collection').val());
190
191
192
193
194
        if (collection.archiveIds === null) {
            collection.archiveIds = [];
        }

        if (isInUserCollection) {
195
196
197
198
199
200
201
            if (archives.length == 0) {
                collection.archiveIds = [];
            } else {
                // remove archive from collection
                // not supported for chrome < 47, firefox < 43, safari <9, edge < 14 (meaning before december 2015)
                collection.archiveIds = collection.archiveIds.filter(item => !archives.includes(item));
            }
202
203
204
        } else {
            collection.archiveIds.push(archives);
        }
205

Jerome Boucher's avatar
Jerome Boucher committed
206
207
        var data = {};
        data.collection = collection;
208

Jerome Boucher's avatar
Jerome Boucher committed
209
210
211
212
213
214
215
        $.ajax({
            url: "/collection",
            type: "PUT",
            dataType: 'json',
            contentType : 'application/json',
            data: JSON.stringify(data),
            success: function (response) {
216
217
218
219
220
                if (isInUserCollection) {
                    gritter.show($('#removedFromCollection').html(), true);
                } else {
                    gritter.show($('#addedToCollection').html(), true);
                }
221
                $('#collection').val(JSON.stringify(collection));
222
223
224
225
226
227
228

                if (htmlElement == null && collectionHtmlElement == null) {
                    $("#archiveList_table").DataTable().clear().draw();
                    $('#numberResults').text(0);
                } else {
                    htmlElement.classList.toggle('fa-star-o');
                    htmlElement.classList.toggle('fa-star');
229
                    htmlElement.classList.toggle('orange');
230
231
                    collectionHtmlElement.attr('data-isinusercollection', !isInUserCollection);
                }
232
233
234
            },
            error: function (response) {
                return false;
Jerome Boucher's avatar
Jerome Boucher committed
235
236
            }
        });
Prosper De Laure's avatar
Prosper De Laure committed
237
238
239
    }
}

240
241
242
243
244
245
246
247
    $('.collection').on('click', function() {
        var td = $(this.closest('td'));
        var tr = $(this.closest('tr'));
        var archiveId = tr.attr('id');
        //casting string to boolean
        var isInUserCollection = (td.attr('data-isinusercollection') == 'true');
        ArchivesAction.updateCollection(archiveId, isInUserCollection, this, td);
    });
Jerome Boucher's avatar
Jerome Boucher committed
248
</script>