2009-10-18 07:52:27 -05:00
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
|
|
|
|
metal:use-macro="here/main_template/macros/master">
|
|
|
|
|
|
|
|
<tal:comment replace="nothing">This page presents results of queries</tal:comment>
|
|
|
|
<body>
|
|
|
|
|
2009-10-20 09:57:00 -05:00
|
|
|
<tal:comment replace="nothing">Disable standard Plone green tabs</tal:comment>
|
|
|
|
<div metal:fill-slot="top_slot">
|
|
|
|
<metal:block metal:use-macro="here/global_defines/macros/defines" />
|
|
|
|
<div tal:define="dummy python:request.set('disable_border', 1)" />
|
|
|
|
</div>
|
2009-10-18 07:52:27 -05:00
|
|
|
|
2009-10-20 09:57:00 -05:00
|
|
|
<tal:comment replace="nothing">We suppose we are in the app folder here.</tal:comment>
|
|
|
|
<div metal:fill-slot="main"
|
|
|
|
tal:define="appFolder context/getParentNode;
|
|
|
|
appName appFolder/id;
|
|
|
|
tool python: portal.get('portal_%s' % appName.lower());
|
2009-11-03 08:02:18 -06:00
|
|
|
contentType python:context.REQUEST.get('type_name');
|
|
|
|
flavourNumber python:int(context.REQUEST.get('flavourNumber'));
|
2009-11-17 03:05:19 -06:00
|
|
|
searchName python:context.REQUEST.get('search', '')">
|
2009-10-18 07:52:27 -05:00
|
|
|
|
2009-10-20 09:57:00 -05:00
|
|
|
<div metal:use-macro="here/skyn/macros/macros/pagePrologue"/>
|
2009-11-03 08:02:18 -06:00
|
|
|
<script language="javascript">
|
|
|
|
<!--
|
|
|
|
function getSortValue(row, fieldName) {
|
|
|
|
// Find, from p_fieldName, the cell that is used for sorting.
|
|
|
|
var cellId = "field_" + fieldName;
|
|
|
|
var cells = row.cells;
|
|
|
|
for (var i=0; i < cells.length; i++) {
|
|
|
|
if (cells[i].id == cellId) {
|
|
|
|
// Ok we have the cell on which we must sort.
|
|
|
|
// Now get the cell content.
|
|
|
|
// If the cell contains links, content is the 1st link content
|
|
|
|
var innerLinks = cells[i].getElementsByTagName("a");
|
|
|
|
if (innerLinks.length > 0) {
|
|
|
|
return innerLinks[0].innerHTML;
|
|
|
|
} else {
|
|
|
|
return cells[i].innerHTML;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-10-18 07:52:27 -05:00
|
|
|
|
2009-11-03 08:02:18 -06:00
|
|
|
function sortRows(fieldName, ascending) {
|
|
|
|
var queryRows = cssQuery('#query_row');
|
|
|
|
// Create a wrapper for sorting
|
|
|
|
var RowWrapper = function(row, fieldName) {
|
|
|
|
this.value = getSortValue(row, fieldName);
|
|
|
|
this.cloned_node = row.cloneNode(true);
|
|
|
|
this.toString = function() {
|
|
|
|
if (this.value.toString) {
|
|
|
|
return this.value.toString();
|
|
|
|
} else {
|
|
|
|
return this.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Wrap nodes
|
|
|
|
var items = new Array();
|
|
|
|
for (var i=0; i<queryRows.length; i++) {
|
|
|
|
items.push(new RowWrapper(queryRows[i], fieldName));
|
|
|
|
}
|
|
|
|
// Sort nodes
|
|
|
|
items.sort();
|
|
|
|
if (!ascending) {
|
|
|
|
items.reverse();
|
|
|
|
}
|
|
|
|
// Reorder nodes
|
|
|
|
for (var i=0; i<items.length; i++) {
|
|
|
|
var dest = queryRows[i];
|
|
|
|
dest.parentNode.replaceChild(items[i].cloned_node, dest);
|
|
|
|
}
|
|
|
|
};
|
2009-10-18 07:52:27 -05:00
|
|
|
|
2009-11-03 08:02:18 -06:00
|
|
|
function onSort(fieldName){
|
|
|
|
// First, switch the sort arrow (up->down or down->up)
|
|
|
|
var arrow = document.getElementById("arrow_" + fieldName);
|
|
|
|
var sortAscending = (arrow.src.indexOf('arrowDown.gif') != -1);
|
|
|
|
if (sortAscending){
|
|
|
|
// Display "up" image
|
|
|
|
arrow.src = arrow.src.replace('arrowDown.gif', 'arrowUp.gif')
|
|
|
|
}
|
|
|
|
else { // Display "down" image
|
|
|
|
arrow.src = arrow.src.replace('arrowUp.gif', 'arrowDown.gif')
|
|
|
|
}
|
|
|
|
// Then, sort the rows on column "fieldName".
|
|
|
|
sortRows(fieldName, sortAscending);
|
|
|
|
}
|
2009-10-20 09:57:00 -05:00
|
|
|
|
2009-11-03 08:02:18 -06:00
|
|
|
function cellMatches(cell, searchValue) {
|
|
|
|
// This function returns true if the HTML p_cell contains p_searchValue
|
|
|
|
var innerLinks = cell.getElementsByTagName("a");
|
|
|
|
// If the cell contains links, we search within the link contents
|
|
|
|
for (var i=0; i < innerLinks.length; i++){
|
|
|
|
var linkContent = innerLinks[i].innerHTML.toLowerCase();
|
|
|
|
if (linkContent.indexOf(searchValue) != -1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If we are here, we still have no match. Let's search directly within
|
|
|
|
// the cell.
|
|
|
|
var cellContent = cell.innerHTML.toLowerCase();
|
|
|
|
if (cellContent.indexOf(searchValue) != -1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onTextEntered(fieldName) {
|
|
|
|
// Is called whenever text is entered into field named p_fieldName.
|
|
|
|
var cellId = "field_" + fieldName
|
|
|
|
var field = document.getElementById("filter_" + fieldName);
|
|
|
|
var fieldValue = field.value.toLowerCase();
|
|
|
|
if (fieldValue.length >= 3) {
|
|
|
|
// Browse all rows and check if it should be visible or not.
|
|
|
|
var queryRows = cssQuery('#query_row');
|
|
|
|
for (var i=0; i < queryRows.length; i++) {
|
|
|
|
// Find the value of the cell.
|
|
|
|
var queryCells = queryRows[i].cells;
|
|
|
|
for (var j=0; j < queryCells.length; j++) {
|
|
|
|
if (queryCells[j].id == cellId) {
|
|
|
|
if (cellMatches(queryCells[j], fieldValue)) {
|
|
|
|
queryRows[i].style.display = "";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
queryRows[i].style.display = "none";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Show all rows
|
|
|
|
var queryRows = cssQuery('#query_row');
|
|
|
|
for (var i=0; i < queryRows.length; i++) {
|
|
|
|
queryRows[i].style.display = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-->
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<tal:comment replace="nothing">Query result</tal:comment>
|
|
|
|
<div id="queryResult"></div>
|
|
|
|
|
|
|
|
<script language="javascript"
|
|
|
|
tal:define="ajaxUrl python: tool.getQueryUrl(contentType, flavourNumber, searchName)"
|
|
|
|
tal:content="python: 'askAjaxChunk(\'queryResult\',\'%s\')' % ajaxUrl">
|
|
|
|
</script>
|
2009-10-20 09:57:00 -05:00
|
|
|
</div>
|
2009-10-18 07:52:27 -05:00
|
|
|
</body>
|
|
|
|
</html>
|