|
5 | 5 | import org.springframework.stereotype.Controller; |
6 | 6 | import org.springframework.ui.Model; |
7 | 7 | import org.springframework.validation.BindingResult; |
| 8 | +import org.springframework.validation.ObjectError; |
8 | 9 | import org.springframework.web.bind.annotation.*; |
9 | 10 | import org.woehlke.greenshop.admin.entities.TaxClass; |
10 | 11 | import org.woehlke.greenshop.admin.entities.TaxRate; |
11 | 12 | import org.woehlke.greenshop.admin.entities.TaxZone; |
12 | 13 | import org.woehlke.greenshop.admin.entities.TaxZone2Zone; |
13 | 14 | import org.woehlke.greenshop.admin.model.NewSubZoneInfoBean; |
14 | 15 | import org.woehlke.greenshop.customer.CustomerService; |
| 16 | +import org.woehlke.greenshop.customer.entities.AddressFormat; |
15 | 17 | import org.woehlke.greenshop.customer.entities.Country; |
16 | 18 | import org.woehlke.greenshop.customer.entities.Zone; |
17 | 19 |
|
@@ -60,6 +62,87 @@ public String countries(@PathVariable long countryId, Model model){ |
60 | 62 | return "admin/countries"; |
61 | 63 | } |
62 | 64 |
|
| 65 | + @RequestMapping(value = "/admin/countries/insert", method = RequestMethod.GET) |
| 66 | + public String countriesInsertForm(Model model){ |
| 67 | + int menuCategory = AdminMenuCategory.LOCATION_TAXES.ordinal(); |
| 68 | + model.addAttribute("menuCategory",menuCategory); |
| 69 | + List<Country> countries = customerService.findAllCountriesOrderByName(); |
| 70 | + model.addAttribute("countries",countries); |
| 71 | + Country thisCountry = new Country(); |
| 72 | + model.addAttribute("thisCountry",thisCountry); |
| 73 | + List<AddressFormat> addressFormats = adminService.findAllAddressFormat(); |
| 74 | + model.addAttribute("addressFormats",addressFormats); |
| 75 | + return "admin/countriesInsertForm"; |
| 76 | + } |
| 77 | + |
| 78 | + @RequestMapping(value = "/admin/countries/insert", method = RequestMethod.POST) |
| 79 | + public String countriesInsertPerform(@Valid Country thisCountry, BindingResult result, Model model){ |
| 80 | + logger.info("Country: "+thisCountry.toString()); |
| 81 | + if(result.hasErrors()){ |
| 82 | + int menuCategory = AdminMenuCategory.LOCATION_TAXES.ordinal(); |
| 83 | + model.addAttribute("menuCategory",menuCategory); |
| 84 | + List<Country> countries = customerService.findAllCountriesOrderByName(); |
| 85 | + model.addAttribute("countries",countries); |
| 86 | + model.addAttribute("thisCountry",thisCountry); |
| 87 | + List<AddressFormat> addressFormats = adminService.findAllAddressFormat(); |
| 88 | + model.addAttribute("addressFormats",addressFormats); |
| 89 | + return "admin/countriesInsertForm"; |
| 90 | + } else { |
| 91 | + adminService.createCountry(thisCountry); |
| 92 | + return "redirect:/admin/countries/"+thisCountry.getId(); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + @RequestMapping(value = "/admin/countries/{countryId}/edit", method = RequestMethod.GET) |
| 97 | + public String countriesEditForm(@PathVariable long countryId, Model model){ |
| 98 | + int menuCategory = AdminMenuCategory.LOCATION_TAXES.ordinal(); |
| 99 | + model.addAttribute("menuCategory",menuCategory); |
| 100 | + Country thisCountry = customerService.findCountryById(countryId); |
| 101 | + model.addAttribute("thisCountry",thisCountry); |
| 102 | + List<Country> countries = customerService.findAllCountriesOrderByName(); |
| 103 | + model.addAttribute("countries",countries); |
| 104 | + List<AddressFormat> addressFormats = adminService.findAllAddressFormat(); |
| 105 | + model.addAttribute("addressFormats",addressFormats); |
| 106 | + return "admin/countriesEditForm"; |
| 107 | + } |
| 108 | + |
| 109 | + @RequestMapping(value = "/admin/countries/{countryId}/edit", method = RequestMethod.POST) |
| 110 | + public String countriesEditSave(@PathVariable long countryId, @Valid Country thisCountry, BindingResult result, Model model){ |
| 111 | + logger.info("Country: "+thisCountry.toString()); |
| 112 | + if(result.hasErrors()){ |
| 113 | + int menuCategory = AdminMenuCategory.LOCATION_TAXES.ordinal(); |
| 114 | + model.addAttribute("menuCategory",menuCategory); |
| 115 | + List<Country> countries = customerService.findAllCountriesOrderByName(); |
| 116 | + model.addAttribute("countries",countries); |
| 117 | + model.addAttribute("thisCountry",thisCountry); |
| 118 | + List<AddressFormat> addressFormats = adminService.findAllAddressFormat(); |
| 119 | + model.addAttribute("addressFormats",addressFormats); |
| 120 | + return "admin/countriesEditForm"; |
| 121 | + } else { |
| 122 | + thisCountry.setId(countryId); |
| 123 | + adminService.updateCountry(thisCountry); |
| 124 | + return "redirect:/admin/countries/"+countryId; |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + @RequestMapping(value = "/admin/countries/{countryId}/delete", method = RequestMethod.GET) |
| 129 | + public String countriesDeleteForm(@PathVariable long countryId, Model model){ |
| 130 | + int menuCategory = AdminMenuCategory.LOCATION_TAXES.ordinal(); |
| 131 | + model.addAttribute("menuCategory",menuCategory); |
| 132 | + Country thisCountry = customerService.findCountryById(countryId); |
| 133 | + model.addAttribute("thisCountry",thisCountry); |
| 134 | + List<Country> countries = customerService.findAllCountriesOrderByName(); |
| 135 | + model.addAttribute("countries",countries); |
| 136 | + return "admin/countriesDeleteForm"; |
| 137 | + } |
| 138 | + |
| 139 | + @RequestMapping(value = "/admin/countries/{countryId}/delete", method = RequestMethod.POST) |
| 140 | + public String countriesDeleteSave(@PathVariable long countryId, Model model){ |
| 141 | + Country thisCountry = customerService.findCountryById(countryId); |
| 142 | + adminService.deleteCountry(thisCountry); |
| 143 | + return "redirect:/admin/countries"; |
| 144 | + } |
| 145 | + |
63 | 146 | @RequestMapping(value = "/admin/zones", method = RequestMethod.GET) |
64 | 147 | public String zones(Model model){ |
65 | 148 | int menuCategory = AdminMenuCategory.LOCATION_TAXES.ordinal(); |
|
0 commit comments