// Controller Page // This is the taxa_list_js.js page included on the species_checklists.php page // This file is the JavaScript used for Ajax checklist generation // This files uses Ajax in prototype.js to populate node with sub list // Contains functions to open and close sublists when user clicks branches // Creates variables: to register behaviours // taxa_list_rules // element_id // // Contains functions: // get_region // get_sub_list - Ajax command to generate and insert checklist sub list // show_response // close_sub_list // show_sub_list // // Calls: // register in behavious.js file to begin /*----- Register behaviours -----*/ var taxa_list_rules = { //alert(el.parentNode.className ); '.taxa_list a' : function(el) { if(el.parentNode.className != 'species'){ //get_sub_list is called to display a sub tree when a checklist tree branch is clicked el.onclick = function(){ get_sub_list(this, 'all'); return false; } } } } var element_id = ''; /*----- Ajax command to generate and insert checklist sub list -----*/ function get_sub_list(element, extent) { //Initialise function variables var current_field = element.parentNode.className; var current_value = element.firstChild.nodeValue; element_id = current_value + '_submenu'; var parent_value = element.parentNode.parentNode.parentNode.firstChild.nodeValue; if(parent_value == null){ //Test for case where submenus have different DOM trees parent_value = element.parentNode.parentNode.parentNode.firstChild.firstChild.nodeValue; } //Check to see if node has already been created, apply open or close functions instead. if($(element_id)){ if($(element_id).style.display == 'none'){ show_sub_list(element); return false; }else{ close_sub_list(element); return false; } } //Create node for sub menu var sub_menu = document.createElement('ul'); element.parentNode.appendChild(sub_menu); sub_menu.setAttribute('id', current_value+'_submenu'); sub_menu.className = 'taxa_list';//creates the style class associated with the checklist ul tags sub_menu.style.display = 'none'; element.style.background = 'url(images/minus_icon.gif) no-repeat left'; //Use Prototype Ajax object to populate node with sub list var pars = 'extent=' + extent +'®ion=1&where=' + parent_value + ',' + current_value + '&species_count=yes¤t_field=' + current_field; var url = 'scripts/ajax_taxa_list.php'; //var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onComplete: show_response, on404: alert_error} ); var myAjax = new Ajax.Updater(element_id, url+'?'+pars, {method:'get', onComplete: show_response});//this is called within the prototype.js file } function show_response(original_request){ //alert(original_request.responseText); $(element_id).innerHTML = original_request.responseText; var links = $(element_id).getElementsByTagName("a"); for (var i=0; i