Newer
Older
import { Pipe, PipeTransform, Component, OnInit, NgZone } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { DomSanitizer } from '@angular/platform-browser';
import { Router, ActivatedRoute } from '@angular/router';
declare function lockDocument(resId: number) : void;
declare function unlockDocument(resId: number) : void;
declare function valid_action_form(a1: string, a2: string, a3: string, a4: number, a5: string, a6: string, a7: string, a8: string, a9: boolean, a10: any) : void;
declare function $j(selector: string) : any;
declare function successNotification(message: string) : void;
declare function errorNotification(message: string) : void;
declare function showAttachmentsForm(path: string) : void;
declare function modifyAttachmentsForm(path: string, width: string, height: string) : void;

Damien
committed
declare var angularGlobals : any;
@Pipe({ name: 'safeUrl' })
export class SafeUrlPipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {}
transform(url: string) {
return this.sanitizer.bypassSecurityTrustResourceUrl(url);
}
}
@Component({
templateUrl: angularGlobals["signature-bookView"],
})
export class SignatureBookComponent implements OnInit {
signatureBook: any = {
currentAction : {},
consigne : "",
documents : [],

Damien
committed
resListIndex : 0,
};
rightSelectedThumbnail : number = 0;
leftSelectedThumbnail : number = 0;
rightViewerLink : string = "";
leftViewerLink : string = "";
headerTab : number = 1;
showTopRightPanel : boolean = false;
showTopLeftPanel : boolean = false;
showResLeftPanel : boolean = true;
showLeftPanel : boolean = true;
showSignaturesPanel : boolean = false;
loading : boolean = false;
loadingSign : boolean = false;
leftContentWidth : string = "44%";
rightContentWidth : string = "44%";
notesViewerLink : string = "";
visaViewerLink : string = "";
histViewerLink : string = "";
constructor(public http: HttpClient, private route: ActivatedRoute, private router: Router, private zone: NgZone) {
window['angularSignatureBookComponent'] = {
componentAfterAttach: (value: string) => this.processAfterAttach(value),
componentAfterAction: () => this.processAfterAction(),
componentAfterNotes: () => this.processAfterNotes()
prepareSignatureBook() {
$j('#inner_content').remove();
$j('#header').remove();
$j('#viewBasketsTitle').remove();
$j('#homePageWelcomeTitle').remove();
$j('#footer').remove();

Damien
committed
ngOnInit() : void {

Damien
committed
this.coreUrl = angularGlobals.coreUrl;
this.loading = true;

Damien
committed
this.route.params.subscribe(params => {
this.resId = +params['resId'];
this.basketId = params['basketId'];
this.signatureBook.resList = []; // This line is added because of manage action behaviour (processAfterAction is called twice)
setInterval(() => {lockDocument(this.resId)}, 50000);
this.http.get(this.coreUrl + "rest/groups/" + this.groupId + "/baskets/" + this.basketId + '/signatureBook/' + this.resId)

Damien
committed
104
105
106
107
108
109
110
111
112
113
114
115
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
if (data.error) {
location.hash = "";
location.search = "";
return;
}
this.signatureBook = data;
this.headerTab = 1;
this.leftSelectedThumbnail = 0;
this.rightSelectedThumbnail = 0;
this.leftViewerLink = "";
this.rightViewerLink = "";
this.showLeftPanel = true;
this.showRightPanel = true;
this.showResLeftPanel = true;
this.showTopLeftPanel = false;
this.showTopRightPanel = false;
this.showAttachmentPanel = false;
this.notesViewerLink = "index.php?display=true&module=notes&page=notes&identifier=" + this.resId + "&origin=document&coll_id=letterbox_coll&load&size=full";
this.visaViewerLink = "index.php?display=true&page=show_visa_tab&module=visa&resId=" + this.resId + "&collId=letterbox_coll&visaStep=true";
this.histViewerLink = "index.php?display=true&page=show_history_tab&resId=" + this.resId + "&collId=letterbox_coll";
this.linksViewerLink = "index.php?display=true&page=show_links_tab&id=" + this.resId;
this.attachmentsViewerLink = "index.php?display=true&module=attachments&page=frame_list_attachments&resId=" + this.resId + "&noModification=true&template_selected=documents_list_attachments_simple&load&attach_type_exclude=converted_pdf,print_folder";
this.leftContentWidth = "44%";
this.rightContentWidth = "44%";
if (this.signatureBook.documents[0]) {
this.leftViewerLink = this.signatureBook.documents[0].viewerLink;
if (this.signatureBook.documents[0].category_id == "outgoing") {
this.headerTab = 3;
}
}
if (this.signatureBook.attachments[0]) {
this.rightViewerLink = this.signatureBook.attachments[0].viewerLink;
}
this.displayPanel("RESLEFT");
this.loading = false;
setTimeout(() => {
$j("#rightPanelContent").niceScroll({touchbehavior:false, cursorcolor:"#666", cursoropacitymax:0.6, cursorwidth:4});
if ($j(".tooltipstered").length == 0) {
$j("#obsVersion").tooltipster({
interactive: true
});
}

Damien
committed
}, 0);
}, (err) => {
errorNotification(JSON.parse(err._body).errors);
setTimeout(() => {
this.backToBasket();
}, 2000);
ngOnDestroy() : void {
delete window['angularSignatureBookComponent'];
}
processAfterAttach(mode: string) {
this.zone.run(() => this.refreshAttachments(mode));
}
processAfterAction() {
var idToGo = -1;
var c = this.signatureBook.resList.length;
for (let i = 0; i < c; i++) {
if (this.signatureBook.resList[i].res_id == this.resId) {
if (this.signatureBook.resList[i + 1]) {
idToGo = this.signatureBook.resList[i + 1].res_id;
} else if (i > 0) {
idToGo = this.signatureBook.resList[i - 1].res_id;
}
}
}
if (c > 0) { // This (if)line is added because of manage action behaviour (processAfterAction is called twice)
unlockDocument(this.resId);
if (idToGo >= 0) {
$j("#send").removeAttr("disabled");
$j("#send").css("opacity", "1");
this.zone.run(() => this.changeLocation(idToGo, "action"));
} else {
this.zone.run(() => this.backToBasket());
}
}
changeSignatureBookLeftContent(id: number) {
this.headerTab = id;
this.showTopLeftPanel = false;
}
changeRightViewer(index: number) {
if (this.signatureBook.attachments[index]) {
this.rightViewerLink = this.signatureBook.attachments[index].viewerLink;
} else {
this.rightViewerLink = "";
}
this.rightSelectedThumbnail = index;
}
changeLeftViewer(index: number) {
this.leftViewerLink = this.signatureBook.documents[index].viewerLink;
this.leftSelectedThumbnail = index;
}
displayPanel(panel: string) {
if (panel == "TOPRIGHT") {
this.showTopRightPanel = !this.showTopRightPanel;
} else if (panel == "TOPLEFT") {
this.showTopLeftPanel = !this.showTopLeftPanel;
} else if (panel == "LEFT") {
this.showLeftPanel = !this.showLeftPanel;
this.showResLeftPanel = false;
$j("#hideLeftContent").css('background', 'none');
this.rightContentWidth = "48%";
this.leftContentWidth = "48%";
$j("#hideLeftContent").css('background', '#CEE9F1');
} else if (panel == "RESLEFT") {
this.showResLeftPanel = !this.showResLeftPanel;
this.rightContentWidth = "48%";
this.leftContentWidth = "48%";
this.rightContentWidth = "44%";
this.leftContentWidth = "44%";
if (this.signatureBook.resList.length == 0 || this.signatureBook.resList[0].allSigned == null) {
this.http.get(this.coreUrl + 'rest/' + this.basketId + '/signatureBook/resList/details')

Damien
committed
this.signatureBook.resList = data.resList;
this.signatureBook.resList.forEach((value: any, index: number) => {
if (value.res_id == this.resId) {
this.signatureBook.resListIndex = index;
}
});
setTimeout(() => {
$j("#resListContent").niceScroll({touchbehavior:false, cursorcolor:"#666", cursoropacitymax:0.6, cursorwidth:4});
$j("#resListContent").scrollTop(0);
$j("#resListContent").scrollTop($j(".resListContentFrameSelected").offset().top - 42);
}, 0);
});
}
}
} else if (panel == "MIDDLE") {
this.showRightPanel = !this.showRightPanel;
this.showResLeftPanel = false;
if (!this.showRightPanel) {
this.leftContentWidth = "96%";
$j("#contentLeft").css('border-right', 'none');
} else {
this.rightContentWidth = "48%";
this.leftContentWidth = "48%";
$j("#contentLeft").css('border-right', 'solid 1px');
displayAttachmentPanel() {
this.showAttachmentPanel = !this.showAttachmentPanel;
this.rightSelectedThumbnail = 0;
if (this.signatureBook.attachments[0]) {
this.rightViewerLink = this.signatureBook.attachments[0].viewerLink;
}
}
refreshAttachments(mode: string) {
if (mode == "rightContent") {
this.http.get(this.coreUrl + 'rest/signatureBook/' + this.resId + '/incomingMailAttachments')
this.signatureBook.documents = data;
});
} else {
this.http.get(this.coreUrl + 'rest/signatureBook/' + this.resId + '/attachments')
var i = 0;
if (mode == "add") {
var found = false;
data.forEach((elem: any, index: number) => {
if (!found && (!this.signatureBook.attachments[index] || elem.res_id != this.signatureBook.attachments[index].res_id)) {
i = index;
found = true;
}
});
} else if (mode == "edit") {
var id = this.signatureBook.attachments[this.rightSelectedThumbnail].res_id;
data.forEach((elem: any, index: number) => {
if (elem.res_id == id) {
i = index;
}
});
}
this.signatureBook.attachments = data;
if (mode == "add" || mode == "edit") {
this.changeRightViewer(i);
} else if (mode == "del") {
this.changeRightViewer(0);
}
});
}
}
addAttachmentIframe() {
showAttachmentsForm('index.php?display=true&module=attachments&page=attachments_content&docId=' + this.resId);
}
editAttachmentIframe(attachment: any) {
if (attachment.canModify && attachment.status != "SIGN") {
var resId: number;
if (attachment.res_id == 0) {
resId = attachment.res_id_version;
} else if (attachment.res_id_version == 0) {
resId = attachment.res_id;
}
modifyAttachmentsForm('index.php?display=true&module=attachments&page=attachments_content&id=' + resId + '&relation=' + attachment.relation + '&docId=' + this.resId, '98%', 'auto');
}
}
delAttachment(attachment: any) {
if (attachment.canDelete) {

Damien
committed
if (this.signatureBook.attachments.length <= 1) {
var r = confirm('Attention, ceci est votre dernière pièce jointe pour ce courrier, voulez-vous vraiment la supprimer ?');
} else {
var r = confirm('Voulez-vous vraiment supprimer la pièce jointe ?');
}
if (r) {
var resId: number;
if (attachment.res_id == 0) {
resId = attachment.res_id_version;
} else if (attachment.res_id_version == 0) {
resId = attachment.res_id;
}
this.http.get('index.php?display=true&module=attachments&page=del_attachment&id=' + resId + '&relation=' + attachment.relation + '&rest=true')
.subscribe(() => {
this.refreshAttachments('del');
});
}
refreshNotes() {
this.http.get(this.coreUrl + 'rest/res/' + this.resId + '/notes/count')
this.signatureBook.nbNotes = data;
});
}
signFile(attachment: any, signature: any) {
if (!this.loadingSign && this.signatureBook.canSign) {
this.loadingSign = true;
var path = "index.php?display=true&module=visa&page=sign_file&collId=letterbox_coll&resIdMaster=" + this.resId + "&signatureId=" + signature.id;
if (attachment.res_id == 0) {
if (attachment.attachment_type == "outgoing_mail" && this.signatureBook.documents[0].category_id == "outgoing") {
path += "&isVersion&isOutgoing&id=" + attachment.res_id_version;
path += "&isVersion&id=" + attachment.res_id_version;
} else if (attachment.res_id_version == 0) {
if (attachment.attachment_type == "outgoing_mail" && this.signatureBook.documents[0].category_id == "outgoing") {
path += "&isOutgoing&id=" + attachment.res_id;
path += "&id=" + attachment.res_id;
this.http.get(path, signature)
if (data.status == 0) {
this.rightViewerLink = "index.php?display=true&module=attachments&page=view_attachment&res_id_master=" + this.resId + "&id=" + data.new_id + "&isVersion=false";
this.signatureBook.attachments[this.rightSelectedThumbnail].viewerLink = this.rightViewerLink;
this.signatureBook.attachments[this.rightSelectedThumbnail].status = 'SIGN';
this.signatureBook.attachments[this.rightSelectedThumbnail].idToDl = data.new_id;
var allSigned = true;
this.signatureBook.attachments.forEach((value: any) => {
if (value.sign && value.status != 'SIGN') {
allSigned = false;
}
});

Damien
committed
if (this.signatureBook.resList.length > 0) {
this.signatureBook.resList[this.signatureBook.resListIndex].allSigned = allSigned;
}
} else {
alert(data.error);
}
this.loadingSign = false;
});
}
}
unsignFile(attachment: any) {
var collId: string;
var resId: number;
if (attachment.res_id == 0) {
resId = attachment.res_id_version;
collId = "res_version_attachments";
} else if (attachment.res_id_version == 0) {
resId = attachment.res_id;
collId = "res_attachments";
this.http.put(this.coreUrl + 'rest/' + collId + '/' + resId + '/unsign', {})
.subscribe(() => {
this.rightViewerLink = "index.php?display=true&module=attachments&page=view_attachment&res_id_master=" + this.resId + "&id=" + attachment.viewerNoSignId + "&isVersion=" + isVersion;
this.signatureBook.attachments[this.rightSelectedThumbnail].viewerLink = this.rightViewerLink;
this.signatureBook.attachments[this.rightSelectedThumbnail].status = 'A_TRA';
this.signatureBook.attachments[this.rightSelectedThumbnail].idToDl = resId;
if (this.signatureBook.resList.length > 0) {
this.signatureBook.resList[this.signatureBook.resListIndex].allSigned = false;

Damien
committed
unlockDocument(this.resId);

Damien
committed
unlockDocument(this.resId);
location.hash = "";
location.search = "?page=details&dir=indexing_searching&id=" + this.resId;
}
changeLocation(resId: number, origin: string) {
this.http.get(this.coreUrl + 'rest/res/' + resId + '/lock')
if (!data.lock) {
let path = "/groups/" + this.groupId + "/baskets/" + this.basketId + '/signatureBook/' + resId;
this.router.navigate([path]);
} else {
if (origin == "view") {
alert("Courrier verrouillé par " + data.lockBy);
alert("Courrier suivant verrouillé par " + data.lockBy);
}
validForm() {
if ($j("#signatureBookActions option:selected")[0].value != "") {
if (this.signatureBook['listinstance']['requested_signature'] == true) {
this.http.get(this.coreUrl + 'rest/listinstance/' + this.signatureBook['listinstance']['listinstance_id'])
.subscribe((data: any) => {
var r = true;
if (data['signatory'] == false) {
r = confirm("Vous n’avez signé aucun document. Êtes-vous sûr de vouloir continuer ?");
}
if (r) {
this.sendActionForm();
}

Damien
committed
});
this.sendActionForm();

Damien
committed
}
} else {
alert("Aucune action choisie");
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
sendActionForm() {
unlockDocument(this.resId);
if (this.signatureBook.resList.length == 0) {
this.http.get(this.coreUrl + 'rest/' + this.basketId + '/signatureBook/resList')
.subscribe((data: any) => {
this.signatureBook.resList = data.resList;
valid_action_form(
'empty',
'index.php?display=true&page=manage_action&module=core',
this.signatureBook.currentAction.id,
this.resId,
'res_letterbox',
'null',
'letterbox_coll',
'page',
false,
[$j("#signatureBookActions option:selected")[0].value]
);
});
} else {
valid_action_form(
'empty',
'index.php?display=true&page=manage_action&module=core',
this.signatureBook.currentAction.id,
this.resId,
'res_letterbox',
'null',
'letterbox_coll',
'page',
false,
[$j("#signatureBookActions option:selected")[0].value]
);
}
}