Source: models/uibuilder/filteredResult.js

define('application/models/uibuilder/filteredResult', [
    'rofl/models/api/abstract',
    'application/managers/api',
    'application/models/broadcast',
    'application/components/uibuilder',
    'rofl/lib/utils'
], function (
    Class,
    ApiManager,
    Broadcast,
    UIBuilder,
    Utils
) {
    'use strict';

    var api = ApiManager.getKPNAPI();

    return Class.extend({

        /**
         * Initialises the Hero model.
         *
         * @param {Object} data - The API data.
         */
        init: function (data) {
            this.setData(data);
        },

        /**
         * Sets model data options.
         *
         * @param {Object} data - The API data.
         */
        setData: function (data) {
            this._title = data.title;
            this._apiEndpoint = '101/1.2.0/A/nld/smarttv/kpn' + data.uri;
        },

        /**
         * Returns the type of widget this model to be used with.
         *
         * @returns {string} - The type of widget.
         */
        getWidgetType: function () {
            return UIBuilder.WIDGET_TYPES.FILTERED_RESULT;
        },

        /**
         * Returns the title.
         *
         * @returns {string} - The title.
         */
        getTitle: function () {
            return this._title;
        },

        /**
         * Returns the api endpoint.
         *
         * @returns {string} - The api endpoint.
         */
        resolveEndpoint: function () {
            return this._apiEndpoint;
        },

        /**
         * Prepares the widget and loads all required data.
         *
         * @returns {Promise} - Promise resolving with the carousel model.
         */
        prepare: function () {
            return api.read(this, {
                    withCredentials: true
                })
                .then(Utils.bind(function (response) {
                    var items = [],
                        containers = response.resultObj.containers;

                    Utils.each(containers, function (container) {
                        items.push(new Broadcast(container));
                    });

                    this._totalCount = Utils.getNested(response, 'resultObj', 'total');
                    this._items = items;

                    return this;
                }, this));
        },

        /**
         * Returns the item.
         *
         * @returns {Object} - The actual hero item.
         */
        getItem: function () {
            return this._item;
        }
    });
});