Merge branch 'api-work' of github.com:keithwoodlock/mifosx into api-work

This commit is contained in:
John Woodlock
2012-05-11 10:54:29 +10:00
2 changed files with 34 additions and 52 deletions
@@ -165,6 +165,23 @@
}).dialog('open');
}
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
function popupDialogWithFormView(getUrl, postUrl, titleCode, templateSelector, width, height, saveSuccessFunction) {
var dialogDiv = $("<div id='dialog-form'></div>");
var jqxhr = $.ajax({
@@ -174,7 +191,7 @@
dataType: 'json',
cache: false,
success: function(data, textStatus, jqXHR) {
console.log(data);
var formHtml = $(templateSelector).render(data);
dialogDiv.append(formHtml);
@@ -193,12 +210,18 @@
$(this).attr("selected", "selected");
});
var newFormData = JSON.stringify($('#entityform').serializeObject());
console.log(newFormData);
var form_data = $('#entityform').serialize();
var jqxhr = $.ajax({
url: postUrl,
type: 'POST',
data: form_data,
contentType: 'application/json',
dataType: 'json',
data: newFormData,
success: saveSuccessFunction,
error: function(jqXHR, textStatus, errorThrown) {
handleXhrError(jqXHR, textStatus, errorThrown, "#formErrorsTemplate", "#formerrors");
@@ -250,7 +273,6 @@
$('#addloanproduct').click(function(e) {
var getUrl = 'http://localhost:8085/mifosng-provider/api/v1/loanproducts/template';
var postUrl = 'http://localhost:8085/mifosng-provider/api/v1/loanproducts';
//var url = '${rootContext}portfolio/product/loan/new';
var templateSelector = "#productFormTemplate";
var width = 800;
@@ -261,7 +283,7 @@
refreshLoanProductsView();
}
popupDialogWithFormView(getUrl, postUrl,"dialog.title.add.loan.product", templateSelector, width, height, saveSuccessFunction);
popupDialogWithFormView(getUrl, postUrl, "dialog.title.add.loan.product", templateSelector, width, height, saveSuccessFunction);
e.preventDefault();
});
@@ -2,6 +2,7 @@ package org.mifosng.platform.api.loanproduct;
import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@@ -9,6 +10,7 @@ import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@@ -69,35 +71,16 @@ public class LoanProductApiResource {
context.setAuthentication(auth);
}
// example POST request
// http://localhost:8085/mifosng-provider/api/v1/loanproducts/
// Content-Type: application/json
// {
// "name": "test",
// "description": "test",
// "commonLoanProperties": {
// "currencyCode": "USD",
// "digitsAfterDecimal": 2,
// "principal": 100000,
// "repaymentEvery": 1,
// "repaymentFrequency": 2,
// "numberOfRepayments": 12,
// "amortizationMethod": 1,
// "inArrearsToleranceAmount": 1000,
// "interestRatePerPeriod": 2,
// "interestRateFrequencyMethod": 2,
// "interestMethod": 0,
// "interestCalculationPeriodMethod": 1
// }
// }
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON})
public Response createLoanProduct(LoanProductCommand command) {
public Response createLoanProduct(@Context HttpServletRequest request) {
hardcodeUserIntoSecurityContext();
EntityIdentifier entityIdentifier = this.loanProductWritePlatformService.createLoanProduct(command);
// TODO - FIX mapping to command object on post and also fix error handling of this when it fails.
EntityIdentifier entityIdentifier = new EntityIdentifier(Long.valueOf(-1));
// this.loanProductWritePlatformService.createLoanProduct(command);
return Response.ok().entity(entityIdentifier).build();
}
@@ -142,30 +125,7 @@ public class LoanProductApiResource {
return Response.ok().entity(loanProduct).build();
}
// example PUT request
// http://localhost:8085/mifosng-provider/api/v1/loanproducts/
// Content-Type: application/json
// {
// "id": 7,
// "name": "test",
// "description": "test",
// "externalId": "",
// "commonLoanProperties": {
// "currencyCode": "USD",
// "digitsAfterDecimal": 2,
// "principal": 100000,
// "repaymentEvery": 1,
// "repaymentFrequency": 2,
// "numberOfRepayments": 12,
// "amortizationMethod": 1,
// "inArrearsToleranceAmount": 1000,
// "interestRatePerPeriod": 2,
// "interestRateFrequencyMethod": 2,
// "interestMethod": 0,
// "interestCalculationPeriodMethod": 1
// }
// }
@PUT
@Path("{productId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })