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 | 1×
1×
1×
1×
882×
882×
1×
882×
882×
1×
882×
882×
882×
882×
1×
882×
12×
12×
12×
12×
1×
126650×
1×
1×
1×
1×
1×
1×
1×
1×
5×
5×
5×
5×
5×
5×
5×
5×
5×
1×
5×
5×
5×
5×
3×
3×
3×
3×
3×
3×
3×
3×
3×
3×
3×
4×
5×
1×
3×
3×
3×
3×
1×
5×
5×
5×
5×
5×
5×
5×
5×
5×
5×
5×
5×
5×
5×
5×
5×
5×
5×
5×
5×
1×
1×
| define(["require", "exports", "../index", "../../workbook/common/event", "@syncfusion/ej2-base"], function (require, exports, index_1, event_1, ej2_base_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Save = (function () {
function Save(parent) {
this.parent = parent;
this.addEventListener();
}
Save.prototype.destroy = function () {
this.removeEventListener();
this.parent = null;
};
Save.prototype.addEventListener = function () {
this.parent.on(event_1.beginSave, this.initiateSave, this);
this.parent.on(event_1.saveCompleted, this.saveCompleted, this);
this.parent.on(event_1.saveError, this.showErrorDialog, this);
this.parent.on(event_1.exportDialog, this.exportDialog, this);
};
Save.prototype.removeEventListener = function () {
if (!this.parent.isDestroyed) {
this.parent.off(event_1.beginSave, this.initiateSave);
this.parent.off(event_1.saveCompleted, this.saveCompleted);
this.parent.off(event_1.saveError, this.showErrorDialog);
this.parent.off(event_1.exportDialog, this.exportDialog);
}
};
Save.prototype.getModuleName = function () {
return 'save';
};
Save.prototype.initiateSave = function () {
this.parent.showSpinner();
};
Save.prototype.saveCompleted = function () {
this.parent.hideSpinner();
};
Save.prototype.showErrorDialog = function (args) {
var _this = this;
var dialogInst = this.parent.serviceLocator.getService(index_1.dialog);
dialogInst.show({
isModal: true, showCloseIcon: true, height: 180, width: 400, content: args.content,
beforeOpen: function () { return index_1.focus(_this.parent.element); }
});
};
Save.prototype.exportDialog = function (args) {
var _this = this;
var l10n = this.parent.serviceLocator.getService(index_1.locale);
var dialogInst = this.parent.serviceLocator.getService(index_1.dialog);
var type = args ? args.item.id.split(this.parent.element.id + '_')[1] : 'xlsx';
Eif (ej2_base_1.isNullOrUndefined(this.parent.element.querySelector('.e-find-dlg'))) {
var dlg = {
isModal: true, showCloseIcon: true, cssClass: 'e-open-dlg',
header: l10n.getConstant('SaveAs'),
beforeOpen: function (args) {
var dlgArgs = {
dialogName: l10n.getConstant('SaveAs'),
element: args.element, target: args.target, cancel: args.cancel
};
_this.parent.trigger('dialogBeforeOpen', dlgArgs);
if (dlgArgs.cancel) {
args.cancel = true;
}
dialogInst.dialogInstance.content = _this.OpenContent(type);
dialogInst.dialogInstance.dataBind();
_this.parent.element.querySelector('.e-text-open').setSelectionRange(0, _this.parent.element.querySelector('.e-text-open').value.length);
index_1.focus(_this.parent.element);
},
buttons: [{
buttonModel: {
content: l10n.getConstant('Save'), isPrimary: true, cssClass: 'e-btn-open-ok'
},
click: function () {
var name = _this.parent.element.querySelector('.e-text-open').value;
Iif (_this.checkValidName(name)) {
dialogInst.hide();
var type_1 = args ? args.item.id.split(_this.parent.element.id + "_")[1] : 'Xlsx';
_this.parent.save({ saveType: type_1, fileName: name });
}
else {
var saveButton = _this.parent.element.querySelector('.e-btn-open-ok');
var saveButtonObj = ej2_base_1.getComponent(saveButton, 'btn');
saveButtonObj.disabled = true;
var l10n_1 = _this.parent.serviceLocator.getService(index_1.locale);
var error = name.length === 0 ? l10n_1.getConstant('EmptyFileName') :
(name.length > 218 ? l10n_1.getConstant('LargeName') : l10n_1.getConstant('FileNameError'));
var fileSpan = _this.parent.createElement('span', { className: 'e-file-alert-span' });
fileSpan.innerText = error;
Iif (_this.parent.element.querySelector('.e-file-alert-span')) {
_this.parent.element.querySelector('.e-file-alert-span').remove();
}
(_this.parent.element.querySelector('.e-open-dlg').querySelector('.e-dlg-content')).appendChild(fileSpan);
}
}
}], close: function () {
dialogInst.hide();
}
};
dialogInst.show(dlg);
}
else {
dialogInst.hide();
}
};
Save.prototype.checkValidName = function (name) {
var isValidName = true;
Eif (name.match(new RegExp('.*[\\[\\]\\*\\\\/\\?\\:\\<\\>\\|\\"].*')) || name.length < 1 || name.length > 218) {
isValidName = false;
}
return isValidName;
};
Save.prototype.OpenContent = function (type) {
var _this = this;
var l10n = this.parent.serviceLocator.getService(index_1.locale);
var dialogElem = this.parent.createElement('div', { className: 'e-open-dialog' });
var openTextHeader = this.parent.createElement('div', { className: 'e-open-head' });
var openTextE = this.parent.createElement('div', { className: 'e-input-group' });
dialogElem.appendChild(openTextHeader);
dialogElem.appendChild(openTextE);
var header = l10n.getConstant('FileName');
var id = this.parent.element.id + "_filename";
var openTextH = this.parent.createElement('p', { className: 'e-header', id: id, attrs: { 'aria-label': l10n.getConstant('SaveAs') + " " + header } });
openTextH.innerText = header;
var openTextIp = this.parent.createElement('input', { className: 'e-input e-text-open', attrs: { 'type': 'Text', 'aria-labelledby': id } });
var openTextSpan = this.parent.createElement('span', { className: 'e-input-group-icon' });
openTextIp.onkeyup = function (e) {
if (_this.parent.element.querySelector('.e-file-alert-span') && e.keyCode !== 13) {
var saveButton = _this.parent.element.querySelector('.e-btn-open-ok');
var buttonObj = ej2_base_1.getComponent(saveButton, 'btn');
buttonObj.disabled = false;
_this.parent.element.querySelector('.e-file-alert-span').remove();
}
};
openTextHeader.appendChild(openTextH);
openTextSpan.textContent = '.' + type.toLowerCase();
openTextE.appendChild(openTextIp);
openTextIp.setAttribute('value', 'Sample');
openTextE.appendChild(openTextSpan);
return dialogElem;
};
return Save;
}());
exports.Save = Save;
});
|