Consolidated ASP Classic MVC framework from best components
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

227 lignes
7.9KB

  1. <%
  2. ' TerritoryController - CRUD controller for Territories
  3. ' Generated for NorthTerritory app
  4. '
  5. ' Dependencies:
  6. ' - app/models/POBO_Territories.asp
  7. ' - app/models/TerritoriesRepository.asp
  8. %>
  9. <!--#include file="../models/POBO_Territories.asp" -->
  10. <!--#include file="../models/TerritoriesRepository.asp" -->
  11. <%
  12. Class TerritoryController_Class
  13. Private m_useLayout
  14. Private m_title
  15. ' Public properties for views
  16. Public territories ' LinkedList for Index
  17. Public territory ' Single POBO for Show/Edit
  18. Public territoryHouseholdCounts
  19. Public territoryStreets ' LinkedList of street names for Show
  20. ' Pagination properties
  21. Public currentPage
  22. Public pageCount
  23. Public recordCount
  24. Public perPage
  25. Public searchTerm
  26. Private Sub Class_Initialize()
  27. m_useLayout = True
  28. m_title = "Territories"
  29. currentPage = 1
  30. pageCount = 0
  31. recordCount = 0
  32. perPage = 20
  33. searchTerm = ""
  34. Set territoryHouseholdCounts = Nothing
  35. End Sub
  36. Public Property Get useLayout
  37. useLayout = m_useLayout
  38. End Property
  39. Public Property Let useLayout(v)
  40. m_useLayout = v
  41. End Property
  42. Public Property Get Title
  43. Title = m_title
  44. End Property
  45. Public Property Let Title(v)
  46. m_title = v
  47. End Property
  48. '-------------------------------------------------------------------------------------------------------------------
  49. ' Index - List all territories with pagination and search
  50. '-------------------------------------------------------------------------------------------------------------------
  51. Public Sub Index()
  52. ' Get pagination params
  53. If Request.QueryString("page") <> "" And IsNumeric(Request.QueryString("page")) Then
  54. currentPage = CInt(Request.QueryString("page"))
  55. If currentPage < 1 Then currentPage = 1
  56. End If
  57. ' Get search param
  58. searchTerm = Trim(Request.QueryString("q") & "")
  59. ' Fetch territories with pagination
  60. If searchTerm <> "" Then
  61. ' Search in Name and Description columns
  62. Set territories = TerritoriesRepository.SearchTablePaged( _
  63. Array("Name", "Description"), _
  64. searchTerm, _
  65. Empty, _
  66. perPage, _
  67. currentPage, _
  68. pageCount, _
  69. recordCount _
  70. )
  71. Else
  72. Set territories = TerritoriesRepository.FindPaged( _
  73. Empty, _
  74. Empty, _
  75. perPage, _
  76. currentPage, _
  77. pageCount, _
  78. recordCount _
  79. )
  80. End If
  81. Set territoryHouseholdCounts = HouseholdsRepository.GetCountsByTerritory()
  82. %> <!--#include file="../views/Territory/index.asp" --> <%
  83. End Sub
  84. '-------------------------------------------------------------------------------------------------------------------
  85. ' Show - Display a single territory
  86. '-------------------------------------------------------------------------------------------------------------------
  87. Public Sub Show(id)
  88. On Error Resume Next
  89. Set territory = TerritoriesRepository.FindByID(id)
  90. If Err.Number <> 0 Or territory Is Nothing Then
  91. On Error GoTo 0
  92. Flash().AddError "Territory not found."
  93. Response.Redirect "/territories"
  94. Exit Sub
  95. End If
  96. On Error GoTo 0
  97. ' Load distinct street names for this territory
  98. Set territoryStreets = HouseholdsRepository.GetDistinctStreetsByTerritory(id)
  99. %> <!--#include file="../views/Territory/show.asp" --> <%
  100. End Sub
  101. '-------------------------------------------------------------------------------------------------------------------
  102. ' Create - Display form for new territory
  103. '-------------------------------------------------------------------------------------------------------------------
  104. Public Sub Create()
  105. Set territory = New POBO_Territories
  106. %> <!--#include file="../views/Territory/create.asp" --> <%
  107. End Sub
  108. '-------------------------------------------------------------------------------------------------------------------
  109. ' Store - Save new territory
  110. '-------------------------------------------------------------------------------------------------------------------
  111. Public Sub Store()
  112. Set territory = New POBO_Territories
  113. territory.Name = Trim(Request.Form("Name"))
  114. territory.Description = Trim(Request.Form("Description"))
  115. territory.Coordinates = Trim(Request.Form("Coordinates"))
  116. ' Validation
  117. If territory.Name = "" Then
  118. Flash().AddError "Name is required."
  119. Response.Redirect "/territories/new"
  120. Exit Sub
  121. End If
  122. TerritoriesRepository.AddNew territory
  123. Flash().Success = "Territory created successfully."
  124. Response.Redirect "/territories/" & territory.Id
  125. End Sub
  126. '-------------------------------------------------------------------------------------------------------------------
  127. ' Edit - Display form to edit territory
  128. '-------------------------------------------------------------------------------------------------------------------
  129. Public Sub Edit(id)
  130. On Error Resume Next
  131. Set territory = TerritoriesRepository.FindByID(id)
  132. If Err.Number <> 0 Or territory Is Nothing Then
  133. On Error GoTo 0
  134. Flash().AddError "Territory not found."
  135. Response.Redirect "/territories"
  136. Exit Sub
  137. End If
  138. On Error GoTo 0
  139. %> <!--#include file="../views/Territory/edit.asp" --> <%
  140. End Sub
  141. '-------------------------------------------------------------------------------------------------------------------
  142. ' Update - Save changes to territory
  143. '-------------------------------------------------------------------------------------------------------------------
  144. Public Sub Update(id)
  145. On Error Resume Next
  146. Set territory = TerritoriesRepository.FindByID(id)
  147. If Err.Number <> 0 Or territory Is Nothing Then
  148. On Error GoTo 0
  149. Flash().AddError "Territory not found."
  150. Response.Redirect "/territories"
  151. Exit Sub
  152. End If
  153. On Error GoTo 0
  154. territory.Name = Trim(Request.Form("Name"))
  155. territory.Description = Trim(Request.Form("Description"))
  156. territory.Coordinates = Trim(Request.Form("Coordinates"))
  157. ' Validation
  158. If territory.Name = "" Then
  159. Flash().AddError "Name is required."
  160. Response.Redirect "/territories/" & id & "/edit"
  161. Exit Sub
  162. End If
  163. TerritoriesRepository.Update territory
  164. Flash().Success = "Territory updated successfully."
  165. Response.Redirect "/territories/" & id
  166. End Sub
  167. '-------------------------------------------------------------------------------------------------------------------
  168. ' Delete - Remove a territory
  169. '-------------------------------------------------------------------------------------------------------------------
  170. Public Sub Delete(id)
  171. On Error Resume Next
  172. Set territory = TerritoriesRepository.FindByID(id)
  173. If Err.Number <> 0 Or territory Is Nothing Then
  174. On Error GoTo 0
  175. Flash().AddError "Territory not found."
  176. Response.Redirect "/territories"
  177. Exit Sub
  178. End If
  179. On Error GoTo 0
  180. TerritoriesRepository.Delete id
  181. Flash().Success = "Territory deleted successfully."
  182. Response.Redirect "/territories"
  183. End Sub
  184. End Class
  185. ' Singleton instance
  186. Dim TerritoryController_Class__Singleton
  187. Function TerritoryController()
  188. If IsEmpty(TerritoryController_Class__Singleton) Then
  189. Set TerritoryController_Class__Singleton = New TerritoryController_Class
  190. End If
  191. Set TerritoryController = TerritoryController_Class__Singleton
  192. End Function
  193. %>

Powered by TurnKey Linux.