/* 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 */
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() {
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);
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>