From e2ab24a7bc947ce4ddcbdc63f04c8aaae7b4a328 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Wed, 22 Jul 2015 14:47:15 +0530 Subject: [PATCH] ui: add effective from date in tariff list/table, add error handling dialogs Signed-off-by: Rohit Yadav --- ui/plugins/quota/quota.js | 55 +++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/ui/plugins/quota/quota.js b/ui/plugins/quota/quota.js index 6fef2b18830..add2f26bbe8 100644 --- a/ui/plugins/quota/quota.js +++ b/ui/plugins/quota/quota.js @@ -35,9 +35,6 @@ var g_quotaCurrency = ''; if (json.hasOwnProperty('listconfigurationsresponse') && json.listconfigurationsresponse.hasOwnProperty('configuration')) { g_quotaCurrency = json.listconfigurationsresponse.configuration[0].value + ' '; } - }, - error: function(data) { - // FIXME: what to do on error? } }); @@ -155,13 +152,11 @@ var g_quotaCurrency = ''; } statementTableBody.appendTo(statementTable); }, - error: function(json) { + error: function(data) { generatedStatement.empty(); - var error = JSON.parse(json.responseText); - if (error.hasOwnProperty('quotastatementresponse')) { - $("

").appendTo(generatedStatement); - $("

").html("Error: " + error.quotastatementresponse.errortext).appendTo(generatedStatement); - } + cloudStack.dialog.notice({ + message: parseXMLHttpResponse(data) + }); } }); @@ -223,17 +218,13 @@ var g_quotaCurrency = ''; statementTableBody.appendTo(statementTable); }, - error: function(json) { + error: function(data) { generatedBalanceStatement.empty(); - var error = JSON.parse(json.responseText); - if (error.hasOwnProperty('quotabalanceresponse')) { - $("
").appendTo(generatedBalanceStatement); - $("

").html("Error: " + error.quotabalanceresponse.errortext).appendTo(generatedBalanceStatement); - } + cloudStack.dialog.notice({ + message: parseXMLHttpResponse(data) + }); } }); - - }); domainDropdown.appendTo(statementForm); @@ -332,6 +323,7 @@ var g_quotaCurrency = ''; $('').html(_l('label.usage.type')).appendTo(tariffTableHead); $('').html(_l('label.usage.unit')).appendTo(tariffTableHead); $('').html(_l('label.quota.value')).appendTo(tariffTableHead); + $('').html('Effective Date').appendTo(tariffTableHead); $('').html(_l('label.quota.description')).appendTo(tariffTableHead); tariffTableHead.appendTo($('').appendTo(tariffTable)); @@ -364,7 +356,7 @@ var g_quotaCurrency = ''; editButton.attr('id', 'quota-tariff-edit-' + items[i].usageType); editButton.click(function() { var usageTypeId = $(this).context.id.replace('quota-tariff-edit-', ''); - cloudStack.dialog.createForm({ + var updateTariffForm = cloudStack.dialog.createForm({ form: { title: 'label.quota.configuration', fields: { @@ -373,7 +365,13 @@ var g_quotaCurrency = ''; validation: { required: true } - } + }, + effectiveDate: { + label: 'Effective Date', + validation: { + required: true + } + }, } }, after: function(args) { @@ -381,29 +379,40 @@ var g_quotaCurrency = ''; url: createURL('quotaTariffUpdate'), data: { usagetype: usageTypeId, - value: args.data.quotaValue + value: args.data.quotaValue, + startDate: args.data.effectiveDate }, type: "POST", success: function(json) { $('#quota-tariff').click(); }, - error: function(json) { - // TODO: handle error? + error: function(data) { + cloudStack.dialog.notice({ + message: parseXMLHttpResponse(data) + }); } }); } }); + updateTariffForm.find('input[name=effectiveDate]').datepicker({ + defaultDate: "+1w", + changeMonth: true, + dateFormat: "yy-mm-dd", + }); }); } else { $('').html(items[i].tariffValue).appendTo(tariffTableBodyRow); } + $('').html(items[i].effectiveDate).appendTo(tariffTableBodyRow); $('').html(items[i].description).appendTo(tariffTableBodyRow); tariffTableBodyRow.appendTo(tariffTableBody); } tariffTableBody.appendTo(tariffTable); }, error: function(data) { - // TODO: Add error dialog? + cloudStack.dialog.notice({ + message: parseXMLHttpResponse(data) + }); } });