sphinix wrote:
Is it possible to incorporate into ATK a feature whereby a person can select records from different tables based on the option selected in the parent attribute.
It is like filtering by a field BUT in this case u select a different table.
what I basically want to do is to have a first attribute displaying a list of item groups(related or unrelated) eg.
.
When I select a group,I want the next attribute to list the items that fall within that group.eg. if I select "Cars",it should query the Cars table a display the items in it. when I select "Generators" it should query the generator table and display the items in it.
Obviously this would have been easier if all items were in one table ;so that I could just filter but they all have different tables.
any thoughts
The way I've done similar features in the passed is by using custom javascript.
Below is you'll find some ideas:
1. Use the onChange() javascript function on the group selector node
2. Hide (with javascript) both sub lists attributes when creating a new record. Below is a sample javascript function to hide HTML elements:
Code:
/* Jorge Garifuna
*
* sets the display of an item to either show or none
*
**/
function set_item_display(elementid, display){
document.getElementById(elementid).style.display = display;
}// end function
NOTE: ATK pre-appends "ar_" as the row ID of every attribute. For example if you have an attribute called "test", ATK would have a table row for this attribute as follows:
Code:
<tr id="ar_test" class="section_default">...</tr>
so to hide the row using the function above:
Code:
set_item_display('ar_test','none');
and the display the row:
Code:
set_item_display('ar_test','');
3. Call a custom javascript function when the user changes the value of your group selector attribute. This custom javascript function should collect enough information from the calling attribute to determine which sub list to process. upon determining the sub list to process, make that sub list visible and hide the unrelated sub list using the javascript function mentioned on the previous step.
4. When loading the record for editing or viewing mode, you can dynamically load javascript to show the proper sub list and hide the unrelated sub list. Below you will find come ATK code with comments where you could possibly choose to hide and display the sub lists. Review the detailPageFooter() function below. Please note that detailPageFooter() is not a native ATK function. I made this function to consolidate the calls of ATK functions: editPage(), viewPage(), addPage(), and adminPage():
Code:
// this function is called when editing an individual record
// any information here will be displayed on the footer section of the edited record page
function editPage(&$handler, $record, $locked=false)
{
return $this->detailPageFooter($handler, $record, $locked);
}
// this function is called when viewing an individual record
// any information here will be displayed on the footer section of the viewed record page
function viewPage(&$handler, $record, $locked=false)
{
return $this->detailPageFooter($handler, $record, $locked,"view");
}
// this function is called when adding a new record
function addPage(&$handler,$record){
return $this->detailPageFooter($handler, $record, $locked,"add");
}
// this function is called on admin mode
function adminPage(&$handler){
return $this->detailPageFooter($handler, "admin", $locked,"admin");
}
// this is a custom helper function for editPage and viewPage
// you can consolidate operations here unless you need to display different information
// when editing and viewing the record
// the information will be displayed on the footer page when editing or viewing an individual record
function detailPageFooter(&$handler, $record, $locked=false, $mode="edit")
{
/* if($mode == "view"){
$page = $handler->viewPage($record, $locked);
}else{// edit
$page = $handler->editPage($record, $locked);
} */
$pageType = $mode."Page";
$page = $handler->$pageType($record, $locked);
// detect mode (edit or view) here
// load javascript to display related sub list and hide unrelated sub list attribute
$data_info = "";
$page .= $data_info;
return $page;
} // end function
Hopefully this provides some useful ideas.