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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499 | 1×
1×
1×
1×
514×
514×
514×
514×
514×
514×
514×
514×
514×
514×
1×
1×
14461×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
4×
4×
1×
3×
4×
4×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
755×
1×
1×
755×
1×
1×
755×
1×
1×
755×
1×
1×
755×
1×
1×
1×
755×
755×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-navigations", "@syncfusion/ej2-dropdowns", "@syncfusion/ej2-popups"], function (require, exports, ej2_base_1, ej2_navigations_1, ej2_dropdowns_1, ej2_popups_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var XmlPane = (function () {
function XmlPane(documentHelper, isRtl) {
var _this = this;
this.isXmlPaneShow = false;
this.contextMenuInstance = undefined;
this.DropDownListData = [
{ ID: 'Choose', Value: 'Choose an XML file' },
{ ID: 'Add', Value: '(Add new part...)' }
];
this.hierarchicalData = [];
this.field = {
dataSource: this.hierarchicalData,
id: 'id',
text: 'displayText',
hasChildren: 'hasChild',
value: "displayValue",
parentID: 'pid',
tooltip: 'tooltip',
};
this.handleFileSelect = function () {
var input = document.createElement('input');
input.type = 'file';
input.accept = '.xml';
input.onchange = function (e) {
var target = e.target;
if (target.files && target.files.length > 0) {
var file = target.files[0];
_this.onFileSelect(file);
}
};
input.click();
};
this.onClose = function () {
_this.showXmlProperties(false);
_this.documentHelper.owner.selectionModule.closeXmlPane();
_this.documentHelper.owner.documentEditorSettings.showNavigationPane = false;
_this.documentHelper.updateFocus();
_this.destroyInternal();
};
this.documentHelper = documentHelper;
this.isRtl = isRtl;
}
Object.defineProperty(XmlPane.prototype, "viewer", {
get: function () {
return this.documentHelper.owner.viewer;
},
enumerable: true,
configurable: true
});
XmlPane.prototype.getModuleName = function () {
return 'XmlPane';
};
XmlPane.prototype.enableDisableElements = function (enable) {
if (enable) {
ej2_base_1.classList(this.element, [], ['e-de-overlay']);
}
else {
ej2_base_1.classList(this.element, ['e-de-overlay'], []);
}
};
XmlPane.prototype.initializeXmlMapping = function () {
var _this = this;
var localObj = new ej2_base_1.L10n('documenteditor', this.documentHelper.owner.defaultLocale, this.documentHelper.owner.locale);
var elementId = 'xml_mapping_properties';
this.element = ej2_base_1.createElement('div', { id: this.documentHelper.owner.element.id + elementId, className: 'e-de-op' });
var headerDiv = this.createDivTemplate('_header_footer', this.element, 'padding-bottom:0');
ej2_base_1.classList(headerDiv, ['e-de-cntr-pane-padding'], []);
headerDiv.style.paddingLeft = '0px';
var headerLabel = ej2_base_1.createElement('label', { className: 'e-de-prop-header-label' });
headerLabel.innerHTML = localObj.getConstant('XML Mapping');
var closeButtonFloat;
Eif (!this.isRtl) {
closeButtonFloat = 'float:right;';
}
else {
closeButtonFloat = 'float:left;';
}
var closeIcon = ej2_base_1.createElement('span', {
id: '_header_footer_close',
className: 'e-de-ctnr-close e-de-close-icon e-icons',
styles: 'display:inline-block;cursor:pointer;' + closeButtonFloat
});
closeIcon.addEventListener('click', function () {
_this.onClose();
});
headerDiv.appendChild(headerLabel);
headerDiv.appendChild(closeIcon);
var optionsLabelDiv = this.createDivTemplate(elementId + '_xml', this.element);
ej2_base_1.classList(optionsLabelDiv, ['e-de-cntr-pane-padding'], []);
optionsLabelDiv.style.paddingLeft = '0px';
optionsLabelDiv.style.paddingRight = '5px';
optionsLabelDiv.style.width = '275px';
var optionsLabel = ej2_base_1.createElement('label', { className: 'e-de-ctnr-prop-label', styles: 'height:20px;' });
optionsLabel.innerHTML = localObj.getConstant('Custom XML Part');
optionsLabelDiv.appendChild(optionsLabel);
var optionsDiv = this.createDivTemplate(elementId + '_xmlDiv', optionsLabelDiv);
var firstPageDiv = this.createDivTemplate(elementId + '_firstPageDiv', optionsDiv);
ej2_base_1.classList(firstPageDiv, ['e-de-hdr-ftr-frst-div'], []);
var firstPage = ej2_base_1.createElement('input', { id: elementId + '_firstPageDiv' + '_dropdownlist', className: 'e-de-prop-sub-label' });
firstPage.type = 'text';
firstPage.tabIndex = 1;
firstPageDiv.appendChild(firstPage);
this.positionLabelDiv = ej2_base_1.createElement('div', { id: elementId + '_positionLabelDiv', className: 'e-de-scrollbar-hide', styles: 'width:270px;height:310px;list-style:none;padding-right:5px;overflow:auto;' });
this.element.appendChild(this.positionLabelDiv);
var tree = ej2_base_1.createElement('div', { id: 'tree', className: 'e-de-scrollbar-hide', styles: 'width:270px;height:310px;list-style:none;padding-right:5px;overflow:auto;' });
var ul = document.createElement('ul');
ul.contentEditable = 'false';
ul.style.width = 'auto';
ul.className = 'e-list-parent e-ul';
ul.style.paddingLeft = '0px';
ul.id = 'e-de-pane-contextmenu-list';
ul.style.listStyle = 'none';
ul.style.margin = '0px';
ul.style.maxHeight = 'auto';
ul.oncontextmenu = this.disableBrowserContextmenu;
this.treeviewObject = new ej2_navigations_1.TreeView({
fields: this.field,
cssClass: 'e-de-custom-treeview',
});
this.treeviewObject.appendTo(tree);
this.positionLabelDiv.appendChild(tree);
this.positionLabelDiv.appendChild(ul);
this.documentHelper.owner.editor.dictionaryObject[this.documentHelper.owner.editor.dictionaryObjectIndexIncrement++] = {
ID: 'Default',
Data: this.hierarchicalData
};
Eif (this.documentHelper.owner.editor.xmlData && this.documentHelper.owner.editor.xmlData.length === 0) {
this.documentHelper.owner.editor.xmlData = this.hierarchicalData;
}
};
XmlPane.prototype.initializeContextMenu = function () {
var menuItems = [
{
text: 'Insert Content control',
id: 'Insert',
items: [
{
text: 'Rich Text',
id: 'RichText'
},
{
text: 'Plain Text',
id: 'PlainText'
},
{
text: 'Picture',
id: 'Picture'
},
{
text: 'CheckBox',
id: 'CheckBox'
},
{
text: 'Combo Box',
id: 'ComboBox'
},
{
text: 'Dropdown List',
id: 'DropdownList'
},
{
text: 'Date Picker',
id: 'DatePicker'
},
]
},
{
text: 'Map to selected content control',
id: 'MapToSelectedContentControl'
},
];
var menuOptions = {
target: '#tree',
items: menuItems,
select: this.handleContextMenuItem.bind(this),
beforeOpen: this.contextMenuBeforeOpen.bind(this)
};
this.contextMenuInstance = new ej2_navigations_1.ContextMenu(menuOptions, '#e-de-pane-contextmenu-list');
};
XmlPane.prototype.intializeDropDownList = function () {
this.dropDownListObject = new ej2_dropdowns_1.DropDownList({
dataSource: this.DropDownListData,
fields: { text: 'Value', value: 'ID' },
text: this.DropDownListData[0].Value,
select: this.handleDropDownList.bind(this)
});
this.dropDownListObject.appendTo('#xml_mapping_properties_firstPageDiv_dropdownlist');
};
XmlPane.prototype.handleDropDownList = function (args) {
var regx = /(no namespace)/;
var currentID;
var selectedItem = args.item.innerText;
for (var i = 0; i < this.DropDownListData.length; i++) {
if (this.dropDownListObject.dataSource[i].Value == selectedItem) {
currentID = this.dropDownListObject.dataSource[i].ID;
}
}
if (selectedItem === '(Add new part...)') {
this.documentHelper.owner.prefixMappings = " ";
this.handleFileSelect();
}
else if (regx.test(selectedItem)) {
this.documentHelper.owner.prefixMappings = " ";
for (var i = 0; i < this.documentHelper.owner.editor.dictionaryObject.length; i++) {
if (currentID === this.documentHelper.owner.editor.dictionaryObject[i].ID) {
this.handleTreeviewObject(i);
}
}
}
else if (selectedItem === 'Choose an XML file') {
this.documentHelper.owner.prefixMappings = " ";
this.handleTreeviewObject(0);
}
else {
this.documentHelper.owner.prefixMappings = selectedItem;
for (var i = 0; i < this.documentHelper.owner.editor.dictionaryObject.length; i++) {
if (currentID === this.documentHelper.owner.editor.dictionaryObject[i].ID) {
this.handleTreeviewObject(i);
}
}
}
};
XmlPane.prototype.handleTreeviewObject = function (index) {
this.treeviewObject.fields.dataSource = this.documentHelper.owner.editor.dictionaryObject[index].Data;
this.treeviewObject.dataBind();
this.documentHelper.owner.editor.xmlData = this.documentHelper.owner.editor.dictionaryObject[index].Data;
};
XmlPane.prototype.contextMenuBeforeOpen = function (args) {
var contentControl = this.documentHelper.owner.editor.getContentControl();
var contentControlImage = this.documentHelper.owner.getImageContentControl();
var content = this.treeviewObject.selectedNodes;
var node = this.treeviewObject.getNode(content[0]);
if (node.hasChildren) {
args.cancel = true;
}
if (!ej2_base_1.isNullOrUndefined(this.contextMenuInstance)) {
if (!ej2_base_1.isNullOrUndefined(contentControl) || !ej2_base_1.isNullOrUndefined(contentControlImage)) {
this.contextMenuInstance.enableItems(['Map to selected content control'], true);
}
else {
this.contextMenuInstance.enableItems(['Map to selected content control'], false);
}
}
};
XmlPane.prototype.handleContextMenuItem = function (args) {
var item = args.element.id;
switch (item) {
case 'RichText':
case 'PlainText':
case 'Picture':
case 'ComboBox':
case 'DropdownList':
case 'CheckBox':
case 'DatePicker':
this.applyContentControl(item);
break;
case 'MapToSelectedContentControl':
var contentControl = this.documentHelper.owner.editor.getContentControl();
var contentControlImage = this.documentHelper.owner.getImageContentControl();
if (!ej2_base_1.isNullOrUndefined(contentControl) || !ej2_base_1.isNullOrUndefined(contentControlImage)) {
this.documentHelper.owner.isXmlMapCC = true;
if (this.documentHelper.owner.isXmlMapCC && !ej2_base_1.isNullOrUndefined(this.documentHelper.owner.editor.xmlData.length) && this.documentHelper.owner.editor.xmlData.length > 0) {
this.getXmlPath();
}
this.documentHelper.owner.selection.selectContentInternal(contentControl);
this.insertContent();
}
break;
}
};
XmlPane.prototype.disableBrowserContextmenu = function () {
return false;
};
XmlPane.prototype.applyContentControl = function (args) {
var _this = this;
this.documentHelper.owner.isXmlMapCC = true;
if (this.documentHelper.owner.isXmlMapCC && !ej2_base_1.isNullOrUndefined(this.documentHelper.owner.editor.xmlData.length) && this.documentHelper.owner.editor.xmlData.length > 0) {
this.getXmlPath();
}
var contentControl = this.documentHelper.owner.editor.getContentControl();
var contentControlImage = this.documentHelper.owner.getImageContentControl();
if (!ej2_base_1.isNullOrUndefined(contentControl) || !ej2_base_1.isNullOrUndefined(contentControlImage)) {
var localObj = new ej2_base_1.L10n('documenteditor', this.documentHelper.owner.defaultLocale);
localObj.setLocale(this.documentHelper.owner.locale);
this.alertDialog = ej2_popups_1.DialogUtility.alert({
title: localObj.getConstant('Information'),
content: localObj.getConstant('Discard Content Control'),
okButton: { text: localObj.getConstant('Ok') },
showCloseIcon: true,
closeOnEscape: true,
animationSettings: { effect: 'Zoom' },
position: { X: 'center', Y: 'center' },
close: function () {
_this.closeDialogUtils.bind(_this);
}
});
}
else {
switch (args) {
case 'PlainText':
this.documentHelper.owner.editor.insertContentControl('Text');
this.insertContent();
break;
case 'RichText':
this.documentHelper.owner.editor.insertContentControl('RichText');
this.insertContent();
break;
case 'Picture':
this.documentHelper.owner.showDialog('PictureContentControl');
break;
case 'ComboBox':
this.documentHelper.owner.editor.insertContentControl('ComboBox');
this.insertContent();
break;
case 'DropdownList':
this.documentHelper.owner.editor.insertContentControl('DropDownList');
this.insertContent();
break;
case 'CheckBox':
this.documentHelper.owner.editor.insertContentControl('CheckBox');
break;
case 'DatePicker':
this.documentHelper.owner.editor.insertContentControl('Date');
this.insertContent();
break;
}
}
};
XmlPane.prototype.insertContent = function () {
var selectedNode = this.treeviewObject.selectedNodes.toString();
for (var i = 1; i < this.documentHelper.owner.editor.xmlData.length; i++) {
var xmlID = this.documentHelper.owner.editor.xmlData[i].id.toString();
if (selectedNode == xmlID) {
if (!ej2_base_1.isNullOrUndefined(this.documentHelper.owner.editor.xmlData[i].displayValue)) {
var content = this.documentHelper.owner.editor.xmlData[i].displayValue.toString();
this.documentHelper.owner.editor.insertText(content);
}
}
}
this.documentHelper.owner.isXmlMapCC = false;
};
XmlPane.prototype.getXmlPath = function () {
var selectedNode = this.treeviewObject.selectedNodes.toString();
var xPath = "";
var nodeId = Number(selectedNode) - 1;
for (var i = this.documentHelper.owner.editor.xmlData.length - 1; i >= 0; i--) {
if (!ej2_base_1.isNullOrUndefined(this.documentHelper.owner.editor.xmlData[nodeId]) && this.documentHelper.owner.editor.xmlData[nodeId].pid == this.documentHelper.owner.editor.xmlData[i].id.toString()) {
xPath = "\\" + this.documentHelper.owner.editor.xmlData[i].displayText + "[1]" + "\\" + xPath;
nodeId = i;
}
}
var nodeNumber = Number(selectedNode) - 1;
if (this.documentHelper.owner.editor.xmlData[nodeNumber]) {
xPath = xPath + this.documentHelper.owner.editor.xmlData[nodeNumber].displayText.toString() + "[1]";
this.documentHelper.owner.xPathString = xPath;
}
};
XmlPane.prototype.closeDialogUtils = function () {
this.alertDialog.close();
this.alertDialog = undefined;
};
XmlPane.prototype.createDivTemplate = function (id, parentDiv, style) {
var divElement;
if (style) {
divElement = ej2_base_1.createElement('div', { id: id, styles: style });
}
else {
divElement = ej2_base_1.createElement('div', { id: id });
}
parentDiv.appendChild(divElement);
return divElement;
};
XmlPane.prototype.onFileSelect = function (file) {
var _this = this;
var reader = new FileReader();
reader.onload = function () {
var xmlString = reader.result;
_this.documentHelper.owner.editor.getPrefixMapping(xmlString);
var parsedXml = _this.documentHelper.owner.editor.parseXml(xmlString);
var arr = _this.documentHelper.owner.editor.objectToArray(parsedXml);
_this.documentHelper.owner.editor.setXmlData(parsedXml, arr);
_this.addingNewFileToDropDownList();
};
reader.readAsText(file);
};
XmlPane.prototype.addingNewFileToDropDownList = function () {
if (this.documentHelper.owner.editor.XMLFilesNameSpaceCount == 1 && this.documentHelper.owner.prefixMappings == null) {
this.DropDownListData.splice(this.DropDownListData.length - 1, 0, { ID: "(no namespace)_" + this.documentHelper.owner.editor.XMLFilesCount, Value: "(no namespace)" });
this.documentHelper.owner.editor.XMLFilesNameSpaceCount++;
}
else if (this.documentHelper.owner.editor.XMLFilesNameSpaceCount > 1 && this.documentHelper.owner.prefixMappings == null) {
this.DropDownListData.splice(this.DropDownListData.length - 1, 0, { ID: "(no namespace)_" + this.documentHelper.owner.editor.XMLFilesCount, Value: "(no namespace) (" + this.documentHelper.owner.editor.XMLFilesNameSpaceCount + ")" });
this.documentHelper.owner.editor.XMLFilesNameSpaceCount++;
}
else if (this.documentHelper.owner.prefixMappings) {
this.DropDownListData.splice(this.DropDownListData.length - 1, 0, { ID: "(no namespace)_" + this.documentHelper.owner.editor.XMLFilesCount, Value: this.documentHelper.owner.prefixMappings });
}
this.dropDownListObject.dataSource = this.DropDownListData;
this.dropDownListObject.refresh();
this.dropDownListObject.value = null;
this.dropDownListObject.text = this.DropDownListData[0].Value;
this.documentHelper.owner.editor.XMLFilesCount++;
};
XmlPane.prototype.showXmlProperties = function (show) {
this.isXmlPaneShow = show;
Eif (show) {
this.localeValue = new ej2_base_1.L10n('documenteditor', this.documentHelper.owner.defaultLocale);
this.localeValue.setLocale(this.documentHelper.owner.locale);
Eif (!ej2_base_1.isNullOrUndefined(XmlPane)) {
this.initializeXmlMapping();
var isRtl = this.documentHelper.owner.enableRtl;
var optionsPaneContainerStyle = void 0;
Iif (isRtl) {
optionsPaneContainerStyle = 'display:inline-flex;direction:rtl;';
}
else {
optionsPaneContainerStyle = 'display:inline-flex;';
}
this.documentHelper.optionsPaneContainer.insertBefore(this.documentHelper.owner.xmlPaneModule.element, this.documentHelper.viewerContainer);
this.documentHelper.owner.isXmlPaneTool = true;
}
this.documentHelper.owner.resize();
Eif (show && !this.contextMenuInstance) {
this.initializeContextMenu();
this.intializeDropDownList();
}
this.documentHelper.updateViewerSize();
}
else {
this.documentHelper.updateViewerSize();
if (!ej2_base_1.isNullOrUndefined(this.element)) {
if (this.element.style.display !== 'none') {
this.element.style.display = 'none';
}
}
this.destroyInternal();
this.documentHelper.owner.isXmlPaneTool = false;
this.documentHelper.owner.triggerResize();
}
};
XmlPane.prototype.destroyInternal = function () {
if (this.treeviewObject) {
this.treeviewObject.destroy();
this.treeviewObject = undefined;
}
if (this.contextMenuInstance) {
this.contextMenuInstance.destroy();
this.contextMenuInstance = undefined;
}
if (this.positionLabelDiv) {
this.positionLabelDiv.innerHTML = '';
this.positionLabelDiv = undefined;
}
if (this.dropDownListObject) {
this.dropDownListObject.destroy();
this.dropDownListObject = undefined;
}
if (this.element) {
this.element.innerHTML = '';
if (this.element.parentElement) {
this.element.parentElement.removeChild(this.element);
}
}
this.element = undefined;
};
XmlPane.prototype.destroy = function () {
if (this.treeviewObject) {
this.treeviewObject.destroy();
this.treeviewObject = undefined;
}
if (this.contextMenuInstance) {
this.contextMenuInstance.destroy();
this.contextMenuInstance = undefined;
}
if (this.positionLabelDiv) {
this.positionLabelDiv.innerHTML = '';
this.positionLabelDiv = undefined;
}
if (this.dropDownListObject) {
this.dropDownListObject.destroy();
this.dropDownListObject = undefined;
}
if (this.element) {
this.element.innerHTML = '';
Eif (this.element.parentElement) {
this.element.parentElement.removeChild(this.element);
}
}
this.element = undefined;
this.documentHelper = undefined;
};
return XmlPane;
}());
exports.XmlPane = XmlPane;
});
|