opensteam 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (265) hide show
  1. data/CHANGELOG +78 -0
  2. data/LICENSE +345 -0
  3. data/{README.txt → README.rdoc} +20 -17
  4. data/Rakefile +40 -0
  5. data/generators/opensteam/opensteam_generator.rb +95 -194
  6. data/generators/opensteam/templates/{controllers/administration → app/controllers/admin}/inventories_controller.rb +4 -4
  7. data/generators/opensteam/templates/app/controllers/admin/invoices_controller.rb +106 -0
  8. data/generators/opensteam/templates/app/controllers/admin/orders_controller.rb +113 -0
  9. data/generators/opensteam/templates/app/controllers/admin/search_controller.rb +17 -0
  10. data/generators/opensteam/templates/app/controllers/admin/shipments_controller.rb +106 -0
  11. data/generators/opensteam/templates/app/controllers/admin/users_controller.rb +99 -0
  12. data/generators/opensteam/templates/app/controllers/admin_controller.rb +40 -0
  13. data/generators/opensteam/templates/app/controllers/cart_controller.rb +94 -0
  14. data/generators/opensteam/templates/app/controllers/checkout_controller.rb +139 -0
  15. data/generators/opensteam/templates/app/controllers/profile/infos_controller.rb +52 -0
  16. data/generators/opensteam/templates/app/controllers/profile/orders_controller.rb +105 -0
  17. data/generators/opensteam/templates/app/controllers/profile_controller.rb +37 -0
  18. data/generators/opensteam/templates/app/controllers/searches_controller.rb +23 -0
  19. data/generators/opensteam/templates/app/controllers/user_sessions_controller.rb +38 -0
  20. data/generators/opensteam/templates/app/controllers/users_controller.rb +40 -0
  21. data/generators/opensteam/templates/{controllers → app/controllers}/webshop_controller.rb +35 -13
  22. data/generators/opensteam/templates/app/helpers/admin_helper.rb +40 -0
  23. data/generators/opensteam/templates/app/helpers/users_helper.rb +53 -0
  24. data/generators/opensteam/templates/app/helpers/webshop_helper.rb +91 -0
  25. data/generators/opensteam/templates/app/models/search.rb +36 -0
  26. data/generators/opensteam/templates/{views/administration → app/views/admin}/_address.html.erb +0 -0
  27. data/generators/opensteam/templates/app/views/admin/_nav.html.erb +5 -0
  28. data/generators/opensteam/templates/app/views/admin/catalog.html.erb +5 -0
  29. data/generators/opensteam/templates/app/views/admin/index.html.erb +21 -0
  30. data/generators/opensteam/templates/{views/administration → app/views/admin}/inventories/edit.html.erb +10 -9
  31. data/generators/opensteam/templates/{views/administration → app/views/admin}/inventories/index.html.erb +3 -3
  32. data/generators/opensteam/templates/{views/administration → app/views/admin}/inventories/new.html.erb +3 -3
  33. data/generators/opensteam/templates/app/views/admin/inventories/show.html.erb +46 -0
  34. data/generators/opensteam/templates/app/views/admin/invoices/_invoice.html.erb +12 -0
  35. data/generators/opensteam/templates/app/views/admin/invoices/_invoices.html.erb +11 -0
  36. data/generators/opensteam/templates/app/views/admin/invoices/index.html.erb +6 -0
  37. data/generators/opensteam/templates/app/views/admin/invoices/new.html.erb +54 -0
  38. data/generators/opensteam/templates/app/views/admin/invoices/show.html.erb +55 -0
  39. data/generators/opensteam/templates/app/views/admin/orders/_event.html.erb +5 -0
  40. data/generators/opensteam/templates/app/views/admin/orders/_order.html.erb +11 -0
  41. data/generators/opensteam/templates/app/views/admin/orders/_order_item.html.erb +10 -0
  42. data/generators/opensteam/templates/app/views/admin/orders/_orders.html.erb +19 -0
  43. data/generators/opensteam/templates/app/views/admin/orders/index.html.erb +14 -0
  44. data/generators/opensteam/templates/app/views/admin/orders/livesearch.rjs +6 -0
  45. data/generators/opensteam/templates/app/views/admin/orders/show.html.erb +58 -0
  46. data/generators/opensteam/templates/app/views/admin/products.html.erb +8 -0
  47. data/generators/opensteam/templates/app/views/admin/properties.html.erb +7 -0
  48. data/generators/opensteam/templates/app/views/admin/sales.html.erb +5 -0
  49. data/generators/opensteam/templates/app/views/admin/shipments/_shipment.erb +11 -0
  50. data/generators/opensteam/templates/app/views/admin/shipments/_shipments.html.erb +11 -0
  51. data/generators/opensteam/templates/app/views/admin/shipments/index.html.erb +6 -0
  52. data/generators/opensteam/templates/app/views/admin/shipments/new.html.erb +51 -0
  53. data/generators/opensteam/templates/app/views/admin/shipments/show.html.erb +55 -0
  54. data/generators/opensteam/templates/app/views/admin/users/_admins.html.erb +26 -0
  55. data/generators/opensteam/templates/app/views/admin/users/_admins_header.html.erb +10 -0
  56. data/generators/opensteam/templates/app/views/admin/users/_customer.html.erb +32 -0
  57. data/generators/opensteam/templates/app/views/admin/users/_customers.html.erb +29 -0
  58. data/generators/opensteam/templates/app/views/admin/users/_customers_header.html.erb +11 -0
  59. data/generators/opensteam/templates/app/views/admin/users/_user_fields.html.erb +9 -0
  60. data/generators/opensteam/templates/app/views/admin/users/_users.html.erb +29 -0
  61. data/generators/opensteam/templates/app/views/admin/users/_users_header.html.erb +11 -0
  62. data/generators/opensteam/templates/app/views/admin/users/edit.html.erb +6 -0
  63. data/generators/opensteam/templates/app/views/admin/users/index.html.erb +7 -0
  64. data/generators/opensteam/templates/app/views/admin/users/new.html.erb +6 -0
  65. data/generators/opensteam/templates/app/views/admin/users/show.html.erb +34 -0
  66. data/generators/opensteam/templates/app/views/admin/users.html.erb +4 -0
  67. data/generators/opensteam/templates/{views → app/views}/administration_mailer/order_admin.erb +0 -0
  68. data/generators/opensteam/templates/{views → app/views}/administration_mailer/order_customer.erb +0 -0
  69. data/generators/opensteam/templates/app/views/cart/_cart.html.erb +8 -0
  70. data/generators/opensteam/templates/{views/webshop → app/views/cart}/_cart_content.html.erb +7 -10
  71. data/generators/opensteam/templates/app/views/cart/index.html.erb +5 -0
  72. data/generators/opensteam/templates/app/views/cart/update.rjs +1 -0
  73. data/generators/opensteam/templates/app/views/checkout/intro.html.erb +18 -0
  74. data/generators/opensteam/templates/{views → app/views}/checkout/outro.html.erb +0 -1
  75. data/generators/opensteam/templates/{views → app/views}/checkout/payment.html.erb +0 -0
  76. data/generators/opensteam/templates/app/views/checkout/shipping.html.erb +45 -0
  77. data/generators/opensteam/templates/app/views/checkout/show_cart.html.erb +13 -0
  78. data/generators/opensteam/templates/{views → app/views}/checkout/update_cart_content.rjs +0 -0
  79. data/generators/opensteam/templates/{views → app/views}/common/_cart.html.erb +2 -2
  80. data/generators/opensteam/templates/{views → app/views}/common/_cart_content.html.erb +1 -1
  81. data/generators/opensteam/templates/app/views/common/_footer.html.erb +1 -0
  82. data/generators/opensteam/templates/app/views/common/_header.html.erb +4 -0
  83. data/generators/opensteam/templates/app/views/common/_header_flash.html.erb +3 -0
  84. data/generators/opensteam/templates/app/views/common/_signup_fields.html.erb +16 -0
  85. data/generators/opensteam/templates/app/views/common/_top_links.html.erb +10 -0
  86. data/generators/opensteam/templates/app/views/layouts/admin.html.erb +45 -0
  87. data/generators/opensteam/templates/app/views/layouts/profile.html.erb +45 -0
  88. data/generators/opensteam/templates/app/views/layouts/webshop.html.erb +51 -0
  89. data/generators/opensteam/templates/app/views/profile/_customer_sidebar.html.erb +12 -0
  90. data/generators/opensteam/templates/app/views/profile/index.html.erb +11 -0
  91. data/generators/opensteam/templates/app/views/profile/infos/_customer.html.erb +5 -0
  92. data/generators/opensteam/templates/app/views/profile/infos/edit.html.erb +25 -0
  93. data/generators/opensteam/templates/app/views/profile/infos/edit_password.html.erb +26 -0
  94. data/generators/opensteam/templates/app/views/profile/orders/_order.html.erb +11 -0
  95. data/generators/opensteam/templates/app/views/profile/orders/_order_item.html.erb +10 -0
  96. data/generators/opensteam/templates/app/views/profile/orders/_orders.html.erb +19 -0
  97. data/generators/opensteam/templates/app/views/profile/orders/index.html.erb +14 -0
  98. data/generators/opensteam/templates/app/views/profile/orders/show.html.erb +48 -0
  99. data/generators/opensteam/templates/app/views/searches/_search_bar.html.erb +5 -0
  100. data/generators/opensteam/templates/app/views/searches/new.html.erb +23 -0
  101. data/generators/opensteam/templates/app/views/searches/show.html.erb +1 -0
  102. data/generators/opensteam/templates/app/views/user_sessions/new.html.erb +14 -0
  103. data/generators/opensteam/templates/app/views/users/_user_bar.html.erb +5 -0
  104. data/generators/opensteam/templates/app/views/users/index.html.erb +27 -0
  105. data/generators/opensteam/templates/app/views/users/new.html.erb +7 -0
  106. data/generators/opensteam/templates/app/views/users/show.html.erb +5 -0
  107. data/generators/opensteam/templates/{views → app/views}/webshop/_inventory_content.html.erb +0 -0
  108. data/generators/opensteam/templates/app/views/webshop/_nav.html.erb +6 -0
  109. data/generators/opensteam/templates/{views → app/views}/webshop/add_inventory_to_cart.rjs +0 -0
  110. data/generators/opensteam/templates/{views → app/views}/webshop/add_to_cart_with_parameters.rjs +0 -0
  111. data/generators/opensteam/templates/{views → app/views}/webshop/del_item.rjs +0 -0
  112. data/generators/opensteam/templates/app/views/webshop/index.html.erb +11 -0
  113. data/generators/opensteam/templates/{views → app/views}/webshop/inventory.rjs +0 -0
  114. data/generators/opensteam/templates/{views → app/views}/webshop/show.html.erb +15 -15
  115. data/generators/opensteam/templates/config/initializers/init_states.rb +68 -0
  116. data/generators/opensteam/templates/{init → config/initializers}/opensteam.rb +6 -0
  117. data/generators/opensteam/templates/config/initializers/opensteam_model_tables.rb +57 -0
  118. data/generators/opensteam/templates/db/migrate/20080609095714_create_profiles.rb +14 -0
  119. data/generators/opensteam/templates/{migrations/create_sessions.rb → db/migrate/20080609095720_create_sessions.rb} +0 -0
  120. data/generators/opensteam/templates/db/migrate/20080609095721_create_users.rb +29 -0
  121. data/generators/opensteam/templates/{migrations/create_addresses.rb → db/migrate/20080609095723_create_addresses.rb} +0 -0
  122. data/generators/opensteam/templates/{migrations/create_customers.rb → db/migrate/20080609095724_create_customers.rb} +0 -0
  123. data/generators/opensteam/templates/db/migrate/20080609095725_create_dummy_users.rb +21 -0
  124. data/generators/opensteam/templates/{migrations/create_inventories.rb → db/migrate/20080609095726_create_inventories.rb} +0 -0
  125. data/generators/opensteam/templates/{migrations/create_inventories_properties.rb → db/migrate/20080609095727_create_inventories_properties.rb} +0 -0
  126. data/generators/opensteam/templates/{migrations/create_order_items.rb → db/migrate/20080609095728_create_order_items.rb} +5 -0
  127. data/generators/opensteam/templates/db/migrate/20080609095729_create_orders.rb +32 -0
  128. data/generators/opensteam/templates/{migrations/create_payment_types.rb → db/migrate/20080609095730_create_payment_types.rb} +0 -0
  129. data/generators/opensteam/templates/{migrations/create_properties.rb → db/migrate/20080609095731_create_properties.rb} +0 -0
  130. data/generators/opensteam/templates/db/migrate/20080623075613_create_states.rb +13 -0
  131. data/generators/opensteam/templates/db/migrate/20080624132807_create_searches.rb +20 -0
  132. data/generators/opensteam/templates/db/migrate/20080630114155_create_state_histories.rb +14 -0
  133. data/generators/opensteam/templates/db/migrate/20080714131513_create_invoices.rb +20 -0
  134. data/generators/opensteam/templates/db/migrate/20080714131650_create_shipments.rb +19 -0
  135. data/generators/opensteam/templates/lib/authenticated_system.rb +201 -0
  136. data/generators/opensteam/templates/lib/authentication/by_cookie_token.rb +90 -0
  137. data/generators/opensteam/templates/lib/authentication/by_password.rb +68 -0
  138. data/generators/opensteam/templates/lib/authentication.rb +46 -0
  139. data/generators/opensteam/templates/lib/states/invoice/finished.rb +6 -0
  140. data/generators/opensteam/templates/lib/states/invoice/payment_received.rb +8 -0
  141. data/generators/opensteam/templates/lib/states/invoice/pending.rb +6 -0
  142. data/generators/opensteam/templates/lib/states/invoice/waiting_for_payment.rb +5 -0
  143. data/generators/opensteam/templates/lib/states/order/finished.rb +6 -0
  144. data/generators/opensteam/templates/lib/states/order/pending.rb +19 -0
  145. data/generators/opensteam/templates/lib/states/order/processing.rb +11 -0
  146. data/generators/opensteam/templates/lib/states/shipment/finished.rb +6 -0
  147. data/generators/opensteam/templates/lib/states/shipment/pending.rb +5 -0
  148. data/generators/opensteam/templates/lib/tasks/opensteam.rake +114 -0
  149. data/generators/opensteam/templates/public/images/athmo_background.jpg +0 -0
  150. data/generators/opensteam/templates/public/images/bg.jpg +0 -0
  151. data/generators/opensteam/templates/public/images/cart_big.gif +0 -0
  152. data/generators/opensteam/templates/public/images/cross.png +0 -0
  153. data/generators/opensteam/templates/public/images/enter.gif +0 -0
  154. data/generators/opensteam/templates/public/images/menu_background.jpg +0 -0
  155. data/generators/opensteam/templates/public/images/opensteam_background.jpg +0 -0
  156. data/generators/opensteam/templates/public/images/opensteam_logo1.jpg +0 -0
  157. data/generators/opensteam/templates/public/images/opensteam_petstore_logo1.jpg +0 -0
  158. data/generators/opensteam/templates/public/images/opensteam_store_logo.jpg +0 -0
  159. data/generators/opensteam/templates/public/images/os_logo.gif +0 -0
  160. data/generators/opensteam/templates/public/images/slogan.png +0 -0
  161. data/generators/opensteam/templates/public/images/tick.png +0 -0
  162. data/generators/opensteam/templates/public/images/zoom.png +0 -0
  163. data/generators/opensteam/templates/public/index.html +19 -36
  164. data/generators/opensteam/templates/public/javascripts/opensteam.js +30 -0
  165. data/generators/opensteam/templates/public/stylesheets/opensteam_newdesign.css +188 -0
  166. data/generators/opensteam/templates/public/stylesheets/opensteam_white.css +168 -0
  167. data/generators/opensteam/templates/public/stylesheets/webshop.css +0 -1
  168. data/generators/opensteam/templates/tasks/opensteam.rake +1 -1
  169. data/generators/opensteam/templates/{fixtures → test/fixtures}/inventories.yml +0 -0
  170. data/generators/opensteam/templates/{fixtures → test/fixtures}/inventories_properties.yml +0 -0
  171. data/generators/opensteam/templates/{fixtures → test/fixtures}/product_animals.yml +0 -0
  172. data/generators/opensteam/templates/{fixtures → test/fixtures}/product_dog_foods.yml +0 -0
  173. data/generators/opensteam/templates/{fixtures → test/fixtures}/properties.yml +0 -0
  174. data/generators/opensteam_product/opensteam_product_generator.rb +25 -9
  175. data/generators/opensteam_product/templates/controllers/product_controller.rb +5 -4
  176. data/generators/opensteam_product/templates/migration.rb +2 -1
  177. data/generators/opensteam_product/templates/models/product.rb +1 -0
  178. data/generators/opensteam_product/templates/views/{administration → admin}/_attributes.html.erb +1 -1
  179. data/generators/opensteam_product/templates/views/{administration → admin}/_get_products.html.erb +0 -0
  180. data/generators/opensteam_product/templates/views/{administration → admin}/_inventories.html.erb +2 -2
  181. data/generators/opensteam_product/templates/views/admin/edit.html.erb +13 -0
  182. data/generators/opensteam_product/templates/views/{administration → admin}/index.html.erb +5 -5
  183. data/generators/opensteam_product/templates/views/admin/new.html.erb +16 -0
  184. data/generators/opensteam_product/templates/views/{administration → admin}/show.html.erb +2 -2
  185. data/generators/opensteam_property/opensteam_property_generator.rb +8 -8
  186. data/generators/opensteam_property/templates/controllers/property_controller.rb +6 -4
  187. data/generators/opensteam_property/templates/migration.rb +2 -1
  188. data/generators/opensteam_property/templates/models/property.rb +1 -0
  189. data/generators/opensteam_property/templates/views/{administration → admin}/edit.html.erb +3 -3
  190. data/generators/opensteam_property/templates/views/admin/index.html.erb +24 -0
  191. data/generators/opensteam_property/templates/views/{administration → admin}/new.html.erb +2 -2
  192. data/generators/opensteam_property/templates/views/admin/show.html.erb +10 -0
  193. data/lib/opensteam/base.rb +16 -0
  194. data/lib/opensteam/cart_base.rb +227 -0
  195. data/lib/opensteam/checkout.rb +30 -3
  196. data/lib/opensteam/config.rb +37 -0
  197. data/lib/opensteam/extension_base.rb +76 -0
  198. data/lib/opensteam/finder.rb +36 -5
  199. data/lib/opensteam/helper/configurable_table.rb +228 -0
  200. data/lib/opensteam/history.rb +56 -0
  201. data/lib/opensteam/initializer.rb +127 -0
  202. data/lib/opensteam/inventory_base.rb +24 -1
  203. data/lib/opensteam/invoice_base.rb +61 -0
  204. data/lib/opensteam/order_base.rb +105 -14
  205. data/lib/opensteam/product_base.rb +31 -3
  206. data/lib/opensteam/property_base.rb +16 -0
  207. data/lib/opensteam/shipment_base.rb +60 -0
  208. data/lib/opensteam/shopping_cart.rb +32 -14
  209. data/lib/opensteam/state_logic.rb +218 -0
  210. data/lib/opensteam/state_machine.rb +216 -0
  211. data/lib/opensteam/user_base.rb +115 -131
  212. data/lib/opensteam/version.rb +17 -1
  213. data/lib/opensteam.rb +30 -35
  214. metadata +245 -146
  215. data/History.txt +0 -0
  216. data/License.txt +0 -4
  217. data/Manifest.txt +0 -131
  218. data/Manifest.txt.bak +0 -132
  219. data/generators/opensteam/templates/controllers/administration/customers_controller.rb +0 -23
  220. data/generators/opensteam/templates/controllers/administration/orders_controller.rb +0 -61
  221. data/generators/opensteam/templates/controllers/administration_controller.rb +0 -80
  222. data/generators/opensteam/templates/controllers/checkout_controller.rb +0 -142
  223. data/generators/opensteam/templates/helpers/webshop_helper.rb +0 -29
  224. data/generators/opensteam/templates/migrations/create_dummy_users.rb +0 -16
  225. data/generators/opensteam/templates/migrations/create_orders.rb +0 -18
  226. data/generators/opensteam/templates/migrations/create_users.rb +0 -19
  227. data/generators/opensteam/templates/models/administration_mailer.rb +0 -18
  228. data/generators/opensteam/templates/models/inventories_property.rb +0 -10
  229. data/generators/opensteam/templates/models/inventory.rb +0 -57
  230. data/generators/opensteam/templates/public/images/rails.png +0 -0
  231. data/generators/opensteam/templates/views/administration/_nav.html.erb +0 -11
  232. data/generators/opensteam/templates/views/administration/_update_tree.html.erb +0 -18
  233. data/generators/opensteam/templates/views/administration/admin_info.html.erb +0 -12
  234. data/generators/opensteam/templates/views/administration/customers/index.html.erb +0 -27
  235. data/generators/opensteam/templates/views/administration/customers/show.html.erb +0 -27
  236. data/generators/opensteam/templates/views/administration/customers.html.erb +0 -44
  237. data/generators/opensteam/templates/views/administration/index.html.erb +0 -9
  238. data/generators/opensteam/templates/views/administration/inventories/show.html.erb +0 -45
  239. data/generators/opensteam/templates/views/administration/login.html.erb +0 -16
  240. data/generators/opensteam/templates/views/administration/order.html.erb +0 -22
  241. data/generators/opensteam/templates/views/administration/orders/_order_item.html.erb +0 -22
  242. data/generators/opensteam/templates/views/administration/orders/index.html.erb +0 -32
  243. data/generators/opensteam/templates/views/administration/orders/show.html.erb +0 -25
  244. data/generators/opensteam/templates/views/administration/orders.html.erb +0 -32
  245. data/generators/opensteam/templates/views/administration/products.html.erb +0 -7
  246. data/generators/opensteam/templates/views/administration/properties.html.erb +0 -7
  247. data/generators/opensteam/templates/views/administration/show_order_item.html.erb +0 -5
  248. data/generators/opensteam/templates/views/administration/signup.html.erb +0 -65
  249. data/generators/opensteam/templates/views/administration/tree.html.erb +0 -15
  250. data/generators/opensteam/templates/views/administration/update_products.html.erb +0 -5
  251. data/generators/opensteam/templates/views/administration/update_properties.html.erb +0 -5
  252. data/generators/opensteam/templates/views/administration/update_tree.rjs +0 -3
  253. data/generators/opensteam/templates/views/checkout/intro.html.erb +0 -5
  254. data/generators/opensteam/templates/views/checkout/shipping.html.erb +0 -39
  255. data/generators/opensteam/templates/views/checkout/show_cart.html.erb +0 -13
  256. data/generators/opensteam/templates/views/common/_header.html.erb +0 -15
  257. data/generators/opensteam/templates/views/layouts/administration.html.erb +0 -29
  258. data/generators/opensteam/templates/views/layouts/webshop.html.erb +0 -36
  259. data/generators/opensteam/templates/views/webshop/_cart.html.erb +0 -11
  260. data/generators/opensteam/templates/views/webshop/_header.html.erb +0 -15
  261. data/generators/opensteam/templates/views/webshop/index.html.erb +0 -12
  262. data/generators/opensteam_product/templates/views/administration/edit.html.erb +0 -13
  263. data/generators/opensteam_product/templates/views/administration/new.html.erb +0 -16
  264. data/generators/opensteam_property/templates/views/administration/index.html.erb +0 -24
  265. data/generators/opensteam_property/templates/views/administration/show.html.erb +0 -10
@@ -1,3 +1,19 @@
1
+ # openSteam - http://www.opensteam.net
2
+ # Copyright (C) 2008 DiamondDogs Webconsulting
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; version 2 of the License.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
1
17
  module Opensteam
2
18
 
3
19
  =begin rdoc
@@ -49,7 +65,7 @@ Used to either be included into a model or injected with the
49
65
  products = (self._has_product || []).inject({}) { |r,v|
50
66
  r.merge!( { v => v.to_s.classify.constantize.find(:all) } ) } || {}
51
67
 
52
- products.delete(self.to_s.tableize) #unless <%= class_name %>.self.referential
68
+ products.delete(self.to_s.tableize)
53
69
 
54
70
  products
55
71
  end
@@ -78,11 +94,23 @@ Used to either be included into a model or injected with the
78
94
 
79
95
 
80
96
 
97
+
98
+
81
99
  # inventory association
82
100
  has_many :inventories, :as => :product,
83
101
  :extend => Opensteam::Base::ExistByPropertiesExtension,
84
102
  :class_name => "Opensteam::InventoryBase::Inventory"
85
-
103
+
104
+ has_many :inventories_properties, :through => :inventories, :include => :property
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
86
114
 
87
115
  # holds the properties the product is allowed to have
88
116
  # used for view
@@ -136,7 +164,7 @@ Used to either be included into a model or injected with the
136
164
  # inventoy-objects which are currently associated with the product and do not
137
165
  # match the properties (p) are deleted.
138
166
  #
139
- # used in the administration-views, to update the product-property associations.
167
+ # used in the admin-views, to update the product-property associations.
140
168
  #
141
169
  def set_properties=(p)
142
170
  save
@@ -1,3 +1,19 @@
1
+ # openSteam - http://www.opensteam.net
2
+ # Copyright (C) 2008 DiamondDogs Webconsulting
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; version 2 of the License.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
1
17
  module Opensteam
2
18
 
3
19
 
@@ -0,0 +1,60 @@
1
+ # openSteam - http://www.opensteam.net
2
+ # Copyright (C) 2008 DiamondDogs Webconsulting
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; version 2 of the License.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
17
+ module Opensteam
18
+
19
+
20
+ module ShipmentBase
21
+
22
+
23
+ # available States for an Shipment-Instance
24
+ module States
25
+
26
+ end
27
+
28
+
29
+
30
+ # Shipment Model
31
+ class Shipment < ActiveRecord::Base
32
+
33
+ include Opensteam::StateMachine
34
+
35
+ belongs_to :order, :class_name => 'Opensteam::OrderBase::Order'
36
+ belongs_to :customer, :class_name => 'Opensteam::UserBase::User'
37
+ belongs_to :address, :class_name => 'Opensteam::UserBase::Address'
38
+
39
+ has_many :order_items, :class_name => 'Opensteam::OrderBase::OrderItem'
40
+
41
+ def initialize(*args)
42
+ super(*args)
43
+
44
+ if order
45
+ self.address = order.shipping_address
46
+ self.customer = order.customer
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+
54
+
55
+
56
+
57
+
58
+ end
59
+
60
+ end
@@ -1,3 +1,18 @@
1
+ # openSteam - http://www.opensteam.net
2
+ # Copyright (C) 2008 DiamondDogs Webconsulting
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; version 2 of the License.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1
16
 
2
17
  require 'opensteam/finder'
3
18
 
@@ -8,20 +23,23 @@ module Opensteam
8
23
  module ShoppingCart
9
24
 
10
25
 
11
-
12
- # CartController
13
- #
14
- # - standard methods for ShoppingCart manipulation
15
- # - automatically sets @cart to access shopping-cart
16
- #
17
- #
18
- #
19
- class CartController < ActionController::Base
20
-
21
-
22
- #
23
- #include @cart instance-variable in all actions
24
- before_filter :set_instance_vars
26
+ def self.included(base)
27
+ base.extend ClassMethods
28
+
29
+ base.class_eval do
30
+ include InstanceMethods
31
+ before_filter :set_instance_vars
32
+
33
+
34
+ end
35
+ end
36
+
37
+ module ClassMethods
38
+ end
39
+
40
+
41
+ module InstanceMethods
42
+
25
43
 
26
44
  # delete item from cart
27
45
  #
@@ -0,0 +1,218 @@
1
+ # openSteam - http://www.opensteam.net
2
+ # Copyright (C) 2008 DiamondDogs Webconsulting
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; version 2 of the License.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
17
+
18
+ module Opensteam
19
+
20
+ module StateLogic
21
+
22
+
23
+ # StateLogic Module
24
+ # included in State Modules
25
+ module Mod
26
+
27
+ @@states = []
28
+ mattr_accessor :states
29
+
30
+ def self.included(base)
31
+ @@states << base
32
+ base.extend(ClassMethods) if base.is_a?(Module)
33
+
34
+ end
35
+
36
+ module ClassMethods
37
+
38
+ def name ; self.to_s.demodulize.downcase.to_sym ; end
39
+
40
+ def respond_to?( method )
41
+ self.protected_instance_methods.include?( method )
42
+ end
43
+
44
+ def state_module? ; true ; end
45
+
46
+
47
+
48
+
49
+ # included method
50
+ # called when the state-module is included into the receiver-class (like Order, Shipment, Invoice)
51
+ #
52
+ # for each instance-method of the state-module, it creates an alias (in the receiver-klass) and delegates it
53
+ # to the corresponding state-module (based on receiver.state -> StatePattern) through the fire_event method.
54
+ #
55
+
56
+ def included(receiver)
57
+ self.instance_methods(false).each do |m|
58
+
59
+ receiver.class_eval do
60
+ define_method(m) { |*args| fire_event( m, *args ) }
61
+ end
62
+
63
+ end
64
+
65
+ state_name = self.to_s.demodulize.downcase
66
+ receiver.class_eval do
67
+ define_method("#{state_name}?") { self.state == state_name }
68
+ named_scope state_name, :conditions => ["#{self.table_name}.state = ?", state_name ]
69
+
70
+ class << self ;
71
+ def available_states
72
+ self.included_modules.select { |s|
73
+ s.ancestors.include?( Opensteam::StateLogic::Mod ) }.reject { |s|
74
+ s == Opensteam::StateLogic::Mod }
75
+ end
76
+ end
77
+ end
78
+
79
+ end
80
+
81
+ end
82
+
83
+ end
84
+
85
+
86
+
87
+
88
+ require 'observer'
89
+
90
+ #
91
+ # class Base < ActiveRecord::Base
92
+ # self.table_name = "states"
93
+ #
94
+ #
95
+ # def self.state_type ; :state_base ; end
96
+ # def state_type ; self.class.state_type ; end
97
+ #
98
+ # Object.const_set "State", self
99
+ #
100
+ # @@sub_states = []
101
+ # class_inheritable_accessor :sub_states
102
+ #
103
+ #
104
+ # def self.inherited(base)
105
+ # ( self.sub_states ||= [] ) << base
106
+ #
107
+ # end
108
+ #
109
+ #
110
+ #
111
+ #
112
+ # def self.mod ; "#{self.to_s}Module".classify.constantize ; end
113
+ # def mod ; self.class.mod ; end
114
+ #
115
+ # def self.state_name
116
+ # self.to_s =~ /^(.+)State$/
117
+ # $1 ? $1.underscore.to_sym : self.to_s.to_sym
118
+ # end
119
+ #
120
+ # def state_name ; self.class.state_name ; end
121
+ #
122
+ # def to_s ; self.state_name ; end
123
+ #
124
+ #
125
+ # def self.events
126
+ # ( ( self.instance_methods(false) - self.generated_methods.to_a ).collect { |x|
127
+ # x =~ /!$/ ? x : nil }.compact.collect(&:to_sym) )
128
+ # end
129
+ #
130
+ #
131
+ # def events ; self.events ; end
132
+ #
133
+ #
134
+ # def self.instance_for_event( sym )
135
+ # "#{sym}State".classify.constantize.create
136
+ # end
137
+ #
138
+ #
139
+ #
140
+ #
141
+ #
142
+ #
143
+ #
144
+ #
145
+ #
146
+ # def self.state(name, &block)
147
+ # klass_name = "#{name}State".classify
148
+ # begin
149
+ # klass = klass_name.constantize
150
+ # raise NameError if klass.superclass != self
151
+ # puts "#{klass} is defined!!"
152
+ # rescue NameError
153
+ # klass = Class.new( self )
154
+ # Object.const_set klass_name, klass
155
+ # end
156
+ # klass.class_eval(&block) if block_given?
157
+ # end
158
+ #
159
+ #
160
+ # def self.event(name, *args, &block)
161
+ # self.class_eval { define_method(name) { block.call } if block_given? }
162
+ # Opensteam::StateMachine.inject_state_queries( self )
163
+ # Opensteam::StateMachine.inject_event_methods( self )
164
+ # end
165
+ #
166
+ #
167
+ # def self.transition_observer(*args, &block)
168
+ # if args.first.is_a?( Hash )
169
+ # from, to = args.first.keys.first, args.first.values.first
170
+ # else
171
+ # from, to = self.state_name, args.first
172
+ # end##
173
+ #
174
+ # if block_given?
175
+ # # Opensteam::StateMachine.transitions[from] ||= {}
176
+ # # ( Opensteam::StateMachine.transitions[from][to] ||= [] ) << block
177
+ # end
178
+ #
179
+ # end
180
+ #
181
+ # end
182
+ #
183
+ #
184
+
185
+
186
+ end
187
+
188
+
189
+ end
190
+
191
+
192
+
193
+ #if defined? RAILS_ROOT
194
+ #
195
+ # Dir.glob("#{RAILS_ROOT}/app/states/**/*.rb").collect { |f|
196
+ # puts f
197
+ # require f
198
+ # klass_name = "#{File.basename(f,'.rb')}State".classify
199
+ # begin
200
+ # klass = klass_name.constantize
201
+ # rescue NameError
202
+ # klass = Class.new( Opensteam::StateLogic::Base )
203
+ # Object.const_set klass_name, klass
204
+ # end
205
+ # }
206
+ #
207
+ #end
208
+
209
+
210
+ ## if rails is runniny
211
+ #if defined? RAILS_ROOT
212
+ # ## init all states and create event methods for the Order-Instance
213
+ # Dir.glob("#{RAILS_ROOT}/app/models/*_states.rb").collect { |f|
214
+ # require Opensteam::State::Machine.create_event_methods_for_order( File.basename(f, ".rb").classify.constantize )
215
+ # }
216
+ #end
217
+
218
+
@@ -0,0 +1,216 @@
1
+ # openSteam - http://www.opensteam.net
2
+ # Copyright (C) 2008 DiamondDogs Webconsulting
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; version 2 of the License.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
17
+ module Opensteam
18
+
19
+
20
+ # StateMachine Module
21
+ #
22
+ #
23
+ module StateMachine
24
+
25
+
26
+ class EventNotDefined < Opensteam::Config::Errors::OpensteamError
27
+ end
28
+
29
+ # raised when the event is not defined for current state
30
+ class EventNotDefinedForCurrentState < Opensteam::Config::Errors::OpensteamError
31
+ end
32
+
33
+ class EventExecutionError < Opensteam::Config::Errors::OpensteamError
34
+ end
35
+
36
+ module ClassMethods
37
+
38
+ def get_observer ; @@observer ||= [] ; end
39
+
40
+ def initial_state( state )
41
+ after_create { |record| record.state = state }
42
+ end
43
+
44
+ # observe state-changes -> calls given block after change_state
45
+ def observe( &block )
46
+ observers << Opensteam::StateMachine::Observer.new( self, &block )
47
+ end
48
+
49
+ # notify association on state-change
50
+ # calls the observers of the association
51
+ def notify(assoc)
52
+ observers << Opensteam::StateMachine::Observer.new( self ) do |record|
53
+ record.send( assoc ).class.observers.each { |o| o.exc( record.send( assoc ) ) }
54
+ end
55
+ end
56
+
57
+ end
58
+
59
+
60
+
61
+ def self.included(base)
62
+ base.extend(ClassMethods)
63
+ base.class_eval do
64
+ include InstanceMethods
65
+
66
+ # include the history module
67
+ include Opensteam::History
68
+
69
+ @observers = []
70
+ class << self ; attr_accessor :observers ; end
71
+
72
+ end
73
+
74
+ end
75
+
76
+
77
+ class Observer
78
+ attr_accessor :receiver, :code
79
+
80
+ def initialize( receiver, &block )
81
+ @receiver = receiver
82
+ @code = block
83
+ end
84
+
85
+ def exc( instance )
86
+ @code.call( instance )
87
+ # @code.bind( instance ).call
88
+ end
89
+
90
+
91
+ end
92
+
93
+
94
+ module ClassMethods
95
+ end
96
+
97
+
98
+ module InstanceMethods
99
+
100
+
101
+ # returns an array of event-methods for the current state
102
+ # -> the instance_methods of the current +state_module+
103
+ def events ; (s = self.state_module ) ? s.instance_methods : [] ; end
104
+
105
+
106
+ # returns the corresponding module for the current state
107
+ #
108
+ # ex:
109
+ # o = Order.create
110
+ # o.state = :pending
111
+ # o.state_module # => OrderStates::Pending
112
+ #
113
+ def state_module
114
+ return nil unless state
115
+ "#{self.class.to_s.demodulize}States::#{self.state.to_s.classify}".constantize rescue nil
116
+ end
117
+
118
+
119
+ # overrides state-attribute setter
120
+ # calls +change_state+
121
+ def state=(new_state)
122
+ change_state(new_state)
123
+ end
124
+
125
+
126
+
127
+
128
+ # fire an event for current state
129
+ #
130
+ # if self.state is nil, returns false
131
+ # if +event+ is not defined for current state (not an instance method of +state_module+), an error is raised
132
+ # if an error occured during the event, an error-entry is saved into the history
133
+ # calls +change_state+ (return value of the event is used as next-state, if return value is a Symbol or a Module)
134
+ #
135
+ def fire_event(event, *args, &block )
136
+
137
+ return false unless self.state
138
+
139
+ add_history( "trying to fire event '#{event}' for state '#{self.state}'" )
140
+
141
+ return false unless event_scope = self.state_module
142
+
143
+ unless events.include?( event.to_s )
144
+ add_history( msg = "Error: event '#{event}' not defined for state '#{self.state}'")
145
+ raise EventNotDefined, msg
146
+ return false
147
+ end
148
+
149
+ begin
150
+ event_return = event_scope.instance_method( event ).bind( self ).call( *args, &block )
151
+ add_history( "Successfully executed event '#{event}' for state '#{self.state}'" )
152
+ rescue
153
+ add_history("Error: An error occured during event '#{event}' in state '#{self.state}' : '#{$!}'")
154
+ end
155
+
156
+ unless event_return == false
157
+ self.state = event_return if( event_return.is_a?(Symbol) || event_return.is_a?(Module) )
158
+ return event_return
159
+ end
160
+
161
+ end
162
+
163
+
164
+ # changes state to +new_state+
165
+ #
166
+ # if current_state is equal +new_state+, return false
167
+ #
168
+ def change_state( new_state )
169
+ if new_state.is_a?( Module )
170
+ new_state = new_state.name
171
+ end
172
+
173
+ current_state = state
174
+
175
+ add_history "starting transition from state '#{current_state}' to state '#{new_state}'"
176
+
177
+ if current_state == new_state
178
+ add_history "transition failed: current_state '#{current_state}' and new_state '#{new_state}' are the same!"
179
+ return false
180
+ end
181
+
182
+ write_attribute(:state, new_state.to_s)
183
+ ret = save
184
+
185
+ if ret
186
+ add_history( "Successfull: transition from state '#{current_state}' to state '#{new_state.to_s}'" )
187
+ else
188
+ add_history("Failed: transition from state '#{current_state}' to state '#{new_state.to_s}'")
189
+ end
190
+
191
+
192
+ self.execute_observers
193
+ # self.class.observers.each do |o|
194
+ # o.exc( self )
195
+ # end
196
+
197
+ ret
198
+
199
+ end
200
+
201
+
202
+ def execute_observers
203
+ self.class.observers.each do |o|
204
+ o.exc( self )
205
+ end
206
+ end
207
+
208
+
209
+
210
+
211
+ end
212
+
213
+ end
214
+
215
+ end
216
+