Koha: Implement branch selection in reservations
@@ -377,7 +377,9 @@ open class Koha : OkHttpBaseApi() {
var reservationFeeConfirmed = false
var selectedCopy: String? = null
+ var selectedBranch: String? = null
val ACTION_ITEM = 101
+ val ACTION_BRANCH = 102
override fun reservation(item: DetailedItem, account: Account, useraction: Int, selection: String?): OpacApi.ReservationResult {
try {
@@ -393,6 +395,7 @@ open class Koha : OkHttpBaseApi() {
}
OpacApi.MultiStepResult.ACTION_CONFIRMATION -> reservationFeeConfirmed = true
ACTION_ITEM -> selectedCopy = selection
+ ACTION_BRANCH -> selectedBranch = selection
}
var doc = httpGet("$baseurl/cgi-bin/koha/opac-reserve.pl?biblionumber=${item.id}", ENCODING).html
@@ -405,12 +408,33 @@ open class Koha : OkHttpBaseApi() {
}
}
+ if (doc.select("select[name=branch]").size > 0) {
+ if (selectedBranch == null && doc.select("select[name=branch] option").size > 1) {
+ return OpacApi.ReservationResult(
+ OpacApi.MultiStepResult.Status.SELECTION_NEEDED,
+ doc.select(".branch label").text).apply {
+ actionIdentifier = ACTION_BRANCH
+ setSelection(doc.select("select[name=branch] option").map { opt ->
+ HashMap<String, String>().apply {
+ put("key", opt.`val`())
+ put("value", opt.text())
+ }
+ })
+ }
+ } else if (doc.select("select[name=branch] option").size == 1) {
+ selectedBranch = doc.select("select[name=branch] option").first().`val`()
+ }
+ }
+
val body = FormBody.Builder()
body.add("place_reserve", "1")
val reserveMode = doc.select("input[name=reserve_mode]").`val`()
body.add("reserve_mode", reserveMode) // can be "single" or "multi"
body.add("single_bib", item.id)
body.add("expiration_date_${item.id}", "")
+ if (selectedBranch != null) {
+ body.add("branch", selectedBranch!!)
+ }
val checkboxes = doc.select("input[name=checkitem_${item.id}]")
if (checkboxes.size > 0) {
body.add("biblionumbers", "${item.id}/")
