diff --git a/ui/scripts/accounts.js b/ui/scripts/accounts.js index bad8435e27e..e5faf33268b 100644 --- a/ui/scripts/accounts.js +++ b/ui/scripts/accounts.js @@ -15,1460 +15,1585 @@ // specific language governing permissions and limitations // under the License. (function(cloudStack) { - - var domainObjs; - var rootDomainId; - cloudStack.sections.accounts = { - title: 'label.accounts', - id: 'accounts', - sectionSelect: { - label: 'Select View', - preFilter: function() { - return ['accounts']; - } - }, - sections: { - accounts: { - type: 'select', - id: 'accounts', + var domainObjs; + var rootDomainId; + + cloudStack.sections.accounts = { title: 'label.accounts', - listView: { - id: 'accounts', - fields: { - name: { label: 'label.name' }, - accounttype: { - label: 'label.role', - converter: function(args){ - return cloudStack.converters.toRole(args); - } - }, - domain: { label: 'label.domain' }, - state: { - converter: function(str) { - // For localization - return str; - }, - label: 'label.state', - indicator: { - 'enabled': 'on', - 'Destroyed': 'off', - 'disabled': 'off' - } + id: 'accounts', + sectionSelect: { + label: 'Select View', + preFilter: function() { + return ['accounts']; } - }, - - actions: { - add: { - label: 'label.add.account', - preFilter: function(args) { - if(isAdmin()) - return true; - else - return false; - }, - messages: { - notification: function(args) { - return 'label.add.account'; - } - }, - - createForm: { - title: 'label.add.account', - desc: 'label.add.account', - fields: { - username: { - label: 'label.username', - validation: { required: true }, - docID: 'helpAccountUsername' - }, - password: { - label: 'label.password', - validation: { required: true }, - isPassword: true, - id: 'password', - docID: 'helpAccountPassword' - }, - 'password-confirm': { - label: 'label.confirm.password', - validation: { - required: true, - equalTo: '#password' - }, - isPassword: true, - docID: 'helpAccountConfirmPassword' - }, - email: { - label: 'label.email', - validation: { required: true, email:true }, - docID: 'helpAccountEmail' - }, - firstname: { - label: 'label.first.name', - validation: { required: true }, - docID: 'helpAccountFirstName' - }, - lastname: { - label: 'label.last.name', - validation: { required: true }, - docID: 'helpAccountLastName' - }, - domainid: { - label: 'label.domain', - docID: 'helpAccountDomain', - validation: { required: true }, - select: function(args) { - var data = {}; - - if (args.context.users) { // In accounts section - data.listAll = true; - } else if (args.context.domains) { // In domain section (use specific domain) - data.id = args.context.domains[0].id; - } - - $.ajax({ - url: createURL("listDomains"), - data: data, - dataType: "json", - async: false, - success: function(json) { - var items = []; - domainObjs = json.listdomainsresponse.domain; - $(domainObjs).each(function() { - items.push({ id: this.id, description: this.path }); - - if(this.level == 0) - rootDomainId = this.id; - }); - args.response.success({ data: items }); + }, + sections: { + accounts: { + type: 'select', + id: 'accounts', + title: 'label.accounts', + listView: { + id: 'accounts', + fields: { + name: { + label: 'label.name' + }, + accounttype: { + label: 'label.role', + converter: function(args) { + return cloudStack.converters.toRole(args); + } + }, + domain: { + label: 'label.domain' + }, + state: { + converter: function(str) { + // For localization + return str; + }, + label: 'label.state', + indicator: { + 'enabled': 'on', + 'Destroyed': 'off', + 'disabled': 'off' + } } - }); - } - }, - account: { - label: 'label.account', - docID: 'helpAccountAccount' - }, - accounttype: { - label: 'label.type', - docID: 'helpAccountType', - validation: { required: true }, - select: function(args) { - var items = []; - items.push({id:0, description: "User"}); //regular-user - items.push({id:1, description: "Admin"}); //root-admin - args.response.success({data: items}); - } - }, - timezone: { - label: 'label.timezone', - docID: 'helpAccountTimezone', - select: function(args) { - var items = []; - items.push({id: "", description: ""}); - for(var p in timezoneMap) - items.push({id: p, description: timezoneMap[p]}); - args.response.success({data: items}); - } - }, - networkdomain: { - label: 'label.network.domain', - docID: 'helpAccountNetworkDomain', - validation: { required: false } - } - } - }, - - action: function(args) { - var data = { - username: args.data.username, - }; - - var password = args.data.password; - if (md5Hashed) { - password = $.md5(password); - } - $.extend(data, { - password: password - }); - - $.extend(data, { - email: args.data.email, - firstname: args.data.firstname, - lastname: args.data.lastname, - domainid: args.data.domainid - }); - - var account = args.data.account; - if(account == null || account.length == 0) { - account = args.data.username; - } - $.extend(data, { - account: account - }); - - var accountType = args.data.accounttype; - if (args.data.accounttype == "1" && args.data.domainid != rootDomainId) { //if account type is admin, but domain is not Root domain - accountType = "2"; // Change accounttype from root-domain("1") to domain-admin("2") - } - $.extend(data, { - accounttype: accountType - }); - - if(args.data.timezone != null && args.data.timezone.length > 0) { - $.extend(data, { - timezone: args.data.timezone - }); - } - - if(args.data.networkdomain != null && args.data.networkdomain.length > 0) { - $.extend(data, { - networkdomain: args.data.networkdomain - }); - } - - $.ajax({ - url: createURL('createAccount'), - type: "POST", - data: data, - success: function(json) { - var item = json.createaccountresponse.account; - args.response.success({data:item}); - }, - error: function(XMLHttpResponse) { - args.response.error(parseXMLHttpResponse(XMLHttpResponse)); - } - }); - }, - - notification: { - poll: function(args) { - args.complete({ - actionFilter: accountActionfilter - }); - } - } - } - }, - - dataProvider: function(args) { - var data = {}; - listViewDataProvider(args, data); - - if("domains" in args.context) { - $.extend(data, { - domainid: args.context.domains[0].id - }); - } - - $.ajax({ - url: createURL('listAccounts'), - data: data, - async: true, - success: function(json) { - var items = json.listaccountsresponse.account; - args.response.success({ - actionFilter: accountActionfilter, - data:items - }); - } - }); - }, - - detailView: { - name: 'Account details', - isMaximized: true, - viewAll: { path: 'accounts.users', label: 'label.users' }, - - actions: { - edit: { - label: 'message.edit.account', - compactLabel: 'label.edit', - action: function(args) { - var accountObj = args.context.accounts[0]; - - var data = { - domainid: accountObj.domainid, - account: accountObj.name, - newname: args.data.name, - networkdomain: args.data.networkdomain - }; - - $.ajax({ - url: createURL('updateAccount'), - data: data, - async: false, - success: function(json) { - accountObj = json.updateaccountresponse.account; - }, - error: function(json) { - var errorMsg = parseXMLHttpResponse(json); - args.response.error(errorMsg); - } - }); - - if(args.data.vmLimit != null) { - var data = { - resourceType: 0, - max: args.data.vmLimit, - domainid: accountObj.domainid, - account: accountObj.name - }; - $.ajax({ - url: createURL('updateResourceLimit'), - data: data, - async: false, - success: function(json) { - accountObj["vmLimit"] = args.data.vmLimit; - } - }); - } - - if(args.data.ipLimit != null) { - var data = { - resourceType: 1, - max: args.data.ipLimit, - domainid: accountObj.domainid, - account: accountObj.name - }; - $.ajax({ - url: createURL('updateResourceLimit'), - data: data, - async: false, - success: function(json) { - accountObj["ipLimit"] = args.data.ipLimit; - } - }); - } - - if(args.data.volumeLimit != null) { - var data = { - resourceType: 2, - max: args.data.volumeLimit, - domainid: accountObj.domainid, - account: accountObj.name - }; - $.ajax({ - url: createURL('updateResourceLimit'), - data: data, - async: false, - success: function(json) { - accountObj["volumeLimit"] = args.data.volumeLimit; - } - }); - } - - if(args.data.snapshotLimit != null) { - var data = { - resourceType: 3, - max: args.data.snapshotLimit, - domainid: accountObj.domainid, - account: accountObj.name - }; - $.ajax({ - url: createURL('updateResourceLimit'), - data: data, - async: false, - success: function(json) { - accountObj["snapshotLimit"] = args.data.snapshotLimit; - } - }); - } - - if(args.data.templateLimit != null) { - var data = { - resourceType: 4, - max: args.data.templateLimit, - domainid: accountObj.domainid, - account: accountObj.name - }; - $.ajax({ - url: createURL('updateResourceLimit'), - data: data, - async: false, - success: function(json) { - accountObj["templateLimit"] = args.data.templateLimit; - } - }); - } - - if(args.data.vpcLimit != null) { - var data = { - resourceType: 7, - max: args.data.vpcLimit, - domainid: accountObj.domainid, - account: accountObj.name - }; - - $.ajax({ - url: createURL('updateResourceLimit'), - data: data, - async: false, - success: function(json) { - accountObj["vpcLimit"] = args.data.vpcLimit; - } - }); - } - - if(args.data.cpuLimit != null) { - var data = { - resourceType: 8, - max: args.data.cpuLimit, - domainid: accountObj.domainid, - account: accountObj.name - }; - - $.ajax({ - url: createURL('updateResourceLimit'), - data: data, - async: false, - success: function(json) { - accountObj["cpuLimit"] = args.data.cpuLimit; - } - }); - } - - if(args.data.memoryLimit != null) { - var data = { - resourceType: 9, - max: args.data.memoryLimit, - domainid: accountObj.domainid, - account: accountObj.name - }; - - $.ajax({ - url: createURL('updateResourceLimit'), - data: data, - async: false, - success: function(json) { - accountObj["memoryLimit"] = args.data.memoryLimit; - } - }); - } - - if(args.data.primaryStorageLimit != null) { - var data = { - resourceType: 10, - max: args.data.primaryStorageLimit, - domainid: accountObj.domainid, - account: accountObj.name - }; - - $.ajax({ - url: createURL('updateResourceLimit'), - data: data, - async: false, - success: function(json) { - accountObj["primaryStorageLimit"] = args.data.primaryStorageLimit; - } - }); - } - - if(args.data.secondaryStorageLimit != null) { - var data = { - resourceType: 11, - max: args.data.secondaryStorageLimit, - domainid: accountObj.domainid, - account: accountObj.name - }; - - $.ajax({ - url: createURL('updateResourceLimit'), - data: data, - async: false, - success: function(json) { - accountObj["secondaryStorageLimit"] = args.data.secondaryStorageLimit; - } - }); - } - args.response.success({data: accountObj}); - } - }, - - updateResourceCount: { - label: 'label.action.update.resource.count', - messages: { - confirm: function(args) { - return 'message.update.resource.count'; - }, - notification: function(args) { - return 'label.action.update.resource.count'; - } - }, - action: function(args) { - var accountObj = args.context.accounts[0]; - var data = { - domainid: accountObj.domainid, - account: accountObj.name - }; - - $.ajax({ - url: createURL('updateResourceCount'), - data: data, - async: true, - success: function(json) { - //var resourcecounts= json.updateresourcecountresponse.resourcecount; //do nothing - args.response.success(); - }, - error: function(json) { - args.response.error(parseXMLHttpResponse(json)); - } - }); - }, - notification: { - poll: function(args) { - args.complete(); - } - } - }, - - disable: { - label: 'label.action.disable.account', - messages: { - confirm: function(args) { - return 'message.disable.account'; - }, - notification: function(args) { - return 'label.action.disable.account'; - } - }, - action: function(args) { - var accountObj = args.context.accounts[0]; - var data = { - lock: false, - domainid: accountObj.domainid, - account: accountObj.name - }; - - $.ajax({ - url: createURL('disableAccount'), - data: data, - async: true, - success: function(json) { - var jid = json.disableaccountresponse.jobid; - args.response.success( - {_custom: - {jobId: jid, - getUpdatedItem: function(json) { - return json.queryasyncjobresultresponse.jobresult.account; - }, - getActionFilter: function() { - return accountActionfilter; - } - } - } - ); - } - }); - }, - notification: { - poll: pollAsyncJobResult - } - }, - - lock: { - label: 'label.action.lock.account', - messages: { - confirm: function(args) { - return 'message.lock.account'; - }, - notification: function(args) { - return 'label.action.lock.account'; - } - }, - action: function(args) { - var accountObj = args.context.accounts[0]; - var data = { - lock: true, - domainid: accountObj.domainid, - account: accountObj.name - }; - - $.ajax({ - url: createURL('disableAccount'), - data: data, - async: true, - success: function(json) { - var jid = json.disableaccountresponse.jobid; - args.response.success( - {_custom: - {jobId: jid, - getUpdatedItem: function(json) { - return json.queryasyncjobresultresponse.jobresult.account; - }, - getActionFilter: function() { - return accountActionfilter; - } - } - } - ); - } - }); - }, - notification: { - poll: pollAsyncJobResult - } - }, - - enable: { - label: 'label.action.enable.account', - messages: { - confirm: function(args) { - return 'message.enable.account'; - }, - notification: function(args) { - return 'label.action.enable.account'; - } - }, - action: function(args) { - var accountObj = args.context.accounts[0]; - var data = { - domainid: accountObj.domainid, - account: accountObj.name - }; - $.ajax({ - url: createURL('enableAccount'), - data: data, - async: true, - success: function(json) { - args.response.success({data: json.enableaccountresponse.account}); - } - }); - }, - notification: { - poll: function(args) { - args.complete({ - data: { state: 'enabled' } - }); - } - } - }, - - remove: { - label: 'label.action.delete.account', - messages: { - confirm: function(args) { - return 'message.delete.account'; - }, - notification: function(args) { - return 'label.action.delete.account'; - } - }, - action: function(args) { - var data = { - id: args.context.accounts[0].id - }; - $.ajax({ - url: createURL('deleteAccount'), - data: data, - async: true, - success: function(json) { - var jid = json.deleteaccountresponse.jobid; - args.response.success( - {_custom: - {jobId: jid, - getUpdatedItem: function(json) { - return {}; //nothing in this account needs to be updated, in fact, this whole account has being deleted - }, - getActionFilter: function() { - return accountActionfilter; - } - } - } - ); - } - }); - }, - notification: { - poll: pollAsyncJobResult - } - } - - }, - - tabs: { - details: { - title: 'label.details', - - fields: [ - { - name: { - label: 'label.name', - isEditable: true, - validation: { required: true } - } - }, - { - id: { label: 'ID' }, - accounttype: { - label: 'label.role', - converter: function(args){ - return cloudStack.converters.toRole(args); - } - }, - domain: { label: 'label.domain' }, - state: { label: 'label.state' }, - networkdomain: { - label: 'label.network.domain', - isEditable: true - }, - vmLimit: { - label: 'label.instance.limits', - isEditable: function(context) { - - if(context.accounts == undefined) - return false; - else { - 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: 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: 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: 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: 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: 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; - } - }, - cpuLimit: { - label: 'label.cpu.limits', - 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; - } - }, - memoryLimit: { - label: 'label.memory.limits', - 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; - } - }, - primaryStorageLimit: { - label: 'label.primary.storage.limits', - 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; - } - }, - secondaryStorageLimit: { - label: 'label.secondary.storage.limits', - 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' }, - iptotal: { label: 'label.total.of.ip' }, - receivedbytes: { - label: 'label.bytes.received', - converter: function(args) { - if (args == null || args == 0) - return ""; - else - return cloudStack.converters.convertBytes(args); - } - }, - sentbytes: { - label: 'label.bytes.sent', - converter: function(args) { - if (args == null || args == 0) - return ""; - else - return cloudStack.converters.convertBytes(args); - } - } - } - ], - - dataProvider: function(args) { - var data = { - id: args.context.accounts[0].id - }; - $.ajax({ - url: createURL('listAccounts'), - data: data, - success: function(json) { - var accountObj = json.listaccountsresponse.account[0]; - var data = { - domainid: accountObj.domainid, - account: accountObj.name - }; - $.ajax({ - url: createURL('listResourceLimits'), - data: data, - success: function(json) { - var limits = json.listresourcelimitsresponse.resourcelimit; - if (limits != null) { - for (var i = 0; i < limits.length; i++) { - var limit = limits[i]; - switch (limit.resourcetype) { - case "0": - accountObj["vmLimit"] = limit.max; - break; - case "1": - accountObj["ipLimit"] = limit.max; - break; - case "2": - accountObj["volumeLimit"] = limit.max; - break; - case "3": - accountObj["snapshotLimit"] = limit.max; - break; - case "4": - accountObj["templateLimit"] = limit.max; - break; - case "7": - accountObj["vpcLimit"] = limit.max; - break; - case "8": - accountObj["cpuLimit"] = limit.max; - break; - case "9": - accountObj["memoryLimit"] = limit.max; - break; - case "10": - accountObj["primaryStorageLimit"] = limit.max; - break; - case "11": - accountObj["secondaryStorageLimit"] = limit.max; - break; - } - } - } - args.response.success( - { - actionFilter: accountActionfilter, - data: accountObj - } - ); - } - }); - } - }); - } - }, - - // Granular settings for account - settings: { - title: 'Settings', - custom: cloudStack.uiCustom.granularSettings({ - dataProvider: function(args) { - $.ajax({ - url:createURL('listConfigurations&accountid=' + args.context.accounts[0].id), - data: { page: args.page, pageSize: pageSize, listAll: true }, - success:function(json){ - args.response.success({ - data:json.listconfigurationsresponse.configuration - - }); - - }, - - error:function(json){ - args.response.error(parseXMLHttpResponse(json)); - - } - }); - - }, - actions: { - edit: function(args) { - // call updateAccountLevelParameters - var data = { - name: args.data.jsonObj.name, - value: args.data.value - }; - - $.ajax({ - url:createURL('updateConfiguration&accountid=' + args.context.accounts[0].id), - data:data, - success:function(json){ - var item = json.updateconfigurationresponse.configuration; - args.response.success({data:item}); + actions: { + add: { + label: 'label.add.account', + preFilter: function(args) { + if (isAdmin()) + return true; + else + return false; + }, + messages: { + notification: function(args) { + return 'label.add.account'; + } }, - error: function(json) { - args.response.error(parseXMLHttpResponse(json)); + createForm: { + title: 'label.add.account', + desc: 'label.add.account', + fields: { + username: { + label: 'label.username', + validation: { + required: true + }, + docID: 'helpAccountUsername' + }, + password: { + label: 'label.password', + validation: { + required: true + }, + isPassword: true, + id: 'password', + docID: 'helpAccountPassword' + }, + 'password-confirm': { + label: 'label.confirm.password', + validation: { + required: true, + equalTo: '#password' + }, + isPassword: true, + docID: 'helpAccountConfirmPassword' + }, + email: { + label: 'label.email', + validation: { + required: true, + email: true + }, + docID: 'helpAccountEmail' + }, + firstname: { + label: 'label.first.name', + validation: { + required: true + }, + docID: 'helpAccountFirstName' + }, + lastname: { + label: 'label.last.name', + validation: { + required: true + }, + docID: 'helpAccountLastName' + }, + domainid: { + label: 'label.domain', + docID: 'helpAccountDomain', + validation: { + required: true + }, + select: function(args) { + var data = {}; + + if (args.context.users) { // In accounts section + data.listAll = true; + } else if (args.context.domains) { // In domain section (use specific domain) + data.id = args.context.domains[0].id; + } + + $.ajax({ + url: createURL("listDomains"), + data: data, + dataType: "json", + async: false, + success: function(json) { + var items = []; + domainObjs = json.listdomainsresponse.domain; + $(domainObjs).each(function() { + items.push({ + id: this.id, + description: this.path + }); + + if (this.level == 0) + rootDomainId = this.id; + }); + args.response.success({ + data: items + }); + } + }); + } + }, + account: { + label: 'label.account', + docID: 'helpAccountAccount' + }, + accounttype: { + label: 'label.type', + docID: 'helpAccountType', + validation: { + required: true + }, + select: function(args) { + var items = []; + items.push({ + id: 0, + description: "User" + }); //regular-user + items.push({ + id: 1, + description: "Admin" + }); //root-admin + args.response.success({ + data: items + }); + } + }, + timezone: { + label: 'label.timezone', + docID: 'helpAccountTimezone', + select: function(args) { + var items = []; + items.push({ + id: "", + description: "" + }); + for (var p in timezoneMap) + items.push({ + id: p, + description: timezoneMap[p] + }); + args.response.success({ + data: items + }); + } + }, + networkdomain: { + label: 'label.network.domain', + docID: 'helpAccountNetworkDomain', + validation: { + required: false + } + } + } + }, + + action: function(args) { + var data = { + username: args.data.username, + }; + + var password = args.data.password; + if (md5Hashed) { + password = $.md5(password); + } + $.extend(data, { + password: password + }); + + $.extend(data, { + email: args.data.email, + firstname: args.data.firstname, + lastname: args.data.lastname, + domainid: args.data.domainid + }); + + var account = args.data.account; + if (account == null || account.length == 0) { + account = args.data.username; + } + $.extend(data, { + account: account + }); + + var accountType = args.data.accounttype; + if (args.data.accounttype == "1" && args.data.domainid != rootDomainId) { //if account type is admin, but domain is not Root domain + accountType = "2"; // Change accounttype from root-domain("1") to domain-admin("2") + } + $.extend(data, { + accounttype: accountType + }); + + if (args.data.timezone != null && args.data.timezone.length > 0) { + $.extend(data, { + timezone: args.data.timezone + }); + } + + if (args.data.networkdomain != null && args.data.networkdomain.length > 0) { + $.extend(data, { + networkdomain: args.data.networkdomain + }); + } + + $.ajax({ + url: createURL('createAccount'), + type: "POST", + data: data, + success: function(json) { + var item = json.createaccountresponse.account; + args.response.success({ + data: item + }); + }, + error: function(XMLHttpResponse) { + args.response.error(parseXMLHttpResponse(XMLHttpResponse)); + } + }); + }, + + notification: { + poll: function(args) { + args.complete({ + actionFilter: accountActionfilter + }); + } + } + } + }, + + dataProvider: function(args) { + var data = {}; + listViewDataProvider(args, data); + + if ("domains" in args.context) { + $.extend(data, { + domainid: args.context.domains[0].id + }); + } + + $.ajax({ + url: createURL('listAccounts'), + data: data, + async: true, + success: function(json) { + var items = json.listaccountsresponse.account; + args.response.success({ + actionFilter: accountActionfilter, + data: items + }); + } + }); + }, + + detailView: { + name: 'Account details', + isMaximized: true, + viewAll: { + path: 'accounts.users', + label: 'label.users' + }, + + actions: { + edit: { + label: 'message.edit.account', + compactLabel: 'label.edit', + action: function(args) { + var accountObj = args.context.accounts[0]; + + var data = { + domainid: accountObj.domainid, + account: accountObj.name, + newname: args.data.name, + networkdomain: args.data.networkdomain + }; + + $.ajax({ + url: createURL('updateAccount'), + data: data, + async: false, + success: function(json) { + accountObj = json.updateaccountresponse.account; + }, + error: function(json) { + var errorMsg = parseXMLHttpResponse(json); + args.response.error(errorMsg); + } + }); + + if (args.data.vmLimit != null) { + var data = { + resourceType: 0, + max: args.data.vmLimit, + domainid: accountObj.domainid, + account: accountObj.name + }; + $.ajax({ + url: createURL('updateResourceLimit'), + data: data, + async: false, + success: function(json) { + accountObj["vmLimit"] = args.data.vmLimit; + } + }); + } + + if (args.data.ipLimit != null) { + var data = { + resourceType: 1, + max: args.data.ipLimit, + domainid: accountObj.domainid, + account: accountObj.name + }; + $.ajax({ + url: createURL('updateResourceLimit'), + data: data, + async: false, + success: function(json) { + accountObj["ipLimit"] = args.data.ipLimit; + } + }); + } + + if (args.data.volumeLimit != null) { + var data = { + resourceType: 2, + max: args.data.volumeLimit, + domainid: accountObj.domainid, + account: accountObj.name + }; + $.ajax({ + url: createURL('updateResourceLimit'), + data: data, + async: false, + success: function(json) { + accountObj["volumeLimit"] = args.data.volumeLimit; + } + }); + } + + if (args.data.snapshotLimit != null) { + var data = { + resourceType: 3, + max: args.data.snapshotLimit, + domainid: accountObj.domainid, + account: accountObj.name + }; + $.ajax({ + url: createURL('updateResourceLimit'), + data: data, + async: false, + success: function(json) { + accountObj["snapshotLimit"] = args.data.snapshotLimit; + } + }); + } + + if (args.data.templateLimit != null) { + var data = { + resourceType: 4, + max: args.data.templateLimit, + domainid: accountObj.domainid, + account: accountObj.name + }; + $.ajax({ + url: createURL('updateResourceLimit'), + data: data, + async: false, + success: function(json) { + accountObj["templateLimit"] = args.data.templateLimit; + } + }); + } + + if (args.data.vpcLimit != null) { + var data = { + resourceType: 7, + max: args.data.vpcLimit, + domainid: accountObj.domainid, + account: accountObj.name + }; + + $.ajax({ + url: createURL('updateResourceLimit'), + data: data, + async: false, + success: function(json) { + accountObj["vpcLimit"] = args.data.vpcLimit; + } + }); + } + + if (args.data.cpuLimit != null) { + var data = { + resourceType: 8, + max: args.data.cpuLimit, + domainid: accountObj.domainid, + account: accountObj.name + }; + + $.ajax({ + url: createURL('updateResourceLimit'), + data: data, + async: false, + success: function(json) { + accountObj["cpuLimit"] = args.data.cpuLimit; + } + }); + } + + if (args.data.memoryLimit != null) { + var data = { + resourceType: 9, + max: args.data.memoryLimit, + domainid: accountObj.domainid, + account: accountObj.name + }; + + $.ajax({ + url: createURL('updateResourceLimit'), + data: data, + async: false, + success: function(json) { + accountObj["memoryLimit"] = args.data.memoryLimit; + } + }); + } + + if (args.data.primaryStorageLimit != null) { + var data = { + resourceType: 10, + max: args.data.primaryStorageLimit, + domainid: accountObj.domainid, + account: accountObj.name + }; + + $.ajax({ + url: createURL('updateResourceLimit'), + data: data, + async: false, + success: function(json) { + accountObj["primaryStorageLimit"] = args.data.primaryStorageLimit; + } + }); + } + + if (args.data.secondaryStorageLimit != null) { + var data = { + resourceType: 11, + max: args.data.secondaryStorageLimit, + domainid: accountObj.domainid, + account: accountObj.name + }; + + $.ajax({ + url: createURL('updateResourceLimit'), + data: data, + async: false, + success: function(json) { + accountObj["secondaryStorageLimit"] = args.data.secondaryStorageLimit; + } + }); + } + args.response.success({ + data: accountObj + }); + } + }, + + updateResourceCount: { + label: 'label.action.update.resource.count', + messages: { + confirm: function(args) { + return 'message.update.resource.count'; + }, + notification: function(args) { + return 'label.action.update.resource.count'; + } + }, + action: function(args) { + var accountObj = args.context.accounts[0]; + var data = { + domainid: accountObj.domainid, + account: accountObj.name + }; + + $.ajax({ + url: createURL('updateResourceCount'), + data: data, + async: true, + success: function(json) { + //var resourcecounts= json.updateresourcecountresponse.resourcecount; //do nothing + args.response.success(); + }, + error: function(json) { + args.response.error(parseXMLHttpResponse(json)); + } + }); + }, + notification: { + poll: function(args) { + args.complete(); + } + } + }, + + disable: { + label: 'label.action.disable.account', + messages: { + confirm: function(args) { + return 'message.disable.account'; + }, + notification: function(args) { + return 'label.action.disable.account'; + } + }, + action: function(args) { + var accountObj = args.context.accounts[0]; + var data = { + lock: false, + domainid: accountObj.domainid, + account: accountObj.name + }; + + $.ajax({ + url: createURL('disableAccount'), + data: data, + async: true, + success: function(json) { + var jid = json.disableaccountresponse.jobid; + args.response.success({ + _custom: { + jobId: jid, + getUpdatedItem: function(json) { + return json.queryasyncjobresultresponse.jobresult.account; + }, + getActionFilter: function() { + return accountActionfilter; + } + } + }); + } + }); + }, + notification: { + poll: pollAsyncJobResult + } + }, + + lock: { + label: 'label.action.lock.account', + messages: { + confirm: function(args) { + return 'message.lock.account'; + }, + notification: function(args) { + return 'label.action.lock.account'; + } + }, + action: function(args) { + var accountObj = args.context.accounts[0]; + var data = { + lock: true, + domainid: accountObj.domainid, + account: accountObj.name + }; + + $.ajax({ + url: createURL('disableAccount'), + data: data, + async: true, + success: function(json) { + var jid = json.disableaccountresponse.jobid; + args.response.success({ + _custom: { + jobId: jid, + getUpdatedItem: function(json) { + return json.queryasyncjobresultresponse.jobresult.account; + }, + getActionFilter: function() { + return accountActionfilter; + } + } + }); + } + }); + }, + notification: { + poll: pollAsyncJobResult + } + }, + + enable: { + label: 'label.action.enable.account', + messages: { + confirm: function(args) { + return 'message.enable.account'; + }, + notification: function(args) { + return 'label.action.enable.account'; + } + }, + action: function(args) { + var accountObj = args.context.accounts[0]; + var data = { + domainid: accountObj.domainid, + account: accountObj.name + }; + $.ajax({ + url: createURL('enableAccount'), + data: data, + async: true, + success: function(json) { + args.response.success({ + data: json.enableaccountresponse.account + }); + } + }); + }, + notification: { + poll: function(args) { + args.complete({ + data: { + state: 'enabled' + } + }); + } + } + }, + + remove: { + label: 'label.action.delete.account', + messages: { + confirm: function(args) { + return 'message.delete.account'; + }, + notification: function(args) { + return 'label.action.delete.account'; + } + }, + action: function(args) { + var data = { + id: args.context.accounts[0].id + }; + $.ajax({ + url: createURL('deleteAccount'), + data: data, + async: true, + success: function(json) { + var jid = json.deleteaccountresponse.jobid; + args.response.success({ + _custom: { + jobId: jid, + getUpdatedItem: function(json) { + return {}; //nothing in this account needs to be updated, in fact, this whole account has being deleted + }, + getActionFilter: function() { + return accountActionfilter; + } + } + }); + } + }); + }, + notification: { + poll: pollAsyncJobResult + } } - }); + }, - } - } - }) - } - } - } - } - }, - users: { - type: 'select', - id: 'users', - title: 'label.users', - listView: { - id: 'users', - fields: { - username: { label: 'label.username', editable: true }, - firstname: { label: 'label.first.name' }, - lastname: { label: 'label.last.name' } - }, - dataProvider: function(args) { - var accountObj = args.context.accounts[0]; - - if(isAdmin() || isDomainAdmin()) { - var data = { - domainid: accountObj.domainid, - account: accountObj.name - }; - listViewDataProvider(args, data); - - $.ajax({ - url: createURL('listUsers'), - data: data, - success: function(json) { - args.response.success({ - actionFilter: userActionfilter, - data: json.listusersresponse.user - }); - } - }) - } - else { //normal user doesn't have access listUsers API until Bug 14127 is fixed. - args.response.success({ - actionFilter: userActionfilter, - data: accountObj.user - }); - } - }, - actions: { - add: { - label: 'label.add.user', + tabs: { + details: { + title: 'label.details', - preFilter: function(args) { - if(isAdmin()) - return true; - else - return false; - }, + fields: [{ + name: { + label: 'label.name', + isEditable: true, + validation: { + required: true + } + } + }, { + id: { + label: 'ID' + }, + accounttype: { + label: 'label.role', + converter: function(args) { + return cloudStack.converters.toRole(args); + } + }, + domain: { + label: 'label.domain' + }, + state: { + label: 'label.state' + }, + networkdomain: { + label: 'label.network.domain', + isEditable: true + }, + vmLimit: { + label: 'label.instance.limits', + isEditable: function(context) { - messages: { - notification: function(args) { - return 'label.add.user'; - } - }, + if (context.accounts == undefined) + return false; + else { + 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: 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: 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: 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: 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: 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; + } + }, + cpuLimit: { + label: 'label.cpu.limits', + 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; + } + }, + memoryLimit: { + label: 'label.memory.limits', + 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; + } + }, + primaryStorageLimit: { + label: 'label.primary.storage.limits', + 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; + } + }, + secondaryStorageLimit: { + label: 'label.secondary.storage.limits', + 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; + } + }, - createForm: { - title: 'label.add.user', - fields: { - username: { - label: 'label.username', - validation: { required: true }, - docID: 'helpUserUsername' - }, - password: { - label: 'label.password', - isPassword: true, - validation: { required: true }, - id: 'password', - docID: 'helpUserPassword' - }, - 'password-confirm': { - label: 'label.confirm.password', - docID: 'helpUserConfirmPassword', - validation: { - required: true, - equalTo: '#password' - }, - isPassword: true - }, - email: { - label: 'label.email', - docID: 'helpUserEmail', - validation: { required: true, email: true } - }, - firstname: { - label: 'label.first.name', - docID: 'helpUserFirstName', - validation: { required: true } - }, - lastname: { - label: 'label.last.name', - docID: 'helpUserLastName', - validation: { required: true } - }, - timezone: { - label: 'label.timezone', - docID: 'helpUserTimezone', - select: function(args) { - var items = []; - items.push({id: "", description: ""}); - for(var p in timezoneMap) - items.push({id: p, description: timezoneMap[p]}); - args.response.success({data: items}); - } - } - } - }, + vmtotal: { + label: 'label.total.of.vm' + }, + iptotal: { + label: 'label.total.of.ip' + }, + receivedbytes: { + label: 'label.bytes.received', + converter: function(args) { + if (args == null || args == 0) + return ""; + else + return cloudStack.converters.convertBytes(args); + } + }, + sentbytes: { + label: 'label.bytes.sent', + converter: function(args) { + if (args == null || args == 0) + return ""; + else + return cloudStack.converters.convertBytes(args); + } + } + }], - action: function(args) { - var accountObj = args.context.accounts[0]; + dataProvider: function(args) { + var data = { + id: args.context.accounts[0].id + }; + $.ajax({ + url: createURL('listAccounts'), + data: data, + success: function(json) { + var accountObj = json.listaccountsresponse.account[0]; + var data = { + domainid: accountObj.domainid, + account: accountObj.name + }; + $.ajax({ + url: createURL('listResourceLimits'), + data: data, + success: function(json) { + var limits = json.listresourcelimitsresponse.resourcelimit; + if (limits != null) { + for (var i = 0; i < limits.length; i++) { + var limit = limits[i]; + switch (limit.resourcetype) { + case "0": + accountObj["vmLimit"] = limit.max; + break; + case "1": + accountObj["ipLimit"] = limit.max; + break; + case "2": + accountObj["volumeLimit"] = limit.max; + break; + case "3": + accountObj["snapshotLimit"] = limit.max; + break; + case "4": + accountObj["templateLimit"] = limit.max; + break; + case "7": + accountObj["vpcLimit"] = limit.max; + break; + case "8": + accountObj["cpuLimit"] = limit.max; + break; + case "9": + accountObj["memoryLimit"] = limit.max; + break; + case "10": + accountObj["primaryStorageLimit"] = limit.max; + break; + case "11": + accountObj["secondaryStorageLimit"] = limit.max; + break; + } + } + } + args.response.success({ + actionFilter: accountActionfilter, + data: accountObj + }); + } + }); + } + }); + } + }, - var data = { - username: args.data.username - }; - - var password = args.data.password; - if (md5Hashed) { - password = $.md5(password); - } - $.extend(data, { - password: password - }); - - $.extend(data, { - email: args.data.email, - firstname: args.data.firstname, - lastname: args.data.lastname - }); - - if(args.data.timezone != null && args.data.timezone.length > 0) { - $.extend(data, { - timezone: args.data.timezone - }); - } - - $.extend(data, { - domainid: accountObj.domainid, - account: accountObj.name, - accounttype: accountObj.accounttype - }); - - $.ajax({ - url: createURL('createUser'), - type: "POST", - data: data, - success: function(json) { - var item = json.createuserresponse.user; - args.response.success({data: item}); - }, - error: function(XMLHttpResponse) { - var errorMsg = parseXMLHttpResponse(XMLHttpResponse); - args.response.error(errorMsg); - } - }); - }, + // Granular settings for account + settings: { + title: 'Settings', + custom: cloudStack.uiCustom.granularSettings({ + dataProvider: function(args) { + $.ajax({ + url: createURL('listConfigurations&accountid=' + args.context.accounts[0].id), + data: { + page: args.page, + pageSize: pageSize, + listAll: true + }, + success: function(json) { + args.response.success({ + data: json.listconfigurationsresponse.configuration - notification: { - poll: function(args) { - args.complete(); - } - } - } - }, + }); - detailView: { - name: 'User details', - isMaximized: true, - actions: { - edit: { - label: 'label.edit', - action: function(args) { - var data = { - id: args.context.users[0].id, - username: args.data.username, - email: args.data.email, - firstname: args.data.firstname, - lastname: args.data.lastname, - timezone: args.data.timezone - }; - $.ajax({ - url: createURL('updateUser'), - data: data, - success: function(json) { - var item = json.updateuserresponse.user; - args.response.success({data:item}); - }, - error: function(data) { - args.response.error(parseXMLHttpResponse(data)); - } - }); + }, - } - }, + error: function(json) { + args.response.error(parseXMLHttpResponse(json)); - changePassword: { - label: 'label.action.change.password', - messages: { - notification: function(args) { - return 'label.action.change.password'; - } - }, - createForm: { - title: 'label.action.change.password', - fields: { - newPassword: { - label: 'label.new.password', - isPassword: true, - validation: { required: true }, - id: 'newPassword' - }, - 'password-confirm': { - label: 'label.confirm.password', - validation: { - required: true, - equalTo: '#newPassword' - }, - isPassword: true - } - } - }, - action: function(args) { - var password = args.data.newPassword; - if (md5Hashed) - password = $.md5(password); - - var data = { - id: args.context.users[0].id, - password: password - }; - - $.ajax({ - url: createURL('updateUser'), - data: data, - async: true, - success: function(json) { - args.response.success({data: json.updateuserresponse.user}); - } - }); - }, - notification: { - poll: function(args) { - args.complete(); - } - } - }, + } + }); - generateKeys: { - label: 'label.action.generate.keys', - messages: { - confirm: function(args) { - return 'message.generate.keys'; - }, - notification: function(args) { - return 'label.action.generate.keys'; - } - }, - action: function(args) { - var data = { - id: args.context.users[0].id - }; - $.ajax({ - url: createURL('registerUserKeys'), - data: data, - success: function(json) { - args.response.success({data: json.registeruserkeysresponse.userkeys}); - } - }); - }, - notification: { - poll: function(args) { - args.complete(); - } - } - }, + }, + actions: { + edit: function(args) { + // call updateAccountLevelParameters + var data = { + name: args.data.jsonObj.name, + value: args.data.value + }; - disable: { - label: 'label.action.disable.user', - messages: { - confirm: function(args) { - return 'message.disable.user'; - }, - notification: function(args) { - return 'label.action.disable.user'; - } - }, - action: function(args) { - var data = { - id: args.context.users[0].id - }; - $.ajax({ - url: createURL('disableUser'), - data: data, - success: function(json) { - var jid = json.disableuserresponse.jobid; - args.response.success( - {_custom: - {jobId: jid, - getUpdatedItem: function(json) { - return json.queryasyncjobresultresponse.jobresult.user; - }, - getActionFilter: function() { - return userActionfilter; - } - } + $.ajax({ + url: createURL('updateConfiguration&accountid=' + args.context.accounts[0].id), + data: data, + success: function(json) { + var item = json.updateconfigurationresponse.configuration; + args.response.success({ + data: item + }); + }, + + error: function(json) { + args.response.error(parseXMLHttpResponse(json)); + } + + }); + + } + } + }) + } } - ); } - }); - }, - notification: { - poll: pollAsyncJobResult } - }, - - enable: { - label: 'label.action.enable.user', - messages: { - confirm: function(args) { - return 'message.enable.user'; - }, - notification: function(args) { - return 'label.action.enable.user'; - } - }, - action: function(args) { - var data = { - id: args.context.users[0].id - }; - $.ajax({ - url: createURL('enableUser'), - data: data, - success: function(json) { - args.response.success({data: json.enableuserresponse.user}); - }, - error: function(json) { - args.response.error(parseXMLHttpResponse(json)); - } - }); - }, - notification: { - poll: function(args) { - args.complete(); - } - } - }, - - remove: { - label: 'label.action.delete.user', - messages: { - confirm: function(args) { - return 'message.delete.user'; - }, - notification: function(args) { - return 'label.action.delete.user'; - } - }, - action: function(args) { - var data = { - id: args.context.users[0].id - }; - $.ajax({ - url: createURL('deleteUser'), - data: data, - success: function(json) { - args.response.success(); - } - }); - }, - notification: { - poll: function(args) { - args.complete(); - } - } - } }, - tabs: { - details: { - title: 'label.details', + users: { + type: 'select', + id: 'users', + title: 'label.users', + listView: { + id: 'users', + fields: { + username: { + label: 'label.username', + editable: true + }, + firstname: { + label: 'label.first.name' + }, + lastname: { + label: 'label.last.name' + } + }, + dataProvider: function(args) { + var accountObj = args.context.accounts[0]; - fields: [ - { - username: { - label: 'label.name', - isEditable: true, - validation: { required: true } - } - }, - { - id: { label: 'ID' }, - state: { label: 'label.state' }, - apikey: { label: 'label.api.key' }, - secretkey: { label: 'label.secret.key' }, - account: { label: 'label.account.name' }, - accounttype: { - label: 'label.role', - converter: function(args) { - return cloudStack.converters.toRole(args); - } - }, - domain: { label: 'label.domain' }, - email: { - label: 'label.email', - isEditable: true, - validation: { required: true, email: true } - }, - firstname: { - label: 'label.first.name', - isEditable: true, - validation: { required: true } - }, - lastname: { - label: 'label.last.name', - isEditable: true, - validation: { required: true } - }, - timezone: { - label: 'label.timezone', - converter: function(args) { - if(args == null || args.length == 0) - return ""; - else - return args; - }, - isEditable: true, - select: function(args) { - var items = []; - items.push({id: "", description: ""}); - for(var p in timezoneMap) - items.push({id: p, description: timezoneMap[p]}); - args.response.success({data: items}); - } - } - } - ], + if (isAdmin() || isDomainAdmin()) { + var data = { + domainid: accountObj.domainid, + account: accountObj.name + }; + listViewDataProvider(args, data); - dataProvider: function(args) { - if(isAdmin() || isDomainAdmin()) { - $.ajax({ - url: createURL('listUsers'), - data: { - id: args.context.users[0].id - }, - success: function(json) { - args.response.success({ - actionFilter: userActionfilter, - data: json.listusersresponse.user[0] - }); - } - }); - } - else { //normal user doesn't have access listUsers API until Bug 14127 is fixed. - args.response.success({ - actionFilter: userActionfilter, - data: args.context.users[0] - }); - } + $.ajax({ + url: createURL('listUsers'), + data: data, + success: function(json) { + args.response.success({ + actionFilter: userActionfilter, + data: json.listusersresponse.user + }); + } + }) + } else { //normal user doesn't have access listUsers API until Bug 14127 is fixed. + args.response.success({ + actionFilter: userActionfilter, + data: accountObj.user + }); + } + }, + actions: { + add: { + label: 'label.add.user', + + preFilter: function(args) { + if (isAdmin()) + return true; + else + return false; + }, + + messages: { + notification: function(args) { + return 'label.add.user'; + } + }, + + createForm: { + title: 'label.add.user', + fields: { + username: { + label: 'label.username', + validation: { + required: true + }, + docID: 'helpUserUsername' + }, + password: { + label: 'label.password', + isPassword: true, + validation: { + required: true + }, + id: 'password', + docID: 'helpUserPassword' + }, + 'password-confirm': { + label: 'label.confirm.password', + docID: 'helpUserConfirmPassword', + validation: { + required: true, + equalTo: '#password' + }, + isPassword: true + }, + email: { + label: 'label.email', + docID: 'helpUserEmail', + validation: { + required: true, + email: true + } + }, + firstname: { + label: 'label.first.name', + docID: 'helpUserFirstName', + validation: { + required: true + } + }, + lastname: { + label: 'label.last.name', + docID: 'helpUserLastName', + validation: { + required: true + } + }, + timezone: { + label: 'label.timezone', + docID: 'helpUserTimezone', + select: function(args) { + var items = []; + items.push({ + id: "", + description: "" + }); + for (var p in timezoneMap) + items.push({ + id: p, + description: timezoneMap[p] + }); + args.response.success({ + data: items + }); + } + } + } + }, + + action: function(args) { + var accountObj = args.context.accounts[0]; + + var data = { + username: args.data.username + }; + + var password = args.data.password; + if (md5Hashed) { + password = $.md5(password); + } + $.extend(data, { + password: password + }); + + $.extend(data, { + email: args.data.email, + firstname: args.data.firstname, + lastname: args.data.lastname + }); + + if (args.data.timezone != null && args.data.timezone.length > 0) { + $.extend(data, { + timezone: args.data.timezone + }); + } + + $.extend(data, { + domainid: accountObj.domainid, + account: accountObj.name, + accounttype: accountObj.accounttype + }); + + $.ajax({ + url: createURL('createUser'), + type: "POST", + data: data, + success: function(json) { + var item = json.createuserresponse.user; + args.response.success({ + data: item + }); + }, + error: function(XMLHttpResponse) { + var errorMsg = parseXMLHttpResponse(XMLHttpResponse); + args.response.error(errorMsg); + } + }); + }, + + notification: { + poll: function(args) { + args.complete(); + } + } + } + }, + + detailView: { + name: 'User details', + isMaximized: true, + actions: { + edit: { + label: 'label.edit', + action: function(args) { + var data = { + id: args.context.users[0].id, + username: args.data.username, + email: args.data.email, + firstname: args.data.firstname, + lastname: args.data.lastname, + timezone: args.data.timezone + }; + $.ajax({ + url: createURL('updateUser'), + data: data, + success: function(json) { + var item = json.updateuserresponse.user; + args.response.success({ + data: item + }); + }, + error: function(data) { + args.response.error(parseXMLHttpResponse(data)); + } + }); + + } + }, + + changePassword: { + label: 'label.action.change.password', + messages: { + notification: function(args) { + return 'label.action.change.password'; + } + }, + createForm: { + title: 'label.action.change.password', + fields: { + newPassword: { + label: 'label.new.password', + isPassword: true, + validation: { + required: true + }, + id: 'newPassword' + }, + 'password-confirm': { + label: 'label.confirm.password', + validation: { + required: true, + equalTo: '#newPassword' + }, + isPassword: true + } + } + }, + action: function(args) { + var password = args.data.newPassword; + if (md5Hashed) + password = $.md5(password); + + var data = { + id: args.context.users[0].id, + password: password + }; + + $.ajax({ + url: createURL('updateUser'), + data: data, + async: true, + success: function(json) { + args.response.success({ + data: json.updateuserresponse.user + }); + } + }); + }, + notification: { + poll: function(args) { + args.complete(); + } + } + }, + + generateKeys: { + label: 'label.action.generate.keys', + messages: { + confirm: function(args) { + return 'message.generate.keys'; + }, + notification: function(args) { + return 'label.action.generate.keys'; + } + }, + action: function(args) { + var data = { + id: args.context.users[0].id + }; + $.ajax({ + url: createURL('registerUserKeys'), + data: data, + success: function(json) { + args.response.success({ + data: json.registeruserkeysresponse.userkeys + }); + } + }); + }, + notification: { + poll: function(args) { + args.complete(); + } + } + }, + + disable: { + label: 'label.action.disable.user', + messages: { + confirm: function(args) { + return 'message.disable.user'; + }, + notification: function(args) { + return 'label.action.disable.user'; + } + }, + action: function(args) { + var data = { + id: args.context.users[0].id + }; + $.ajax({ + url: createURL('disableUser'), + data: data, + success: function(json) { + var jid = json.disableuserresponse.jobid; + args.response.success({ + _custom: { + jobId: jid, + getUpdatedItem: function(json) { + return json.queryasyncjobresultresponse.jobresult.user; + }, + getActionFilter: function() { + return userActionfilter; + } + } + }); + } + }); + }, + notification: { + poll: pollAsyncJobResult + } + }, + + enable: { + label: 'label.action.enable.user', + messages: { + confirm: function(args) { + return 'message.enable.user'; + }, + notification: function(args) { + return 'label.action.enable.user'; + } + }, + action: function(args) { + var data = { + id: args.context.users[0].id + }; + $.ajax({ + url: createURL('enableUser'), + data: data, + success: function(json) { + args.response.success({ + data: json.enableuserresponse.user + }); + }, + error: function(json) { + args.response.error(parseXMLHttpResponse(json)); + } + }); + }, + notification: { + poll: function(args) { + args.complete(); + } + } + }, + + remove: { + label: 'label.action.delete.user', + messages: { + confirm: function(args) { + return 'message.delete.user'; + }, + notification: function(args) { + return 'label.action.delete.user'; + } + }, + action: function(args) { + var data = { + id: args.context.users[0].id + }; + $.ajax({ + url: createURL('deleteUser'), + data: data, + success: function(json) { + args.response.success(); + } + }); + }, + notification: { + poll: function(args) { + args.complete(); + } + } + } + }, + tabs: { + details: { + title: 'label.details', + + fields: [{ + username: { + label: 'label.name', + isEditable: true, + validation: { + required: true + } + } + }, { + id: { + label: 'ID' + }, + state: { + label: 'label.state' + }, + apikey: { + label: 'label.api.key' + }, + secretkey: { + label: 'label.secret.key' + }, + account: { + label: 'label.account.name' + }, + accounttype: { + label: 'label.role', + converter: function(args) { + return cloudStack.converters.toRole(args); + } + }, + domain: { + label: 'label.domain' + }, + email: { + label: 'label.email', + isEditable: true, + validation: { + required: true, + email: true + } + }, + firstname: { + label: 'label.first.name', + isEditable: true, + validation: { + required: true + } + }, + lastname: { + label: 'label.last.name', + isEditable: true, + validation: { + required: true + } + }, + timezone: { + label: 'label.timezone', + converter: function(args) { + if (args == null || args.length == 0) + return ""; + else + return args; + }, + isEditable: true, + select: function(args) { + var items = []; + items.push({ + id: "", + description: "" + }); + for (var p in timezoneMap) + items.push({ + id: p, + description: timezoneMap[p] + }); + args.response.success({ + data: items + }); + } + } + }], + + dataProvider: function(args) { + if (isAdmin() || isDomainAdmin()) { + $.ajax({ + url: createURL('listUsers'), + data: { + id: args.context.users[0].id + }, + success: function(json) { + args.response.success({ + actionFilter: userActionfilter, + data: json.listusersresponse.user[0] + }); + } + }); + } else { //normal user doesn't have access listUsers API until Bug 14127 is fixed. + args.response.success({ + actionFilter: userActionfilter, + data: args.context.users[0] + }); + } + } + } + } + } } - } } - } } - } - } - }; + }; - var accountActionfilter = function(args) { - var jsonObj = args.context.item; - var allowedActions = []; + var accountActionfilter = function(args) { + var jsonObj = args.context.item; + var allowedActions = []; - if (jsonObj.state == 'Destroyed') return []; + if (jsonObj.state == 'Destroyed') return []; - if( isAdmin() && jsonObj.isdefault == false) - allowedActions.push("remove"); - - if(isAdmin()) { - 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"); - } else if(jsonObj.state == "disabled" || jsonObj.state == "locked") { - allowedActions.push("enable"); - } + if (isAdmin() && jsonObj.isdefault == false) allowedActions.push("remove"); + + if (isAdmin()) { + 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"); + } else if (jsonObj.state == "disabled" || jsonObj.state == "locked") { + allowedActions.push("enable"); + } + allowedActions.push("remove"); + } + allowedActions.push("updateResourceCount"); + } else if (isDomainAdmin()) { + allowedActions.push("updateResourceCount"); } - allowedActions.push("updateResourceCount"); - } else if(isDomainAdmin()) { - allowedActions.push("updateResourceCount"); + return allowedActions; } - return allowedActions; - } - var userActionfilter = function(args) { - var jsonObj = args.context.item; - var allowedActions = []; - - if( isAdmin() && jsonObj.isdefault == false) - allowedActions.push("remove"); + var userActionfilter = function(args) { + var jsonObj = args.context.item; + var allowedActions = []; - if(isAdmin()) { - allowedActions.push("edit"); - allowedActions.push("changePassword"); - allowedActions.push("generateKeys"); - if(!(jsonObj.domain == "ROOT" && jsonObj.account == "admin" && jsonObj.accounttype == 1)) { //if not system-generated default admin account user - if(jsonObj.state == "enabled") - allowedActions.push("disable"); - if(jsonObj.state == "disabled") - allowedActions.push("enable"); - allowedActions.push("remove"); - } - } else { - if(isSelfOrChildDomainUser(jsonObj.username, jsonObj.accounttype, jsonObj.domainid, jsonObj.iscallerchilddomain)) { + if (isAdmin() && jsonObj.isdefault == false) + allowedActions.push("remove"); + + if (isAdmin()) { + allowedActions.push("edit"); allowedActions.push("changePassword"); allowedActions.push("generateKeys"); + if (!(jsonObj.domain == "ROOT" && jsonObj.account == "admin" && jsonObj.accounttype == 1)) { //if not system-generated default admin account user + if (jsonObj.state == "enabled") + allowedActions.push("disable"); + if (jsonObj.state == "disabled") + allowedActions.push("enable"); + allowedActions.push("remove"); + } + } else { + if (isSelfOrChildDomainUser(jsonObj.username, jsonObj.accounttype, jsonObj.domainid, jsonObj.iscallerchilddomain)) { + allowedActions.push("changePassword"); + allowedActions.push("generateKeys"); + } } + return allowedActions; } - return allowedActions; - } })(cloudStack); diff --git a/ui/scripts/affinity.js b/ui/scripts/affinity.js index a9c66957ad5..8a8869453e7 100644 --- a/ui/scripts/affinity.js +++ b/ui/scripts/affinity.js @@ -15,169 +15,193 @@ // specific language governing permissions and limitations // under the License. (function(cloudStack) { - cloudStack.sections.affinityGroups = { - title: 'label.affinity.groups', - listView: { - id: 'affinityGroups', - fields: { - name: { label: 'label.name' }, - type: { label: 'label.type' } - }, - dataProvider: function(args) { - var data = {}; - if (args.context != null) { - if ("instances" in args.context) { - $.extend(data, { - virtualmachineid: args.context.instances[0].id - }); - } - } - $.ajax({ - url: createURL('listAffinityGroups'), - data: data, - success: function(json) { - var items = json.listaffinitygroupsresponse.affinitygroup; - args.response.success({data: items}); - } - }); - }, - actions: { - add: { - label: 'label.add.affinity.group', - - messages: { - notification: function(args) { - return 'label.add.affinity.group'; - } - }, - - createForm: { - title: 'label.add.affinity.group', + cloudStack.sections.affinityGroups = { + title: 'label.affinity.groups', + listView: { + id: 'affinityGroups', fields: { - name: { - label: 'label.name', - validation: { required: true } - }, - description: { - label: 'label.description' - }, - type: { - label: 'label.type', - select: function(args) { - $.ajax({ - url: createURL('listAffinityGroupTypes'), - success: function(json) { - var types = []; - var items = json.listaffinitygrouptypesresponse.affinityGroupType; - if(items != null) { - for(var i = 0; i < items.length; i++) { - types.push({id: items[i].type, description: items[i].type}); - } - } - args.response.success({data: types}) - } - }); + name: { + label: 'label.name' + }, + type: { + label: 'label.type' } - } - } - }, - - action: function(args) { - var data = { - name: args.data.name, - type: args.data.type - }; - if(args.data.description != null && args.data.description.length > 0) - $.extend(data, {description: args.data.description}); - - $.ajax({ - url: createURL('createAffinityGroup'), - data: data, - success: function(json) { - var jid = json.createaffinitygroupresponse.jobid; - args.response.success( - {_custom: - {jobId: jid, - getUpdatedItem: function(json) { - return json.queryasyncjobresultresponse.jobresult.affinitygroup; - } - } - } - ); - } - }); - }, - - notification: { - poll: pollAsyncJobResult - } - } - }, - detailView: { - actions: { - remove: { - label: 'label.delete.affinity.group', - messages: { - confirm: function(args) { - return 'message.delete.affinity.group'; - }, - notification: function(args) { - return 'label.delete.affinity.group'; - } }, - action: function(args) { - $.ajax({ - url: createURL('deleteAffinityGroup'), - data: { - id: args.context.affinityGroups[0].id - }, - success: function(json) { - var jid = json.deleteaffinitygroupresponse.jobid; - args.response.success({ - _custom:{ - jobId: jid - } - }); - } - }); + dataProvider: function(args) { + var data = {}; + if (args.context != null) { + if ("instances" in args.context) { + $.extend(data, { + virtualmachineid: args.context.instances[0].id + }); + } + } + $.ajax({ + url: createURL('listAffinityGroups'), + data: data, + success: function(json) { + var items = json.listaffinitygroupsresponse.affinitygroup; + args.response.success({ + data: items + }); + } + }); }, - notification: { - poll: pollAsyncJobResult - } - } - }, + actions: { + add: { + label: 'label.add.affinity.group', - viewAll: { path: 'instances', label: 'label.instances' }, - - tabs: { - details: { - title: 'label.details', - fields: [ - { - name: { label: 'label.name' } - }, - { - description: { label: 'label.description' }, - type: { label: 'label.type' }, - id: { label: 'label.id' } - } - ], + messages: { + notification: function(args) { + return 'label.add.affinity.group'; + } + }, - dataProvider: function(args) { - $.ajax({ - url: createURL('listAffinityGroups'), - data: { - id: args.context.affinityGroups[0].id - }, - success: function(json) { - var item = json.listaffinitygroupsresponse.affinitygroup[0]; - args.response.success({data: item}); - } - }); + createForm: { + title: 'label.add.affinity.group', + fields: { + name: { + label: 'label.name', + validation: { + required: true + } + }, + description: { + label: 'label.description' + }, + type: { + label: 'label.type', + select: function(args) { + $.ajax({ + url: createURL('listAffinityGroupTypes'), + success: function(json) { + var types = []; + var items = json.listaffinitygrouptypesresponse.affinityGroupType; + if (items != null) { + for (var i = 0; i < items.length; i++) { + types.push({ + id: items[i].type, + description: items[i].type + }); + } + } + args.response.success({ + data: types + }) + } + }); + } + } + } + }, + + action: function(args) { + var data = { + name: args.data.name, + type: args.data.type + }; + if (args.data.description != null && args.data.description.length > 0) + $.extend(data, { + description: args.data.description + }); + + $.ajax({ + url: createURL('createAffinityGroup'), + data: data, + success: function(json) { + var jid = json.createaffinitygroupresponse.jobid; + args.response.success({ + _custom: { + jobId: jid, + getUpdatedItem: function(json) { + return json.queryasyncjobresultresponse.jobresult.affinitygroup; + } + } + }); + } + }); + }, + + notification: { + poll: pollAsyncJobResult + } + } + }, + detailView: { + actions: { + remove: { + label: 'label.delete.affinity.group', + messages: { + confirm: function(args) { + return 'message.delete.affinity.group'; + }, + notification: function(args) { + return 'label.delete.affinity.group'; + } + }, + action: function(args) { + $.ajax({ + url: createURL('deleteAffinityGroup'), + data: { + id: args.context.affinityGroups[0].id + }, + success: function(json) { + var jid = json.deleteaffinitygroupresponse.jobid; + args.response.success({ + _custom: { + jobId: jid + } + }); + } + }); + }, + notification: { + poll: pollAsyncJobResult + } + } + }, + + viewAll: { + path: 'instances', + label: 'label.instances' + }, + + tabs: { + details: { + title: 'label.details', + fields: [{ + name: { + label: 'label.name' + } + }, { + description: { + label: 'label.description' + }, + type: { + label: 'label.type' + }, + id: { + label: 'label.id' + } + }], + + dataProvider: function(args) { + $.ajax({ + url: createURL('listAffinityGroups'), + data: { + id: args.context.affinityGroups[0].id + }, + success: function(json) { + var item = json.listaffinitygroupsresponse.affinitygroup[0]; + args.response.success({ + data: item + }); + } + }); + } + } + } } - } } - } - } - }; + }; })(cloudStack); diff --git a/ui/scripts/autoscaler.js b/ui/scripts/autoscaler.js index 15a9dac6530..d30ace89458 100644 --- a/ui/scripts/autoscaler.js +++ b/ui/scripts/autoscaler.js @@ -15,1417 +15,1454 @@ // specific language governing permissions and limitations // under the License. -(function($,cloudstack) { - var scaleUpData = []; - var totalScaleUpCondition = 0; - var scaleDownData = []; - var totalScaleDownCondition = 0; +(function($, cloudstack) { + var scaleUpData = []; + var totalScaleUpCondition = 0; + var scaleDownData = []; + var totalScaleDownCondition = 0; - cloudStack.autoscaler = { - // UI actions to appear in dialog - autoscaleActions: { - enable: { - label: 'Enable Autoscale', - action: function(args) { - $.ajax({ - url: createURL('enableAutoScaleVmGroup'), - data: { - id: args.context.originalAutoscaleData.context.autoscaleVmGroup.id - }, - success: function(json) { - var jid = json.enableautoscalevmGroupresponse.jobid; - args.response.success({ - _custom: { - jobId: jid, - getUpdatedItem: function(json) { - return json.queryasyncjobresultresponse.jobresult.autoscalevmgroup; - }, - getActionFilter: function() { - return cloudStack.autoscaler.actionFilter; - } - }, - notification: { - poll: pollAsyncJobResult - } - }); - } - }); - } - }, - disable: { - label: 'Disable Autoscale', - action: function(args) { - $.ajax({ - url: createURL('disableAutoScaleVmGroup'), - data: { - id: args.context.originalAutoscaleData.context.autoscaleVmGroup.id - }, - success: function(json) { - var jid = json.disableautoscalevmGroupresponse.jobid; - args.response.success({ - _custom: { - jobId: jid, - getUpdatedItem: function(json) { - return json.queryasyncjobresultresponse.jobresult.autoscalevmgroup; - }, - getActionFilter: function() { - return cloudStack.autoscaler.actionFilter; - } - }, - notification: { - poll: pollAsyncJobResult - } - }); - } - }); - } - } - }, - actionFilter: function(args) { - var allowedActions = []; - if(args.context.originalAutoscaleData == null) { //new LB rule - //no actions for new LB rule - } - else { //existing LB rule - if(args.context.originalAutoscaleData[0].afterActionIsComplete == null) { - if(args.context.originalAutoscaleData[0].context.autoscaleVmGroup.state == 'disabled') - allowedActions.push('enable'); - else if(args.context.originalAutoscaleData[0].context.autoscaleVmGroup.state == 'enabled') - allowedActions.push('disable'); - } - else { - if(args.context.originalAutoscaleData[0].afterActionIsComplete.state == 'disabled') - allowedActions.push('enable'); - else if(args.context.originalAutoscaleData[0].afterActionIsComplete.state == 'enabled') - allowedActions.push('disable'); - } - } - return allowedActions; - }, - dataProvider: function(args) { - // Reset data - scaleUpData = []; - totalScaleUpCondition = 0; - scaleDownData = []; - totalScaleDownCondition = 0; - - if(!('multiRules' in args.context)) { //from a new LB - args.response.success({ data: null }); - } - else { //from an existing LB - $.ajax({ - url: createURL('listAutoScaleVmGroups'), - data: { - listAll: true, - lbruleid: args.context.multiRules[0].id - }, - success: function(json) { - var autoscaleVmGroup = json.listautoscalevmgroupsresponse.autoscalevmgroup[0]; - - $.ajax({ - url: createURL('listAutoScaleVmProfiles'), - data: { - listAll: true, - id: autoscaleVmGroup.vmprofileid - }, - success: function(json) { - var autoscaleVmProfile = json.listautoscalevmprofilesresponse.autoscalevmprofile[0]; - - var scaleUpPolicy = { - id: autoscaleVmGroup.scaleuppolicies[0].id, - duration: autoscaleVmGroup.scaleuppolicies[0].duration, - conditions: [] - }; - $(autoscaleVmGroup.scaleuppolicies[0].conditions).each(function(){ - var condition = { - id: this.id, - counterid: this.counter[0].id, - relationaloperator: this.relationaloperator, - threshold: this.threshold - }; - scaleUpPolicy.conditions.push(condition); - }); - - var scaleDownPolicy = { - id: autoscaleVmGroup.scaledownpolicies[0].id, - duration: autoscaleVmGroup.scaledownpolicies[0].duration, - conditions: [] - }; - $(autoscaleVmGroup.scaledownpolicies[0].conditions).each(function(){ - var condition = { - id: this.id, - counterid: this.counter[0].id, - relationaloperator: this.relationaloperator, - threshold: this.threshold.toString() - }; - scaleDownPolicy.conditions.push(condition); - }); - - var diskOfferingId, securityGroups; - var otherdeployparams = autoscaleVmProfile.otherdeployparams; - if(otherdeployparams != null && otherdeployparams.length > 0) { - var array1 = otherdeployparams.split('&'); - $(array1).each(function(){ - var array2 = this.split('='); - if(array2[0] == 'diskofferingid') - diskOfferingId= array2[1]; - if(array2[0] == 'securitygroupids') - securityGroups = array2[1]; - }); - } - - var originalAutoscaleData = { - templateNames: autoscaleVmProfile.templateid, - serviceOfferingId: autoscaleVmProfile.serviceofferingid, - minInstance: autoscaleVmGroup.minmembers, - maxInstance: autoscaleVmGroup.maxmembers, - scaleUpPolicy: scaleUpPolicy, - scaleDownPolicy: scaleDownPolicy, - interval: autoscaleVmGroup.interval, - quietTime: autoscaleVmGroup.scaleuppolicies[0].quiettime, - destroyVMgracePeriod: autoscaleVmProfile.destroyvmgraceperiod, - securityGroups: securityGroups, - diskOfferingId: diskOfferingId, - snmpCommunity: autoscaleVmProfile.counterparam.snmpcommunity, - snmpPort: autoscaleVmProfile.counterparam.snmpport, - username: autoscaleVmProfile.autoscaleuserid, - context: { - autoscaleVmGroup: autoscaleVmGroup, - autoscaleVmProfile: autoscaleVmProfile - } - //isAdvanced: false // Set this to true if any advanced field data is present - }; - - args.response.success({ data: originalAutoscaleData }); - } - }); - } - }); - } - }, - - // -- - // Add the following object blocks: - // - // topFields: { } - // bottomFields: { }, - // scaleUpPolicy: { }, - // scaleDownPolicy: { } - // -- - // - forms: { - topFields: { - //** - //** Disabled due to UI issues - //** - // templateCategory: { - // label: 'Template', - // id: 'templatecategory', - // select: function(args) { - // args.response.success({ - // data: [ - // { id: 'all', description: _l('ui.listView.filters.all') }, - // { id: 'featured', description: _l('label.featured') }, - // { id: 'Community', description: _l('label.menu.community.templates') }, - // { id: 'self', description: _l('ui.listView.filters.mine') } - // ] - // }); - // } - // }, - //** - - templateNames: { - label: 'label.template', - id: 'templatename', - select: function(args) { - var templates; - var templateIdMap = {}; - $.ajax({ - url: createURL('listTemplates'), - data: { - templatefilter: 'featured', - zoneid: args.context.networks[0].zoneid - }, - async: false, - success: function(json) { - templates = json.listtemplatesresponse.template; - if (templates == null) - templates = []; - $(templates).each(function() { - templateIdMap[this.id] = 1; - }); - } - }); - - $.ajax({ - url: createURL('listTemplates'), - data: { - templatefilter: 'community', - zoneid: args.context.networks[0].zoneid - }, - async: false, - success: function(json) { - var items = json.listtemplatesresponse.template; - $(items).each(function() { - if(!(this.id in templateIdMap)) { - templates.push(this); - templateIdMap[this.id] = 1; - } - }); - } - }); - - $.ajax({ - url: createURL('listTemplates'), - data: { - templatefilter: 'selfexecutable', - zoneid: args.context.networks[0].zoneid - }, - async: false, - success: function(json) { - var items = json.listtemplatesresponse.template; - $(items).each(function() { - if(!(this.id in templateIdMap)) { - templates.push(this); - templateIdMap[this.id] = 1; - } - }); - } - }); - - args.response.success({ - data: $.map(templates, function(template) { - return { - id: template.id, - description: template.name - }; - }) - }); - } + cloudStack.autoscaler = { + // UI actions to appear in dialog + autoscaleActions: { + enable: { + label: 'Enable Autoscale', + action: function(args) { + $.ajax({ + url: createURL('enableAutoScaleVmGroup'), + data: { + id: args.context.originalAutoscaleData.context.autoscaleVmGroup.id + }, + success: function(json) { + var jid = json.enableautoscalevmGroupresponse.jobid; + args.response.success({ + _custom: { + jobId: jid, + getUpdatedItem: function(json) { + return json.queryasyncjobresultresponse.jobresult.autoscalevmgroup; + }, + getActionFilter: function() { + return cloudStack.autoscaler.actionFilter; + } + }, + notification: { + poll: pollAsyncJobResult + } + }); + } + }); + } + }, + disable: { + label: 'Disable Autoscale', + action: function(args) { + $.ajax({ + url: createURL('disableAutoScaleVmGroup'), + data: { + id: args.context.originalAutoscaleData.context.autoscaleVmGroup.id + }, + success: function(json) { + var jid = json.disableautoscalevmGroupresponse.jobid; + args.response.success({ + _custom: { + jobId: jid, + getUpdatedItem: function(json) { + return json.queryasyncjobresultresponse.jobresult.autoscalevmgroup; + }, + getActionFilter: function() { + return cloudStack.autoscaler.actionFilter; + } + }, + notification: { + poll: pollAsyncJobResult + } + }); + } + }); + } + } }, + actionFilter: function(args) { + var allowedActions = []; + if (args.context.originalAutoscaleData == null) { //new LB rule + //no actions for new LB rule + } else { //existing LB rule + if (args.context.originalAutoscaleData[0].afterActionIsComplete == null) { + if (args.context.originalAutoscaleData[0].context.autoscaleVmGroup.state == 'disabled') + allowedActions.push('enable'); + else if (args.context.originalAutoscaleData[0].context.autoscaleVmGroup.state == 'enabled') + allowedActions.push('disable'); + } else { + if (args.context.originalAutoscaleData[0].afterActionIsComplete.state == 'disabled') + allowedActions.push('enable'); + else if (args.context.originalAutoscaleData[0].afterActionIsComplete.state == 'enabled') + allowedActions.push('disable'); + } + } + return allowedActions; + }, + dataProvider: function(args) { + // Reset data + scaleUpData = []; + totalScaleUpCondition = 0; + scaleDownData = []; + totalScaleDownCondition = 0; - serviceOfferingId: { - label: 'label.compute.offering', - select: function(args) { - $.ajax({ - url: createURL("listServiceOfferings&issystem=false"), - dataType: "json", - async: true, - success: function(json) { - var serviceofferings = json.listserviceofferingsresponse.serviceoffering; + if (!('multiRules' in args.context)) { //from a new LB args.response.success({ - data: $.map(serviceofferings, function(serviceoffering) { - return { - id: serviceoffering.id, - description: serviceoffering.name - }; - }) + data: null }); - } - }); - } - }, - - minInstance: { - label: 'Min Instances', - defaultValue: '3', - validation: { - required: true, - number: true - } - }, - - maxInstance: { - label: 'Max Instances', - defaultValue: '10', - validation: { - required: true, - number: true - } - } - }, - - bottomFields: { - isAdvanced: { isBoolean: true, label: 'Show advanced settings' }, - interval: { - label: 'Polling Interval (in sec)', - defaultValue: '30', - validation: { - required: true, - number: true - } - }, - - quietTime: { - label: 'Quiet Time (in sec)', - defaultValue: '300', - validation: { - required: true, - number: true - } - }, - - destroyVMgracePeriod: { - label: 'Destroy VM Grace Period', - defaultValue: '30', - isHidden:true, - dependsOn:'isAdvanced', - validation: { - required: true, - number: true - } - }, - securityGroups: { - label: 'label.menu.security.groups', - isHidden: true, - dependsOn: 'isAdvanced', - select: function(args) { - $.ajax({ - url: createURL("listSecurityGroups&listAll=true"), - dataType: "json", - async: true, - success: function(json) { - var securitygroups = json.listsecuritygroupsresponse.securitygroup; - var items = []; - items.push({id: "", description: ""}); - $(securitygroups).each(function(){ - items.push({id: this.id, description: this.name}); - }); - args.response.success({ data: items }); - } - }); - } - }, - - diskOfferingId: { - label: 'label.menu.disk.offerings', - isHidden: true, - dependsOn: 'isAdvanced', - select: function(args) { - $.ajax({ - url: createURL("listDiskOfferings&listAll=true"), - dataType: "json", - async: true, - success: function(json) { - var diskofferings = json.listdiskofferingsresponse.diskoffering; - var items = []; - items.push({id: "", description: ""}); - $(diskofferings).each(function(){ - items.push({id: this.id, description: this.name}); - }); - args.response.success({ data: items }); - } - }); - } - }, - - snmpCommunity: { - isHidden: true, - dependsOn: 'isAdvanced', - label: 'SNMP Community', - defaultValue: 'public', - validation: { required: true } - }, - - snmpPort: { - isHidden: true, - dependsOn: 'isAdvanced', - label: 'SNMP Port', - defaultValue: '161', - validation: { - required: true, - number: true - } - }, - - username: { - isHidden: true, - dependsOn: 'isAdvanced', - label: 'User', - select: function(args) { - var items = []; - if(args.context.originalAutoscaleData == null) { //new LB rule - if(isAdmin() || isDomainAdmin()) { - $.ajax({ - url: createURL('listUsers'), - data: { - domainid: g_domainid, - account: g_account - }, - success: function(json) { - var users = json.listusersresponse.user; - $(users).each(function(){ - items.push({id: this.id, description: this.username}); - }); - args.response.success({ data: items }); - } - }); - } - else { //regular user doesn't have access to listUers API call. - items.push({id: "", description: ""}); - args.response.success({ data: items }); - } - } - else { //existing LB rule - if(isAdmin() || isDomainAdmin()) { - $.ajax({ - url: createURL('listUsers'), - data: { - domainid: args.context.originalAutoscaleData.context.autoscaleVmProfile.domainid, - account: args.context.originalAutoscaleData.context.autoscaleVmProfile.account - }, - success: function(json) { - var users = json.listusersresponse.user; - $(users).each(function(){ - items.push({id: this.id, description: this.username}); - }); - args.response.success({ data: items }); - } - }); - } - else { //regular user doesn't have access to listUers API call. - items.push({id: "", description: ""}); - args.response.success({ data: items }); - } - } - } - } - }, - scaleUpPolicy: { - title: 'ScaleUp Policy', - label: 'SCALE UP POLICY', - noSelect: true, - noHeaderActionsColumn: true, - ignoreEmptyFields: true, - fields: { - 'counterid': { - label: 'Counter', - select: function(args) { - $.ajax({ - url: createURL("listCounters"), - dataType: "json", - async: false, - success: function(json) { - var counters = json.counterresponse.counter; - - args.response.success({ - data: $.map(counters, function(counter) { - return { - name: counter.id, - description: counter.name - }; - }) - }); - } - }); - } - }, - 'relationaloperator': { - label: 'Operator', - select: function(args) { - args.response.success({ - data: [ - { name: 'GT', description: 'greater-than' }, - { name: 'GE', description: 'greater-than or equals to' }, - { name: 'LT', description: 'less-than' }, - { name: 'LE', description: 'less-than or equals to' }, - { name: 'EQ', description: 'equals-to' } - ] - }); - } - }, - 'threshold': { edit: true, label: 'Threshold' }, - 'add-scaleUpcondition': { - label: 'label.add', - addButton: true - } - }, - add: { - label: 'label.add', - action: function(args) { - scaleUpData.push($.extend(args.data, { - index: totalScaleUpCondition - })); - - totalScaleUpCondition++; - args.response.success(); - } - }, - actions: { - destroy: { - label: '', - action: function(args) { - scaleUpData = $.grep(scaleUpData, function(item) { - return item.index != args.context.multiRule[0].index; - }); - totalScaleUpCondition--; - args.response.success(); - } - } - }, - dataProvider: function(args) { - var data = scaleUpData; - var $autoscaler = $('.ui-dialog .autoscaler'); - var initialData = $autoscaler.data('autoscaler-scale-up-data'); - - if ($.isArray(initialData)) { - $(initialData).each(function() { - this.index = totalScaleUpCondition; - totalScaleUpCondition++; - scaleUpData.push(this); - }); - - $autoscaler.data('autoscaler-scale-up-data', null); - } - - args.response.success({ - data: scaleUpData - }); - } - }, - - scaleDownPolicy: { - title: 'ScaleDown Policy', - noSelect: true, - noHeaderActionsColumn: true, - ignoreEmptyFields: true, - fields: { - 'counterid': { - label: 'Counter', - select: function(args) { - $.ajax({ - url: createURL("listCounters"), - dataType: "json", - async: false, - success: function(json) { - var counters = json.counterresponse.counter; - - args.response.success({ - data: $.map(counters, function(counter) { - return { - name: counter.id, - description: counter.name - }; - }) - }); - } - }); - } - }, - 'relationaloperator': { - label: 'Operator', - select: function(args) { - args.response.success({ - data: [ - { name: 'GT', description: 'greater-than' }, - { name: 'GE', description: 'greater-than or equals to' }, - { name: 'LT', description: 'less-than' }, - { name: 'LE', description: 'less-than or equals to' }, - { name: 'EQ', description: 'equals-to' } - ] - }); - } - }, - 'threshold': { edit: true, label: 'Threshold'}, - 'add-scaleDowncondition': { - label: 'label.add', - addButton: true - } - }, - add: { - label: 'label.add', - action: function(args) { - scaleDownData.push($.extend(args.data, { - index: totalScaleDownCondition - })); - totalScaleDownCondition++; - args.response.success(); - } - }, - actions: { - destroy: { - label: '', - action: function(args) { - scaleDownData = $.grep(scaleDownData, function(item) { - return item.index != args.context.multiRule[0].index; - }); - totalScaleDownCondition--; - args.response.success(); - } - } - }, - dataProvider: function(args) { - var data = scaleDownData; - var $autoscaler = $('.ui-dialog .autoscaler'); - var initialData = $autoscaler.data('autoscaler-scale-down-data'); - - if ($.isArray(initialData)) { - $(initialData).each(function() { - this.index = totalScaleDownCondition; - totalScaleDownCondition++; - scaleDownData.push(this); - }); - - $autoscaler.data('autoscaler-scale-down-data', null); - } - - args.response.success({ - data: scaleDownData - }); - } - } - }, - - actions: { - apply: function(args) { - //validation (begin) ***** - if(!('multiRules' in args.context)) { //from a new LB - if(args.formData.name == '' || args.formData.publicport == '' || args.formData.privateport == '') { - args.response.error('Name, Public Port, Private Port of Load Balancing are required. Please close this dialog box and fill Name, Public Port, Private Port first.'); - return; - } - } - else { //from an existing LB - if(args.context.originalAutoscaleData.afterActionIsComplete == null) { - if(args.context.originalAutoscaleData.context.autoscaleVmGroup.state != 'disabled') { - args.response.error('An Autoscale VM Group can be updated only if it is in disabled state. Please disable the Autoscale VM Group first.'); - return; - } - } - else { - if(args.context.originalAutoscaleData.afterActionIsComplete.state != 'disabled') { - args.response.error('An Autoscale VM Group can be updated only if it is in disabled state. Please disable the Autoscale VM Group first.'); - return; - } - } - } - - if(isAdmin() || isDomainAdmin()) { //only admin and domain-admin has access to listUers API - var havingApiKeyAndSecretKey = false; - $.ajax({ - url: createURL('listUsers'), - data: { - id: args.data.username - }, - async: false, - success: function(json) { - if(json.listusersresponse.user[0].apikey != null && json.listusersresponse.user[0].secretkey != null) { - havingApiKeyAndSecretKey = true; - } - } - }); - if(havingApiKeyAndSecretKey == false) { - args.response.error('The selected user in advanced settings does not have API key or secret key'); - return; - } - } - - if(isAdmin()) { //only admin has access to listConfigurations API - var hasValidEndpointeUrl = false; - $.ajax({ - url: createURL('listConfigurations'), - data: { - name: 'endpointe.url' - }, - async: false, - success: function(json) { - if(json.listconfigurationsresponse.configuration != null) { - if(json.listconfigurationsresponse.configuration[0].value.indexOf('localhost') == -1) { - hasValidEndpointeUrl = true; - } - } - } - }); - if(hasValidEndpointeUrl == false) { - args.response.error("Global setting endpointe.url has to be set to the Management Server's API end point"); - return; - } - } - - //Scale Up Policy - if(args.data.scaleUpDuration == null || args.data.scaleUpDuration.length == 0) { - args.response.error("Duration of Scale Up Policy is required."); - return; - } - if(isNaN(args.data.scaleUpDuration)) { - args.response.error("Duration of Scale Up Policy should be a number."); - return; - } - if(parseInt(args.data.scaleUpDuration) < parseInt(args.data.interval)) { - args.response.error("Duration of Scale Up Policy must be greater than or equal to Polling Interval."); - return; - } - if(scaleUpData.length == 0) { - args.response.error("At least one condition is required in Scale Up Policy."); - return; - } - - //Scale Down Policy - if(args.data.scaleDownDuration == null || args.data.scaleDownDuration.length == 0) { - args.response.error("Duration of Scale Down Policy is required."); - return; - } - if(isNaN(args.data.scaleDownDuration)) { - args.response.error("Duration of Scale Down Policy should be a number."); - return; - } - if(parseInt(args.data.scaleDownDuration) < parseInt(args.data.interval)) { - args.response.error("Duration of Scale Down Policy must be greater than or equal to Polling Interval."); - return; - } - if(scaleDownData.length == 0) { - args.response.error("At least one condition is required in Scale Down Policy."); - return; - } - //validation (end) ***** - - var scaleVmProfileResponse = []; - var loadBalancerResponse = []; - var scaleVmGroupResponse = []; - var scaleUpConditionIds = []; - var scaleDownConditionIds = []; - - var scaleUp = function(args){ - var scaleUpConditionIds = []; - $(scaleUpData).each(function(){ - var data = { - counterid: this.counterid, - relationaloperator: this.relationaloperator, - threshold: this.threshold - }; - $.ajax({ - url: createURL('createCondition'), - data: data, - success: function(json) { - var createConditionIntervalID = setInterval(function() { - $.ajax({ - url: createURL("queryAsyncJobResult&jobid=" + json.conditionresponse.jobid), - dataType: "json", - success: function(json) { - var result = json.queryasyncjobresultresponse; - if(result.jobstatus == 0) { - return; - } - else { - clearInterval(createConditionIntervalID); - if(result.jobstatus == 1) { - var item = json.queryasyncjobresultresponse.jobresult.condition; - scaleUpConditionIds.push(item.id); - if (scaleUpConditionIds.length == scaleUpData.length) { - if(!('multiRules' in args.context)) { //from a new LB - var data = { - action: 'scaleup', - conditionids: scaleUpConditionIds.join(","), - duration: args.data.scaleUpDuration, - quiettime: args.data.quietTime - }; - $.ajax({ - url: createURL('createAutoScalePolicy'), - data: data, - success: function(json) { - var jobId = json.autoscalepolicyresponse.jobid; - var createAutoScalePolicyInterval = setInterval(function(){ - $.ajax({ - url: createURL("queryAsyncJobResult&jobId="+jobId), - dataType: "json", - success: function(json) { - var result = json.queryasyncjobresultresponse; - if (result.jobstatus == 0) { - return; //Job has not completed - } - else { - clearInterval(createAutoScalePolicyInterval); - if (result.jobstatus == 1) { //AutoScalePolicy successfully created - var item = result.jobresult.autoscalepolicy; - scaleDown($.extend(args, { - scaleUpPolicyResponse: item - })); - } - else if (result.jobstatus == 2) { - args.response.error(_s(result.jobresult.errortext)); - } - } - } - }); - }, g_queryAsyncJobResultInterval); - }, - error: function(XMLHttpResponse) { - args.response.error(parseXMLHttpResponse(XMLHttpResponse)); - } - }); - } - else { //from an existing LB - var data = { - id: args.context.originalAutoscaleData.scaleUpPolicy.id, - conditionids: scaleUpConditionIds.join(","), - duration: args.data.scaleUpDuration, - quiettime: args.data.quietTime - }; - - $.ajax({ - url: createURL('updateAutoScalePolicy'), - data: data, - success: function(json) { - var updateAutoScalePolicyInterval = setInterval(function(){ - $.ajax({ - url: createURL("queryAsyncJobResult&jobId=" + json.updateautoscalepolicyresponse.jobid), - dataType: "json", - success: function(json) { - var result = json.queryasyncjobresultresponse; - if (result.jobstatus == 0) { - return; //Job has not completed - } - else { - clearInterval(updateAutoScalePolicyInterval); - if (result.jobstatus == 1) { - var item = result.jobresult.autoscalepolicy; - - //delete old conditions which are orphans now. Don't need to call queryAsyncJobResult because subsequent API calls have no dependency on deleteCondition. - $(args.context.originalAutoscaleData.scaleUpPolicy.conditions).each(function(){ - $.ajax({ - url: createURL('deleteCondition'), - data: { - id: this.id - } - }); - }); - - scaleDown($.extend(args, { - scaleUpPolicyResponse: item - })); - } - else if (result.jobstatus == 2) { - args.response.error(_s(result.jobresult.errortext)); - } - } - } - }); - }, g_queryAsyncJobResultInterval); - }, - error: function(XMLHttpResponse) { - args.response.error(parseXMLHttpResponse(XMLHttpResponse)); - } - }); - } - } - } - else if(result.jobstatus == 2) { - args.response.error(_s(result.jobresult.errortext)); - } - } - } - }); - }, g_queryAsyncJobResultInterval); - }, - error: function(XMLHttpResponse) { - args.response.error(parseXMLHttpResponse(XMLHttpResponse)); - } - }); - }); - }; - - var scaleDown = function(args){ - var scaleDownConditionIds = []; - $(scaleDownData).each(function(){ - var data = { - counterid: this.counterid, - relationaloperator: this.relationaloperator, - threshold: this.threshold - }; - $.ajax({ - url: createURL('createCondition'), - data: data, - success: function(json) { - var createConditionIntervalID = setInterval(function() { - $.ajax({ - url: createURL("queryAsyncJobResult&jobid=" + json.conditionresponse.jobid), - dataType: "json", - success: function(json) { - var result = json.queryasyncjobresultresponse; - if(result.jobstatus == 0) { - return; - } - else { - clearInterval(createConditionIntervalID); - if(result.jobstatus == 1) { - var item = json.queryasyncjobresultresponse.jobresult.condition; - scaleDownConditionIds.push(item.id); - if (scaleDownConditionIds.length == scaleDownData.length) { - if(!('multiRules' in args.context)) { //from a new LB - var data = { - action: 'scaledown', - conditionids: scaleDownConditionIds.join(","), - duration: args.data.scaleDownDuration, - quiettime: args.data.quietTime - }; - $.ajax({ - url: createURL('createAutoScalePolicy'), - data: data, - success: function(json) { - var jobId = json.autoscalepolicyresponse.jobid; - var createAutoScalePolicyInterval = setInterval(function(){ - $.ajax({ - url: createURL("queryAsyncJobResult&jobId="+jobId), - dataType: "json", - success: function(json) { - var result = json.queryasyncjobresultresponse; - if (result.jobstatus == 0) { - return; //Job has not completed - } - else { - clearInterval(createAutoScalePolicyInterval); - if (result.jobstatus == 1) { //AutoScalePolicy successfully created - var item = result.jobresult.autoscalepolicy; - createOrUpdateVmProfile($.extend(args, { - scaleDownPolicyResponse: item - })); - } - else if (result.jobstatus == 2) { - args.response.error(_s(result.jobresult.errortext)); - } - } - } - }); - }, g_queryAsyncJobResultInterval); - }, - error: function(XMLHttpResponse) { - args.response.error(parseXMLHttpResponse(XMLHttpResponse)); - } - }); - } - else { //from an existing LB - var data = { - id: args.context.originalAutoscaleData.scaleDownPolicy.id, - conditionids: scaleDownConditionIds.join(","), - duration: args.data.scaleDownDuration, - quiettime: args.data.quietTime - }; - - $.ajax({ - url: createURL('updateAutoScalePolicy'), - data: data, - success: function(json) { - var jobId = json.updateautoscalepolicyresponse.jobid; - var updateAutoScalePolicyInterval = setInterval(function(){ - $.ajax({ - url: createURL("queryAsyncJobResult&jobId="+jobId), - dataType: "json", - success: function(json) { - var result = json.queryasyncjobresultresponse; - if (result.jobstatus == 0) { - return; //Job has not completed - } - else { - clearInterval(updateAutoScalePolicyInterval); - if (result.jobstatus == 1) { - var item = result.jobresult.autoscalepolicy; - - //delete old conditions which are orphans now. Don't need to call queryAsyncJobResult because subsequent API calls have no dependency on deleteCondition. - $(args.context.originalAutoscaleData.scaleDownPolicy.conditions).each(function(){ - $.ajax({ - url: createURL('deleteCondition'), - data: { - id: this.id - } - }); - }); - - createOrUpdateVmProfile($.extend(args, { - scaleDownPolicyResponse: item - })); - } - else if (result.jobstatus == 2) { - args.response.error(_s(result.jobresult.errortext)); - } - } - } - }); - }, g_queryAsyncJobResultInterval); - }, - error: function(XMLHttpResponse) { - args.response.error(parseXMLHttpResponse(XMLHttpResponse)); - } - }); - } - } - } - else if(result.jobstatus == 2) { - args.response.error(_s(result.jobresult.errortext)); - } - } - }, - error: function(XMLHttpResponse) { - args.response.error(parseXMLHttpResponse(XMLHttpResponse)); - } - }); - }, g_queryAsyncJobResultInterval); - } - }); - }); - }; - - var createOrUpdateVmProfile = function(args){ - var array1 = []; - var apiCmd, apiCmdRes; - if(!('multiRules' in args.context)) { //from a new LB - var data = { - zoneid: args.context.ipAddresses[0].zoneid, //args.context.networks[0] doesn't have zoneid property, so use args.context.ipAddresses[0] instead - serviceofferingid: args.data.serviceOfferingId, - templateid: args.data.templateNames, - destroyvmgraceperiod: args.data.destroyVMgracePeriod, - snmpcommunity: args.data.snmpCommunity, - snmpport: args.data.snmpPort - }; - - var allParamNames=$.map(data,function(value,key){ - return key; - }); - - var notParams =['zoneid','serviceofferingid','templateid','destroyvmgraceperiod']; - var index=0; - $(allParamNames).each(function() { - var param='counterparam[' + index + ']'; - var name = this.toString(); - var value = data[name]; - if(!value || $.inArray(name,notParams) >-1 ) return true; - data[param+ '.name']=name; - data[param+ '.value']=value; - index++; - delete data[name]; - - return true; - }); - - - if(args.data.username != null && args.data.username.length > 0) { - $.extend(data, { - autoscaleuserid: args.data.username - }); - } - - var array2 = []; - if(args.data.diskOfferingId != null && args.data.diskOfferingId.length > 0) - array2.push("diskofferingid=" + args.data.diskOfferingId); - if(args.data.securityGroups != null && args.data.securityGroups.length > 0){ - if(array2.length > 0) - array2.push("&securitygroupids=" + args.data.securityGroups); - else - array2.push("securitygroupids=" + args.data.securityGroups); - } - if(array2.length > 0) { - $.extend(data, { - otherdeployparams: array2.join("") - }); - } - - $.ajax({ - url: createURL('createAutoScaleVmProfile'), - data: data, - success: function(json) { - var jobId = json.autoscalevmprofileresponse.jobid; - var autoscaleVmProfileTimer = setInterval(function(){ - $.ajax({ - url: createURL("queryAsyncJobResult&jobId="+jobId), - dataType: "json", - success: function(json) { - var result = json.queryasyncjobresultresponse; - if (result.jobstatus == 0) { - return; //Job has not completed - } - else { - clearInterval(autoscaleVmProfileTimer); - if (result.jobstatus == 1) { - scaleVmProfileResponse = result.jobresult.autoscalevmprofile; - loadBalancer(args); //create a load balancer rule - } - else if (result.jobstatus == 2) { - args.response.error(_s(result.jobresult.errortext)); - } - } - } - }); - }, g_queryAsyncJobResultInterval); - }, - error: function(XMLHttpResponse) { - args.response.error(parseXMLHttpResponse(XMLHttpResponse)); - } - }); - } - else { //from an existing LB - var data = { - id: args.context.originalAutoscaleData.context.autoscaleVmProfile.id, - templateid: args.data.templateNames, - destroyvmgraceperiod: args.data.destroyVMgracePeriod, - snmpcommunity: args.data.snmpCommunity, - snmpport: args.data.snmpPort - }; - - var allParamNames=$.map(data,function(value,key){ - return key; - }); - - var notParams =['id','templateid','destroyvmgraceperiod']; - var index=0; - $(allParamNames).each(function() { - var param='counterparam[' + index + ']'; - var name = this.toString(); - var value = data[name]; - if(!value || $.inArray(name,notParams) >-1 ) return true; - data[param+ '.name']=name; - data[param+ '.value']=value; - index++; - delete data[name]; - - return true; - }); - - - - - if(args.data.username != null && args.data.username.length > 0) { - $.extend(data, { - autoscaleuserid: args.data.username - }); - } - - $.ajax({ - url: createURL('updateAutoScaleVmProfile'), - data: data, - success: function(json) { - var jobId = json.updateautoscalevmprofileresponse.jobid; - var autoscaleVmProfileTimer = setInterval(function(){ - $.ajax({ - url: createURL("queryAsyncJobResult&jobId="+jobId), - dataType: "json", - success: function(json) { - var result = json.queryasyncjobresultresponse; - if (result.jobstatus == 0) { - return; //Job has not completed - } - else { - clearInterval(autoscaleVmProfileTimer); - if (result.jobstatus == 1) { - scaleVmProfileResponse = result.jobresult.autoscalevmprofile; - autoScaleVmGroup(args); //update autoScaleVmGroup - } - else if (result.jobstatus == 2) { - args.response.error(_s(result.jobresult.errortext)); - } - } - } - }); - }, g_queryAsyncJobResultInterval); - }, - error: function(XMLHttpResponse) { - args.response.error(parseXMLHttpResponse(XMLHttpResponse)); - } - }); - } - }; - - var loadBalancer = function(args){ - var networkid; - if('vpc' in args.context) { //from VPC section - if(args.data.tier == null) { - cloudStack.dialog.notice({ message: 'Tier is required' }); - return; - } - networkid = args.data.tier; - } - else if('networks' in args.context) { //from Guest Network section - networkid = args.context.networks[0].id; - } - var data = { - algorithm: args.formData.algorithm, - name: args.formData.name, - privateport: args.formData.privateport, - publicport: args.formData.publicport, - openfirewall: false, - networkid: networkid - }; - if(args.context.ipAddresses != null) { - data = $.extend(data, { - publicipid: args.context.ipAddresses[0].id - }); - } - else { - data = $.extend(data, { - domainid: g_domainid, - account: g_account - }); - } - - $.ajax({ - url: createURL('createLoadBalancerRule'), - dataType: 'json', - data: data, - async: true, - success: function(json) { - var jobId = json.createloadbalancerruleresponse.jobid; - var loadBalancerTimer = setInterval(function(){ + } else { //from an existing LB $.ajax({ - url: createURL("queryAsyncJobResult&jobId="+jobId), - dataType: "json", - success: function(json) { - var result = json.queryasyncjobresultresponse; - if (result.jobstatus == 0) { - return; //Job has not completed + url: createURL('listAutoScaleVmGroups'), + data: { + listAll: true, + lbruleid: args.context.multiRules[0].id + }, + success: function(json) { + var autoscaleVmGroup = json.listautoscalevmgroupsresponse.autoscalevmgroup[0]; + + $.ajax({ + url: createURL('listAutoScaleVmProfiles'), + data: { + listAll: true, + id: autoscaleVmGroup.vmprofileid + }, + success: function(json) { + var autoscaleVmProfile = json.listautoscalevmprofilesresponse.autoscalevmprofile[0]; + + var scaleUpPolicy = { + id: autoscaleVmGroup.scaleuppolicies[0].id, + duration: autoscaleVmGroup.scaleuppolicies[0].duration, + conditions: [] + }; + $(autoscaleVmGroup.scaleuppolicies[0].conditions).each(function() { + var condition = { + id: this.id, + counterid: this.counter[0].id, + relationaloperator: this.relationaloperator, + threshold: this.threshold + }; + scaleUpPolicy.conditions.push(condition); + }); + + var scaleDownPolicy = { + id: autoscaleVmGroup.scaledownpolicies[0].id, + duration: autoscaleVmGroup.scaledownpolicies[0].duration, + conditions: [] + }; + $(autoscaleVmGroup.scaledownpolicies[0].conditions).each(function() { + var condition = { + id: this.id, + counterid: this.counter[0].id, + relationaloperator: this.relationaloperator, + threshold: this.threshold.toString() + }; + scaleDownPolicy.conditions.push(condition); + }); + + var diskOfferingId, securityGroups; + var otherdeployparams = autoscaleVmProfile.otherdeployparams; + if (otherdeployparams != null && otherdeployparams.length > 0) { + var array1 = otherdeployparams.split('&'); + $(array1).each(function() { + var array2 = this.split('='); + if (array2[0] == 'diskofferingid') + diskOfferingId = array2[1]; + if (array2[0] == 'securitygroupids') + securityGroups = array2[1]; + }); + } + + var originalAutoscaleData = { + templateNames: autoscaleVmProfile.templateid, + serviceOfferingId: autoscaleVmProfile.serviceofferingid, + minInstance: autoscaleVmGroup.minmembers, + maxInstance: autoscaleVmGroup.maxmembers, + scaleUpPolicy: scaleUpPolicy, + scaleDownPolicy: scaleDownPolicy, + interval: autoscaleVmGroup.interval, + quietTime: autoscaleVmGroup.scaleuppolicies[0].quiettime, + destroyVMgracePeriod: autoscaleVmProfile.destroyvmgraceperiod, + securityGroups: securityGroups, + diskOfferingId: diskOfferingId, + snmpCommunity: autoscaleVmProfile.counterparam.snmpcommunity, + snmpPort: autoscaleVmProfile.counterparam.snmpport, + username: autoscaleVmProfile.autoscaleuserid, + context: { + autoscaleVmGroup: autoscaleVmGroup, + autoscaleVmProfile: autoscaleVmProfile + } + //isAdvanced: false // Set this to true if any advanced field data is present + }; + + args.response.success({ + data: originalAutoscaleData + }); + } + }); } - else { - clearInterval(loadBalancerTimer); - if (result.jobstatus == 1) { //LoadBalancerRule successfully created - loadBalancerResponse = result.jobresult.loadbalancer; - autoScaleVmGroup(args); - } - else if (result.jobstatus == 2) { - args.response.error(_s(result.jobresult.errortext)); - } - } - } }); - }, g_queryAsyncJobResultInterval); - }, - error: function(XMLHttpResponse) { - args.response.error(parseXMLHttpResponse(XMLHttpResponse)); } - }); - }; + }, - var autoScaleVmGroup = function(args){ - if(!('multiRules' in args.context)) { //from a new LB - var array1 = []; - array1.push("&lbruleid=" + loadBalancerResponse.id); - array1.push("&minMembers=" + args.data.minInstance); - array1.push("&maxMembers=" + args.data.maxInstance ); - array1.push("&vmprofileid=" + scaleVmProfileResponse.id); - array1.push("&interval=" + args.data.interval); - array1.push("&scaleuppolicyids=" + args.scaleUpPolicyResponse.id); - array1.push("&scaledownpolicyids=" + args.scaleDownPolicyResponse.id ); - $.ajax({ - url: createURL('createAutoScaleVmGroup' + array1.join("")), - dataType: 'json', - async: true, - success: function(json) { - var jobId = json.autoscalevmgroupresponse.jobid; - var scaleVmGroupTimer = setInterval(function(){ - $.ajax({ - url: createURL("queryAsyncJobResult&jobId="+jobId), - dataType: "json", - success: function(json) { - var result = json.queryasyncjobresultresponse; - if (result.jobstatus == 0) { - return; //Job has not completed - } - else { - clearInterval(scaleVmGroupTimer); - if (result.jobstatus == 1) { //autoscale Vm group successfully created - scaleVmGroupResponse = result.jobresult.autoscalevmgroup; - args.response.success(); - } - else if (result.jobstatus == 2) { - args.response.error(_s(result.jobresult.errortext)); - } - } - } - }); - }, g_queryAsyncJobResultInterval); - }, - error: function(XMLHttpResponse) { - args.response.error(parseXMLHttpResponse(XMLHttpResponse)); - } - }); - } - else { //from an existing LB - var data = { - id: args.context.originalAutoscaleData.context.autoscaleVmGroup.id, - minmembers: args.data.minInstance, - maxmembers: args.data.maxInstance, - interval: args.data.interval, - scaleuppolicyids: args.context.originalAutoscaleData.scaleUpPolicy.id, - scaledownpolicyids: args.context.originalAutoscaleData.scaleDownPolicy.id - }; - - $.ajax({ - url: createURL('updateAutoScaleVmGroup'), - data: data, - success: function(json) { - var jobId = json.updateautoscalevmgroupresponse.jobid; - var updateAutoScaleVmGroupTimer = setInterval(function(){ - $.ajax({ - url: createURL("queryAsyncJobResult&jobId="+jobId), - dataType: "json", - success: function(json) { - var result = json.queryasyncjobresultresponse; - if (result.jobstatus == 0) { - return; //Job has not completed - } - else { - clearInterval(updateAutoScaleVmGroupTimer); - if (result.jobstatus == 1) { //autoscale Vm group successfully created - args.response.success(); - } - else if (result.jobstatus == 2) { - args.response.error(_s(result.jobresult.errortext)); - } - } - } - }); - }, g_queryAsyncJobResultInterval); - }, - error: function(XMLHttpResponse) { - args.response.error(parseXMLHttpResponse(XMLHttpResponse)); - } - }); - } - }; + // -- + // Add the following object blocks: + // + // topFields: { } + // bottomFields: { }, + // scaleUpPolicy: { }, + // scaleDownPolicy: { } + // -- + // + forms: { + topFields: { + //** + //** Disabled due to UI issues + //** + // templateCategory: { + // label: 'Template', + // id: 'templatecategory', + // select: function(args) { + // args.response.success({ + // data: [ + // { id: 'all', description: _l('ui.listView.filters.all') }, + // { id: 'featured', description: _l('label.featured') }, + // { id: 'Community', description: _l('label.menu.community.templates') }, + // { id: 'self', description: _l('ui.listView.filters.mine') } + // ] + // }); + // } + // }, + //** - //*** API calls start!!! ******** - scaleUp(args); - - }, - destroy: function(args) { - $.ajax({ - url: createURL('') - }); - } - }, + templateNames: { + label: 'label.template', + id: 'templatename', + select: function(args) { + var templates; + var templateIdMap = {}; + $.ajax({ + url: createURL('listTemplates'), + data: { + templatefilter: 'featured', + zoneid: args.context.networks[0].zoneid + }, + async: false, + success: function(json) { + templates = json.listtemplatesresponse.template; + if (templates == null) + templates = []; + $(templates).each(function() { + templateIdMap[this.id] = 1; + }); + } + }); - dialog: function(args) { - return function(args) { - var context = args.context; + $.ajax({ + url: createURL('listTemplates'), + data: { + templatefilter: 'community', + zoneid: args.context.networks[0].zoneid + }, + async: false, + success: function(json) { + var items = json.listtemplatesresponse.template; + $(items).each(function() { + if (!(this.id in templateIdMap)) { + templates.push(this); + templateIdMap[this.id] = 1; + } + }); + } + }); - var $dialog= $('
'); - $dialog.dialog ({ - title: 'AutoScale Configuration Wizard', - closeonEscape: false, + $.ajax({ + url: createURL('listTemplates'), + data: { + templatefilter: 'selfexecutable', + zoneid: args.context.networks[0].zoneid + }, + async: false, + success: function(json) { + var items = json.listtemplatesresponse.template; + $(items).each(function() { + if (!(this.id in templateIdMap)) { + templates.push(this); + templateIdMap[this.id] = 1; + } + }); + } + }); - draggable:true, - width: 825 , - height :600, - buttons: { - 'Cancel': function() { - $(this).dialog("close"); - $('.overlay').remove(); + args.response.success({ + data: $.map(templates, function(template) { + return { + id: template.id, + description: template.name + }; + }) + }); + } + }, + + serviceOfferingId: { + label: 'label.compute.offering', + select: function(args) { + $.ajax({ + url: createURL("listServiceOfferings&issystem=false"), + dataType: "json", + async: true, + success: function(json) { + var serviceofferings = json.listserviceofferingsresponse.serviceoffering; + args.response.success({ + data: $.map(serviceofferings, function(serviceoffering) { + return { + id: serviceoffering.id, + description: serviceoffering.name + }; + }) + }); + } + }); + } + }, + + minInstance: { + label: 'Min Instances', + defaultValue: '3', + validation: { + required: true, + number: true + } + }, + + maxInstance: { + label: 'Max Instances', + defaultValue: '10', + validation: { + required: true, + number: true + } + } }, + bottomFields: { + isAdvanced: { + isBoolean: true, + label: 'Show advanced settings' + }, + interval: { + label: 'Polling Interval (in sec)', + defaultValue: '30', + validation: { + required: true, + number: true + } + }, - 'Apply': function() { - $(':ui-dialog').remove(); - $('.overlay').remove(); + quietTime: { + label: 'Quiet Time (in sec)', + defaultValue: '300', + validation: { + required: true, + number: true + } + }, + + destroyVMgracePeriod: { + label: 'Destroy VM Grace Period', + defaultValue: '30', + isHidden: true, + dependsOn: 'isAdvanced', + validation: { + required: true, + number: true + } + }, + securityGroups: { + label: 'label.menu.security.groups', + isHidden: true, + dependsOn: 'isAdvanced', + select: function(args) { + $.ajax({ + url: createURL("listSecurityGroups&listAll=true"), + dataType: "json", + async: true, + success: function(json) { + var securitygroups = json.listsecuritygroupsresponse.securitygroup; + var items = []; + items.push({ + id: "", + description: "" + }); + $(securitygroups).each(function() { + items.push({ + id: this.id, + description: this.name + }); + }); + args.response.success({ + data: items + }); + } + }); + } + }, + + diskOfferingId: { + label: 'label.menu.disk.offerings', + isHidden: true, + dependsOn: 'isAdvanced', + select: function(args) { + $.ajax({ + url: createURL("listDiskOfferings&listAll=true"), + dataType: "json", + async: true, + success: function(json) { + var diskofferings = json.listdiskofferingsresponse.diskoffering; + var items = []; + items.push({ + id: "", + description: "" + }); + $(diskofferings).each(function() { + items.push({ + id: this.id, + description: this.name + }); + }); + args.response.success({ + data: items + }); + } + }); + } + }, + + snmpCommunity: { + isHidden: true, + dependsOn: 'isAdvanced', + label: 'SNMP Community', + defaultValue: 'public', + validation: { + required: true + } + }, + + snmpPort: { + isHidden: true, + dependsOn: 'isAdvanced', + label: 'SNMP Port', + defaultValue: '161', + validation: { + required: true, + number: true + } + }, + + username: { + isHidden: true, + dependsOn: 'isAdvanced', + label: 'User', + select: function(args) { + var items = []; + if (args.context.originalAutoscaleData == null) { //new LB rule + if (isAdmin() || isDomainAdmin()) { + $.ajax({ + url: createURL('listUsers'), + data: { + domainid: g_domainid, + account: g_account + }, + success: function(json) { + var users = json.listusersresponse.user; + $(users).each(function() { + items.push({ + id: this.id, + description: this.username + }); + }); + args.response.success({ + data: items + }); + } + }); + } else { //regular user doesn't have access to listUers API call. + items.push({ + id: "", + description: "" + }); + args.response.success({ + data: items + }); + } + } else { //existing LB rule + if (isAdmin() || isDomainAdmin()) { + $.ajax({ + url: createURL('listUsers'), + data: { + domainid: args.context.originalAutoscaleData.context.autoscaleVmProfile.domainid, + account: args.context.originalAutoscaleData.context.autoscaleVmProfile.account + }, + success: function(json) { + var users = json.listusersresponse.user; + $(users).each(function() { + items.push({ + id: this.id, + description: this.username + }); + }); + args.response.success({ + data: items + }); + } + }); + } else { //regular user doesn't have access to listUers API call. + items.push({ + id: "", + description: "" + }); + args.response.success({ + data: items + }); + } + } + } + } + }, + scaleUpPolicy: { + title: 'ScaleUp Policy', + label: 'SCALE UP POLICY', + noSelect: true, + noHeaderActionsColumn: true, + ignoreEmptyFields: true, + fields: { + 'counterid': { + label: 'Counter', + select: function(args) { + $.ajax({ + url: createURL("listCounters"), + dataType: "json", + async: false, + success: function(json) { + var counters = json.counterresponse.counter; + + args.response.success({ + data: $.map(counters, function(counter) { + return { + name: counter.id, + description: counter.name + }; + }) + }); + } + }); + } + }, + 'relationaloperator': { + label: 'Operator', + select: function(args) { + args.response.success({ + data: [{ + name: 'GT', + description: 'greater-than' + }, { + name: 'GE', + description: 'greater-than or equals to' + }, { + name: 'LT', + description: 'less-than' + }, { + name: 'LE', + description: 'less-than or equals to' + }, { + name: 'EQ', + description: 'equals-to' + }] + }); + } + }, + 'threshold': { + edit: true, + label: 'Threshold' + }, + 'add-scaleUpcondition': { + label: 'label.add', + addButton: true + } + }, + add: { + label: 'label.add', + action: function(args) { + scaleUpData.push($.extend(args.data, { + index: totalScaleUpCondition + })); + + totalScaleUpCondition++; + args.response.success(); + } + }, + actions: { + destroy: { + label: '', + action: function(args) { + scaleUpData = $.grep(scaleUpData, function(item) { + return item.index != args.context.multiRule[0].index; + }); + totalScaleUpCondition--; + args.response.success(); + } + } + }, + dataProvider: function(args) { + var data = scaleUpData; + var $autoscaler = $('.ui-dialog .autoscaler'); + var initialData = $autoscaler.data('autoscaler-scale-up-data'); + + if ($.isArray(initialData)) { + $(initialData).each(function() { + this.index = totalScaleUpCondition; + totalScaleUpCondition++; + scaleUpData.push(this); + }); + + $autoscaler.data('autoscaler-scale-up-data', null); + } + + args.response.success({ + data: scaleUpData + }); + } + }, + + scaleDownPolicy: { + title: 'ScaleDown Policy', + noSelect: true, + noHeaderActionsColumn: true, + ignoreEmptyFields: true, + fields: { + 'counterid': { + label: 'Counter', + select: function(args) { + $.ajax({ + url: createURL("listCounters"), + dataType: "json", + async: false, + success: function(json) { + var counters = json.counterresponse.counter; + + args.response.success({ + data: $.map(counters, function(counter) { + return { + name: counter.id, + description: counter.name + }; + }) + }); + } + }); + } + }, + 'relationaloperator': { + label: 'Operator', + select: function(args) { + args.response.success({ + data: [{ + name: 'GT', + description: 'greater-than' + }, { + name: 'GE', + description: 'greater-than or equals to' + }, { + name: 'LT', + description: 'less-than' + }, { + name: 'LE', + description: 'less-than or equals to' + }, { + name: 'EQ', + description: 'equals-to' + }] + }); + } + }, + 'threshold': { + edit: true, + label: 'Threshold' + }, + 'add-scaleDowncondition': { + label: 'label.add', + addButton: true + } + }, + add: { + label: 'label.add', + action: function(args) { + scaleDownData.push($.extend(args.data, { + index: totalScaleDownCondition + })); + totalScaleDownCondition++; + args.response.success(); + } + }, + actions: { + destroy: { + label: '', + action: function(args) { + scaleDownData = $.grep(scaleDownData, function(item) { + return item.index != args.context.multiRule[0].index; + }); + totalScaleDownCondition--; + args.response.success(); + } + } + }, + dataProvider: function(args) { + var data = scaleDownData; + var $autoscaler = $('.ui-dialog .autoscaler'); + var initialData = $autoscaler.data('autoscaler-scale-down-data'); + + if ($.isArray(initialData)) { + $(initialData).each(function() { + this.index = totalScaleDownCondition; + totalScaleDownCondition++; + scaleDownData.push(this); + }); + + $autoscaler.data('autoscaler-scale-down-data', null); + } + + args.response.success({ + data: scaleDownData + }); + } } - } - }).closest('.ui-dialog').overlay(); + }, - $("buttons").each(function() { - $(this).attr('style','float: right'); - }); - var $field = $('
').addClass('field username'); - var $input = $('').attr({ name: 'username' }); - var $inputLabel = $('