From e07737bf64183be211f08b2724dba0833be8e5ba Mon Sep 17 00:00:00 2001 From: Steven Chan Date: Sun, 7 Sep 2014 17:24:24 -0700 Subject: [PATCH] Fix format type mismatch The format type that is listed on search results, record details, and place hold form doesn't match what is listed in the selection option list of the checkout dialogue. To remove the mismatch, we need to use the format types found in the checkout action object, which is gotten from Availability, rather than the basic list found from Metadata. The difference is presumably due to Advantage accounts. For search results or record details, we omit the call for Metadata and substitute the format types from checkout action. For place hold form, we cannot omit a call to Metadata, because it supplies title details as well as format types. Therefore, we have to reschedule the asynchronous calls to Metadata and Availability to run in parallel, wait for both results, and then check to see if there is a checkout action in Availability before being able to do the right thing. Signed-off-by: Steven Chan --- src/od_data.coffee | 10 +++++++ src/od_pages_myopac.coffee | 4 +-- src/od_pages_opac.coffee | 15 ++++++---- src/overdrive.coffee | 70 ++++++++++++++++++++++++++++------------------ 4 files changed, 65 insertions(+), 34 deletions(-) diff --git a/src/od_data.coffee b/src/od_data.coffee index 4b37d61..55a820a 100644 --- a/src/od_data.coffee +++ b/src/od_data.coffee @@ -70,6 +70,7 @@ define [ @zero() @hold email_address if @actions?.hold @proxies @actions if @actions? + @action_formats() return @ @@ -89,6 +90,15 @@ define [ _.where(@actions.hold.fields, name: 'emailAddress')[0].value = email_address return @ + # Surface the format options list that might be buried in an actions object + action_formats: -> + xs = @actions?.checkout?.fields + return @ unless xs?.length > 0 + break for x in xs when x.name is 'formatType' + return @ unless x.options.length > 0 + @formats = ( { id: v, name: '' } for v in x.options ) + return @ + class Holds extends U constructor: (x) -> diff --git a/src/od_pages_myopac.coffee b/src/od_pages_myopac.coffee index 8e80111..770ee22 100644 --- a/src/od_pages_myopac.coffee +++ b/src/od_pages_myopac.coffee @@ -280,7 +280,7 @@ define [ _row_meta: (meta, classnames...) -> status = if arguments.length is 0 then value: false else 'destroy' - @find(".#{n}").progressbar(status) for n in ['title', 'author', 'formats'] + try @find(".#{n}").progressbar(status) for n in ['title', 'author', 'formats'] return @ unless meta @@ -299,7 +299,7 @@ define [ when 'thumbnail' then $n.empty().append $thumbnail when 'title' then $n.empty().append $title when 'author' then $n.empty().append $author - when 'formats' then $n._show_formats meta + when 'formats' then $n._show_formats meta?.formats return @ _holds_row_avail1: (hold) -> diff --git a/src/od_pages_opac.coffee b/src/od_pages_opac.coffee index 9ced00d..e64dee3 100644 --- a/src/od_pages_opac.coffee +++ b/src/od_pages_opac.coffee @@ -4,8 +4,13 @@ define [ 'jquery' 'lodash' + 'od_api' 'jquery-ui' -], ($, _) -> +], ( + $ + _ + od +) -> $.fn.extend @@ -14,10 +19,10 @@ define [ return @ unless x $x = - if x.formats + if x?.length > 0 $('