Use checkbox tree rather than a simple array for element tags in dirtag.xul
[dirtag.git] / static / dirtag.js
index d04acaa6ca5129ec6f196a9c5f2f89e2a14e141c..e40611210fe08afb9c31fa657426b30bcad37352 100644 (file)
@@ -12,6 +12,20 @@ function tree_selection(id) {
     return path;
 }
 
+function tree_selection_and_check(id) {
+    var tree = document.getElementById(id);
+    var name = tree.columns.getPrimaryColumn();
+    var check = tree.columns.getFirstColumn();
+    var i = tree.currentIndex;
+    var checked = tree.view.getCellValue(i, check);
+    var path = new Array();
+    while (i >= 0) {
+       path.splice(0, 0, tree.view.getCellText(i, name));
+       i = tree.view.getParentIndex(i);
+    }
+    return [path, checked];
+}
+
 /* Functions driving the CherryPy backend */
 
 function new_tag(path) {
@@ -20,11 +34,11 @@ function new_tag(path) {
 }
 
 function add_tag(path, tag) {
-    alert('Add tag '+path.toString()+' to '+tag);
+    alert('Add tag '+tag+' to '+path.toString());
 }
 
 function remove_tag(path, tag) {
-    alert('Remove tag '+path.toString()+' from '+tag);
+    alert('Remove tag '+tag+' from '+path.toString());
 }
 
 /* The bindings themselves */
@@ -41,7 +55,7 @@ function new_tag_button() {
 function set_selected_element(path) {
     element = document.getElementById('element');
     element.file_path = path;
-    alert(path.toString());
+    alert('Set selected element: '+path.toString());
 }
 
 function raw_tree_select() {
@@ -54,9 +68,15 @@ function tag_tree_select() {
 
 function tag_check(event) {
     var path = document.getElementById('element').file_path;
-    if (event.target.checked) {
-       add_tag(path, event.target.id);
+    var a = tree_selection_and_check('checkbox-tree');
+    id = a[0];
+    checked = a[1];
+    alert('path: '+path.toString());
+    alert('id: '+id);
+    alert('check: '+checked);
+    if (checked) {
+       add_tag(path, id);
     } else {
-       remove_tag(path, event.target.id);
+       remove_tag(path, id);
     }
 }