1
|
/**
|
2
|
* Class representing a popover revealed on edge click to display its compatibility information.
|
3
|
* @see Edge
|
4
|
* @constructor
|
5
|
*/
|
6
|
function EdgePopover() {
|
7
|
var rootElement;
|
8
|
var popoverContentElement;
|
9
|
|
10
|
/**
|
11
|
* Sets compatibility information held by the edge.
|
12
|
* @param {object} compatibilityInfo Compatibility information of the edge.
|
13
|
*/
|
14
|
this.setContent = function(compatibilityInfo) {
|
15
|
popoverContentElement.appendChild(createHtmlTree(compatibilityInfo));
|
16
|
|
17
|
$.jstree.create(popoverContentElement, {
|
18
|
core : {
|
19
|
'animation': 25,
|
20
|
},
|
21
|
themes : {
|
22
|
'theme': 'classic',
|
23
|
'dots': true,
|
24
|
'icons': false,
|
25
|
},
|
26
|
plugins : [ 'themes', 'html_data' ],
|
27
|
});
|
28
|
};
|
29
|
|
30
|
/**
|
31
|
* Moves the popover to the coordinates.
|
32
|
* @param {Coordinates} coords Coordinates to display the popover at.
|
33
|
*/
|
34
|
this.setPosition = function(coords) {
|
35
|
rootElement.style.top = coords.y + 'px';
|
36
|
rootElement.style.left = coords.x + 'px';
|
37
|
};
|
38
|
|
39
|
/**
|
40
|
* Opens the popover.
|
41
|
*/
|
42
|
this.open = function() {
|
43
|
rootElement.classList.remove('hidden');
|
44
|
};
|
45
|
|
46
|
/**
|
47
|
* Closes the popover.
|
48
|
*/
|
49
|
this.close = function() {
|
50
|
rootElement.classList.add('hidden');
|
51
|
|
52
|
$.jstree.destroy(popoverContentElement);
|
53
|
|
54
|
popoverContentElement.innerHTML = '';
|
55
|
};
|
56
|
|
57
|
/**
|
58
|
* Creates a new DOM element representing the popover in memory. Binds user interactions to local handler functions.
|
59
|
* @returns {Element} HTML DOM element.
|
60
|
*/
|
61
|
this.render = function() {
|
62
|
rootElement = app.utils.createHtmlElement('div', {
|
63
|
'class': 'popover edge-popover hidden',
|
64
|
});
|
65
|
rootElement.addEventListener('wheel', stopPropagation.bind(this));
|
66
|
rootElement.addEventListener('mousedown', stopPropagation.bind(this));
|
67
|
rootElement.addEventListener('mouseleave', this.close.bind(this));
|
68
|
|
69
|
var popoverTitle = app.utils.createHtmlElement('span', {
|
70
|
'class': 'popover-title',
|
71
|
});
|
72
|
popoverTitle.appendChild(document.createTextNode('Incompatibility details'));
|
73
|
rootElement.appendChild(popoverTitle);
|
74
|
|
75
|
popoverContentElement = app.utils.createHtmlElement('div', {
|
76
|
'class': 'popover-content',
|
77
|
});
|
78
|
rootElement.appendChild(popoverContentElement);
|
79
|
|
80
|
return rootElement;
|
81
|
};
|
82
|
|
83
|
/**
|
84
|
* Stops propagation of the event which triggered this function to its parental elements.
|
85
|
* @param {Event} e The event.
|
86
|
*/
|
87
|
function stopPropagation(e) {
|
88
|
e.stopPropagation();
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
* Creates a new list displaying the compatibility information as tree in memory.
|
93
|
* @param {array<object>} compatibilityInfoList List of compatibility information held by the edge.
|
94
|
* @returns {Element} HTML DOM element.
|
95
|
*/
|
96
|
function createHtmlTree(compatibilityInfoList) {
|
97
|
var incompatibilityNameList = [];
|
98
|
var list = app.utils.createHtmlElement('ul', {});
|
99
|
|
100
|
compatibilityInfoList.forEach(function(compatibilityInfo) {
|
101
|
if (compatibilityInfo.incomps.length === 0) return;
|
102
|
|
103
|
compatibilityInfo.incomps.forEach(function(incompatibility) {
|
104
|
if (!incompatibility.desc.isIncompCause && incompatibility.subtree.length === 0) return;
|
105
|
|
106
|
if (incompatibilityNameList.indexOf(incompatibility.desc.name) > -1) return;
|
107
|
incompatibilityNameList.push(incompatibility.desc.name);
|
108
|
|
109
|
var label;
|
110
|
if (incompatibility.desc.isIncompCause) {
|
111
|
label = app.dom.htmlStringToElement(`<span>${incompatibility.desc.incompName}</span>`);
|
112
|
} else {
|
113
|
label = document.createTextNode(incompatibility.desc.name);
|
114
|
}
|
115
|
|
116
|
var listItem = app.utils.createHtmlElement('li', {});
|
117
|
listItem.appendChild(label);
|
118
|
list.appendChild(listItem);
|
119
|
|
120
|
var subList = app.utils.createHtmlElement('ul', {});
|
121
|
listItem.appendChild(subList);
|
122
|
|
123
|
appendHtmlSubtree(subList, incompatibility.subtree);
|
124
|
});
|
125
|
});
|
126
|
|
127
|
return list;
|
128
|
}
|
129
|
|
130
|
/**
|
131
|
* Appends a new list item displaying a single incompatibility to the list passed as a parameter.
|
132
|
* @param {Element} list HTML DOM element to append this tree to.
|
133
|
* @param {array<object>} incompatibilityList List of incompatibility information.
|
134
|
*/
|
135
|
function appendHtmlSubtree(list, incompatibilityList) {
|
136
|
incompatibilityList.forEach(function(incompatibility) {
|
137
|
if (!incompatibility.desc.isIncompCause && incompatibility.subtree.length === 0) return;
|
138
|
|
139
|
var label;
|
140
|
if (incompatibility.desc.isIncompCause) {
|
141
|
label = app.dom.htmlStringToElement(`<span>${incompatibility.desc.incompName}</span>`);
|
142
|
} else {
|
143
|
label = document.createTextNode(incompatibility.desc.name);
|
144
|
}
|
145
|
|
146
|
var listItem = app.utils.createHtmlElement('li', {});
|
147
|
listItem.appendChild(label);
|
148
|
list.appendChild(listItem);
|
149
|
|
150
|
if (incompatibility.desc.isIncompCause && incompatibility.desc.difference !== 'DEL') {
|
151
|
var subList = app.utils.createHtmlElement('ul', {});
|
152
|
listItem.appendChild(subList);
|
153
|
|
154
|
var subListItemProvided = app.utils.createHtmlElement('li', {});
|
155
|
subListItemProvided.appendChild(app.dom.htmlStringToElement(`<span><img src="images/efp_qtip/provided.png"> <span class="second">${incompatibility.desc.objectNameSecond}</span></span>`));
|
156
|
subList.appendChild(subListItemProvided);
|
157
|
|
158
|
var subListItemRequired = app.utils.createHtmlElement('li', {});
|
159
|
subListItemRequired.appendChild(app.dom.htmlStringToElement(`<span><img src="images/efp_qtip/required.png"> <span class="first">${incompatibility.desc.objectNameFirst}</span></span>`));
|
160
|
subList.appendChild(subListItemRequired);
|
161
|
}
|
162
|
|
163
|
if (incompatibility.subtree.length !== 0) {
|
164
|
var subList = app.utils.createHtmlElement('ul', {});
|
165
|
listItem.appendChild(subList);
|
166
|
|
167
|
appendHtmlSubtree(subList, incompatibility.subtree);
|
168
|
}
|
169
|
});
|
170
|
}
|
171
|
|
172
|
}
|