archiveForm.html 25.5 KB
Newer Older
Cyril Vazquez's avatar
Cyril Vazquez committed
1
2
3
4
5
6
7
8
<!--#
    This file is part of the auth package.
    (c) Maarch Prospre DE LAURE <prosper.delaure@maarch.org>

    For the full copyright and license information, please view the LICENSE
    file that was distributed with this source code.
#-->
<form class="form-horizontal" id="archiveForm">
9
    <div  id="archiveImportTitleForm">
10
11
12
        <div class="form-group">
            <label class="col-sm-3 control-label">Originator organization</label>
            <div class="col-sm-9">
13
                <select class="form-control archiveInput" name="originatorOrgRegNumber" id="originatorOrgRegNumber">
14
15
16
17
                    <?merge orgUnitList ?>
                    <option value="[?merge .registrationNumber ?]"><?merge .displayName ?></option>
                </select>
            </div>
18
        </div>
19
20
21
        <div class="form-group">
            <label class="col-sm-3 control-label">Archival profile</label>
            <div class="col-sm-9">
22
                <select class="form-control archiveInput" name="archivalProfileReference" id="archivalProfile">
23
                </select>
24
                <input type="hidden" id="archivalProfileToEdit" />
25
26
27
28
29
30
31
32
            </div>
        </div>
        <div class="form-group">
            <h4 class="pull-left">
                <span id="import_archivalProfile"/>
                <br/>
                <small id="import_isSubArchive"><span>Sub-archive of </span><span id="import_parentArchiveName"><b></b></span></small>
            </h4>
33
34
        </div>
    </div>
Cyril Vazquez's avatar
Cyril Vazquez committed
35
    <div class="form-group">
36
        <label class="col-sm-3 control-label">Name</label>
37
        <div class="col-sm-9">
Alexis Ragot's avatar
Alexis Ragot committed
38
            <input type="text" class="input-sm form-control archiveInput" name="archiveName" placeholder="Archive name"/>
Cyril Vazquez's avatar
Cyril Vazquez committed
39
40
        </div>
    </div>
Alexis Ragot's avatar
Alexis Ragot committed
41
    <div class="form-group" data-translate-catalog="recordsManagement/archive">
42
        <label class="col-sm-3 control-label">Identifier</label>
43
        <div class="col-sm-9">
Alexis Ragot's avatar
Alexis Ragot committed
44
            <input type="text" class="input-sm form-control archiveInput" name="originatorArchiveId" placeholder="Identifier"/>
Cyril Vazquez's avatar
Cyril Vazquez committed
45
46
        </div>
    </div>
47
    <div class="form-group">
48
        <label class="col-sm-3 control-label">Originating date</label>
49
50
        <div class="input-group col-sm-9" style="padding-left: 15px; padding-right: 15px;">
            <input class="input-sm form-control datePicker archiveInput" name="originatingDate" placeholder="Originating date"/>
51
52
        </div>
    </div>
53

54
    <div class="form-group hide" id="fileplanLevelDiv">
55
        <label class="col-md-3 control-label">Fileplan level</label>
56
57
58
59
        <div class="col-md-9">
            <input type="checkbox" data-width="100" class="input-sm" id="fileplanLevelToggle">
        </div>
    </div>
60

61
    <input type="hidden" id="isArchiver" name="isArchiver" value="[?merge isArchiver.json() ?]" />
Alexis Ragot's avatar
Alexis Ragot committed
62
    <input type="hidden" class="archiveInput" name="filePlanPosition"/>
63
    <input type="hidden" class="archiveInput" id="parentArchiveId" name="parentArchiveId"/>
64
    <input type="hidden" class="archiveInput" id="fileplanLevel" name="fileplanLevel" value='file'/>
65
</form>
Alexis Ragot's avatar
Alexis Ragot committed
66
67
68

<?hinclude dashboard/mainScreen/descriptionForm.html ?>

69
<div id="managementMetadataDiv">
70
71
<div class="panel-heading" role="tab">
    <strong>
Cyril Vazquez's avatar
Cyril Vazquez committed
72
        <a data-toggle="collapse" href="#management">Management metadata</a>
73
74
    </strong>
</div>
Alexis Ragot's avatar
Alexis Ragot committed
75
<div id="management" class="panel-collapse collapse in">
76
    <form id="managementMetadataForm" class="form-horizontal">
Cyril Vazquez's avatar
Cyril Vazquez committed
77
        <div class="form-group">
78
            <label class="col-md-3 control-label">Retention rule</label>
Cyril Vazquez's avatar
Cyril Vazquez committed
79
            <div class="col-md-6">
Alexis Ragot's avatar
Alexis Ragot committed
80
                <select class="input-sm form-control archiveInput" name="retentionRuleCode" id="retentionRule">
Cyril Vazquez's avatar
Cyril Vazquez committed
81
82
83
84
85
                    <option value=""></option>
                    <?merge retentionRules ?>
                    <option value="[?merge .code ?]" data-duration="[?merge .durationText ?]" data-final-disposition="[?merge .finalDisposition ?]"><?merge .label ?></option>
                </select>
            </div>
Cyril Vazquez's avatar
Cyril Vazquez committed
86
            <div class="col-md-3">
87
                <p class="help-block small"><i id="retentionRuleText"></i></p>
Cyril Vazquez's avatar
Cyril Vazquez committed
88
            </div>
Cyril Vazquez's avatar
Cyril Vazquez committed
89
90
        </div>
        <div class="form-group">
91
            <label class="col-md-3 control-label">Retention start date</label>
Alexis Ragot's avatar
Alexis Ragot committed
92
            <div class="col-md-6">
Alexis Ragot's avatar
Alexis Ragot committed
93
                <input class="input-sm form-control datePicker archiveInput" name="retentionStartDate" placeholder="Retention start date"/>
Cyril Vazquez's avatar
Cyril Vazquez committed
94
95
            </div>
        </div>
96
97
    </form>
</div>
98
</div>
99

100
<div class="hide">
101
102
    <span id="text_file"><i class='fa fa-folder'></i> File</span>
    <span id="text_item"><i class='fa fa-file'></i> Item</span>
103
104
105
    <span id="message_requiredFieldOnEmptyForm">You must define at least the name, the identifier, the date of the document or a document</span>
</div>

106
<script src="/public/js/bootstrap-toggle/bootstrap-toggle.js"></script>
107

Cyril Vazquez's avatar
Cyril Vazquez committed
108
<script type="text/javascript">
109

110

111
    FilePlanLevelToggle = {
112
113
114
115
        load: function (isWithoutProfile) {
            if (isWithoutProfile === undefined) {
                isWithoutProfile = true;
            }
116

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
            if(isWithoutProfile == true) {
                if($('#fileplanLevelDiv').is(":hidden")) {
                    $('#fileplanLevelDiv').show();
                }

                $('#fileplanLevelToggle').bootstrapToggle({
                    on: $('#text_item'),
                    off: $('#text_file'),
                });

                $('#fileplanLevel').val("file");

                if($('#fileplanLevel').val() == 'item') {
                    $('#fileplanLevelToggle').bootstrapToggle('on');
                    $("#contentsTabBtn").addClass('hide');
                }


                $('#fileplanLevelToggle').on('change', function (e) {
                    if ($('#fileplanLevelToggle').prop('checked')) {
                        $("#fileplanLevel").val('item');
                        $("#contentsTabBtn").addClass('hide');
                    } else {
                        $("#fileplanLevel").val('file');
                        $("#contentsTabBtn").removeClass('hide');
                    }
                });
            } else {
                $('#fileplanLevelDiv').hide();
            }
        }
    };

150
151
152
153
154
155
156
    $("#archiveForm").keypress(function(e) {
    //To disable Enter keypress in this form
        if (e.which == 13) {
            return false;
        }
    });

Cyril Vazquez's avatar
Cyril Vazquez committed
157
158
159
160
    // ARCHIVE
    $('#retentionRule').on('change', function() {
        ArchiveForm.displayRetentionRulesInfo();
    });
jerome's avatar
jerome committed
161

Cyril Vazquez's avatar
Cyril Vazquez committed
162
    var ArchiveForm = {
Alexis Ragot's avatar
Alexis Ragot committed
163
164
165
        send : function(type, event, button) { //
            let url = null;
            let data = null;
Alexis Ragot's avatar
Alexis Ragot committed
166
            let archive = null;
Cyril Vazquez's avatar
Cyril Vazquez committed
167

Alexis Ragot's avatar
Alexis Ragot committed
168
169
            if (type === 'sync') {
                url = "/archive";
Alexis Ragot's avatar
Alexis Ragot committed
170
                archive = this.syncSerialize();
Alexis Ragot's avatar
Alexis Ragot committed
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

                if (archive < 0) {
                    return;
                }

                data = JSON.stringify({archive : archive, zipContainer : DocumentForm.zipContainer});
            } else {
                url = "/transfer";
                data = this.asyncSerialize();

                if (data.message <0) {
                    return;
                }

                data = JSON.stringify(data);

Cyril Vazquez's avatar
Cyril Vazquez committed
187
            }
Alexis Ragot's avatar
Alexis Ragot committed
188
            ajax($(button),
Prosper De Laure's avatar
Prosper De Laure committed
189
190
                {
                    type        : 'POST',
Alexis Ragot's avatar
Alexis Ragot committed
191
192
                    url         : url,
                    data        : data,
Prosper De Laure's avatar
Prosper De Laure committed
193
194
195
196
                    contentType : 'application/json',
                    dataType    : 'json',
                    success     : function (response) {
                        gritter.show(response.message, response.status, response.errors);
Alexandre Goldstein's avatar
Alexandre Goldstein committed
197

Prosper De Laure's avatar
Prosper De Laure committed
198
                        if (response.status) {
199
                            // trigger("archiveImportOver.recordsManagement", [archive.parentArchiveId]); //
Prosper De Laure's avatar
Prosper De Laure committed
200
                            ImportPanel.cancel();
201
202
203
                            var folder = archive.originatorOrgRegNumber;
                            if (archive.filePlanPosition) {
                                folder = archive.filePlanPosition;
jerome's avatar
jerome committed
204
                            }
205
                            trigger('loadFolder.filePlan', [folder]); //
206

207
                            // $("#documentForm").show();
Prosper De Laure's avatar
Prosper De Laure committed
208
209
210
211
                        }
                    },
                    error       : function (response) {
                        gritter.show(response.responseJSON.message, response.responseJSON.status, response.responseJSON.errors);
Arnaud Pauget's avatar
Arnaud Pauget committed
212
                    }
Cyril Vazquez's avatar
Cyril Vazquez committed
213
                }
Prosper De Laure's avatar
Prosper De Laure committed
214
            );
Cyril Vazquez's avatar
Cyril Vazquez committed
215
        },
216
217
218
219
220

        modify : function(event, button) {
            let url = null;
            let data = null;
            let archive = null;
221
            let archiveId = null;
222
223

            archiveId = $(button).data("archive-id");
224
            archive = this.syncSerialize("modify");
225

226
227
228
229
            if (archive < 0) {
                return;
            }

230
231
232
233
            var parameters = {
                archiveId           : archiveId,
                originatorArchiveId : archive.originatorArchiveId,
                archiveName         : archive.archiveName,
234
                originatingDate     : archive.originatingDate,
235
236
237
238
239
240
241
242
243
244
245
246
247
                description         : archive.descriptionObject
            };

            $.ajax({
                type        : 'PUT',
                url         : "/recordsmanagement/archive/metadata",
                data        : JSON.stringify(parameters),
                contentType : 'application/json',
                dataType    : 'json',
                success     : function (response) {
                    gritter.show(response.message, response.status, response.errors);

                    if (response.status) {
248
                        ImportPanel.cancel();
249
                        $('#archivalProfileFields').empty();
250
                        Archive.getInfo(ArchiveInformation.archiveId);
251
                        $("#searchForm_inputSearchBtn").click();
252
                        trigger("archiveImportOver.recordsManagement");
253
254
                        $("#modifyArchive").addClass("hide");
                        $("#syncImport").removeClass("hide");
255
                        $("#asyncImport").removeClass("hide");
256
                        $("#managementMetadataDiv").removeClass("hide");
257
                        $("#documentForm").show();
258
259
260
261
262
263
264
265
                    }
                },
                error       : function (response) {
                    gritter.show(response.responseJSON.message, response.responseJSON.status, response.responseJSON.errors);
                }
            });
        },

Cyril Vazquez's avatar
Cyril Vazquez committed
266
        loadProfile : function() {
267
268
269
270
271
272
273
274
275
            var archivalProfileReference = $('#archivalProfile').val();
            $.ajax({
                type        : 'GET',
                url         : "/profilebyreference/" + archivalProfileReference,
                dataType    : 'json',
                async       : false,
                success     : function (response) {
                    $("#archivalProfile").data('json', response);
                    var dataJson = $('#archivalProfile').data('json');
Cyril Vazquez's avatar
Cyril Vazquez committed
276

277
278
279
280
                    var selectedProfile = "";
                    if (dataJson !== undefined && dataJson !== null && dataJson !== "") {
                        selectedProfile = dataJson;
                    }
281

282
283
284
285
286
287
288
289
290
291
292
293
294
295
                    if (archivalProfileReference == '' || selectedProfile.retentionRuleCode == null || selectedProfile.retentionRuleCode == '' || selectedProfile.retentionRuleCode == undefined) {
                        $('#retentionRule').val('').removeAttr("disabled").change();
                    } else {
                        $('#retentionRule').val(selectedProfile.retentionRuleCode).change().attr("disabled", "disabled");
                    }

                    if (archivalProfileReference == ''
                        || selectedProfile.retentionStartDate == ''
                        || selectedProfile.retentionStartDate == null) {
                        var retentionStartDate = $("#managementMetadataForm").find("[name=retentionStartDate]");
                        if (retentionStartDate.data("datepicker")) {
                            retentionStartDate.data("datepicker").setDate(new Date());
                        }
                        retentionStartDate.closest(".form-group").removeClass("hide");
Cyril Vazquez's avatar
Cyril Vazquez committed
296

297
298
299
300
301
302
303
                    } else {
                        $("#managementMetadataForm").find("[name=retentionStartDate]").val("").closest(".form-group").addClass("hide");
                    }
                    ArchiveForm.displayArchiveDescription();
                },
                error       : function (response) {
                    gritter.show(response.responseJSON.message, response.responseJSON.status, response.responseJSON.errors);
Arnaud Pauget's avatar
Arnaud Pauget committed
304
                }
305
            });
jerome's avatar
jerome committed
306

307
            
Cyril Vazquez's avatar
Cyril Vazquez committed
308
309
310
        },
        displayArchiveDescription : function() {
            var value = $('#archivalProfile').val();
311

Cyril Vazquez's avatar
Cyril Vazquez committed
312
            $('#archivalProfileFields').empty();
jerome's avatar
jerome committed
313

Cyril Vazquez's avatar
Cyril Vazquez committed
314
315
316
317
            if (value == "") {
                Metadata.acceptUserIndex(true);
                return;
            }
jerome's avatar
jerome committed
318

319
            var selectedProfile = $('#archivalProfile').data('json');
jerome's avatar
jerome committed
320

Cyril Vazquez's avatar
Cyril Vazquez committed
321
            Metadata.acceptUserIndex(selectedProfile.acceptUserIndex);
jerome's avatar
jerome committed
322

Cyril Vazquez's avatar
Cyril Vazquez committed
323
324
325
326
327
328
            $.each(selectedProfile.archiveDescription, function(key, value) {
                Metadata.addArchiveDescription(value);
            });
        },
        displayRetentionRulesInfo : function() {
            var value = $('#retentionRule').val();
329

Cyril Vazquez's avatar
Cyril Vazquez committed
330
331
            var selected = $('#retentionRule').find('option:selected');

332
            if (value == '' ||  value == null) {
Cyril Vazquez's avatar
Cyril Vazquez committed
333
334
335
336
                $('#retentionRuleText').empty();
                return;
            }

337
            var finalDisposition = selected.data('final-disposition');
jerome's avatar
jerome committed
338

Cyril Vazquez's avatar
Cyril Vazquez committed
339
340
            var duration = selected.data('duration');

341
342
343
344
            if (duration === undefined) {
                $('#retentionRuleText').text($("#preservation_text").text() + " " + $("#unlimited_text").text());
                return;
            }
Cyril Vazquez's avatar
Cyril Vazquez committed
345
346
347
348
            var numeric = duration.slice(1, -1);
            var unit = duration.substr(duration.length-1);
            var retentionRuleText = $('#retentionRule_text').text();

349
350
351
352
353
            if (unit === 'Y' && numeric >= 9999) {
                $('#retentionRuleText').text($("#preservation_text").text() + " " + $("#unlimited_text").text());
                return;
            }

Cyril Vazquez's avatar
Cyril Vazquez committed
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
            switch (unit) {
                case 'D' : unit = $("#days_text").text();
                           break;

                case 'M' : unit = $("#months_text").text();
                           break;

                case 'Y' : unit = $("#years_text").text();
                           break;
            }

            switch (finalDisposition) {
                case 'destruction'  : finalDisposition = $("#destruction_text").text();
                           break;

                case 'preservation' : finalDisposition = $("#preservation_text").text();
                           break;
            }
372
373
            retentionRuleText = retentionRuleText.replace(/%1\$s/g, finalDisposition);
            retentionRuleText = retentionRuleText.replace(/%2\$s/g, numeric+' '+unit);
374
            $('#retentionRuleText').text(retentionRuleText);
Cyril Vazquez's avatar
Cyril Vazquez committed
375
        },
376
377
378
379
380
381
        syncSerialize : function(action) {
            // to inititate default value and avoid bug on IE 11
            if (action === undefined)
            {
                action = "add";
            }
382
            var form = $('#archiveForm, #managementMetadataForm');
Cyril Vazquez's avatar
Cyril Vazquez committed
383
384
385
            var inputs = form.find('.archiveInput');
            var archive = {
                digitalResources : [],
386
                descriptionObject : {}
Cyril Vazquez's avatar
Cyril Vazquez committed
387
388
389
            }

            inputs.each(function() {
Alexis Ragot's avatar
Alexis Ragot committed
390
391
392
                var value = $(this).val();
                if (value) {
                    if ($(this).hasClass('datePicker')) {
Jerome Boucher's avatar
Jerome Boucher committed
393
                        value = new Date($(this).data('datepicker').getFormattedDate('yyyy-mm-dd'));
Alexis Ragot's avatar
Alexis Ragot committed
394
395
                    }
                    archive[$(this).attr('name')] = value;
Cyril Vazquez's avatar
Cyril Vazquez committed
396
                }
Alexis Ragot's avatar
Alexis Ragot committed
397
            });
Cyril Vazquez's avatar
Cyril Vazquez committed
398

Alexis Ragot's avatar
Alexis Ragot committed
399
400
401
            var selectedProfile = $('#archivalProfile').data('json');

            if (selectedProfile !== undefined && selectedProfile !== null && selectedProfile !== "") {
Cyril Vazquez's avatar
Cyril Vazquez committed
402
                archive.descriptionClass = selectedProfile.descriptionClass;
403
404
405
                if (selectedProfile.fileplanLevel != null) {
                    archive.fileplanLevel = selectedProfile.fileplanLevel;
                }
Cyril Vazquez's avatar
Cyril Vazquez committed
406
407
408
            }

            archive.descriptionObject = Metadata.serialize($('#allFields'));
Cyril Vazquez's avatar
Cyril Vazquez committed
409
410

            if (archive.descriptionObject === -1) {
Cyril Vazquez's avatar
Cyril Vazquez committed
411
412
413
                return -1;
            }

Alexis Ragot's avatar
Alexis Ragot committed
414
            archive.digitalResources = DocumentList.serialize();
415

416
417
418
419
            if (archive.descriptionObject === undefined) {
                return -1;
            }

420
            if (selectedProfile !== undefined && selectedProfile !== null && selectedProfile !== "" && action !== "modify") {
421
422
423
424
425
                if (selectedProfile.fileplanLevel == 'item' && archive.digitalResources==null) {
                    gritter.show($('#documentMissing_error').text(), false);
                    return -2;
                }
            }
Cyril Vazquez's avatar
Cyril Vazquez committed
426

Alexis Ragot's avatar
Alexis Ragot committed
427
            if (!selectedProfile && !archive.archiveName && !archive.originatorArchiveId && !archive.originatingDate && archive.digitalResources == null) {
428
429
430
431
                gritter.show($("#message_requiredFieldOnEmptyForm").text(), false);
                return -3;
            }

Cyril Vazquez's avatar
Cyril Vazquez committed
432
433
434
            return archive;
        },

Alexandre Morin's avatar
Alexandre Morin committed
435
436
437
438
        asyncSerialize : function() {
            var form = $('#archiveForm, #managementMetadataForm');
            var inputs = form.find('.archiveInput');
            var data = {
439
440
441
442
                messageFile : {
                    binaryDataObject : {},
                    descriptiveMetadata : {}
                },
Alexis Ragot's avatar
Alexis Ragot committed
443
444
                attachments : [],
                schema : "recordsManagement"
Alexandre Morin's avatar
Alexandre Morin committed
445
446
            };

447
448
449
450
451
452
            var id = Math.random().toString(36).substr(2, 9);
            var obj = {};
            obj[id] = {
                archiveName                 : null,
                originatorArchiveId         : null,
                originatorId                : null,
453
                archiveType                 : null,
454
455
456
457
458
459
460
461
462
                descriptionObject           : {},
                originatingDate             : null,
                managementMetadata          : {
                    storageRule             : {},
                    accessRule              : {},
                    appraisalRule           : {},
                    classificationRule      : {}
                },
                descriptionClass            : null,
Alexis Ragot's avatar
Alexis Ragot committed
463
                dataObjects                 : []
Alexandre Morin's avatar
Alexandre Morin committed
464
465
466
467
            };

            inputs.each(function() {
                var value = $(this).val();
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514

                switch ($(this).attr('name')) {
                    case 'archivalProfileReference' :
                        if (value) {
                            obj[id].managementMetadata.archivalProfile = value;
                        }
                        break;
                    case 'archiveName' :
                        if (value) {
                            obj[id].archiveName = value;
                        }
                        break;
                    case 'originatingDate' :
                        if (value) {
                            obj[id].originatingDate = $(this).data('datepicker').getFormattedDate('yyyy-mm-dd');
                        }
                        break;
                    case 'originatorArchiveId' :
                        if (value) {
                            obj[id].originatorArchiveId = value;
                        }
                        break;
                    case 'originatorOrgRegNumber' :
                        if (value) {
                            obj[id].originatorId = value;
                        }
                        break;
                    case 'filePlanPosition' :
                        if (value) {
                            obj[id].folderPath = value;
                        }
                        break;
                    case 'parentArchiveId' :
                        if (value) {
                            obj[id].parentArchiveId = value;
                        }
                        break;
                    case 'retentionRuleCode' :
                        if (value) {
                            obj[id].managementMetadata.appraisalRule.code = value;
                        }
                        break;
                    case 'retentionStartDate' :
                        if (value) {
                            obj[id].managementMetadata.appraisalRule.startDate = $(this).data('datepicker').getFormattedDate('yyyy-mm-dd');
                        }
                        break;
Alexandre Morin's avatar
Alexandre Morin committed
515
516
517
518
519
520
                }
            });

            var selectedProfile = $('#archivalProfile').data('json');

            if (selectedProfile !== undefined && selectedProfile !== null && selectedProfile !== "") {
521
                obj[id].descriptionClass = selectedProfile.descriptionClass;
Alexandre Morin's avatar
Alexandre Morin committed
522
                if (selectedProfile.fileplanLevel != null) {
523
524
525
526
527
                    if (selectedProfile.fileplanLevel === 'file') {
                        obj[id].archiveType = 'container';
                    } else {
                        obj[id].archiveType = 'item';
                    }
Alexandre Morin's avatar
Alexandre Morin committed
528
529
530
                }
            }

531
            if (!obj[id].archiveType) {
Alexis Ragot's avatar
Alexis Ragot committed
532
                obj[id].archiveType = 'container';
533
534
            }

535
536
            obj[id].descriptionObject = Metadata.serialize($('#allFields'));
            if (obj[id].descriptionObject === true) {
Alexandre Morin's avatar
Alexandre Morin committed
537
538
539
                return -1;
            }

540
            data.messageFile.binaryDataObject = DocumentList.asyncSerialize();
Alexandre Morin's avatar
Alexandre Morin committed
541
542

            if (selectedProfile !== undefined && selectedProfile !== null && selectedProfile !== "") {
543
                if (obj[id].archiveType === 'item' && data.messageFile.binaryDataObject==null) {
Alexandre Morin's avatar
Alexandre Morin committed
544
545
546
547
548
                    gritter.show($('#documentMissing_error').text(), false);
                    return -2;
                }
            }

549
            if (!selectedProfile && !obj[id].archiveName && !obj[id].originatorArchiveId && !obj[id].originatingDate && data.messageFile.binaryDataObject == null) {
Alexandre Morin's avatar
Alexandre Morin committed
550
551
552
553
                gritter.show($("#message_requiredFieldOnEmptyForm").text(), false);
                return -3;
            }

554
            $.each(data.messageFile.binaryDataObject, function(index, value) {
Alexis Ragot's avatar
Alexis Ragot committed
555
                obj[id].dataObjects.push(index);
556
557
558
            });

            data.messageFile.descriptiveMetadata[id] = obj[id];
559
            data.messageFile = btoa(unescape(encodeURIComponent(JSON.stringify(data.messageFile))));
Alexandre Morin's avatar
Alexandre Morin committed
560
561
            return data;
        },
Cyril Vazquez's avatar
Cyril Vazquez committed
562
        clear : function() {
563
            $('#retentionRule').removeAttr("disabled");
564
            $('#archiveForm, #managementMetadataForm').find('.archiveInput').not('[name="filePlanPosition"]').val('').change();
565
            $("#import_archivalProfile").text("");
Cyril Vazquez's avatar
Cyril Vazquez committed
566

Alexis Ragot's avatar
Alexis Ragot committed
567
            DocumentList.clear();
Cyril Vazquez's avatar
Cyril Vazquez committed
568
569
570
            Metadata.clear($('#allFields'));
        }
    }
571

572
    $("#originatorOrgRegNumber").on('change', function() {
573
574
        var archivalProfile = $('#archivalProfile');
        archivalProfile.empty();
575
        var option = $('<option/>').val("").text("").appendTo(archivalProfile);
576
        var originatorOrgRegNumber = $("#archiveForm").find("[name=originatorOrgRegNumber]").val();
577
        var archivalProfileToEdit = $('#archivalProfileToEdit').val();
578
579
580
581
582
583
        if (originatorOrgRegNumber && !$('#parentArchiveId').val()) {
            $.ajax({
                type: 'GET',
                url: '/orgunitprofiles?orgRegNumber=' + originatorOrgRegNumber,
                dataType: 'json',
                contentType: 'application/json',
584
                async: false,
585
                success: function (response) {    
586
587
588
                    $.each(response, function(index, profile){
                        addSelectProfiles(profile);
                    })
589
                    archivalProfile.val(archivalProfileToEdit).change();
590
591
                }
            });
592
593
        };
    });
594

595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
    function updateSelectProfilesFromArchivalProfileReference(archivalProfileReference) {
        var archivalProfile = $('#archivalProfile');
        archivalProfile.empty();
        var option = $('<option/>').val("").text("").appendTo(archivalProfile);

        if (archivalProfileReference) {
            $.ajax({
                type        : 'GET',
                url         : "/profilebyreference/" + archivalProfileReference,
                dataType    : 'json',
                async       : false,
                success     : function (response) {
                    $.each(response.containedProfiles, function(index, profile){
                        addSelectProfiles(profile);
                    })
                }   
            });
        } else {
            addSelectProfiles("*");
        }
    };

617
    function addSelectProfiles(profile){
618
        var archivalProfile = $('#archivalProfile');
619
620
        if (profile === "*") {
            var option = $('<option/>')
621
            .val("")
622
            .text("Sans profil")
623
            .appendTo(archivalProfile);
624
625
626
627
        } else {
            var option = $('<option/>')
            .val(profile.reference)
            .text(profile.name)
628
            .appendTo(archivalProfile);
629
630
631
        }
    }

632
633
634
635
    $("#archivalProfile").on('change', function () {
        var archivalProfileText = $("#archivalProfile").find('option:selected').text();
        var archivalProfileValue = $("#archivalProfile").val();
        if (archivalProfileValue === "") {
636
            $("#import_archivalProfile").text("");
637
638
639
640
641
            $('#archivalProfileFields').empty();
        } else if (archivalProfileValue != null) {
            $('#archivalProfile').val(archivalProfileValue);
            $("#import_archivalProfile").text(archivalProfileText);
            ArchiveForm.loadProfile();
642
643
        }
    });
644
</script>