Added working RDF refresh. master
authorW. Trevor King <wking@drexel.edu>
Sun, 18 Jul 2010 00:07:48 +0000 (20:07 -0400)
committerW. Trevor King <wking@drexel.edu>
Sun, 18 Jul 2010 00:07:48 +0000 (20:07 -0400)
The previous Components.classes approach required chrome:// permissions.

Also took a stab at updating the checkboxes when we reload data or
change the currently selected file.  I think I'm writing the correct
value, but the checkboxes are not being displayed...

static/dirtag.js
template/dirtag.xul

index 47f63d4f0fb8534bb8e84406d424d20f9e26ebe2..b6f5373e93884ec745e3260cb64ecfc0628edb1b 100644 (file)
@@ -1,5 +1,14 @@
 /* Useful helper functions */
 
 /* Useful helper functions */
 
+function tree_tags(tree, row) {
+    var ctags = tree.columns.getLastColumn();
+    var tags = tree.view.getCellText(row, ctags).split(',');
+    for (var i=0; i<tags.length; i++) {
+       tags[i] = tags[i].split('/');
+    }
+    return tags;
+}
+
 function tree_path(tree, row) {
     var name = tree.columns.getPrimaryColumn();
     var path = new Array();
 function tree_path(tree, row) {
     var name = tree.columns.getPrimaryColumn();
     var path = new Array();
@@ -12,26 +21,49 @@ function tree_path(tree, row) {
 
 function tree_selection(id) {
     var tree = document.getElementById(id);
 
 function tree_selection(id) {
     var tree = document.getElementById(id);
-    return tree_path(tree, tree.currentIndex);
+    return [tree_path(tree, tree.currentIndex),
+           tree_tags(tree, tree.currentIndex),];
+}
+
+function tag_in_tags(tag, tags) {
+    /* Convert a regular array into an associative array for 'in' comparisons
+         http://snook.ca/archives/javascript/testing_for_a_v
+    */
+    var o = {};
+    for(var i=0; i<tags.length; i++) {
+       o[tags[i].join('/')] = '';  // .join('/') b/c indexes must be strings
+    }
+    return tag.join('/') in o;
+}
+
+function setup_checkboxes(tags) {
+    var tree = document.getElementById('checkbox-tree');
+    var ctags = tree.columns.getLastColumn();
+    for (var row=0; row<tree.view.rowCount; row++) {
+       p = tree_path(tree, row);
+       tree.view.origSetCellValue(row, ctags, tag_in_tags(p, tags));
+    }
+    tree.treeBoxObject.invalidateColumn(ctags);
 }
 
 /* Functions driving the CherryPy backend */
 
 function reload_rdf(e) {
 }
 
 /* Functions driving the CherryPy backend */
 
 function reload_rdf(e) {
-    /* https://developer.mozilla.org/en/RDF_in_Mozilla_FAQ */
+    /* https://developer.mozilla.org/en/RDF_in_Mozilla_FAQ
+       https://developer.mozilla.org/en/XUL/Template_Guide/Template_Builder_Interface
+     */
     if (e.readyState == 4) { /* 4: request finished and response is ready */
        if(e.status != 200) {
            alert("Error loading page\n\n"+e.responseText);
            return;
        }
     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');
+       document.getElementById('raw-tree').builder.refresh();
+       document.getElementById('tag-tree').builder.refresh();
+       document.getElementById('checkbox-tree').builder.refresh();
+
+       var id = document.getElementById('element').tree_id;
+       var path_tags = tree_selection(id);
+       setup_checkboxes(path_tags[1]);
     }
 }
 
     }
 }
 
@@ -60,7 +92,7 @@ function remove_tag(path, tag) {
 /* The bindings themselves */
 
 function initialize() {
 /* The bindings themselves */
 
 function initialize() {
-    element = document.getElementById('element').file_path = 'UNDEFINED';
+    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) {
     var tree = document.getElementById('checkbox-tree');
     tree.view.origSetCellValue = tree.view.setCellValue;
     tree.view.setCellValue = function (row, col, value) {
@@ -74,17 +106,28 @@ function new_tag_button() {
     new_tag(text.split('/'));
 }
 
     new_tag(text.split('/'));
 }
 
-function set_selected_element(path) {
-    element = document.getElementById('element');
+function set_selected_element(path, tags, id) {
+    var caption = document.getElementById('selected-caption');
+    var title = caption.label.split(':', 1)[0];
+    caption.label = title+': '+path.join('/');
+
+    setup_checkboxes(tags);
+
+    var element = document.getElementById('element');
     element.file_path = path;
     element.file_path = path;
+    element.file_tags = tags;
+    element.tree_id = id;
+    // element.source = ...
 }
 
 function raw_tree_select() {
 }
 
 function raw_tree_select() {
-    set_selected_element(tree_selection('raw-tree'));
+    var path_tags = tree_selection('raw-tree');
+    set_selected_element(path_tags[0], path_tags[1], 'raw-tree');
 }
 
 function tag_tree_select() {
 }
 
 function tag_tree_select() {
-    set_selected_element(tree_selection('tag-tree'));
+    var path_tags = tree_selection('tag-tree');
+    set_selected_element(path_tags[0], path_tags[1], 'tag-tree');
 }
 
 function checkbox_activity(tree, row, col, value) {
 }
 
 function checkbox_activity(tree, row, col, value) {
index a6d6920cc47143a5403bbd1036c3c11babd29061..26b145766b55fd736e9ff15c3a82cbb8797e1977 100644 (file)
     </groupbox>
     <splitter collapse="before"><grippy/></splitter>
     <groupbox id="selected" flex="2" orient="horizontal">
     </groupbox>
     <splitter collapse="before"><grippy/></splitter>
     <groupbox id="selected" flex="2" orient="horizontal">
-      <caption label="&selected.caption;"/>
+      <caption id="selected-caption" label="&selected.caption;"/>
       <groupbox id="tags" flex="1">
        <caption label="&tags.caption;"/>
        <tree id="checkbox-tree" rows="2" seltype="single" selstype="primary"
       <groupbox id="tags" flex="1">
        <caption label="&tags.caption;"/>
        <tree id="checkbox-tree" rows="2" seltype="single" selstype="primary"
              <treechildren>
                <treeitem uri="rdf:*" open="true">
                  <treerow>
              <treechildren>
                <treeitem uri="rdf:*" open="true">
                  <treerow>
-                   <treecell value="true" editable="true"/>
+                   <treecell editable="true"/>
                    <treecell label="rdf:http://dirtag.com/rdf#name"/>
                  </treerow>
                </treeitem>
                    <treecell label="rdf:http://dirtag.com/rdf#name"/>
                  </treerow>
                </treeitem>