The checkboxes were not settable in the previous implementation.
[dirtag.git] / static / dirtag.js
index e40611210fe08afb9c31fa657426b30bcad37352..554f9ae3976113ca984fae7b60f9632c027efed2 100644 (file)
@@ -1,29 +1,18 @@
 /* Useful helper functions */
 
-function tree_selection(id) {
-    var tree = document.getElementById(id);
+function tree_path(tree, row) {
     var name = tree.columns.getPrimaryColumn();
-    var i = tree.currentIndex;
     var path = new Array();
-    while (i >= 0) {
-       path.splice(0, 0, tree.view.getCellText(i, name));
-       i = tree.view.getParentIndex(i);
+    while (row >= 0) {
+       path.splice(0, 0, tree.view.getCellText(row, name));
+       row = tree.view.getParentIndex(row);
     }
     return path;
 }
 
-function tree_selection_and_check(id) {
+function tree_selection(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];
+    return tree_path(tree, tree.currentIndex);
 }
 
 /* Functions driving the CherryPy backend */
@@ -45,6 +34,12 @@ function remove_tag(path, tag) {
 
 function initialize() {
     element = document.getElementById('element').file_path = 'UNDEFINED';
+    var tree = document.getElementById('checkbox-tree');
+    tree.view.origSetCellValue = tree.view.setCellValue;
+    tree.view.setCellValue = function (row, col, value) {
+       tree.view.origSetCellValue(row, col, value);
+       checkbox_activity(tree, row, col, value);
+    };
 }
 
 function new_tag_button() {
@@ -66,15 +61,11 @@ function tag_tree_select() {
     set_selected_element(tree_selection('tag-tree'));
 }
 
-function tag_check(event) {
+function checkbox_activity(tree, row, col, value) {
     var path = document.getElementById('element').file_path;
-    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) {
+    var name = tree.columns.getPrimaryColumn();
+    id = tree_path(tree, row);
+    if (value == true || value == "true") {
        add_tag(path, id);
     } else {
        remove_tag(path, id);