The checkboxes were not settable in the previous implementation.
authorW. Trevor King <wking@drexel.edu>
Sat, 17 Jul 2010 14:08:34 +0000 (10:08 -0400)
committerW. Trevor King <wking@drexel.edu>
Sat, 17 Jul 2010 14:08:34 +0000 (10:08 -0400)
The problem seems to stem from the old
  flags="dont-build-content"
setting, which selects tree vs. content templating.  See
  https://developer.mozilla.org/en/XUL_Tutorial/Trees_and_Templates
  https://developer.mozilla.org/en/XUL/Attribute/flags
for details.

Also hooked checkbox handler (checkbox_activity()) on as a method of
the tree.view, which makes it easier to only act on checkbox activity,
and locate the active row.

Other tidbits:
  * Set type="application/javascript" in dirtag.js import.
    Might as well to that formally.
  * selstype="primary" in checkbox-tree.
    I'd rather disable selection entirely, but this at least keeps it off the
    checkbox column.

static/dirtag.js
static/dirtag.xul

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);
index 9481f341defcc169e6f9d96e8ecf545c268af531..cf5ac73104a6ba7161e00804f5f2c5558272c0c2 100644 (file)
@@ -28,7 +28,7 @@
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    >
 
-  <script src="dirtag.js"/>
+  <script type="application/javascript" src="dirtag.js"/>
   <groupbox id="new-tag">
     <caption label="&new_tag.caption;"/>
     <hbox>
     <splitter collapse="before"><grippy/></splitter>
     <groupbox id="selected" flex="2" orient="horizontal">
       <caption label="&selected.caption;"/>
-      <groupbox id="tags" oncommand="tag_check(event);" flex="1">
+      <groupbox id="tags" flex="1">
        <caption label="&tags.caption;"/>
-       <tree id="checkbox-tree" rows="2" seltype="single" editable="true"
+       <tree id="checkbox-tree" rows="2" seltype="single" selstype="primary"
+             editable="true"
              datasources="tag-tree.rdf raw-tree.rdf"
              ref="http://dirtag.com/tag/files"
-             flags="dont-build-content" onselect="tag_check();" flex="1">
+             flex="1">
+         <!-- checkbox callback attached in dirtag.js's initialize() -->
          <treecols>
            <treecol id="checkbox-tree-check-column" label="CK" type="checkbox"
                     editable="true"/>
              <treechildren>
                <treeitem uri="rdf:*" open="true">
                  <treerow>
-                   <treecell value="true"/>
+                   <treecell value="true" editable="true"/>
                    <treecell label="rdf:http://dirtag.com/rdf#name"/>
                  </treerow>
                </treeitem>