add CORs filter for backend platform and hook view all offices up to it.
This commit is contained in:
@@ -53,9 +53,9 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
globalDate: function(dateParts) {
|
globalDate: function(localDateAsISOString) {
|
||||||
try {
|
try {
|
||||||
|
var dateParts = localDateAsISOString.split("-")
|
||||||
var year = dateParts[0];
|
var year = dateParts[0];
|
||||||
var month = parseInt(dateParts[1]) - 1; // month is zero indexed
|
var month = parseInt(dateParts[1]) - 1; // month is zero indexed
|
||||||
var day = dateParts[2];
|
var day = dateParts[2];
|
||||||
@@ -68,9 +68,9 @@
|
|||||||
return "??";
|
return "??";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
globalDateTime: function(dateParts) {
|
globalDateTime: function(dateInMillis) {
|
||||||
try {
|
try {
|
||||||
var d = new Date(dateParts);
|
var d = new Date(dateInMillis);
|
||||||
|
|
||||||
return Globalize.format(d,"F");
|
return Globalize.format(d,"F");
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
@@ -165,10 +165,10 @@
|
|||||||
}).dialog('open');
|
}).dialog('open');
|
||||||
}
|
}
|
||||||
|
|
||||||
function popupDialogWithFormView(url, titleCode, templateSelector, width, height, saveSuccessFunction) {
|
function popupDialogWithFormView(getUrl, postUrl, titleCode, templateSelector, width, height, saveSuccessFunction) {
|
||||||
var dialogDiv = $("<div id='dialog-form'></div>");
|
var dialogDiv = $("<div id='dialog-form'></div>");
|
||||||
var jqxhr = $.ajax({
|
var jqxhr = $.ajax({
|
||||||
url: url,
|
url: getUrl,
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
@@ -196,7 +196,7 @@
|
|||||||
var form_data = $('#entityform').serialize();
|
var form_data = $('#entityform').serialize();
|
||||||
|
|
||||||
var jqxhr = $.ajax({
|
var jqxhr = $.ajax({
|
||||||
url: url,
|
url: postUrl,
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: form_data,
|
data: form_data,
|
||||||
success: saveSuccessFunction,
|
success: saveSuccessFunction,
|
||||||
@@ -248,7 +248,10 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('#addloanproduct').click(function(e) {
|
$('#addloanproduct').click(function(e) {
|
||||||
var url = '${rootContext}portfolio/product/loan/new';
|
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 templateSelector = "#productFormTemplate";
|
||||||
var width = 800;
|
var width = 800;
|
||||||
var height = 550;
|
var height = 550;
|
||||||
@@ -258,7 +261,7 @@
|
|||||||
refreshLoanProductsView();
|
refreshLoanProductsView();
|
||||||
}
|
}
|
||||||
|
|
||||||
popupDialogWithFormView(url, "dialog.title.add.loan.product", templateSelector, width, height, saveSuccessFunction);
|
popupDialogWithFormView(getUrl, postUrl,"dialog.title.add.loan.product", templateSelector, width, height, saveSuccessFunction);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -338,7 +341,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('#addoffice').click(function(e) {
|
$('#addoffice').click(function(e) {
|
||||||
var url = '${rootContext}org/office/new';
|
var getUrl = 'http://localhost:8085/mifosng-provider/api/v1/offices/template';
|
||||||
|
var postUrl = 'http://localhost:8085/mifosng-provider/api/v1/offices';
|
||||||
var templateSelector = "#officeFormTemplate";
|
var templateSelector = "#officeFormTemplate";
|
||||||
var width = 600;
|
var width = 600;
|
||||||
var height = 400;
|
var height = 400;
|
||||||
@@ -354,14 +358,18 @@
|
|||||||
|
|
||||||
function refreshOfficesView() {
|
function refreshOfficesView() {
|
||||||
var jqxhr = $.ajax({
|
var jqxhr = $.ajax({
|
||||||
url: '${allOfficesUrl}',
|
url: 'http://localhost:8085/mifosng-provider/api/v1/offices', // '${allOfficesUrl}',
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(data, textStatus, jqXHR) {
|
success: function(data, textStatus, jqXHR) {
|
||||||
|
|
||||||
|
$.each(data.offices, function(i, item) {
|
||||||
|
//alert(item.name);
|
||||||
|
});
|
||||||
|
console.log(data);
|
||||||
var officelistParent = new Object();
|
var officelistParent = new Object();
|
||||||
officelistParent.items = data;
|
officelistParent.items = data.offices;
|
||||||
|
|
||||||
var officeListHtml = $("#officeListTemplate").render(officelistParent);
|
var officeListHtml = $("#officeListTemplate").render(officelistParent);
|
||||||
$("#listplaceholder").html(officeListHtml);
|
$("#listplaceholder").html(officeListHtml);
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package org.mifosng.platform.filters;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.Response.ResponseBuilder;
|
||||||
|
|
||||||
|
import com.sun.jersey.spi.container.ContainerRequest;
|
||||||
|
import com.sun.jersey.spi.container.ContainerResponse;
|
||||||
|
import com.sun.jersey.spi.container.ContainerResponseFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* General approach to turn back-end capabilities exposed through resource-oriented API as Cross-Origin-Request complaint.
|
||||||
|
*/
|
||||||
|
public class ResponseCorsFilter implements ContainerResponseFilter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
|
||||||
|
|
||||||
|
ResponseBuilder resp = Response.fromResponse(response.getResponse());
|
||||||
|
|
||||||
|
resp.header("Access-Control-Allow-Origin", "*").header("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
||||||
|
|
||||||
|
String reqHead = request.getHeaderValue("Access-Control-Request-Headers");
|
||||||
|
|
||||||
|
if (null != reqHead && !reqHead.equals(null)) {
|
||||||
|
resp.header("Access-Control-Allow-Headers", reqHead);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.setResponse(resp.build());
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -51,12 +51,25 @@
|
|||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>jersey-serlvet</servlet-name>
|
<servlet-name>jersey-serlvet</servlet-name>
|
||||||
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
|
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
|
||||||
<!-- debugging on for development -->
|
|
||||||
<init-param>
|
<init-param>
|
||||||
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
|
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
|
||||||
<param-value>true</param-value>
|
<param-value>true</param-value>
|
||||||
</init-param>
|
</init-param>
|
||||||
|
<!-- debugging on for development -->
|
||||||
|
<!--
|
||||||
|
<init-param>
|
||||||
|
<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
|
||||||
|
<param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
|
||||||
|
</init-param>
|
||||||
|
<init-param>
|
||||||
|
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
|
||||||
|
<param-value>com.sun.jersey.api.container.filter.LoggingFilter, org.mifosng.platform.filters.ResponseCorsFilter</param-value>
|
||||||
|
</init-param>
|
||||||
|
-->
|
||||||
|
<init-param>
|
||||||
|
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
|
||||||
|
<param-value>org.mifosng.platform.filters.ResponseCorsFilter</param-value>
|
||||||
|
</init-param>
|
||||||
<load-on-startup>1</load-on-startup>
|
<load-on-startup>1</load-on-startup>
|
||||||
</servlet>
|
</servlet>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user