-
Notifications
You must be signed in to change notification settings - Fork 7
/
selections.js
101 lines (94 loc) · 2.52 KB
/
selections.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
/*
* This file is part of the BBjGridExWidget plugin.
* (c) Basis Europe <eu@basis.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { gw_sendEvent, gw_parseNodeFromEvent } from "./utilities";
import { gw_escape, gw_getGrid } from "api/utilities";
import {
GW_EVENT_ROW_CLICK,
GW_EVENT_ROW_DOUBLE_CLICK,
GW_EVENT_CELL_CLICK,
GW_EVENT_CELL_DOUBLE_CLICK,
GW_EVENT_RANGE_SELECTION_CHANGED
} from "./constants";
const CELL_CLICKING_EVENTS_MAP = {
'cellClicked': GW_EVENT_CELL_CLICK,
'cellDoubleClicked': GW_EVENT_CELL_DOUBLE_CLICK,
};
/**
* An handler for the grid `rowDoubleClicked` event
*
* The function will send a bbj event with `GW_NODE` as payload
*
* @param {Object} e The event's payload
*
* @listens agGrid.rowDoubleClicked
* @fires gw.rowDoubleClick
*/
export function gw_onRowDoubleClicked(e) {
const context = e.api.gridOptionsWrapper.gridOptions.context;
gw_sendEvent(context, {
'type': 'gw.rowDoubleClick',
'detail': ''
}, GW_EVENT_ROW_DOUBLE_CLICK);
}
/**
* A handler for the grid `selectionChanged` event
*
* @param {Object} e The event payload
*
* @listens agGrid.selectionChanged
* @fires gw.rowSelect
*/
export function gw_onSelectionChanged(e) {
const context = e.api.gridOptionsWrapper.gridOptions.context;
gw_sendEvent(context, {
'type': 'gw.rowSelect',
'detail': ''
}, GW_EVENT_ROW_CLICK);
}
/**
* A handler for the grid `rangeSelectionChanged` event
*
* @param {Object} e
*
* @listens agGrid.rangeSelectionChanged
* @fires gw.rangeSelection
*/
export function gw_onRangeSelectionChanged(e) {
const context = e.api.gridOptionsWrapper.gridOptions.context;
gw_sendEvent(context, {
'type': 'gw.rangeSelection',
'detail': ''
}, GW_EVENT_RANGE_SELECTION_CHANGED);
}
/**
* A handler for the grid `cellClickEvent` & `cellDoubleClicked` event
*
* @param {String} id The grid's id
* @param {Object} e The event payload
*
* @listens agGrid.cellClickEvent
* @listens agGrid.cellDoubleClicked
*
* @fires gw.cellClicked
* @fires gw.cellDoubleClicked
*/
export function gw_onCellClickEvent(id, e) {
const parsed = gw_parseNodeFromEvent(e);
if (parsed) {
const type = e.type;
gw_sendEvent(gw_getGrid(id).options.context, {
'type': `gw.${e.type}`,
'detail': JSON.stringify({
row: parsed,
value: gw_escape(e.value),
oldValue: gw_escape(e.value),
column: e.column.colId
})
}, CELL_CLICKING_EVENTS_MAP[type]);
}
}