Newer
Older
import { Component, OnInit, NgZone } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
declare function $j(selector: any) : any;
declare var angularGlobals : any;
@Component({
templateUrl : "../../../../Views/save-numeric-package.component.html",
// styleUrls : ['../../node_modules/bootstrap/dist/css/bootstrap.min.css', 'css/profile.component.css']
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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
})
export class SaveNumericPackageComponent implements OnInit {
coreUrl : string;
numericPackage : any = {
base64 : "",
name : "",
type : "",
size : 0,
label : "",
extension : "",
};
resultInfo : string = "";
loading : boolean = false;
constructor(public http: Http, private zone: NgZone) {
window['angularSaveNumericPackageComponent'] = {
componentAfterUpload: (base64Content: any) => this.processAfterUpload(base64Content),
};
}
preparePage() {
$j('#inner_content').remove();
$j('#menunav').hide();
$j('#divList').remove();
$j('#magicContactsTable').remove();
$j('#manageBasketsOrderTable').remove();
$j('#controlParamTechnicTable').remove();
$j('#container').width("99%");
if ($j('#content h1')[0] && $j('#content h1')[0] != $j('my-app h1')[0]) {
$j('#content h1')[0].remove();
}
}
updateBreadcrumb(applicationName: string) {
if ($j('#ariane')[0]) {
$j('#ariane')[0].innerHTML = "<a href='index.php?reinit=true'>" + applicationName + "</a> > Enregistrer un pli numérique";
}
}
ngOnInit(): void {
this.preparePage();
this.updateBreadcrumb(angularGlobals.applicationName);
this.coreUrl = angularGlobals.coreUrl;
this.loading = false;
}
processAfterUpload(b64Content: any) {
this.zone.run(() => this.resfreshUpload(b64Content));
}
resfreshUpload(b64Content: any) {
this.numericPackage.base64 = b64Content.replace(/^data:.*?;base64,/, "");
}
uploadNumericPackage(fileInput: any) {
if (fileInput.target.files && fileInput.target.files[0]) {
var reader = new FileReader();
this.numericPackage.name = fileInput.target.files[0].name;
this.numericPackage.size = fileInput.target.files[0].size;
this.numericPackage.type = fileInput.target.files[0].type;
this.numericPackage.extension = fileInput.target.files[0].name.split('.').pop();
if (this.numericPackage.label == "") {
this.numericPackage.label = this.numericPackage.name;
}
reader.readAsDataURL(fileInput.target.files[0]);
reader.onload = function (value: any) {
window['angularSaveNumericPackageComponent'].componentAfterUpload(value.target.result);
};
}
}
submitNumericPackage() {
if(this.numericPackage.size != 0) {
this.http.post(this.coreUrl + 'rest/saveNumericPackage', this.numericPackage)
.map(res => res.json())
.subscribe((data) => {
if (data.errors) {
this.resultInfo = data.errors;
$j('#resultInfo').removeClass().addClass('alert alert-danger alert-dismissible');
$j("#resultInfo").fadeTo(3000, 500).slideUp(500, function(){
$j("#resultInfo").slideUp(500);
});
} else {
this.numericPackage = {
base64 : "",
name : "",
type : "",
size : 0,
label : "",
extension : "",
};
$j("#numericPackageFilePath").val(null);
this.resultInfo = 'Pli numérique correctement importé';
$j('#resultInfo').removeClass().addClass('alert alert-success alert-dismissible');
$j("#resultInfo").fadeTo(3000, 500).slideUp(500, function(){
$j("#resultInfo").slideUp(500);
});
if(data.basketRedirection != null){
window.location.href = data.basketRedirection;
// action_send_first_request('index.php?display=true&page=manage_action&module=core', 'page', 22, '', 'res_letterbox', 'basket', 'letterbox_coll');
}
}
});
} else {
this.numericPackage.name = "";
this.numericPackage.size = 0;
this.numericPackage.type = "";
this.numericPackage.base64 = "";
this.numericPackage.extension = "";
this.resultInfo = "Aucun pli numérique séléctionné";
$j('#resultInfo').removeClass().addClass('alert alert-danger alert-dismissible');
$j("#resultInfo").fadeTo(3000, 500).slideUp(500, function(){
$j("#resultInfo").slideUp(500);
});
}
}
}