PWA Fundvelo der Caritas.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CaritasServiceFundVeloAlternatePickupContactPage.razor 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. @page "/fundvelo/alternate_pickup"
  2. @using cwebplusApp.Shared.Models;
  3. @using cwebplusApp.Shared.Services;
  4. @inject NavigationManager NavigationManager
  5. @inject UserDataProvider UserDataProvider
  6. @inject IStringLocalizer<Resources> I18n
  7. @inject PageHistoryManager PageHistoryManager
  8. @inject ReportDataProvider ReportDataProvider
  9. @inject Toaster Toaster
  10. @inject InputCursorHandler InputCursorHandler
  11. @inject MasterDataService MasterDataService
  12. <div class="row px-3 h-100">
  13. @*<div class="row no-gutters align-items-start justify-content-center w-100">
  14. <MatHeadline4 Style="font-family:Ubuntu;padding-top:1em">@I18n["PickupContact"]</MatHeadline4>
  15. </div>*@
  16. <div class="row no-gutters align-items-center justify-content-center w-100" style="padding-top:1em">
  17. <h2>@I18n["PickupContact"]</h2>
  18. </div>
  19. <div class="row no-gutters align-items-start w-100">
  20. <div class="row no-gutters w-100">
  21. <div class="col-12">
  22. <MatSelect Class="w-100 required" Label="@I18n["Salutation"]" Outlined="true" @bind-Value="pucSalutation" Required="true" Style="margin-bottom: 0.5rem"
  23. @onkeydown="InputCursorHandler.OnKeyDownHandlerAsync">
  24. <MatOptionString Value="M">@I18n["Male"]</MatOptionString>
  25. <MatOptionString Value="F">@I18n["Female"]</MatOptionString>
  26. </MatSelect>
  27. </div>
  28. </div>
  29. <div class="row no-gutters w-100">
  30. <div class="col-6" style="padding-right:0.5em">
  31. <MatStringField Class="w-100" Label="@I18n["Firstname"]" Outlined="true" type="text" @bind-Value="pucFirstname" Required="true"
  32. OnKeyDown="@InputCursorHandler.OnKeyDownHandlerAsync" maxlength="50"></MatStringField>
  33. </div>
  34. <div class="col-6" style="padding-left:0.5em">
  35. <MatStringField Class="w-100" Label="@I18n["Lastname"]" Outlined="true" type="text" @bind-Value="pucLastname" Required="true"
  36. OnKeyDown="@InputCursorHandler.OnKeyDownHandlerAsync" maxlength="50"></MatStringField>
  37. </div>
  38. </div>
  39. <div class="row no-gutters align-items-center w-100">
  40. <div class="col-12">
  41. <MatStringField Class="w-100" Label="@I18n["Address"]" Outlined="true" type="text" @bind-Value="pucAddress" Required="true"
  42. OnKeyDown="@InputCursorHandler.OnKeyDownHandlerAsync" maxlength="50"></MatStringField>
  43. </div>
  44. </div>
  45. <div class="row no-gutters align-items-center w-100">
  46. <div class="col-12">
  47. <div class="outlined">
  48. <MatAutocompleteList TItem="ZipCity" FullWidth="true" Label="@getZipCityLbl()" Required="true" Items="@ZipCities" OnTextChanged="setZipCityValue" @bind-Value="SelectedZipCity" CustomStringSelector="@(i => i?.Zip_City)"
  49. ShowClearButton="true" NumberOfElementsInPopup="6" @onkeydown="InputCursorHandler.OnKeyDownHandlerAsync">
  50. <ItemTemplate>
  51. <div>
  52. <span>@context?.Zip_City</span>
  53. </div>
  54. </ItemTemplate>
  55. </MatAutocompleteList>
  56. </div>
  57. </div>
  58. </div>
  59. <div class="row no-gutters align-items-center w-100">
  60. <div class="col-12">
  61. <MatStringField Class="w-100" Label="@I18n["Mobile"]" Outlined="true" type="text" @bind-Value="pucMobile"
  62. OnKeyDown="@InputCursorHandler.OnConstrainedFieldKeyDownHandlerAsync" maxlength="20" pattern="^([0-9]*)$"></MatStringField>
  63. </div>
  64. </div>
  65. <div class="row no-gutters align-items-center w-100">
  66. <div class="col-12">
  67. <MatStringField Class="w-100" Label="@I18n["Phone"]" Outlined="true" type="text" @bind-Value="pucPhone"
  68. OnKeyDown="@InputCursorHandler.OnConstrainedFieldKeyDownHandlerAsync" maxlength="20" pattern="^([0-9]*)$"></MatStringField>
  69. </div>
  70. </div>
  71. <div class="row no-gutters align-items-center w-100">
  72. <div class="col-12">
  73. <MatStringField Class="w-100" Label="@I18n["Mail"]" Outlined="true" type="email" @bind-Value="pucEmail" Required="true"
  74. OnKeyDown="@InputCursorHandler.OnKeyDownHandlerAsync" maxlength="50"></MatStringField>
  75. </div>
  76. </div>
  77. </div>
  78. <div class="row no-gutters align-items-end justify-content-center w-100" style="padding-bottom:2em">
  79. <div class="col" style="padding-right:0.5em">
  80. <MatButton Class="w-100" Outlined="true" @onclick="Cancel">@I18n["Cancel"]</MatButton>
  81. </div>
  82. <div class="col" style="padding-left:0.5em">
  83. <MatButton Class="w-100" Raised="true" @onclick="Next">@I18n["Continue"]</MatButton>
  84. </div>
  85. </div>
  86. </div>
  87. @code {
  88. private string pucSalutation;
  89. private string pucFirstname;
  90. private string pucLastname;
  91. private string pucAddress;
  92. private string pucMobile;
  93. private string pucPhone;
  94. private string pucEmail;
  95. private string pucZipCityStringValue;
  96. private ZipCity selectedZipCity;
  97. private ZipCity SelectedZipCity {
  98. get { return selectedZipCity; }
  99. set { selectedZipCity = (value != null) ? value : new ZipCity(pucZipCityStringValue); }
  100. }
  101. private void setZipCityValue(string value) {
  102. pucZipCityStringValue = value;
  103. selectedZipCity = null;
  104. }
  105. private ZipCity[] ZipCities {
  106. get => MasterDataService.ZipCities;
  107. }
  108. protected override void OnInitialized() {
  109. base.OnInitialized();
  110. PageHistoryManager.OnBeforeNavigateBack = new EventCallback(this, (Action)OnBeforeNavigateBack);
  111. refreshGUIFromDto();
  112. StateHasChanged();
  113. }
  114. private void OnBeforeNavigateBack() {
  115. updateDtoFromGUI();
  116. }
  117. private void Next() {
  118. updateDtoFromGUI();
  119. PageHistoryManager.AddPageToHistory(NavigationManager.Uri);
  120. try {
  121. Validator.ValidateAlternatePickContact(ReportDataProvider.GetFoundReport());
  122. NavigationManager.NavigateTo("fundvelo/account/Found");
  123. } catch (ArgumentException) {
  124. Toaster.ShowWarning(I18n.GetString("Warning.MandatoryFields.Title"), I18n.GetString("Warning.MandatoryFields.Msg"));
  125. }
  126. }
  127. private void Cancel() {
  128. NavigationManager.NavigateTo("caritas_services");
  129. }
  130. private string getZipCityLbl() {
  131. return String.Format("{0} {1}", I18n.GetString("Zip"), I18n.GetString("City"));
  132. }
  133. private void refreshGUIFromDto() {
  134. FoundReport report = ReportDataProvider.GetFoundReport();
  135. pucSalutation = report.AbholAnrede;
  136. pucFirstname = report.AbholVorname;
  137. pucLastname = report.AbholNachname;
  138. pucAddress = report.AbholStrasse;
  139. setZipCityValue(getZipCityFromReport(report));
  140. SelectedZipCity = Array.Find(ZipCities, zipCity => (zipCity.Zip.Equals(report.AbholPLZ) && zipCity.City.Equals(report.AbholOrt)));
  141. pucMobile = report.AbholMobil;
  142. pucPhone = report.AbholTelefon;
  143. pucEmail = report.AbholMail;
  144. }
  145. private void updateDtoFromGUI() {
  146. FoundReport report = ReportDataProvider.GetFoundReport();
  147. report.AbholAnrede = pucSalutation;
  148. report.AbholVorname = pucFirstname;
  149. report.AbholNachname = pucLastname;
  150. report.AbholStrasse = pucAddress;
  151. report.AbholPLZ = SelectedZipCity.Zip;
  152. report.AbholOrt = SelectedZipCity.City;
  153. report.AbholMobil = pucMobile;
  154. report.AbholTelefon = pucPhone;
  155. report.AbholMail = pucEmail;
  156. }
  157. private String getZipCityFromReport(FoundReport report) {
  158. return report.AbholPLZ + (!String.IsNullOrEmpty(report.AbholOrt)? " " + report.AbholOrt: "");
  159. }
  160. }