CLOUDSTACK-8701: Allow users to switch across SAML account/domains from topbar

Moves the previous switch account logic to its own ui-custom module

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2015-08-05 21:16:38 +05:30
parent 65f6851603
commit abecb36aae
4 changed files with 100 additions and 80 deletions

View File

@ -9654,7 +9654,7 @@ div.container div.panel div#details-tab-addloadBalancer.detail-group div.loadBal
}
/*** View switcher (drop-down)*/
.project-switcher {
.project-switcher, .domain-switcher {
float: left;
width: 223px;
padding: 9px 17px 0 19px;
@ -9665,7 +9665,7 @@ div.container div.panel div#details-tab-addloadBalancer.detail-group div.loadBal
border-radius: 4px;
}
.project-switcher label {
.project-switcher label, .domain-switcher label {
top: 29px;
color: #FFFFFF;
font-size: 13px;
@ -9674,7 +9674,7 @@ div.container div.panel div#details-tab-addloadBalancer.detail-group div.loadBal
margin-top: 5px;
}
.project-switcher select {
.project-switcher select, .domain-switcher select {
width: 70%;
float: left;
margin-top: 0px;

View File

@ -1797,6 +1797,7 @@
<script type="text/javascript" src="scripts/docs.js?t=<%=now%>"></script>
<script type="text/javascript" src="scripts/vm_snapshots.js?t=<%=now%>"></script>
<script type="text/javascript" src="scripts/ui-custom/projectSelect.js?t=<%=now%>"></script>
<script type="text/javascript" src="scripts/ui-custom/saml.js?t=<%=now%>"></script>
<!-- Plugin/module API -->
<script type="text/javascript" src="scripts/ui-custom/pluginListing.js?t=<%=now%>"></script>

View File

@ -0,0 +1,96 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
(function($, cloudStack) {
$(window).bind('cloudStack.ready', function() {
var showSamlDomainSwitcher = false;
if (g_idpList) {
showSamlDomainSwitcher = true;
}
if (!showSamlDomainSwitcher) {
return;
}
var $label = $('<label>').html('Domain:');
var $header = $('#header .controls');
var $domainSwitcher = $('<div>').addClass('domain-switcher');
var $domainSelect = $('<select>');
$domainSwitcher.append($label, $domainSelect);
var switchAccount = function(userId, domainId) {
var toReload = true;
$.ajax({
url: createURL('listAndSwitchSamlAccount'),
type: 'POST',
async: false,
data: {
userid: userId,
domainid: domainId
},
success: function(data, textStatus) {
document.location.reload(true);
},
error: function(data) {
cloudStack.dialog.notice({
message: parseXMLHttpResponse(data)
});
if (data.status !== 200) {
toReload = false;
}
},
complete: function() {
if (toReload) {
document.location.reload(true);
}
toReload = true;
}
});
};
$domainSelect.change(function() {
var selectedOption = $domainSelect.val();
var userId = selectedOption.split('/')[0];
var domainId = selectedOption.split('/')[1];
switchAccount(userId, domainId);
});
$.ajax({
url: createURL('listAndSwitchSamlAccount'),
success: function(json) {
var accounts = json.listandswitchsamlaccountresponse.samluseraccount;
if (accounts.length < 2) {
return;
};
$domainSelect.empty();
for (var i = 0; i < accounts.length; i++) {
var option = $('<option>');
option.data("userId", accounts[i].userId);
option.data("domainId", accounts[i].domainId);
option.val(accounts[i].userId + '/' + accounts[i].domainId);
option.html(accounts[i].accountName + "/" + accounts[i].domainName);
option.appendTo($domainSelect);
}
var currentAccountDomain = g_userid + '/' + g_domainid;
$domainSelect.find('option[value="' + currentAccountDomain + '"]').attr("selected", "selected");
$domainSwitcher.insertAfter($header.find('.region-switcher'));
},
error: function(data) {
// if call fails, the logged in user in not a SAML authenticated user
}
});
});
}(jQuery, cloudStack));

View File

@ -304,83 +304,6 @@
})
.appendTo($('#user'));
// Switch account option for SAML users
if (g_idpList) {
$.ajax({
url: createURL('listAndSwitchSamlAccount'),
success: function(json) {
var accounts = json.listandswitchsamlaccountresponse.samluseraccount;
if (accounts.length < 2) {
return
};
var switchAccount = function() {
var toReload = true;
$.ajax({
url: createURL('listAndSwitchSamlAccount'),
type: 'POST',
async: false,
data: {
userid: $(this).data("userId"),
domainid: $(this).data("domainId")
},
success: function(data, textStatus) {
document.location.reload(true);
},
error: function(data) {
cloudStack.dialog.notice({
message: parseXMLHttpResponse(data)
});
if (data.status !== 200) {
toReload = false;
}
},
complete: function() {
if (toReload) {
document.location.reload(true);
}
toReload = true;
}
});
};
$('<a>').attr({
href: '#'
})
.text('Switch Account')
.appendTo($options).click(function() {
var $switchSamlAccount = $('<div>');
for (var i = 0; i < accounts.length; i++) {
var item = $('<a>').html(accounts[i].accountName + "/" + accounts[i].domainName);
item.data("userId", accounts[i].userId);
item.data("domainId", accounts[i].domainId);
item.click(switchAccount);
item.appendTo($switchSamlAccount);
item.attr("href", "#");
$('<br>').appendTo($switchSamlAccount);
}
$switchSamlAccount.dialog({
modal: true,
width: 400,
title: 'Switch Account',
closeOnEscape: false,
dialogClass: 'dialog-about',
buttons: {
'Close': function() {
$(this).dialog("close");
$(':ui-dialog, .overlay').remove();
}
}
}).closest('.ui-dialog').overlay();
return false;
});
},
error: function(data) {
}
});
}
$(['label.logout', 'label.help', 'label.about']).each(function() {
var $link = $('<a>')
.attr({