Skip to content
Permalink
Browse files

Merge pull request #2127 from internetarchive/2124/hotfix/authors-pag…

…e-broken-waitlist-btn

fixes availability.js, working waitlist on author pages
  • Loading branch information...
mekarpeles committed May 15, 2019
2 parents a346179 + 0ad94ac commit 811fbbf5a3fa64a8d73baef5a13d74c265ab86eb
Showing with 15 additions and 42 deletions.
  1. +15 −42 openlibrary/plugins/openlibrary/js/availability.js
@@ -202,11 +202,6 @@ function init() {
var work = response[_type][key];
var li = $(e).closest("li");
var cta = li.find(".searchResultItemCTA-lending");
var msg = '';
var link = '';
var annotation = '';
var tag = 'a';

var mode = filter ? localStorage.getItem('mode') : 'everything';

if (mode !== "printdisabled") {
@@ -215,51 +210,29 @@ function init() {
li.remove();
}
} else {
var cls = 'borrow_available borrow-link';
link = ' href="/books/' + work.openlibrary_edition + '/x/borrow" ';

if (work.status === 'open') {
cls = 'cta-btn--available';
msg = 'Read';
} else if (work.status === 'borrow_available') {
cls = 'cta-btn--available';
msg = 'Borrow';
if (work.status === 'open' || work.status === 'borrow_available') {
$(cta).append('<a href="/books/' + work.openlibrary_edition + '/x/borrow" ' +
'class="cta-btn cta-btn--available" ' +
'data-ol-link-track="' + work.status + '">' +
(work.status === 'open' ? 'Read' : ' Borrow') +
'</a>');
} else if (work.status === 'borrow_unavailable') {
tag = 'span';
link = '';
cls = 'cta-btn--unavailable';
msg = '<form method="POST" action="/books/' + work.openlibrary_edition + '/x/borrow?action=join-waitinglist" class="join-waitlist waitinglist-form"><input type="hidden" name="action" value="join-waitinglist">';
if (work.num_waitlist !== '0') {
msg += 'Join Waitlist <span class="cta-btn__badge">' + work.num_waitlist + '</span></form>';

} else {
msg += 'Join Waitlist</form>';
annotation = '<div class="waitlist-msg">You will be first in line!</div>';
}
}
$(cta).append(
'<' + tag + ' ' + link + ' class="' + cls +
' ' + btnClassName + '" data-ol-link-track="' +
work.status
+ '">' + msg + '</' + tag + '>'
);

if (annotation) {
$(cta).append(annotation);
$(cta).append('<form method="POST" ' +
'action="/books/' + work.openlibrary_edition + '/x/borrow?action=join-waitinglist" ' +
'class="join-waitlist waitinglist-form">' +
'<input type="hidden" name="action" value="join-waitinglist">' +
'<button type="submit" class="cta-btn cta-btn--unavailable" data-ol-link-track="' + work.status + '">' +
'Join Waitlist' +
(work.num_waitlist !== '0' ? ' <span class="cta-btn__badge">' + work.num_waitlist + '</span>' : '') +
'</button></form>' +
(work.num_waitlist === '0' ? '<div class="waitlist-msg">You will be first in line!</div>' : ''));
}
}
}
}
});
});
})
/* eslint-disable no-unused-vars */
// event object is passed to this function
$('.searchResultItemCTA-lending form.join-waitlist').on('click', function(e) {
// consider submitting form async and refreshing search results page
$(this).submit()
})
/* eslint-enable no-unused-vars */
updateBookAvailability();
}
}

0 comments on commit 811fbbf

Please sign in to comment.
You can’t perform that action at this time.