forked from axa-rev-research/fairness-compass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprops.js
162 lines (138 loc) · 3.72 KB
/
props.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
* Extended version of the props plugin.
*/
Draw.loadPlugin(function(ui) {
var div = document.createElement('div');
div.style.background = (uiTheme == 'dark') ? '#2a2a2a' : '#ffffff';
div.style.border = '1px solid gray';
div.style.opacity = '0.0';
div.style.position = 'absolute';
div.style.padding = '10px';
div.style.paddingTop = '0px';
div.style.width = '20%';
div.style.minWidth = '200px';
div.style.top = '40px';
div.style.right = '20px';
var graph = ui.editor.graph;
// Made for chromeless mode
if (!ui.editor.isChromelessView())
{
div.style.top = '100px';
div.style.right = '260px';
}
document.body.appendChild(div);
window.setTimeout(function()
{
var parent = graph.getDefaultParent();
var cells = graph.getChildCells(parent);
for (var i=0; i<cells.length; i++)
{
var cell = cells[i];
var attrs = (cell.value != null) ? cell.value.attributes : null;
if (attrs != null)
{
for (var j = 0; j < attrs.length; j++) {
if (attrs[j].nodeName == "reasoning")
{
var highlight = new mxCellHighlight(graph, '#ebe834', 8);
highlight.highlight(graph.view.getState(cell));
}
}
}
}
}, 10);
// Highlights current cell
var highlight = new mxCellHighlight(graph, '#00ff00', 8);
/**
* Updates the properties panel
*/
function cellClicked(cell)
{
// Forces focusout in IE
graph.container.focus();
div.style.opacity = '0.0';
// Gets the selection cell
if (cell == null)
{
highlight.highlight(null);
div.style.opacity = '0.0';
}
else
{
var attrs = (cell.value != null) ? cell.value.attributes : null;
highlight.highlight(graph.view.getState(cell));
if (attrs != null)
{
var accepted = ['description', 'reasoning'];
for (var i = 0; i < attrs.length; i++)
{
if (mxUtils.indexOf(accepted, attrs[i].nodeName) > -1 && attrs[i].nodeValue.length > 0)
{
div.innerHTML = '';
div.style.opacity = '0.9';
div.innerHTML += '<p>' + graph.sanitizeHtml(attrs[i].nodeValue) + '</p>';
}
}
}
}
};
/**
* Creates the textfield for the given property.
*/
function createTextField(graph, form, cell, attribute)
{
var input = form.addText(attribute.nodeName + ':', attribute.nodeValue);
var applyHandler = function()
{
var newValue = input.value || '';
var oldValue = cell.getAttribute(attribute.nodeName, '');
if (newValue != oldValue)
{
graph.getModel().beginUpdate();
try
{
var edit = new mxCellAttributeChange(
cell, attribute.nodeName,
newValue);
graph.getModel().execute(edit);
graph.updateCellSize(cell);
}
finally
{
graph.getModel().endUpdate();
}
}
};
mxEvent.addListener(input, 'keypress', function (evt)
{
// Needs to take shift into account for textareas
if (evt.keyCode == /*enter*/13 &&
!mxEvent.isShiftDown(evt))
{
input.blur();
}
});
if (mxClient.IS_IE)
{
mxEvent.addListener(input, 'focusout', applyHandler);
}
else
{
// Note: Known problem is the blurring of fields in
// Firefox by changing the selection, in which case
// no event is fired in FF and the change is lost.
// As a workaround you should use a local variable
// that stores the focused field and invoke blur
// explicitely where we do the graph.focus above.
mxEvent.addListener(input, 'blur', applyHandler);
}
};
graph.click = function(me)
{
// Async required to enable hyperlinks in labels
window.setTimeout(function()
{
cellClicked(me.getCell());
}, 0);
};
});