| 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
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
145
146
147
148
149
150
151
152
153
154
155
156
157 | 1×
1×
1×
1×
3197×
3197×
1×
3197×
3197×
3197×
1×
6×
6×
6×
6×
5×
5×
1×
1×
5×
5×
5×
5×
5×
5×
5×
5×
5×
5×
1×
9×
9×
5×
4×
1×
12×
12×
12×
12×
12×
12×
12×
6×
6×
6×
6×
5×
5×
5×
12×
12×
12×
9×
9×
9×
9×
3×
3×
3×
9×
9×
8×
8×
8×
8×
8×
8×
8×
8×
8×
8×
4×
8×
8×
8×
8×
8×
1×
1×
1×
1×
1×
1×
6368×
3172×
3196×
3196×
3196×
3196×
5×
5×
1×
69991×
1×
1×
| define(["require", "exports", "../base/constant", "@syncfusion/ej2-inputs", "../../common/export-styles", "@syncfusion/ej2-base", "@syncfusion/ej2-splitbuttons"], function (require, exports, events, ej2_inputs_1, export_styles_1, ej2_base_1, ej2_splitbuttons_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;
var actionBegin = {
cancel: false,
requestType: 'Import'
};
this.parent.trigger(events.actionBegin, actionBegin, function (actionBeginArgs) {
if (!actionBeginArgs.cancel) {
Eif (ej2_base_1.isNullOrUndefined(_this.uploaderObj)) {
_this.uploaderObj = new ej2_inputs_1.Uploader({
allowedExtensions: '.doc,.docx,.rtf,.dot,.dotx,.docm,.dotm',
asyncSettings: {
saveUrl: _this.parent.importWord.serviceUrl
},
uploading: function (e) {
Eif (!_this.parent.isServerRendered) {
_this.parent.trigger(events.wordImporting, e);
}
},
success: function (args) {
_this.parent.executeCommand('importWord', args.e.currentTarget.response, { undo: true });
_this.parent.trigger(events.actionComplete, { requestType: 'Import' });
_this.parent.notify(events.count, {});
}
});
}
_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.getExportProgressButton = function (member) {
var toolbarItem = this.parent.element.querySelector("#" + this.parent.element.id + "_toolbar_" + member);
if (!ej2_base_1.isNullOrUndefined(toolbarItem)) {
return ej2_base_1.getComponent(toolbarItem, ej2_splitbuttons_1.ProgressButton);
}
return null;
};
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 + export_styles_1.EXPORT_STYLES) + "</style></head><body><div class=\"e-content\">" + rteHtmlData + "</div></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 + export_styles_1.EXPORT_STYLES) + "</style></head><body><div class=\"e-content\">" + rteHtmlData + "</div></body></html>";
}
var actionBegin = {
requestType: args.member,
exportValue: html,
cancel: false
};
this.parent.trigger(events.actionBegin, actionBegin, function (actionBeginArgs) {
if (!actionBeginArgs.cancel) {
var exportArgs = {
exportType: (args.member === 'ExportPdf' ? 'PDF' : 'Word')
};
_this.parent.trigger(events.documentExporting, exportArgs);
var headers = {
'Content-Type': 'application/json'
};
if (exportArgs.currentRequest) {
for (var _i = 0, _a = exportArgs.currentRequest; _i < _a.length; _i++) {
var h = _a[_i];
Object.assign(headers, h);
}
}
var payload = exportArgs.customFormData
? { html: actionBeginArgs.exportValue, formData: exportArgs.customFormData }
: { html: actionBeginArgs.exportValue };
fetch(serviceUrl, {
method: 'POST',
headers: headers,
body: JSON.stringify(payload)
})
.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);
var btn = _this.getExportProgressButton(args.member);
if (!ej2_base_1.isNullOrUndefined(btn)) {
btn.progressComplete();
}
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
_this.parent.trigger(events.actionComplete, { requestType: args.member });
_this.parent.contentModule.getEditPanel().focus();
})
.catch(function (error) {
var btn = _this.getExportProgressButton(args.member);
Eif (!ej2_base_1.isNullOrUndefined(btn)) {
btn.progressComplete();
}
console.error('Fetch error:', error);
_this.parent.contentModule.getEditPanel().focus();
});
}
});
};
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;
});
|