2010-08-06 09:01:44 -05:00
|
|
|
|
|
|
|
//Columns is an array of items in the form
|
|
|
|
// {title, column, render}
|
|
|
|
//title: the the value that goes at the head of the column
|
|
|
|
//filed: the column in the response used for populating the value
|
|
|
|
//render: the function used to generate cell.innerHtml
|
|
|
|
// it is in the form:
|
|
|
|
// render(current, cell)
|
|
|
|
// current is the row in response
|
|
|
|
// cell is the td in the table
|
|
|
|
|
|
|
|
|
|
|
|
//These are helper functions, either assigned to the rneder method
|
|
|
|
//Or called from a thin wrapper render method
|
|
|
|
function renderSimpleColumn(current,cell){
|
2010-08-23 21:32:23 -05:00
|
|
|
cell.innerHTML = current[this.column];
|
2010-08-06 09:01:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function renderUnknownColumn(current,cell){
|
|
|
|
cell.innerHTML = "Unknown";
|
|
|
|
}
|
|
|
|
|
2010-08-23 21:32:23 -05:00
|
|
|
|
2010-09-07 09:08:19 -05:00
|
|
|
function renderPkeyColumn2(obj,pkeyCol,current,cell){
|
2010-08-23 21:32:23 -05:00
|
|
|
$("<a/>",{
|
2010-09-07 09:08:19 -05:00
|
|
|
href:"#tab="+obj+"&facet=details&pkey="+current[pkeyCol],
|
|
|
|
html: "" + current[pkeyCol],
|
2010-08-23 21:32:23 -05:00
|
|
|
}).appendTo(cell);
|
|
|
|
}
|
|
|
|
|
2010-09-07 09:08:19 -05:00
|
|
|
function renderPkeyColumn(form,current,cell){
|
|
|
|
renderPkeyColumn2(form.obj, form.pkeyCol,current, cell);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-23 21:32:23 -05:00
|
|
|
|
2010-08-06 09:01:44 -05:00
|
|
|
function renderDetailColumn(current,cell,pkey,obj){
|
2010-08-19 19:48:21 -05:00
|
|
|
$("<a/>",{
|
2010-08-23 21:32:23 -05:00
|
|
|
href:"#tab="+obj+"&facet=details&pkey="+pkey,
|
|
|
|
html: ""+ current[this.column],
|
2010-08-19 19:48:21 -05:00
|
|
|
}).appendTo(cell);
|
2010-08-06 09:01:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-09-07 09:08:19 -05:00
|
|
|
function SearchForm(obj, method, cols){
|
2010-08-06 09:01:44 -05:00
|
|
|
|
|
|
|
this.buildColumnHeaders = function (){
|
2010-08-23 21:32:23 -05:00
|
|
|
var columnHeaders = document.createElement("tr");
|
|
|
|
for (var i =0 ; i != this.columns.length ;i++){
|
|
|
|
var th = document.createElement("th");
|
|
|
|
th.innerHTML = this.columns[i].title;
|
|
|
|
columnHeaders.appendChild(th);
|
|
|
|
}
|
|
|
|
$('#searchResultsTable thead:last').append(columnHeaders);
|
2010-08-06 09:01:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.renderResultRow = function(current){
|
2010-08-23 21:32:23 -05:00
|
|
|
var row = document.createElement("tr");
|
|
|
|
var cell;
|
|
|
|
var link;
|
|
|
|
for(var index = 0 ; index < this.columns.length; index++){
|
|
|
|
this.columns[index].render(current, row.insertCell(-1));
|
|
|
|
}
|
|
|
|
return row;
|
2010-08-06 09:01:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
this.searchSuccess = function (json){
|
2010-09-07 09:08:19 -05:00
|
|
|
if (json.result.truncated){
|
|
|
|
$("#searchResultsTable tfoot").html("More than "+sizelimit+" results returned. First "+ sizelimit+" results shown." );
|
|
|
|
}else{
|
|
|
|
$("#searchResultsTable tfoot").html(json.result.summary);
|
|
|
|
}
|
|
|
|
$("#searchResultsTable tbody").find("tr").remove();
|
|
|
|
for (var index = 0; index != json.result.result.length; index++){
|
|
|
|
var current = json.result.result[index];
|
|
|
|
$('#searchResultsTable tbody:last').append(this.renderResultRow(current));
|
|
|
|
}
|
2010-08-06 09:01:44 -05:00
|
|
|
}
|
|
|
|
|
2010-08-19 19:48:21 -05:00
|
|
|
this.searchWithFilter = function(queryFilter){
|
2010-09-07 09:08:19 -05:00
|
|
|
var form = this;
|
|
|
|
|
|
|
|
$('#searchResultsTable tbody').html("");
|
|
|
|
$('#searchResultsTable tbody').html("");
|
|
|
|
$('#searchResultsTable tfoot').html("");
|
|
|
|
|
|
|
|
ipa_cmd(this.method,
|
|
|
|
[queryFilter],
|
|
|
|
{"all":"true"},
|
|
|
|
function(json){
|
|
|
|
form.searchSuccess(json);
|
|
|
|
},
|
|
|
|
function(json){
|
|
|
|
alert("Search Failed");
|
|
|
|
},
|
|
|
|
form.obj);
|
2010-08-23 21:32:23 -05:00
|
|
|
}
|
2010-08-06 09:01:44 -05:00
|
|
|
|
2010-08-23 21:32:23 -05:00
|
|
|
this.setup = function(){
|
2010-09-07 09:08:19 -05:00
|
|
|
showSearch();
|
|
|
|
|
|
|
|
$('#searchResultsTable thead').html("");
|
|
|
|
$('#searchResultsTable tbody').html("");
|
|
|
|
$('#searchResultsTable tfoot').html("");
|
|
|
|
$("#new").click(function(){
|
|
|
|
location.hash="tab="+obj+"&facet=add";
|
|
|
|
});
|
|
|
|
$("#query").click(executeSearch);
|
|
|
|
this.buildColumnHeaders();
|
|
|
|
var params = ipa_parse_qs();
|
|
|
|
qs = location.hash.substring(1);
|
|
|
|
//TODO fix this hack. since parse returns an object, I don't know how to see if that object has a"critia" property if criteria is null.
|
|
|
|
if (qs.indexOf("criteria") > 0)
|
|
|
|
{
|
|
|
|
this.searchWithFilter(params["criteria"]);
|
|
|
|
}
|
2010-08-19 19:48:21 -05:00
|
|
|
}
|
2010-08-06 09:01:44 -05:00
|
|
|
|
2010-08-23 21:32:23 -05:00
|
|
|
this.obj = obj;
|
|
|
|
this.method = method;
|
|
|
|
this.columns = cols;
|
|
|
|
this.setup();
|
|
|
|
}
|
|
|
|
executeSearch = function(){
|
2010-08-06 09:01:44 -05:00
|
|
|
var queryFilter = $("#queryFilter").val();
|
2010-08-23 21:32:23 -05:00
|
|
|
var qp = ipa_parse_qs();
|
|
|
|
var tab = qp.tab;
|
|
|
|
if (!tab){
|
|
|
|
tab = 'user';
|
|
|
|
}
|
|
|
|
window.location.hash="#tab="
|
|
|
|
+tab
|
|
|
|
+"&facet=search&criteria="
|
|
|
|
+queryFilter;
|
2010-08-06 09:01:44 -05:00
|
|
|
}
|