RT26084: Hide Suspend button on suspended holds
[sitka/overdrive-evergreen-opac.git] / src / od_pages_myopac.coffee
index 8e80111..40a27ec 100644 (file)
@@ -4,10 +4,11 @@
 define [
        'jquery'
        'lodash'
+       'od_config'
        'jquery-ui'
        'od_action'
        'od_pages_opac'
-], ($, _) ->
+], ($, _, config) ->
 
        $.fn.extend
 
@@ -23,25 +24,29 @@ define [
                _dashboard: (x) ->
 
                        if arguments.length is 0
+                               @append $('<div id="dashboard">')
 
+                       else
                                # Add a new dashboard for to show counts of e-items; start with
                                # zero counts
                                base = '/eg/opac/myopac'
-                               @append """
-       <div id="dashboard">
-               <span class="dash-align">
-                       <a class="dash-link" href="#{base}/circs?e_items"><span class="ncheckouts" id="dash_checked">0</span> E-items Checked Out</a>
-               </span>
-               <span class="dash_divider">|</span>
-               <span class="dash-align">
-                       <a class="dash-link" href="#{base}/holds?e_items"><span class="nholds" id="dash_holds">0</span> E-items on Hold</a>
-               </span>
-               <span class="dash_divider">|</span>
-               <span class="dash-align">
-                       <a class="dash-link" href="#{base}/holds?e_items&available=1"><span class="nholdsready" id="dash_pickup">0</span> E-items Ready for Checkout</a>
-               </span>
-       </div>
-                               """
+                               @find 'div'
+                                       .eq 2
+                                       .append """
+                                       <span class="dash-align">
+                                               <a class="dash-link" href="#{base}/circs?e_items"><span class="ncheckouts" id="dash_checked">0</span> E-items Checked Out</a>
+                                       </span>
+                                       <span class="dash_divider">|</span>
+                                       <span class="dash-align">
+                                               <a class="dash-link" href="#{base}/holds?e_items"><span class="nholds" id="dash_holds">0</span> E-items on Hold</a>
+                                       </span>
+                                       <span class="dash_divider">|</span>
+                                       <span class="dash-align">
+                                               <a class="dash-link" href="#{base}/holds?e_items&available=1"><span class="nholdsready" id="dash_pickup">0</span> E-items Ready for Checkout</a>
+                                       </span>
+                                       """
+                                       .end()
+                                       .end()
 
                                # The following sequence is necessary to align the new dashboard
                                # with the existing ones, but do not know why it needs to be done
@@ -49,24 +54,24 @@ define [
                                        .css float: 'none'
                                        .end()
 
-                       else
                                @_counters x # Change the values of the counters
+
                        return @
 
                # Replace account summary area with one that shows links to go to
-               # e-items lists
+               # physical and e-items lists
                _account_summary: (x) ->
 
                        if arguments.length is 0
                                # Parse a list of totals of physical items from the account summary table
                                totals = ( +(v.textContent.match(/\d+?/)[0]) for v in @find('td').not '[align="right"]' )
 
-                               tpl = """
+                               tpl = _.template """
                                <tbody>
                                        <tr>
                                                <td>
                                                        <a href="/eg/opac/myopac/circs">
-                                                               <span><span class="ncheckouts" /> Items Currently Checked out</span>
+                                                               <span><span class="ncheckouts" /> <%= ncheckouts %> Items Currently Checked out</span>
                                                        </a>
                                                </td>
                                                <td align="right">
@@ -75,7 +80,7 @@ define [
                                        </tr>
                                        <tr>
                                                <td>
-                                                       <a href="/eg/opac/myopac/holds"><span class="nholds" /> Items Currently on Hold</a>
+                                                       <a href="/eg/opac/myopac/holds"><span class="nholds" /> <%= nholds %> Items Currently on Hold</a>
                                                </td>
                                                <td align="right">
                                                        <a href="/eg/opac/myopac/holds?e_items"><span class="n_holds" /> E-items Currently on Hold</a>
@@ -83,7 +88,7 @@ define [
                                        </tr>
                                        <tr>
                                                <td>
-                                                       <a href="/eg/opac/myopac/holds?available=1"><span class="nready" /> Items ready for pickup</a>
+                                                       <a href="/eg/opac/myopac/holds?available=1"><span class="nready" /> <%= nready %> Items ready for pickup</a>
                                                </td>
                                                <td align="right">
                                                        <a href="/eg/opac/myopac/holds?e_items&available=1"><span class="n_ready" /> E-items ready for pickup</a>
@@ -91,11 +96,32 @@ define [
                                        </tr>
                                </tbody>
                                """
-                               @empty().append tpl
-                               return totals
+
+                               # Build a new table consisting of two columns.  The first
+                               # column is for physical items with the existing totals.  The
+                               # second column is for e-items and is initially hidden until
+                               # its total values are available.
+                               @empty()
+                               .append tpl
+                                       ncheckouts:  totals[0]
+                                       nholds:      totals[1]
+                                       nready:      totals[2]
+                               .find 'td'
+                                       .filter '[align="right"]'
+                                       .find 'a'
+                                               .hide()
+                                               .end()
+                                       .end()
 
                        else
-                               @_counters x # Change the values of the counters
+                               # Change the values of the counters and reveal the e-items column
+                               @_counters x
+                               .find 'td'
+                                       .filter '[align="right"]'
+                                       .find 'a'
+                                               .show()
+                                               .end()
+                                       .end()
 
                # Relabel a history tab
                _tab_history: ->
@@ -269,29 +295,31 @@ define [
 
                _holds_row: (hold) ->
 
+                       suspended = if hold.holdSuspension? then 1
+
                        @find 'td.availability'
                                ._holds_row_avail1 hold
                                .end()
                        .find 'td.actions'
-                               ._actions hold.actions, hold.reserveId
+                               ._actions hold.actions, hold.reserveId, suspended
                                .end()
 
                # Show a title, author, or format by using the given metadata object
                _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
 
                        $title = $ """
-                       <a href="/eg/opac/results?query=#{meta.title};locg=10;qtype=title">#{meta.title}</a>
+                       <a href="/eg/opac/results?query=#{meta.title};qtype=title">#{meta.title}</a>
                        """
                        $thumbnail = $ """
                        <img src="#{meta.images?.thumbnail?.href}" alt="#{meta.title}" />
                        """
                        $author = $ """
-                       <a href="/eg/opac/results?query=#{meta.author};locg=10;qtype=author">#{meta.author}</a>
+                       <a href="/eg/opac/results?query=#{meta.author};qtype=author">#{meta.author}</a>
                        """
                        for n in classnames
                                $n = @find ".#{n}"
@@ -299,7 +327,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) ->
@@ -332,7 +360,7 @@ define [
                                <li>Hold will expire <%= expires %></li>
                                </ul>
                        </div>
-                       <a href="http://downloads.bclibrary.ca/ContentDetails.htm?ID=<%= id %>">Link to Overdrive Account to change preferences</a>
+                       <a href="<%= baseURL %>?ID=<%= id %>">Link to Overdrive Account to change preferences</a>
                        """
                        @empty().append tpl
                                position:  hold.holdListPosition
@@ -341,6 +369,7 @@ define [
                                expires:   hold.holdExpires.fromNow()
                                placed:    hold.holdPlacedDate.fromNow()
                                activates: hold.holdSuspension?.numberOfDays.calendar()
+                               baseURL:   config.baseURL
                                id:        hold.reserveId
 
                        # Illuminate areas of this row according to the hold status
@@ -418,11 +447,9 @@ define [
                                        ._row_meta() # progress bars
 
                        # Add checkout rows to <tbody> and remove the warning box.
-                       # <tbody> also has the responsibility of handling format buttons.
                        if $rows.length > 0
                                @find 'tbody'
                                        .empty().append $rows
-                                       ._download_format()
                                        .end()
                                .find '.warning_box'
                                        .remove()
@@ -447,11 +474,12 @@ define [
                        tpl = _.template """
                        <div>Expires <%= expires_relatively %></div>
                        <div><%= expires_exactly %></div>
-                       <a href="http://downloads.bclibrary.ca/ContentDetails.htm?ID=<%= id %>">Click to access online (library card required)</a>
+                       <a href="<%= baseURL %>?ID=<%= id %>">Click to access online (library card required)</a>
                        """
                        @empty().append tpl
                                expires_relatively: circ.expires.fromNow()
                                expires_exactly:    circ.expires.format 'YYYY MMM D, h:mm:ss a'
+                               baseURL:            config.baseURL
                                id:                 circ.reserveId
 
                # Build a <tr> element to show the available actions of an item.