cell-edit-mixin.js
5.23 KB
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
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _utils = require('../../src/utils/utils.js');
var _utils2 = _interopRequireDefault(_utils);
var _dom = require('../../src/utils/dom.js');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = {
methods: {
cellEdit: function cellEdit(e, callback, rowIndex, rowData, field) {
var target = e.target,
self = this,
oldVal = void 0,
editInput = void 0,
editInputLen = void 0,
_actionFun = void 0,
textAlign = void 0,
childTarget = void 0;
while (target.className && target.className.indexOf('v-table-body-cell') === -1 || !target.className) {
target = target.parentNode;
}
childTarget = target.children[0];
childTarget.style.display = 'none';
if ((0, _dom.hasClass)(target, 'cell-editing')) {
return false;
}
(0, _dom.addClass)(target, 'cell-editing');
oldVal = childTarget.innerText.trim();
if (target.style.textAlign) {
textAlign = target.style.textAlign;
}
editInput = document.createElement('input');
editInput.value = oldVal;
editInput.className = 'cell-edit-input';
editInput.style.textAlign = textAlign;
editInput.style.width = '100%';
editInput.style.height = '100%';
target.appendChild(editInput);
editInput.focus();
editInputLen = editInput.value.length;
if (document.selection) {
var ctr = editInput.createTextRange();
ctr.moveStart('character', editInputLen);
ctr.collapse();
ctr.select();
} else if (typeof editInput.selectionStart == 'number' && typeof editInput.selectionEnd == 'number') {
editInput.selectionStart = editInput.selectionEnd = editInputLen;
}
_actionFun = function actionFun(e) {
if (typeof e.keyCode === 'undefined' || e.keyCode === 0 || e.keyCode == 13) {
if ((0, _dom.hasClass)(target, 'cell-editing')) {
(0, _dom.removeClass)(target, 'cell-editing');
} else {
return false;
}
childTarget.style.display = '';
callback(editInput.value, oldVal);
_utils2.default.unbind(editInput, 'blur', _actionFun);
_utils2.default.unbind(editInput, 'keydown', _actionFun);
target.removeChild(editInput);
}
};
_utils2.default.bind(editInput, 'blur', _actionFun);
_utils2.default.bind(editInput, 'keydown', _actionFun);
},
cellEditClick: function cellEditClick(e, isEdit, rowData, field, rowIndex) {
if (isEdit) {
var self = this;
var onCellEditCallBack = function onCellEditCallBack(newValue, oldVal) {
self.cellEditDone && self.cellEditDone(newValue, oldVal, rowIndex, rowData, field);
};
this.cellEdit(e, onCellEditCallBack, rowIndex, rowData, field);
}
}
}
};