WIP post extra data and parson json string for edits
This commit is contained in:
@@ -348,6 +348,23 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$.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 extraDataOpenDialog(url) {
|
function extraDataOpenDialog(url) {
|
||||||
|
|
||||||
// var saveButton = jQuery.i18n.prop('dialog.button.save');
|
// var saveButton = jQuery.i18n.prop('dialog.button.save');
|
||||||
@@ -361,7 +378,9 @@
|
|||||||
$(this).attr("selected", "selected");
|
$(this).attr("selected", "selected");
|
||||||
});
|
});
|
||||||
|
|
||||||
var form_data = $('#entityform').serialize();
|
//var form_data = $('#entityform').serialize();
|
||||||
|
var form_data = JSON.stringify($('#entityform').serializeObject());
|
||||||
|
console.log(form_data);
|
||||||
var jqxhr = $.ajax({
|
var jqxhr = $.ajax({
|
||||||
url : url,
|
url : url,
|
||||||
type : 'POST',
|
type : 'POST',
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.mifosng.platform.api;
|
package org.mifosng.platform.api;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -7,6 +8,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.servlet.ServletInputStream;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
@@ -22,6 +24,9 @@ import javax.ws.rs.core.Response;
|
|||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
import javax.ws.rs.core.UriInfo;
|
import javax.ws.rs.core.UriInfo;
|
||||||
|
|
||||||
|
import org.codehaus.jettison.json.JSONArray;
|
||||||
|
import org.codehaus.jettison.json.JSONException;
|
||||||
|
import org.codehaus.jettison.json.JSONObject;
|
||||||
import org.mifosng.data.EntityIdentifier;
|
import org.mifosng.data.EntityIdentifier;
|
||||||
import org.mifosng.data.ErrorResponse;
|
import org.mifosng.data.ErrorResponse;
|
||||||
import org.mifosng.data.ErrorResponseList;
|
import org.mifosng.data.ErrorResponseList;
|
||||||
@@ -93,35 +98,34 @@ public class ExtraDataApiResource {
|
|||||||
@Path("{datasetType}/{datasetName}/{datasetPKValue}")
|
@Path("{datasetType}/{datasetName}/{datasetPKValue}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
@Produces({ MediaType.APPLICATION_JSON})
|
@Produces({ MediaType.APPLICATION_JSON})
|
||||||
public Response saveExtraData(@PathParam("datasetType") final String datasetType,@PathParam("datasetName") final String datasetName, @PathParam("datasetPKValue") final String datasetPKValue, @Context HttpServletRequest req) {
|
public Response saveExtraData(@PathParam("datasetType") final String datasetType,@PathParam("datasetName") final String datasetName, @PathParam("datasetPKValue") final String datasetPKValue, String reqbody) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
//MultivaluedMap<String, String> incomingParams = uriInfo.getQueryParameters();
|
|
||||||
Map<String, String> queryParams = new HashMap<String, String>();
|
Map<String, String> queryParams = new HashMap<String, String>();
|
||||||
|
|
||||||
//Set<String> keys = incomingParams.keySet();
|
|
||||||
|
|
||||||
logger.info("Request JPW: " + req.toString());
|
|
||||||
Enumeration paramNames = req.getParameterNames();
|
|
||||||
String pValue = "";
|
String pValue = "";
|
||||||
String pName;
|
String pName;
|
||||||
String[] paramValues;
|
try {
|
||||||
while(paramNames.hasMoreElements()) {
|
JSONObject jsonObj = new JSONObject(reqbody);
|
||||||
pName = (String) paramNames.nextElement();
|
JSONArray jsonArr = jsonObj.names();
|
||||||
paramValues = req.getParameterValues(pName);
|
if (jsonArr != null) {
|
||||||
if (paramValues.length > 1) {
|
for (int i = 0; i < jsonArr.length(); i++) {
|
||||||
logger.info("Unexpected Parameter Error: " + pName + " has " + paramValues.length + " value(s)");
|
pName = (String) jsonArr.get(i);
|
||||||
} else {
|
pValue = jsonObj.getString(pName);
|
||||||
if (paramValues.length == 1) {
|
logger.info( pName + " - " + pValue);
|
||||||
pValue = paramValues[0];
|
queryParams.put(pName, pValue);
|
||||||
} else {
|
}
|
||||||
pValue = "";
|
} else {
|
||||||
}
|
throw new WebApplicationException(Response
|
||||||
}
|
.status(Status.BAD_REQUEST)
|
||||||
logger.info(pName + " - " + pValue);
|
.entity("JSON body empty").build());
|
||||||
queryParams.put(pName, pValue);
|
}
|
||||||
}
|
} catch (JSONException e) {
|
||||||
|
throw new WebApplicationException(Response
|
||||||
|
.status(Status.BAD_REQUEST)
|
||||||
|
.entity("JSON body is wrong").build());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
this.readPlatformService.tempSaveExtraData(datasetType, datasetName, datasetPKValue, queryParams);
|
this.readPlatformService.tempSaveExtraData(datasetType, datasetName, datasetPKValue, queryParams);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user