File: src\internal\ui\scheduleCallback\component.ts
/// <reference path="../../api/modalities/scheduleCallbackModality.ts" />
/// <reference path="../../utils/modality.ts" />
/// <reference path="../../packages.ts" />
/// <reference path="../constants.ts" />
/// <reference path="config.ts" />
/**
* @module UI
* @submodule UI ScheduleCallback
* @namespace ui
*/
/**
* Schedule Callback UI Module
* @class scheduleCallback
* @static
*/
namespace internal.ui.scheduleCallback {
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 SCHEDULE_CALLBACK_COMPONENT = "ScheduleCallback";
/**
* Render the ScheduleCallback UI
* @method render
* @static
* @param {ui.scheduleCallback.Config} config A {{#crossLink "ui.scheduleCallback.Config"}}{{/crossLink}} object
* @param {ui.UIInfo} [config.uiInfo] A {{#crossLink "ui.UIInfo"}}{{/crossLink}} object {{#crossLink "ui.UIInfo"}}{{/crossLink}}
* @param {ui.HostType} [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 scheduleCallback.
* // Render scheduleCallback 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.scheduleCallback.Config"}}scheduleCallback 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 scheduled.");
* },
* onCallbackRejected: function (e) {
* console.log("Callback rejected.");
* }
* };
*
* // Render ScheduleCallback UI
* MsSupportSdk.ui.scheduleCallback.render(config).then(
* function() {
* console.log("ScheduleCallback rendered successfully.");
* },
* function(err) {
* console.log(err.message);
* });
*/
export function render(config: Config): JQueryPromise<any> {
return ui.renderComponent(Component, config, SCHEDULE_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.ScheduleCallbackModality>utils.getModalityByType(config.modalities, api.modalities.Modality.SCHEDULE_CALLBACK);
if (!modality) {
throw new Error("Schedule 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);
}
}