summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2012-05-05 11:09:34 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2012-05-05 11:09:34 +0200
commitc5fb4fd4d89086399762ac844b53564d98ff2d4e (patch)
treef38508eea678a5a55bde893e12a8b178b477c2d4
parent19fe0e08586e9e4063d507ff45b25315f5cf5bc7 (diff)
Fix move task by drag'n'drop.
-rw-r--r--proto.js261
1 files changed, 2 insertions, 259 deletions
diff --git a/proto.js b/proto.js
index 4cbbfc7..74eeabd 100644
--- a/proto.js
+++ b/proto.js
@@ -55,8 +55,6 @@ var BrowserDetect = {
};
-//document.cursor = crosshair;
-
BrowserDetect.init();
function get_appropriate_ws_url()
@@ -83,40 +81,20 @@ function get_appropriate_ws_url()
return pcol + u[0];
}
-
-//document.getElementById("create_task").style.display = '';
-
-/* lws-task protocol */
-
-var down = 0;
-var no_last = 1;
-var last_x = 0, last_y = 0;
-var ctx;
var socket_task;
-//var socket_observe;
-var color = "#000000";
-var dragged = "";
var board = document.getElementById("board");
-board.setAttribute("ondrop", "dropInBody(event)");
-board.setAttribute("ondragover", "return false");
-board.setAttribute("ondragenter", "return dragenter(this)");
-board.setAttribute("ondragleave", "return dragleave(this)");
-
if (BrowserDetect.browser == "Firefox") {
socket_task = new MozWebSocket(get_appropriate_ws_url(), "lws-task-protocol");
- // socket_observe = new MozWebSocket(get_appropriate_ws_url(), "lws-observe-protocol");
} else {
socket_task = new WebSocket(get_appropriate_ws_url(), "lws-task-protocol");
- // socket_observe = new WebSocket(get_appropriate_ws_url(), "lws-observe-protocol");
}
try {
socket_task.onopen = function() {
document.getElementById("wstask_status").style.backgroundColor = "#40ff40";
document.getElementById("wstask_status").textContent = "TaskProto websocket connection opened ";
- // document.getElementById("box").style.display = "none";
}
socket_task.onmessage = function got_packet(msg) {
@@ -185,8 +163,6 @@ try {
task.name = "task";
task.setAttribute("class", "task");
task.setAttribute("ondrop", "drop(this, event)");
- task.setAttribute("ondragenter", "return dragenter(this)");
- task.setAttribute("ondragleave", "return dragleave(this)");
task.setAttribute("ondragover", "return false");
task.setAttribute("draggable", true);
task.setAttribute("ondragstart", "drag(this, event)");
@@ -196,21 +172,7 @@ try {
var taskText = document.createTextNode('[' + task.id + ']');
taskText.id = "txt";
task.appendChild(taskText);
-
- //task.style.position = "absolute";
- //task.style.left = left + "px";
- //task.style.top = top + "px";
- //task.setAttribute("onMouseDown", "dragged = '" + id + "';");
-
- //var dlButton = document.createElement("input");
- //dlButton.type = "button";
- //dlButton.value = "Remove";
- //dlButton.onclick = "deleteTask(document.getElementById(" + task.id + ").id";
- //dlButton.setAttribute("onclick", "deleteTask(" + id +")");
- //task.appendChild(dlButton);
-
- //board.appendChild(task);
-
+
var parent_task = document.getElementById("task_" + parent_id);
if(parent_task) {
@@ -227,9 +189,6 @@ try {
task.appendChild(taskText);
}
f++;
- //document.getElementById("box").style.top = i[3] + "px";
- //document.getElementById("box").style.left = i[2] + "px";
- //document.getElementById("box").style.display = "block";
}
}
@@ -241,198 +200,11 @@ try {
alert('<p>Error' + exception + '</p>');
}
-/*
- try {
- socket_observe.onopen = function() {
- document.getElementById("wsobserve_status").style.backgroundColor = "#40ff40";
- document.getElementById("wsobserve_status").textContent = "ObserveProto websocket connection opened ";
- // document.getElementById("box").style.display = "none";
- }
-
- socket_observe.onmessage = function got_packet(msg) {
- document.getElementById("wsobserve_lastmsg").textContent = msg.data;
-
- var msgs = new Array();
- var idx = 0;
- msgs[idx] = '';
- var c = 0;
- var instring = false;
- for(c = 0; c < msg.data.length; c++) {
- if(msg.data[c] == '"' && c > 0 && msg.data[c - 1] != '\\') instring = !instring;
- if(msg.data[c] == ';' && instring == false) {
- idx++;
- msgs[idx] = '';
- }
- if(msg.data[c] != ';' || instring == true) msgs[idx] += msg.data[c];
- }
-
- f = 0;
- while (f < msgs.length - 1) {
- var msg = new Array();
- instring = false;
- idx = 0;
- msg[idx] = '';
- for(c = 0; c < msgs[f].length; c++) {
- if(msgs[f][c] == '"' && c > 0 && msgs[f][c - 1] != '\\') {
- instring = !instring;
- continue;
- }
- if(msgs[f][c] == ' ' && instring == false) {
- msg[idx] = msg[idx].replace("\\\\","\\").replace("\\\"","\"");
- idx++;
- msg[idx] = '';
- }
- if(msgs[f][c] != ' ' || instring == true) msg[idx] += msgs[f][c];
- }
-
- var cmd = msg[0];
-
- if(cmd == "del") {
- var id = msg[1];
- var task = document.getElementById("task_" + id);
- //todo: remove from parent not board
- board.removeChild(task);
- }
- else if(cmd == "move") {
- var id = msg[1];
- var parent_id = msg[2];
- // var left = msg[2];
- // var top = msg[3];
- var task = document.getElementById("task_" + id);
- if(parent_id != -1) {
- var parent_observe = document.getElementById("task_" + parent_id);
- parent_observe.appendChild(task);
- }
- else {
- board.appendChild(task);
- }
- // task.parentNode.removeChild(task);
- // board.removeChild(task);
- // parent_observe.appendChild(task);
- // task.style.left = left + "px";
- // task.style.top = top + "px";
- }
- else if(cmd == "add") {
- var id = msg[1];
- var title = msg[2];
- var description = msg[3];
- var parent_id = msg[4];
-
- var task = document.createElement("div");
- task.name = "task";
- task.setAttribute("class", "task");
- task.setAttribute("ondrop", "drop(this, event)");
- task.setAttribute("ondragenter", "return dragenter(this)");
- task.setAttribute("ondragleave", "return dragleave(this)");
- task.setAttribute("ondragover", "return false");
- task.setAttribute("draggable", true);
- task.setAttribute("ondragstart", "drag(this, event)");
-
- task.id = "task_" + id;
-
- var taskText = document.createTextNode(title + ": " + description + " :" + task.id);
- taskText.id = "txt";
- task.appendChild(taskText);
-
- // task.style.position = "absolute";
- // task.style.left = left + "px";
- // task.style.top = top + "px";
- // task.setAttribute("onMouseDown", "dragged = '" + id + "';");
-
- // var dlButton = document.createElement("input");
- // dlButton.type = "button";
- // dlButton.value = "Remove";
- // dlButton.onclick = "deleteTask(document.getElementById(" + task.id + ").id";
- // dlButton.setAttribute("onclick", "deleteTask(" + id +")");
- // task.appendChild(dlButton);
-
- // board.appendChild(task);
-
- var parent_observe = document.getElementById("task_" + parent_id);
-
- if(parent_observe) {
- parent_observe.appendChild(task);
- }
- else {
- board.appendChild(task);
- }
- }
- else if(cmd == "update") {
- var id = msg[1];
- var title = msg[2];
- var description = msg[3];
-
- var task = document.getElementById("task_" + id);
-
- var taskText = document.createTextNode(title + ": " + description + " :" + task.id);
- task.appendChild(taskText);
- }
- f++;
- // document.getElementById("box").style.top = i[3] + "px";
- // document.getElementById("box").style.left = i[2] + "px";
- // document.getElementById("box").style.display = "block";
- }
- }
-
- socket_observe.onclose = function(){
- document.getElementById("wsobserve_status").style.backgroundColor = "#ff4040";
- document.getElementById("wsobserve_status").textContent = "ObserveProto websocket connection CLOSED ";
- }
- } catch(exception) {
- alert('<p>Error' + exception + '</p>');
- }
-*/
-
-//var canvas = document.createElement('canvas');
-//canvas.height = 600;
-//canvas.width = 800;
-//ctx = canvas.getContext("2d");
-
-//document.addEventListener('mousemove', ev_mousemove, false);
-//document.addEventListener('mouseup', ev_mouseup, false);
-/*
- canvas.addEventListener('mousedown', ev_mousedown, false);
- //cancas.addEventListener('dragend', ev_mousemove, false);
- */
-
-//offsetX = offsetY = 0;
-//element = canvas;
-//if (element.offsetParent) {
-// do {
-// offsetX += element.offsetLeft;
-// offsetY += element.offsetTop;
-// } while ((element = element.offsetParent));
-//}
-
-function update_color() {
- color = document.getElementById("color").value;
-}
-
-//function ev_mouseup(ev) {
-// dragged = '';
-//}
-
-//function ev_mousemove (ev)
-//{
-// if(dragged == '') return;
-//
-// var x, y;
-// x = ev.clientX;
-// y = ev.clientY;
-
-// socket_observe.send("move " + dragged + " " + x + " " + y);
-//}
-
function task_submit() {
var data = document.getElementById("input_task_data").value;
socket_task.send(data);
}
-/*
- function observe_submit() {
- var data = document.getElementById("input_observe_data").value;
- socket_observe.send(data);
- }
-*/
+
function clear() {
document.getElementById("input_data").value = "";
}
@@ -448,39 +220,10 @@ function drag(target, e) {
}
function drop(target, e) {
- this.style.opacity = '1.0';
e.preventDefault();
e.stopPropagation();
var id = e.dataTransfer.getData('Text');
var task = document.getElementById(id);
- // task.parentNode.removeChild(task);
- // alert("move " + id.substring(5, id.length) + " " + target.id.substring(5,target.id.length) + ";");
socket_task.send("move " + id.substring(5, id.length) + " " + target.id.substring(5, target.id.length) + ";");
-
- // target.appendChild(task);
-}
-
-function dragenter(obj) {
- obj.style.backgroundColor = 'red';
- return false;
}
-
-function dragleave(obj) {
- obj.style.backgroundColor = 'grey';
- return false;
-}
-
-function dropInBody(e) {
- e.preventDefault();
- e.stopPropagation();
-
- var id = e.dataTransfer.getData('Text');
- var task = document.getElementById(id);
- // task.parentNode.removeChild(task);
- // alert("move " + id.substring(5, id.length) + " " + target.id.substring(5,target.id.length) + ";");
- socket_task.send("move " + id.substring(5, id.length) + " -1;");
-
- // target.appendChild(task);
-}
-