Skip to content

Commit 942f2e3

Browse files
committed
Ensure that edited map range and expression properties are sent to the network if user clicks away from editor.
1 parent 62ea161 commit 942f2e3

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

js/MapProperties.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class MapProperties {
77
this.mapModes = ["Linear", "Expression"];
88
this.mapProtocols = ["UDP", "TCP"];
99
this.boundaryIcons = ["none", "right", "left", "mute", "clamp", "wrap"];
10+
this.cachedProperty = { "key": null, "value": null };
1011

1112
$(this.container).append(
1213
"<div' class='topMenu' id='mapPropsContainer' style='width:calc(100% - 605px);'>"+
@@ -74,12 +75,17 @@ class MapProperties {
7475

7576
// The range input handler
7677
$('#mapPropsContainer').on({
77-
keydown: function(e) {
78+
keydown: function(e) { e.stopPropagation(); },
79+
keyup: function(e) {
7880
e.stopPropagation();
7981
if (e.which == 13 || e.which == 9) { //'enter' or 'tab' key
8082
self.setMapProperty($(this).attr('id').split(' ')[0],
8183
this.value);
8284
}
85+
else {
86+
self.cacheMapProperty($(this).attr('id').split(' ')[0],
87+
this.value);
88+
}
8389
},
8490
click: function(e) { e.stopPropagation(); },
8591
focusout: function(e) {
@@ -91,19 +97,27 @@ class MapProperties {
9197

9298
// The expression input handler
9399
$('#mapPropsContainer').on({
94-
keydown: function(e) {
100+
keydown: function(e) { e.stopPropagation(); },
101+
keyup: function(e) {
95102
e.stopPropagation();
96103
if (e.which == 13) { //'enter' key
97-
if (counter >= 1) {
104+
// check if expression contains a semicolon
105+
if (this.value.indexOf(';') == -1 || counter >= 1) {
98106
self.setMapProperty($(this).attr('id').split(' ')[0],
99107
this.value);
100-
counter = 0;
108+
counter = 0;
101109
}
102-
else
110+
else {
103111
counter += 1;
112+
self.cacheMapProperty($(this).attr('id').split(' ')[0],
113+
this.value);
114+
}
104115
}
105-
else
116+
else {
106117
counter = 0;
118+
self.cacheMapProperty($(this).attr('id').split(' ')[0],
119+
this.value);
120+
}
107121
},
108122
click: function(e) { e.stopPropagation(); },
109123
focusout: function(e) {
@@ -344,8 +358,19 @@ class MapProperties {
344358
this.updateMapProperties();
345359
}
346360

361+
cacheMapProperty(key, value) {
362+
this.cachedProperty.key = key;
363+
this.cachedProperty.value = value;
364+
}
365+
366+
sendCachedProperty() {
367+
if (!this.cachedProperty.key || !this.cachedProperty.value)
368+
return;
369+
this.setMapProperty(this.cachedProperty.key, this.cachedProperty.value);
370+
}
371+
347372
setMapProperty(key, value) {
348-
let container = $(this.container);
373+
this.cacheMapProperty();
349374
let modes = this.mapModeCommands;
350375
this.database.maps.filter(this.selected).forEach(function(map) {
351376
if (map[key] && (map[key] == value || map[key] == parseFloat(value)))

js/ViewManager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ class ViewManager
228228
$('#svgDiv').on('mousedown', function(e) {
229229
if (self.views[self.currentView].dragging)
230230
return;
231+
$('#container').trigger("sendCachedProperty");
231232
if (e.shiftKey == false) {
232233
deselectAllMaps(self.tables);
233234
}

js/main.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ function init() {
6464
"</div>"+
6565
"</div>");
6666

67-
// init the view
68-
$('#container').empty();
69-
tooltip = new Tooltip();
70-
viewManager = new ViewManager(document.getElementById('container'), database,
71-
tooltip);
72-
7367
// init the top menu
7468
$('#TopMenuWrapper').empty()
7569
saverLoader = new SaverLoader(document.getElementById("TopMenuWrapper"),
@@ -83,6 +77,12 @@ function init() {
8377
netSelector = new NetworkSelector(document.getElementById("TopMenuWrapper"),
8478
database, viewManager);
8579

80+
// init the view
81+
$('#container').empty();
82+
tooltip = new Tooltip();
83+
viewManager = new ViewManager(document.getElementById('container'), database,
84+
tooltip);
85+
8686
// init controller
8787
initMonitorCommands();
8888
initViewCommands();
@@ -259,7 +259,7 @@ function initViewCommands()
259259

260260
// allows anyone to call updateMapProperties by triggering an event on #container
261261
function initMapPropertiesCommands() {
262-
// asks the view for the selected maps and updates the edit bar
262+
// asks the database for the selected maps and updates the edit bar
263263
$("#container").on("updateMapProperties", function(e) {
264264
mapProperties.updateMapProperties();
265265
});
@@ -268,6 +268,11 @@ function initMapPropertiesCommands() {
268268
$("#container").on("updateMapPropertiesFor", function(e, key) {
269269
mapProperties.updateMapPropertiesFor(key);
270270
});
271+
272+
// send out any partially-edited properties when maps are deselected
273+
$("#container").on("sendCachedProperty", function(e) {
274+
mapProperties.sendCachedProperty();
275+
});
271276
}
272277

273278
function select_obj(obj) {

0 commit comments

Comments
 (0)