support submit new loan application and delete loan capabilities through api.

This commit is contained in:
Keith Woodlock
2012-05-16 18:21:36 +01:00
parent bf7783fc94
commit a006e60681
32 changed files with 1040 additions and 1118 deletions
@@ -206,7 +206,7 @@ $(document).ready(function() {
return o;
};
function popupConfirmationDialogAndPost(url, titleCode, width, height, tabIndex, redirectUrl) {
function popupConfirmationDialogAndPost(url, submitType, titleCode, width, height, tabIndex, redirectUrl) {
var dialogDiv = $("<div id='dialog-form'><div id='formerrors'></div>" + jQuery.i18n.prop('text.confirmation.required') + "</div>");
var confirmButton = jQuery.i18n.prop('dialog.button.confirm');
@@ -216,7 +216,9 @@ $(document).ready(function() {
buttonsOpts[confirmButton] = function() {
var jqxhr = $.ajax({
url: url,
type: 'POST',
type: submitType,
contentType: 'application/json',
dataType: 'json',
success: function(data, textStatus, jqXHR) {
dialogDiv.dialog("close");
if (tabIndex > 0) {
@@ -322,70 +324,70 @@ $(document).ready(function() {
dataType: 'json',
cache: false,
success: function(data, textStatus, jqXHR) {
console.log(data);
var formHtml = $(templateSelector).render(data);
dialogDiv.append(formHtml);
var saveButton = jQuery.i18n.prop('dialog.button.save');
var cancelButton = jQuery.i18n.prop('dialog.button.cancel');
var buttonsOpts = {};
buttonsOpts[saveButton] = function() {
console.log(data);
var formHtml = $(templateSelector).render(data);
$('#notSelectedItems option').each(function(i) {
dialogDiv.append(formHtml);
var saveButton = jQuery.i18n.prop('dialog.button.save');
var cancelButton = jQuery.i18n.prop('dialog.button.cancel');
var buttonsOpts = {};
buttonsOpts[saveButton] = function() {
$('#notSelectedItems option').each(function(i) {
$(this).attr("selected", "selected");
});
$('#selectedItems option').each(function(i) {
$(this).attr("selected", "selected");
});
$('#selectedItems option').each(function(i) {
$(this).attr("selected", "selected");
});
var newFormData = JSON.stringify($('#entityform').serializeObject());
console.log(newFormData);
var jqxhr = $.ajax({
url: postUrl,
type: submitType,
contentType: 'application/json',
dataType: 'json',
data: newFormData,
success: saveSuccessFunction,
error: function(jqXHR, textStatus, errorThrown) {
handleXhrError(jqXHR, textStatus, errorThrown, "#formErrorsTemplate", "#formerrors");
}
});
};
buttonsOpts[cancelButton] = function() {$(this).dialog( "close" );};
dialogDiv.dialog({
title: jQuery.i18n.prop(titleCode),
width: width,
height: height,
modal: true,
buttons: buttonsOpts,
close: function() {
// if i dont do this, theres a problem with errors being appended to dialog view second time round
$(this).remove();
},
open: function (event, ui) {
$('#add').click(function() {
return !$('#notSelectedItems option:selected').remove().appendTo('#selectedItems');
});
$('#remove').click(function() {
return !$('#selectedItems option:selected').remove().appendTo('#notSelectedItems');
});
$('.datepickerfield').datepicker({constrainInput: true, maxDate: 0, dateFormat: 'dd MM yy'});
$("#entityform textarea").first().focus();
$('#entityform input').first().focus();
}
}).dialog('open');
}
});
var newFormData = JSON.stringify($('#entityform').serializeObject());
console.log(newFormData);
var jqxhr = $.ajax({
url: postUrl,
type: submitType,
contentType: 'application/json',
dataType: 'json',
data: newFormData,
success: saveSuccessFunction,
error: function(jqXHR, textStatus, errorThrown) {
handleXhrError(jqXHR, textStatus, errorThrown, "#formErrorsTemplate", "#formerrors");
}
});
};
buttonsOpts[cancelButton] = function() {$(this).dialog( "close" );};
dialogDiv.dialog({
title: jQuery.i18n.prop(titleCode),
width: width,
height: height,
modal: true,
buttons: buttonsOpts,
close: function() {
// if i dont do this, theres a problem with errors being appended to dialog view second time round
$(this).remove();
},
open: function (event, ui) {
$('#add').click(function() {
return !$('#notSelectedItems option:selected').remove().appendTo('#selectedItems');
});
$('#remove').click(function() {
return !$('#selectedItems option:selected').remove().appendTo('#notSelectedItems');
});
$('.datepickerfield').datepicker({constrainInput: true, maxDate: 0, dateFormat: 'dd MM yy'});
$("#entityform textarea").first().focus();
$('#entityform input').first().focus();
}
}).dialog('open');
}
});
jqxhr.error(function(jqXHR, textStatus, errorThrown) {
@@ -435,19 +437,6 @@ $(document).ready(function() {
// retrieve accounts summary info
refreshLoanSummaryInfo();
// retrieve additional info
var additionalFieldsParams = {
url: "http://localhost:8080/mifosng-provider/",
datasetType: "portfolio_client",
datasetPKValue: data.id,
datasetTypeDiv: "clientadditionaldata",
headingPrefix: "",
headingClass: "",
labelClass: "longrowlabel",
valueClass: "rowvalue"
};
jQuery.stretchyData.displayAllExtraData(additionalFieldsParams);
// bind click listeners to buttons.
$('.casflowbtn').button().click(function(e) {
var linkId = this.id;
@@ -489,24 +478,25 @@ $(document).ready(function() {
refreshNoteWidget();
} else {
var tableHtml = $("#loanDataTabTemplate").render(data);
var currentTab = $("#newtabs").children(".ui-tabs-panel").not(".ui-tabs-hide");
currentTab.html(tableHtml);
// retrieve additional info
var additionalFieldsParams = {
url: "http://localhost:8080/mifosng-provider/",
datasetType: "portfolio_loan",
datasetType: "portfolio_client",
datasetPKValue: data.id,
datasetTypeDiv: "loanadditionaldata" + data.id,
datasetTypeDiv: "clientadditionaldata",
headingPrefix: "",
headingClass: "",
labelClass: "longrowlabel",
valueClass: "rowvalue"
};
jQuery.stretchyData.displayAllExtraData(additionalFieldsParams);
} else {
var tableHtml = $("#loanDataTabTemplate").render(data);
var currentTab = $("#newtabs").children(".ui-tabs-panel").not(".ui-tabs-hide");
currentTab.html(tableHtml);
var curTabID = currentTab.prop("id")
@@ -560,13 +550,13 @@ $(document).ready(function() {
var linkId = this.id;
var loanId = linkId.replace("deletebtn", "");
var url = '${rootContext}portfolio/loan/' + loanId + '/delete';
var url = 'http://localhost:8080/mifosng-provider/api/v1/loans/' + loanId;
var width = 400;
var height = 225;
var redirectUrl = '${clientUrl}';
popupConfirmationDialogAndPost(url, 'dialog.title.confirmation.required', width, height, 0, redirectUrl);
popupConfirmationDialogAndPost(url, 'DELETE', 'dialog.title.confirmation.required', width, height, 0, redirectUrl);
e.preventDefault();
});
$('button.deleteloan span').text(jQuery.i18n.prop('dialog.button.delete.loan'));
@@ -660,6 +650,19 @@ $(document).ready(function() {
var curTabID = curTab.prop("id")
}
});
// additional data
var additionalFieldsParams = {
url: "http://localhost:8080/mifosng-provider/",
datasetType: "portfolio_loan",
datasetPKValue: data.id,
datasetTypeDiv: "loanadditionaldata" + data.id,
headingPrefix: "",
headingClass: "",
labelClass: "longrowlabel",
valueClass: "rowvalue"
};
jQuery.stretchyData.displayAllExtraData(additionalFieldsParams);
}
}
}
@@ -173,13 +173,13 @@ $.views.registerHelpers({
};
function calculateAnnualPercentageRate() {
var periodInterestRate = parseFloat($('#nominalInterestRate').val());
var periodInterestRate = parseFloat($('#interestRatePerPeriodFormatted').val());
if (isNaN(periodInterestRate)) {
periodInterestRate = 0;
}
var periodsInYear = 12;
var periodType = $('#selectedInterestFrequencyOption').val();
var periodType = $('#interestRateFrequencyMethod').val();
if (periodType == 3) {
periodsInYear = 1;
} else if (periodType == 2) {
@@ -220,15 +220,15 @@ $.views.registerHelpers({
calculateLoanSchedule();
// change detection
$('#principalMoney').change(function() {
$('#principalFormatted').change(function() {
calculateLoanSchedule();
});
$('#repaidEvery').change(function() {
$('#repaymentEvery').change(function() {
calculateLoanSchedule();
});
$('#selectedRepaymentFrequencyOption').change(function() {
$('#repaymentFrequency').change(function() {
calculateLoanSchedule();
});
@@ -236,37 +236,37 @@ $.views.registerHelpers({
calculateLoanSchedule();
});
$('#expectedDisbursementDate').change(function() {
$('#expectedDisbursementDateFormatted').change(function() {
calculateLoanSchedule();
});
$('#repaymentsStartingFromDate').change(function() {
$('#repaymentsStartingFromDateFormatted').change(function() {
calculateLoanSchedule();
});
$('#nominalInterestRate').change(function() {
$('#interestRatePerPeriodFormatted').change(function() {
calculateAnnualPercentageRate();
calculateLoanSchedule();
});
$('#selectedInterestFrequencyOption').change(function() {
$('#interestRateFrequencyMethod').change(function() {
calculateAnnualPercentageRate();
calculateLoanSchedule();
});
$('#selectedAmortizationMethodOption').change(function() {
$('#amortizationMethod').change(function() {
calculateLoanSchedule();
});
$('#selectedInterestMethodOption').change(function() {
$('#interestMethod').change(function() {
calculateLoanSchedule();
});
$('#interestRateCalculatedInPeriod').change(function() {
$('#interestCalculationPeriodMethod').change(function() {
calculateLoanSchedule();
});
$('#interestCalculatedFromDate').change(function() {
$('#interestCalculatedFromDateFormatted').change(function() {
calculateLoanSchedule();
});
@@ -291,14 +291,17 @@ $.views.registerHelpers({
}
function calculateLoanSchedule() {
var calculateLoanScheduleurl = '${rootContext}portfolio/loanschedule/calculate';
var calculateLoanScheduleurl = 'http://localhost:8080/mifosng-provider/api/v1/loans?command=calculateLoanSchedule';
var form_data = $('#entityform').serialize();
var newFormData = JSON.stringify($('#entityform').serializeObject());
console.log(newFormData);
var jqxhr2 = $.ajax({
url: calculateLoanScheduleurl,
type: 'POST',
data: form_data,
contentType: 'application/json',
dataType: 'json',
data: newFormData,
success: function(data, textStatus, jqXHR) {
removeErrors("#formerrors");
var loanScheduleHtml = $("#newLoanScheduleTemplate").render(data);
@@ -313,17 +316,20 @@ $.views.registerHelpers({
}
function submitLoanApplication() {
var submitLoanApplicationUrl = '${rootContext}portfolio/client/${clientId}/loan/new';
var submitLoanApplicationUrl = 'http://localhost:8080/mifosng-provider/api/v1/loans';
var form_data = $('#entityform').serialize();
var newFormData = JSON.stringify($('#entityform').serializeObject());
console.log(newFormData);
var jqxhr2 = $.ajax({
url: submitLoanApplicationUrl,
type: 'POST',
data: form_data,
contentType: 'application/json',
dataType: 'json',
data: newFormData,
success: function(data, textStatus, jqXHR) {
var url = '${rootContext}portfolio/client/${clientId}';
window.location.href = url;
var localAppUrlToSwitchToClientPage = '${rootContext}portfolio/client/${clientId}';
window.location.href = localAppUrlToSwitchToClientPage;
}
});
@@ -331,9 +337,8 @@ $.views.registerHelpers({
handleXhrError(jqXHR, textStatus, errorThrown, "#formErrorsTemplate", "#formerrors");
});
}
// on page load
var jqxhr = $.ajax({
url: 'http://localhost:8080/mifosng-provider/api/v1/loans/template?clientId=${clientId}',
type: 'GET',
@@ -54,7 +54,7 @@
<form id="entityform">
<div id="formerrors"></div>
<input type="hidden" id="clientId" name="clientId" value="{{=clientId}}" />
<input type="hidden" id="applicantId" name="applicantId" value="{{=clientId}}" />
<input type="hidden" id="currencyCode" name="currencyCode" value="{{=selectedProduct.principalMoney.currencyCode}}" />
<input type="hidden" id="digitsAfterDecimal" name="digitsAfterDecimal" value="{{=$ctx.number(selectedProduct.principalMoney.currencyDigitsAfterDecimal)}}" />
@@ -103,16 +103,16 @@
<tr>
<td><spring:message code="form.label.loan.product.loan.amount"/></td>
<td>
<input id="principalMoney" name="principalMoney" title="" type="text" value="{{=$ctx.money(selectedProduct.principalMoney)}}" style="width: 125px;" />
<input id="principalMoney.currencyCode" name="principalMoney.currencyCode" title="" type="text" value="{{=selectedProduct.principalMoney.displaySymbol}}" style="width: 40px;" disabled="disabled" />
<input id="principalFormatted" name="principalFormatted" title="" type="text" value="{{=$ctx.money(selectedProduct.principalMoney)}}" style="width: 125px;" />
<input id="principalCurrencyCode" name="principalCurrencyCode" title="" type="text" value="{{=selectedProduct.principalMoney.displaySymbol}}" style="width: 40px;" disabled="disabled" />
</td>
</tr>
<tr>
<td><spring:message code="form.label.loan.product.repaidevery"/></td>
<td>
<input id="repaidEvery" name="repaidEvery" title="" type="text" value="{{=$ctx.number(selectedProduct.repaidEvery)}}" style="width: 50px;" />
<input id="repaymentEvery" name="repaymentEvery" title="" type="text" value="{{=$ctx.number(selectedProduct.repaidEvery)}}" style="width: 50px;" />
<select name="selectedRepaymentFrequencyOption" id="selectedRepaymentFrequencyOption" title="" style="width: 121px;">
<select name="repaymentFrequency" id="repaymentFrequency" title="" style="width: 121px;">
{{#each selectedProduct.repaymentFrequencyOptions}}
{{#if $ctx.number($parent.parent.data.selectedProduct.repaymentPeriodFrequency)===$ctx.number(id)}}
<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
@@ -149,9 +149,9 @@
<tr>
<td><spring:message code="form.label.loan.product.nominal.interestrate"/></td>
<td>
<input id="nominalInterestRate" name="nominalInterestRate" title="" type="text" value="{{=$ctx.decimal(selectedProduct.interestRatePerPeriod, 4)}}" style="width: 60px;" />
<input id="interestRatePerPeriodFormatted" name="interestRatePerPeriodFormatted" title="" type="text" value="{{=$ctx.decimal(selectedProduct.interestRatePerPeriod, 4)}}" style="width: 60px;" />
<select name="selectedInterestFrequencyOption" id="selectedInterestFrequencyOption" title="" style="width: 115px;">
<select name="interestRateFrequencyMethod" id="interestRateFrequencyMethod" title="" style="width: 115px;">
{{#each selectedProduct.interestFrequencyOptions}}
{{#if $ctx.number($parent.parent.data.selectedProduct.interestRatePeriod)===$ctx.number(id)}}
<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
@@ -171,7 +171,7 @@
<tr>
<td><spring:message code="form.label.loan.product.amortization"/></td>
<td>
<select name="selectedAmortizationMethodOption" id="selectedAmortizationMethodOption" title="" style="width: 178px;">
<select name="amortizationMethod" id="amortizationMethod" title="" style="width: 178px;">
{{#each selectedProduct.possibleAmortizationOptions}}
{{#if $ctx.number($parent.parent.data.selectedProduct.amortizationMethod)===$ctx.number(id)}}
<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
@@ -185,7 +185,7 @@
<tr>
<td><spring:message code="form.label.loan.product.interest.method"/></td>
<td>
<select name="selectedInterestMethodOption" id="selectedInterestMethodOption" title="" style="width: 180px;">
<select name="interestMethod" id="interestMethod" title="" style="width: 180px;">
{{#each selectedProduct.possibleInterestOptions}}
{{#if $ctx.number($parent.parent.data.selectedProduct.interestMethod)===$ctx.number(id)}}
<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
@@ -199,7 +199,7 @@
<tr>
<td><spring:message code="form.label.loan.product.interest.rate.calcutated.in.period"/></td>
<td>
<select id="interestRateCalculatedInPeriod" name="interestRateCalculatedInPeriod" title="" style="width: 220px;">
<select id="interestCalculationPeriodMethod" name="interestCalculationPeriodMethod" title="" style="width: 220px;">
{{#each selectedProduct.possibleInterestRateCalculatedInPeriodOptions}}
{{#if $ctx.number($parent.parent.data.selectedProduct.interestRateCalculatedInPeriod)===$ctx.number(id)}}
<option value="{{=$ctx.number(id)}}" selected="selected">{{=value}}</option>
@@ -213,14 +213,14 @@
<tr>
<td><spring:message code="form.label.loan.interest.charged.from"/></td>
<td>
<input id="interestCalculatedFromDate" name="interestCalculatedFromDate" title="" type="text" class="datepickerfield" value="{{=$ctx.globalDate(interestCalculatedFromDate)}}" style="width:172px;"/>
<input id="interestCalculatedFromDateFormatted" name="interestCalculatedFromDateFormatted" title="" type="text" class="datepickerfield" value="{{=$ctx.globalDate(interestCalculatedFromDate)}}" style="width:172px;"/>
</td>
</tr>
<tr>
<td><spring:message code="form.label.loan.product.arrears.tolerance"/></td>
<td>
<input id="inArrearsTolerance" name="inArrearsTolerance" title="" type="text" value="{{=$ctx.money(selectedProduct.inArrearsTolerance)}}" style="width: 125px;" />
<input id="inArrearsTolerance.currencyCode" name="inArrearsTolerance.currencyCode" title="" type="text" value="{{=selectedProduct.inArrearsTolerance.displaySymbol}}" style="width: 40px;" disabled="disabled" />
<input id="inArrearsToleranceAmountFormatted" name="inArrearsToleranceAmountFormatted" title="" type="text" value="{{=$ctx.money(selectedProduct.inArrearsTolerance)}}" style="width: 125px;" />
<input id="inArrearsCurrencyCode" name="inArrearsCurrencyCode" title="" type="text" value="{{=selectedProduct.inArrearsTolerance.displaySymbol}}" style="width: 40px;" disabled="disabled" />
</td>
</tr>
</table>