modalModification.html 18.2 KB
Newer Older
Prosper De Laure's avatar
Prosper De Laure committed
1
2
3
4
5
6
7
8
9
10
11
<div class="modal fade" id="modificationModal" data-backdrop="static" data-keyboard="false" tabindex="999"  data-focus-on="input:first" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" data-translate-catalog="recordsManagement/messages">
            <div class="container-fluid">
                <div class="page-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h3><span id="modification_title"></span></h3>
                </div>
            </div>
            <div class="container-fluid">
                <div class="sidebar-offcanvas col-sm-12">
12
                    <?hinclude recordsManagement/archive/archiveModificationForm.html?>
Prosper De Laure's avatar
Prosper De Laure committed
13
14
15
16
                    <div class="panel panel-default" data-translate-context="validationModal" id="modal_multipleSelection">
                        <div class="panel-body">
                            <h4><strong style="color:red"><span id="modal_selected"></span></strong> archives selected.</h4>
                            <h4>The modification will be applied on <strong style="color:red"><span id="modal_relevant"></span></strong> archives.</h4>
Alexandre Morin's avatar
Alexandre Morin committed
17
                            <!--<br/>
Prosper De Laure's avatar
Prosper De Laure committed
18
19
20
21
22
23
24
25
26
27
28
29
30
                            <div class="table-responsive">
                                <table id="archiveTable" class="table table-condensed">
                                    <thead>
                                    <th>Id</th>
                                    <th>Archive name</th>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td></td>
                                            <td></td>
                                        </tr>
                                    </tbody>
                                </table>
Alexandre Morin's avatar
Alexandre Morin committed
31
                            </div>-->
Prosper De Laure's avatar
Prosper De Laure committed
32
33
34
35
36
37
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer" data-translate-catalog="recordsManagement/messages">
                <button class="btn btn-warning" data-dismiss="modal" title="Cancel"><i class="fa fa-times">&nbsp;</i>Cancel</button>
38
                <button id="save" class="btn btn-success" data-archiveIds="" data-dismiss="modal" title="Save"><i class="fa fa-check">&nbsp;</i>OK</button>
Prosper De Laure's avatar
Prosper De Laure committed
39
40
41
42
43
44
45
46
47
48
49
50
            </div>
        </div>
    </div>
</div>

<div style="display:none">
    <span id="mtext_retentionRule">Change disposal rule</span>
    <span id="mtext_accessRule">Edit access rule</span>
    <span id="mtext_flagForDestruction">Flag for destruction</span>
    <span id="mtext_cancelDestruction">Cancel destruction</span>
    <span id="mtext_freeze">Freeze</span>
    <span id="mtext_unfreeze">Unfreeze</span>
51
    <span id="empty_text">The fields with a star are required.</span>
Alexandre Morin's avatar
Alexandre Morin committed
52
    <span id="empty_archivalAgency">No archival agency found</span>
Prosper De Laure's avatar
Prosper De Laure committed
53
54
55
56

    <span id="text_D">day(s)</span>
    <span id="text_M">month(s)</span>
    <span id="text_Y">year(s)</span>
Dylan's avatar
Dylan committed
57
58
    <span id="text_preservation">preservation</span>
    <span id="text_destruction">destruction</span>
Prosper De Laure's avatar
Prosper De Laure committed
59
60
61
62
63
64
65
66
67
68
69
</div>

<style>
.datepicker{z-index:1151 !important;}
</style>

<script>
    $("#accessRuleCode").on('change', function () {
        ModificationModal.loadAccessCode();
    });
    
Dylan's avatar
Dylan committed
70
71
72
73
    $("#retentionRuleCode").on('change', function () {
        ModificationModal.loadRetentionCode();
    });

Alexandre Morin's avatar
Alexandre Morin committed
74
75
76
77
78
79
80
81
    $("#comment").bind('input propertychange', function () {
        if ($("#comment").val() == "") {
            $("#save").prop("disabled",true);
        } else {
            $("#save").prop("disabled",false);
        }
    });
    
Prosper De Laure's avatar
Prosper De Laure committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
    $("#save").on('click', function (e) {
        e.preventDefault();
        ModificationModal.save(); 
    });
    
    ModificationModal = {
        actionsList : {
            accessRule          : '/recordsManagement/archive/accessRule',
            retentionRule       : '/recordsManagement/archive/retentionRule',
            flagForDestruction  : '/recordsManagement/dispose',
            cancelDestruction   : '/recordsManagement/cancelDestruction',
            freeze              : '/recordsManagement/archive/freeze',
            unfreeze            : '/recordsManagement/archive/unfreeze'
        },
        actionsType : {},
        modal : $('#modificationModal'),
        modalType : null,
        dataTable : null,
        load : function(archiveId, archiveName, type) {
            this.modalType = type;

            this.loadTitle();
            
105
106
            $('#selectedArchiveId').css('display', '').find('span').text(archiveId);
            $('#selectedArchiveReference').css('display', '').find('span').text(archiveName);
Prosper De Laure's avatar
Prosper De Laure committed
107
108

            if (type == 'accessRule') {
Dylan's avatar
Dylan committed
109
110
                $('#startDate, #accessCode').css('display', '');
                $('#retentionCode').css('display', 'none');
111
                $('#archivalAgency').css('display', 'none');
Alexandre Morin's avatar
Alexandre Morin committed
112
                this.loadRule(archiveId, archiveName, type);
Prosper De Laure's avatar
Prosper De Laure committed
113
114

            } else if (type == "retentionRule") { 
Dylan's avatar
Dylan committed
115
116
                $('#startDate,#retentionCode').css('display', '');
                $('#accessCode').css('display', 'none');
117
                $('#archivalAgency').css('display', 'none');
Alexandre Morin's avatar
Alexandre Morin committed
118
                this.loadRule(archiveId, archiveName);
Prosper De Laure's avatar
Prosper De Laure committed
119

120
121
122
123
            } else if (type == "flagForTransfer") {
                $('#archivalAgency').css('display', '');
                $('#startDate,#accessCode,#retentionCode').css('display', 'none');
                this.loadArchivalAgency();
Prosper De Laure's avatar
Prosper De Laure committed
124
            } else {
125
                $('#archivalAgency').css('display', 'none');
Alexandre Morin's avatar
Alexandre Morin committed
126
                $('#startDate,#accessCode,#retentionCode').css('display', 'none');
Alexandre Morin's avatar
Alexandre Morin committed
127
                this.modal.modal();
Prosper De Laure's avatar
Prosper De Laure committed
128
129
130
            }
            
            $('#save').data("archiveids", "");
Alexandre Morin's avatar
Alexandre Morin committed
131
            $('#archiveModificationForm').css('display', '');
Prosper De Laure's avatar
Prosper De Laure committed
132
133
134
            $('#modal_multipleSelection').css('display', 'none');
        },

135
136
137
138
139
140
141
142
143
144
145
146
147
148
        loadArchivalAgency : function() {
            $.ajax({
                type     : "GET",
                url      : "/organization/ByRole/archiver",
                dataType : 'json',
                success  : function (response) {
                    var organizations = response;
                    $('#archivalAgencySelect').find('option').remove();
                    $.each(organizations, function (key, value) {
                        $('#archivalAgencySelect').append($('<option>', {
                            value: value.registrationNumber,
                            text: value.displayName
                        }));
                    });
Alexandre Morin's avatar
Alexandre Morin committed
149
150
151
152
153
154
155
156
157

                    var length = $('#archivalAgencySelect').children('option').length;
                    if (length === 0) {
                        $('#archivalAgencySelect').append($('<option>', {
                            value: '',
                            text: $('#empty_archivalAgency').html()
                        }));
                    }

158
159
160
161
162
163
164
165
                    $('#modificationModal').modal();
                },
                error   : function (response) {
                    gritter.show(response.responseJSON.message, response.responseJSON.status, response.responseJSON.errors);
                }
            });
        },

Prosper De Laure's avatar
Prosper De Laure committed
166
167
168
169
170
171
172
173
174
175
176
177
178
179
        loadRule: function(archiveId, archiveName) {
            if (this.modalType ==='accessRule') {
                url = '/recordsManagement/archive/accessRule/' + archiveId;
            } else if (this.modalType === 'retentionRule') {
                url = "/recordsManagement/archive/retentionRule/" + archiveId;
            } else {
                return;
            }

            $.ajax({
                type     : "GET",
                url      : url,
                dataType : 'json',
                success  : function (response) {
180
181
182
183
184
185
186
187
188
                    if (response.status) {
                        if (ModificationModal.modalType === "accessRule") {
                            rule = response.accessRule;
                            if (rule.accessRuleDuration) {
                                rule.accessRuleDurationUnit = rule.accessRuleDuration.substring(rule.accessRuleDuration.length - 1);
                                rule.accessRuleDuration = rule.accessRuleDuration.substring(1, rule.accessRuleDuration.length - 1);
                            }
                        } else {
                            rule = response.retentionRule;
Prosper De Laure's avatar
Prosper De Laure committed
189
190
                        }

191
192
193
                        $.each(rule, function (key, value) {
                            ModificationModal.modal.find("[name='" + key + "']").val(value);
                        });
Prosper De Laure's avatar
Prosper De Laure committed
194

195
196
197
                        if (ModificationModal.modalType === "accessRule") {
                            ModificationModal.loadAccessCode();
                        }
Prosper De Laure's avatar
Prosper De Laure committed
198

199
200
201
                        if (ModificationModal.modalType === "retentionRule") {
                            ModificationModal.loadRetentionCode(rule);
                        }
Dylan's avatar
Dylan committed
202

203
204
205
206
207
208
209
210
211
212
                        // Set datepicker Date
                        dateValue = rule.startDate.split('/');
                        if (dateValue.length == 3) {
                            date = new Date(parseInt(dateValue[2]), parseInt(dateValue[1]) - 1, parseInt(dateValue[0]));
                            $('#startDate').find('input').datepicker('setDate', date);
                        }

                        $('#modificationModal').modal();
                    } else {
                        gritter.show(response.message, response.status);
Prosper De Laure's avatar
Prosper De Laure committed
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
                    }
                },
                error   : function(response) {
                    gritter.show(response.responseJSON.message, response.responseJSON.status, response.responseJSON.errors);
                }
            });
        },

        loadMultiple: function(selected, relevant, ids, names, type) {
            this.modalType = type;

            this.loadTitle();
            $('#selectedArchiveId, #selectedArchiveReference').css('display', 'none');

            if( type === "accessRule") {
228
229
                $('#startDate, #accessCode').css('display', '');
                $('#retentionCode').css('display', 'none');
230
231
                $('#archiveModificationForm').css('display', '');
                $('#archivalAgency').css('display', 'none');
Prosper De Laure's avatar
Prosper De Laure committed
232
233

            } else if ( type === "retentionRule") {
234
235
                $('#startDate,#retentionCode').css('display', '');
                $('#accessCode').css('display', 'none');
236
237
                $('#archiveModificationForm').css('display', '');
                $('#archivalAgency').css('display', 'none');
Prosper De Laure's avatar
Prosper De Laure committed
238

239
240
241
242
            } else if (type == "flagForTransfer") {
                $('#archivalAgency').css('display', '');
                $('#startDate,#accessCode,#retentionCode').css('display', 'none');
                this.loadArchivalAgency();
Prosper De Laure's avatar
Prosper De Laure committed
243
            } else {
244
                $('#archivalAgency').css('display', 'none');
245
                $('#startDate,#accessCode,#retentionCode').css('display', 'none');
246
                this.modal.modal();
Prosper De Laure's avatar
Prosper De Laure committed
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
            }
                
            $('#save').data("archiveids", ids);
            $('#modal_multipleSelection').css('display', '');
            $('#modal_selected').html(selected);
            $('#modal_relevant').html(relevant);

            ModificationModal.loadTable(ids, names);
            
            this.modal.find('input, select').val('');
            this.modal.modal();
        },

        loadTitle: function() {
            $('#modification_title').html($('#mtext_'+this.modalType).html());
        },

        save: function() {
            parameters = ArchiveModification.serialize(this.modalType);
Alexandre Morin's avatar
Alexandre Morin committed
266
267
268
269

            if (!parameters.comment) {
                gritter.show($('#empty_text').html(), false);
                return;
Alexandre Morin's avatar
Alexandre Morin committed
270
            } else if (this.modalType == 'flagForTransfer' && !parameters.archiverOrgRegNumber) {
271
272
                gritter.show($('#empty_text').html(), false);
                return;
Alexandre Morin's avatar
Alexandre Morin committed
273
274
            }

Prosper De Laure's avatar
Prosper De Laure committed
275
276
277
278
279
280
281
282
283
284
285
            parameters.archiveIds = $("#save").data('archiveids');

            if(!parameters.archiveIds) {
                parameters.archiveIds = $('#selectedArchiveId').find('span').html();
            }

            if (this.actionsType[this.modalType]) {
                type = this.actionsType[this.modalType];
            } else {
                type = 'PUT';
            }
Alexandre Morin's avatar
Alexandre Morin committed
286

Prosper De Laure's avatar
Prosper De Laure committed
287
288
289
290
291
292
293
294
295
296
            $.ajax({
                url         : this.actionsList[this.modalType],
                type        : type,
                data        : JSON.stringify(parameters),
                contentType : 'application/json',
                dataType    : 'json',
                success     : function (response) {
                    gritter.show(response.message, response.status, response.errors);
                    if (response.status) {
                        ModificationModal.close();
297
298
299
300
301
302
                        ModificationModal.modal.one('hidden.bs.modal', function () {
                            console.log("passage");
                            //$('#modificationModal').modal();*
                            $('#archive_search').click();
                        });

Prosper De Laure's avatar
Prosper De Laure committed
303
304
305
306
307
308
309
310
311
                    }
                },
                error       : function(response) {
                    gritter.show(response.responseJSON.message, response.responseJSON.status, response.responseJSON.errors);
                }
            });
        },

        close: function() {
312
313
            ModificationModal.modal.find('input, textarea').val('');
            ModificationModal.modal.modal('hide');
Prosper De Laure's avatar
Prosper De Laure committed
314
315
316
317
318
319
320
321
322
323
324
325
326
        },

        loadAccessCode: function() {
            var accessRuleCode = $("#accessRuleCode").find(':selected').data('json');
            var accessRules = "";
            var accessRuleTable = $('#accessRuleTable');

            if (accessRuleCode) {
                if (accessRuleCode.duration) {
                    var accessRules = accessRuleCode.accessRules;
                    var accessRuleDurationUnit = accessRuleCode.duration.substr(accessRuleCode.duration.length - 1, 1);
                    var accessRuleDuration = (accessRuleCode.duration.split(accessRuleDurationUnit))[0].split("P");
                    $('#accessRule').css("display", '');
327
                    $('#accessRuleDuration').text(accessRuleDuration[1] + ' ' + $('#text_' + accessRuleDurationUnit).html());
328
                    $('#accessRuleDescription').text(accessRuleCode.description);
Prosper De Laure's avatar
Prosper De Laure committed
329
330
                } else {
                    $('#accessRule').css("display", '');
331
                    $('#accessRuleDuration').text(accessRuleCode.durationUnit);
332
                    $('#accessRuleDescription').text(accessRuleCode.description);
Prosper De Laure's avatar
Prosper De Laure committed
333
334
                }

335

336

Prosper De Laure's avatar
Prosper De Laure committed
337
338
339
            } else {
                $('#accessRule').css("display", 'none');
            }
340

Prosper De Laure's avatar
Prosper De Laure committed
341
342
343
344
345
346
347
348
            if(accessRules){
                if (!accessRules.length) {
                    $('#accessRuleTable').css('display', 'none');
                } else {
                    var checked = $('<i>').addClass('fa fa-check').html('&nbsp;');
                }
            }
        },
349

Dylan's avatar
Dylan committed
350
         loadRetentionCode: function(rule) {
Dylan's avatar
Dylan committed
351
352
353
            var retentionRuleCode = $("#retentionRuleCode").find(':selected').data('json');
            var retentionRules = "";
            var retentionRuleTable = $('#retentionRuleTable');
Prosper De Laure's avatar
Prosper De Laure committed
354
console.log(retentionRuleCode);
Dylan's avatar
Dylan committed
355
             if (retentionRuleCode) {
Dylan's avatar
Dylan committed
356

Dylan's avatar
Dylan committed
357
358
                 var retentionRuleDurationUnit = retentionRuleCode.duration.substr(retentionRuleCode.duration.length - 1, 1);
                 var retentionRuleDuration = (retentionRuleCode.duration.split(retentionRuleDurationUnit))[0].split("P");
Dylan's avatar
Dylan committed
359

Dylan's avatar
Dylan committed
360
                 if (rule) {
Dylan's avatar
Dylan committed
361
                    $('#retentionRule').css("display", '');
362
                    $('#retentionRuleDuration').text(retentionRuleDuration[1] + ' ' + $('#text_' + retentionRuleDurationUnit).html());
Dylan's avatar
Dylan committed
363
                    $('#retentionRuleFinalDisposition').val(rule.finalDisposition);
364
                    $('#retentionRuleDescription').text(retentionRuleCode.description);
Dylan's avatar
Dylan committed
365
366
                } else {
                    $('#retentionRule').css("display", '');
Dylan's avatar
Dylan committed
367
368
                    $('#retentionRuleDuration').text(retentionRuleDuration[1] + ' ' + $('#text_' + retentionRuleDurationUnit).html());
                    $('#retentionRuleFinalDisposition').val(retentionRuleCode.finalDisposition);
369
                    $('#retentionRuleDescription').text(retentionRuleCode.description);
Dylan's avatar
Dylan committed
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
                }

            } else {
                $('#retentionRule').css("display", 'none');
            }
            
            if(retentionRules){
                if (!retentionRules.length) {
                    $('#retentionRuleTable').css('display', 'none');
                } else {
                    var checked = $('<i>').addClass('fa fa-check').html('&nbsp;');
                }
            }
        },

Prosper De Laure's avatar
Prosper De Laure committed
385
386
387
388
389
390
391
        loadTable: function(ids, names) {
            var table = $('#archiveTable');
            var tbody = table.find('tbody');
            tbody.empty();

            $.each(ids,function(index,value) {
                var tr = $('<tr/>');
392
393
                var tdId = $('<td/>').text(value).appendTo(tr);
                var tdName = $('<td/>').text(names[index]).appendTo(tr);
Prosper De Laure's avatar
Prosper De Laure committed
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
                tr.appendTo(tbody);
            });

            if (ModificationModal.dataTable) {
                ModificationModal.dataTable.destroy();
                ModificationModal.dataTable = null;
            }

            ModificationModal.dataTable = table.DataTable({
                "sdom": '<"dataTable-footer clearfix"<"pull-left"f>><"table-responsive"t><"dataTable-footer"<"pull-left"li><"pull-right"p><"clearfix">>',
                "sPaginationType": "full_numbers",
                "bFilter": false,
                "bInfo" : false,
                "pageLength": 10,
                "oLanguage": {
                    "sLengthMenu" : $('#lengthMenu_text').html(),
                    "oPaginate" : {
                        "sFirst" : $('#first_text').html(),
                        "sPrevious" : $('#previous_text').html(),
                        "sNext" : $('#next_text').html(),
                        "sLast" : $('#last_text').html()
                    }
                }
            });
Alexandre Morin's avatar
Alexandre Morin committed
418
419
420
421
422
        },
        
        reset : function() {
            $('#modificationModal').find('[name="identifier"]').val("");
            $('#modificationModal').find('[name="comment"]').val("");
Prosper De Laure's avatar
Prosper De Laure committed
423
424
425
426
        }
    };

</script>