diff --git a/ui/scripts/accounts.js b/ui/scripts/accounts.js index 03ec799c00f..15da5218aea 100644 --- a/ui/scripts/accounts.js +++ b/ui/scripts/accounts.js @@ -282,59 +282,71 @@ }); - $.ajax({ - url: createURL("updateResourceLimit&resourceType=0&max=" + todb(args.data.vmLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid), - dataType: "json", - async: false, - success: function(json) { - accountObj["vmLimit"] = args.data.vmLimit; - } - }); + if(args.data.vmLimit != null) { + $.ajax({ + url: createURL("updateResourceLimit&resourceType=0&max=" + todb(args.data.vmLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid), + dataType: "json", + async: false, + success: function(json) { + accountObj["vmLimit"] = args.data.vmLimit; + } + }); + } - $.ajax({ - url: createURL("updateResourceLimit&resourceType=1&max=" + todb(args.data.ipLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid), - dataType: "json", - async: false, - success: function(json) { - accountObj["ipLimit"] = args.data.ipLimit; - } - }); + if(args.data.ipLimit != null) { + $.ajax({ + url: createURL("updateResourceLimit&resourceType=1&max=" + todb(args.data.ipLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid), + dataType: "json", + async: false, + success: function(json) { + accountObj["ipLimit"] = args.data.ipLimit; + } + }); + } - $.ajax({ - url: createURL("updateResourceLimit&resourceType=2&max=" + todb(args.data.volumeLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid), - dataType: "json", - async: false, - success: function(json) { - accountObj["volumeLimit"] = args.data.volumeLimit; - } - }); + if(args.data.volumeLimit != null) { + $.ajax({ + url: createURL("updateResourceLimit&resourceType=2&max=" + todb(args.data.volumeLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid), + dataType: "json", + async: false, + success: function(json) { + accountObj["volumeLimit"] = args.data.volumeLimit; + } + }); + } - $.ajax({ - url: createURL("updateResourceLimit&resourceType=3&max=" + todb(args.data.snapshotLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid), - dataType: "json", - async: false, - success: function(json) { - accountObj["snapshotLimit"] = args.data.snapshotLimit; - } - }); - - $.ajax({ - url: createURL("updateResourceLimit&resourceType=4&max=" + todb(args.data.templateLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid), - dataType: "json", - async: false, - success: function(json) { - accountObj["templateLimit"] = args.data.templateLimit; - } - }); - - $.ajax({ - url: createURL("updateResourceLimit&resourceType=7&max=" + todb(args.data.vpcLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid), - dataType: "json", - async: false, - success: function(json) { - accountObj["vpcLimit"] = args.data.vpcLimit; - } - }); + if(args.data.snapshotLimit != null) { + $.ajax({ + url: createURL("updateResourceLimit&resourceType=3&max=" + todb(args.data.snapshotLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid), + dataType: "json", + async: false, + success: function(json) { + accountObj["snapshotLimit"] = args.data.snapshotLimit; + } + }); + } + + if(args.data.templateLimit != null) { + $.ajax({ + url: createURL("updateResourceLimit&resourceType=4&max=" + todb(args.data.templateLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid), + dataType: "json", + async: false, + success: function(json) { + accountObj["templateLimit"] = args.data.templateLimit; + } + }); + } + + if(args.data.vpcLimit != null) { + $.ajax({ + url: createURL("updateResourceLimit&resourceType=7&max=" + todb(args.data.vpcLimit) + "&account=" + accountObj.name + "&domainid=" + accountObj.domainid), + dataType: "json", + async: false, + success: function(json) { + accountObj["vpcLimit"] = args.data.vpcLimit; + } + }); + } if(errorMsg == "") args.response.success({data: accountObj}); @@ -546,27 +558,57 @@ }, vmLimit: { label: 'label.instance.limits', - isEditable: true + isEditable: function(context) { + if (context.accounts[0].accounttype == roleTypeUser || context.accounts[0].accounttype == roleTypeDomainAdmin) //updateResourceLimits is only allowed on account whose type is user or domain-admin + return true; + else + return false; + } }, ipLimit: { label: 'label.ip.limits', - isEditable: true + isEditable: function(context) { + if (context.accounts[0].accounttype == roleTypeUser || context.accounts[0].accounttype == roleTypeDomainAdmin) //updateResourceLimits is only allowed on account whose type is user or domain-admin + return true; + else + return false; + } }, volumeLimit: { label: 'label.volume.limits', - isEditable: true + isEditable: function(context) { + if (context.accounts[0].accounttype == roleTypeUser || context.accounts[0].accounttype == roleTypeDomainAdmin) //updateResourceLimits is only allowed on account whose type is user or domain-admin + return true; + else + return false; + } }, snapshotLimit: { label: 'label.snapshot.limits', - isEditable: true + isEditable: function(context) { + if (context.accounts[0].accounttype == roleTypeUser || context.accounts[0].accounttype == roleTypeDomainAdmin) //updateResourceLimits is only allowed on account whose type is user or domain-admin + return true; + else + return false; + } }, templateLimit: { label: 'label.template.limits', - isEditable: true + isEditable: function(context) { + if (context.accounts[0].accounttype == roleTypeUser || context.accounts[0].accounttype == roleTypeDomainAdmin) //updateResourceLimits is only allowed on account whose type is user or domain-admin + return true; + else + return false; + } }, vpcLimit: { label: 'VPC limits', - isEditable: true + isEditable: function(context) { + if (context.accounts[0].accounttype == roleTypeUser || context.accounts[0].accounttype == roleTypeDomainAdmin) //updateResourceLimits is only allowed on account whose type is user or domain-admin + return true; + else + return false; + } }, vmtotal: { label: 'label.total.of.vm' }, @@ -1091,12 +1133,8 @@ if (jsonObj.state == 'Destroyed') return []; if(isAdmin()) { - if(!(jsonObj.domain == "ROOT" && jsonObj.name == "admin" && jsonObj.accounttype == 1)) { //if not system-generated default admin account - //allowedActions.push("edit"); - if (jsonObj.accounttype == roleTypeUser || jsonObj.accounttype == roleTypeDomainAdmin) { - //allowedActions.push("updateResourceLimits"); - allowedActions.push("edit"); - } + allowedActions.push("edit"); //updating networkdomain is allowed on any account, including system-generated default admin account + if(!(jsonObj.domain == "ROOT" && jsonObj.name == "admin" && jsonObj.accounttype == 1)) { //if not system-generated default admin account if(jsonObj.state == "enabled") { allowedActions.push("disable"); allowedActions.push("lock"); diff --git a/ui/scripts/ui/widgets/detailView.js b/ui/scripts/ui/widgets/detailView.js index fc2ae459243..a51cfcc12a8 100644 --- a/ui/scripts/ui/widgets/detailView.js +++ b/ui/scripts/ui/widgets/detailView.js @@ -789,7 +789,7 @@ // Set up editable metadata if(typeof(value.isEditable) == 'function') - $value.data('detail-view-is-editable', value.isEditable()); + $value.data('detail-view-is-editable', value.isEditable(context)); else //typeof(value.isEditable) == 'boolean' or 'undefined' $value.data('detail-view-is-editable', value.isEditable); if (value.select) {