aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@frank.tg14.gathering.org>2014-04-14 02:17:04 +0200
committerroot <root@frank.tg14.gathering.org>2014-04-14 02:17:04 +0200
commit4e4763dded00347f0bc13757c3a9a7f0ed07e0b0 (patch)
treef01d01f3dbea85d869903e94bf2e5b692b8acfc7
parentae8098de011b9dafab5c590c4fd5fa5efe1c0fd7 (diff)
Make it possible to drag the switches around in ping.html.
-rwxr-xr-xweb/nms.gathering.org/change-switch-pos.pl15
-rw-r--r--web/nms.gathering.org/ping.html2
-rw-r--r--web/nms.gathering.org/ping.js39
-rwxr-xr-xweb/nms.gathering.org/switches-json.pl4
4 files changed, 57 insertions, 3 deletions
diff --git a/web/nms.gathering.org/change-switch-pos.pl b/web/nms.gathering.org/change-switch-pos.pl
new file mode 100755
index 0000000..70d12f4
--- /dev/null
+++ b/web/nms.gathering.org/change-switch-pos.pl
@@ -0,0 +1,15 @@
+#! /usr/bin/perl
+use CGI;
+use GD;
+use DBI;
+use lib '../../include';
+use nms;
+my $cgi = CGI->new;
+
+my $dbh = nms::db_connect();
+my $box = sprintf("(%d,%d)", $cgi->param('x'), $cgi->param('y'));
+
+$dbh->do('UPDATE placements SET placement=box(?::point, ?::point + point(width(placement),height(placement))) WHERE switch=?',
+ undef, $box, $box, $cgi->param('switch'));
+print $cgi->header(-type=>'text/plain', -expires=>'now');
+
diff --git a/web/nms.gathering.org/ping.html b/web/nms.gathering.org/ping.html
index 377ae62..423c73e 100644
--- a/web/nms.gathering.org/ping.html
+++ b/web/nms.gathering.org/ping.html
@@ -1,6 +1,6 @@
<html>
<body>
- <p style="border: 1px solid black;" id="playground"><img src="tg14-salkart.png" alt="" id="map" style="border: 1px solid black"; /></p>
+ <p id="playground"><img src="tg14-salkart.png" alt="" id="map" /></p>
<script type="text/javascript" src="ping.js"></script>
</body>
</html>
diff --git a/web/nms.gathering.org/ping.js b/web/nms.gathering.org/ping.js
index 8879e9a..c0f6b46 100644
--- a/web/nms.gathering.org/ping.js
+++ b/web/nms.gathering.org/ping.js
@@ -87,5 +87,44 @@ function create_switch(switchnum, sysname, x, y, width, height) {
var text = document.createTextNode(sysname);
s.appendChild(text);
+ //var attr = document.createAttribute("data-switchnum", switchnum);
+ s.setAttribute("data-switchnum", switchnum);
+
document.body.appendChild(s);
}
+
+var dragging_switch = null;
+var delta_x = null, delta_y = null;
+
+document.onmousedown = function(e) {
+ var switchnum = e.target.getAttribute("data-switchnum");
+ if (switchnum === null) {
+ return;
+ }
+ dragging_switch = switchnum;
+ delta_x = parseInt(e.target.style.left.replace("px", "")) - e.clientX;
+ delta_y = parseInt(e.target.style.top.replace("px", "")) - e.clientY;
+}
+
+document.onmousemove = function(e) {
+ if (dragging_switch === null) {
+ return;
+ }
+ switches[dragging_switch].style.left = (e.clientX + delta_x) + 'px';
+ switches[dragging_switch].style.top = (e.clientY + delta_y) + 'px';
+}
+
+document.onmouseup = function(e) {
+ if (dragging_switch === null) {
+ return;
+ }
+ var x = e.clientX + delta_x;
+ var y = e.clientY + delta_y;
+
+ var request = new XMLHttpRequest();
+ request.open('POST', '/change-switch-pos.pl', true);
+ request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
+ request.send("switch=" + dragging_switch + "&x=" + x + "&y=" + y);
+
+ dragging_switch = null;
+}
diff --git a/web/nms.gathering.org/switches-json.pl b/web/nms.gathering.org/switches-json.pl
index 1dccfe2..8d3d88a 100755
--- a/web/nms.gathering.org/switches-json.pl
+++ b/web/nms.gathering.org/switches-json.pl
@@ -14,12 +14,12 @@ $q->execute();
my %json = ();
while (my $ref = $q->fetchrow_hashref()) {
- $ref->{'placement'} =~ /\((\d+),(\d+)\),\((\d+),(\d+)\)/;
+ $ref->{'placement'} =~ /\((-?\d+),(-?\d+)\),\((-?\d+),(-?\d+)\)/;
my ($x1, $y1, $x2, $y2) = ($1, $2, $3, $4);
$json{$ref->{'switch'}} = {
sysname => $ref->{'sysname'},
x => $x2,
- y => $y1,
+ y => $y2,
width => $x1 - $x2,
height => $y1 - $y2
};