This repository has been archived by the owner on Aug 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Ext.plugin.touch.GridEditor.js
111 lines (88 loc) · 2.14 KB
/
Ext.plugin.touch.GridEditor.js
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
Ext.ns("Ext.plugin.touch");
Ext.plugin.touch.GridEditor = Ext.extend(Ext.util.Observable, {
listenEvent : "taphold",
init: function(cmp) {
var me = this;
me.cmp = cmp;
cmp.on("afterrender", me.initListeners, me);
cmp.on("beforedestroy", me.cleanUp, me);
},
cleanUp: function() {
var me = this;
delete me.cmp;
delete me.aboutEdit;
},
initListeners: function() {
var me = this,
cmp = me.cmp,
listener = {
scope : me
};
listener[me.listenEvent] = {
delegate : "td.x-grid-cell",
fn : me.handleEditEvent
}
cmp.mon(cmp.body, listener);
return;
cmp.mon(cmp.body, {
scope : me,
taphold : {
delegate : "td.x-grid-cell",
fn : me.handleEditEvent
}
});
},
handleEditEvent: function(e, node) {
var me = this,
cmp = me.cmp,
el = Ext.get(node),
index = parseInt(el.getAttribute("rowIndex")),
view = cmp.getView(),
store = view.getStore(),
rec = store.getAt(index),
value = el.getHTML(),
mappings = cmp.getMappings(),
mapping = el.getAttribute("mapping");
me.aboutEdit = {
grid : cmp,
record : rec,
field : mapping,
value : value,
row : index,
column : mappings[mapping],
el : el
};
if (!cmp.fireEvent("beforeedit", me.aboutEdit)) { return false; }
me.showPopup(value);
},
showPopup: function(value) {
var me = this;
Ext.Msg.show({
title : "Edit",
prompt : true,
msg : "Please enter a new value:",
scope : me,
buttons : Ext.MessageBox.OKCANCEL,
icon : Ext.MessageBox.QUESTION,
fn : me.handleEdit,
value : value
});
},
handleEdit: function(btn, text) {
if (btn !== "ok") { return false; }
var me = this,
cmp = me.cmp,
aboutEdit = me.aboutEdit,
rec = aboutEdit.record,
mapping = aboutEdit.field;
if (aboutEdit.value === text) { return false; }
rec.set(mapping, text);
rec.setDirty();
Ext.apply(aboutEdit, {
originalValue : aboutEdit.value,
value : text
});
cmp.fireEvent("edit", aboutEdit);
}
});
Ext.preg("ext.plugin.touch.grideditor", Ext.plugin.touch.GridEditor);