25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

129 satır
5.1KB

  1. <%
  2. Class IndustriesController_Class
  3. Private m_useLayout
  4. Private m_title
  5. Private Sub Class_Initialize()
  6. m_useLayout = True
  7. m_title = "Industries"
  8. End Sub
  9. Public Property Get useLayout
  10. useLayout = m_useLayout
  11. End Property
  12. Public Property Let useLayout(v)
  13. m_useLayout = v
  14. End Property
  15. Public Property Get Title
  16. Title = m_title
  17. End Property
  18. Public Property Let Title(v)
  19. m_title = v
  20. End Property
  21. '-------------------------------------------------------------------------------------------------------------------
  22. ' GET /industries
  23. '-------------------------------------------------------------------------------------------------------------------
  24. Public Sub index()
  25. Dim list, uncategorized, csrf
  26. Set list = IndustryRepository().All()
  27. uncategorized = IndustryRepository().UncategorizedCount()
  28. csrf = Csrf_Token("industries")
  29. %>
  30. <!--#include file="../views/Industries/index.asp" -->
  31. <%
  32. End Sub
  33. '-------------------------------------------------------------------------------------------------------------------
  34. ' POST /industries/create
  35. '-------------------------------------------------------------------------------------------------------------------
  36. Public Sub create()
  37. Dim name
  38. GuardCsrf
  39. name = Left(Trim(F("name")), 100)
  40. If Len(name) = 0 Then Fail "Enter an industry name."
  41. If IndustryRepository().NameTaken(name, 0) Then Fail """" & name & """ already exists."
  42. IndustryRepository().Create name
  43. Flash().Success = "Added """ & name & """."
  44. Response.Redirect "/industries"
  45. End Sub
  46. '-------------------------------------------------------------------------------------------------------------------
  47. ' POST /industries/:id/rename
  48. '-------------------------------------------------------------------------------------------------------------------
  49. Public Sub rename(id)
  50. Dim ind, name
  51. Set ind = Load(id)
  52. name = Left(Trim(F("name")), 100)
  53. If Len(name) = 0 Then Fail "The name can't be blank."
  54. If IndustryRepository().NameTaken(name, ind("id")) Then
  55. Fail """" & name & """ already exists. Use Merge to combine them."
  56. End If
  57. IndustryRepository().Rename ind("id"), name
  58. Flash().Success = "Renamed to """ & name & """."
  59. Response.Redirect "/industries"
  60. End Sub
  61. '-------------------------------------------------------------------------------------------------------------------
  62. ' POST /industries/:id/merge : move everything from this industry into another one, then delete this one
  63. '-------------------------------------------------------------------------------------------------------------------
  64. Public Sub merge(id)
  65. Dim ind, target, moved
  66. Set ind = Load(id)
  67. If Not Valid_Id(F("target_id")) Then Fail "Choose the industry to merge into."
  68. If CLng(F("target_id")) = ind("id") Then Fail "Choose a different industry to merge into."
  69. Set target = IndustryRepository().Find(CLng(F("target_id")))
  70. If target Is Nothing Then Fail "That industry no longer exists."
  71. moved = IndustryRepository().Merge(ind("id"), target("id"))
  72. Flash().Success = "Merged """ & ind("name") & """ into """ & target("name") & """ (" & moved & " businesses moved)."
  73. Response.Redirect "/industries"
  74. End Sub
  75. '-------------------------------------------------------------------------------------------------------------------
  76. ' POST /industries/:id/delete : only when no business uses it
  77. '-------------------------------------------------------------------------------------------------------------------
  78. Public Sub delete(id)
  79. Dim ind
  80. Set ind = Load(id)
  81. If ind("n") > 0 Then Fail "Can't delete """ & ind("name") & """ while " & ind("n") & " businesses use it. Merge it instead."
  82. IndustryRepository().Delete ind("id")
  83. Flash().Success = "Deleted """ & ind("name") & """."
  84. Response.Redirect "/industries"
  85. End Sub
  86. '-------------------------------------------------------------------------------------------------------------------
  87. Private Function Load(id)
  88. GuardCsrf
  89. If Not Valid_Id(id) Then Response.Redirect "/404"
  90. Dim ind : Set ind = IndustryRepository().Find(CLng(id))
  91. If ind Is Nothing Then Response.Redirect "/404"
  92. Set Load = ind
  93. End Function
  94. Private Sub GuardCsrf()
  95. If Not Csrf_Valid("industries", F("csrf")) Then Fail "Invalid form state. Please try again."
  96. End Sub
  97. Private Sub Fail(msg)
  98. Flash().AddError msg
  99. Response.Redirect "/industries"
  100. End Sub
  101. Private Function F(name)
  102. F = CStr(Request.Form(name))
  103. End Function
  104. End Class
  105. Dim IndustriesController_Class__Singleton
  106. Function IndustriesController()
  107. If IsEmpty(IndustriesController_Class__Singleton) Then
  108. Set IndustriesController_Class__Singleton = New IndustriesController_Class
  109. End If
  110. Set IndustriesController = IndustriesController_Class__Singleton
  111. End Function
  112. %>

Powered by TurnKey Linux.