diff --git a/client/WEB-INF/classes/resources/messages.properties b/client/WEB-INF/classes/resources/messages.properties index 77a655591b6..d4dc46ac7c2 100644 --- a/client/WEB-INF/classes/resources/messages.properties +++ b/client/WEB-INF/classes/resources/messages.properties @@ -1360,6 +1360,8 @@ label.usage.unit=Unit label.quota.value=Quota Value label.quota.description=Quota Description label.quota.configuration=Quota Configuration +label.quota.configure=Configure Quota +label.quota.remove=Remove Quota label.destroy.vm.graceperiod=Destroy VM Grace Period label.SNMP.community=SNMP Community label.SNMP.port=SNMP Port diff --git a/ui/dictionary.jsp b/ui/dictionary.jsp index e72b773b9e5..df03367ba1c 100644 --- a/ui/dictionary.jsp +++ b/ui/dictionary.jsp @@ -987,6 +987,8 @@ dictionary = { 'label.quota.value': '', 'label.quota.description': '', 'label.quota.configuration': '', +'label.quota.configure': '', +'label.quota.remove': '', 'label.rbd': '', 'label.rbd.monitor': '', 'label.rbd.pool': '', diff --git a/ui/plugins/quota/quota.js b/ui/plugins/quota/quota.js index 288e16ee801..28e01572049 100644 --- a/ui/plugins/quota/quota.js +++ b/ui/plugins/quota/quota.js @@ -16,8 +16,209 @@ // under the License. (function (cloudStack) { cloudStack.plugins.quota = function(plugin) { + // Quota Global Settings + var gsView = cloudStack.sections['global-settings'].sections; + gsView.quotaConfiguration = { + type: 'select', + title: 'label.quota.configuration', + listView: { + id: 'quota', + label: 'label.quota.configuration', + fields: { + usageType: { + label: 'label.usage.type' + }, + usageUnit: { + label: 'label.usage.unit' + }, + currencyValue: { + label: 'label.quota.value' + }, + description: { + label: 'label.quota.description' + } + }, + dataProvider: function(args) { + var data = {}; + listViewDataProvider(args, data); + if (data.hasOwnProperty('page') && data.page > 1) { + args.response.success({ + data: [] + }); + return; + } + $.ajax({ + url: createURL('quotaMapping'), + data: data, + success: function(json) { + var items = json.quotaconfigurationresponse.quotamapping; + args.response.success({ + data: items + }); + }, + error: function(data) { + args.response.error(parseXMLHttpResponse(data)); + } + }); + }, + detailView: { + name: 'label.details', + actions: { + remove: { + label: 'label.quota.remove', + messages: { + notification: function(args) { + return 'label.quota.remove'; + }, + confirm: function() { + return 'label.quota.remove'; + } + }, + action: function(args) { + $.ajax({ + url: createURL("deleteQuotaConfiguration&hostname=" + args.context.quotaConfiguration[0].hostname), + success: function(json) { + args.response.success(); + } + }); + $(window).trigger('cloudStack.fullRefresh'); + } + }, + edit: { + label: 'label.quota.configure', + messages: { + notification: function(args) { + return 'label.quota.configure'; + }, + confirm: function() { + return 'label.quota.configure'; + } + }, + action: function(args) { + var data = { + 'type': args.context.quotaConfiguration[0].usageType, + 'usageUnit': args.data.usageUnit, + 'value': args.data.currencyValue, + 'description': args.data.description + }; + $.ajax({ + url: createURL("editQuotaConfiguration"), + data: data, + success: function(json) { + args.response.success(); + } + }); + $(window).trigger('cloudStack.fullRefresh'); + } + } + + + }, + tabs: { + details: { + title: 'label.quota.configuration', + fields: [{ + usageType: { + label: 'label.usage.type' + }, + usageUnit: { + label: 'label.usage.unit', + isEditable: true + }, + currencyValue: { + label: 'label.quota.value', + isEditable: true + }, + description: { + label: 'label.quota.description', + isEditable: true + } + }], + dataProvider: function(args) { + var items = []; + $.ajax({ + url: createURL("quotaMapping&type=" + args.context.quotaConfiguration[0].usageType), + dataType: "json", + async: true, + success: function(json) { + var item = json.quotaconfigurationresponse.quotamapping; + args.response.success({ + data: item[0] + }); + } + }); + } + } + } + }, + actions: { + add: { + label: 'label.quota.configure', + messages: { + confirm: function(args) { + return 'message.configure.quota'; + }, + notification: function(args) { + return 'label.quota.configure'; + } + }, + createForm: { + title: 'label.quota.configure', + fields: { + usageType: { + label: 'label.usage.type', + validation: { + required: true + } + }, + periodUnit: { + label: 'label.usage.unit', + validation: { + required: true + } + }, + quotaValue: { + label: 'label.quota.value', + validation: { + required: true + } + }, + quotaDescription: { + label: 'label.quota.description', + validation: { + required: false + } + } + } + }, + action: function(args) { + var array = []; + array.push("&type=" + todb(args.data.usageType)); + array.push("&period=" + todb(args.data.periodUnit));; + array.push("&value=" + todb(args.data.quotaValue));; + array.push("&description=" + todb(args.data.quotaDescription));; + $.ajax({ + url: createURL("addQuotaConfiguration" + array.join("")), + dataType: "json", + async: true, + success: function(json) { + var items = json.quotaconfigurationresponse.QuotaAddConfiguration; + args.response.success({ + data: items + }); + }, + error: function(json) { + args.response.error(parseXMLHttpResponse(json)); + } + }); + } + } + } + } + }; + + // Quota view on user page var userView = cloudStack.sections.accounts.sections.users.listView.detailView; - // Add view to show quota information userView.tabs.quota = { title: 'Quota', fields: [{ diff --git a/ui/scripts/globalSettings.js b/ui/scripts/globalSettings.js index d61f2d5300a..4124ccd59ae 100644 --- a/ui/scripts/globalSettings.js +++ b/ui/scripts/globalSettings.js @@ -100,154 +100,8 @@ } } }, - quotaConfiguration: { - type: 'select', - title: 'label.quota.configuration', - listView: { - id: 'quota', - label: 'label.quota.configuration', - fields: { - usageType: { - label: 'label.usage.type' - }, - usageUnit: { - label: 'label.usage.unit' - }, - currencyValue: { - label: 'label.quota.value' - }, - description: { - label: 'label.quota.description' - } - }, - dataProvider: function(args) { - var data = {}; - listViewDataProvider(args, data); - $.ajax({ - url: createURL('quotaMapping'), - data: data, - success: function(json) { - var items = json.quotaconfigurationresponse.QuotaConfiguration; - args.response.success({ - data: items - }); - }, - error: function(data) { - args.response.error(parseXMLHttpResponse(data)); - } - }); - }, - detailView: { - name: 'label.details', - actions: { - remove: { - label: 'label.remove.quota', - messages: { - notification: function(args) { - return 'label.remove.quota'; - }, - confirm: function() { - return 'message.remove.quota'; - } - }, - action: function(args) { - $.ajax({ - url: createURL("deleteQuotaConfiguration&hostname=" + args.context.quotaConfiguration[0].hostname), - success: function(json) { - args.response.success(); - } - }); - $(window).trigger('cloudStack.fullRefresh'); - } - } - }, - tabs: { - details: { - title: 'label.quota.configuration', - fields: [{ - usageType: { - label: 'label.usage.type' - }, - usageUnit: { - label: 'label.usage.unit' - }, - currencyValue: { - label: 'label.quota.value' - }, - description: { - label: 'label.quota.description' - } - }], - dataProvider: function(args) { - var items = []; - console.log(args); - $.ajax({ - url: createURL("quotaMapping&hostname=" + args.context.quotaConfiguration[0].hostname), - dataType: "json", - async: true, - success: function(json) { - var item = json.quotaconfigurationresponse.QuotaConfiguration; - args.response.success({ - data: item[0] - }); - } - }); - } - } - } - }, - actions: { - add: { - label: 'label.configure.quota', - messages: { - confirm: function(args) { - return 'message.configure.quota'; - }, - notification: function(args) { - return 'label.configure.quota'; - } - }, - createForm: { - title: 'label.configure.quota', - fields: { - hostname: { - label: 'label.host.name', - validation: { - required: true - } - }, - port: { - label: 'label.port', - validation: { - required: true - } - } - } - }, - action: function(args) { - var array = []; - array.push("&hostname=" + todb(args.data.hostname)); - array.push("&port=" + todb(args.data.port));; - $.ajax({ - url: createURL("addQuotaConfiguration" + array.join("")), - dataType: "json", - async: true, - success: function(json) { - var items = json.quotaconfigurationresponse.QuotaAddConfiguration; - args.response.success({ - data: items - }); - }, - error: function(json) { - args.response.error(parseXMLHttpResponse(json)); - } - }); - } - } - } - } - }, + ldapConfiguration: { type: 'select', title: 'label.ldap.configuration',