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 | 1×
1×
1×
1×
26×
26×
26×
26×
1×
26×
26×
1×
26×
26×
26×
7×
19×
19×
19×
19×
19×
19×
19×
85×
21×
21×
72×
72×
72×
17×
55×
95×
55×
4×
19×
19×
19×
3×
16×
6×
6×
6×
1×
1×
1×
2×
2×
2×
6×
5×
6×
6×
6×
6×
6×
6×
5×
6×
1×
20535×
1×
51×
26×
25×
1×
27×
1×
26×
26×
26×
26×
1×
27×
1×
26×
26×
26×
26×
1×
6×
2×
2×
1×
26×
26×
26×
109×
32×
32×
95×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-base", "../base/constant", "../base/enum", "../renderer/command-column-renderer", "../base/util", "../base/string-literals"], function (require, exports, ej2_base_1, constant_1, enum_1, command_column_renderer_1, util_1, literals) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var CommandColumn = (function () {
function CommandColumn(parent, locator) {
this.parent = parent;
this.locator = locator;
this.initiateRender();
this.addEventListener();
}
CommandColumn.prototype.initiateRender = function () {
var cellFac = this.locator.getService('cellRendererFactory');
cellFac.addCellRenderer(enum_1.CellType.CommandColumn, new command_column_renderer_1.CommandColumnRenderer(this.parent, this.locator));
};
CommandColumn.prototype.commandClickHandler = function (e) {
var gObj = this.parent;
var target = ej2_base_1.closest(e.target, 'button');
if (!target || !ej2_base_1.closest(e.target, '.e-unboundcell')) {
return;
}
var buttonObj = target.ej2_instances[0];
var type = buttonObj.commandType;
var uid = target.getAttribute('data-uid');
var commandColumn;
var row = gObj.getRowObjectFromUID(ej2_base_1.closest(target, '.' + literals.row).getAttribute('data-uid'));
var cols = this.parent.columnModel;
for (var i = 0; i < cols.length; i++) {
if (cols[parseInt(i.toString(), 10)].commands) {
var commandCols = cols[parseInt(i.toString(), 10)].commands;
for (var j = 0; j < commandCols.length; j++) {
var idInString = 'uid';
var typeInString = 'type';
if (commandCols[parseInt(j.toString(), 10)]["" + idInString] === uid && commandCols[parseInt(j.toString(), 10)]["" + typeInString] === type) {
commandColumn = commandCols[parseInt(j.toString(), 10)];
}
else {
var buttons = [].slice.call(ej2_base_1.closest(target, '.e-unboundcell').querySelectorAll('button'));
var index = buttons.findIndex(function (ele) { return ele === target; });
if (index < commandCols.length && commandCols[parseInt(index.toString(), 10)]["" + typeInString] === type &&
String(commandCols[parseInt(j.toString(), 10)]["" + idInString]) === uid) {
commandColumn = commandCols[parseInt(index.toString(), 10)];
}
}
}
}
}
var args = {
cancel: false,
target: target,
commandColumn: commandColumn,
rowData: ej2_base_1.isNullOrUndefined(row) ? undefined : row.data
};
this.parent.trigger(constant_1.commandClick, args, function (commandclickargs) {
if (buttonObj.disabled || !gObj.editModule || commandclickargs.cancel) {
return;
}
switch (type) {
case 'Edit':
gObj.editModule.endEdit();
gObj.editModule.startEdit(ej2_base_1.closest(target, 'tr'));
break;
case 'Cancel':
gObj.isFocusFirstCell = true;
gObj.editModule.closeEdit();
break;
case 'Save':
gObj.isFocusFirstCell = true;
gObj.editModule.endEdit();
break;
case 'Delete':
if (gObj.editSettings.mode !== 'Batch') {
gObj.editModule.endEdit();
}
gObj.commandDelIndex = parseInt(ej2_base_1.closest(target, 'tr').getAttribute(literals.dataRowIndex), 10);
gObj.clearSelection();
gObj.selectRow(gObj.commandDelIndex, false);
gObj.isFocusFirstCell = true;
gObj.editModule.deleteRecord();
if (!(gObj.editSettings.showDeleteConfirmDialog && !gObj.allowSelection)) {
gObj.commandDelIndex = undefined;
}
break;
}
});
};
CommandColumn.prototype.getModuleName = function () {
return 'commandColumn';
};
CommandColumn.prototype.destroy = function () {
if (this.parent.isDestroyed) {
return;
}
this.removeEventListener();
};
CommandColumn.prototype.removeEventListener = function () {
if (this.parent.isDestroyed) {
return;
}
this.parent.off(constant_1.click, this.commandClickHandler);
this.parent.off(constant_1.keyPressed, this.keyPressHandler);
this.parent.off(constant_1.initialEnd, this.load);
this.parent.off(constant_1.destroy, this.destroy);
};
CommandColumn.prototype.addEventListener = function () {
if (this.parent.isDestroyed) {
return;
}
this.parent.on(constant_1.click, this.commandClickHandler, this);
this.parent.on(constant_1.keyPressed, this.keyPressHandler, this);
this.parent.on(constant_1.initialEnd, this.load, this);
this.parent.on(constant_1.destroy, this.destroy, this);
};
CommandColumn.prototype.keyPressHandler = function (e) {
if ((e.action === 'enter' || e.action === 'space') && ej2_base_1.closest(e.target, '.e-unboundcelldiv')) {
this.commandClickHandler(e);
e.preventDefault();
}
};
CommandColumn.prototype.load = function () {
var uid = 'uid';
var col = this.parent.columnModel;
for (var i = 0; i < col.length; i++) {
if (col[parseInt(i.toString(), 10)].commands) {
var commandCol = col[parseInt(i.toString(), 10)].commands;
for (var j = 0; j < commandCol.length; j++) {
commandCol[parseInt(j.toString(), 10)]["" + uid] = util_1.getUid('gridcommand');
}
}
}
};
return CommandColumn;
}());
exports.CommandColumn = CommandColumn;
});
|