_SearchCustomerPartial.cshtml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. @model GreenTree.Strohrmann.ERP.Web.Models.Search.ICustomerSearchable
  2. @{
  3. var partialId = Html.RandomId();
  4. }
  5. <script type="text/javascript">
  6. @{
  7. <text>
  8. $(document).ready(function () {
  9. $("#text_@partialId").on('keypress', function (e) {
  10. if (e.keyCode == 13) {
  11. search_@partialId ();
  12. e.preventDefault();
  13. };
  14. });
  15. $("#text_@partialId").on('keydown', function (e) {
  16. if (e.keyCode == 8 && $("#value_@partialId").val() != "") {
  17. $("#text_@partialId").val("");
  18. $("#value_@partialId").val("");
  19. $("#text_@partialId").next().children(".fa-check-circle").fadeOut("fast", function () {
  20. $("#text_@partialId").next().children(".fa-ellipsis-h").fadeIn("fast");
  21. });
  22. e.preventDefault();
  23. };
  24. });
  25. });
  26. function search_@partialId () {
  27. $.ajax({
  28. method: "POST",
  29. url: "@Url.Action("Search", "Customer")",
  30. data: {
  31. SearchTerm: $("#text_@partialId").val()
  32. },
  33. success: function (data) {
  34. $("#searchCustomerModal_@partialId").find(".list-group").empty();
  35. if (data.length > 0) {
  36. $(data).each(function (index, elem) {
  37. $("#searchCustomerModal_@partialId").find(".list-group").append(
  38. '<a href="#" class="list-group-item list-group-item-info list-group-item-action" ' +
  39. 'data-toggle="list" data-val="{0}" data-text="{1}" ondblclick="select_@partialId ()">{1} ({2})</a>'
  40. .format(elem.id, elem.fullname, elem.localAddress));
  41. });
  42. } else {
  43. $("#searchCustomerModal_@partialId").find(".list-group").append(
  44. '<button type="button" class="list-group-item">Keine Treffer</button>');
  45. }
  46. $("#searchCustomerModal_@partialId").modal("show");
  47. },
  48. error: function (msg) {
  49. }
  50. });
  51. }
  52. function select_@partialId () {
  53. $("#searchCustomerModal_@partialId").modal("hide");
  54. var val = $("#searchCustomerModal_@partialId").find("a.active").attr("data-val");
  55. var text = $("#searchCustomerModal_@partialId").find("a.active").attr("data-text");
  56. $("#value_@partialId").val(val);
  57. $("#text_@partialId").val(text);
  58. $("#text_@partialId").next().children(".fa-ellipsis-h").fadeOut("fast", function () {
  59. $("#text_@partialId").next().children(".fa-check-circle").fadeIn("fast");
  60. });
  61. }
  62. </text>
  63. }
  64. </script>
  65. <div class="input-group">
  66. <div class="input-group-prepend">
  67. <button class="btn btn-info fas fa-search" type="button" onclick="search_@partialId ()"></button>
  68. </div>
  69. <input id="text_@partialId" type="text" asp-for="CustomerText" class="form-control" placeholder="Suchbegriff"
  70. aria-label="Suchbegriff" aria-describedby="basic-addon1">
  71. <div class="input-group-append">
  72. @if (Model.CustomerId > 0)
  73. {
  74. @Html.Span("", new { @class = "input-group-text bg-success text-white rounded-right fas fa-cust-lh fa-check-circle" })
  75. @Html.Span("", new { @class = "input-group-text rounded-right fas fa-cust-lh fa-ellipsis-h", style = "display: none" })
  76. }
  77. else
  78. {
  79. @Html.Span("", new { @class = "input-group-text bg-success text-white rounded-right fas fa-cust-lh fa-check-circle", style = "display: none" })
  80. @Html.Span("", new { @class = "input-group-text rounded-right fas fa-cust-lh fa-ellipsis-h" })
  81. }
  82. </div>
  83. </div>
  84. <input id="value_@partialId" type="hidden" asp-for="CustomerId" />
  85. <div id="searchCustomerModal_@partialId" class="modal fade">
  86. <div class="modal-dialog">
  87. <div class="modal-content">
  88. <div class="modal-header">
  89. <h4 class="modal-title">Suchergebnisse</h4>
  90. </div>
  91. <div class="modal-body overflow-auto" style="max-height: 400px">
  92. <div class="list-group">
  93. </div>
  94. </div>
  95. <div class="modal-footer">
  96. <div class="btn btn-secondary" data-dismiss="modal">Schließen</div>
  97. <div class="btn btn-success" onclick="select_@partialId ()">Auswählen</div>
  98. </div>
  99. </div>
  100. </div>
  101. </div>