Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 9489a52765edf18d9aa84f9803bc37229d2f0440 Mino committed Apr 26, 2010
Showing with 2,579 additions and 0 deletions.
  1. +25 −0 Emakefile
  2. +6 −0 Makefile
  3. BIN Mnesia.nitrogen@127.0.0.1/DECISION_TAB.LOG
  4. BIN Mnesia.nitrogen@127.0.0.1/LATEST.LOG
  5. +1 −0 Mnesia.nitrogen@127.0.0.1/category.DCD
  6. BIN Mnesia.nitrogen@127.0.0.1/category.DCL
  7. +1 −0 Mnesia.nitrogen@127.0.0.1/ids.DCD
  8. BIN Mnesia.nitrogen@127.0.0.1/ids.DCL
  9. +1 −0 Mnesia.nitrogen@127.0.0.1/product.DCD
  10. BIN Mnesia.nitrogen@127.0.0.1/product.DCL
  11. BIN Mnesia.nitrogen@127.0.0.1/schema.DAT
  12. +11 −0 apps/cookieCart.app
  13. +11 −0 apps/cookieCart.app~
  14. BIN ebin/cart.beam
  15. BIN ebin/category.beam
  16. BIN ebin/cookieCart.beam
  17. BIN ebin/cookieCart_app.beam
  18. BIN ebin/db.beam
  19. BIN ebin/error.beam
  20. BIN ebin/image.beam
  21. BIN ebin/price.beam
  22. BIN ebin/product.beam
  23. BIN ebin/web_index.beam
  24. BIN ebin/web_login.beam
  25. +33 −0 include/records.hrl
  26. +28 −0 include/records.hrl~
  27. +44 −0 src/cart.erl
  28. +44 −0 src/cart.erl~
  29. +73 −0 src/category.erl
  30. +76 −0 src/category.erl~
  31. +18 −0 src/cookieCart.erl
  32. +16 −0 src/cookieCart.erl~
  33. +72 −0 src/cookieCart_app.erl
  34. +72 −0 src/cookieCart_app.erl~
  35. +126 −0 src/db.erl
  36. +125 −0 src/db.erl~
  37. +18 −0 src/error.erl
  38. +5 −0 src/image.erl
  39. +4 −0 src/image.erl~
  40. +20 −0 src/pages/web_index.erl~
  41. +34 −0 src/pages/web_login.erl
  42. +10 −0 src/price.erl
  43. +5 −0 src/price.erl~
  44. +50 −0 src/product.erl
  45. +54 −0 src/product.erl~
  46. +31 −0 src/web_index.erl
  47. +36 −0 src/web_index.erl~
  48. +15 −0 start.sh
  49. +117 −0 tpl/1.tpl
  50. +117 −0 tpl/1.tpl~
  51. +120 −0 tpl/1121.tpl
  52. +120 −0 tpl/1_1.tpl~
  53. +117 −0 tpl/CC_category.tpl
  54. +120 −0 tpl/CC_product.tpl
  55. +103 −0 tpl/main.tpl
  56. +103 −0 tpl/main.tpl~
  57. +2 −0 windows.bat
  58. +13 −0 wwwroot/CC_listProducts.html
  59. +13 −0 wwwroot/CC_listProducts.html~
  60. +1 −0 wwwroot/category.tpl~
  61. +1 −0 wwwroot/contact.tpl~
  62. +258 −0 wwwroot/css/style.css
  63. +309 −0 wwwroot/css/style2.css
  64. BIN wwwroot/img/arrow.png
  65. BIN wwwroot/img/bg-end.png
  66. BIN wwwroot/img/bg-row.png
  67. BIN wwwroot/img/default.gif
  68. BIN wwwroot/img/full-banner.gif
  69. BIN wwwroot/img/half-banner.gif
  70. BIN wwwroot/img/icons/accept.png
  71. BIN wwwroot/img/icons/add.png
  72. BIN wwwroot/img/icons/anchor.png
  73. BIN wwwroot/img/icons/application.png
  74. BIN wwwroot/img/icons/application_add.png
  75. BIN wwwroot/img/icons/application_cascade.png
  76. BIN wwwroot/img/icons/application_delete.png
  77. BIN wwwroot/img/icons/application_double.png
  78. BIN wwwroot/img/icons/application_edit.png
  79. BIN wwwroot/img/icons/application_error.png
  80. BIN wwwroot/img/icons/application_form.png
  81. BIN wwwroot/img/icons/application_form_add.png
  82. BIN wwwroot/img/icons/application_form_delete.png
  83. BIN wwwroot/img/icons/application_form_edit.png
  84. BIN wwwroot/img/icons/application_form_magnify.png
  85. BIN wwwroot/img/icons/application_get.png
  86. BIN wwwroot/img/icons/application_go.png
  87. BIN wwwroot/img/icons/application_home.png
  88. BIN wwwroot/img/icons/application_key.png
  89. BIN wwwroot/img/icons/application_lightning.png
  90. BIN wwwroot/img/icons/application_link.png
  91. BIN wwwroot/img/icons/application_osx.png
  92. BIN wwwroot/img/icons/application_osx_terminal.png
  93. BIN wwwroot/img/icons/application_put.png
  94. BIN wwwroot/img/icons/application_side_boxes.png
  95. BIN wwwroot/img/icons/application_side_contract.png
  96. BIN wwwroot/img/icons/application_side_expand.png
  97. BIN wwwroot/img/icons/application_side_list.png
  98. BIN wwwroot/img/icons/application_side_tree.png
  99. BIN wwwroot/img/icons/application_split.png
  100. BIN wwwroot/img/icons/application_tile_horizontal.png
  101. BIN wwwroot/img/icons/application_tile_vertical.png
  102. BIN wwwroot/img/icons/application_view_columns.png
  103. BIN wwwroot/img/icons/application_view_detail.png
  104. BIN wwwroot/img/icons/application_view_gallery.png
  105. BIN wwwroot/img/icons/application_view_icons.png
  106. BIN wwwroot/img/icons/application_view_list.png
  107. BIN wwwroot/img/icons/application_view_tile.png
  108. BIN wwwroot/img/icons/application_xp.png
  109. BIN wwwroot/img/icons/application_xp_terminal.png
  110. BIN wwwroot/img/icons/arrow_branch.png
  111. BIN wwwroot/img/icons/arrow_divide.png
  112. BIN wwwroot/img/icons/arrow_down.png
  113. BIN wwwroot/img/icons/arrow_down_mini.gif
  114. BIN wwwroot/img/icons/arrow_in.png
  115. BIN wwwroot/img/icons/arrow_inout.png
  116. BIN wwwroot/img/icons/arrow_join.png
  117. BIN wwwroot/img/icons/arrow_left.gif
  118. BIN wwwroot/img/icons/arrow_left.png
  119. BIN wwwroot/img/icons/arrow_merge.png
  120. BIN wwwroot/img/icons/arrow_out.png
  121. BIN wwwroot/img/icons/arrow_redo.png
  122. BIN wwwroot/img/icons/arrow_refresh.png
  123. BIN wwwroot/img/icons/arrow_refresh_small.png
  124. BIN wwwroot/img/icons/arrow_right.gif
  125. BIN wwwroot/img/icons/arrow_right.png
  126. BIN wwwroot/img/icons/arrow_rotate_anticlockwise.png
  127. BIN wwwroot/img/icons/arrow_rotate_clockwise.png
  128. BIN wwwroot/img/icons/arrow_switch.png
  129. BIN wwwroot/img/icons/arrow_turn_left.png
  130. BIN wwwroot/img/icons/arrow_turn_right.png
  131. BIN wwwroot/img/icons/arrow_undo.png
  132. BIN wwwroot/img/icons/arrow_up.png
  133. BIN wwwroot/img/icons/asterisk_orange.png
  134. BIN wwwroot/img/icons/asterisk_yellow.png
  135. BIN wwwroot/img/icons/attach.png
  136. BIN wwwroot/img/icons/award_star_add.png
  137. BIN wwwroot/img/icons/award_star_bronze_1.png
  138. BIN wwwroot/img/icons/award_star_bronze_2.png
  139. BIN wwwroot/img/icons/award_star_bronze_3.png
  140. BIN wwwroot/img/icons/award_star_delete.png
  141. BIN wwwroot/img/icons/award_star_gold_1.png
  142. BIN wwwroot/img/icons/award_star_gold_2.png
  143. BIN wwwroot/img/icons/award_star_gold_3.png
  144. BIN wwwroot/img/icons/award_star_silver_1.png
  145. BIN wwwroot/img/icons/award_star_silver_2.png
  146. BIN wwwroot/img/icons/award_star_silver_3.png
  147. BIN wwwroot/img/icons/basket.png
  148. BIN wwwroot/img/icons/basket_add.png
  149. BIN wwwroot/img/icons/basket_delete.png
  150. BIN wwwroot/img/icons/basket_edit.png
  151. BIN wwwroot/img/icons/basket_error.png
  152. BIN wwwroot/img/icons/basket_go.png
  153. BIN wwwroot/img/icons/basket_put.png
  154. BIN wwwroot/img/icons/basket_remove.png
  155. BIN wwwroot/img/icons/bell.png
  156. BIN wwwroot/img/icons/bell_add.png
  157. BIN wwwroot/img/icons/bell_delete.png
  158. BIN wwwroot/img/icons/bell_error.png
  159. BIN wwwroot/img/icons/bell_go.png
  160. BIN wwwroot/img/icons/bell_link.png
  161. BIN wwwroot/img/icons/bin.png
  162. BIN wwwroot/img/icons/bin_closed.png
  163. BIN wwwroot/img/icons/bin_empty.png
  164. BIN wwwroot/img/icons/bomb.png
  165. BIN wwwroot/img/icons/book.png
  166. BIN wwwroot/img/icons/book_add.png
  167. BIN wwwroot/img/icons/book_addresses.png
  168. BIN wwwroot/img/icons/book_delete.png
  169. BIN wwwroot/img/icons/book_edit.png
  170. BIN wwwroot/img/icons/book_error.png
  171. BIN wwwroot/img/icons/book_go.png
  172. BIN wwwroot/img/icons/book_key.png
  173. BIN wwwroot/img/icons/book_link.png
  174. BIN wwwroot/img/icons/book_next.png
  175. BIN wwwroot/img/icons/book_open.png
  176. BIN wwwroot/img/icons/book_previous.png
  177. BIN wwwroot/img/icons/box.png
  178. BIN wwwroot/img/icons/brick.png
  179. BIN wwwroot/img/icons/brick_add.png
  180. BIN wwwroot/img/icons/brick_delete.png
  181. BIN wwwroot/img/icons/brick_edit.png
  182. BIN wwwroot/img/icons/brick_error.png
  183. BIN wwwroot/img/icons/brick_go.png
  184. BIN wwwroot/img/icons/brick_link.png
  185. BIN wwwroot/img/icons/bricks.png
  186. BIN wwwroot/img/icons/bricks_gear.png
  187. BIN wwwroot/img/icons/briefcase.png
  188. BIN wwwroot/img/icons/bug.png
  189. BIN wwwroot/img/icons/bug_add.png
  190. BIN wwwroot/img/icons/bug_delete.png
  191. BIN wwwroot/img/icons/bug_edit.png
  192. BIN wwwroot/img/icons/bug_error.png
  193. BIN wwwroot/img/icons/bug_go.png
  194. BIN wwwroot/img/icons/bug_link.png
  195. BIN wwwroot/img/icons/building.png
  196. BIN wwwroot/img/icons/building_add.png
  197. BIN wwwroot/img/icons/building_delete.png
  198. BIN wwwroot/img/icons/building_edit.png
  199. BIN wwwroot/img/icons/building_error.png
  200. BIN wwwroot/img/icons/building_go.png
  201. BIN wwwroot/img/icons/building_key.png
  202. BIN wwwroot/img/icons/building_link.png
  203. BIN wwwroot/img/icons/bullet_add.png
  204. BIN wwwroot/img/icons/bullet_arrow_bottom.png
  205. BIN wwwroot/img/icons/bullet_arrow_down.png
  206. BIN wwwroot/img/icons/bullet_arrow_top.png
  207. BIN wwwroot/img/icons/bullet_arrow_up.png
  208. BIN wwwroot/img/icons/bullet_black.png
  209. BIN wwwroot/img/icons/bullet_blue.png
  210. BIN wwwroot/img/icons/bullet_delete.png
  211. BIN wwwroot/img/icons/bullet_disk.png
  212. BIN wwwroot/img/icons/bullet_error.png
  213. BIN wwwroot/img/icons/bullet_feed.png
  214. BIN wwwroot/img/icons/bullet_go.png
  215. BIN wwwroot/img/icons/bullet_green.png
  216. BIN wwwroot/img/icons/bullet_key.png
  217. BIN wwwroot/img/icons/bullet_orange.png
  218. BIN wwwroot/img/icons/bullet_picture.png
  219. BIN wwwroot/img/icons/bullet_pink.png
  220. BIN wwwroot/img/icons/bullet_purple.png
  221. BIN wwwroot/img/icons/bullet_red.png
  222. BIN wwwroot/img/icons/bullet_star.png
  223. BIN wwwroot/img/icons/bullet_toggle_minus.png
  224. BIN wwwroot/img/icons/bullet_toggle_plus.png
  225. BIN wwwroot/img/icons/bullet_white.png
  226. BIN wwwroot/img/icons/bullet_wrench.png
  227. BIN wwwroot/img/icons/bullet_yellow.png
  228. BIN wwwroot/img/icons/cake.png
  229. BIN wwwroot/img/icons/calculator.png
  230. BIN wwwroot/img/icons/calculator_add.png
  231. BIN wwwroot/img/icons/calculator_delete.png
  232. BIN wwwroot/img/icons/calculator_edit.png
  233. BIN wwwroot/img/icons/calculator_error.png
  234. BIN wwwroot/img/icons/calculator_link.png
  235. BIN wwwroot/img/icons/calendar.png
  236. BIN wwwroot/img/icons/calendar_add.png
  237. BIN wwwroot/img/icons/calendar_delete.png
  238. BIN wwwroot/img/icons/calendar_edit.png
  239. BIN wwwroot/img/icons/calendar_link.png
  240. BIN wwwroot/img/icons/calendar_view_day.png
  241. BIN wwwroot/img/icons/calendar_view_month.png
  242. BIN wwwroot/img/icons/calendar_view_week.png
  243. BIN wwwroot/img/icons/camera.png
  244. BIN wwwroot/img/icons/camera_add.png
  245. BIN wwwroot/img/icons/camera_delete.png
  246. BIN wwwroot/img/icons/camera_edit.png
  247. BIN wwwroot/img/icons/camera_error.png
  248. BIN wwwroot/img/icons/camera_go.png
  249. BIN wwwroot/img/icons/camera_link.png
  250. BIN wwwroot/img/icons/camera_small.png
  251. BIN wwwroot/img/icons/cancel.png
  252. BIN wwwroot/img/icons/car.png
  253. BIN wwwroot/img/icons/car_add.png
  254. BIN wwwroot/img/icons/car_delete.png
  255. BIN wwwroot/img/icons/cart.png
  256. BIN wwwroot/img/icons/cart_add.png
  257. BIN wwwroot/img/icons/cart_delete.png
  258. BIN wwwroot/img/icons/cart_edit.png
  259. BIN wwwroot/img/icons/cart_error.png
  260. BIN wwwroot/img/icons/cart_go.png
  261. BIN wwwroot/img/icons/cart_put.png
  262. BIN wwwroot/img/icons/cart_remove.png
  263. BIN wwwroot/img/icons/cd.png
  264. BIN wwwroot/img/icons/cd_add.png
  265. BIN wwwroot/img/icons/cd_burn.png
  266. BIN wwwroot/img/icons/cd_delete.png
  267. BIN wwwroot/img/icons/cd_edit.png
  268. BIN wwwroot/img/icons/cd_eject.png
  269. BIN wwwroot/img/icons/cd_go.png
  270. BIN wwwroot/img/icons/chart_bar.png
  271. BIN wwwroot/img/icons/chart_bar_add.png
  272. BIN wwwroot/img/icons/chart_bar_delete.png
  273. BIN wwwroot/img/icons/chart_bar_edit.png
  274. BIN wwwroot/img/icons/chart_bar_error.png
  275. BIN wwwroot/img/icons/chart_bar_link.png
  276. BIN wwwroot/img/icons/chart_curve.png
  277. BIN wwwroot/img/icons/chart_curve_add.png
  278. BIN wwwroot/img/icons/chart_curve_delete.png
  279. BIN wwwroot/img/icons/chart_curve_edit.png
  280. BIN wwwroot/img/icons/chart_curve_error.png
  281. BIN wwwroot/img/icons/chart_curve_go.png
  282. BIN wwwroot/img/icons/chart_curve_link.png
  283. BIN wwwroot/img/icons/chart_line.png
  284. BIN wwwroot/img/icons/chart_line_add.png
  285. BIN wwwroot/img/icons/chart_line_delete.png
  286. BIN wwwroot/img/icons/chart_line_edit.png
  287. BIN wwwroot/img/icons/chart_line_error.png
  288. BIN wwwroot/img/icons/chart_line_link.png
  289. BIN wwwroot/img/icons/chart_organisation.png
  290. BIN wwwroot/img/icons/chart_organisation_add.png
  291. BIN wwwroot/img/icons/chart_organisation_delete.png
  292. BIN wwwroot/img/icons/chart_pie.png
  293. BIN wwwroot/img/icons/chart_pie_add.png
  294. BIN wwwroot/img/icons/chart_pie_delete.png
  295. BIN wwwroot/img/icons/chart_pie_edit.png
  296. BIN wwwroot/img/icons/chart_pie_error.png
  297. BIN wwwroot/img/icons/chart_pie_link.png
  298. BIN wwwroot/img/icons/clock.png
  299. BIN wwwroot/img/icons/clock_add.png
  300. BIN wwwroot/img/icons/clock_delete.png
Sorry, we could not display the entire diff because too many files (1,125) changed.
25 Emakefile
@@ -0,0 +1,25 @@
+% Compile CW files.
+{ './src/*', [
+ { i, "./include" },
+ { outdir, "./ebin" },
+ debug_info
+]}.
+
+{ './src/pages/*', [
+ { i, "./include" },
+ { outdir, "./ebin" },
+ debug_info
+]}.
+
+{ './src/mnesia/*', [
+ { i, "./include" },
+ { outdir, "./ebin/mnesia" },
+ debug_info
+]}.
+
+{ './src/SQL/*', [
+ { i, "./include" },
+ { outdir, "./ebin/SQL" },
+ debug_info
+]}.
+
6 Makefile
@@ -0,0 +1,6 @@
+compile:
+ erl -make
+
+clean:
+ rm -rf ./ebin/*.*
+
BIN Mnesia.nitrogen@127.0.0.1/DECISION_TAB.LOG
Binary file not shown.
BIN Mnesia.nitrogen@127.0.0.1/LATEST.LOG
Binary file not shown.
1 Mnesia.nitrogen@127.0.0.1/category.DCD
@@ -0,0 +1 @@
+cXM
BIN Mnesia.nitrogen@127.0.0.1/category.DCL
Binary file not shown.
1 Mnesia.nitrogen@127.0.0.1/ids.DCD
@@ -0,0 +1 @@
+cXM
BIN Mnesia.nitrogen@127.0.0.1/ids.DCL
Binary file not shown.
1 Mnesia.nitrogen@127.0.0.1/product.DCD
@@ -0,0 +1 @@
+cXM
BIN Mnesia.nitrogen@127.0.0.1/product.DCL
Binary file not shown.
BIN Mnesia.nitrogen@127.0.0.1/schema.DAT
Binary file not shown.
11 apps/cookieCart.app
@@ -0,0 +1,11 @@
+{application, cookieCart, [
+ {description, "CC Nitrogen"},
+ {mod, {cookieCart_app, []}},
+ {env, [
+ {platform, inets},
+ {port, 8000},
+ {session_timeout, 20},
+ {sign_key, "b37ca07"},
+ {wwwroot, "./wwwroot"}
+ ]}
+]}.
11 apps/cookieCart.app~
@@ -0,0 +1,11 @@
+{application, cookieCart, [
+ {description, "CC Nitrogen"},
+ {mod, {cookieCart, []}},
+ {env, [
+ {platform, inets},
+ {port, 8000},
+ {session_timeout, 20},
+ {sign_key, "b37ca07"},
+ {wwwroot, "./wwwroot"}
+ ]}
+]}.
BIN ebin/cart.beam
Binary file not shown.
BIN ebin/category.beam
Binary file not shown.
BIN ebin/cookieCart.beam
Binary file not shown.
BIN ebin/cookieCart_app.beam
Binary file not shown.
BIN ebin/db.beam
Binary file not shown.
BIN ebin/error.beam
Binary file not shown.
BIN ebin/image.beam
Binary file not shown.
BIN ebin/price.beam
Binary file not shown.
BIN ebin/product.beam
Binary file not shown.
BIN ebin/web_index.beam
Binary file not shown.
BIN ebin/web_login.beam
Binary file not shown.
33 include/records.hrl
@@ -0,0 +1,33 @@
+-record(ids,
+ {table,
+ ids}).
+
+-record(category,
+ {id,
+ name,
+ url}).
+
+-record(product,
+ {id,
+ name,
+ url,
+ cat_id,
+ img,
+ price,
+ description}).
+
+-record(price,
+ {price,
+ currency}).
+
+-record(prodId,
+ {product,
+ category}).
+
+-record(cart,
+ {products,
+ sum}).
+
+-record(cartItem,
+ {prodId,
+ quantity}).
28 include/records.hrl~
@@ -0,0 +1,28 @@
+
+-record(category,
+ {id,
+ name}).
+
+-record(product,
+ {id,
+ name,
+ url,
+ img,
+ price,
+ description}).
+
+-record(price,
+ {price,
+ currency}).
+
+-record(prodId,
+ {product,
+ category}).
+
+-record(cart,
+ {products,
+ sum}).
+
+-record(cartItem,
+ {prodId,
+ quantity}).
44 src/cart.erl
@@ -0,0 +1,44 @@
+-module(cart).
+-compile(export_all).
+
+-include_lib ("nitrogen/include/wf.inc").
+-include("records.hrl").
+
+list()->
+ Cart = get_cart(),
+ CartItemList = Cart#cart.products,
+ ProdIdList = [X#cartItem.prodId||X<-CartItemList],
+ Data = db:get_products(ProdIdList),
+ Map = #product{name=name@text, url=name@url},
+ Body = [#link{ id=name },
+ #br{}],
+ #bind{ data = Data, map = Map, body = Body}.
+
+add(Quantity, ProdId) ->
+ Cart = get_cart(),
+ Prods = cc_add(#cartItem{prodId=ProdId,quantity=Quantity},
+ Cart#cart.products, []),
+ wf:set_cookie(cart,wf:pickle(Cart#cart{products=Prods})).
+
+%%%%%% Internal Functions %%%%%%
+
+get_cart() ->
+ case wf:get_cookie(cart) of
+ undefined ->
+ #cart{products=[]};
+ Cart ->
+ wf:depickle(Cart)
+ end.
+
+cc_add(Item,[],Acc) ->
+ [Item|lists:reverse(Acc)];
+cc_add(Item,[HD|TL],Acc) ->
+ case Item#cartItem.prodId == HD#cartItem.prodId of
+ true ->
+ NewQty = Item#cartItem.quantity + HD#cartItem.quantity,
+ lists:reverse(Acc,[HD#cartItem{quantity=NewQty}|TL]);
+ false ->
+ cc_add(Item,TL,[HD|Acc])
+ end.
+
+
44 src/cart.erl~
@@ -0,0 +1,44 @@
+-module(cart).
+-compile(export_all).
+
+-include_lib ("nitrogen/include/wf.inc").
+-include("records.hrl").
+
+list()->
+ Cart = get_cart(),
+ CartItemList = Cart#cart.products,
+ ProdIdList = [X#cartItem.prodId||X<-CartItemList],
+ Data = db:get_products(ProdIdList),
+ Map = #product{name=name@text, url=name@url},
+ Body = [#link{ id=name },
+ #br{}],
+ #bind{ data = Data, map = Map, body = Body}.
+
+add(Quantity, ProdId) ->
+ Cart = get_cart(),
+ Prods = cc_add(#cartItem{prodId=ProdId,quantity=Quantity},
+ Cart#cart.products, []),
+ wf:set_cookie(cart,wf:pickle(Cart#cart{products=Prods})).
+
+%%%%%% Internal Functions %%%%%%
+
+get_cart() ->
+ case wf:get_cookie(cart) of
+ undefined ->
+ #cart{products=[]};
+ Cart ->
+ wf:depickle(Cart)
+ end.
+
+cc_add(Item,[],Acc) ->
+ [Item|lists:reverse(Acc)];
+cc_add(Item,[HD|TL],Acc) ->
+ case Item#cartItem.prodId == HD#cartItem.prodId of
+ true ->
+ NewQty = Item#cartItem.quantity + HD#cartItem.quantity,
+ lists:reverse(Acc,[HD#cartItem{quantity=NewQty}|TL]);
+ false ->
+ cc_add(Item,TL,[HD|Acc])
+ end.
+
+
73 src/category.erl
@@ -0,0 +1,73 @@
+-module (category).
+-compile (export_all).
+
+-include_lib ("nitrogen/include/wf.inc").
+-include("records.hrl").
+
+-define(CATEGORY,wf:state(category)).
+
+load(CatId) ->
+ wf:state(category,db:get_category(CatId)),
+
+ IdStr = integer_to_list(CatId),
+ Path = "./tpl/" ++ IdStr ++ ".tpl",
+ case file:read_file_info(Path) of
+ {ok,_} ->
+ #template { file=Path };
+ {error,_} ->
+ #template{ file="./tpl/CC_category.tpl" }
+ end.
+
+%%%%%% Default %%%%%%
+
+list()->
+ Data = db:get_categories(),
+ Map = #category{name=name@text, url=name@url},
+ Body = [#link{ id=name },
+ #br{}],
+ #bind{ data = Data, map = Map, body = Body}.
+
+listProducts() ->
+ Data = db:get_products((?CATEGORY)#category.id),
+ wf:state(product_cache,Data),
+ Map = #product{name=name@text, url=name@url},
+ Body = [ #link{id=name},
+ #br{}],
+ #bind{ data = Data, map = Map, body = Body}.
+
+%%%%%% Custom %%%%%%
+
+list(Template) ->
+ File = "./wwwroot/"++Template,
+ Data = db:get_categories(),
+
+ Render = fun(Category) ->
+ wf:state(category,Category),
+ wf:state(template_was_called,false),
+ wf:render(#template{ file=File })
+ end,
+[Render(X)||X<-Data].
+
+listProducts(Template) ->
+ File = "./wwwroot/" ++ Template,
+ Data = db:get_products((?CATEGORY)#category.id),
+ wf:state(prod_cache,Data),
+
+ Render = fun(Product) ->
+ product:load(Product),
+ wf:state(template_was_called,false),
+ wf:render(#template{ file=File })
+ end,
+
+ [Render(X)||X<-Data].
+
+%%%%%% Field Access Functions %%%%%%
+
+name() ->
+ (?CATEGORY)#category.name.
+
+url() ->
+ "./"++ integer_to_list((?CATEGORY)#category.id).
+
+event(Event) ->
+ ?PRINT(Event).
76 src/category.erl~
@@ -0,0 +1,76 @@
+-module (category).
+-compile (export_all).
+
+-include_lib ("nitrogen/include/wf.inc").
+-include("records.hrl").
+
+-define(CATEGORY,wf:state(category)).
+
+load(CatId) ->
+ wf:state(category,db:get_category(CatId)),
+
+ IdStr = integer_to_list(CatId),
+ Path = "./tpl/" ++ IdStr ++ ".tpl",
+ case file:read_file_info(Path) of
+ {ok,_} ->
+ #template { file=Path };
+ {error,_} ->
+ #template{ file="./tpl/CC_category.tpl" }
+ end.
+
+%%%%%% Default %%%%%%
+
+list()->
+ Data = db:get_categories(),
+ Map = #category{name=name@text, id=name@url},
+ Body = [#link{ id=name },
+ #br{}],
+ #bind{ data = Data, map = Map, body = Body}.
+
+listProducts() ->
+ Data = db:get_product_list(wf:state(cat_id)),
+ wf:state(product_cache,Data),
+ Map = #product{name=name@text, url=name@url},
+ Body = [ #link{id=name},
+ #br{}],
+ #bind{ data = Data, map = Map, body = Body}.
+
+%%%%%% Custom %%%%%%
+
+list(Template) ->
+ File = "./wwwroot/"++Template,
+ Data = db:get_categories(),
+
+ Render = fun(Category) ->
+ wf:state(category,Category),
+ wf:state(template_was_called,false),
+ wf:render(#template{ file=File })
+ end,
+[Render(X)||X<-Data].
+
+listProducts(Template) ->
+ File = "./wwwroot/" ++ Template,
+ Data = db:get_product_list(id()),
+ wf:state(prod_cache,Data),
+
+ Render = fun(Product) ->
+ product:load(Product),
+ wf:state(template_was_called,false),
+ wf:render(#template{ file=File })
+ end,
+
+ [Render(X)||X<-Data].
+
+%%%%%% Field Access Functions %%%%%%
+
+id() ->
+ (?CATEGORY)#category.id.
+
+name() ->
+ (?CATEGORY)#category.name.
+
+url() ->
+ "./"++id().
+
+event(Event) ->
+ ?PRINT(Event).
18 src/cookieCart.erl
@@ -0,0 +1,18 @@
+-module (cookieCart).
+-compile (export_all).
+
+-include_lib ("nitrogen/include/wf.inc").
+
+
+categories() ->
+ category:main().
+categories(Template) ->
+ category:main(Template).
+
+template(Template) ->
+ %% Hacka-dodel-doo
+ wf:state(template_was_called,false),
+ #template { file="./wwwroot/" ++ Template }.
+
+event(Event) ->
+ ?PRINT(Event).
16 src/cookieCart.erl~
@@ -0,0 +1,16 @@
+-module (cookieCart).
+-compile (export_all).
+
+-include_lib ("nitrogen/include/wf.inc").
+
+
+categories() ->
+ "categories".
+
+template(Template) ->
+ %% Hacka-dodel-doo
+ wf:state(template_was_called,false),
+ #template { file="./wwwroot/" ++ Template }.
+
+event(Event) ->
+ ?PRINT(Event).
72 src/cookieCart_app.erl
@@ -0,0 +1,72 @@
+-module (cookieCart_app).
+-include_lib ("nitrogen/include/wf.inc").
+-compile(export_all).
+
+%%% APPLICATION FUNCTIONS %%%
+
+start(_, _) ->
+ db:start(),
+ nitrogen:start().
+stop(_) -> nitrogen:stop().
+
+%% route/1 lets you define new URL routes to your web pages,
+%% or completely create a new routing scheme.
+%% The 'Path' argument specifies the request path. Your
+%% function should return either an atom which is the page module
+%% to run, or a tuple containing {Module, PathInfo}. PathInfo
+%% can be accessed using wf:get_path_info().
+%%
+%% Uncomment the line below to direct requests
+%% from "/web/newroute" to the web_index module:
+%%
+%% route("/web/newroute") -> web_index;
+%%
+%% Uncomment the line below to direct requests
+%% from "/web/newroute" to the web_index module,
+%% with trailing PathInfo included:
+%%
+%% route("/web/newroute/" ++ PathInfo) -> {web_index, PathInfo};
+
+route("/web/" ++ PathInfo) -> {web_index,PathInfo};
+route(Path) -> nitrogen:route(Path).
+
+
+%% request/1 is executed before every Nitrogen page, and lets
+%% you add authentication and authorization. The 'Module' argument
+%% is the name of the page module.
+%% This function should return either 'ok' if processing can proceed,
+%% or it can return a full-fledged page by treating it just like the main function
+%% of a page. Alternatively, you can use the wf:redirect* functions to
+%% issue a client-side redirect to a new page.
+
+
+request(Module) ->
+ ProtectedPages = [web_postwork,web_PM,web_privchat],
+
+ case lists:member(Module,ProtectedPages) of
+ false ->
+ nitrogen:request(Module);
+ true ->
+ case wf:user() of
+ undefined ->
+ wf:redirect_to_login("/web/login");
+ _->
+ ok
+ end
+ end.
+
+%request(Module) ->
+% nitrogen:request(Module).
+
+% Code for testing basic authentication:
+%
+% request(Module) ->
+% wf_http_basic_auth:run(Module, ?MODULE).
+%
+% realm() -> "nitrogen".
+%
+% is_authenticated(Module, _) -> false.
+%
+% authenticate(Module, User, Password) ->
+% User == "Rusty" andalso Password == "password".ubuntu@ubuntu:/usr/local/lib/erlang/lib/nitrogen-master/Quickstart/src$
+
72 src/cookieCart_app.erl~
@@ -0,0 +1,72 @@
+-module (cookieCart_app).
+-include_lib ("nitrogen/include/wf.inc").
+-compile(export_all).
+
+%%% APPLICATION FUNCTIONS %%%
+
+start(_, _) ->
+ %db:start(),
+ nitrogen:start().
+stop(_) -> nitrogen:stop().
+
+%% route/1 lets you define new URL routes to your web pages,
+%% or completely create a new routing scheme.
+%% The 'Path' argument specifies the request path. Your
+%% function should return either an atom which is the page module
+%% to run, or a tuple containing {Module, PathInfo}. PathInfo
+%% can be accessed using wf:get_path_info().
+%%
+%% Uncomment the line below to direct requests
+%% from "/web/newroute" to the web_index module:
+%%
+%% route("/web/newroute") -> web_index;
+%%
+%% Uncomment the line below to direct requests
+%% from "/web/newroute" to the web_index module,
+%% with trailing PathInfo included:
+%%
+%% route("/web/newroute/" ++ PathInfo) -> {web_index, PathInfo};
+
+route("/web/" ++ PathInfo) -> {web_index,PathInfo};
+route(Path) -> nitrogen:route(Path).
+
+
+%% request/1 is executed before every Nitrogen page, and lets
+%% you add authentication and authorization. The 'Module' argument
+%% is the name of the page module.
+%% This function should return either 'ok' if processing can proceed,
+%% or it can return a full-fledged page by treating it just like the main function
+%% of a page. Alternatively, you can use the wf:redirect* functions to
+%% issue a client-side redirect to a new page.
+
+
+request(Module) ->
+ ProtectedPages = [web_postwork,web_PM,web_privchat],
+
+ case lists:member(Module,ProtectedPages) of
+ false ->
+ nitrogen:request(Module);
+ true ->
+ case wf:user() of
+ undefined ->
+ wf:redirect_to_login("/web/login");
+ _->
+ ok
+ end
+ end.
+
+%request(Module) ->
+% nitrogen:request(Module).
+
+% Code for testing basic authentication:
+%
+% request(Module) ->
+% wf_http_basic_auth:run(Module, ?MODULE).
+%
+% realm() -> "nitrogen".
+%
+% is_authenticated(Module, _) -> false.
+%
+% authenticate(Module, User, Password) ->
+% User == "Rusty" andalso Password == "password".ubuntu@ubuntu:/usr/local/lib/erlang/lib/nitrogen-master/Quickstart/src$
+
126 src/db.erl
@@ -0,0 +1,126 @@
+%%%-------------------------------------------------------------------
+%%% File : db.erl
+%%% Author : Mino
+%%% Description : a database API for the CookieCart e-commerce framework.
+%%%
+%%% Created : 25 Apr 2010 by Mino
+%%%-------------------------------------------------------------------
+-module(db).
+
+-compile (export_all).
+
+-include_lib ("nitrogen/include/wf.inc").
+
+-include("records.hrl").
+
+start()->
+ io:format("~n*******************~n" ++
+ " Starting mnesia~n" ++
+ "*******************~n"),
+
+ mnesia:create_schema([node()]),
+ mnesia:start(),
+ mnesia:create_table(ids, [{attributes, record_info(fields, ids)},
+ {disc_copies, [node()]}]),
+
+ mnesia:create_table(category, [{attributes, record_info(fields, category)},
+ {disc_copies, [node()]}]),
+
+ mnesia:create_table(product, [{attributes, record_info(fields, product)},
+ {disc_copies, [node()]}]).
+
+init() ->
+ add_category(#category{name="Cookies"}),
+ add_category(#category{name="Cakes"}),
+ add_category(#category{name="Pies"}),
+
+ add_product(#product{name="Choco Cookie", cat_id = 1,
+ description="Some very tasty cookies!",
+ price=#price{price=1000,currency="SEK"}}),
+ add_product(#product{name="Wedding Cake", cat_id = 2,
+ description="Some very tasty cookies!",
+ price=#price{price=1000,currency="SEK"}}),
+ add_product(#product{name="Meat Pie", cat_id = 3,
+ description="Some very tasty cookies!",
+ price=#price{price=1000,currency="SEK"}}).
+
+
+%%====================================================================
+%% API functions
+%%====================================================================
+
+%%--------------------------------------------------------------------
+%% Category functions
+%%--------------------------------------------------------------------
+add_category(Category) ->
+ Id = mnesia:dirty_update_counter(ids,category_id,1),
+ URL = "99" ++ integer_to_list(Id),
+ Cat = Category#category{id = Id, url = URL},
+ Fun = fun() ->
+ mnesia:write(Cat)
+ end,
+ case mnesia:transaction(Fun) of
+ {aborted,Reason} ->
+ ?PRINT(Reason),
+ throw(dberror);
+ _ -> ok
+ end.
+
+get_categories()->
+ Fun = fun() ->
+ R = #category{ _ = '_'},
+ mnesia:select(category, [{R, [], ['$_']}])
+ end,
+ call(Fun).
+
+get_category(Id) ->
+ Fun = fun() ->
+ hd(mnesia:read(category,Id))
+ end,
+ call(Fun).
+
+
+%%--------------------------------------------------------------------
+%% Product functions
+%%--------------------------------------------------------------------
+
+add_product(Product) ->
+ Id = mnesia:dirty_update_counter(ids,product_id,1),
+ URL = "112" ++ integer_to_list(Id),
+ Prod = Product#product{id = Id, url = URL},
+ Fun = fun() ->
+ mnesia:write(Prod)
+ end,
+ call(Fun).
+
+
+get_product(ProdId) ->
+ Fun = fun() ->
+ hd(mnesia:read(product,ProdId))
+ end,
+ call(Fun).
+
+
+get_products(ProdIdList) when is_list(ProdIdList) ->
+ Fun = fun() ->
+ [hd(mnesia:read(product,X))||X<-ProdIdList]
+ end,
+ call(Fun);
+get_products(CatId) when is_integer(CatId) ->
+ Fun = fun() ->
+ R = #product{ cat_id = CatId, _ = '_'},
+ mnesia:select(product, [{R, [], ['$_']}])
+ end,
+ call(Fun).
+
+%%====================================================================
+%% Internal functions
+%%====================================================================
+
+call(Fun) ->
+ case mnesia:transaction(Fun) of
+ {aborted,Reason} ->
+ ?PRINT(Reason),
+ throw(dberror);
+ {atomic,Result} -> Result
+ end.
125 src/db.erl~
@@ -0,0 +1,125 @@
+%%%-------------------------------------------------------------------
+%%% File : db.erl
+%%% Author : Mino
+%%% Description : a database API for the CookieCart e-commerce framework.
+%%%
+%%% Created : 25 Apr 2010 by <Mino@X60S>
+%%%-------------------------------------------------------------------
+-module(db).
+
+-compile (export_all).
+
+-include_lib ("nitrogen/include/wf.inc").
+
+-include("records.hrl").
+
+start()->
+ io:format("~n*******************~n" ++
+ " Starting mnesia~n" ++
+ "*******************~n"),
+
+ mnesia:create_schema([node()]),
+ mnesia:start(),
+ mnesia:create_table(ids, [{attributes, record_info(fields, ids)},
+ {disc_copies, [node()]}]),
+
+ mnesia:create_table(category, [{attributes, record_info(fields, category)},
+ {disc_copies, [node()]}]),
+
+ mnesia:create_table(product, [{attributes, record_info(fields, product)},
+ {disc_copies, [node()]}]).
+
+init() ->
+ add_category(#category{name="Cookies"}),
+ add_category(#category{name="Cakes"}),
+ add_category(#category{name="Pies"}),
+
+ add_product(#product{name="Choco Cookie", cat_id = 1,
+ description="Some very tasty cookies!",
+ price=#price{price=1000,currency="SEK"}}),
+ add_product(#product{name="Wedding Cake", cat_id = 2,
+ description="Some very tasty cookies!",
+ price=#price{price=1000,currency="SEK"}}),
+ add_product(#product{name="Meat Pie", cat_id = 3,
+ description="Some very tasty cookies!",
+ price=#price{price=1000,currency="SEK"}}).
+
+
+%%====================================================================
+%% API functions
+%%====================================================================
+
+%%--------------------------------------------------------------------
+%% Category functions
+%%--------------------------------------------------------------------
+add_category(Category) ->
+ Id = mnesia:dirty_update_counter(ids,category_id,1),
+ URL = "99" ++ integer_to_list(Id),
+ Cat = Category#category{id = Id, url = URL},
+ Fun = fun() ->
+ mnesia:write(Cat)
+ end,
+ case mnesia:transaction(Fun) of
+ {aborted,Reason} ->
+ ?PRINT(Reason),
+ throw(dberror);
+ _ -> ok
+ end.
+
+get_categories()->
+ Fun = fun() ->
+ R = #category{ _ = '_'},
+ mnesia:select(category, [{R, [], ['$_']}])
+ end,
+ call(Fun).
+
+get_category(Id) ->
+ Fun = fun() ->
+ hd(mnesia:read(category,Id))
+ end,
+ call(Fun).
+
+
+%%--------------------------------------------------------------------
+%% Product functions
+%%--------------------------------------------------------------------
+
+add_product(Product) ->
+ Id = mnesia:dirty_update_counter(ids,product_id,1),
+ Prod = Product#product{id = Id},
+ Fun = fun() ->
+ mnesia:write(Prod)
+ end,
+ call(Fun).
+
+
+get_product(ProdId) ->
+ Fun = fun() ->
+ hd(mnesia:read(product,ProdId))
+ end,
+ call(Fun).
+
+
+get_products(ProdIdList) when is_list(ProdIdList) ->
+ Fun = fun() ->
+ [hd(mnesia:read(product,X))||X<-ProdIdList]
+ end,
+ call(Fun);
+get_products(CatId) when is_integer(CatId) ->
+ Fun = fun() ->
+ R = #product{ cat_id = CatId, _ = '_'},
+ mnesia:select(product, [{R, [], ['$_']}])
+ end,
+ call(Fun).
+
+%%====================================================================
+%% Internal functions
+%%====================================================================
+
+call(Fun) ->
+ case mnesia:transaction(Fun) of
+ {aborted,Reason} ->
+ ?PRINT(Reason),
+ throw(dberror);
+ {atomic,Result} -> Result
+ end.
18 src/error.erl
@@ -0,0 +1,18 @@
+-module (error).
+-compile (export_all).
+
+-include_lib ("nitrogen/include/wf.inc").
+
+
+%% Use this module to trap errors you know how to handle
+%% but could potentialy happen in many different places.
+%% i.e loss of database connection.
+
+event(Event) ->
+ Module = wf:get_page_module(),
+ try Module:handle_event(Event)
+ catch throw:dberror ->
+ wf:wire(#alert { text="Connection to database failed, please try again later" }),
+ []
+ end.
+
5 src/image.erl
@@ -0,0 +1,5 @@
+-module(image).
+-compile(export_all).
+
+load(_ImgID) ->
+ "../img/default.gif/".
4 src/image.erl~
@@ -0,0 +1,4 @@
+-module(image).
+
+load(ImgID) ->
+ "./img/default.gif/".
20 src/pages/web_index.erl~
@@ -0,0 +1,20 @@
+-module (web_index).
+-compile (export_all).
+
+-include_lib ("nitrogen/include/wf.inc").
+
+main() ->
+ #template { file="./wwwroot/main.tpl"}.
+
+render() ->
+ wf:render(#label { text="2010-03-04 : Code Work is rolling and soon you will be able to start using this wonderful page. /admin" }).
+render_page(String) ->
+ String.
+
+template() ->
+ %% Hacka-dodel-doo
+ wf:state(template_was_called,false),
+ #template { file="./wwwroot/contact.tpl"}.
+
+event(Event) ->
+ ?PRINT(Event).
34 src/pages/web_login.erl
@@ -0,0 +1,34 @@
+-module (web_login).
+-compile (export_all).
+
+-include_lib ("nitrogen/include/wf.inc").
+
+main() ->
+ #template { file="./wwwroot/main.html"}.
+
+render() ->
+ wf:wire("obj('username').focus()"),
+ #panel{body=
+ [#literal{text="if you don't have a password you can register " },
+ #link{text="here", url="/web/registration"},#br{},
+ #label{text="Username"},#br{},
+ #textbox{id=username, next=password},#br{},
+ #label{text="Password"},#br{},
+ #password{id=password, next=login_btn},#br{},#br{},
+ #button{id=login_btn, text="Login", postback=login}
+ ]}.
+
+event(Event)->
+ error:event(Event).
+
+%%% Never call handle_event directly! %%%
+handle_event(login) ->
+ User = hd(wf:q(username)),
+ Pass = hd(wf:q(password)),
+ case db:auth_user(User,Pass) of
+ false ->
+ wf:wire(#alert { text="Wrong Username or Password" });
+ true ->
+ wf:user(User),
+ wf:redirect_from_login("/")
+ end.
10 src/price.erl
@@ -0,0 +1,10 @@
+-module(price).
+-compile(export_all).
+
+-include("records.hrl").
+
+toString(Price) ->
+ PriceStr = integer_to_list(Price#price.price),
+ Length = length(PriceStr),
+ {Integer,Fraction} = lists:split(Length-2,PriceStr),
+ Integer++","++Fraction++" "++Price#price.currency.
5 src/price.erl~
@@ -0,0 +1,5 @@
+-module(price).
+
+-include("records.hrl").
+
+toString(Price)
50 src/product.erl
@@ -0,0 +1,50 @@
+-module (product).
+-compile (export_all).
+
+-include_lib ("nitrogen/include/wf.inc").
+-include("records.hrl").
+
+-define(PRODUCT,wf:state(product)).
+
+%load(Product) ->
+
+load(Product) when is_record(Product,product)->
+ wf:state(product,Product);
+load(ProdId) ->
+ wf:state(product,db:get_product(ProdId)),
+
+ ProdStr = integer_to_list(ProdId),
+ Path = "./tpl/112" ++ ProdStr ++ ".tpl",
+ case file:read_file_info(Path) of
+ {ok,_} ->
+ #template { file=Path };
+ {error,_} ->
+ #template{ file="./tpl/CC_product.tpl" }
+ end.
+
+id() ->
+ (?PRODUCT)#product.id.
+
+name() ->
+ (?PRODUCT)#product.name.
+
+url() ->
+ (?PRODUCT)#product.url.
+
+img() ->
+ image:load((?PRODUCT)#product.img).
+
+description() ->
+ (?PRODUCT)#product.description.
+
+price() ->
+ price:toString((?PRODUCT)#product.price).
+
+buyLink() ->
+ Delegate = #event{type=click, delegate=product, postback={buy,id(),1}},
+ #link{text="add to cart", class="icon cart_put", actions=Delegate}.
+
+event({buy,ProdId,Qty}) ->
+ cart:add(Qty,ProdId);
+event(Event) ->
+ ?PRINT(Event).
54 src/product.erl~
@@ -0,0 +1,54 @@
+-module (product).
+-compile (export_all).
+
+-include_lib ("nitrogen/include/wf.inc").
+-include("records.hrl").
+
+-define(PRODUCT,wf:state(product)).
+
+%load(Product) ->
+
+
+load(ProductId) when is_record(ProductId,prodId)->
+ ProdId = ProductId#prodId.product,
+ CatId = ProductId#prodId.category,
+ wf:state(product,db:get_product(CatId,ProdId)),
+
+ CatStr = integer_to_list(CatId),
+ ProdStr = integer_to_list(ProdId),
+ Path = "./tpl/" ++ CatStr ++ "_" ++ ProdStr ++ ".tpl",
+ case file:read_file_info(Path) of
+ {ok,_} ->
+ #template { file=Path };
+ {error,_} ->
+ #template{ file="./tpl/CC_product.tpl" }
+ end;
+load(Prod) ->
+ wf:state(product,Prod).
+
+id() ->
+ (?PRODUCT)#product.id.
+
+name() ->
+ (?PRODUCT)#product.name.
+
+url() ->
+ (?PRODUCT)#product.url.
+
+img() ->
+ image:load((?PRODUCT)#product.img).
+
+description() ->
+ (?PRODUCT)#product.description.
+
+price() ->
+ price:toString((?PRODUCT)#product.price).
+
+buyLink() ->
+ Delegate = #event{type=click, delegate=product, postback={buy,id(),1}},
+ #link{text="add to cart", actions=Delegate}.
+
+event({buy,ProdId,Qty}) ->
+ cart:add(Qty,ProdId);
+event(Event) ->
+ ?PRINT(Event).
31 src/web_index.erl
@@ -0,0 +1,31 @@
+-module (web_index).
+-compile (export_all).
+
+-include_lib ("nitrogen/include/wf.inc").
+-include("records.hrl").
+
+main() ->
+ PathInfo = wf:get_path_info(),
+ select_template(PathInfo).
+
+select_template([]) ->
+ #template { file="./tpl/main.tpl"};
+select_template("112" ++ ProdId) ->
+ product:load(list_to_integer(ProdId));
+select_template("99" ++ CatId) ->
+ category:load(list_to_integer(CatId));
+select_template(PathInfo) ->
+ #template { file="./wwwroot/"++ PathInfo}.
+
+render() ->
+ wf:render(#label { text="2010-03-04 : Code Work is rolling and soon you will be able to start using this wonderful page. /admin" }).
+render_page(String) ->
+ String.
+
+template() ->
+ %% Hacka-dodel-doo
+ wf:state(template_was_called,false),
+ #template { file="./wwwroot/contact.tpl"}.
+
+event(Event) ->
+ ?PRINT(Event).
36 src/web_index.erl~
@@ -0,0 +1,36 @@
+-module (web_index).
+-compile (export_all).
+
+-include_lib ("nitrogen/include/wf.inc").
+-include("records.hrl").
+
+main() ->
+ PathInfo = wf:get_path_info(),
+ select_template(PathInfo).
+
+select_template([]) ->
+ #template { file="./tpl/main.tpl"};
+select_template(PathInfo) ->
+ Tokens = string:tokens(PathInfo,"_"),
+ try [list_to_integer(X)||X<-Tokens] of
+ [CatId,ProdId] ->
+ product:load(#prodId{category=CatId,product=ProdId});
+ [CatId] ->
+ category:load(CatId)
+ catch
+ _Error ->
+ #template { file="./wwwroot/"++ PathInfo}
+ end.
+
+render() ->
+ wf:render(#label { text="2010-03-04 : Code Work is rolling and soon you will be able to start using this wonderful page. /admin" }).
+render_page(String) ->
+ String.
+
+template() ->
+ %% Hacka-dodel-doo
+ wf:state(template_was_called,false),
+ #template { file="./wwwroot/contact.tpl"}.
+
+event(Event) ->
+ ?PRINT(Event).
15 start.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+export NITROGEN_SRC=/usr/lib/erlang/lib/nitrogen-master/www
+cd `dirname $0`
+
+echo Creating link to nitrogen support files...
+rm -rf wwwroot/nitrogen
+ln -s $NITROGEN_SRC wwwroot/nitrogen
+
+echo Starting Nitrogen on Inets...
+erl \
+ -name nitrogen@127.0.0.1 \
+ -pa $PWD/apps $PWD/ebin $PWD/include \
+ -s make all \
+ -eval "application:start(codeWork)"
+
117 tpl/1.tpl
@@ -0,0 +1,117 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>Code Work</title>
+
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <script src='/nitrogen/jquery.js' type='text/javascript' charset='utf-8'>
+ </script>
+ <script src='/nitrogen/jquery-ui.js' type='text/javascript' charset='utf-8'>
+ </script>
+ <script src='/nitrogen/livevalidation.js'
+ type='text/javascript' charset='utf-8'></script>
+ <script src='/nitrogen/nitrogen.js' type='text/javascript' charset='utf-8'>
+ </script>
+
+ <link rel="stylesheet"
+ type="text/css"
+ href="/css/style.css"
+ media="screen" />
+ </head>
+
+ <body>
+ <div id="wrap">
+ <div id="container">
+ <div id="top-panel">
+ <div class="left">
+ [[[web_index:render_page("smalllogin")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("internationalization")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("currency")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("tax")]]]
+ </div>
+ </div> <!-- top-panel end !-->
+
+ <div id="header">
+ <h1>Cookie Cart</h1>
+ </div>
+
+ <div>
+ <div id="searchpanel">
+ [[[web_index:render_page("mainsearch")]]]
+ </div>
+
+ <div id="locationpanel">
+ [[[web_index:render_page("location")]]]
+ </div>
+ </div>
+
+ <div id="sidebar">
+ <div class="block">
+ <h3>Cart</h3>
+ [[[web_index:render_page("smallcart")]]]
+ </div>
+
+ <div class="block">
+ <h3>Categories</h3>
+ [[[category:list()]]]
+ </div>
+
+ <div class="block">
+ [[[web_index:render_page("Contactinfo")]]]
+ </div>
+ </div> <!-- sidebar end !-->
+
+ <div id="content">
+ <h2>[[[category:name()]]]</h2>
+
+ <table>
+ <tr>
+ <th></th>
+ <th class="fullwidth">Name</th>
+ <th>Price</th>
+ <th>Status</th>
+ <th>Quantity</th>
+ <th></th>
+ </tr>
+
+ [[[category:listProducts("CC_listProducts.html")]]]
+ </table>
+ <hr>
+ </div>
+
+ <div class="clear"></div>
+
+ <div class="text-center">
+ <img src="/themes/default/img/payment_methods.gif" />
+ </div>
+ </div><!-- container end !-->
+
+ <div id="end"></div>
+
+ <div id="footer">
+ <div id="credits">
+ Powered by <a href="http://klarna.se/">Cookie Cart</a> -
+ <a href="http://www.nitrogenproject.com/">Nitrogen</a> -
+ <a href="http://riak.basho.com/">Riak</a> -
+ <a href="http://code.google.com/p/mochiweb/">Mochiweb</a> -
+ </div>
+ </div> <!-- footer end !-->
+ </div><!-- wrap end !-->
+
+ <script>
+ [[[script]]]
+ </script>
+
+ </body>
+</html>
117 tpl/1.tpl~
@@ -0,0 +1,117 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>Code Work</title>
+
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <script src='/nitrogen/jquery.js' type='text/javascript' charset='utf-8'>
+ </script>
+ <script src='/nitrogen/jquery-ui.js' type='text/javascript' charset='utf-8'>
+ </script>
+ <script src='/nitrogen/livevalidation.js'
+ type='text/javascript' charset='utf-8'></script>
+ <script src='/nitrogen/nitrogen.js' type='text/javascript' charset='utf-8'>
+ </script>
+
+ <link rel="stylesheet"
+ type="text/css"
+ href="/css/style.css"
+ media="screen" />
+ </head>
+
+ <body>
+ <div id="wrap">
+ <div id="container">
+ <div id="top-panel">
+ <div class="left">
+ [[[web_index:render_page("smalllogin")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("internationalization")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("currency")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("tax")]]]
+ </div>
+ </div> <!-- top-panel end !-->
+
+ <div id="header">
+ <h1>Cookie Cart</h1>
+ </div>
+
+ <div>
+ <div id="searchpanel">
+ [[[web_index:render_page("mainsearch")]]]
+ </div>
+
+ <div id="locationpanel">
+ [[[web_index:render_page("location")]]]
+ </div>
+ </div>
+
+ <div id="sidebar">
+ <div class="block">
+ <h3>Cart</h3>
+ [[[web_index:render_page("smallcart")]]]
+ </div>
+
+ <div class="block">
+ <h3>Categories</h3>
+ [[[category:list()]]]
+ </div>
+
+ <div class="block">
+ [[[web_index:render_page("Contactinfo")]]]
+ </div>
+ </div> <!-- sidebar end !-->
+
+ <div id="content">
+ <h2>[[[category:name()]]]</h2>
+
+ <table>
+ <tr>
+ <th></th>
+ <th class="fullwidth">Name</th>
+ <th>Price</th>
+ <th>Status</th>
+ <th>Quantity</th>
+ <th></th>
+ </tr>
+
+ [[[category:listProducts("CC_listProducts.html")]]]
+ </table>
+ <hr>
+ </div>
+
+ <div class="clear"></div>
+
+ <div class="text-center">
+ <img src="/themes/default/img/payment_methods.gif" />
+ </div>
+ </div><!-- container end !-->
+
+ <div id="end"></div>
+
+ <div id="footer">
+ <div id="credits">
+ Powered by <a href="http://klarna.se/">Cookie Cart</a> -
+ <a href="http://www.nitrogenproject.com/">Nitrogen</a> -
+ <a href="http://riak.basho.com/">Riak</a> -
+ <a href="http://code.google.com/p/mochiweb/">Mochiweb</a> -
+ </div>
+ </div> <!-- footer end !-->
+ </div><!-- wrap end !-->
+
+ <script>
+ [[[script]]]
+ </script>
+
+ </body>
+</html>
120 tpl/1121.tpl
@@ -0,0 +1,120 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>Code Work</title>
+
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <script src='/nitrogen/jquery.js' type='text/javascript' charset='utf-8'>
+ </script>
+ <script src='/nitrogen/jquery-ui.js' type='text/javascript' charset='utf-8'>
+ </script>
+ <script src='/nitrogen/livevalidation.js'
+ type='text/javascript' charset='utf-8'></script>
+ <script src='/nitrogen/nitrogen.js' type='text/javascript' charset='utf-8'>
+ </script>
+
+ <link rel="stylesheet"
+ type="text/css"
+ href="/css/style.css"
+ media="screen" />
+ </head>
+
+ <body>
+ <div id="wrap">
+ <div id="container">
+ <div id="top-panel">
+ <div class="left">
+ [[[web_index:render_page("smalllogin")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("internationalization")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("currency")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("tax")]]]
+ </div>
+ </div> <!-- top-panel end !-->
+
+ <div id="header">
+ <h1>Cookie Cart</h1>
+ </div>
+
+ <div>
+ <div id="searchpanel">
+ [[[web_index:render_page("mainsearch")]]]
+ </div>
+
+ <div id="locationpanel">
+ [[[web_index:render_page("location")]]]
+ </div>
+ </div>
+
+ <div id="sidebar">
+ <div class="block">
+ <h3>Cart</h3>
+ [[[web_index:render_page("smallcart")]]]
+ </div>
+
+ <div class="block">
+ <h3>Categories</h3>
+ [[[category:list()]]]
+ </div>
+
+ <div class="block">
+ [[[web_index:render_page("Contactinfo")]]]
+ </div>
+ </div> <!-- sidebar end !-->
+
+ <div id="content">
+ <h2>[[[product:name()]]]</h2>
+
+ <div class="column">
+ <img style="width:150px;"
+ src=[[[product:img()]]]/>
+ </div>
+
+ <div class="column">
+ <strong>Price</strong> [[[product:price()]]] <br/>
+ <strong>Status</strong>status<br/>
+ <strong>Quantity</strong>quantity<br/>
+ [[[product:buyLink()]]]
+ </div>
+
+ <div class="clear"></div>
+
+ <h3>Product description</h3>
+ [[[product:description()]]]
+ </div>
+
+ <div class="clear"></div>
+
+ <div class="text-center">
+ <img src="/themes/default/img/payment_methods.gif" />
+ </div>
+ </div><!-- container end !-->
+
+ <div id="end"></div>
+
+ <div id="footer">
+ <div id="credits">
+ Powered by <a href="http://klarna.se/">Cookie Cart</a> -
+ <a href="http://www.nitrogenproject.com/">Nitrogen</a> -
+ <a href="http://riak.basho.com/">Riak</a> -
+ <a href="http://code.google.com/p/mochiweb/">Mochiweb</a> -
+ </div>
+ </div> <!-- footer end !-->
+ </div><!-- wrap end !-->
+
+ <script>
+ [[[script]]]
+ </script>
+
+ </body>
+</html>
120 tpl/1_1.tpl~
@@ -0,0 +1,120 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>Code Work</title>
+
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <script src='/nitrogen/jquery.js' type='text/javascript' charset='utf-8'>
+ </script>
+ <script src='/nitrogen/jquery-ui.js' type='text/javascript' charset='utf-8'>
+ </script>
+ <script src='/nitrogen/livevalidation.js'
+ type='text/javascript' charset='utf-8'></script>
+ <script src='/nitrogen/nitrogen.js' type='text/javascript' charset='utf-8'>
+ </script>
+
+ <link rel="stylesheet"
+ type="text/css"
+ href="/css/style.css"
+ media="screen" />
+ </head>
+
+ <body>
+ <div id="wrap">
+ <div id="container">
+ <div id="top-panel">
+ <div class="left">
+ [[[web_index:render_page("smalllogin")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("internationalization")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("currency")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("tax")]]]
+ </div>
+ </div> <!-- top-panel end !-->
+
+ <div id="header">
+ <h1>Cookie Cart</h1>
+ </div>
+
+ <div>
+ <div id="searchpanel">
+ [[[web_index:render_page("mainsearch")]]]
+ </div>
+
+ <div id="locationpanel">
+ [[[web_index:render_page("location")]]]
+ </div>
+ </div>
+
+ <div id="sidebar">
+ <div class="block">
+ <h3>Cart</h3>
+ [[[web_index:render_page("smallcart")]]]
+ </div>
+
+ <div class="block">
+ <h3>Categories</h3>
+ [[[category:list()]]]
+ </div>
+
+ <div class="block">
+ [[[web_index:render_page("Contactinfo")]]]
+ </div>
+ </div> <!-- sidebar end !-->
+
+ <div id="content">
+ <h2>[[[product:name()]]]</h2>
+
+ <div class="column">
+ <img style="width:150px;"
+ src=[[[product:img()]]]/>
+ </div>
+
+ <div class="column">
+ <strong>Price</strong> [[[product:price()]]] <br/>
+ <strong>Status</strong>status<br/>
+ <strong>Quantity</strong>quantity<br/>
+ buyLink
+ </div>
+
+ <div class="clear"></div>
+
+ <h3>Product description</h3>
+ [[[product:description()]]]
+ </div>
+
+ <div class="clear"></div>
+
+ <div class="text-center">
+ <img src="/themes/default/img/payment_methods.gif" />
+ </div>
+ </div><!-- container end !-->
+
+ <div id="end"></div>
+
+ <div id="footer">
+ <div id="credits">
+ Powered by <a href="http://klarna.se/">Cookie Cart</a> -
+ <a href="http://www.nitrogenproject.com/">Nitrogen</a> -
+ <a href="http://riak.basho.com/">Riak</a> -
+ <a href="http://code.google.com/p/mochiweb/">Mochiweb</a> -
+ </div>
+ </div> <!-- footer end !-->
+ </div><!-- wrap end !-->
+
+ <script>
+ [[[script]]]
+ </script>
+
+ </body>
+</html>
117 tpl/CC_category.tpl
@@ -0,0 +1,117 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>Code Work</title>
+
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <script src='/nitrogen/jquery.js' type='text/javascript' charset='utf-8'>
+ </script>
+ <script src='/nitrogen/jquery-ui.js' type='text/javascript' charset='utf-8'>
+ </script>
+ <script src='/nitrogen/livevalidation.js'
+ type='text/javascript' charset='utf-8'></script>
+ <script src='/nitrogen/nitrogen.js' type='text/javascript' charset='utf-8'>
+ </script>
+
+ <link rel="stylesheet"
+ type="text/css"
+ href="/css/style.css"
+ media="screen" />
+ </head>
+
+ <body>
+ <div id="wrap">
+ <div id="container">
+ <div id="top-panel">
+ <div class="left">
+ [[[web_index:render_page("smalllogin")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("internationalization")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("currency")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("tax")]]]
+ </div>
+ </div> <!-- top-panel end !-->
+
+ <div id="header">
+ <h1>Cookie Cart</h1>
+ </div>
+
+ <div>
+ <div id="searchpanel">
+ [[[web_index:render_page("mainsearch")]]]
+ </div>
+
+ <div id="locationpanel">
+ [[[web_index:render_page("location")]]]
+ </div>
+ </div>
+
+ <div id="sidebar">
+ <div class="block">
+ <h3>Cart</h3>
+ [[[web_index:render_page("smallcart")]]]
+ </div>
+
+ <div class="block">
+ <h3>Categories</h3>
+ [[[category:list()]]]
+ </div>
+
+ <div class="block">
+ [[[web_index:render_page("Contactinfo")]]]
+ </div>
+ </div> <!-- sidebar end !-->
+
+ <div id="content">
+ <h2>[[[category:name()]]]</h2>
+
+ <table>
+ <tr>
+ <th></th>
+ <th class="fullwidth">Name</th>
+ <th>Price</th>
+ <th>Status</th>
+ <th>Quantity</th>
+ <th></th>
+ </tr>
+
+ [[[category:listProducts("CC_listProducts.html")]]]
+ </table>
+ <hr>
+ </div>
+
+ <div class="clear"></div>
+
+ <div class="text-center">
+ <img src="/themes/default/img/payment_methods.gif" />
+ </div>
+ </div><!-- container end !-->
+
+ <div id="end"></div>
+
+ <div id="footer">
+ <div id="credits">
+ Powered by <a href="http://klarna.se/">Cookie Cart</a> -
+ <a href="http://www.nitrogenproject.com/">Nitrogen</a> -
+ <a href="http://riak.basho.com/">Riak</a> -
+ <a href="http://code.google.com/p/mochiweb/">Mochiweb</a> -
+ </div>
+ </div> <!-- footer end !-->
+ </div><!-- wrap end !-->
+
+ <script>
+ [[[script]]]
+ </script>
+
+ </body>
+</html>
120 tpl/CC_product.tpl
@@ -0,0 +1,120 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>Code Work</title>
+
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <script src='/nitrogen/jquery.js' type='text/javascript' charset='utf-8'>
+ </script>
+ <script src='/nitrogen/jquery-ui.js' type='text/javascript' charset='utf-8'>
+ </script>
+ <script src='/nitrogen/livevalidation.js'
+ type='text/javascript' charset='utf-8'></script>
+ <script src='/nitrogen/nitrogen.js' type='text/javascript' charset='utf-8'>
+ </script>
+
+ <link rel="stylesheet"
+ type="text/css"
+ href="/css/style.css"
+ media="screen" />
+ </head>
+
+ <body>
+ <div id="wrap">
+ <div id="container">
+ <div id="top-panel">
+ <div class="left">
+ [[[web_index:render_page("smalllogin")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("internationalization")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("currency")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("tax")]]]
+ </div>
+ </div> <!-- top-panel end !-->
+
+ <div id="header">
+ <h1>Cookie Cart</h1> </