/
listItemView.js
57 lines (47 loc) · 1.43 KB
/
listItemView.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
'use strict';
import {LayoutView} from 'marionette';
import Tooltipable from 'foreground/view/behavior/tooltipable';
import ListItemButtonsView from 'foreground/view/listItemButton/listItemButtonsView';
var ListItemView = LayoutView.extend({
tagName: 'li',
className: 'listItem listItem--clickable',
attributes: function() {
// Store the clientId on the view until the model has been saved successfully.
var id = this.model.isNew() ? this.model.cid : this.model.get('id');
return {
'data-id': id,
'data-type': this.options.type,
// Children unloaded by slidingRender lose track of their parent DOM node.
'data-parentid': this.options.parentId
};
},
events: {
'contextmenu': '_onContextMenu',
'mouseenter': '_onMouseEnter',
'mouseleave': '_onMouseLeave'
},
regions: {
buttons: 'buttons',
spinner: 'spinner',
checkbox: 'checkbox'
},
behaviors: {
Tooltipable: {
behaviorClass: Tooltipable
}
},
_onContextMenu: function(event) {
event.preventDefault();
// Show the element just slightly offset as to not break onHover effects.
this.showContextMenu(event.pageY, event.pageX + 1);
},
_onMouseEnter: function() {
this.showChildView('buttons', new ListItemButtonsView({
buttonViewOptions: this.buttonViewOptions.bind(this)
}));
},
_onMouseLeave: function() {
this.buttons.empty();
}
});
export default ListItemView;