/* 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_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) {
- /* 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;
}
- // 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]);
}
}
/* 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) {
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_tags = tags;
+ element.tree_id = id;
+ // element.source = ...
}
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() {
- 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) {