From: Wen Wang <wenwang(a)linux.vnet.ibm.com>
1)Fixed the bug that login page cannot find cookies when "roles" in
the cookie is deleted in browser
2)Have the "eval()" function changed to JSON.parse() which is safer
3)Have the var "_tabMode" changed to "kimchi.tabMode" that better fit
kimchi namespace
4)Changed lifetime of cookie "roles" to session
Signed-off-by: Wen Wang <wenwang(a)linux.vnet.ibm.com>
---
ui/js/src/kimchi.guest_main.js | 3 +--
ui/js/src/kimchi.login.js | 2 +-
ui/js/src/kimchi.main.js | 23 +++++++++++++----------
ui/js/src/kimchi.network.js | 5 ++---
ui/js/src/kimchi.storage_main.js | 7 +++----
ui/js/src/kimchi.template_main.js | 3 +--
6 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/ui/js/src/kimchi.guest_main.js b/ui/js/src/kimchi.guest_main.js
index d81c6b7..394ec9d 100644
--- a/ui/js/src/kimchi.guest_main.js
+++ b/ui/js/src/kimchi.guest_main.js
@@ -323,8 +323,7 @@ kimchi.guestSetRequestHeader = function(xhr) {
};
kimchi.guest_main = function() {
- var guestsMode = _tabMode['guests'];
- if(guestsMode === 'admin') {
+ if(kimchi.tabMode['guests'] === 'admin') {
$('.tools').attr('style','display');
$("#vm-add").on("click", function(event) {
kimchi.window.open('guest-add.html');
diff --git a/ui/js/src/kimchi.login.js b/ui/js/src/kimchi.login.js
index b20f0b0..f9c9af0 100644
--- a/ui/js/src/kimchi.login.js
+++ b/ui/js/src/kimchi.login.js
@@ -57,7 +57,7 @@ kimchi.login_main = function() {
var next_url = lastPage ? lastPage.replace(/\"/g,'') :
"/";
}
var next_url = lastPage ? lastPage.replace(/\"/g,'') :
"/";
- kimchi.cookie.set('roles',JSON.stringify(data.roles), 365);
+ kimchi.cookie.set('roles',JSON.stringify(data.roles));
window.location.replace(next_url)
}, function() {
$("#messUserPass").show();
diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js
index 01ebded..b79c7f8 100644
--- a/ui/js/src/kimchi.main.js
+++ b/ui/js/src/kimchi.main.js
@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-var _tabMode = {};
+kimchi.tabMode = {};
kimchi.main = function() {
kimchi.popable();
@@ -46,15 +46,18 @@ kimchi.main = function() {
var title = i18n[titleKey] ? i18n[titleKey] : titleKey;
var path = $tab.find('path').text();
var roles = kimchi.cookie.get('roles');
- var roleString = 'JSON.parse(roles).' + titleKey.toLowerCase();
- var role = eval(roleString);
- var mode = $tab.find('[role="' + role +
'"]').attr('mode');
- _tabMode[titleKey.toLowerCase()] = mode;
- tabs.push({
- title: title,
- path: path,
- mode: mode
- });
+ if (roles) {
+ var role = JSON.parse(roles)[titleKey.toLowerCase()];
+ var mode = $tab.find('[role="' + role +
'"]').attr('mode');
+ kimchi.tabMode[titleKey.toLowerCase()] = mode;
+ tabs.push({
+ title: title,
+ path: path,
+ mode: mode
+ });
+ } else {
+ document.location.href = 'login.html';
+ }
});
return tabs;
diff --git a/ui/js/src/kimchi.network.js b/ui/js/src/kimchi.network.js
index 5b811ca..1530dd9 100644
--- a/ui/js/src/kimchi.network.js
+++ b/ui/js/src/kimchi.network.js
@@ -19,8 +19,7 @@
kimchi.NETWORK_TYPE_BRIDGE = "bridged";
kimchi.initNetwork = function() {
- var networkMode = _tabMode['network'];
- if(networkMode === 'admin') {
+ if(kimchi.tabMode['network'] === 'admin') {
$('.tools').attr('style','display');
$('#network-content .header
span:last-child').attr('style','display');
kimchi.initNetworkCreation();
@@ -53,7 +52,7 @@ kimchi.initNetworkListView = function() {
kimchi.addNetworkItem = function(network) {
$("#networkBody").append(kimchi.getNetworkItemHtml(network));
- if(_tabMode["network"] === "admin") {
+ if(kimchi.tabMode["network"] === "admin") {
$(".column-action").attr("style","display");
} else {
$(".column-space").addClass('column-space-no-border-right');
diff --git a/ui/js/src/kimchi.storage_main.js b/ui/js/src/kimchi.storage_main.js
index 4b6fd13..49fcc4a 100644
--- a/ui/js/src/kimchi.storage_main.js
+++ b/ui/js/src/kimchi.storage_main.js
@@ -30,7 +30,7 @@ kimchi.doListStoragePools = function() {
}
});
$('#storagepoolsList').html(listHtml);
- if(_tabMode['storage'] === 'admin') {
+ if(kimchi.tabMode['storage'] === 'admin') {
$('.storage-button').attr('style','display');
} else {
$('.storage-allocate').addClass('storage-allocate-padding-user');
@@ -79,7 +79,7 @@ kimchi.storageBindClick = function() {
}
});
- if(_tabMode['storage'] === 'admin') {
+ if(kimchi.tabMode['storage'] === 'admin') {
$('.pool-delete').on('click', function(event) {
var $pool = $(this);
var settings = {
@@ -242,8 +242,7 @@ kimchi.initLogicalPoolExtend = function() {
}
kimchi.storage_main = function() {
- var storageMode = _tabMode['storage'];
- if(storageMode === 'admin') {
+ if(kimchi.tabMode['storage'] === 'admin') {
$('.tools').attr('style','display');
$('#storage-pool-add').on('click', function() {
kimchi.window.open('storagepool-add.html');
diff --git a/ui/js/src/kimchi.template_main.js b/ui/js/src/kimchi.template_main.js
index 7ce408f..4fa4dd8 100644
--- a/ui/js/src/kimchi.template_main.js
+++ b/ui/js/src/kimchi.template_main.js
@@ -83,8 +83,7 @@ kimchi.hideTitle = function() {
};
kimchi.template_main = function() {
- var templatesMode = _tabMode['templates'];
- if(templatesMode === 'admin') {
+ if(kimchi.tabMode['templates'] === 'admin') {
$('.tools').attr('style','display');
$("#template-add").on("click", function(event) {
kimchi.window.open({
--
1.7.1