This repository was archived by the owner on Jul 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdocument-loader.ts
More file actions
49 lines (47 loc) · 2.05 KB
/
document-loader.ts
File metadata and controls
49 lines (47 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
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
import { DocumentEditor } from '@syncfusion/ej2-documenteditor';
/**
* Document editor - Document loader
*/
export class DocumentLoader {
private hostUrl: string = 'https://ej2services.syncfusion.com/production/web-services/';
private documentEditor: DocumentEditor = undefined;
constructor(documentEditor: DocumentEditor) {
this.documentEditor = documentEditor;
}
public loadDefault(defaultDocument: Object): void {
this.documentEditor.open(JSON.stringify(defaultDocument));
}
public loadFile(path: any): void {
let baseUrl: string = this.hostUrl + 'api/documenteditor/import';
let httpRequest: XMLHttpRequest = new XMLHttpRequest();
httpRequest.open('POST', baseUrl, true);
let waitingPopUp: HTMLElement = document.getElementById('waiting-popup');
let inActiveDiv: HTMLElement = document.getElementById('popup-overlay');
this.documentEditor.isReadOnly = true;
waitingPopUp.style.display = 'block';
inActiveDiv.style.display = 'block';
httpRequest.onreadystatechange = () => {
if (httpRequest.readyState === 4) {
if (httpRequest.status === 200 || httpRequest.status === 304) {
this.documentEditor.open(httpRequest.responseText);
this.documentEditor.isReadOnly = false;
waitingPopUp.style.display = 'none';
inActiveDiv.style.display = 'none';
} else {
waitingPopUp.style.display = 'none';
inActiveDiv.style.display = 'none';
this.documentEditor.isReadOnly = false;
console.error(httpRequest.response);
}
}
};
let formData: FormData = new FormData();
formData.append('files', path);
this.documentEditor.documentName = path.name.substr(0, path.name.lastIndexOf('.'));
httpRequest.send(formData);
}
public destroy(): void {
this.documentEditor = undefined;
this.hostUrl = undefined;
}
}