Skip to content

Commit 3a313ee

Browse files
author
Jessica Wang
committed
CLOUDSTACK-110: cloudstack UI - domain page - allow root domain to have Edit option, but only network domain field is editable, Resource Limits fields and domain name field is not editable.
1 parent acaa220 commit 3a313ee

1 file changed

Lines changed: 126 additions & 62 deletions

File tree

ui/scripts/domains.js

Lines changed: 126 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -97,66 +97,92 @@
9797
},
9898
action: function(args) {
9999
var domainObj;
100-
var array1 = [];
101-
array1.push("&name=" + todb(args.data.name));
102-
array1.push("&networkdomain=" + todb(args.data.networkdomain));
100+
101+
var data = {
102+
id: args.context.domains[0].id,
103+
networkdomain: args.data.networkdomain
104+
};
105+
106+
if(args.data.name != null) {
107+
$.extend(data, {
108+
name: args.data.name
109+
});
110+
}
111+
103112
$.ajax({
104-
url: createURL("updateDomain&id=" + args.context.domains[0].id + array1.join("")),
113+
url: createURL("updateDomain"),
105114
async: false,
106-
dataType: "json",
115+
data: data,
107116
success: function(json) {
108117
domainObj = json.updatedomainresponse.domain;
109118
}
110119
});
111120

112-
$.ajax({
113-
url: createURL("updateResourceLimit&domainid=" + args.context.domains[0].id + "&resourceType=0&max=" + args.data.vmLimit),
114-
dataType: "json",
115-
async: false,
116-
success: function(json) {
117-
domainObj["vmLimit"] = args.data.vmLimit;
118-
}
119-
});
120-
$.ajax({
121-
url: createURL("updateResourceLimit&domainid=" + args.context.domains[0].id + "&resourceType=1&max=" + args.data.ipLimit),
122-
dataType: "json",
123-
async: false,
124-
success: function(json) {
125-
domainObj["ipLimit"] = args.data.ipLimit;
126-
}
127-
});
128-
$.ajax({
129-
url: createURL("updateResourceLimit&domainid=" + args.context.domains[0].id + "&resourceType=2&max=" + args.data.volumeLimit),
130-
dataType: "json",
131-
async: false,
132-
success: function(json) {
133-
domainObj["volumeLimit"] = args.data.volumeLimit;
134-
}
135-
});
136-
$.ajax({
137-
url: createURL("updateResourceLimit&domainid=" + args.context.domains[0].id + "&resourceType=3&max=" + args.data.snapshotLimit),
138-
dataType: "json",
139-
async: false,
140-
success: function(json) {
141-
domainObj["snapshotLimit"] = args.data.snapshotLimit;
142-
}
143-
});
144-
$.ajax({
145-
url: createURL("updateResourceLimit&domainid=" + args.context.domains[0].id + "&resourceType=4&max=" + args.data.templateLimit),
146-
dataType: "json",
147-
async: false,
148-
success: function(json) {
149-
domainObj["templateLimit"] = args.data.templateLimit;
150-
}
151-
});
152-
$.ajax({
153-
url: createURL("updateResourceLimit&domainid=" + args.context.domains[0].id + "&resourceType=7&max=" + args.data.vpcLimit),
154-
dataType: "json",
155-
async: false,
156-
success: function(json) {
157-
domainObj["vpcLimit"] = args.data.vpcLimit;
158-
}
159-
});
121+
if(args.data.vmLimit != null) {
122+
$.ajax({
123+
url: createURL("updateResourceLimit&domainid=" + args.context.domains[0].id + "&resourceType=0&max=" + args.data.vmLimit),
124+
dataType: "json",
125+
async: false,
126+
success: function(json) {
127+
domainObj["vmLimit"] = args.data.vmLimit;
128+
}
129+
});
130+
}
131+
132+
if(args.data.ipLimit != null) {
133+
$.ajax({
134+
url: createURL("updateResourceLimit&domainid=" + args.context.domains[0].id + "&resourceType=1&max=" + args.data.ipLimit),
135+
dataType: "json",
136+
async: false,
137+
success: function(json) {
138+
domainObj["ipLimit"] = args.data.ipLimit;
139+
}
140+
});
141+
}
142+
143+
if(args.data.volumeLimit != null) {
144+
$.ajax({
145+
url: createURL("updateResourceLimit&domainid=" + args.context.domains[0].id + "&resourceType=2&max=" + args.data.volumeLimit),
146+
dataType: "json",
147+
async: false,
148+
success: function(json) {
149+
domainObj["volumeLimit"] = args.data.volumeLimit;
150+
}
151+
});
152+
}
153+
154+
if(args.data.snapshotLimit != null) {
155+
$.ajax({
156+
url: createURL("updateResourceLimit&domainid=" + args.context.domains[0].id + "&resourceType=3&max=" + args.data.snapshotLimit),
157+
dataType: "json",
158+
async: false,
159+
success: function(json) {
160+
domainObj["snapshotLimit"] = args.data.snapshotLimit;
161+
}
162+
});
163+
}
164+
165+
if(args.data.templateLimit != null) {
166+
$.ajax({
167+
url: createURL("updateResourceLimit&domainid=" + args.context.domains[0].id + "&resourceType=4&max=" + args.data.templateLimit),
168+
dataType: "json",
169+
async: false,
170+
success: function(json) {
171+
domainObj["templateLimit"] = args.data.templateLimit;
172+
}
173+
});
174+
}
175+
176+
if(args.data.vpcLimit != null) {
177+
$.ajax({
178+
url: createURL("updateResourceLimit&domainid=" + args.context.domains[0].id + "&resourceType=7&max=" + args.data.vpcLimit),
179+
dataType: "json",
180+
async: false,
181+
success: function(json) {
182+
domainObj["vpcLimit"] = args.data.vpcLimit;
183+
}
184+
});
185+
}
160186

161187
args.response.success({data: domainObj});
162188
}
@@ -243,7 +269,15 @@
243269
title: 'label.details',
244270
fields: [
245271
{
246-
name: { label: 'label.name', isEditable: true }
272+
name: {
273+
label: 'label.name',
274+
isEditable: function(context) {
275+
if(context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to change domain name
276+
return true;
277+
else
278+
return false;
279+
}
280+
}
247281
},
248282
{
249283
id: { label: 'ID' },
@@ -256,27 +290,57 @@
256290
},
257291
vmLimit: {
258292
label: 'label.instance.limits',
259-
isEditable: true
293+
isEditable: function(context) {
294+
if(context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
295+
return true;
296+
else
297+
return false;
298+
}
260299
},
261300
ipLimit: {
262301
label: 'label.ip.limits',
263-
isEditable: true
302+
isEditable: function(context) {
303+
if(context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
304+
return true;
305+
else
306+
return false;
307+
}
264308
},
265309
volumeLimit: {
266310
label: 'label.volume.limits',
267-
isEditable: true
311+
isEditable: function(context) {
312+
if(context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
313+
return true;
314+
else
315+
return false;
316+
}
268317
},
269318
snapshotLimit: {
270319
label: 'label.snapshot.limits',
271-
isEditable: true
320+
isEditable: function(context) {
321+
if(context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
322+
return true;
323+
else
324+
return false;
325+
}
272326
},
273327
templateLimit: {
274328
label: 'label.template.limits',
275-
isEditable: true
329+
isEditable: function(context) {
330+
if(context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
331+
return true;
332+
else
333+
return false;
334+
}
276335
},
277336
vpcLimit: {
278337
label: 'VPC limits',
279-
isEditable: true
338+
isEditable: function(context) {
339+
if(context.domains[0].level != 0) //ROOT domain (whose level is 0) is not allowed to updateResourceLimits
340+
return true;
341+
else
342+
return false;
343+
}
280344
},
281345
accountTotal: { label: 'label.accounts' },
282346
vmTotal: { label: 'label.instances' },
@@ -412,8 +476,8 @@
412476
var allowedActions = [];
413477
if(isAdmin()) {
414478
allowedActions.push("create");
415-
if(jsonObj.level != 0) { //ROOT domain (whose level is 0) is not allowed to edit or delete
416-
allowedActions.push("edit"); //merge updateResourceLimit into edit
479+
allowedActions.push("edit"); //merge updateResourceLimit into edit
480+
if(jsonObj.level != 0) { //ROOT domain (whose level is 0) is not allowed to delete
417481
allowedActions.push("delete");
418482
}
419483
}

0 commit comments

Comments
 (0)