From: Owen Leonard <[email protected]> Columns on the summary table are shown or hidden based on a variety of different settings, leading to convoluted if/else template constructions if we want to define header sorting in the <script> block. Using the jQuery Metadata plugin allows us to specify sorting options as classes on the table header. This adds a dependency but simplifies the template markup significantly.
I recommend continuing to specify header sort options in the <script> block in cases where it is relatively simple to do so and saving inclusion of the additional jQuery plugin for pages which really need it. Other changes: Moved common sorter configuration detalis to default declaration; Moved the date due column so that it could be set as the default sort without taking into account multiple disappearing columns (default sort cannot be set in the markup for a <th>). Signed-off-by: Nicole C. Engard <[email protected]> --- .../en/lib/jquery/plugins/jquery.metadata.min.js | 8 ++ koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt | 83 ++++++-------------- 2 files changed, 31 insertions(+), 60 deletions(-) create mode 100644 koha-tmpl/opac-tmpl/prog/en/lib/jquery/plugins/jquery.metadata.min.js diff --git a/koha-tmpl/opac-tmpl/prog/en/lib/jquery/plugins/jquery.metadata.min.js b/koha-tmpl/opac-tmpl/prog/en/lib/jquery/plugins/jquery.metadata.min.js new file mode 100644 index 0000000..d9370d5 --- /dev/null +++ b/koha-tmpl/opac-tmpl/prog/en/lib/jquery/plugins/jquery.metadata.min.js @@ -0,0 +1,8 @@ +(function($){$.extend({metadata:{defaults:{type:'class',name:'metadata',cre:/({.*})/,single:'metadata'},setType:function(type,name){this.defaults.type=type;this.defaults.name=name;},get:function(elem,opts){var settings=$.extend({},this.defaults,opts);if(!settings.single.length)settings.single='metadata';var data=$.data(elem,settings.single);if(data)return data;data="{}";var getData=function(data){if(typeof data!="string")return data;if(data.indexOf('{')<0){data=eval("("+data+")");}} +var getObject=function(data){if(typeof data!="string")return data;data=eval("("+data+")");return data;} +if(settings.type=="html5"){var object={};$(elem.attributes).each(function(){var name=this.nodeName;if(name.match(/^data-/))name=name.replace(/^data-/,'');else return true;object[name]=getObject(this.nodeValue);});}else{if(settings.type=="class"){var m=settings.cre.exec(elem.className);if(m) +data=m[1];}else if(settings.type=="elem"){if(!elem.getElementsByTagName)returnvar;e=elem.getElementsByTagName(settings.name);if(e.length) +data=$.trim(e[0].innerHTML);}else if(elem.getAttribute!=undefined){var attr=elem.getAttribute(settings.name);if(attr) +data=attr;} +object=getObject(data.indexOf("{")<0?"{"+data+"}":data);} +$.data(elem,settings.single,object);return object;}}});$.fn.metadata=function(opts){return $.metadata.get(this[0],opts);};})(jQuery); \ No newline at end of file diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt index 58c6fa5..af09b74 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt @@ -4,6 +4,7 @@ [% BORROWER_INF.firstname %] [% BORROWER_INF.surname %] [% END %] [% INCLUDE 'doc-head-close.inc' %] +<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.metadata.min.js"></script> <script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.tablesorter.min.js"></script> <script type="text/JavaScript" language="JavaScript"> //<![CDATA[ @@ -16,53 +17,15 @@ $.tablesorter.addParser({ }); $(function() { $('#opac-user-views > ul').tabs(); - $("#holdst").tablesorter({[% IF ( dateformat == 'metric' ) %] - dateFormat: 'uk',[% END %] - widgets : ['zebra'], - sortList: [[0,0]], - headers: { 0: { sorter: 'articles' },5: { sorter: false } - } + $.tablesorter.defaults.widgets = ['zebra']; + [% IF ( dateformat == 'metric' ) %]$.tablesorter.defaults.dateFormat = ['uk'];[% END %] + $("#holdst").tablesorter({ + sortList: [[0,0]] }); - $("#checkoutst").tablesorter({[% IF ( dateformat == 'metric' ) %] - dateFormat: 'uk',[% END %] - widgets : ['zebra'], - [% IF ( JacketImages ) %] - sortList: [[3,0]], - [% IF ( item_level_itypes ) %] - headers: { 0: { sorter: false }, 1: { sorter: 'articles' },4: { sorter: false },5: { sorter: false },6: { sorter: false }} - [% ELSE %] - headers: { 0: { sorter: false }, 1: { sorter: 'articles' },5: { sorter: false },6: { sorter: false },7: { sorter: false }} - [% END %] - [% ELSE %] - [% IF ( item_level_itypes ) %] - sortList: [[2,0]], - headers: { 0: { sorter: 'articles' },3: { sorter: false },4: { sorter: false },5: { sorter: false }} - [% ELSE %] - sortList: [[3,0]], - headers: { 0: { sorter: 'articles' },4: { sorter: false },5: { sorter: false },6: { sorter: false }} - [% END %] - [% END %] - }); - $("#overduest").tablesorter({[% IF ( dateformat == 'metric' ) %] - dateFormat: 'uk',[% END %] - widgets : ['zebra'], - [% IF ( JacketImages ) %] - sortList: [[1,0]], - [% IF ( item_level_itypes ) %] - headers: { 0: { sorter: false }, 1: { sorter: 'articles' },4: { sorter: false },5: { sorter: false }} - [% ELSE %] - headers: { 0: { sorter: false }, 1: { sorter: 'articles' },5: { sorter: false },6: { sorter: false }} - [% END %] - [% ELSE %] - [% IF ( item_level_itypes ) %] - sortList: [[0,0]], - headers: { 0: { sorter: 'articles' },3: { sorter: false }} - [% ELSE %] - sortList: [[0,0]], - headers: { 0: { sorter: 'articles' },1: { sorter: false },3: { sorter: false }} - [% END %] - [% END %] - }); + $("#checkoutst").tablesorter({ + [% IF ( JacketImages ) %]sortList: [[2,0]][% ELSE %]sortList: [[1,0]][% END %] + }); + $("#overduest").tablesorter(); [% IF ( GoogleJackets ) %]KOHA.Google.GetCoverFromIsbn();[% END %] }); //]]> @@ -168,7 +131,7 @@ $.tablesorter.addParser({ <table id="waitingt"> <caption>Holds Waiting</caption> <thead> <tr> - <th colspan="2">Title</th> + <th colspan="2" class="{sorter:'articles'}">Title</th> <th>Hold date</th> <th>Pick Up Library</th> </tr></thead> @@ -198,20 +161,20 @@ $.tablesorter.addParser({ <table id="checkoutst"> <caption>[% issues_count %] Item(s) Checked Out</caption> <thead><tr> - [% IF ( JacketImages ) %]<th> </th>[% END %] - <th>Title</th> + [% IF ( JacketImages ) %]<th class="{sorter: false}"> </th>[% END %] + <th class="{sorter:'articles'}">Title</th> + <th>Due</th> [% UNLESS ( item_level_itypes ) %]<th>Item Type</th> [% END %] [% IF ( show_barcode ) %]<th>Barcode</th>[% END %] <th>Call No.</th> - <th>Due</th> [% IF ( OpacRenewalAllowed ) %] - [% UNLESS ( patron_flagged ) %]<th>Renew</th>[% END %] + [% UNLESS ( patron_flagged ) %]<th class="{sorter: false}">Renew</th>[% END %] [% END %] [% IF ( OPACFinesTab ) %] <th>Fines</th> [% END %] [% IF ( OPACMySummaryHTML ) %] - <th>Links</th> + <th class="{sorter: false}">Links</th> [% END %] </tr></thead> <tbody> @@ -244,14 +207,14 @@ $.tablesorter.addParser({ <td><a href="/cgi-bin/koha/opac-detail.pl?biblionumber=[% ISSUE.biblionumber %]">[% ISSUE.title |html %]</a><span class="item-details"> [% ISSUE.author %] </span></td> - [% UNLESS ( item_level_itypes ) %]<td>[% IF ( ISSUE.imageurl ) %]<img src="[% ISSUE.imageurl %]" title="[% ISSUE.description %]" alt="[% ISSUE.description %]" />[% END %] [% ISSUE.description %]</td>[% END %] - [% IF ( show_barcode ) %]<td>[% ISSUE.barcode %]</td>[% END %] - <td>[% ISSUE.itemcallnumber %]</td> [% IF ( ISSUE.overdue ) %] <td class="overdue">[% ISSUE.date_due %]</td> [% ELSE %] <td>[% ISSUE.date_due %]</td> [% END %] + [% UNLESS ( item_level_itypes ) %]<td>[% IF ( ISSUE.imageurl ) %]<img src="[% ISSUE.imageurl %]" title="[% ISSUE.description %]" alt="[% ISSUE.description %]" />[% END %] [% ISSUE.description %]</td>[% END %] + [% IF ( show_barcode ) %]<td>[% ISSUE.barcode %]</td>[% END %] + <td>[% ISSUE.itemcallnumber %]</td> [% IF ( OpacRenewalAllowed ) %] [% UNLESS ( ISSUE.patron_flagged ) %] <td>[% IF ( ISSUE.status ) %]<input type="checkbox" name="item" value="[% ISSUE.itemnumber %]"/><a href="/cgi-bin/koha/opac-renew.pl?from=opac_user&item=[% ISSUE.itemnumber %]&borrowernumber=[% ISSUE.borrowernumber %]">Renew</a> <span class="renewals">([% ISSUE.renewsleft %] of [% ISSUE.renewsallowed %] renewals remaining)</span> @@ -297,14 +260,14 @@ $.tablesorter.addParser({ <caption>Overdues <span class="count">([% overdues_count %] total)</span></caption> <!-- OVERDUES TABLE ROWS --> <thead><tr> -[% IF ( JacketImages ) %]<th> </th>[% END %] -<th>Title</th> +[% IF ( JacketImages ) %]<th class="{sorter: false}"> </th>[% END %] +<th class="{sorter:'articles'}">Title</th> [% UNLESS ( item_level_itypes ) %]<th>Item Type</th> [% END %] [% IF ( show_barcode ) %]<th>Barcode</th>[% END %] <th>Call No.</th> <th>Due</th> [% IF ( OpacRenewalAllowed ) %] - [% UNLESS ( patron_flagged ) %]<th>Renew</th>[% END %][% END %] + [% UNLESS ( patron_flagged ) %]<th class="{sorter: false}">Renew</th>[% END %][% END %] [% IF ( OPACFinesTab ) %] <th>Fines</th> [% END %] @@ -360,7 +323,7 @@ $.tablesorter.addParser({ <caption>Holds <span class="count">([% reserves_count %] total)</span></caption> <!-- RESERVES TABLE ROWS --> <thead><tr> - <th>Title</th> + <th class="{sorter:'articles'}">Title</th> <th>Placed On</th> <th>Expires On</th> <th>Pick Up Location</th> @@ -368,7 +331,7 @@ $.tablesorter.addParser({ <th>Priority</th> [% END %] <th>Status</th> - <th>Modify</th> + <th class="{sorter: false}">Modify</th> </tr></thead> <tbody> [% FOREACH RESERVE IN RESERVES %] -- 1.7.2.3 _______________________________________________ Koha-patches mailing list [email protected] http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-patches website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/
