Add dirtag.xul -> web.py data transfer.
[dirtag.git] / static / dirtag.js
index 554f9ae3976113ca984fae7b60f9632c027efed2..47f63d4f0fb8534bb8e84406d424d20f9e26ebe2 100644 (file)
@@ -17,17 +17,44 @@ function tree_selection(id) {
 
 /* Functions driving the CherryPy backend */
 
-function new_tag(path) {
-    alert('Adding tag: '+path.toString());
+function reload_rdf(e) {
     /* https://developer.mozilla.org/en/RDF_in_Mozilla_FAQ */
+    if (e.readyState == 4) { /* 4: request finished and response is ready */
+       if(e.status != 200) {
+           alert("Error loading page\n\n"+e.responseText);
+           return;
+       }
+       // Get the RDF service
+       var RDF =
+           Components
+           .classes['@mozilla.org/rdf/rdf-service;1']
+           .getService(Components.interfaces.nsIRDFService);
+       // Get the datasources and refresh them
+       RDF.GetDataSource('raw.rdf').Refresh('non-blocking');
+       RDF.GetDataSource('tag.rdf').Refresh('non-blocking');
+    }
+}
+
+function push_data(url) {
+    /* https://developer.mozilla.org/en/using_xmlhttprequest */
+    xmlDoc = new XMLHttpRequest();
+    xmlDoc.open('GET', url, true);
+    xmlDoc.onreadystatechange = function() { reload_rdf(xmlDoc); };
+    xmlDoc.send(null);
+}
+
+function new_tag(tag) {
+    push_data('/new_tag?tag='+escape(tag.join('/')));
 }
 
 function add_tag(path, tag) {
-    alert('Add tag '+tag+' to '+path.toString());
+    push_data('/add_tag?path='+escape(path.join('/'))
+             +'&tag='+escape(tag.join('/')));
 }
 
 function remove_tag(path, tag) {
-    alert('Remove tag '+tag+' from '+path.toString());
+    push_data('/remove_tag?path='+escape(path.join('/'))
+             +'&tag='+escape(tag.join('/')));
 }
 
 /* The bindings themselves */
@@ -50,7 +77,6 @@ function new_tag_button() {
 function set_selected_element(path) {
     element = document.getElementById('element');
     element.file_path = path;
-    alert('Set selected element: '+path.toString());
 }
 
 function raw_tree_select() {
@@ -65,7 +91,9 @@ function checkbox_activity(tree, row, col, value) {
     var path = document.getElementById('element').file_path;
     var name = tree.columns.getPrimaryColumn();
     id = tree_path(tree, row);
-    if (value == true || value == "true") {
+    if (path == 'UNDEFINED') {
+       return;
+    } else if (value == true || value == 'true') {
        add_tag(path, id);
     } else {
        remove_tag(path, id);