main-authorize.js revision 3cea0a519b1f17828a7d379e50869d43a7f9791c
0N/A/**
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0N/A *
0N/A * Copyright (c) 2014-2016 ForgeRock AS. All rights reserved.
0N/A *
0N/A * The contents of this file are subject to the terms
0N/A * of the Common Development and Distribution License
0N/A * (the License). You may not use this file except in
0N/A * compliance with the License.
0N/A *
0N/A * You can obtain a copy of the License at
0N/A * http://forgerock.org/license/CDDLv1.0.html
0N/A * See the License for the specific language governing
0N/A * permission and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL
0N/A * Header Notice in each file and include the License file
0N/A * at http://forgerock.org/license/CDDLv1.0.html
0N/A * If applicable, add the following below the CDDL Header,
0N/A * with the fields enclosed by brackets [] replaced by
0N/A * your own identifying information:
0N/A * "Portions Copyrighted [year] [name of copyright owner]"
0N/A */
0N/A
0N/Arequire.config({
0N/A map: {
0N/A "*" : {
0N/A "ThemeManager" : "org/forgerock/openam/ui/common/util/ThemeManager",
0N/A "Router": "org/forgerock/openam/ui/common/SingleRouteRouter",
0N/A // TODO: Remove this when there are no longer any references to the "underscore" dependency
0N/A "underscore" : "lodash"
0N/A }
0N/A },
0N/A paths: {
0N/A "lodash": "libs/lodash-3.10.1-min",
0N/A "handlebars": "libs/handlebars-4.0.5",
0N/A "i18next": "libs/i18next-1.7.3-min",
0N/A "jquery": "libs/jquery-2.1.1-min",
0N/A "text": "libs/text"
0N/A },
0N/A shim: {
0N/A "handlebars": {
0N/A exports: "handlebars"
0N/A },
0N/A "i18next": {
0N/A deps: ["jquery", "handlebars"],
0N/A exports: "i18n"
0N/A },
0N/A "lodash": {
0N/A exports: "_"
0N/A }
}
});
require([
"jquery",
"lodash",
"handlebars",
"org/forgerock/commons/ui/common/main/Configuration",
"org/forgerock/openam/ui/common/util/Constants",
"org/forgerock/commons/ui/common/main/i18nManager",
"ThemeManager",
"Router"
], function ($, _, HandleBars, Configuration, Constants, i18nManager, ThemeManager, Router) {
// Helpers for the code that hasn't been properly migrated to require these as explicit dependencies:
window.$ = $;
window._ = _;
var formTemplate,
baseTemplate,
footerTemplate,
loginHeaderTemplate,
templatePaths = [
"templates/user/AuthorizeTemplate.html",
"templates/common/LoginBaseTemplate.html",
"templates/common/FooterTemplate.html",
"templates/common/LoginHeaderTemplate.html"
],
data = window.pageData || {},
KEY_CODE_ENTER = 13,
KEY_CODE_SPACE = 32;
i18nManager.init({
paramLang: {
locale: data.locale || Constants.DEFAULT_LANGUAGE
},
defaultLang: Constants.DEFAULT_LANGUAGE,
nameSpace: "authorize"
});
if (data.oauth2Data) {
_.each(data.oauth2Data.displayScopes, function (obj) {
if (_.isEmpty(obj.values)) {
delete obj.values;
}
return obj;
});
_.each(data.oauth2Data.displayClaims, function (obj) {
if (_.isEmpty(obj.values)) {
delete obj.values;
}
return obj;
});
if (_.isEmpty(data.oauth2Data.displayScopes) && _.isEmpty(data.oauth2Data.displayClaims)) {
data.noScopes = true;
}
} else {
data.noScopes = true;
}
Configuration.globalData = { realm : data.realm };
Router.currentRoute = {
navGroup: "user"
};
ThemeManager.getTheme().always(function (theme) {
// add prefix to templates for custom theme when path is defined
var themePath = Configuration.globalData.theme.path;
templatePaths = _.map(templatePaths, function (templatePath) {
return `text!${themePath}${templatePath}`;
});
require(templatePaths, function (AuthorizeTemplate, LoginBaseTemplate, FooterTemplate, LoginHeaderTemplate) {
data.theme = theme;
baseTemplate = HandleBars.compile(LoginBaseTemplate);
formTemplate = HandleBars.compile(AuthorizeTemplate);
footerTemplate = HandleBars.compile(FooterTemplate);
loginHeaderTemplate = HandleBars.compile(LoginHeaderTemplate);
$("#wrapper").html(baseTemplate(data));
$("#footer").html(footerTemplate(data));
$("#loginBaseLogo").html(loginHeaderTemplate(data));
$("#content").html(formTemplate(data)).find(".panel-heading").bind("click keyup", function (e) {
// keyup is required so that the collapsed panel can be opened with the keyboard alone,
// and without relying on a mouse click event.
if (e.type === "keyup" && e.keyCode !== KEY_CODE_ENTER && e.keyCode !== KEY_CODE_SPACE) {
return;
}
$(this).toggleClass("expanded").next(".panel-collapse").slideToggle();
});
});
});
});