1 /* Useful helper functions */
3 function tree_path(tree, row) {
4 var name = tree.columns.getPrimaryColumn();
5 var path = new Array();
7 path.splice(0, 0, tree.view.getCellText(row, name));
8 row = tree.view.getParentIndex(row);
13 function tree_selection(id) {
14 var tree = document.getElementById(id);
15 return tree_path(tree, tree.currentIndex);
18 /* Functions driving the CherryPy backend */
20 function reload_rdf(e) {
21 /* https://developer.mozilla.org/en/RDF_in_Mozilla_FAQ */
22 if (e.readyState == 4) { /* 4: request finished and response is ready */
24 alert("Error loading page\n\n"+e.responseText);
27 // Get the RDF service
30 .classes['@mozilla.org/rdf/rdf-service;1']
31 .getService(Components.interfaces.nsIRDFService);
32 // Get the datasources and refresh them
33 RDF.GetDataSource('raw.rdf').Refresh('non-blocking');
34 RDF.GetDataSource('tag.rdf').Refresh('non-blocking');
38 function push_data(url) {
39 /* https://developer.mozilla.org/en/using_xmlhttprequest */
40 xmlDoc = new XMLHttpRequest();
41 xmlDoc.open('GET', url, true);
42 xmlDoc.onreadystatechange = function() { reload_rdf(xmlDoc); };
46 function new_tag(tag) {
47 push_data('/new_tag?tag='+escape(tag.join('/')));
50 function add_tag(path, tag) {
51 push_data('/add_tag?path='+escape(path.join('/'))
52 +'&tag='+escape(tag.join('/')));
55 function remove_tag(path, tag) {
56 push_data('/remove_tag?path='+escape(path.join('/'))
57 +'&tag='+escape(tag.join('/')));
60 /* The bindings themselves */
62 function initialize() {
63 element = document.getElementById('element').file_path = 'UNDEFINED';
64 var tree = document.getElementById('checkbox-tree');
65 tree.view.origSetCellValue = tree.view.setCellValue;
66 tree.view.setCellValue = function (row, col, value) {
67 tree.view.origSetCellValue(row, col, value);
68 checkbox_activity(tree, row, col, value);
72 function new_tag_button() {
73 var text = document.getElementById('new-tag-text').value;
74 new_tag(text.split('/'));
77 function set_selected_element(path) {
78 element = document.getElementById('element');
79 element.file_path = path;
82 function raw_tree_select() {
83 set_selected_element(tree_selection('raw-tree'));
86 function tag_tree_select() {
87 set_selected_element(tree_selection('tag-tree'));
90 function checkbox_activity(tree, row, col, value) {
91 var path = document.getElementById('element').file_path;
92 var name = tree.columns.getPrimaryColumn();
93 id = tree_path(tree, row);
94 if (path == 'UNDEFINED') {
96 } else if (value == true || value == 'true') {