_TenantChange.cshtml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. @using WeApp
  2. @using WeApp.Configuration
  3. @using WeApp.Helpers
  4. @using WeApp.Views.Shared.Modals
  5. @model WeApp.BaseSystem.Sessions.Dto.TenantLoginInfoDto
  6. <div class="text-center" style="margin-bottom: 3px;">
  7. <span>
  8. @L("CurrentTenant"):
  9. @if (Model!=null)
  10. {
  11. <span title="@Model.Name"><strong>@Model.TenancyName</strong></span>
  12. }
  13. else
  14. {
  15. <span>@L("NotSelected")</span>
  16. }
  17. (<a href="#" data-toggle="modal" data-target="#TenantChangeModal">@L("Change")</a>)
  18. </span>
  19. </div>
  20. @{
  21. }
  22. @using (Html.BeginScripts())
  23. {
  24. <script>
  25. (function () {
  26. // var _accountService = abp.services.app.account;
  27. $(function() {
  28. var $tenantChangeForm = $('#TenantChangeForm');
  29. function switchToSelectedTenant() {
  30. var tenancyName = $tenantChangeForm.find('input[name=TenancyName]').val();
  31. if (!tenancyName) {
  32. abp.multiTenancy.setTenantIdCookie(null);
  33. location.reload();
  34. return;
  35. }
  36. $.iwbAjax4({
  37. url: '@Path.Combine(ApplicationPath, IwbConsts.ApiAppUrl)account/isTenantAvailable',
  38. form:$tenantChangeForm,
  39. success: function (result) {
  40. switch (result.state) {
  41. case 1: //Available
  42. abp.multiTenancy.setTenantIdCookie(result.tenantId);
  43. //_modalManager.close();
  44. location.reload();
  45. return;
  46. case 2: //InActive
  47. abp.message.warn(abp.utils.formatString(abp.localization
  48. .localize("TenantIsNotActive", "WeApp"),
  49. tenancyName));
  50. break;
  51. case 3: //NotFound
  52. abp.message.warn(abp.utils.formatString(abp.localization
  53. .localize("ThereIsNoTenantDefinedWithName{0}", "WeApp"),
  54. tenancyName));
  55. break;
  56. }
  57. }
  58. });
  59. //_accountService.isTenantAvailable({
  60. // tenancyName: tenancyName
  61. //}).done(function (result) {
  62. // switch (result.state) {
  63. // case 1: //Available
  64. // abp.multiTenancy.setTenantIdCookie(result.tenantId);
  65. // //_modalManager.close();
  66. // location.reload();
  67. // return;
  68. // case 2: //InActive
  69. // abp.message.warn(abp.utils.formatString(abp.localization
  70. // .localize("TenantIsNotActive", "WeApp"),
  71. // tenancyName));
  72. // break;
  73. // case 3: //NotFound
  74. // abp.message.warn(abp.utils.formatString(abp.localization
  75. // .localize("ThereIsNoTenantDefinedWithName{0}", "WeApp"),
  76. // tenancyName));
  77. // break;
  78. // }
  79. //});
  80. }
  81. //Handle save button click
  82. $tenantChangeForm.closest('div.modal-content').find(".save-btn").click(function (e) {
  83. e.preventDefault();
  84. switchToSelectedTenant();
  85. });
  86. //Handle enter key
  87. $tenantChangeForm.find('input').on('keypress', function (e) {
  88. if (e.which === 13) {
  89. e.preventDefault();
  90. switchToSelectedTenant();
  91. }
  92. });
  93. $.AdminBSB.input.activate($tenantChangeForm);
  94. $('#TenantChangeModal').on('shown.bs.modal', function () {
  95. $tenantChangeForm.find('input[type=text]:first').focus();
  96. });
  97. });
  98. })();
  99. </script>
  100. @Html.Partial("Modals/_Modal", tenantModal)
  101. }