The checkboxes were not settable in the previous implementation.
[dirtag.git] / static / dirtag.js
1 /* Useful helper functions */
2
3 function tree_path(tree, row) {
4     var name = tree.columns.getPrimaryColumn();
5     var path = new Array();
6     while (row >= 0) {
7         path.splice(0, 0, tree.view.getCellText(row, name));
8         row = tree.view.getParentIndex(row);
9     }
10     return path;
11 }
12
13 function tree_selection(id) {
14     var tree = document.getElementById(id);
15     return tree_path(tree, tree.currentIndex);
16 }
17
18 /* Functions driving the CherryPy backend */
19
20 function new_tag(path) {
21     alert('Adding tag: '+path.toString());
22     /* https://developer.mozilla.org/en/RDF_in_Mozilla_FAQ */
23 }
24
25 function add_tag(path, tag) {
26     alert('Add tag '+tag+' to '+path.toString());
27 }
28
29 function remove_tag(path, tag) {
30     alert('Remove tag '+tag+' from '+path.toString());
31 }
32
33 /* The bindings themselves */
34
35 function initialize() {
36     element = document.getElementById('element').file_path = 'UNDEFINED';
37     var tree = document.getElementById('checkbox-tree');
38     tree.view.origSetCellValue = tree.view.setCellValue;
39     tree.view.setCellValue = function (row, col, value) {
40         tree.view.origSetCellValue(row, col, value);
41         checkbox_activity(tree, row, col, value);
42     };
43 }
44
45 function new_tag_button() {
46     var text = document.getElementById('new-tag-text').value;
47     new_tag(text.split('/'));
48 }
49
50 function set_selected_element(path) {
51     element = document.getElementById('element');
52     element.file_path = path;
53     alert('Set selected element: '+path.toString());
54 }
55
56 function raw_tree_select() {
57     set_selected_element(tree_selection('raw-tree'));
58 }
59
60 function tag_tree_select() {
61     set_selected_element(tree_selection('tag-tree'));
62 }
63
64 function checkbox_activity(tree, row, col, value) {
65     var path = document.getElementById('element').file_path;
66     var name = tree.columns.getPrimaryColumn();
67     id = tree_path(tree, row);
68     if (value == true || value == "true") {
69         add_tag(path, id);
70     } else {
71         remove_tag(path, id);
72     }
73 }