kpac : breadcrumbs, paging, misc
authorBill Erickson <berick@esilibrary.com>
Thu, 26 Jan 2012 16:49:55 +0000 (11:49 -0500)
committerMike Rylander <mrylander@gmail.com>
Mon, 30 Jul 2012 18:59:01 +0000 (14:59 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
14 files changed:
Open-ILS/examples/kpac.xml
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGKPacLoader.pm
Open-ILS/src/templates/kpac/category.tt2
Open-ILS/src/templates/kpac/index.tt2
Open-ILS/src/templates/kpac/parts/base.tt2
Open-ILS/src/templates/kpac/parts/breadcrumb.tt2 [new file with mode: 0644]
Open-ILS/src/templates/kpac/parts/footer.tt2 [new file with mode: 0644]
Open-ILS/src/templates/kpac/parts/grid.tt2
Open-ILS/src/templates/kpac/parts/header.tt2 [new file with mode: 0644]
Open-ILS/src/templates/kpac/parts/paginate.tt2 [new file with mode: 0644]
Open-ILS/src/templates/kpac/parts/subpage.tt2 [changed mode: 0755->0644]
Open-ILS/src/templates/kpac/parts/util.tt2 [new file with mode: 0644]
Open-ILS/src/templates/kpac/search_results.tt2
Open-ILS/web/css/skin/default/kpac/style.css

index 92182e1..c905cc1 100644 (file)
         </page>
 
         <!-- topic pages -->
-        <page id="10" columns="3" name="Book Series" img="category.png">
-            <cell name="Mammals" img="category.png" type="search">su:mammal audience(j)</cell>
-            <cell name="Molluscs" img="category.png" type="search">su:mammal audience(j)</cell>
-            <cell name="Squids" img="category.png" type="search">su:mammal audience(j)</cell>
-            <cell name="Snails" img="category.png" type="search">su:mammal audience(j)</cell>
-            <cell name="Jellyfish" img="category.png" type="search">su:mammal audience(j)</cell>
-            <cell name="Old Yeller" img="category.png" type="search">su:mammal audience(j)</cell>
-        </page>
-        <page id="11" columns="1" name="Current Events" img="category.png">
+        <page id="10" columns="3" name="Musical Instruments" img="category.png">
+            <cell name="Piano"    img="category.png" type="search">su:piano</cell>
+            <cell name="Guitar"   img="category.png" type="search">su:guitar</cell>
+            <cell name="Trumpet"  img="category.png" type="search">su:trumpet</cell>
+            <cell name="Drums"    img="category.png" type="search">su:drums</cell>
+            <cell name="Bass"     img="category.png" type="search">su:bass</cell>
+            <cell name="Clarinet" img="category.png" type="search">su:clarinet</cell>
+        </page>
+        <page id="11" columns="3" name="Current Events" img="category.png">
+            <cell name="Entertainment"  img="category.png" type="search">su:entertainment sort('pubdate')#descending</cell>
+            <cell name="Politics"       img="category.png" type="search">su:politics sort('pubdate')#descending</cell>
+            <cell name="Economy"        img="category.png" type="search">su:economy sort('pubdate')#descending</cell>
         </page>
         <page id="12" columns="3" name="Programming" img="category.png">
         </page>
index bbbba45..266c821 100644 (file)
@@ -23,14 +23,19 @@ sub load {
     $self->load_kpac_config;
 
     my $path = $self->apache->path_info;
+    ($self->ctx->{page} = $path) =~ s#.*/(.*)#$1#g;
 
     return $self->load_simple("index") if $path =~ m|kpac/index|;
     return $self->load_simple("category") if $path =~ m|kpac/category|;
     return $self->load_simple("checkout") if $path =~ m|kpac/checkout|;
     return $self->load_simple("checkout_results") if $path =~ m|kpac/checkout_results|;
-    return $self->load_simple("detailed") if $path =~ m|kpac/detailed|;
+
+    # note: sets page=rresult
     return $self->load_rresults if $path =~ m|kpac/search_results|; # inherited from tpac
 
+    # note: sets page=record
+    return $self->load_simple("detailed") if $path =~ m|kpac/detailed|;
+
     # ----------------------------------------------------------------
     #  Everything below here requires SSL
     # ----------------------------------------------------------------
@@ -86,8 +91,9 @@ sub load_kpac_config {
         $ou = $org->parent_ou;
     }
 
-    $self->ctx->{kpac_layout} = $kpac_config->{pages}->{page}->{$layout->{page}};
+    $self->ctx->{kpac_layout} = $layout;
     $self->ctx->{kpac_config} = $kpac_config;
+    $self->ctx->{kpac_root} = $self->ctx->{base_path} . "/kpac"; 
 }
 
 
index 0a63e9d..6ff11a1 100644 (file)
@@ -1,12 +1,14 @@
 [%  PROCESS "opac/parts/header.tt2";
     PROCESS "kpac/parts/grid.tt2";
     WRAPPER "kpac/parts/subpage.tt2";
-    ctx.page_title = ctx.kpac_layout.name %]
+    page_id = trail_endpoint();
+    page = ctx.kpac_config.pages.page.$page_id;
+    ctx.page_title = page.name %]
           
-<h2 class="sub_header2">Living Creatures</h2>
+<h2 class="sub_header2">[% page.name | html %]</h2>
 <div class="hr">&nbsp;</div>
 <div class="sub_cat_wrapper">
-    [% render_kpac_grid(ctx.kpac_config.pages.page.10); # TODO %]
+    [% render_kpac_grid(page_id) %]
 </div>
 
 <div class="sub_navigation1">
index f53ed0d..99325b6 100644 (file)
@@ -34,7 +34,7 @@
             </div>
             <div class="category_wrapper">
                 <h3 class="c_header_image">Or click on an image to get started:</h3>
-                [% render_kpac_grid(ctx.kpac_layout); %]
+                [% render_kpac_grid(ctx.kpac_layout.page) %]
             </div>
 
         </td>
index eb838d5..e3d122a 100644 (file)
     </head>
     <body>
         <div class="main_center">
-
-          <!-- TODO -->
-            <div class="main_header_wrapper">
-                <div class="logo_wrapper">
-                    <a href="javascript:;">
-                        <span class="logo_left">&nbsp;</span>
-                        <span class="logo_middle"><img src="[% ctx.media_prefix %]/images/kpac/kcls_logo.jpg" alt="kcls" /></span>
-                        <span class="logo_right">&nbsp;</span>
-                    </a>
-                </div>
-                <div class="header_utils">
-                    <a href="javascript:;" class="text_size_btn"><span>Text size</span> &nbsp; <img 
-                        alt="text size" src="[% ctx.media_prefix %]/images/kpac/text_size_btn.png" /></a>
-                    <a href="javascript:;" class="print_btn"><span>Print</span> &nbsp; <img 
-                        alt="print" src="[% ctx.media_prefix %]/images/kpac/print_btn.png" /></a>
-                </div>
-                <div class="header_menu">
-                    <!-- menu rendered in reverse order -->
-                    <a href="javascript:;">Login</a>
-                    <a href="javascript:;">Get a Library Card</a>
-                    <a href="javascript:;">Help</a>
-                </div>
-                <div class="clear">&nbsp;</div>
-            </div>
-
+            [% INCLUDE 'kpac/parts/header.tt2' %]
             <div class="main_wrapper"> [% content %] </div>
-
-            <!-- TODO -->
-            <div class="footer_wrapper">
-                <a href="javascript:;">Contact Us</a>
-                <a href="javascript:;">Site Help</a>
-                <a href="javascript:;">Site Map</a>
-                <a href="javascript:;">Back to Main KCLS Catalog</a>
-                <div class="clear">&nbsp;</div>
-            </div>
-
+            [% INCLUDE 'kpac/parts/footer.tt2' %]
         </div>
         <script type="text/javascript" src="js/functions.js"></script>
     </body>
diff --git a/Open-ILS/src/templates/kpac/parts/breadcrumb.tt2 b/Open-ILS/src/templates/kpac/parts/breadcrumb.tt2
new file mode 100644 (file)
index 0000000..4fa27cc
--- /dev/null
@@ -0,0 +1,38 @@
+<div class="breadcrumb">
+
+    <!-- home page -->
+    <a href="[% mkurl(ctx.kpac_root _ '/index', {}, ['trail']) %]" 
+        class="bread_home"><img alt="[% l('Home') %]" 
+        src="[% ctx.media_prefix %]/images/kpac/home_icon.png" /></a>
+
+    <!-- category trail -->
+    [%  trail = CGI.param('trail'); 
+        trail = trail ? trail.split('/') : [];
+        FOR page_id IN trail;
+            page = ctx.kpac_config.pages.page.$page_id %]
+            <div class="bread_green_mid">&nbsp;</div>
+            <a href="[% mkurl(ctx.kpac_root _ '/category', 
+                {trail = trail_splice(page_id)}) %]">[% page.name | html %]</a>
+    [%  END %]
+
+    [% IF ctx.page != 'index' AND ctx.page != 'category' %]
+
+        <!-- search results -->
+        <div class="bread_green_mid">&nbsp;</div>
+        <a href="[% mkurl(ctx.kpac_root _ '/search_results') %]">[% l('search results') | html %]</a>
+
+        [% IF ctx.page != 'rresult' %]
+
+            <!-- record title -->
+            <div class="bread_green_mid">&nbsp;</div>
+            <a href="javascript:;">book name</a>
+
+            <!-- Get it -->
+            <div class="bread_green_last">&nbsp;</div>
+            <span class="bread_last">[% l('Get it') %]</span>
+            <div class="clear">&nbsp;</div>
+
+        [% END %]
+    [% END %]
+</div>
+
diff --git a/Open-ILS/src/templates/kpac/parts/footer.tt2 b/Open-ILS/src/templates/kpac/parts/footer.tt2
new file mode 100644 (file)
index 0000000..b738aee
--- /dev/null
@@ -0,0 +1,8 @@
+<div class="footer_wrapper">
+    <a href="javascript:;">Contact Us</a>
+    <a href="javascript:;">Site Help</a>
+    <a href="javascript:;">Site Map</a>
+    <a href="javascript:;">Back to Main KCLS Catalog</a>
+    <div class="clear">&nbsp;</div>
+</div>
+
index fd3471a..3a2d204 100644 (file)
@@ -1,24 +1,15 @@
-
 [% 
-    # Use absolute and fully-qualified image URLs as-is.
-    # Otherwise, use the kpac base path.
-    MACRO kpac_img_path(img) BLOCK;
-        IF img.match('^/') OR img.match('^https?://');
-            img;
-        ELSE;
-            ctx.media_prefix _ '/images/kpac/' _ img;
-        END;
-    END;
-%]
-
-[%
-    MACRO render_kpac_grid(page) BLOCK;
-        ncols = page.columns;
-        name = page.name;
-        idx = 0 %]
+PROCESS 'kpac/parts/util.tt2';
+
+# Renders a single 'page' grid
+
+MACRO render_kpac_grid(page_id) BLOCK;
+    page = ctx.kpac_config.pages.page.$page_id;
+    ncols = page.columns || 3; # avoid divide-by-zero
+    name = page.name;
+    idx = 0 %]
 <table cellpadding="0" cellspacing="0" border="0" class="main_category_table">
-    <tr>
-    [% 
+    <tr> [% 
     width = 100 / ncols;
     FOR cell IN page.cell;
         IF idx == ncols; 
         idx = idx + 1;
 
         IF cell.type == 'topic';
-            page_id = cell.content;
-            topic_page = ctx.kpac_config.pages.page.$page_id %]
+            tpage_id = cell.content;
+            topic_page = ctx.kpac_config.pages.page.$tpage_id %]
 
-        <td width="[% width %]%"><a href="javascript:;"><img 
+        <td width="[% width %]%"><a href="[% mkurl(ctx.kpac_root _ '/category', {trail => trail_append(tpage_id)}) %]"><img 
             src="[% kpac_img_path(topic_page.img) %]" alt="" /><span>[% topic_page.name %]</span></a></td>
 
         [% ELSIF cell.type == 'search'; %]
 
-        <td width="[% width %]%"><a href="[% mkurl('search_results') %]"><img 
+        <td width="[% width %]%"><a href="[% mkurl(ctx.kpac_root _ '/search_results', {query => cell.content}) %]"><img 
             src="[% kpac_img_path(cell.img) %]" alt="" /><span>[% cell.name %]</span></a></td>
 
         [% ELSIF cell.type == 'link'; %]
 
-        <td width="[% width %]%"><a href="[% mkurl(cell.content) %]"><img 
+        <td width="[% width %]%"><a href="[% cell.content | html %]"><img 
             src="[% kpac_img_path(cell.img) %]" alt="" /><span>[% cell.name %]</span></a></td>
 
         [% END %]
diff --git a/Open-ILS/src/templates/kpac/parts/header.tt2 b/Open-ILS/src/templates/kpac/parts/header.tt2
new file mode 100644 (file)
index 0000000..7275684
--- /dev/null
@@ -0,0 +1,23 @@
+<div class="main_header_wrapper">
+    <div class="logo_wrapper">
+        <a href="javascript:;">
+            <span class="logo_left">&nbsp;</span>
+            <span class="logo_middle"><img src="[% ctx.media_prefix %]/images/kpac/kcls_logo.jpg" alt="kcls" /></span>
+            <span class="logo_right">&nbsp;</span>
+        </a>
+    </div>
+    <div class="header_utils">
+        <a href="javascript:;" class="text_size_btn"><span>Text size</span> &nbsp; <img 
+            alt="text size" src="[% ctx.media_prefix %]/images/kpac/text_size_btn.png" /></a>
+        <a href="javascript:;" class="print_btn"><span>Print</span> &nbsp; <img 
+            alt="print" src="[% ctx.media_prefix %]/images/kpac/print_btn.png" /></a>
+    </div>
+    <div class="header_menu">
+        <!-- menu rendered in reverse order -->
+        <a href="javascript:;">Login</a>
+        <a href="javascript:;">Get a Library Card</a>
+        <a href="javascript:;">Help</a>
+    </div>
+    <div class="clear">&nbsp;</div>
+</div>
+
diff --git a/Open-ILS/src/templates/kpac/parts/paginate.tt2 b/Open-ILS/src/templates/kpac/parts/paginate.tt2
new file mode 100644 (file)
index 0000000..c87c9fa
--- /dev/null
@@ -0,0 +1,50 @@
+[%  # paging, weeee
+    page = CGI.param('page');
+    page = page.match('^\d+$') ? page : 0; # verify page is a sane value
+    page_count = ctx.page_size == 0 ? 1 : POSIX.ceil(ctx.hit_count / ctx.page_size);
+    ctx.result_start = 1 + ctx.page_size * page;
+    ctx.result_stop = ctx.page_size * (page + 1);
+    IF ctx.result_stop > ctx.hit_count; ctx.result_stop = ctx.hit_count; END;
+    result_count = ctx.result_start;
+%]
+
+<table cellpadding="0" cellspacing="0" border="0" width="100%">
+    <tr>
+        <!-- Next -->
+        <td>
+            [%  class = '';
+                href = '#';
+                IF page > 0;
+                    href = mkurl('', {page => page - 1});
+                ELSE; class = class _ ' invisible'; END %]
+            <a class="[% class %]" href="[% href %]"><img src="[% ctx.media_prefix %]/images/kpac/arrow_last.png" /></a>
+        </td>
+
+        <!-- page X of Y -->
+        <td width="100%" class="nav_mid_bg">
+            <table cellpadding="0" cellspacing="0" border="0" align="center">
+                <tr>
+                    [% |l(page + 1, page_count) %]
+                    <td>Page </td><td class="current_page">[_1]</td><td> of </td><td class="total_pages">[_2]</td>
+                    [% END %]
+                </tr>
+            </table>
+        </td>
+
+        <!-- Prev -->
+        <td class="to_top_btn">
+            [%  class = '';
+                href = '#';
+                IF (page + 1) < page_count;
+                    href = mkurl('', {page => page + 1});
+                ELSE; class = class _ ' invisible'; END;
+            %]
+            <a class="[% class %]" href="[% href %]"><img src="[% ctx.media_prefix %]/images/kpac/arrow_next.png" /></a>
+        </td>
+
+        <!-- Top of page -->
+        [% IF showtop; href = mmkurl('').replace('#.*', '') %]
+        <td class="to_top_btn"><a href="[% href %]"><img src="[% ctx.media_prefix %]/images/kpac/to_top_btn.png" /></a></td>
+        [% END %]
+    </tr>
+</table>
old mode 100755 (executable)
new mode 100644 (file)
index 0a40a99..785f2d8
@@ -1,20 +1,12 @@
-[% WRAPPER "kpac/parts/base.tt2" %]
+[% PROCESS 'kpac/parts/util.tt2'; WRAPPER "kpac/parts/base.tt2" %]
+
+<!--
+subpage is the main wrapper page for everything except 'index'
+-->
 
 <div class="main_top_shadow_sub">
     <div class="main_mid_top_sub">
-        [%# TODO BREADCRUMBS %]
-        <div class="breadcrumb">
-            <a class="bread_home"><img alt="home" src="[% ctx.media_prefix %]/images/kpac/home_icon.png" /></a>
-            <div class="bread_green_mid">&nbsp;</div>
-            <a href="javascript:;">Animals, insects, &amp; birds</a>
-            <div class="bread_green_mid">&nbsp;</div>
-            <a href="javascript:;">search results</a>
-            <div class="bread_green_mid">&nbsp;</div>
-            <a href="javascript:;">book name</a>
-            <div class="bread_green_last">&nbsp;</div>
-            <span class="bread_last">got it</span>
-            <div class="clear">&nbsp;</div>
-        </div>
+        [% INCLUDE 'kpac/parts/breadcrumb.tt2' %]
     </div>
 </div>
 <table cellpadding="0" cellspacing="0" border="0" width="100%">
diff --git a/Open-ILS/src/templates/kpac/parts/util.tt2 b/Open-ILS/src/templates/kpac/parts/util.tt2
new file mode 100644 (file)
index 0000000..632c180
--- /dev/null
@@ -0,0 +1,44 @@
+[% 
+
+    # -----------------------------------------------------------------
+    # Category trail/path utilities
+    # page trail looks like trail=id/id/id
+
+    # adds an ID, esults in the full trail as a string
+    MACRO trail_append(node_id) BLOCK;
+        trail = CGI.param('trail');
+        trail ? trail _ '/' _ node_id : node_id;
+    END;
+
+    # last trail component/id as a string
+    MACRO trail_endpoint BLOCK;
+        trail = CGI.param('trail');
+        list = trail ? trail.split('/') : [];
+        list().last;
+    END;
+
+    MACRO trail_splice(page_id) BLOCK;
+        trail = CGI.param('trail');
+        list = trail ? trail.split('/') : [];
+        path = '';
+        FOR id IN list;
+            path = path ? path _ '/' _ id : id;
+            IF id == page_id; LAST; END;
+        END;
+        path;
+    END;
+
+    # -----------------------------------------------------------------
+    # Determines the full path to image URLs
+    # Use absolute and fully-qualified image URLs as-is.
+    # For all others, use the kpac base path.
+    MACRO kpac_img_path(img) BLOCK;
+        IF img.match('^/') OR img.match('^https?://');
+            img;
+        ELSE;
+            ctx.media_prefix _ '/images/kpac/' _ img;
+        END;
+    END;
+%]
+
+
index e241606..f059dc9 100644 (file)
@@ -2,33 +2,12 @@
     PROCESS "opac/parts/misc_util.tt2"; # MARC 
     PROCESS "kpac/parts/grid.tt2";
     WRAPPER "kpac/parts/subpage.tt2";
-
-    ctx.page_title = l('Search Results') 
-    ctx.result_start = 1 + ctx.page_size * page;
-    ctx.result_stop = ctx.page_size * (page + 1);
-    IF ctx.result_stop > ctx.hit_count; ctx.result_stop = ctx.hit_count; END;
-    result_count = ctx.result_start;
-%]
+    ctx.page_title = l('Search Results') %]
         
 <h2 class="sub_header2">Search Results</h2>
 
 <div class="sub_navigation2">
-    <table cellpadding="0" cellspacing="0" border="0" width="100%">
-        <tr>
-            <td><a href="javascript:;"><img src="[% ctx.media_prefix %]/images/kpac/arrow_last.png" /></a></td>
-            <td width="100%" class="nav_mid_bg">
-                <table cellpadding="0" cellspacing="0" border="0" align="center">
-                    <tr>
-                        <td>Page </td>
-                        <td class="current_page">3</td>
-                        <td> of </td>
-                        <td class="total_pages">12</td>
-                    </tr>
-                </table>
-            </td>
-            <td class="to_top_btn"><a href="javascript:;"><img src="[% ctx.media_prefix %]/images/kpac/arrow_next.png" /></a></td>
-        </tr>
-    </table>
+    [% INCLUDE 'kpac/parts/paginate.tt2' %]
 </div>
 
 <div id="search_results_parent">
             <div class="item_detail_name"><a href="[% mkurl('detailed/' _ rec.id) %]">[% attrs.title %]</a></div>
             <div class="item_detail_author">[% l('by [_1]', attrs.author) %]</div>
             <div class="item_detail_callnumber">[% attrs.holdings.0.label | html %]</div>
-            <div class="item_detail_extra_info">[% l('[_1], [_2]', attrs.publisher, attrs.pubdate) | html %] <!-- TODO fix and add Size --></div>
+            <div class="item_detail_extra_info">
+                [% l('[_1], [_2]', attrs.publisher, attrs.pubdate) | html %] <!-- TODO fix commas, etc. -->
+                [% IF attrs.phys_desc %]<br/>[% attrs.phys_desc | html; END %]
+            </div>
             <div class="item_detail_actions">
-                <div class="button"><a href="javascript:;"><img src="[% ctx.media_prefix %]/images/kpac/more_info_btn.png" alt="more info" /></a></div>
-                <div class="button"><a href="javascript:;"><img src="[% ctx.media_prefix %]/images/kpac/get_it_btn_sm.png" alt="get it" /></a></div>
+                <div class="button"><a href="[% mkurl(ctx.kpac_root _ '/detailed/' _ rec.id) %]"><img 
+                    src="[% ctx.media_prefix %]/images/kpac/more_info_btn.png" alt="more info" /></a></div>
+                <div class="button"><a href="javascript:;"><img 
+                    src="[% ctx.media_prefix %]/images/kpac/get_it_btn_sm.png" alt="get it" /></a></div>
                 <div class="clear">&nbsp;</div>
             </div>
         </div>
 </div>
 
 <div class="sub_navigation3">
-    <table cellpadding="0" cellspacing="0" border="0" width="100%">
-        <tr>
-            <td><a href="javascript:;"><img src="[% ctx.media_prefix %]/images/kpac/arrow_last.png" /></a></td>
-            <td width="100%" class="nav_mid_bg">
-                <table cellpadding="0" cellspacing="0" border="0" align="center">
-                    <tr>
-                        <td>Page </td>
-                        <td class="current_page">3</td>
-                        <td> of </td><td class="total_pages">12</td>
-                    </tr>
-                </table>
-            </td>
-            <td><a href="javascript:;"><img src="[% ctx.media_prefix %]/images/kpac/arrow_next.png" /></a></td>
-            <td class="to_top_btn"><a href="javascript:;"><img src="[% ctx.media_prefix %]/images/kpac/to_top_btn.png" /></a></td>
-        </tr>
-    </table>
+    [% INCLUDE 'kpac/parts/paginate.tt2' showtop=1 %]
 </div>
 
 [% END %]
index 451e0ff..ba050ce 100755 (executable)
@@ -1015,7 +1015,9 @@ div.hr {
        background:url('/images/kpac/popup_br.png') no-repeat;\r
 }\r
 \r
-\r
+.invisible {\r
+    visibility : hidden;\r
+}\r
 \r
 \r
 \r