Skip to content
Snippets Groups Projects
Commit 7e6fbd29 authored by Robert Goldmann's avatar Robert Goldmann
Browse files

#297 - account select now changes selected account on select and reloads page

parent 57f1bd26
No related branches found
No related tags found
No related merge requests found
package de.deadlocker8.budgetmaster.controller;
import de.deadlocker8.budgetmaster.entities.Account;
import de.deadlocker8.budgetmaster.repositories.AccountRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Controller
public class AccountController extends BaseController
{
@Autowired
private AccountRepository accountRepository;
@RequestMapping(value = "/account/{ID}/select")
public String selectAccount(HttpServletRequest request, @PathVariable("ID") Integer ID)
{
List<Account> accounts = accountRepository.findAll();
for(Account currentAccount : accounts)
{
currentAccount.setSelected(false);
accountRepository.save(currentAccount);
}
Account accountToSelect = accountRepository.findOne(ID);
accountToSelect.setSelected(true);
accountRepository.save(accountToSelect);
return "redirect:" + request.getHeader("Referer");
}
}
\ No newline at end of file
......@@ -6,6 +6,12 @@ $( document ).ready(function() {
$('.modal').modal();
$('select').material_select();
$("#selectAccount").on('change', function()
{
var accountID = $(this).val();
window.location = "/account/" + accountID + "/select";
});
});
function addClass(element, className)
......
......@@ -43,7 +43,7 @@
<div class="input-field no-margin">
<select id="selectAccount">
<#list helpers.getAllAccounts() as account>
<option <#if account.isSelected()>selected</#if> value="${account.getName()}">${account.getName()}</option>
<option <#if account.isSelected()>selected</#if> value="${account.getID()}">${account.getName()}</option>
</#list>
</select>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment