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
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 | 1×
1×
1×
1×
1748×
1748×
1×
1748×
1748×
1748×
1×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
1×
7×
7×
7×
7×
7×
7×
7×
3×
3×
3×
4×
3×
3×
3×
7×
7×
7×
4×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
1×
3476×
1729×
1747×
1747×
1747×
1747×
2×
2×
1×
32470×
1×
1×
| define(["require", "exports", "../base/constant", "@syncfusion/ej2-inputs"], function (require, exports, events, ej2_inputs_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ImportExport = (function () {
function ImportExport(parent) {
this.parent = parent;
this.addEventListener();
}
ImportExport.prototype.addEventListener = function () {
this.parent.on(events.onImport, this.onImport, this);
this.parent.on(events.onExport, this.onExport, this);
this.parent.on(events.destroy, this.destroy, this);
};
ImportExport.prototype.onImport = function () {
var _this = this;
this.uploaderObj = new ej2_inputs_1.Uploader({
allowedExtensions: '.doc,.docx,.rtf,.dot,.dotx,.docm,.dotm',
asyncSettings: {
saveUrl: this.parent.importWord.serviceUrl
},
success: function (args) {
_this.parent.executeCommand('importWord', args.e.currentTarget.response, { undo: true });
}
});
this.parent.setProperties({ enableXhtml: true }, true);
var uploadParentEle = this.parent.createElement('div', { className: 'e-import-uploadwrap e-droparea' + this.parent.getCssClass(true) });
var uploadEle = this.parent.createElement('input', {
id: this.rteID + '_upload', attrs: { type: 'File', name: 'UploadFiles' }, className: this.parent.getCssClass()
});
uploadParentEle.appendChild(uploadEle);
this.uploaderObj.appendTo(uploadEle);
this.uploaderObj.element.click();
this.uploaderObj.element.closest('.e-upload').style.display = 'none';
};
ImportExport.prototype.onExport = function (args) {
var _this = this;
var filename;
var serviceUrl;
this.parent.setProperties({ enableXhtml: true }, true);
var rteHtmlData = this.parent.getHtml();
var html;
if (args.member === 'ExportWord') {
filename = this.parent.exportWord.fileName;
serviceUrl = this.parent.exportWord.serviceUrl;
html = "<html><head><style>" + this.parent.exportWord.stylesheet + "</style></head><body>" + rteHtmlData + "</body></html>";
}
else if (args.member === 'ExportPdf') {
filename = this.parent.exportPdf.fileName;
serviceUrl = this.parent.exportPdf.serviceUrl;
html = "<html><head><style>" + this.parent.exportPdf.stylesheet + "</style></head><body>" + rteHtmlData + "</body></html>";
}
var actionBegin = {
requestType: args.member,
exportValue: html,
cancel: false
};
this.parent.trigger(events.actionBegin, actionBegin, function (actionBeginArgs) {
if (!actionBeginArgs.cancel) {
fetch(serviceUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ html: actionBeginArgs.exportValue })
})
.then(function (response) {
Iif (!response.ok) {
throw new Error("HTTP error! Status: " + response.status);
}
return response.blob().then(function (blob) { return ({ blob: blob, filename: filename }); });
})
.then(function (_a) {
var blob = _a.blob, filename = _a.filename;
var url = window.URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
_this.parent.trigger(events.actionComplete, { requestType: args.member });
})
.catch(function (error) {
console.error('Fetch error:', error);
});
}
});
};
ImportExport.prototype.destroy = function () {
if (this.parent.isDestroyed) {
return;
}
this.parent.off(events.onImport, this.onImport);
this.parent.off(events.onExport, this.onExport);
this.parent.off(events.destroy, this.destroy);
if (this.uploaderObj && !this.uploaderObj.isDestroyed) {
this.uploaderObj.destroy();
this.uploaderObj = null;
}
};
ImportExport.prototype.getModuleName = function () {
return 'importExport';
};
return ImportExport;
}());
exports.ImportExport = ImportExport;
});
|