Golem.de API

Golem  alpha

Golem.de API > Golem > List.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
*/

if(!Golem.Api.Theme) {

    Golem.Api.Theme = {};

}

/**
 * Get a list of theme categories via Golem web interface
 *
 * @class List
 * @namespace Golem.Api.Theme
 * @extends Golem.Api
 * @constructor
 */
Golem.Api.Theme.List = function() {

}

/**
 * The URL of the used web service
 *
 * @property URL
 * @type {String}
 * @protected
 */
Golem.Api.Theme.List.URL  = 'http://api.golem.de/api/theme/list/';

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

Golem.Api.Theme.List.prototype = {

    /**
     * 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 theme categories via web service
     *
     * <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.Theme.List.URL,
            '',
            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 list of theme categories.
     *
     * <p>
     * After a succesful request you can traverse
     * through the article list. You pass a callback
     * function to the method, and the method is
     * called for each article
     * </p>
     * <p>
     * The first argument to this callback function is
     * a <i>theme</i> object with the properties:
     * <ul>
     * <li><i>name</i> - {Integer} - The theme category name</li>
     * <li><i>headline</i> - {String(60)} - The short theme category name, also used as identifier</li>
     * <li><i>url</i> - {String} - The URL to the theme category homepage</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, {
                      name      : r.name,
                      shortname : r.shortname,
                      url       : r.url,
                      },
                      params
                );

            }

        }

    }

}

Golem.Api.Theme.List.prototype.data    = Golem.Api.prototype.data;
Golem.Api.Theme.List.prototype.getData = Golem.Api.prototype.getData;

Golem.Api.Theme.List.prototype.errorMessage    = Golem.Api.prototype.errorMessage;
Golem.Api.Theme.List.prototype.errorCode       = Golem.Api.prototype.errorCode;
Golem.Api.Theme.List.prototype.getErrorMessage = Golem.Api.prototype.getErrorMessage;
Golem.Api.Theme.List.prototype.getErrorCode    = Golem.Api.prototype.getErrorCode;

Golem.Api.Theme.List.prototype.useTimeout = Golem.Api.prototype.useTimeout;
Golem.Api.Theme.List.prototype.timeout    = Golem.Api.prototype.timeout;

Copyright © 2010 Golem.de.