Add back navigation for subgalleries.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 3 Jan 2011 18:24:00 +0000 (13:24 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 3 Jan 2011 18:25:05 +0000 (13:25 -0500)
Now we correctly go back to the gallery's parent, if applicable,
otherwise to the gallerylist

ansel/js/mobile.js
ansel/lib/Ajax/Application.php
ansel/lib/Gallery.php
ansel/templates/mobile/gallery.html.php

index 6e55f5a..c5803b6 100644 (file)
  */
 var AnselMobile = {
 
+    /**
+     * The currently displayed gallery
+     *
+     * @var object
+     */
     currentGallery: null,
 
     /**
@@ -65,14 +70,14 @@ var AnselMobile = {
     {
         // TODO: error checks, build any subgallery lists etc...
         if ($.mobile.currentPage != 'galleryview' &&
-            AnselMobile.currentGallery && (r.id == AnselMobile.currentGallery)) {
+            AnselMobile.currentGallery && (r.id == AnselMobile.currentGallery.id)) {
 
             $.mobile.changePage('galleryview', 'slide', false, true);
             return;
         }
 
         //AnselMobile.imgs = r.imgs;
-        AnselMobile.currentGallery = r.id;
+        AnselMobile.currentGallery = r;
         if (r.sg.length) {
             var l = $('<ul>').addClass('anselgalleries').attr({ 'data-role': 'listview', 'data-inset': 'true' });
             $('#thumbs').before(AnselMobile.buildGalleryList(l, r.sg).listview());
@@ -88,6 +93,13 @@ var AnselMobile = {
             var img = $('<li>').addClass('anselthumb').append($('<a>').attr({ 'href': '#' }).append($('<img>').attr({ src: i.url })));
             $('#thumbs').append(img);
         });
+        if (r.p) {
+            $('#gallerybackbutton .ui-btn-text').text(r.pn);
+            $('#gallerybackbutton').attr({ 'action': 'gallery', 'gallery-id': r.p });
+        } else {
+            $('#gallerybackbutton .ui-btn-text').text($.mobile.page.prototype.options.backBtnText);
+            $('#gallerybackbutton').attr({ 'action': 'home' });
+        }
         AnselMobile.centerGrid();
     },
 
@@ -127,6 +139,15 @@ var AnselMobile = {
             if (elt.hasClass('ansel-gallery')) {
                 AnselMobile.toGallery(elt.attr('ansel-gallery-id'));
             }
+            if (elt.attr('id') == 'gallerybackbutton') {
+                switch (elt.attr('action')) {
+                case 'home':
+                    $.mobile.changePage('gallerylist', 'slide', true, true);
+                    break;
+                case 'gallery':
+                    AnselMobile.toGallery(elt.attr('gallery-id'));
+                }
+            }
             elt = elt.parent();
         }
     },
index a47199d..5deb7ee 100644 (file)
@@ -24,24 +24,7 @@ class Ansel_Ajax_Application extends Horde_Core_Ajax_Application
      *
      * @return mixed  False on failure, object representing the gallery with
      *                the following structure:
-     * <pre>
-     * 'id' - gallery id
-     * 'n'  - gallery name
-     * 'dc' - date created
-     * 'dm' - date modified
-     * 'd'  - description
-     * 'ki' - key image
-     * 'sg' - an object with the following properties:
-     *      'n'  - gallery name
-     *      'dc' - date created
-     *      'dm' - date modified
-     *      'd'  - description
-     *      'ki' - key image
-     *
-     *  'imgs' - an array of image objects with the following properties:
-     *      'id'  - the image id
-     *      'url' - the image url
-     * </pre>
+     * @see Ansel_Gallery::toJson()
      */
     public function getGallery()
     {
index 37ce737..a28ff89 100644 (file)
@@ -988,6 +988,26 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical implements Seria
      * @param boolean $full  Return all information (subgalleries and images)?
      *
      * @return StdClass  An object describing the gallery
+     * <pre>
+     * 'id' - gallery id
+     * 'p'  - gallery's parent's id (null if top level)
+     * 'pn' - gallery's parent's name (null if top level)
+     * 'n'  - gallery name
+     * 'dc' - date created
+     * 'dm' - date modified
+     * 'd'  - description
+     * 'ki' - key image
+     * 'sg' - an object with the following properties:
+     *      'n'  - gallery name
+     *      'dc' - date created
+     *      'dm' - date modified
+     *      'd'  - description
+     *      'ki' - key image
+     *
+     *  'imgs' - an array of image objects with the following properties:
+     *      'id'  - the image id
+     *      'url' - the image url
+     * </pre>
      */
     public function toJson($full = false)
     {
@@ -1003,9 +1023,11 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical implements Seria
         $parents = $this->get('parents');
         if (empty($parents)) {
             $json->p = null;
+            $json->pn - null;
         } else {
             $parents = explode(':', $parents);
             $json->p = array_pop($parents);
+            $json->pn = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($json->p)->get('name');
         }
 
         if ($full) {
index 9097e9a..bfa434e 100644 (file)
@@ -1,5 +1,6 @@
 <div data-role="page" data-theme="h" id="galleryview">
   <div data-role="header">
+    <a data-role="button" data-icon="arrow-l" href="#" id="gallerybackbutton"></a>
     <h1></h1>
   </div>
   <div id="anselgalleryview">