Consolidated ASP Classic MVC framework from best components
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

152 rindas
4.7KB

  1. <%
  2. '=======================================================================================================================
  3. ' Flash Message Class
  4. '=======================================================================================================================
  5. Class Flash_Class
  6. Private m_errors_key
  7. Private m_success_key
  8. Private Sub Class_Initialize
  9. ' Use constants to avoid typos
  10. m_errors_key = "mvc.flash.errors_array"
  11. m_success_key = "mvc.flash.success_message"
  12. End Sub
  13. 'helper methods to avoid if..then statements in views
  14. Public Sub ShowErrorsIfPresent
  15. if HasErrors then ShowErrors
  16. End Sub
  17. Public Sub ShowSuccessIfPresent
  18. if HasSuccess then ShowSuccess
  19. End Sub
  20. '---------------------------------------------------------------------------------------------------------------------
  21. ' Errors
  22. '---------------------------------------------------------------------------------------------------------------------
  23. Public Property Get HasErrors
  24. HasErrors = (Not IsEmpty(Session(m_errors_key)))
  25. End Property
  26. Public Property Get Errors
  27. Errors = Session(m_errors_key)
  28. End Property
  29. Public Property Let Errors(ary)
  30. Session(m_errors_key) = ary
  31. End Property
  32. Public Sub AddError(msg)
  33. dim ary
  34. if IsEmpty(Session(m_errors_key)) then
  35. ary = Array()
  36. redim ary(-1)
  37. else
  38. ary = Session(m_errors_key)
  39. end if
  40. redim preserve ary(ubound(ary) + 1)
  41. ary(ubound(ary)) = msg
  42. Session(m_errors_key) = ary
  43. End Sub
  44. 'Public Sub ShowErrors
  45. ' ClearErrors
  46. 'End Sub
  47. Public Sub ShowErrors
  48. if HasErrors then
  49. %>
  50. <div id="flashErrorBox" class="alert alert-danger alert-dismissible fade show" role="alert">
  51. <strong>Error!</strong>
  52. <ul class="mb-0 mt-2">
  53. <%
  54. dim ary, i
  55. ary = Errors
  56. for i = 0 to ubound(ary)
  57. put "<li>"
  58. put H(ary(i))
  59. put "</li>"
  60. next
  61. %>
  62. </ul>
  63. <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
  64. </div>
  65. <script>
  66. (function() {
  67. var timeout = <%= GetAppSetting("FlashMessageTimeout") %>;
  68. if (isNaN(timeout) || timeout <= 0) timeout = 3000;
  69. setTimeout(function() {
  70. var alertEl = document.getElementById("flashErrorBox");
  71. if (alertEl && typeof bootstrap !== 'undefined') {
  72. var bsAlert = bootstrap.Alert.getOrCreateInstance(alertEl);
  73. bsAlert.close();
  74. } else if (alertEl) {
  75. alertEl.style.display = "none";
  76. }
  77. }, timeout);
  78. })();
  79. </script>
  80. <%
  81. ClearErrors
  82. end if
  83. End Sub
  84. Public Sub ClearErrors
  85. Session.Contents.Remove(m_errors_key)
  86. End Sub
  87. '---------------------------------------------------------------------------------------------------------------------
  88. ' Success
  89. '---------------------------------------------------------------------------------------------------------------------
  90. Public Property Get HasSuccess
  91. HasSuccess = (Not IsEmpty(Session(m_success_key)))
  92. End Property
  93. Public Property Get Success
  94. Success = Session(m_success_key)
  95. End Property
  96. Public Property Let Success(msg)
  97. Session(m_success_key) = msg
  98. End Property
  99. Public Sub ShowSuccess
  100. if HasSuccess then
  101. %>
  102. <div id="flashSuccessBox" class="alert alert-success alert-dismissible fade show" role="alert">
  103. <%= H(Success) %>
  104. <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
  105. </div>
  106. <script>
  107. (function() {
  108. var timeout = <%= GetAppSetting("FlashMessageTimeout") %>;
  109. if (isNaN(timeout) || timeout <= 0) timeout = 3000;
  110. setTimeout(function() {
  111. var alertEl = document.getElementById("flashSuccessBox");
  112. if (alertEl && typeof bootstrap !== 'undefined') {
  113. var bsAlert = bootstrap.Alert.getOrCreateInstance(alertEl);
  114. bsAlert.close();
  115. } else if (alertEl) {
  116. alertEl.style.display = "none";
  117. }
  118. }, timeout);
  119. })();
  120. </script>
  121. <%
  122. ClearSuccess
  123. end if
  124. End Sub
  125. Public Sub ClearSuccess
  126. Session.Contents.Remove(m_success_key)
  127. End Sub
  128. End Class
  129. Function Flash()
  130. set Flash = new Flash_Class
  131. End Function
  132. %>

Powered by TurnKey Linux.