summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Suhr Christensen <jsc@umbraculum.org>2012-03-11 11:39:35 +0100
committerJonas Suhr Christensen <jsc@umbraculum.org>2012-03-11 11:39:35 +0100
commite0b372c0ba5748e378919e55900220112575b583 (patch)
tree91d06a58de5ce33c153f8b1ce7f44178d2c6f1d9
parent39396a2660150770c3fd14aac8b4be0dcbae8497 (diff)
Fixed drag and drop problem by stopping propagation of the event.
+ some non-finished updatign code.
-rw-r--r--proto.js20
-rw-r--r--src/http.cc2
-rw-r--r--src/msgparser.cc5
-rw-r--r--src/task_proto.cc28
4 files changed, 47 insertions, 8 deletions
diff --git a/proto.js b/proto.js
index 5d855b0..f0aa571 100644
--- a/proto.js
+++ b/proto.js
@@ -172,8 +172,6 @@ try {
var title = msg[2];
var description = msg[3];
var parent_id = msg[4];
-// var left = msg[4];
-// var top = msg[5];
var task = document.createElement("div");
task.name = "task";
@@ -187,8 +185,9 @@ try {
task.id = "task_" + id;
var taskText = document.createTextNode(title + ": " + description + " :" + task.id);
- task.appendChild(taskText);
-
+ taskText.id = "txt";
+ task.appendChild(taskText);
+
// task.style.position = "absolute";
// task.style.left = left + "px";
// task.style.top = top + "px";
@@ -201,7 +200,7 @@ try {
// dlButton.setAttribute("onclick", "deleteTask(" + id +")");
// task.appendChild(dlButton);
- document.body.appendChild(task);
+// document.body.appendChild(task);
var parent_task = document.getElementById("task_" + parent_id);
@@ -212,6 +211,16 @@ try {
document.body.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";
@@ -282,6 +291,7 @@ function deleteTask(id) {
function drag(target, e) {
e.dataTransfer.setData('Text', target.id);
+ e.stopPropagation(); // <--- this fixes the drag target problem
}
function drop(target, e) {
diff --git a/src/http.cc b/src/http.cc
index c755442..fe37d76 100644
--- a/src/http.cc
+++ b/src/http.cc
@@ -41,7 +41,7 @@ int callback_http(struct libwebsocket_context * context,
switch(reason) {
case LWS_CALLBACK_HTTP:
fprintf(stderr, "serving HTTP URI %s\n", (char *)in);
-
+//
// add favicon later
if(in && strcmp((const char *)in, "/favicon.ico") == 0) {
if(libwebsockets_serve_http_file(wsi,
diff --git a/src/msgparser.cc b/src/msgparser.cc
index f3bafe1..675e305 100644
--- a/src/msgparser.cc
+++ b/src/msgparser.cc
@@ -203,6 +203,9 @@ MsgVector parse_msg(std::string data) {
printf("Wrong number of parameters\n");
continue;
}
+ m.update.id = atoi(t[1].c_str());
+ sprintf(m.update.title, "%s", t[2].c_str());
+ sprintf(m.update.desc, "%s", t[3].c_str());
break;
}
default:
@@ -247,6 +250,7 @@ msg_t create_msg(cmd::cmd_t type, task_t t) {
// m.update.desc = t.desc;
snprintf(m.update.title, sizeof(m.update.title), "%s", t.title.c_str());
snprintf(m.update.desc, sizeof(m.update.desc), "%s", t.desc.c_str());
+// printf("msg: %d, %s, %s\n", m.update.id, m.update.title, m.update.desc);
break;
};
default:
@@ -286,6 +290,7 @@ std::string msg_tostring(msg_t m) {
}
case cmd::update: {
//todo
+ asprintf(&buf, "update %d \"%s\" \"%s\";", m.update.id, m.update.title, m.update.desc);
break;
};
default:
diff --git a/src/task_proto.cc b/src/task_proto.cc
index 717ca3e..2312c9e 100644
--- a/src/task_proto.cc
+++ b/src/task_proto.cc
@@ -260,9 +260,33 @@ int callback_lws_task(struct libwebsocket_context * context,
printf("Moving task: %s\n", buf_str.c_str());
break;
}
- case cmd::update:
- printf("Update\n");
+ case cmd::update: {
+ printf("Updating %d\n", m.update.id);
+
+ bool id_found = false;
+ TaskList::iterator it;
+
+ task_t updated_task;
+ for(it = tasklist.begin(); it != tasklist.end(); it++) {
+ task_t &t = *it;
+ if(t.id == m.update.id) {
+ id_found = true;
+ t.title = m.update.title;
+ t.desc = m.update.desc;
+ updated_task = t;
+ break;
+ }
+ }
+
+ if(!id_found) {
+ printf("\t!!!Could not locate task with id %d\n", m.update.id);
+ }
+
+ buf_str = msg_tostring(create_msg(cmd::update, updated_task));
+ printf("Updating task: %s\n", buf_str.c_str());
+
break;
+ }
default:
printf("Wrong command :(\n");
break;