Reapply merged changes

This commit is contained in:
Terry Brady
2016-04-27 14:18:01 -07:00
parent 2e309a116f
commit f9fc64aaeb
6 changed files with 1301 additions and 1189 deletions

View File

@@ -0,0 +1,58 @@
<!--
The contents of this file are subject to the license and copyright
detailed in the LICENSE and NOTICE files at the root of the source
tree and available online at
http://www.dspace.org/license/
-->
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<!-- sortable.js can be obtained at http://www.kryogenix.org/code/browser/sorttable/ -->
<!-- <script src="sorttable.js"></script> -->
<script src="restReport.js"></script>
<script type="text/javascript">
var AuthReport = function() {
Report.call(this);
this.makeAuthLink = function(){return false;};
}
$(document).ready(function(){
var myReport=new AuthReport();
$("#authenticate").on("click",function(){
myReport.init();
});
$("#logout").on("click",function(){
myReport.myAuth.logout();
});
});
</script>
<script src="spin.js"></script>
<link rel="stylesheet" type="text/css" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/smoothness/jquery-ui.css"></link>
<link rel="stylesheet" type="text/css" href="restClient.css"></link>
<title>Authenticate for the REST Report Tools</title>
</head>
<body>
<h2>Login for an Authenticated Report View</h2>
<div>This is intended for sites with Password Authentication Enabled</div>
<span id="currentUser"></span>
<div id="password">
<div>
<label for="restemail">Email</label>
<input id="restemail" type="text" value="" size="30"/>
</div>
<div>
<label for="restpass">Password</label>
<input id="restpass" type="password" value=""/>
</div>
<div>
<button id="authenticate">Authenticate</button>
<button id="logout">Logout</button>
</div>
</div>
</body>
</html>

View File

@@ -25,6 +25,7 @@
</head> </head>
<body> <body>
<a href="query.html">Query Tool</a> <a href="query.html">Query Tool</a>
<span id="currentUser"></span>
<hr/> <hr/>
<h1>DSpace REST QC Client</h1> <h1>DSpace REST QC Client</h1>
<div id='metadatadiv'> <div id='metadatadiv'>

View File

@@ -24,6 +24,7 @@
</head> </head>
<body> <body>
<a href="index.html">Collection Filter</a> <a href="index.html">Collection Filter</a>
<span id="currentUser"></span>
<hr/> <hr/>
<h1>DSpace REST Query Client</h1> <h1>DSpace REST Query Client</h1>
<div id="querydiv"> <div id="querydiv">

View File

@@ -6,357 +6,356 @@
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*/ */
var CollReport = function() { var CollReport = function() {
Report.call(this); Report.call(this);
//If sortable.js is included, uncomment the following //If sortable.js is included, uncomment the following
//this.hasSorttable = function(){return true;} //this.hasSorttable = function(){return true;}
this.COLL_LIMIT = 20; this.COLL_LIMIT = 20;
this.TOOBIG = 10000; this.TOOBIG = 10000;
this.loadId = 0; this.loadId = 0;
this.THREADS =11; this.THREADS =11;
this.THREADSP = 11; this.THREADSP = 11;
this.ACCIDX_COLL = 1; this.ACCIDX_COLL = 1;
this.ACCIDX_ITEM = 2; this.ACCIDX_ITEM = 2;
this.getDefaultParameters = function(){ this.getDefaultParameters = function(){
return { return {
"show_fields[]" : [], "show_fields[]" : [],
filters : "", filters : "",
limit : this.COUNT_LIMIT, limit : this.COUNT_LIMIT,
offset : 0, offset : 0,
icollection : "", icollection : "",
ifilter : "", ifilter : "",
}; };
} }
this.getCurrentParameters = function(){ this.getCurrentParameters = function(){
return { return {
"show_fields[]" : this.myMetadataFields.getShowFields(), "show_fields[]" : this.myMetadataFields.getShowFields(),
filters : this.myFilters.getFilterList(), filters : this.myFilters.getFilterList(),
limit : this.myReportParameters.getLimit(), limit : this.myReportParameters.getLimit(),
offset : this.myReportParameters.getOffset(), offset : this.myReportParameters.getOffset(),
icollection : $("#icollection").val(), icollection : $("#icollection").val(),
ifilter : $("#ifilter").val(), ifilter : $("#ifilter").val(),
}; };
} }
var self = this; var self = this;
this.init = function() { this.init = function() {
this.baseInit(); this.baseInit();
$("#icollection").val(self.myReportParameters.params.icollection); $("#icollection").val(self.myReportParameters.params.icollection);
$("#ifilter").val(self.myReportParameters.params.ifilter); $("#ifilter").val(self.myReportParameters.params.ifilter);
$("#itemResults").accordion({ $("#itemResults").accordion({
heightStyle: "content", heightStyle: "content",
collapsible: true, collapsible: true,
active: 1 active: 1
}); });
} }
this.myAuth.callback = function(data) { this.myAuth.callback = function(data) {
self.createCollectionTable(); self.createCollectionTable();
$(".showCollections").bind("click", function(){ $("#table tbody tr").remove();
self.loadData(); $(".showCollections").bind("click", function(){
}); self.loadData();
$("#refresh-fields").bind("click", function(){ });
self.drawItemTable($("#icollection").val(), $("#ifilter").val(), 0); $("#refresh-fields").bind("click", function(){
}); self.drawItemTable($("#icollection").val(), $("#ifilter").val(), 0);
} });
}
this.createCollectionTable = function() { this.createCollectionTable = function() {
var self = this; var self = this;
var tbl = $("<table/>"); var tbl = $("<table/>");
tbl.attr("id","table"); tbl.attr("id","table");
$("#report").replaceWith(tbl); $("#report").replaceWith(tbl);
var thead = $("<thead/>"); var thead = $("<thead/>");
tbl.append(thead); tbl.append(thead);
var tbody = $("<tbody/>"); var tbody = $("<tbody/>");
tbl.append(tbody); tbl.append(tbody);
var tr = self.myHtmlUtil.addTr(thead).addClass("header"); var tr = self.myHtmlUtil.addTr(thead).addClass("header");
self.myHtmlUtil.addTh(tr, "Num").addClass("num").addClass("sorttable_numeric"); self.myHtmlUtil.addTh(tr, "Num").addClass("num").addClass("sorttable_numeric");
self.myHtmlUtil.addTh(tr, "Community").addClass("title"); self.myHtmlUtil.addTh(tr, "Community").addClass("title");
self.myHtmlUtil.addTh(tr, "Collection").addClass("title"); self.myHtmlUtil.addTh(tr, "Collection").addClass("title");
var thn = self.myHtmlUtil.addTh(tr, "Num Items").addClass("sorttable_numeric"); var thn = self.myHtmlUtil.addTh(tr, "Num Items").addClass("sorttable_numeric");
self.myHtmlUtil.makeTotalCol(thn); self.myHtmlUtil.makeTotalCol(thn);
thn = self.myHtmlUtil.addTh(tr, "Num Filtered").addClass("sorttable_numeric"); thn = self.myHtmlUtil.addTh(tr, "Num Filtered").addClass("sorttable_numeric");
self.myHtmlUtil.makeTotalCol(thn); self.myHtmlUtil.makeTotalCol(thn);
self.addCollections(); self.addCollections();
} }
this.addCollections = function() { this.addCollections = function() {
var self = this; var self = this;
$.ajax({ $.ajax({
url: "/rest/hierarchy", url: "/rest/hierarchy",
dataType: "json", dataType: "json",
headers: self.myAuth.getHeaders(), headers: self.myAuth.getHeaders(),
success: function(data){ success: function(data){
if (data.community != null) { if (data.community != null) {
$.each(data.community, function(index, comm){ $.each(data.community, function(index, comm){
self.addCommunity(comm, comm); self.addCommunity(comm, comm);
}); });
} }
self.setCollectionCounts(0); self.setCollectionCounts(0);
}, },
error: function(xhr, status, errorThrown) { error: function(xhr, status, errorThrown) {
alert("Error in /rest/hierarchy "+ status+ " " + errorThrown); alert("Error in /rest/hierarchy "+ status+ " " + errorThrown);
} }
}); });
}; };
this.addCommunity = function(top, comm) { this.addCommunity = function(top, comm) {
var self = this; var self = this;
if (comm.collection != null) { if (comm.collection != null) {
$.each(comm.collection, function(index, coll){ $.each(comm.collection, function(index, coll){
self.addCollection(top, coll); self.addCollection(top, coll);
}); });
} }
if (comm.community != null) { if (comm.community != null) {
$.each(comm.community, function(index, scomm){ $.each(comm.community, function(index, scomm){
self.addCommunity(top, scomm); self.addCommunity(top, scomm);
}); });
} }
}; };
this.addCollection = function(top, coll) { this.addCollection = function(top, coll) {
var self = this; var self = this;
var tbody = $("#table tbody"); var tbody = $("#table tbody");
var index = tbody.find("tr").length; var index = tbody.find("tr").length;
var tr = self.myHtmlUtil.addTr(tbody); var tr = self.myHtmlUtil.addTr(tbody);
tr.attr("cid", coll.id).attr("index",index).addClass(index % 2 == 0 ? "odd data" : "even data"); tr.attr("cid", coll.id).attr("index",index).addClass(index % 2 == 0 ? "odd data" : "even data");
self.myHtmlUtil.addTd(tr, index + 1).addClass("num"); self.myHtmlUtil.addTd(tr, index + 1).addClass("num");
var parval = self.myHtmlUtil.getAnchor(top.name, self.ROOTPATH + top.handle); var parval = self.myHtmlUtil.getAnchor(top.name, self.ROOTPATH + top.handle);
self.myHtmlUtil.addTd(tr, parval).addClass("title comm"); self.myHtmlUtil.addTd(tr, parval).addClass("title comm");
self.myHtmlUtil.addTdAnchor(tr, coll.name, self.ROOTPATH + coll.handle).addClass("title"); self.myHtmlUtil.addTdAnchor(tr, coll.name, self.ROOTPATH + coll.handle).addClass("title");
var td = self.myHtmlUtil.addTd(tr, "").addClass("num").addClass("link").addClass("numCount"); var td = self.myHtmlUtil.addTd(tr, "").addClass("num").addClass("link").addClass("numCount");
td = self.myHtmlUtil.addTd(tr, "").addClass("num").addClass("numFiltered"); td = self.myHtmlUtil.addTd(tr, "").addClass("num").addClass("numFiltered");
}; };
this.setCollectionCounts = function(offset) { this.setCollectionCounts = function(offset) {
var self = this; var self = this;
$.ajax({ $.ajax({
url: "/rest/filtered-collections", url: "/rest/filtered-collections",
data: { data: {
limit : self.COLL_LIMIT, limit : self.COLL_LIMIT,
offset : offset offset : offset
}, },
dataType: "json", dataType: "json",
headers: self.myAuth.getHeaders(), headers: self.myAuth.getHeaders(),
success: function(data){ success: function(data){
$.each(data, function(index, coll){ $.each(data, function(index, coll){
var id = self.getId(coll); var id = self.getId(coll);
var tr = $("#table tbody").find("tr[cid="+id+"]"); var tr = $("#table tbody").find("tr[cid="+id+"]");
var td = tr.find("td.numCount"); var td = tr.find("td.numCount");
td.text(coll.numberItems); td.text(coll.numberItems);
td.on("click", function(){ td.on("click", function(){
self.drawItemTable(self.getId(coll),'',0); self.drawItemTable(self.getId(coll),'',0);
$("#icollection").val(self.getId(coll)); $("#icollection").val(self.getId(coll));
$("#ifilter").val(""); $("#ifilter").val("");
}); });
}); });
//cannot assume data returned is full amount in case some items are restricted //cannot assume data returned is full amount in case some items are restricted
//if (data.length == self.COLL_LIMIT) { //if (data.length == self.COLL_LIMIT) {
if (data.length > 0) { if (data.length > 0) {
self.setCollectionCounts(offset + self.COLL_LIMIT); self.setCollectionCounts(offset + self.COLL_LIMIT);
return; return;
} }
self.myHtmlUtil.totalCol(3); self.myHtmlUtil.totalCol(3);
$("#table").addClass("sortable"); $("#table").addClass("sortable");
if (self.myFilters.getFilterList() != "") { if (self.myFilters.getFilterList() != "") {
self.loadData(); self.loadData();
if ($("#icollection").val() != "") { if ($("#icollection").val() != "") {
self.drawItemTable($("#icollection").val(), $("#ifilter").val(), 0); self.drawItemTable($("#icollection").val(), $("#ifilter").val(), 0);
} }
} }
}, },
error: function(xhr, status, errorThrown) { error: function(xhr, status, errorThrown) {
alert("Error in /rest/collections "+ status+ " " + errorThrown); alert("Error in /rest/collections "+ status+ " " + errorThrown);
}, },
complete: function(xhr, status) { complete: function(xhr, status) {
self.spinner.stop(); self.spinner.stop();
$(".showCollections").attr("disabled", false); $(".showCollections").attr("disabled", false);
} }
}); });
} }
this.loadData = function() { this.loadData = function() {
self.spinner.spin($("h1")[0]); self.spinner.spin($("h1")[0]);
$(".showCollections").attr("disabled", true); $(".showCollections").attr("disabled", true);
$("#metadatadiv").accordion("option", "active", self.ACCIDX_COLL); $("#metadatadiv").accordion("option", "active", self.ACCIDX_COLL);
self.loadId++; self.loadId++;
$("td.datacol,th.datacol").remove(); $("td.datacol,th.datacol").remove();
$("#table tr.data").addClass("processing"); $("#table tr.data").addClass("processing");
self.myFilters.filterString = self.myFilters.getFilterList(); self.myFilters.filterString = self.myFilters.getFilterList();
self.doRow(0, self.THREADS, self.loadId); self.doRow(0, self.THREADS, self.loadId);
} }
this.doRow = function(row, threads, curLoadId) { this.doRow = function(row, threads, curLoadId) {
if (self.loadId != curLoadId) return; if (self.loadId != curLoadId) return;
var tr = $("tr[index="+row+"]"); var tr = $("tr[index="+row+"]");
if (!tr.is("*")){ if (!tr.is("*")){
return; return;
} }
var cid = tr.attr("cid"); var cid = tr.attr("cid");
$.ajax({ $.ajax({
url: "/rest/filtered-collections/"+cid, url: "/rest/filtered-collections/"+cid,
data: { data: {
limit : self.COUNT_LIMIT, limit : self.COUNT_LIMIT,
filters : self.myFilters.filterString, filters : self.myFilters.filterString,
}, },
dataType: "json", dataType: "json",
headers: self.myAuth.getHeaders(), headers: self.myAuth.getHeaders(),
success: function(data) { success: function(data) {
var numItems = data.numberItems; var numItems = data.numberItems;
var numItemsProcessed = data.numberItemsProcessed; var numItemsProcessed = data.numberItemsProcessed;
$.each(data.itemFilters, function(index, itemFilter){ $.each(data.itemFilters, function(index, itemFilter){
if (self.loadId != curLoadId) { if (self.loadId != curLoadId) {
return; return;
}
var trh = $("#table tr.header");
var filterName = itemFilter["filter-name"];
var filterTitle = itemFilter.title == null ? filterName : itemFilter.title;
if (!trh.find("th."+filterName).is("*")) {
var th = self.myHtmlUtil.addTh(trh, filterTitle);
th.addClass(filterName).addClass("datacol").addClass("sorttable_numeric");
self.myHtmlUtil.makeTotalCol(th);
if (itemFilter.description != null) {
th.attr("title", itemFilter.description);
}
$("tr.data").each(function(){
var td = self.myHtmlUtil.addTd($(this), "");
td.addClass(filterName).addClass("num").addClass("datacol");
});
}
self.setCellCount(tr, cid, 0, (numItems != numItemsProcessed), itemFilter);
self.setFilteredCount(tr, cid, 0, numItems, numItemsProcessed);
});
tr.removeClass("processing");
if (!$("#table tr.processing").is("*")) {
self.updateSortable();
self.totalFilters();
self.spinner.stop();
$(".showCollections").attr("disabled", false);
return;
} }
if (row % threads == 0 || threads == 1) { var trh = $("#table tr.header");
for(var i=1; i<=threads; i++) { var filterName = itemFilter["filter-name"];
self.doRow(row+i, threads, curLoadId); var filterTitle = itemFilter.title == null ? filterName : itemFilter.title;
} if (!trh.find("th."+filterName).is("*")) {
} var th = self.myHtmlUtil.addTh(trh, filterTitle);
}, th.addClass(filterName).addClass("datacol").addClass("sorttable_numeric");
error: function(xhr, status, errorThrown) { self.myHtmlUtil.makeTotalCol(th);
alert("Error in /rest/filtered-collections "+ status+ " " + errorThrown);
},
complete: function(xhr, status) {
self.spinner.stop();
$(".showCollections").attr("disabled", false);
}
if (itemFilter.description != null) {
th.attr("title", itemFilter.description);
}
}); $("tr.data").each(function(){
}; var td = self.myHtmlUtil.addTd($(this), "");
td.addClass(filterName).addClass("num").addClass("datacol");
});
}
this.updateSortable = function() { self.setCellCount(tr, cid, 0, (numItems != numItemsProcessed), itemFilter);
if (self.hasSorttable()) { self.setFilteredCount(tr, cid, 0, numItems, numItemsProcessed);
$("#table").removeClass("sortable"); });
$("#table").addClass("sortable");
sorttable.makeSortable($("#table")[0]);
}
}
this.totalFilters = function() { tr.removeClass("processing");
var colcount = $("#table tr th").length; if (!$("#table tr.processing").is("*")) {
for(var i=4; i<colcount; i++) { self.updateSortable();
self.myHtmlUtil.totalCol(i); self.totalFilters();
} self.spinner.stop();
} $(".showCollections").attr("disabled", false);
return;
}
if (row % threads == 0 || threads == 1) {
for(var i=1; i<=threads; i++) {
self.doRow(row+i, threads, curLoadId);
}
}
},
error: function(xhr, status, errorThrown) {
alert("Error in /rest/filtered-collections "+ status+ " " + errorThrown);
},
complete: function(xhr, status) {
self.spinner.stop();
$(".showCollections").attr("disabled", false);
}
});
};
this.updateRow = function(cid, offset) { this.updateSortable = function() {
var tr = $("tr[cid="+cid+"]"); if (self.hasSorttable()) {
$.ajax({ $("#table").removeClass("sortable");
url: "/rest/filtered-collections/"+cid, $("#table").addClass("sortable");
data: { sorttable.makeSortable($("#table")[0]);
limit : self.COUNT_LIMIT, }
offset : offset, }
filters : self.myFilters.filterString,
},
dataType: "json",
headers: self.myAuth.getHeaders(),
success: function(data) {
var numItems = data.numberItems;
var numItemsProcessed = data.numberItemsProcessed;
$.each(data.itemFilters, function(index, itemFilter){
self.setCellCount(tr, cid, offset, (numItems != numItemsProcessed + offset),itemFilter);
});
self.setFilteredCount(tr, cid, offset, numItems, numItemsProcessed);
},
error: function(xhr, status, errorThrown) {
alert("Error in /rest/filtered-collections/ " + cid+ status+ " " + errorThrown);
},
complete: function(xhr, status) {
self.spinner.stop();
$(".showCollections").attr("disabled", false);
}
});
};
this.setFilteredCount = function(tr, cid, offset, numItems, numItemsProcessed) { this.totalFilters = function() {
var colcount = $("#table tr th").length;
for(var i=4; i<colcount; i++) {
self.myHtmlUtil.totalCol(i);
}
}
this.updateRow = function(cid, offset) {
var tr = $("tr[cid="+cid+"]");
$.ajax({
url: "/rest/filtered-collections/"+cid,
data: {
limit : self.COUNT_LIMIT,
offset : offset,
filters : self.myFilters.filterString,
},
dataType: "json",
headers: self.myAuth.getHeaders(),
success: function(data) {
var numItems = data.numberItems;
var numItemsProcessed = data.numberItemsProcessed;
$.each(data.itemFilters, function(index, itemFilter){
self.setCellCount(tr, cid, offset, (numItems != numItemsProcessed + offset),itemFilter);
});
self.setFilteredCount(tr, cid, offset, numItems, numItemsProcessed);
},
error: function(xhr, status, errorThrown) {
alert("Error in /rest/filtered-collections/ " + cid+ status+ " " + errorThrown);
},
complete: function(xhr, status) {
self.spinner.stop();
$(".showCollections").attr("disabled", false);
}
});
};
this.setFilteredCount = function(tr, cid, offset, numItems, numItemsProcessed) {
var td = tr.find("td.numFiltered"); var td = tr.find("td.numFiltered");
var total = numItemsProcessed + offset; var total = numItemsProcessed + offset;
td.text(total); td.text(total);
td.removeClass("partial"); td.removeClass("partial");
td.removeClass("toobig"); td.removeClass("toobig");
if (numItems != numItemsProcessed + offset) { if (numItems != numItemsProcessed + offset) {
if (offset == 0) { if (offset == 0) {
td.addClass("button"); td.addClass("button");
td.off(); td.off();
td.on("click", function(){ td.on("click", function(){
if ($(this).hasClass("toobig")) { if ($(this).hasClass("toobig")) {
if (!confirm("A large number of items are present in this collection.\n\n" + if (!confirm("A large number of items are present in this collection.\n\n" +
"If you choose to load this data, it will take some time to load and may impact server performance.")) { "If you choose to load this data, it will take some time to load and may impact server performance.")) {
return; return;
} }
} }
$(this).off(); $(this).off();
$(this).removeClass("button"); $(this).removeClass("button");
self.updateRow(cid, offset + self.COUNT_LIMIT); self.updateRow(cid, offset + self.COUNT_LIMIT);
}); });
} else { } else {
self.updateRow(cid, offset + self.COUNT_LIMIT); self.updateRow(cid, offset + self.COUNT_LIMIT);
} }
td.addClass("partial"); td.addClass("partial");
var title = "Collection partially processed, item counts are incomplete. "; var title = "Collection partially processed, item counts are incomplete. ";
if (numItems >= self.TOOBIG) { if (numItems >= self.TOOBIG) {
td.addClass("toobig"); td.addClass("toobig");
title+= "\nIt will take significant time to apply this filter to the entire collection." title+= "\nIt will take significant time to apply this filter to the entire collection."
} }
td.attr("title", title); td.attr("title", title);
return false; return false;
} else { } else {
self.totalFilters(); self.totalFilters();
} }
return true; return true;
} }
this.setCellCount = function(tr, cid, offset, isPartial, itemFilter) { this.setCellCount = function(tr, cid, offset, isPartial, itemFilter) {
var filterName = itemFilter["filter-name"]; var filterName = itemFilter["filter-name"];
var icount = itemFilter["item-count"]; var icount = itemFilter["item-count"];
var td = tr.find("td."+filterName); var td = tr.find("td."+filterName);
if (icount == null) { if (icount == null) {
icount = 0; icount = 0;
} }
var cur = parseInt(td.text()); var cur = parseInt(td.text());
if (!isNaN(cur)) { if (!isNaN(cur)) {
@@ -368,113 +367,113 @@ var CollReport = function() {
td.removeAttr("title"); td.removeAttr("title");
td.off(); td.off();
td.text(icount); td.text(icount);
if (icount != 0) { if (icount != 0) {
td.addClass("link"); td.addClass("link");
if (isPartial) { if (isPartial) {
td.addClass("partial"); td.addClass("partial");
td.attr("title", "Collection partially processed, item counts are incomplete"); td.attr("title", "Collection partially processed, item counts are incomplete");
} }
td.on("click", function(){ td.on("click", function(){
self.drawItemTable(cid,filterName,0); self.drawItemTable(cid,filterName,0);
$("#icollection").val(cid); $("#icollection").val(cid);
$("#ifilter").val(filterName); $("#ifilter").val(filterName);
}); });
} }
} }
this.drawItemTable = function(cid, filter, offset) { this.drawItemTable = function(cid, filter, offset) {
self = this; self = this;
self.spinner.spin($("h1")[0]); self.spinner.spin($("h1")[0]);
$("#itemtable").replaceWith($('<table id="itemtable" class="sortable"></table>')); $("#itemtable").replaceWith($('<table id="itemtable" class="sortable"></table>'));
var itbl = $("#itemtable"); var itbl = $("#itemtable");
//itbl.find("tr").remove("*"); //itbl.find("tr").remove("*");
var tr = self.myHtmlUtil.addTr(itbl).addClass("header"); var tr = self.myHtmlUtil.addTr(itbl).addClass("header");
self.myHtmlUtil.addTh(tr, "Num").addClass("num").addClass("sorttable_numeric"); self.myHtmlUtil.addTh(tr, "Num").addClass("num").addClass("sorttable_numeric");
self.myHtmlUtil.addTh(tr, "id"); self.myHtmlUtil.addTh(tr, "id");
self.myHtmlUtil.addTh(tr, "Handle"); self.myHtmlUtil.addTh(tr, "Handle");
self.myHtmlUtil.addTh(tr, "dc.title" + self.getLangSuffix()).addClass("title"); self.myHtmlUtil.addTh(tr, "dc.title" + self.getLangSuffix()).addClass("title");
var fields = $("#show-fields select").val(); var fields = $("#show-fields select").val();
if (fields != null) { if (fields != null) {
$.each(fields, function(index, field){ $.each(fields, function(index, field){
self.myHtmlUtil.addTh(tr, field + self.getLangSuffix()); self.myHtmlUtil.addTh(tr, field + self.getLangSuffix());
}); });
} }
var params = { var params = {
expand: fields == null ? "items" : "items,metadata", expand: fields == null ? "items" : "items,metadata",
limit: self.ITEM_LIMIT, limit: self.ITEM_LIMIT,
filters: filter, filters: filter,
offset: offset, offset: offset,
"show_fields[]" : fields, "show_fields[]" : fields,
} }
$.ajax({ $.ajax({
url: "/rest/filtered-collections/"+cid, url: "/rest/filtered-collections/"+cid,
data: params, data: params,
dataType: "json", dataType: "json",
headers: self.myAuth.getHeaders(), headers: self.myAuth.getHeaders(),
success: function(data){ success: function(data){
var source = filter == "" ? data.items : data.itemFilters[0].items; var source = filter == "" ? data.items : data.itemFilters[0].items;
$.each(source, function(index, item){ $.each(source, function(index, item){
var tr = self.myHtmlUtil.addTr(itbl); var tr = self.myHtmlUtil.addTr(itbl);
tr.addClass(index % 2 == 0 ? "odd data" : "even data"); tr.addClass(index % 2 == 0 ? "odd data" : "even data");
self.myHtmlUtil.addTd(tr, offset+index+1).addClass("num"); self.myHtmlUtil.addTd(tr, offset+index+1).addClass("num");
self.myHtmlUtil.addTd(tr, self.getId(item)); self.myHtmlUtil.addTd(tr, self.getId(item));
self.myHtmlUtil.addTdAnchor(tr, item.handle, self.ROOTPATH + item.handle); self.myHtmlUtil.addTdAnchor(tr, item.handle, self.ROOTPATH + item.handle);
self.myHtmlUtil.addTd(tr, item.name).addClass("ititle"); self.myHtmlUtil.addTd(tr, item.name).addClass("ititle");
if (fields != null) { if (fields != null) {
$.each(fields, function(index, field){ $.each(fields, function(index, field){
var text = ""; var text = "";
$.each(item.metadata, function(mindex,mv){ $.each(item.metadata, function(mindex,mv){
if (mv.key == field) { if (mv.key == field) {
if (text != "") { if (text != "") {
text += "<hr/>"; text += "<hr/>";
} }
text += mv.value; text += mv.value;
} }
}); });
self.myHtmlUtil.addTd(tr, text); self.myHtmlUtil.addTd(tr, text);
}); });
} }
}); });
self.displayItems(filter + " Items in " + data.name, self.displayItems(filter + " Items in " + data.name,
offset, offset,
self.ITEM_LIMIT, self.ITEM_LIMIT,
data.numberItems, data.numberItems,
function(){self.drawItemTable(cid, filter, (offset - self.ITEM_LIMIT < 0) ? 0 : offset - self.ITEM_LIMIT);}, function(){self.drawItemTable(cid, filter, (offset - self.ITEM_LIMIT < 0) ? 0 : offset - self.ITEM_LIMIT);},
function(){self.drawItemTable(cid, filter, offset + self.ITEM_LIMIT);} function(){self.drawItemTable(cid, filter, offset + self.ITEM_LIMIT);}
); );
if (self.hasSorttable()){ if (self.hasSorttable()){
sorttable.makeSortable(itbl[0]); sorttable.makeSortable(itbl[0]);
} }
$("#metadatadiv").accordion("option", "active", self.ACCIDX_ITEM); $("#metadatadiv").accordion("option", "active", self.ACCIDX_ITEM);
}, },
error: function(xhr, status, errorThrown) { error: function(xhr, status, errorThrown) {
alert("Error in /rest/filtered-collections "+ status+ " " + errorThrown); alert("Error in /rest/filtered-collections "+ status+ " " + errorThrown);
}, },
complete: function(xhr, status) { complete: function(xhr, status) {
self.spinner.stop(); self.spinner.stop();
$(".showCollections").attr("disabled", false); $(".showCollections").attr("disabled", false);
} }
}); });
} }
//Ignore the first column containing a row number and the item handle //Ignore the first column containing a row number and the item handle
this.exportCol = function(colnum, col) { this.exportCol = function(colnum, col) {
var data = ""; var data = "";
if (colnum == 0) return ""; if (colnum == 0) return "";
if (colnum == 2) return ""; if (colnum == 2) return "";
data += (colnum == 1) ? "" : ","; data += (colnum == 1) ? "" : ",";
data += self.exportCell(col); data += self.exportCell(col);
return data; return data;
} }
} }
CollReport.prototype = Object.create(Report.prototype); CollReport.prototype = Object.create(Report.prototype);
$(document).ready(function(){ $(document).ready(function(){
var myReport=new CollReport(); var myReport=new CollReport();
myReport.init(); myReport.init();
}); });

View File

@@ -6,318 +6,318 @@
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*/ */
var QueryReport = function() { var QueryReport = function() {
Report.call(this); Report.call(this);
//If sortable.js is included, uncomment the following //If sortable.js is included, uncomment the following
//this.hasSorttable = function(){return true;} //this.hasSorttable = function(){return true;}
this.getDefaultParameters = function(){ this.getDefaultParameters = function(){
return { return {
"collSel[]" : [], "collSel[]" : [],
"query_field[]" : [], "query_field[]" : [],
"query_op[]" : [], "query_op[]" : [],
"query_val[]" : [], "query_val[]" : [],
"show_fields[]" : [], "show_fields[]" : [],
"filters" : "", "filters" : "",
"limit" : this.ITEM_LIMIT, "limit" : this.ITEM_LIMIT,
"offset" : 0, "offset" : 0,
}; };
} }
this.getCurrentParameters = function(){ this.getCurrentParameters = function(){
var params = { var params = {
"query_field[]" : [], "query_field[]" : [],
"query_op[]" : [], "query_op[]" : [],
"query_val[]" : [], "query_val[]" : [],
"collSel[]" : ($("#collSel").val() == null) ? [""] : $("#collSel").val(), "collSel[]" : ($("#collSel").val() == null) ? [""] : $("#collSel").val(),
limit : this.myReportParameters.getLimit(), limit : this.myReportParameters.getLimit(),
offset : this.myReportParameters.getOffset(), offset : this.myReportParameters.getOffset(),
"expand" : "parentCollection,metadata", "expand" : "parentCollection,metadata",
filters : this.myFilters.getFilterList(), filters : this.myFilters.getFilterList(),
"show_fields[]" : this.myMetadataFields.getShowFields(), "show_fields[]" : this.myMetadataFields.getShowFields(),
}; };
$("select.query-tool,input.query-tool").each(function() { $("select.query-tool,input.query-tool").each(function() {
var paramArr = params[$(this).attr("name")]; var paramArr = params[$(this).attr("name")];
paramArr[paramArr.length] = $(this).val(); paramArr[paramArr.length] = $(this).val();
}); });
return params; return params;
} }
var self = this; var self = this;
this.init = function() { this.init = function() {
this.baseInit(); this.baseInit();
var communitySelector = new CommunitySelector(this, $("#collSelector"), this.myReportParameters.params["collSel[]"]); }
}
this.initMetadataFields = function() { this.initMetadataFields = function() {
this.myMetadataFields = new QueryableMetadataFields(self); this.myMetadataFields = new QueryableMetadataFields(self);
this.myMetadataFields.load(); this.myMetadataFields.load();
} }
this.myAuth.callback = function(data) { this.myAuth.callback = function(data) {
$(".query-button").click(function(){self.runQuery();}) var communitySelector = new CommunitySelector(self, $("#collSelector"), self.myReportParameters.params["collSel[]"]);
} $(".query-button").click(function(){self.runQuery();})
}
this.runQuery = function() { this.runQuery = function() {
this.spinner.spin($("body")[0]); this.spinner.spin($("body")[0]);
$("button").attr("disabled", true); $("button").attr("disabled", true);
$.ajax({ $.ajax({
url: "/rest/filtered-items", url: "/rest/filtered-items",
data: this.getCurrentParameters(), data: this.getCurrentParameters(),
dataType: "json", dataType: "json",
headers: self.myAuth.getHeaders(), headers: self.myAuth.getHeaders(),
success: function(data){ success: function(data){
data.metadata = $("#show-fields select").val(); data.metadata = $("#show-fields select").val();
self.drawItemFilterTable(data); self.drawItemFilterTable(data);
self.spinner.stop(); self.spinner.stop();
$("button").not("#next,#prev").attr("disabled", false); $("button").not("#next,#prev").attr("disabled", false);
}, },
error: function(xhr, status, errorThrown) { error: function(xhr, status, errorThrown) {
alert("Error in /rest/filtered-items "+ status+ " " + errorThrown); alert("Error in /rest/filtered-items "+ status+ " " + errorThrown);
}, },
complete: function(xhr, status, errorThrown) { complete: function(xhr, status, errorThrown) {
self.spinner.stop(); self.spinner.stop();
$("button").not("#next,#prev").attr("disabled", false); $("button").not("#next,#prev").attr("disabled", false);
} }
}); });
} }
this.drawItemFilterTable = function(data) { this.drawItemFilterTable = function(data) {
$("#itemtable").replaceWith($('<table id="itemtable" class="sortable"></table>')); $("#itemtable").replaceWith($('<table id="itemtable" class="sortable"></table>'));
var itbl = $("#itemtable"); var itbl = $("#itemtable");
var tr = self.myHtmlUtil.addTr(itbl).addClass("header"); var tr = self.myHtmlUtil.addTr(itbl).addClass("header");
self.myHtmlUtil.addTh(tr, "Num").addClass("num").addClass("sorttable_numeric"); self.myHtmlUtil.addTh(tr, "Num").addClass("num").addClass("sorttable_numeric");
self.myHtmlUtil.addTh(tr, "id"); self.myHtmlUtil.addTh(tr, "id");
self.myHtmlUtil.addTh(tr, "collection"); self.myHtmlUtil.addTh(tr, "collection");
self.myHtmlUtil.addTh(tr, "Item Handle"); self.myHtmlUtil.addTh(tr, "Item Handle");
self.myHtmlUtil.addTh(tr, "dc.title" + self.getLangSuffix()); self.myHtmlUtil.addTh(tr, "dc.title" + self.getLangSuffix());
var mdCols = []; var mdCols = [];
if (data.metadata) { if (data.metadata) {
$.each(data.metadata, function(index, field) { $.each(data.metadata, function(index, field) {
if (field != "") { if (field != "") {
self.myHtmlUtil.addTh(tr,field + self.getLangSuffix()).addClass("returnFields"); self.myHtmlUtil.addTh(tr,field + self.getLangSuffix()).addClass("returnFields");
mdCols[mdCols.length] = field; mdCols[mdCols.length] = field;
} }
}); });
} }
$.each(data.items, function(index, item){ $.each(data.items, function(index, item){
var tr = self.myHtmlUtil.addTr(itbl); var tr = self.myHtmlUtil.addTr(itbl);
tr.addClass(index % 2 == 0 ? "odd data" : "even data"); tr.addClass(index % 2 == 0 ? "odd data" : "even data");
self.myHtmlUtil.addTd(tr, self.myReportParameters.getOffset()+index+1).addClass("num"); self.myHtmlUtil.addTd(tr, self.myReportParameters.getOffset()+index+1).addClass("num");
self.myHtmlUtil.addTd(tr, self.getId(item)); self.myHtmlUtil.addTd(tr, self.getId(item));
if (item.parentCollection == null) { if (item.parentCollection == null) {
self.myHtmlUtil.addTd(tr, "--"); self.myHtmlUtil.addTd(tr, "--");
} else { } else {
self.myHtmlUtil.addTdAnchor(tr, item.parentCollection.name, self.ROOTPATH + item.parentCollection.handle); self.myHtmlUtil.addTdAnchor(tr, item.parentCollection.name, self.ROOTPATH + item.parentCollection.handle);
} }
self.myHtmlUtil.addTdAnchor(tr, item.handle, self.ROOTPATH + item.handle); self.myHtmlUtil.addTdAnchor(tr, item.handle, self.ROOTPATH + item.handle);
self.myHtmlUtil.addTd(tr, item.name); self.myHtmlUtil.addTd(tr, item.name);
for(var i=0; i<mdCols.length; i++) { for(var i=0; i<mdCols.length; i++) {
var key = mdCols[i]; var key = mdCols[i];
var td = self.myHtmlUtil.addTd(tr, ""); var td = self.myHtmlUtil.addTd(tr, "");
$.each(item.metadata, function(colindex, metadata) { $.each(item.metadata, function(colindex, metadata) {
if (metadata.key == key) { if (metadata.key == key) {
if (metadata.value != null) { if (metadata.value != null) {
var div = $("<div>"+metadata.value+"</div>"); var div = $("<div>"+metadata.value+"</div>");
td.append(div); td.append(div);
} }
} }
}); });
} }
}); });
this.displayItems(data["query-annotation"], this.displayItems(data["query-annotation"],
this.myReportParameters.getOffset(), this.myReportParameters.getOffset(),
this.myReportParameters.getLimit(), this.myReportParameters.getLimit(),
data["unfiltered-item-count"], data["unfiltered-item-count"],
function(){ function(){
self.myReportParameters.updateOffset(false); self.myReportParameters.updateOffset(false);
self.runQuery(); self.runQuery();
}, },
function(){ function(){
self.myReportParameters.updateOffset(true); self.myReportParameters.updateOffset(true);
self.runQuery(); self.runQuery();
} }
); );
if (this.hasSorttable()) { if (this.hasSorttable()) {
sorttable.makeSortable(itbl[0]); sorttable.makeSortable(itbl[0]);
} }
$("#metadatadiv").accordion("option", "active", $("#metadatadiv > h3").length - 1); $("#metadatadiv").accordion("option", "active", $("#metadatadiv > h3").length - 1);
} }
//Ignore the first column containing a row number and the item handle, get handle for the collection //Ignore the first column containing a row number and the item handle, get handle for the collection
this.exportCol = function(colnum, col) { this.exportCol = function(colnum, col) {
var data = ""; var data = "";
if (colnum == 0) return ""; if (colnum == 0) return "";
if (colnum == 3) return ""; if (colnum == 3) return "";
data += (colnum == 1) ? "" : ","; data += (colnum == 1) ? "" : ",";
if (colnum == 2) { if (colnum == 2) {
var anchor = $(col).find("a"); var anchor = $(col).find("a");
var href = anchor.is("a") ? anchor.attr("href").replace(self.ROOTPATH,"") : $(col).text(); var href = anchor.is("a") ? anchor.attr("href").replace(self.ROOTPATH,"") : $(col).text();
data += "\"" + href + "\""; data += "\"" + href + "\"";
} else { } else {
data += self.exportCell(col); } data += self.exportCell(col); }
return data; return data;
} }
} }
QueryReport.prototype = Object.create(Report.prototype); QueryReport.prototype = Object.create(Report.prototype);
$(document).ready(function(){ $(document).ready(function(){
var myReport=new QueryReport(); var myReport=new QueryReport();
myReport.init(); myReport.init();
}); });
var QueryableMetadataFields = function(report) { var QueryableMetadataFields = function(report) {
MetadataFields.call(this, report); MetadataFields.call(this, report);
var self = this; var self = this;
this.initFields = function(data, report) { this.initFields = function(data, report) {
self.metadataSchemas = data; self.metadataSchemas = data;
var params = report.myReportParameters.params; var params = report.myReportParameters.params;
var fields = params["query_field[]"]; var fields = params["query_field[]"];
var ops = params["query_op[]"]; var ops = params["query_op[]"];
var vals = params["query_val[]"]; var vals = params["query_val[]"];
if (fields && ops && vals) { if (fields && ops && vals) {
if (fields.length == 0) { if (fields.length == 0) {
self.drawFilterQuery("*","exists",""); self.drawFilterQuery("*","exists","");
} else { } else {
for(var i=0; i<fields.length; i++) { for(var i=0; i<fields.length; i++) {
var op = ops.length > i ? ops[i] : ""; var op = ops.length > i ? ops[i] : "";
var val = vals.length > i ? vals[i] : ""; var val = vals.length > i ? vals[i] : "";
self.drawFilterQuery(fields[i],op,val); self.drawFilterQuery(fields[i],op,val);
} }
} }
} }
self.drawShowFields(params["show_fields[]"]); self.drawShowFields(params["show_fields[]"]);
self.initQueries(); self.initQueries();
report.spinner.stop(); report.spinner.stop();
$(".query-button").attr("disabled", false); $(".query-button").attr("disabled", false);
} }
this.initQueries = function() { this.initQueries = function() {
$("#predefselect") $("#predefselect")
.append($("<option value='new'>New Query</option>")) .append($("<option value='new'>New Query</option>"))
.append($("<option value='q1'>Has No Title</option>")) .append($("<option value='q1'>Has No Title</option>"))
.append($("<option value='q2'>Has No dc.identifier.uri</option>")) .append($("<option value='q2'>Has No dc.identifier.uri</option>"))
.append($("<option value='q3'>Has compound subject</option>")) .append($("<option value='q3'>Has compound subject</option>"))
.append($("<option value='q4'>Has compound dc.contributor.author</option>")) .append($("<option value='q4'>Has compound dc.contributor.author</option>"))
.append($("<option value='q5'>Has compound dc.creator</option>")) .append($("<option value='q5'>Has compound dc.creator</option>"))
.append($("<option value='q6'>Has URL in dc.description</option>")) .append($("<option value='q6'>Has URL in dc.description</option>"))
.append($("<option value='q7'>Has full text in dc.description.provenance</option>")) .append($("<option value='q7'>Has full text in dc.description.provenance</option>"))
.append($("<option value='q8'>Has non-full text in dc.description.provenance</option>")) .append($("<option value='q8'>Has non-full text in dc.description.provenance</option>"))
.append($("<option value='q9'>Has empty metadata</option>")) .append($("<option value='q9'>Has empty metadata</option>"))
.append($("<option value='q10'>Has unbreaking metadata in description</option>")) .append($("<option value='q10'>Has unbreaking metadata in description</option>"))
.append($("<option value='q12'>Has XML entity in metadata</option>")) .append($("<option value='q12'>Has XML entity in metadata</option>"))
.append($("<option value='q13'>Has non-ascii character in metadata</option>")) .append($("<option value='q13'>Has non-ascii character in metadata</option>"))
.on("change",function(){ .on("change",function(){
$("div.metadata").remove(); $("div.metadata").remove();
var val = $("#predefselect").val(); var val = $("#predefselect").val();
if (val == 'new') { if (val == 'new') {
self.drawFilterQuery("","",""); self.drawFilterQuery("","","");
} else if (val == 'q1') { } else if (val == 'q1') {
self.drawFilterQuery("dc.title","doesnt_exist",""); self.drawFilterQuery("dc.title","doesnt_exist","");
} else if (val == 'q2') { } else if (val == 'q2') {
self.drawFilterQuery("dc.identifier.uri","doesnt_exist",""); self.drawFilterQuery("dc.identifier.uri","doesnt_exist","");
} else if (val == 'q3') { } else if (val == 'q3') {
self.drawFilterQuery("dc.subject.*","like","%;%"); self.drawFilterQuery("dc.subject.*","like","%;%");
} else if (val == 'q4') { } else if (val == 'q4') {
self.drawFilterQuery("dc.contributor.author","like","% and %"); self.drawFilterQuery("dc.contributor.author","like","% and %");
} else if (val == 'q5') { } else if (val == 'q5') {
self.drawFilterQuery("dc.creator","like","% and %"); self.drawFilterQuery("dc.creator","like","% and %");
} else if (val == 'q6') { } else if (val == 'q6') {
self.drawFilterQuery("dc.description","matches","^.*(http://|https://|mailto:).*$"); self.drawFilterQuery("dc.description","matches","^.*(http://|https://|mailto:).*$");
} else if (val == 'q7') { } else if (val == 'q7') {
self.drawFilterQuery("dc.description.provenance","matches","^.*No\\. of bitstreams(.|\\r|\\n|\\r\\n)*\\.(PDF|pdf|DOC|doc|PPT|ppt|DOCX|docx|PPTX|pptx).*$"); self.drawFilterQuery("dc.description.provenance","matches","^.*No\\. of bitstreams(.|\\r|\\n|\\r\\n)*\\.(PDF|pdf|DOC|doc|PPT|ppt|DOCX|docx|PPTX|pptx).*$");
} else if (val == 'q8') { } else if (val == 'q8') {
self.drawFilterQuery("dc.description.provenance","doesnt_match","^.*No\\. of bitstreams(.|\\r|\\n|\\r\\n)*\\.(PDF|pdf|DOC|doc|PPT|ppt|DOCX|docx|PPTX|pptx).*$"); self.drawFilterQuery("dc.description.provenance","doesnt_match","^.*No\\. of bitstreams(.|\\r|\\n|\\r\\n)*\\.(PDF|pdf|DOC|doc|PPT|ppt|DOCX|docx|PPTX|pptx).*$");
} else if (val == 'q9') { } else if (val == 'q9') {
self.drawFilterQuery("*","matches","^\\s*$"); self.drawFilterQuery("*","matches","^\\s*$");
} else if (val == 'q10') { } else if (val == 'q10') {
self.drawFilterQuery("dc.description.*","matches","^.*[^\\s]{50,}.*$"); self.drawFilterQuery("dc.description.*","matches","^.*[^\\s]{50,}.*$");
} else if (val == 'q12') { } else if (val == 'q12') {
self.drawFilterQuery("*","matches","^.*&#.*$"); self.drawFilterQuery("*","matches","^.*&#.*$");
} else if (val == 'q13') { } else if (val == 'q13') {
self.drawFilterQuery("*","matches","^.*[^[:ascii:]].*$"); self.drawFilterQuery("*","matches","^.*[^[:ascii:]].*$");
} }
}); });
} }
this.drawFilterQuery = function(pField, pOp, pVal) { this.drawFilterQuery = function(pField, pOp, pVal) {
var div = $("<div class='metadata'/>").appendTo("#queries"); var div = $("<div class='metadata'/>").appendTo("#queries");
var sel = $("<select class='query-tool' name='query_field[]'/>"); var sel = $("<select class='query-tool' name='query_field[]'/>");
var opt = $("<option value='*'>Any Field</option>"); var opt = $("<option value='*'>Any Field</option>");
sel.append(opt); sel.append(opt);
$.each(self.metadataSchemas, function(index, schema){ $.each(self.metadataSchemas, function(index, schema){
if (schema.prefix == 'eperson') { if (schema.prefix == 'eperson') {
return; return;
} }
$.each(schema.fields, function(findex, field) { $.each(schema.fields, function(findex, field) {
var name = field.name; var name = field.name;
var parts = name.match(/^([^\.]+)\.([^\.]+)\.([^\.]+)$/); var parts = name.match(/^([^\.]+)\.([^\.]+)\.([^\.]+)$/);
if (parts == null) { if (parts == null) {
var wildname = name + ".*"; var wildname = name + ".*";
var opt = $("<option/>"); var opt = $("<option/>");
opt.attr("value",wildname).text(wildname); opt.attr("value",wildname).text(wildname);
sel.append(opt); sel.append(opt);
} }
var opt = $("<option/>"); var opt = $("<option/>");
opt.attr("value",name).text(name); opt.attr("value",name).text(name);
sel.append(opt); sel.append(opt);
}); });
}); });
sel.val(pField); sel.val(pField);
div.append(sel); div.append(sel);
var opsel = $("<select class='query-tool' name='query_op[]'/>"); var opsel = $("<select class='query-tool' name='query_op[]'/>");
$("<option>exists</option>").val("exists").appendTo(opsel); $("<option>exists</option>").val("exists").appendTo(opsel);
$("<option>does not exist</option>").val("doesnt_exist").appendTo(opsel); $("<option>does not exist</option>").val("doesnt_exist").appendTo(opsel);
$("<option selected>equals</option>").val("equals").appendTo(opsel); $("<option selected>equals</option>").val("equals").appendTo(opsel);
$("<option>does not equal</option>").val("not_equals").appendTo(opsel); $("<option>does not equal</option>").val("not_equals").appendTo(opsel);
$("<option>like</option>").val("like").appendTo(opsel); $("<option>like</option>").val("like").appendTo(opsel);
$("<option>not like</option>").val("not_like").appendTo(opsel); $("<option>not like</option>").val("not_like").appendTo(opsel);
$("<option>contains</option>").val("contains").appendTo(opsel); $("<option>contains</option>").val("contains").appendTo(opsel);
$("<option>does not contain</option>").val("doesnt_contain").appendTo(opsel); $("<option>does not contain</option>").val("doesnt_contain").appendTo(opsel);
$("<option>matches</option>").val("matches").appendTo(opsel); $("<option>matches</option>").val("matches").appendTo(opsel);
$("<option>does not match</option>").val("doesnt_match").appendTo(opsel); $("<option>does not match</option>").val("doesnt_match").appendTo(opsel);
opsel.val(pOp); opsel.val(pOp);
opsel.change(function(){ opsel.change(function(){
self.valField($(this)); self.valField($(this));
}); });
div.append(opsel); div.append(opsel);
var input = $("<input class='query-tool' name='query_val[]'/>"); var input = $("<input class='query-tool' name='query_val[]'/>");
div.append(input); div.append(input);
input.val(pVal); input.val(pVal);
self.valField(opsel); self.valField(opsel);
$("<button class='field_plus'>+</button>").appendTo(div).click(function(){ $("<button class='field_plus'>+</button>").appendTo(div).click(function(){
self.drawFilterQuery(); self.drawFilterQuery();
self.queryButtons(); self.queryButtons();
}); });
$("<button class='field_minus'>-</button>").appendTo(div).click(function(){ $("<button class='field_minus'>-</button>").appendTo(div).click(function(){
$(this).parent("div.metadata").remove(); $(this).parent("div.metadata").remove();
self.queryButtons(); self.queryButtons();
}); });
self.queryButtons(); self.queryButtons();
} }
this.valField = function(valop) { this.valField = function(valop) {
var val = valop.val(); var val = valop.val();
var disableval = (val == "exists" || val == "not_exists"); var disableval = (val == "exists" || val == "not_exists");
var valinput = valop.parent("div.metadata").find("input[name='query_val[]']"); var valinput = valop.parent("div.metadata").find("input[name='query_val[]']");
valinput.attr("readonly",disableval); valinput.attr("readonly",disableval);
if (disableval) { if (disableval) {
valinput.val(""); valinput.val("");
} }
} }
this.queryButtons = function() { this.queryButtons = function() {
$("button.field_plus").attr("disabled",true); $("button.field_plus").attr("disabled",true);
$("button.field_plus:last").attr("disabled",false); $("button.field_plus:last").attr("disabled",false);
$("button.field_minus").attr("disabled",false); $("button.field_minus").attr("disabled",false);
if ($("button.field_minus").length == 1) { if ($("button.field_minus").length == 1) {
$("button.field_minus").attr("disabled",true); $("button.field_minus").attr("disabled",true);
} }
} }
} }
QueryableMetadataFields.prototype = Object.create(MetadataFields.prototype); QueryableMetadataFields.prototype = Object.create(MetadataFields.prototype);

File diff suppressed because it is too large Load Diff