adminview-registration.js 5.58 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-registration', [
    'underscore',
    'jquery',
    'screens/player/shared/serviceadmin',
    'screens/player/store/store',
    'screens/player/firmware/core/statusmodel/statusmodel',
    'backbone',
    './baseview'
], function(_, $, ServiceAdmin, Store, StatusModel, Backbone, BaseView) {
    'use strict';

    var DEFAULT_OPTIONS = {
    };

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

        template: function(statusmodel) {
            // The status is empty when the device is previewed
            if (!statusmodel || !statusmodel.registrationState) {
                return 'empty';
            }

            var html = '<h1>Device Registration</h1>';

            switch (statusmodel.registrationState) {
                case 'UNREGISTERED':
                    html += '<h2>State</h2><h3 class="aem-ScreensPlayer-registrationView-state">' + statusmodel.registrationState + '</h3>';
                    html += '<h2>Token</h2><h3 class="aem-ScreensPlayer-registrationView-token">' + statusmodel.registrationToken + '</h3>';
                    html += '<h2>Note</h2>Please select this device in the device control center and initiate the registration wizard.';
                    break;
                case 'REGISTRATION':
                    html += '<h2>State</h2><h3 class="aem-ScreensPlayer-registrationView-state">' + statusmodel.registrationState + '</h3>';
                    html += '<h2>Token</h2><h3 class="aem-ScreensPlayer-registrationView-token">' + statusmodel.registrationToken + '</h3>';
                    html += '<h2>Note</h2>Verify that the code displayed in the device control center matches the one below and complete the registration wizard.';
                    html += '<h2>Registration Code</h2><b class="aem-ScreensPlayer-registrationView-code">' + statusmodel.registrationCode + '</b>';
                    break;
                case 'REGISTERED':
                    html += '<h2>State</h2><h3 class="aem-ScreensPlayer-registrationView-state">' + statusmodel.registrationState + '</h3>';
                    html += '<h2>Note</h2>Device is registered with the AEM Screens server at <b class="aem-ScreensPlayer-registrationView-serverUrl">' + statusmodel.server + '</b>.<br>' +
                        '<br>' +
                        'Device id: <b class="aem-ScreensPlayer-registrationView-deviceId">' + statusmodel.deviceId + '</b>';
                    break;
                case 'FAILURE':
                    html += '<h2>State</h2><h3 class="aem-ScreensPlayer-registrationView-state">' + statusmodel.registrationState + '</h3>';
                    html += '<h2>Note</h2>Error during registration request: <i class="aem-ScreensPlayer-registrationView-error">' + statusmodel.registrationError + '</i>';
                    break;
                case 'LINK_DOWN':
                    html += '<h2>Link Down</h2>';
                    html += 'The device was not able to reach ' + statusmodel.server + '. Registration currently not possible.';
                    break;
                default:
                    html += '<h2>Internal Error<h2>';
                    html += 'Internal error. Unknown registration state "' + statusmodel.registrationState + '".';
                    break;
            }

            return html;
        },

        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);
            RegistrationAdminView.__super__.constructor.apply(this, arguments);

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

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

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

            this._statusModelChangeListener = store.subscribe(this.render.bind(this), StatusModel.NAMESPACE);
            this.render(store.getState()[StatusModel.NAMESPACE]);
        },

        render: function(statusmodel) {
            this.$el.html(this.template(statusmodel));
            return this;
        }

    });

    // return module exports
    return RegistrationAdminView;
});