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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185 | 1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
14×
1×
14×
14×
14×
14×
14×
54×
54×
53×
13×
13×
13×
13×
13×
13×
14×
14×
1×
14×
1×
8×
8×
8×
2×
2×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
8×
1×
1×
1×
1×
14×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-popups", "../../../document-editor/base/index", "../ribbon-base/ribbon-constants"], function (require, exports, ej2_base_1, ej2_popups_1, index_1, ribbon_constants_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FILE_MENU_ID = 'file_menu';
exports.NEW_DOCUMENT_ID = 'new';
exports.OPEN_DOCUMENT_ID = 'open';
exports.EXPORT_ID = 'export';
exports.EXPORT_SFDT_ID = 'export_sfdt';
exports.EXPORT_DOCX_ID = 'export_docx';
exports.EXPORT_DOTX_ID = 'export_dotx';
exports.EXPORT_TXT_ID = 'export_txt';
exports.PRINT_ID = 'print';
var FileMenu = (function () {
function FileMenu(container) {
this.container = container;
}
FileMenu.prototype.getFileMenuItems = function () {
var locale = this.container.localObj;
var fileMenuItems = [];
var commentId = this.container.element.id + ribbon_constants_1.RIBBON_ID;
var items = this.container.fileMenuItems;
for (var i = 0; i < items.length; i++) {
var item = items[i];
if (typeof item === 'string') {
switch (item) {
case 'New':
fileMenuItems.push({
text: locale.getConstant('New'),
iconCss: 'e-icons e-de-ctnr-new',
id: commentId + exports.NEW_DOCUMENT_ID
});
break;
case 'Open':
fileMenuItems.push({
text: locale.getConstant('Open'),
iconCss: 'e-icons e-de-ctnr-open',
id: commentId + exports.OPEN_DOCUMENT_ID
});
break;
case 'Export':
fileMenuItems.push({
text: locale.getConstant('Export'),
iconCss: 'e-icons e-de-ctnr-export',
id: commentId + exports.EXPORT_ID,
items: [
{ id: commentId + exports.EXPORT_SFDT_ID, text: locale.getConstant('Syncfusion Document Text (*.sfdt)') },
{ id: commentId + exports.EXPORT_DOCX_ID, text: locale.getConstant('Word Document (*.docx)') },
{ id: commentId + exports.EXPORT_DOTX_ID, text: locale.getConstant('Word Template (*.dotx)') },
{ id: commentId + exports.EXPORT_TXT_ID, text: locale.getConstant('Plain Text (*.txt)') }
]
});
break;
case 'Print':
fileMenuItems.push({
text: locale.getConstant('Print'),
iconCss: 'e-icons e-de-ctnr-print',
id: commentId + exports.PRINT_ID
});
break;
}
}
else {
fileMenuItems.push(item);
}
}
return fileMenuItems;
};
FileMenu.prototype.onFileMenuItemSelect = function (args) {
var locale = this.container.localObj;
Eif (args.item && args.item.id) {
switch (args.item.text) {
case locale.getConstant('New'):
this.container.documentEditor.openBlank();
break;
case locale.getConstant('Open'):
this.initializeFilePicker();
this.filePicker.value = '';
this.filePicker.click();
break;
case locale.getConstant('Print'):
this.container.documentEditor.print();
break;
case locale.getConstant('Word Document (*.docx)'):
this.container.documentEditor.save(this.container.documentEditor.documentName || 'Document', 'Docx');
break;
case locale.getConstant('Word Template (*.dotx)'):
this.container.documentEditor.save(this.container.documentEditor.documentName || 'Document', 'Dotx');
break;
case locale.getConstant('Syncfusion Document Text (*.sfdt)'):
this.container.documentEditor.save(this.container.documentEditor.documentName || 'Document', 'Sfdt');
break;
case locale.getConstant('Plain Text (*.txt)'):
this.container.documentEditor.save(this.container.documentEditor.documentName || 'Document', 'Txt');
break;
default:
this.container.trigger(index_1.fileMenuItemClickEvent, args);
break;
}
this.container.documentEditor.focusIn();
}
};
FileMenu.prototype.initializeFilePicker = function () {
if (!this.filePicker) {
this.filePicker = ej2_base_1.createElement('input', {
attrs: { type: 'file', accept: '.doc,.docx,.rtf,.txt,.htm,.html,.sfdt' },
className: 'e-de-ctnr-file-picker'
});
if (ej2_base_1.Browser.isIE) {
document.body.appendChild(this.filePicker);
}
ej2_base_1.EventHandler.add(this.filePicker, 'change', this.onFileChange, this);
}
};
FileMenu.prototype.onFileChange = function () {
var _this = this;
var file = this.filePicker.files[0];
var fileSize = file.size;
var check;
var eventArgs = { fileSize: fileSize, isCanceled: check };
this.container.documentEditor.trigger(index_1.beforeFileOpenEvent, eventArgs);
if (eventArgs.isCanceled) {
return;
}
if (file) {
var formatType_1 = file.name.substr(file.name.lastIndexOf('.'));
if (formatType_1 === '.sfdt' || formatType_1 === '.txt') {
var fileReader_1 = new FileReader();
fileReader_1.onload = function () {
if (formatType_1 === '.txt') {
_this.container.documentEditor.documentHelper.openTextFile(fileReader_1.result);
}
else {
_this.container.documentEditor.openAsync(fileReader_1.result);
}
};
fileReader_1.readAsText(file);
}
else {
if (this.isSupportedFormatType(formatType_1.toLowerCase())) {
this.container.documentEditor.open(file);
}
else {
var localizeValue = new ej2_base_1.L10n('documenteditor', this.container.documentEditor.defaultLocale);
ej2_popups_1.DialogUtility.alert({
content: localizeValue.getConstant('Unsupported format'),
closeOnEscape: true,
showCloseIcon: true,
position: { X: 'center', Y: 'center' }
}).enableRtl = this.container.enableRtl;
}
}
this.container.documentEditor.documentName = file.name.substr(0, file.name.lastIndexOf('.'));
}
};
FileMenu.prototype.isSupportedFormatType = function (formatType) {
switch (formatType) {
case '.dotx':
case '.docx':
case '.docm':
case '.dotm':
case '.dot':
case '.doc':
case '.rtf':
case '.txt':
case '.xml':
case '.html':
return true;
default:
return false;
}
};
FileMenu.prototype.destroy = function () {
Iif (this.filePicker) {
ej2_base_1.EventHandler.remove(this.filePicker, 'change', this.onFileChange);
if (this.filePicker.parentNode) {
this.filePicker.parentNode.removeChild(this.filePicker);
}
this.filePicker = null;
}
};
return FileMenu;
}());
exports.FileMenu = FileMenu;
});
|