Skip to content

Commit

Permalink
Added clear button to patron filter
Browse files Browse the repository at this point in the history
  • Loading branch information
allisonglittle committed Dec 4, 2021
1 parent 8fed22d commit 95cc4c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 4 additions & 3 deletions library-express/patrons.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = function () {
/* Find people whose fname starts with a given string in the req */
function getPatronsWithNameLike(req, res, mysql, context, complete) {
//sanitize the input as well as include the % character
var query = "SELECT p.memberID as id, p.firstName, p.lastName, DATE_FORMAT(p.registerDate, '%d/%m/%Y') as 'registerDate', p.contactEmail, p.contactPhone, t.bookTitle FROM Patrons p LEFT JOIN Titles t ON p.favoriteTitle = t.ISBN WHERE p.firstName LIKE '%'" + mysql.pool.escape(req.params.s + '%');
var query = "SELECT p.memberID as id, p.firstName, p.lastName, DATE_FORMAT(p.registerDate, '%d/%m/%Y') as 'registerDate', p.contactEmail, p.contactPhone, t.bookTitle FROM Patrons p LEFT JOIN Titles t ON p.favoriteTitle = t.ISBN WHERE p.firstName LIKE " + mysql.pool.escape(req.params.s + '%');
console.log(query)

mysql.pool.query(query, function (error, results, fields) {
Expand Down Expand Up @@ -114,12 +114,13 @@ module.exports = function () {
router.get('/search/:s', function (req, res) {
var callbackCount = 0;
var context = {};
context.jsscripts = ["searchpatrons.js"];
// context.jsscripts = ["searchpatrons.js"];
var mysql = req.app.get('mysql');
getPatronsWithNameLike(req, res, mysql, context, complete);
getTitles(res, mysql, context, complete);
function complete() {
callbackCount++;
if (callbackCount >= 1) {
if (callbackCount >= 2) {
res.render('patrons', context);
}
}
Expand Down
15 changes: 15 additions & 0 deletions library-express/views/patrons.handlebars
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<div>
<script src="https://code.jquery.com/jquery-3.5.1.js"
integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
<h1>Library Inventory Management</h1>
<h2>Add a New Patron</h2>
<form id="addPatron" action="/patrons" method="post">
Expand Down Expand Up @@ -36,6 +38,7 @@
<input id='first_name_search_string' type='text' name='first_name_search_string' value=''>
<input type="button" value="Search" onclick="searchPatronsByFirstName()">
</form>
<button id="redirectPatrons">Clear</button>
</div>
</div>
<div>
Expand Down Expand Up @@ -67,4 +70,16 @@
{{/each}}
</tbody>
</table>
<script>function searchPatronsByFirstName() {
//get the first name
var first_name_search_string = document.getElementById('first_name_search_string').value
//construct the URL and redirect to it
window.location = '/patrons/search/' + encodeURI(first_name_search_string)
}</script>
<script type="text/javascript">
document.getElementById("redirectPatrons").onclick = function () {
{{!-- location.href = "/patrons"; --}}
window.location.href = "/patrons";
};
</script>
</div>

0 comments on commit 95cc4c5

Please sign in to comment.