[Koha-patches] [SIGNED OFF] Ergonomy improvement in smart rule management

Colin Campbell colin.campbell at ptfs-europe.com
Mon Dec 6 19:00:21 CET 2010


From: Jean-André Santoni <jeanandre.santoni at biblibre.com>

Added a jQuery table filter, usefull when you have a lot of rows. This filter works on the entire row and allows you for exemple to type "Adul Perio 5".
Indentation cleaning.
Added tabs to filter colums on 4 axes: All, Issues, Fines and Reserves.
Moved the table filter to the right of the tabs.

Signed-off-by: Colin Campbell <colin.campbell at ptfs-europe.com>
---
 .../en/lib/jquery/plugins/jquery.uitablefilter.js  |   90 +++++++++++++
 .../prog/en/modules/admin/smart-rules.tmpl         |  141 ++++++++++++++------
 2 files changed, 190 insertions(+), 41 deletions(-)
 create mode 100644 koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.uitablefilter.js

diff --git a/koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.uitablefilter.js b/koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.uitablefilter.js
new file mode 100644
index 0000000..d80c8dd
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.uitablefilter.js
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2008 Greg Weber greg at gregweber.info
+ * Dual licensed under the MIT and GPL licenses:
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.gnu.org/licenses/gpl.html
+ *
+ * documentation at http://gregweber.info/projects/uitablefilter
+ *
+ * allows table rows to be filtered (made invisible)
+ * <code>
+ * t = $('table')
+ * $.uiTableFilter( t, phrase )
+ * </code>
+ * arguments:
+ *   jQuery object containing table rows
+ *   phrase to search for
+ *   optional arguments:
+ *     column to limit search too (the column title in the table header)
+ *     ifHidden - callback to execute if one or more elements was hidden
+ */
+jQuery.uiTableFilter = function(jq, phrase, column, ifHidden){
+  var new_hidden = false;
+  if( this.last_phrase === phrase ) return false;
+
+  var phrase_length = phrase.length;
+  var words = phrase.toLowerCase().split(" ");
+
+  // these function pointers may change
+  var matches = function(elem) { elem.show() }
+  var noMatch = function(elem) { elem.hide(); new_hidden = true }
+  var getText = function(elem) { return elem.text() }
+
+  if( column ) {
+    var index = null;
+    jq.find("thead > tr:last > th").each( function(i){
+      if( $.trim($(this).text()) == column ){
+        index = i; return false;
+      }
+    });
+    if( index == null ) throw("given column: " + column + " not found")
+
+    getText = function(elem){ return jQuery(elem.find(
+      ("td:eq(" + index + ")")  )).text()
+    }
+  }
+
+  // if added one letter to last time,
+  // just check newest word and only need to hide
+  if( (words.size > 1) && (phrase.substr(0, phrase_length - 1) ===
+        this.last_phrase) ) {
+
+    if( phrase[-1] === " " )
+    { this.last_phrase = phrase; return false; }
+
+    var words = words[-1]; // just search for the newest word
+
+    // only hide visible rows
+    matches = function(elem) {;}
+    var elems = jq.find("tbody > tr:visible")
+  }
+  else {
+    new_hidden = true;
+    var elems = jq.find("tbody > tr")
+  }
+
+  elems.each(function(){
+    var elem = jQuery(this);
+    jQuery.uiTableFilter.has_words( getText(elem), words, false ) ?
+      matches(elem) : noMatch(elem);
+  });
+
+  last_phrase = phrase;
+  if( ifHidden && new_hidden ) ifHidden();
+  return jq;
+};
+
+// caching for speedup
+jQuery.uiTableFilter.last_phrase = ""
+
+// not jQuery dependent
+// "" [""] -> Boolean
+// "" [""] Boolean -> Boolean
+jQuery.uiTableFilter.has_words = function( str, words, caseSensitive )
+{
+  var text = caseSensitive ? str : str.toLowerCase();
+  for (var i=0; i < words.length; i++) {
+    if (text.indexOf(words[i]) === -1) return false;
+  }
+  return true;
+}
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl
index 4e65c59..6cba8f3 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl
@@ -2,6 +2,9 @@
 <title>Koha &rsaquo; Administration &rsaquo; Issuing Rules</title>
 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
 
+<script type="text/javascript" src="/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.uitablefilter.js"></script>
+<script type="text/javascript" src="/intranet-tmpl/prog/en/lib/jquery/plugins/ui.tabs.js"></script>
+<link rel="stylesheet" type="text/css" href="/intranet-tmpl/prog/en/lib/jquery/plugins/ui.tabs.css" />
 <script type="text/javascript">
 //<![CDATA[
 $(document).ready(function() {
@@ -9,6 +12,45 @@ $(document).ready(function() {
         $('#branch').change(function() {
                 $('#selectlibrary').submit();
         });
+        $('#filter').keyup(function() {
+                $.uiTableFilter( $('#smartrules'), this.value );
+        });
+        $('#nofilter').click(function() {
+            $('.issues').show();
+            $('.fines').show();
+            $('.reserves').show();
+            $(this).parent().attr('class','ui-tabs-selected');
+            $('#issuesfilter').parent().attr('class',null);
+            $('#finesfilter').parent().attr('class',null);
+            $('#reservesfilter').parent().attr('class',null);
+        });
+        $('#issuesfilter').click(function() {
+            $('.issues').show();
+            $('.fines').hide();
+            $('.reserves').hide();
+            $(this).parent().attr('class','ui-tabs-selected');
+            $('#nofilter').parent().attr('class',null);
+            $('#finesfilter').parent().attr('class',null);
+            $('#reservesfilter').parent().attr('class',null);
+        });
+        $('#finesfilter').click(function() {
+            $('.issues').hide();
+            $('.fines').show();
+            $('.reserves').hide();
+            $(this).parent().attr('class','ui-tabs-selected');
+            $('#issuesfilter').parent().attr('class',null);
+            $('#nofilter').parent().attr('class',null);
+            $('#reservesfilter').parent().attr('class',null);
+        });
+        $('#reservesfilter').click(function() {
+            $('.issues').hide();
+            $('.fines').hide();
+            $('.reserves').show();
+            $(this).parent().attr('class','ui-tabs-selected');
+            $('#issuesfilter').parent().attr('class',null);
+            $('#finesfilter').parent().attr('class',null);
+            $('#nofilter').parent().attr('class',null);
+        });
 });
 //]]>
 </script>
@@ -46,36 +88,48 @@ $(document).ready(function() {
         </ul>
         <p>To modify a rule, create a new one with the same patron type and item type.</p>
     </div>
-    <div>
+    <div id="bloc100">
         <form method="get" action="/cgi-bin/koha/admin/smart-rules.pl" id="selectlibrary">
         Select a library :
             <select name="branch" id="branch" style="width:20em;">
                 <option value="*">Default</option>
             <!-- TMPL_LOOP NAME="branchloop" -->
-				<!-- TMPL_IF NAME="selected" --><option value="<!-- TMPL_VAR NAME="value" -->" selected="selected"><!-- TMPL_VAR NAME="branchname" --></option><!-- TMPL_ELSE --><option value="<!-- TMPL_VAR NAME="value" -->"><!-- TMPL_VAR NAME="branchname" --></option><!-- /TMPL_IF -->
+                <!-- TMPL_IF NAME="selected" --><option value="<!-- TMPL_VAR NAME="value" -->" selected="selected"><!-- TMPL_VAR NAME="branchname" --></option><!-- TMPL_ELSE --><option value="<!-- TMPL_VAR NAME="value" -->"><!-- TMPL_VAR NAME="branchname" --></option><!-- /TMPL_IF -->
             <!-- /TMPL_LOOP -->
             </select>
         </form>
 <!-- TMPL_IF Name="definedbranch" --><form action="/cgi-bin/koha/admin/clone-rules.pl" method="post"><label for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidden" name="frombranch" value="<!-- TMPL_VAR NAME="branch" -->" />
             <select name="tobranch" id="tobranch"><!-- TMPL_LOOP NAME="branchloop" --><option value="<!-- TMPL_VAR NAME="value" -->"><!-- TMPL_VAR NAME="branchname" --></option><!-- /TMPL_LOOP --></select> <input type="submit" value="Clone" /></form><!-- /TMPL_IF --></fieldset>
 
-        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
+        <div class="toptabs">
+            <ul class="ui-tabs-nav">
+                <li class="ui-tabs-selected"><a id="nofilter">All</a></li>
+                <li><a id="issuesfilter">Issues</a></li>
+                <li><a id="finesfilter">Fines</a></li>
+                <li><a id="reservesfilter">Reserves</a></li>
+                <div style="text-align:right;"><label for="filter">Filter: </label><input type="text" name="filter" id="filter" /></div>
+            </ul>
+            <div class="tabs-container">
+            <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
             <input type="hidden" name="op" value="add" />
-            <table>
-            <tr>
-                <th>Patron Category</th>
-                <th>Item Type</th>
-                <th>Current Checkouts Allowed</th>
-                <th>Loan Period (day)</th>
-                <th>Fine Amount</th>
-                <th>Fine Charging Interval</th>
-                <th>Fine Grace period (day)</th>
-                <th>Suspension in Days (day)</th>
-                <th>Renewals Allowed (count)</th>
-                <th>Holds Allowed (count)</th>
-		        <th>Rental Discount (%)</th>
-				<th>&nbsp;</th>
-            </tr>
+            <table id="smartrules" width="100%">
+                <thead>
+                    <tr>
+                        <th>Patron Category</th>
+                        <th>Item Type</th>
+                        <th class="issues">Current Checkouts Allowed</th>
+                        <th class="issues">Loan Period (day)</th>
+                        <th class="fines">Fine Amount</th>
+                        <th class="fines">Fine Charging Interval</th>
+                        <th class="fines">Fine Grace period (day)</th>
+                        <th class="fines">Suspension in Days (day)</th>
+                        <th class="issues">Renewals Allowed (count)</th>
+                        <th class="reserves">Holds Allowed (count)</th>
+                        <th class="issues">Rental Discount (%)</th>
+                        <th>&nbsp;</th>
+                    </tr>
+                </thead>
+                <tbody>
 				<!-- TMPL_LOOP NAME="rules" -->
 					<!-- TMPL_UNLESS NAME="__odd__" -->
 					<tr class="highlight">
@@ -94,25 +148,27 @@ $(document).ready(function() {
 									<!-- TMPL_VAR NAME="humanitemtype" -->
 								<!-- /TMPL_IF -->
 							</td>
-							<td><!-- TMPL_IF NAME="unlimited_maxissueqty" -->
-									Unlimited
-								<!-- TMPL_ELSE -->
-									<!-- TMPL_VAR NAME="maxissueqty" -->
-								<!-- /TMPL_IF -->
-							</td>
-							<td><!-- TMPL_VAR NAME="issuelength" --></td>
-							<td><!-- TMPL_VAR NAME="fine" --></td>
-							<td><!-- TMPL_VAR NAME="chargeperiod" --></td>
-							<td><!-- TMPL_VAR NAME="firstremind" --></td>
-							<td><!-- TMPL_VAR NAME="finedays" --></td>
-							<td><!-- TMPL_VAR NAME="renewalsallowed" --></td>
-							<td><!-- TMPL_VAR NAME="reservesallowed" --></td>
-							<td><!-- TMPL_VAR NAME="rentaldiscount" --></td>
+						            <td class="issues"><!-- TMPL_IF NAME="unlimited_maxissueqty" -->
+                                            Unlimited
+                                        <!-- TMPL_ELSE -->
+                                            <!-- TMPL_VAR NAME="maxissueqty" -->
+                                        <!-- /TMPL_IF -->
+                                    </td>
+                                    <td class="issues"><!-- TMPL_IF NAME="issuelength" --><!-- TMPL_VAR NAME="issuelength" --> <!-- /TMPL_IF --></td>
+                                    <td class="fines"><!-- TMPL_VAR NAME="fine" --></td>
+                                    <td class="fines"><!-- TMPL_IF NAME="chargeperiod" --><!-- TMPL_VAR NAME="chargeperiod" --> <!-- /TMPL_IF --></td>
+                                    <td class="fines"><!-- TMPL_IF NAME="firstremind" --><!-- TMPL_VAR NAME="firstremind" --> <!-- /TMPL_IF --></td>
+                                    <td class="fines"><!-- TMPL_IF NAME="finedays" --> <!-- TMPL_VAR NAME="finedays" --> <!-- /TMPL_IF --></td>
+                                    <td class="issues"><!-- TMPL_IF NAME="renewalsallowed" --><!-- TMPL_VAR NAME="renewalsallowed" --> <!-- /TMPL_IF --></td>
+                                    <td class="reserves"><!-- TMPL_IF NAME="reservesallowed" --><!-- TMPL_VAR NAME="reservesallowed" --> <!-- /TMPL_IF --></td>
+							<td class="issues"><!-- TMPL_VAR NAME="rentaldiscount" --></td>
 							<td>
 								<a class="button" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=<!-- TMPL_VAR NAME="itemtype" -->&amp;categorycode=<!-- TMPL_VAR NAME="categorycode" -->&amp;branch=<!-- TMPL_VAR NAME="branch" -->">Delete</a>
 							</td>
                 	</tr>
             	<!-- /TMPL_LOOP -->
+                </tbody>
+                <tfoot>
                 <tr>
                     <td>
                         <select name="categorycode">
@@ -130,19 +186,22 @@ $(document).ready(function() {
                         <!-- /TMPL_LOOP -->
                         </select>
                     </td>
-                    <td><input name="maxissueqty" size="3" /></td>
-                    <td><input name="issuelength" size="3" /> </td>
-                    <td><input name="fine" size="4" /></td>
-                    <td><input name="chargeperiod" size="2" /></td>
-                    <td><input name="firstremind" size="2" /> </td>
-                    <td><input name="finedays" size="3" /> </td>
-                    <td><input name="renewalsallowed" size="2" /></td>
-                    <td><input name="reservesallowed" size="2" /></td>
-		    <td><input name="rentaldiscount" size="2" /></td>
+                        <td class="issues"><input name="maxissueqty" size="3" /></td>
+                                <td class="issues"><input name="issuelength" size="3" /> </td>
+                                <td class="fines"><input name="fine" size="4" /></td>
+                                <td class="fines"><input name="chargeperiod" size="2" /></td>
+                                <td class="fines"><input name="firstremind" size="2" /> </td>
+                                <td class="fines"><input name="finedays" size="3" /> </td>
+                                <td class="issues"><input name="renewalsallowed" size="2" /></td>
+                                <td class="reserves"><input name="reservesallowed" size="2" /></td>
+		    <td><input class="issues" name="rentaldiscount" size="2" /></td>
                     <td><input type="hidden" name="branch" value="<!-- TMPL_VAR NAME="branch" -->"/><input type="submit" value="Add" class="submit" /></td>
                 </tr>
+                </tfoot>
             </table>
         </form>
+            </div><!-- tabs-container -->
+        </div><!-- toptabs -->
     </div>
     <div class="help">
         <h4>Defaults for this library</h4>
-- 
1.7.3.2



More information about the Koha-patches mailing list