Golem.de API

Golem  alpha

Golem.de API > Golem > Images.js (source view)
Search:
 
Filters
/*
Copyright (c) 2009, Klass und Ihlenfeld Verlag GmbH
All rights reserved.

Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, 
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright 
      notice, this list of conditions and the following disclaimer in the 
      documentation and/or other materials provided with the distribution.
    * Neither the name of the Klass und Ihlenfeld Verlag GmbH nor the names of its
      contributors may be used to endorse or promote products derived from 
      this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE

$Id$
*/

if(!Golem.Api.Article) {

    Golem.Api.Article = {};

}

/**
 * Get a list of images associated with an article
 *
 * @class Images
 * @namespace Golem.Api.Article
 * @extends Golem.Api
 * @constructor
 *
 * @param {Integer} idArticle the identifier of the article
 */
Golem.Api.Article.Images = function(idArticle) {

    if(idArticle) {

        this.idArticle = idArticle;

    }

}

/**
 * The URL of the used web service
 *
 * @property URL
 * @type {String}
 * @protected
 */
Golem.Api.Article.Images.URL  = 'http://api.golem.de/api/article/images/';

/**
 * The type of access method for the web service
 *
 * @property TYPE
 * @type {String}
 * @protected
 */
Golem.Api.Article.Images.TYPE = 'GET';

Golem.Api.Article.Images.prototype = {

    /**
     * Identifier of the article the images to fetch for
     *
     * @property idArticle
     * @type {Integer}
     * @protected
     */
    idArticle : null,

    /**
     * Shortcut method for traversing the article data
     *
     * <p>
     * Fetches the articles via <i>fetch()</i> first
     * and then calls <i>fnCallback</i> for every
     * article record like <i>each()</i> does.
     * </p>
     * <p>
     * There is no way to handle errors with this method!
     * </p>
     *
     * @method fetchEach
     *
     * @param {Function} fnCallback - Function to call for every article record
     * @param {Mixed} params - additional data to pass to the callback function
     */
    fetchEach : function(fnCallback, params) {

        var oSelf = this;

        this.fetch(
            {

                fnSuccess : function() {

                    if(fnCallback) {

                        oSelf.each(fnCallback, params);

                    }

                }

            }

        );

    },

    /**
     * Fetches the list of images for an article via Webservice
     *
     * <p>
     * In case of a successful request, the <i>obj.fnSuccess</i>-callback function
     * will be called. The first argument for the callback method is the result
     * data of the request. The second argument will be the data provided by <i>obj.params</i>.
     * </p>
     * <p>
     * In case of a failed request, the <i>obj.fnError</i> callback function
     * will be called. The first argument to the callback is the error code,
     * the second ist the error message.
     * </p>
     *
     * @method fetch
     *
     * @param {Object} obj - Object literal specifing the callback methods
     */
    fetch : function(obj) {

        var oSelf = this;

        Golem.Request.doRequest(Golem.Api.Article.Images.URL+this.idArticle+'/',
            '',
            function(result) {
                oSelf.data = result.data;

                if(obj.fnSuccess) {

                    var p = undefined;

                    if(obj.params) {

                        p = obj.params;

                    }

                    obj.fnSuccess.call(oSelf, result, p);

                }

            },
            function(errCode, errMsg) {

                oSelf.errorMessage = errMsg;
                oSelf.errorCode    = errCode;

                if(obj.fnError) {

                    var p = undefined;

                    if(obj.params) {

                        p = obj.params;

                    }

                    obj.fnError.call(oSelf, p);

                }
            }, this.timeout
        );

    },

    /**
     * Traverses through the image list.
     *
     * <p>
     * After a succesful request you can traverse
     * through the image list. You pass a callback
     * function to the method, and the method is
     * called for each image entry
     * </p>
     * <p>
     * The first argument to this callback function is
     * an <i>image</i> object with the properties:
     * <ul>
     * <li><i>imageid</i> - {Integer} - The image identifier. The identifier should be not expected to be unique!</li>
     * <li><i>subtext</i> - {String} - A text associated with the image.</li>
     * <li><i>small</i> - {Array} - The data for the image as thumbnail. The typical size of an thumbnail is 120x90 pixel.
     *    <ul>
     *      <li><i>url</i> - {String} - The image url</li>
     *      <li><i>width</i> - {Integer} - The image width in pixel </li>
     *      <li><i>height</i> - {Integer} - The image height in pixel </li>
     *    </ul>
     * </li>
     * <li><i>medium</i> - {Array} - The data for the image in a medium size. The maximum width of a medium size image is 480 pixel. The height may differ.
     *    <ul>
     *      <li><i>url</i> - {String} - The image url</li>
     *      <li><i>width</i> - {Integer} - The image width in pixel </li>
     *      <li><i>height</i> - {Integer} - The image height in pixel </li>
     *    </ul>
     * </li>
     * <li><i>native</i> - {Array} - The data for the image. The size of the image is not limited, but a size of 1024x786 is exceeded in rare situations only.
     *    <ul>
     *      <li><i>url</i> - {String} - The image url</li>
     *      <li><i>width</i> - {Integer} - The image width in pixel </li>
     *      <li><i>height</i> - {Integer} - The image height in pixel </li>
     *    </ul>
     * </li>

     * </ul>
     * The second argument will be the data provided by <i>params</i>.
     * </p>
     *
     * @method each
     *
     * @param {Function} fnCallback - the callback function to call for each article
     * @param {Mixed} params - additional data passed to the callback function
     */
    each : function(fnCallback, params) {

        for(var i = 0; i < this.data.length; i++) {

            if(fnCallback) {

                var r = this.data[i];

                fnCallback.call(this, r,
                      params
                );

            }

        }

    }

}

Golem.Api.Article.Images.prototype.data    = Golem.Api.prototype.data;
Golem.Api.Article.Images.prototype.getData = Golem.Api.prototype.getData;

Golem.Api.Article.Images.prototype.errorMessage    = Golem.Api.prototype.errorMessage;
Golem.Api.Article.Images.prototype.errorCode       = Golem.Api.prototype.errorCode;
Golem.Api.Article.Images.prototype.getErrorMessage = Golem.Api.prototype.getErrorMessage;
Golem.Api.Article.Images.prototype.getErrorCode    = Golem.Api.prototype.getErrorCode;

Golem.Api.Article.Images.prototype.useTimeout = Golem.Api.prototype.useTimeout;
Golem.Api.Article.Images.prototype.timeout    = Golem.Api.prototype.timeout;

/**
 * Indicates, that the article identifier is invalid or article does not exists
 *
 * @property ERROR_INVALID_IDENTIFIER
 * @type {Integer}
 */
Golem.Api.Article.Images.ERROR_INVALID_IDENTIFIER = 10;

Copyright © 2010 Golem.de.