more work towards mobile ansel view:
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 30 Dec 2010 02:42:31 +0000 (21:42 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 30 Dec 2010 19:40:29 +0000 (14:40 -0500)
implement ajax method for obtaining a gallery, start building up
click handler, use SquareThumbs

ansel/js/mobile.js
ansel/lib/Ajax/Application.php
ansel/lib/Gallery.php
ansel/lib/ImageGenerator/Mini.php
ansel/lib/ImageGenerator/SquareThumb.php
ansel/templates/mobile/javascript_defs.php

index c0f2467..9268c40 100644 (file)
@@ -21,10 +21,9 @@ var AnselMobile = {
         var list = $('<ul>')
             .addClass('anselGalleryList')
             .attr({ 'data-role': 'listview' }), item;
-
         $('#anselgallerylist ul').detach();
         $.each(galleries, function(k, g) {
-            var item = $('<li>');
+            var item = $('<li>').attr({ 'class': 'ansel-gallery', 'ansel-gallery-id': g.id });
             item.append($('<img>').attr({ src: g.ki }));
             item.append($('<h3>').append($('<a>').attr({ href: '#' }).text(g.n)));
             item.append($('<p>').text(g.d));
@@ -35,12 +34,38 @@ var AnselMobile = {
     },
 
     /**
+     * Load the specified gallery
+     */
+    toGallery: function(id)
+    {
+        HordeMobile.doAction('getGallery', { id: id }, AnselMobile.galleryLoaded);
+    },
+
+    /**
+     * Callback for after a gallery is loaded.
+     */
+    galleryLoaded: function(r)
+    {
+        console.log(r);
+    },
+    
+    /**
      * Global click handler
      *
      */
     clickHandler: function(e)
     {
+        var elt = $(e.target), id;
+
+        while (elt && elt != window.document && elt.parent().length) {
 
+            // Navigate to a gallery
+            if (elt.hasClass('ansel-gallery')) {
+                alert(elt.attr('ansel-gallery-id'));
+                AnselMobile.toGallery(elt.attr('ansel-gallery-id'));
+            }
+            elt = elt.parent();
+        }
     },
 
     /**
index 2d35f29..c073055 100644 (file)
@@ -19,6 +19,33 @@ class Ansel_Ajax_Application extends Horde_Core_Ajax_Application
      */
     public $notify = true;
 
-
+    /**
+     * Obtain a gallery
+     *
+     * @return mixed  False on failure, object representing the gallery with
+     *                the following structure:
+     * <pre>
+     * '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 getGallery()
+    {
+        $id = $this->_vars->id;
+        return $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($id)->toJson(true);
+    }
     
 }
index a69587f..51c3ed3 100644 (file)
@@ -994,4 +994,43 @@ class Ansel_Gallery extends Horde_Share_Object_Sql_Hierarchical implements Seria
         parent::unserialize($data);
         $this->_setModeHelper($this->get('view_mode'));
     }
+
+    /**
+     * Returns a json representation of this gallery.
+     *
+     * @param boolean $full  Return all information (subgalleries and images)?
+     *
+     * @return StdClass  An object describing the gallery
+     */
+    public function toJson($full = false)
+    {
+        $json = new StdClass();
+        $json->id = $this->getId();
+        $json->n = $this->get('name');
+        $json->dc = $this->get('date_created');
+        $json->dm = $this->get('date_modified');
+        $json->d = $this->get('desc');
+        $json->ki = Ansel::getImageUrl($this->getKeyImage(), 'mini', false, 'ansel_default')->toString();
+
+        if ($full) {
+            $json->sg = array();
+            if ($this->hasSubGalleries()) {
+                $sgs = $GLOBALS['injector']->getInstance('Ansel_Storage')->listGalleries(array('parent' => $this->getId(), 'all_levels' => false));
+                foreach ($sgs as $g) {
+                    $json->sg[] = $g->toJson();
+                }
+            }
+
+            $images = $this->listImages();
+            foreach ($images as $img) {
+                $i = new StdClass();
+                $i->id = $img;
+                $i->url = Ansel::getImageUrl($img, 'mini', false, Ansel::getStyleDefinition('ansel_mobile'))->toString();
+                $json->imgs[] = $i;
+            }
+        }
+
+        return $json;
+    }
+
 }
index 6c8ca1c..2dd0b70 100755 (executable)
@@ -13,22 +13,10 @@ class Ansel_ImageGenerator_Mini extends Ansel_ImageGenerator
      */
     protected function _create()
     {
-        $this->_image->resize(min(50, $this->_dimensions['width']),
-                                      min(50, $this->_dimensions['height']),
-                                      true);
-        if ($GLOBALS['conf']['thumbnail']['unsharp'] && Ansel::isAvailable('Unsharpmask')) {
-            try {
-                $this->_image->addEffect('Unsharpmask',
-                                         array('radius' => $GLOBALS['conf']['thumbnail']['radius'],
-                                               'threshold' => $GLOBALS['conf']['thumbnail']['threshold'],
-                                               'amount' => $GLOBALS['conf']['thumbnail']['amount']));
-                $this->_image->applyEffects();
-            } catch (Horde_Image_Exception $e) {
-                throw new Ansel_Exception($e);
-            }
-        }
-
-        return $this->_image->getHordeImage();
+        $generator = Ansel_ImageGenerator::factory('SquareThumb', array('width' => min(50, $this->_dimensions['width']),
+                                                                        'height' => min(50, $this->_dimensions['height']),
+                                                                        'image' => $this->_image));
+        return $generator->create();
     }
 
 }
index 9b961ca..37a82a0 100644 (file)
@@ -25,10 +25,10 @@ class Ansel_ImageGenerator_SquareThumb extends Ansel_ImageGenerator
     protected function _create()
     {
         // Take the largest requested dimension
-        if (empty($this->_dimensions['width'])) {
-            $size = max($GLOBALS['conf']['thumbnail']['height'], $GLOBALS['conf']['thumbnail']['width']);
+        if (empty($this->_params['width'])) {
+            $size = min($GLOBALS['conf']['thumbnail']['height'], $GLOBALS['conf']['thumbnail']['width']);
         } else {
-            $size = max($this->_dimensions['width'], $this->_dimensions['height']);
+            $size = min($this->_params['width'], $this->_params['height']);
         }
 
         // Use smartcrop algorithm if we have it, otherwise a plain center crop.
index 89de663..6aba72a 100644 (file)
@@ -21,13 +21,7 @@ $gallerylist = $GLOBALS['injector']->getInstance('Ansel_Storage')->listGalleries
 $galleries = array();
 
 foreach ($gallerylist as $gallery) {
-    $galleries[$gallery->id] = array(
-        'n' => $gallery->get('name'),
-        'dc' => $gallery->get('date_created'),
-        'dm' => $gallery->get('date_modified'),
-        'd' => $gallery->get('desc'),
-        'ki' => Ansel::getImageUrl($gallery->getKeyImage(), 'prettythumb', false, 'ansel_mobile')->toString()
-    );
+    $galleries[] = $gallery->toJson();
 }
 $code['conf']['galleries'] = $galleries;