API Docs for: 2.0.20133.2
Show:

File: src\internal\ui\callback\component.ts

/// <reference path="../../api/modalities/callbackModality.ts" />
/// <reference path="../../utils/modality.ts" />
/// <reference path="../../packages.ts" />
/// <reference path="../constants.ts" />
/// <reference path="config.ts" /> 

/**
 * @module UI
 * @submodule UI Callback
 * @namespace ui
 */

/**
 * Callback UI Module
 * @class callback
 * @static
 */
namespace internal.ui.callback {

    const LOAD_TIMEOUT_MS = 15000; // Use this to overwrite the default loaded timeout  
    const REPORT_HEIGHT_CHANGE = false; // set to true to report height change events
    const CALLBACK_COMPONENT = "Callback";

    /**
     * Render the Callback UI
     * @method render
     * @static
     * @param {Object} config A {{#crossLink "ui.callback.Config"}}{{/crossLink}} object
     * @param {Object} [config.uiInfo] A {{#crossLink "ui.UIInfo"}}{{/crossLink}} object {{#crossLink "ui.UIInfo"}}{{/crossLink}}
     * @param {String} [config.uiInfo.type] A value in {{#crossLink "ui.HostType"}}{{/crossLink}} which indicates the type of UI to render e.g. IFRAME, POPUP.
     * @param {String} [config.uiInfo.containerSelector] Only required for iframe -- a JQuery selector statement to define the element into which the iframe will be loaded
     * @param {Number} [config.uiInfo.height] The height of the rendered UI
     * @param {Number} [config.uiInfo.width] The width of the rendered UI
     * @return {Promise} A promise that resolves when the UI component has successfully loaded
     * @example
     *
     *     // Modalities API must be called first to get the modalities object which is required to render callback.
     *     // Render callback as an IFRAME.
     *     // More UIInfo examples available {{#crossLink "ui.UIInfo"}}here{{/crossLink}}
     *     var uiInfo = {
     *         type: {{#crossLink "ui.HostType"}}MsSupportSdk.ui.HostType.IFRAME{{/crossLink}},
     *         containerSelector: "#iframe-container"
     *     };
     *
     *     // Create a {{#crossLink "ui.callback.Config"}}callback config{{/crossLink}}
     *     var config = {
     *         uiInfo: uiInfo
     *         modalities: window.savedModalities, // See {{#crossLink "api.modalities"}}Modalities API examples{{/crossLink}} about how to get the modalities object
     *         onCallbackAccepted: function() {
     *             console.log("Callback accepted.");
     *         },
     *         onCallbackRejected: function (e) {
     *             console.log("Callback rejected.");
     *         }
     *      };
     *
     *     // Render callback UI
     *     MsSupportSdk.ui.callback.render(config).then(
     *         function() {
     *             console.log("Callback rendered successfully."); 
     *         },
     *         function(err) {
     *             console.log(err.message);
     *         });
     */
    export function render(config: Config): JQueryPromise<any> {
        return ui.renderComponent(Component, config, CALLBACK_COMPONENT);
    }

    export class Component extends UIComponent {

        constructor(config: UIConfig) {
            super(config, LOAD_TIMEOUT_MS, REPORT_HEIGHT_CHANGE);
        }

        public getComponentUrl(): string {
            return getCallbackUrl(<Config>this.config);
        }

        public getComponentSdk(): ComponentSDK {
            return {};
        }

        public getXframeProxyUrl(): string {
            return `${utils.getOriginFromUrl(this.getComponentUrl())}/xframeproxy/`;
        }
    }

    function getCallbackUrl(config: Config): string {
        let modality = <api.modalities.CallbackModality>utils.getModalityByType(config.modalities, api.modalities.Modality.CALLBACK);
        if (!modality) {
            throw new Error("Callback is not supported for this product/issue/langugage/country.");
        }
        let link = modality.link;
        let values: any = {};
        if (config.authInfo && config.authInfo.type && config.authInfo.type === <any>AuthType.AAD) {
            values["useAAD"] = true;
        }
        return utils.appendParams(link, values);
    }
}