tidy up ui for loanproducts and offices after json changes.

This commit is contained in:
Keith Woodlock
2012-05-25 14:04:16 +01:00
parent 5ac62588f6
commit 63a1f6cd63
8 changed files with 74 additions and 251 deletions
@@ -1,8 +1,6 @@
package org.mifosng.data.command;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
@@ -10,30 +8,30 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class OrganisationCurrencyCommand implements Serializable {
private Collection<String> notSelectedItems = new ArrayList<String>();
private Collection<String> selectedItems = new ArrayList<String>();
private String[] notSelectedCurrencies;
private String[] currencies;
public OrganisationCurrencyCommand() {
//
}
public OrganisationCurrencyCommand(final List<String> selectedCurrencyCodes) {
this.selectedItems = selectedCurrencyCodes;
this.currencies = selectedCurrencyCodes.toArray(new String[selectedCurrencyCodes.size()]);
}
public Collection<String> getSelectedItems() {
return selectedItems;
public String[] getNotSelectedCurrencies() {
return notSelectedCurrencies;
}
public void setSelectedItems(Collection<String> selectedItems) {
this.selectedItems = selectedItems;
public void setNotSelectedCurrencies(String... notSelectedCurrencies) {
this.notSelectedCurrencies = notSelectedCurrencies;
}
public Collection<String> getNotSelectedItems() {
return notSelectedItems;
public String[] getCurrencies() {
return currencies;
}
public void setNotSelectedItems(Collection<String> notSelectedItems) {
this.notSelectedItems = notSelectedItems;
public void setCurrencies(String... currencies) {
this.currencies = currencies;
}
}
@@ -16,7 +16,7 @@ label.client.search=Choose client:
option.client.search.first.choice=--Select Client--
link.add.new.client=Add a new client
page.client.account.title=View Client Account Details
page.client.account.title=View Client Account Detailscon
page.admin.home.title=Administration Home
page.admin.settings.title=Account Settings
@@ -281,7 +281,7 @@ dialog.title.configuration.currencies=Currency Configuration
form.label.configuration.available.currencies=Available currencies:
form.label.configuration.allowed.currencies=Allowed currencies:
validation.msg.organisation.allowed.currencies.cannot.be.blank=You must select at least one currency that is 'allowed' for your organisation.
validation.msg.configuration.currencies.cannot.be.empty=You must select at least one currency that is 'allowed' for your organisation.
# user account settings and admin screens
tab.settings=Settings
@@ -279,7 +279,7 @@ validation.msg.office.externalId.exceeds.max.length=External id exceeds max leng
form.label.configuration.available.currencies=Available currencies:(fr)
form.label.configuration.allowed.currencies=Allowed currencies:(fr)
validation.msg.organisation.allowed.currencies.cannot.be.blank=You must select at least one currency that is 'allowed' for your organisation.(fr)
validation.msg.configuration.currencies.cannot.be.empty=You must select at least one currency that is 'allowed' for your organisation.(fr)
# user account settings and admin screens
tab.settings=Settings(fr)
@@ -58,7 +58,23 @@
return false;
}
},
globalDate: function(localDateAsISOString) {
globalDate: function(dateParts) {
try {
var year = dateParts[0];
var month = parseInt(dateParts[1]) - 1; // month is zero indexed
var day = dateParts[2];
var d = new Date();
d.setFullYear(year,month,day);
return Globalize.format(d,"dd MMMM yyyy");
} catch(e) {
return "??";
}
},
globalDateAsISOString: function(localDateAsISOString) {
try {
var dateParts = localDateAsISOString.split("-")
var year = dateParts[0];
@@ -193,7 +209,7 @@
o[this.name].push(this.value || '');
} else {
if (this.name === 'selectedItems' || this.name === 'notSelectedItems') {
if (this.name === 'currencies' || this.name === 'notSelectedCurrencies') {
o[this.name] = new Array();
o[this.name].push(this.value || '');
} else {
@@ -228,11 +244,11 @@
var buttonsOpts = {};
buttonsOpts[saveButton] = function() {
$('#notSelectedItems option').each(function(i) {
$('#notSelectedCurrencies option').each(function(i) {
$(this).attr("selected", "selected");
});
$('#selectedItems option').each(function(i) {
$('#currencies option').each(function(i) {
$(this).attr("selected", "selected");
});
@@ -272,11 +288,11 @@
open: function (event, ui) {
$('#add').click(function() {
return !$('#notSelectedItems option:selected').remove().appendTo('#selectedItems');
return !$('#notSelectedCurrencies option:selected').remove().appendTo('#currencies');
});
$('#remove').click(function() {
return !$('#selectedItems option:selected').remove().appendTo('#notSelectedItems');
return !$('#currencies option:selected').remove().appendTo('#notSelectedCurrencies');
});
$('.datepickerfield').datepicker({constrainInput: true, maxDate: 0, dateFormat: 'dd MM yy'});
@@ -322,13 +338,12 @@
dataType: 'json',
cache: false,
beforeSend: function(xhr) {
console.log("base64: " + base64);
xhr.setRequestHeader("Authorization", "Basic " + base64);
},
success: function(data, textStatus, jqXHR) {
var productlistParent = new Object();
productlistParent.items = data.products;
productlistParent.products = data;
var productListHtml = $("#productListTemplate").render(productlistParent);
$("#listplaceholder").html(productListHtml);
@@ -336,7 +351,7 @@
$("a.editproduct").click( function(e) {
var linkId = this.id;
var productId = linkId.replace("editproduct", "");
var getUrl = baseApiUrl + 'loanproducts/' + productId;
var getUrl = baseApiUrl + 'loanproducts/' + productId + '?template=true';
var putUrl = baseApiUrl + 'loanproducts/' + productId;
var templateSelector = "#productFormTemplate";
@@ -423,12 +438,8 @@
},
success: function(data, textStatus, jqXHR) {
$.each(data.offices, function(i, item) {
//alert(item.name);
});
console.log(data);
var officelistParent = new Object();
officelistParent.items = data.offices;
officelistParent.offices = data;
var officeListHtml = $("#officeListTemplate").render(officelistParent);
$("#listplaceholder").html(officeListHtml);
@@ -436,7 +447,7 @@
$("a.edit").click( function(e) {
var linkId = this.id;
var entityId = linkId.replace("edit", "");
var getUrl = baseApiUrl + 'offices/' + entityId;
var getUrl = baseApiUrl + 'offices/' + entityId + '?template=true';
var putUrl = baseApiUrl + 'offices/' + entityId;
var templateSelector = "#officeFormTemplate";
@@ -170,7 +170,7 @@
</tr>
</thead>
<tbody>
{{#each items}}
{{#each products}}
<tr>
<td title='{{=description}}'>{{=name}}</td>
<td>{{=$ctx.globalDateTime(createdOn)}}</td>
@@ -201,7 +201,7 @@
</tr>
</thead>
<tbody>
{{#each items}}
{{#each offices}}
<tr>
<td>{{=name}}</td>
<td>{{=externalId}}</td>
@@ -261,8 +261,8 @@
<legend><spring:message code="form.legend.loan.product.currency"/></legend>
<div class="multiselectwidget" style="width:400px;height:125px;">
<label for="notSelectedItems"><spring:message code="form.label.configuration.available.currencies"/></label>
<select id="notSelectedItems" name="notSelectedItems" title="" class="multiselectwidget" multiple="multiple" style="width:400px;height:125px;">
<label for="notSelectedCurrencies"><spring:message code="form.label.configuration.available.currencies"/></label>
<select id="notSelectedCurrencies" name="notSelectedCurrencies" title="" class="multiselectwidget" multiple="multiple" style="width:400px;height:125px;">
{{#each currencyOptions}}
{{#if $ctx.number($parent.parent.data.code)===code}}
<option value="{{=code}}" selected="selected">{{=displayLabel}}</option>
@@ -275,8 +275,8 @@
</div>
<div class="multiselectwidget">
<label for="selectedItems"><spring:message code="form.label.configuration.allowed.currencies"/></label>
<select id="selectedItems" name="selectedItems" title="" class="multiselectwidget" multiple="multiple" style="width:400px;height:125px;">
<label for="currencies"><spring:message code="form.label.configuration.allowed.currencies"/></label>
<select id="currencies" name="currencies" title="" class="multiselectwidget" multiple="multiple" style="width:400px;height:125px;">
{{#each selectedCurrencyOptions}}
{{#if $ctx.number($parent.parent.data.code)===code}}
<option value="{{=code}}" selected="selected">{{=displayLabel}}</option>
@@ -160,4 +160,11 @@ public class DataValidatorBuilder {
}
return this;
}
public void inValidValue(String parameterValueCode, Object invalidValue) {
StringBuilder validationErrorCode = new StringBuilder("validation.msg.").append(resource).append(".").append(parameter).append(".invalid.").append(parameterValueCode);
StringBuilder defaultEnglishMessage = new StringBuilder("The parameter ").append(parameter).append(" has an invalid value.");
ApiParameterError error = ApiParameterError.parameterError(validationErrorCode.toString(), defaultEnglishMessage.toString(), parameter, invalidValue);
dataValidationErrors.add(error);
}
}
@@ -7,6 +7,7 @@ import java.util.Set;
import org.mifosng.data.ApiParameterError;
import org.mifosng.data.command.OrganisationCurrencyCommand;
import org.mifosng.platform.DataValidatorBuilder;
import org.mifosng.platform.currency.domain.ApplicationCurrency;
import org.mifosng.platform.currency.domain.ApplicationCurrencyRepository;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
@@ -40,33 +41,33 @@ public class ConfigurationWritePlatformServiceJpaRepositoryImpl implements Confi
AppUser currentUser = context.authenticatedUser();
if (command.getSelectedItems().isEmpty()) {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
ApiParameterError error = ApiParameterError.parameterError("validation.msg.organisation.allowed.currencies.cannot.be.blank", "The parameter selectedItems is invalid.", "selectedItems");
dataValidationErrors.add(error);
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("configuration");
baseDataValidator.reset().parameter("currencies").value(command.getCurrencies()).arrayNotEmpty();
if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
}
Set<OrganisationCurrency> allowedCurrencies = new HashSet<OrganisationCurrency>();
for (String currencyCode : command.getSelectedItems()) {
for (String currencyCode : command.getCurrencies()) {
ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode);
if (currency == null) {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
ApiParameterError error = ApiParameterError.parameterError("validation.msg.currency.code.invalid", "The parameter selectedItems contains an invalid currency code entry.", "selectedItems", currencyCode);
dataValidationErrors.add(error);
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
baseDataValidator.reset().parameter("currencies").value(command.getCurrencies()).inValidValue("currency.code", currencyCode);
} else {
OrganisationCurrency allowedCurrency = new OrganisationCurrency(
currency.getCode(), currency.getName(),
currency.getDecimalPlaces(), currency.getNameCode(), currency.getDisplaySymbol());
allowedCurrencies.add(allowedCurrency);
}
OrganisationCurrency allowedCurrency = new OrganisationCurrency(
currency.getCode(), currency.getName(),
currency.getDecimalPlaces(), currency.getNameCode(), currency.getDisplaySymbol());
allowedCurrencies.add(allowedCurrency);
}
if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
}
Organisation org = currentUser.getOrganisation();
@@ -82,199 +82,5 @@ public class LoanProductCommandValidator {
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
}
}
// FIXME - commented out old validation for now. test that new validation is appropriate
// private void validateRemainingAttributes(LoanProductCommand command, List<ApiParameterError> dataValidationErrors) {
//
// if (StringUtils.isBlank(command.getName())) {
// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.name.cannot.be.blank", "The parameter name cannot be blank.", "name");
// dataValidationErrors.add(error);
// }
//
// if (command.getDescription() != null) {
// if (command.getDescription().length() > 500) {
// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.description.exceeds.max.length", "The parameter description cannot exceed max length of {}.", "description", 500);
// dataValidationErrors.add(error);
// }
// }
//
// if (StringUtils.isBlank(command.getCurrencyCode())) {
// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.currency.cannot.be.empty", "The parameter currencyCode cannot be blank.", "currencyCode");
// dataValidationErrors.add(error);
// }
//
// if (command.getDigitsAfterDecimal() != null) {
//
// if (command.getDigitsAfterDecimal() < 0 || command.getDigitsAfterDecimal() > 6) {
// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.currency.digitsAfterDecimal.must.be.between.zero.and.six.inclusive", "The parameter digitsAfterDecimal must be between {0} and {1} inclusive.", "selectedDigitsAfterDecimal", 0, 6);
// dataValidationErrors.add(error);
// }
// } else {
// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.currency.digitsAfterDecimal.cannot.be.empty", "The parameter digitsAfterDecimal cannot be blank.", "selectedDigitsAfterDecimal");
// dataValidationErrors.add(error);
// }
//
// if (command.getPrincipal() != null) {
// if (command.getPrincipal().doubleValue() <= Double.valueOf("0.0")) {
// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.principal.amount.must.be.greater.than.zero", "The parameter amount must be greater than zero.", "amount");
// dataValidationErrors.add(error);
// }
// } else {
// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.principal.amount.cannot.be.empty", "The parameter amount cannot be blank.", "amount");
// dataValidationErrors.add(error);
// }
//
// if (command.getRepaymentFrequency() != null) {
// PeriodFrequencyType frequencyType = PeriodFrequencyType.fromInt(command.getRepaymentFrequency());
// ApiParameterError error = null;
// switch (frequencyType) {
// case DAYS:
// error = validateNumberExistsAndInRange("validation.msg.product.repayment.repaidEvery", "repaidEvery", command.getRepaymentEvery(), 1, 365);
// break;
// case WEEKS:
// error = validateNumberExistsAndInRange("validation.msg.product.repayment.repaidEvery", "repaidEvery", command.getRepaymentEvery(), 1, 52);
// break;
// case MONTHS:
// error = validateNumberExistsAndInRange("validation.msg.product.repayment.repaidEvery", "repaidEvery", command.getRepaymentEvery(), 1, 12);
// break;
// case YEARS:
// error = validateNumberExistsAndInRange("validation.msg.product.repayment.repaidEvery", "repaidEvery", command.getRepaymentEvery(), 1, 2);
// break;
// default:
// error = ApiParameterError.parameterError("validation.msg.product.repayment.frequency.invalid", "The parameter selectedRepaymentFrequencyOption is invalid.", "selectedRepaymentFrequencyOption");
// break;
// }
// if (error != null) {
// dataValidationErrors.add(error);
// }
// } else {
// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.repayment.frequency.cannot.be.empty",
// "The parameter selectedRepaymentFrequencyOption cannot be blank.", "selectedRepaymentFrequencyOption");
// dataValidationErrors.add(error);
// }
//
// if (command.getNumberOfRepayments() != null) {
// if (command.getNumberOfRepayments() < 1 || command.getNumberOfRepayments() > 100) {
// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.number.of.repayments.is.out.of.range",
// "The parameter numberOfRepayments must be between {} and {} inclusive.", "numberOfRepayments", 1, 100);
// dataValidationErrors.add(error);
// }
// } else {
// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.number.of.repayments.cannot.be.empty",
// "The parameter numberOfRepayments cannot be empty.", "numberOfRepayments");
// dataValidationErrors.add(error);
// }
//
// if (command.getAmortizationMethod() != null) {
// AmortizationMethod amortizationMethod = AmortizationMethod.fromInt(command.getAmortizationMethod());
// ApiParameterError error = null;
// switch (amortizationMethod) {
// case EQUAL_PRINCIPAL:
// break;
// case EQUAL_INSTALLMENTS:
// break;
// default:
// error = ApiParameterError.parameterError("validation.msg.product.amortization.method.invalid",
// "The parameter selectedAmortizationMethodOption cannot be empty.", "selectedAmortizationMethodOption");
// break;
// }
// if (error != null) {
// dataValidationErrors.add(error);
// }
// } else {
// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.amortization.method.cannot.be.empty",
// "The parameter selectedAmortizationMethodOption cannot be empty.", "selectedAmortizationMethodOption");
// dataValidationErrors.add(error);
// }
//
// // refactor in validation of monetary value.
// if (command.getInArrearsToleranceAmount() != null) {
// if (command.getInArrearsToleranceAmount().doubleValue() < Double.valueOf("0.0")) {
// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.arrears.tolerance.amount.cannot.be.negative",
// "The parameter inArrearsTolerance cannot be less than zero.", "inArrearsTolerance");
// dataValidationErrors.add(error);
// }
// } else {
// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.arrears.tolerance.amount.cannot.be.empty",
// "The parameter inArrearsTolerance cannot be empty.", "inArrearsTolerance");
// dataValidationErrors.add(error);
// }
//
// if (command.getInterestRatePerPeriod()!= null) {
// if (command.getInterestRatePerPeriod().doubleValue() < Double.valueOf("0.0")) {
// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.interest.rate.per.period.amount.cannot.be.negative",
// "The parameter nominalInterestRate cannot be less than zero.", "nominalInterestRate");
// dataValidationErrors.add(error);
// }
// } else {
// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.interest.rate.per.period.amount.cannot.be.empty",
// "The parameter nominalInterestRate cannot be empty.", "nominalInterestRate");
// dataValidationErrors.add(error);
// }
//
// // interest rate period type
// if (command.getInterestRateFrequencyMethod() != null) {
// PeriodFrequencyType frequencyType = PeriodFrequencyType.fromInt(command.getInterestRateFrequencyMethod());
// ApiParameterError error = null;
// switch (frequencyType) {
// case DAYS:
// break;
// case WEEKS:
// break;
// case MONTHS:
// break;
// case YEARS:
// break;
// default:
// error = ApiParameterError.parameterError("validation.msg.product.interest.frequency.invalid",
// "The parameter selectedInterestFrequencyOption is invalid.", "selectedInterestFrequencyOption");
// break;
// }
// if (error != null) {
// dataValidationErrors.add(error);
// }
// } else {
// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.interest.frequency.cannot.be.empty",
// "The parameter selectedInterestFrequencyOption cannot be empty.", "selectedInterestFrequencyOption");
// dataValidationErrors.add(error);
// }
//
// if (command.getInterestMethod() != null) {
// InterestMethod interestMethod = InterestMethod.fromInt(command.getInterestMethod());
// ApiParameterError error = null;
// switch (interestMethod) {
// case DECLINING_BALANCE:
// break;
// case FLAT:
// break;
// default:
// error = ApiParameterError.parameterError("validation.msg.product.interest.method.invalid",
// "The parameter selectedInterestMethodOption is invalid.", "selectedInterestMethodOption");
// break;
// }
// if (error != null) {
// dataValidationErrors.add(error);
// }
// } else {
// ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.interest.method.cannot.be.empty",
// "The parameter selectedInterestMethodOption cannot be empty.", "selectedInterestMethodOption");
// dataValidationErrors.add(error);
// }
//
// if (!dataValidationErrors.isEmpty()) {
// throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
// }
// }
//
// private ApiParameterError validateNumberExistsAndInRange(String errorCodePreFix, String fieldName, Integer value, int min, int max) {
// ApiParameterError error = null;
// if (value == null) {
// error = ApiParameterError.parameterError(errorCodePreFix + ".cannot.be.empty", "The parameter " + fieldName + " cannot be blank.", fieldName);
// } else {
// if (value < min || value > max) {
// error = ApiParameterError.parameterError(errorCodePreFix + ".outside.allowed.range", "The parameter " + fieldName + " must be between {0} and {1} inclusive.", fieldName, min, max);
// }
// }
// return error;
// }
}