modalModification.html 20.4 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/archiveModificationModal/archiveModificationForm.html?>
Prosper De Laure's avatar
Prosper De Laure committed
13
14
15
16
17
18
19
20
21
                    <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>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer" data-translate-catalog="recordsManagement/messages">
22
                <button id="cancelEdit" class="btn btn-warning" data-dismiss="modal" title="Cancel"><i class="fa fa-times">&nbsp;</i>Cancel</button>
23
                <button id="save" class="btn btn-success" data-archiveIds="" title="Save"><i class="fa fa-check">&nbsp;</i>OK</button>
Prosper De Laure's avatar
Prosper De Laure committed
24
25
26
27
28
29
            </div>
        </div>
    </div>
</div>

<div style="display:none">
30
    <span id="mtext_flagForTransfer">Flag for transfer</span>
Prosper De Laure's avatar
Prosper De Laure committed
31
32
33
    <span id="mtext_retentionRule">Change disposal rule</span>
    <span id="mtext_accessRule">Edit access rule</span>
    <span id="mtext_flagForDestruction">Flag for destruction</span>
Alexandre Morin's avatar
Alexandre Morin committed
34
    <span id="mtext_requestModification">Request a modification</span>
Prosper De Laure's avatar
Prosper De Laure committed
35
36
37
    <span id="mtext_cancelDestruction">Cancel destruction</span>
    <span id="mtext_freeze">Freeze</span>
    <span id="mtext_unfreeze">Unfreeze</span>
38
    <span id="empty_text">The fields with a star are required.</span>
Alexandre Morin's avatar
Alexandre Morin committed
39
    <span id="empty_archivalAgency">No archival agency found</span>
Prosper De Laure's avatar
Prosper De Laure committed
40
41
42
43

    <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
44
45
    <span id="text_preservation">preservation</span>
    <span id="text_destruction">destruction</span>
46
    <span id="text_unlimited">Unlimited</span>
Prosper De Laure's avatar
Prosper De Laure committed
47
48
49
50
51
52
53
</div>

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

<script>
54
    // empty description / reference fields / button state when the user press cancel
55
    $("#cancelEdit").on('click', function () {
56
        $('#save').prop("disabled",false);
57
58
59
        ModificationModal.modal.find('input, textarea').val('');
    });

Prosper De Laure's avatar
Prosper De Laure committed
60
61
62
63
    $("#accessRuleCode").on('change', function () {
        ModificationModal.loadAccessCode();
    });
    
Dylan's avatar
Dylan committed
64
65
66
67
    $("#retentionRuleCode").on('change', function () {
        ModificationModal.loadRetentionCode();
    });

Alexis Ragot's avatar
Alexis Ragot committed
68
69
70
71
72
73
74
    $("#checkboxUpdateFinalDisposition").on('change', function () {
        if (this.checked) {
            $("#retentionRuleFinalDisposition").prop("disabled",true);
        } else {
            $("#retentionRuleFinalDisposition").prop("disabled",false);
        }
    });
75
    // State of button 'save' will change according to value of comment's field
76
77
    $("#comment").on('change keyup', function () {
        if ($("#comment").val() !== "") {
Alexandre Morin's avatar
Alexandre Morin committed
78
            $("#save").prop("disabled",false);
79
80
81
        } 
        else{
            $("#save").prop("disabled",true);
Alexandre Morin's avatar
Alexandre Morin committed
82
83
        }
    });
84

Prosper De Laure's avatar
Prosper De Laure committed
85
86
87
88
89
90
91
92
93
94
    $("#save").on('click', function (e) {
        e.preventDefault();
        ModificationModal.save(); 
    });
    
    ModificationModal = {
        actionsList : {
            accessRule          : '/recordsManagement/archive/accessRule',
            retentionRule       : '/recordsManagement/archive/retentionRule',
            flagForDestruction  : '/recordsManagement/dispose',
Cyril Vazquez's avatar
Cyril Vazquez committed
95
            requestModification : '/modificationRequest',
Prosper De Laure's avatar
Prosper De Laure committed
96
97
98
            cancelDestruction   : '/recordsManagement/cancelDestruction',
            freeze              : '/recordsManagement/archive/freeze',
            unfreeze            : '/recordsManagement/archive/unfreeze'
99
/*             originatorOrg       : '/recordsManagement/archive/originatorOrg' */
Prosper De Laure's avatar
Prosper De Laure committed
100
101
102
103
104
        },
        actionsType : {},
        modal : $('#modificationModal'),
        modalType : null,
        dataTable : null,
Alexandre Morin's avatar
Alexandre Morin committed
105
        load : function(archiveId, archiveName, type, transaction) {
Prosper De Laure's avatar
Prosper De Laure committed
106
107
108
109
            this.modalType = type;

            this.loadTitle();
            
110
111
            $('#selectedArchiveId').css('display', '').find('span').text(archiveId);
            $('#selectedArchiveReference').css('display', '').find('span').text(archiveName);
112
            $('#archiveModificationForm').find('.modificationForm').css('display', 'none');
Prosper De Laure's avatar
Prosper De Laure committed
113

114
115
116
117
            try {
                eval(type+"_load(archiveId, archiveName, type)");
            }
            catch(err) {
Alexandre Morin's avatar
Alexandre Morin committed
118
                this.modal.modal();
Prosper De Laure's avatar
Prosper De Laure committed
119
            }
120

Alexandre Morin's avatar
Alexandre Morin committed
121
122
            if (type === 'requestCommunication' && $('#' +archiveId).data('iscommunicable') === 1) {
                $('#derogationTr').show();
Alexandre Morin's avatar
Alexandre Morin committed
123
                $('#derogationInputTr').show();
Alexandre Morin's avatar
Alexandre Morin committed
124
125
126
                $("#derogationTr .toggle").removeClass('btn-default off');
                $("#derogationTr .toggle").addClass('btn-info');

Alexandre Morin's avatar
Alexandre Morin committed
127
128
            } else {
                $('#derogationTr').hide();
Alexandre Morin's avatar
Alexandre Morin committed
129
                $('#derogationInputTr').hide();
Alexandre Morin's avatar
Alexandre Morin committed
130
131
            }

132
            if (type === 'requestModification') {
133
134
135
                $('#messageFormatTr').hide();
            }

Alexandre Morin's avatar
Alexandre Morin committed
136
137
138
139
            if (!transaction) {
                $('#message').hide();
            }

Prosper De Laure's avatar
Prosper De Laure committed
140
            $('#save').data("archiveids", "");
Alexandre Morin's avatar
Alexandre Morin committed
141
            $('#archiveModificationForm').css('display', '');
Prosper De Laure's avatar
Prosper De Laure committed
142
143
144
            $('#modal_multipleSelection').css('display', 'none');
        },

145
146
147
148
149
150
151
152
153
154
155
156
157
158
        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
159
160
161
162
163
164
165
166
167

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

168
169
170
171
172
173
174
175
                    $('#modificationModal').modal();
                },
                error   : function (response) {
                    gritter.show(response.responseJSON.message, response.responseJSON.status, response.responseJSON.errors);
                }
            });
        },

176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*         loadOriginatorOrg : function() {
            $.ajax({
                type     : "GET",
                url      : "http://maarchrm/organization/organization/search?enabled=true",
                dataType : 'json',
                success  : function (response) {
                    var organizations = response;
                    $('#originatorOrgSelect').find('option').remove();
                    $.each(organizations, function (key, value) {
                        $('#originatorOrgSelect').append($('<option>', {
                            value: value.registrationNumber,
                            text: value.displayName
                        }));
                    });

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

                    $('#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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
        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) {
221
222
223
224
225
                    if (response.status) {
                        if (ModificationModal.modalType === "accessRule") {
                            rule = response.accessRule;
                        } else {
                            rule = response.retentionRule;
Prosper De Laure's avatar
Prosper De Laure committed
226
227
                        }

228
229
230
                        $.each(rule, function (key, value) {
                            ModificationModal.modal.find("[name='" + key + "']").val(value);
                        });
Prosper De Laure's avatar
Prosper De Laure committed
231

232
                        if (ModificationModal.modalType === "accessRule") {
233
                            ModificationModal.loadAccessCode(rule);
234
                        }
Prosper De Laure's avatar
Prosper De Laure committed
235

236
237
238
                        if (ModificationModal.modalType === "retentionRule") {
                            ModificationModal.loadRetentionCode(rule);
                        }
Dylan's avatar
Dylan committed
239

240
241
242
243
244
245
246
247
248
249
                        // 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
250
251
252
253
254
255
256
257
                    }
                },
                error   : function(response) {
                    gritter.show(response.responseJSON.message, response.responseJSON.status, response.responseJSON.errors);
                }
            });
        },

Alexandre Morin's avatar
Alexandre Morin committed
258
        loadMultiple: function(selected, relevant, ids, names, type, transaction) {
Prosper De Laure's avatar
Prosper De Laure committed
259
260
261
262
            this.modalType = type;

            this.loadTitle();
            $('#selectedArchiveId, #selectedArchiveReference').css('display', 'none');
263
            $('#archiveModificationForm').find('.modificationForm').css('display', 'none');
Prosper De Laure's avatar
Prosper De Laure committed
264

265
266
            try {
                eval(type+"_loadMultiple()");
267
                $('#archiveModificationForm').css('display', '');
268
269
270
271
            }
            catch(err) {
                console.log(err);
                $('#archiveModificationForm').css('display', 'none');
Prosper De Laure's avatar
Prosper De Laure committed
272
            }
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287

            if (type === 'requestCommunication') {
                var isNotCommunicable = ids.some((id) => $('#' +id).data('iscommunicable') === 1);
                if (isNotCommunicable) {
                    $('#derogationTr').show();
                    $('#derogationInputTr').show();
                    $("#derogationTr .toggle").removeClass('btn-default off');
                    $("#derogationTr .toggle").addClass('btn-info');
                }
                 else {
                    $('#derogationTr').hide();
                    $('#derogationInputTr').hide();
                }
            }

Prosper De Laure's avatar
Prosper De Laure committed
288
289
290
291
292
293
            $('#save').data("archiveids", ids);
            $('#modal_multipleSelection').css('display', '');
            $('#modal_selected').html(selected);
            $('#modal_relevant').html(relevant);

            ModificationModal.loadTable(ids, names);
Alexandre Morin's avatar
Alexandre Morin committed
294
295
296
297
298

            if (!transaction) {
                $('#message').hide();
            }

Prosper De Laure's avatar
Prosper De Laure committed
299
300
301
302
303
304
305
306
307
308
            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
309

310
            if (!parameters == -1) {
311
                return;
Alexandre Morin's avatar
Alexandre Morin committed
312
            }
313
            
Prosper De Laure's avatar
Prosper De Laure committed
314
315
316
317
318
319
320
321
322
323
324
            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';
            }
325
326

            console.log(this.actionsList[this.modalType]);
Arnaud Pauget's avatar
Arnaud Pauget committed
327
            
Prosper De Laure's avatar
Prosper De Laure committed
328
329
330
331
332
333
334
335
336
337
            $.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();
338
339
340
341
                        ModificationModal.modal.one('hidden.bs.modal', function () {
                            $('#archive_search').click();
                        });

Prosper De Laure's avatar
Prosper De Laure committed
342
343
344
345
346
347
348
349
350
                    }
                },
                error       : function(response) {
                    gritter.show(response.responseJSON.message, response.responseJSON.status, response.responseJSON.errors);
                }
            });
        },

        close: function() {
351
352
            ModificationModal.modal.find('input, textarea').val('');
            ModificationModal.modal.modal('hide');
Prosper De Laure's avatar
Prosper De Laure committed
353
354
        },

355
        loadAccessCode: function(rule) {
Prosper De Laure's avatar
Prosper De Laure committed
356
357
358
359
360
            var accessRuleCode = $("#accessRuleCode").find(':selected').data('json');
            var accessRules = "";
            var accessRuleTable = $('#accessRuleTable');

            if (accessRuleCode) {
361
362
363
364
                let accessRuleDurationUnit = accessRuleCode.duration.substr(accessRuleCode.duration.length - 1, 1);
                let accessRuleDuration = (accessRuleCode.duration.split(accessRuleDurationUnit))[0].split("P");

                if (rule) {
Prosper De Laure's avatar
Prosper De Laure committed
365
                    $('#accessRule').css("display", '');
366
367
368
369
370
371

                    if(accessRuleDuration[1] >= 9999){
                        $('#accessRuleDuration').text($('#text_unlimited').text());
                    } else {
                        $('#accessRuleDuration').text(accessRuleDuration[1] + ' ' + $('#text_' + accessRuleDurationUnit).html());
                    }
372
                    $('#accessRuleDescription').text(accessRuleCode.description);
Prosper De Laure's avatar
Prosper De Laure committed
373
374
375
376
377
                }

            } else {
                $('#accessRule').css("display", 'none');
            }
378

Prosper De Laure's avatar
Prosper De Laure committed
379
380
381
382
383
384
385
386
            if(accessRules){
                if (!accessRules.length) {
                    $('#accessRuleTable').css('display', 'none');
                } else {
                    var checked = $('<i>').addClass('fa fa-check').html('&nbsp;');
                }
            }
        },
387

Dylan's avatar
Dylan committed
388
         loadRetentionCode: function(rule) {
Dylan's avatar
Dylan committed
389
390
391
392
            var retentionRuleCode = $("#retentionRuleCode").find(':selected').data('json');
            var retentionRules = "";
            var retentionRuleTable = $('#retentionRuleTable');

Dylan's avatar
Dylan committed
393
             if (retentionRuleCode) {
394

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

Dylan's avatar
Dylan committed
398
                 if (rule) {
Alexis Ragot's avatar
Alexis Ragot committed
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
                     $('#retentionRule').css("display", '');

                     if(retentionRuleDuration[1] >= 9999){
                         $('#retentionRuleDuration').text($('#text_unlimited').text());
                     } else {
                         $('#retentionRuleDuration').text(retentionRuleDuration[1] + ' ' + $('#text_' + retentionRuleDurationUnit).html());
                     }
                     $('#retentionRuleFinalDisposition').val(rule.finalDisposition);
                     $('#retentionRuleDescription').text(retentionRuleCode.description);
                 } else {
                     $('#retentionRule').css("display", '');

                     if(retentionRuleDuration[1] >= 9999){
                         $('#retentionRuleDuration').text($('#text_unlimited').text());
                     } else {
                         $('#retentionRuleDuration').text(retentionRuleDuration[1] + ' ' + $('#text_' + retentionRuleDurationUnit).html());
                     }

                     $('#retentionRuleDescription').text(retentionRuleCode.description);
                 }

             } else {
                 $('#retentionRule').css("display", 'none');
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442

                 if (rule) {
                     $('#retentionRule').css("display", '');

                     if(rule.retentionDuration) {
                         var retentionRuleDurationUnit = rule.retentionDuration.substr(rule.retentionDuration.length - 1, 1);
                         var retentionRuleDuration = (rule.retentionDuration.split(retentionRuleDurationUnit))[0].split("P");

                         if(retentionRuleDuration[1] >= 9999){
                             $('#retentionRuleDuration').text($('#text_unlimited').text());
                         } else {
                             $('#retentionRuleDuration').text(retentionRuleDuration[1] + ' ' + $('#text_' + retentionRuleDurationUnit).html());
                         }
                     }

                     if(rule.finalDisposition) {
                        $('#retentionRuleFinalDisposition').val(rule.finalDisposition);
                     } else {
                         $('#retentionRuleFinalDisposition').val("");
                     }
                 }
Alexis Ragot's avatar
Alexis Ragot committed
443
             }
Dylan's avatar
Dylan committed
444
445
446
447
448
449
450
451
452
453
            
            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
454
455
456
457
458
459
460
        loadTable: function(ids, names) {
            var table = $('#archiveTable');
            var tbody = table.find('tbody');
            tbody.empty();

            $.each(ids,function(index,value) {
                var tr = $('<tr/>');
461
462
                var tdId = $('<td/>').text(value).appendTo(tr);
                var tdName = $('<td/>').text(names[index]).appendTo(tr);
Prosper De Laure's avatar
Prosper De Laure committed
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
                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
487
488
489
490
491
        },
        
        reset : function() {
            $('#modificationModal').find('[name="identifier"]').val("");
            $('#modificationModal').find('[name="comment"]').val("");
Prosper De Laure's avatar
Prosper De Laure committed
492
493
494
        }
    };

495
496
497
498
499
500
501
502
    $("#modificationModal").on("shown.bs.modal", function() {
        isModalOpen = true;
    });

    $("#modificationModal").on("hidden.bs.modal", function() {
        isModalOpen = false;
    });

503
</script>