adminview-channels.js 3.65 KB
/*
 *
 * ADOBE CONFIDENTIAL
 * __________________
 *
 *  Copyright 2014 Adobe Systems Incorporated
 *  All Rights Reserved.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Adobe Systems Incorporated and its suppliers,
 * if any.  The intellectual and technical concepts contained
 * herein are proprietary to Adobe Systems Incorporated and its
 * suppliers and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Adobe Systems Incorporated.
 */

define('screens/player/ui/adminview-channels', [
    'underscore',
    'jquery',
    './baseview',
    './adminview-channel',
    'screens/player/shared/serviceadmin',
    'screens/player/store/store',
    'screens/player/firmware/core/config/config'
], function(_, $, BaseView, ChannelView, ServiceAdmin, Store, Config) {
    'use strict';

    var DEFAULT_OPTIONS = {
    };

    var ChannelsAdminView = BaseView.extend(/** @lends ChannelsAdminView.prototype */{

        template: function() {
            return '<h1>Channels</h1>' +
                '<table class="aem-ScreensPlayer-admin-channelsview-channels">' +
                '<tr>' +
                '<th>Title</th>' +
                '<th>Role</th>' +
                '<th>Online</th>' +
                '<th>Cached</th>' +
                '</tr>' +
                '</table>';
        },

        className: 'aem-ScreensPlayer-admin-view',

        events: {
        },

        /**
         * @classdesc View that renders the admin menu
         * @class AdminView
         * @extends BaseView
         *
         * @param {Object} [options] An object of configurable options.
         */
        constructor: function(options) {
            this._initOptions(options, DEFAULT_OPTIONS);
            ChannelsAdminView.__super__.constructor.apply(this, arguments);

            this.$el.on('show', this.onShow.bind(this));
            this.$el.on('hide', this.onHide.bind(this));

            ServiceAdmin.onServiceHighestRankedStart(Store.serviceName, function(store) {
                store.requestState();
            });

            $('body').append(this.render().$el);
        },

        /**
         * Event handler for when this view's contents are hidden
         */
        onHide: function() {
            var store = ServiceAdmin.getService(Store.serviceName);
            if (this._channelsConfigChangeListener) {
                store.unsubscribe(this._channelsConfigChangeListener);
                this._channelsConfigChangeListener = null;
            }
        },

        /**
         * Event handler for when this view's contents are shown
         */
        onShow: function() {
            var store = ServiceAdmin.getService(Store.serviceName);
            if (this._channelsConfigChangeListener) {
                store.unsubscribe(this._channelsConfigChangeListener);
            }

            this._channelsConfigChangeListener = store.subscribe(this.render.bind(this), Config.NAMESPACES.CHANNELS);
            this.render(store.getState()[Config.NAMESPACES.CHANNELS]);
        },

        render: function(channels) {
            this.$el.html(this.template());
            var $channels = this.$el.find('.aem-ScreensPlayer-admin-channelsview-channels');

            if (channels) {
                _.each(channels._list, function(channel) {
                    var channelView = new ChannelView();
                    $channels.append(channelView.render(channel).el);
                }, this);
            }

            return this;
        }

    });

    // return module exports
    return ChannelsAdminView;
});