wheels 0.0.48 → 0.0.49

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) hide show
  1. data/VERSION +1 -1
  2. data/app/controllers/access_control_entries_controller.rb +4 -4
  3. data/app/controllers/external_links_controller.rb +5 -0
  4. data/app/controllers/feedbacks_controller.rb +10 -0
  5. data/app/controllers/menus_controller.rb +2 -0
  6. data/app/controllers/pages_controller.rb +16 -29
  7. data/app/controllers/sitemaps_controller.rb +135 -0
  8. data/app/helpers/application_helper.rb +4 -3
  9. data/app/helpers/external_links_helper.rb +2 -0
  10. data/app/helpers/feedbacks_helper.rb +2 -0
  11. data/app/helpers/menus_helper.rb +2 -0
  12. data/app/helpers/sitemaps_helper.rb +12 -0
  13. data/app/mailers/feedback_mailer.rb +10 -0
  14. data/app/models/ability.rb +2 -1
  15. data/app/models/access_control_entry.rb +17 -15
  16. data/app/models/external_link.rb +4 -0
  17. data/app/models/feedback.rb +13 -0
  18. data/app/models/image.rb +1 -1
  19. data/app/models/menu.rb +4 -0
  20. data/app/models/page.rb +2 -5
  21. data/app/models/sitemap.rb +153 -0
  22. data/app/models/user.rb +7 -1
  23. data/app/validators/email_validator.rb +22 -0
  24. data/app/views/access_control_entries/_form.html.haml +1 -1
  25. data/app/views/access_control_entries/_index.html.haml +3 -3
  26. data/app/views/access_control_entries/_show.html.haml +1 -1
  27. data/app/views/external_links/_fields_for.html.haml +2 -0
  28. data/app/views/external_links/_form.html.haml +18 -0
  29. data/app/views/external_links/_show.html.haml +7 -0
  30. data/app/views/external_links/edit.html.haml +7 -0
  31. data/app/views/external_links/index.html.haml +23 -0
  32. data/app/views/external_links/new.html.haml +5 -0
  33. data/app/views/external_links/show.html.haml +2 -0
  34. data/app/views/feedback_mailer/submit_feedback.html.haml +22 -0
  35. data/app/views/feedbacks/_form.html.haml +37 -0
  36. data/app/views/feedbacks/index.html.haml +27 -0
  37. data/app/views/feedbacks/new.html.haml +5 -0
  38. data/app/views/feedbacks/show.html.haml +19 -0
  39. data/app/views/layouts/application.html.haml +21 -16
  40. data/app/views/layouts/bare.html.haml +2 -0
  41. data/app/views/loadbehind/_view.js.haml +1 -2
  42. data/app/views/menus/_form.html.haml +13 -0
  43. data/app/views/menus/edit.html.haml +7 -0
  44. data/app/views/menus/index.html.haml +19 -0
  45. data/app/views/menus/new.html.haml +5 -0
  46. data/app/views/menus/show.html.haml +7 -0
  47. data/app/views/pages/_child_pages_links.html.haml +1 -1
  48. data/app/views/pages/_control_panel.html.haml +1 -6
  49. data/app/views/pages/_form.html.haml +2 -2
  50. data/app/views/pages/_form_fields.html.haml +7 -2
  51. data/app/views/pages/_show.html.haml +4 -0
  52. data/app/views/pages/create.js.haml +2 -1
  53. data/app/views/pages/destroy.js.haml +3 -0
  54. data/app/views/pages/edit.js.haml +4 -0
  55. data/app/views/pages/index.html.haml +4 -2
  56. data/app/views/pages/index.js.haml +3 -0
  57. data/app/views/pages/new.js.haml +3 -0
  58. data/app/views/pages/show.html.haml +2 -10
  59. data/app/views/pages/show.js.haml +3 -0
  60. data/app/views/pages/update.js.haml +2 -2
  61. data/app/views/sitemaps/edit.html.haml +12 -0
  62. data/app/views/sitemaps/edit.js.erb +0 -0
  63. data/app/views/sitemaps/index.html.haml +93 -0
  64. data/app/views/sitemaps/index.json.erb +23 -0
  65. data/app/views/sitemaps/new.html.haml +8 -0
  66. data/app/views/sitemaps/new.js.erb +0 -0
  67. data/app/views/users/edit.html.haml +45 -0
  68. data/db/migrate/{add_fields_to_users.rb → 0010_add_fields_to_users.rb} +0 -0
  69. data/db/migrate/{create_blogs.rb → 0020_create_blogs.rb} +0 -0
  70. data/db/migrate/{create_galleries.rb → 0030_create_galleries.rb} +0 -0
  71. data/db/migrate/{create_images.rb → 0040_create_images.rb} +0 -0
  72. data/db/migrate/{create_profiles.rb → 0050_create_profiles.rb} +0 -0
  73. data/db/migrate/{insert_admin_user_and_roles.rb → 0060_insert_admin_user_and_roles.rb} +0 -0
  74. data/db/migrate/{create_pages.rb → 0070_create_pages.rb} +0 -0
  75. data/db/migrate/{create_forums.rb → 0080_create_forums.rb} +0 -0
  76. data/db/migrate/{create_discussions.rb → 0090_create_discussions.rb} +0 -0
  77. data/db/migrate/{create_forum_messages.rb → 0100_create_forum_messages.rb} +0 -0
  78. data/db/migrate/{create_access_control_entries.rb → 0110_create_access_control_entries.rb} +3 -3
  79. data/db/migrate/{create_attachments.rb → 0120_create_attachments.rb} +0 -4
  80. data/db/migrate/{create_roles.rb → 0130_create_roles.rb} +0 -0
  81. data/db/migrate/0140_create_feedbacks.rb +20 -0
  82. data/db/migrate/0150_create_external_links.rb +14 -0
  83. data/db/migrate/0160_create_sitemaps.rb +17 -0
  84. data/db/migrate/0170_create_menus.rb +14 -0
  85. data/lib/development_mail_interceptor.rb +7 -0
  86. data/lib/generators/wheels/recipes/wheels.rb +18 -12
  87. data/lib/wheels/base.rb +7 -0
  88. data/lib/wheels/routes.rb +8 -3
  89. data/lib/wheels.rb +2 -0
  90. data/public/javascripts/jquery-validate/additional-methods.js +259 -0
  91. data/public/javascripts/jquery-validate/changelog.txt +239 -0
  92. data/public/javascripts/jquery-validate/jquery.validate.js +1146 -0
  93. data/public/javascripts/jquery-validate/jquery.validate.min.js +16 -0
  94. data/public/javascripts/jquery-validate/jquery.validate.pack.js +15 -0
  95. data/public/javascripts/jquery-validate/lib/jquery-1.4.2.js +6240 -0
  96. data/public/javascripts/jquery-validate/lib/jquery.form.js +660 -0
  97. data/public/javascripts/jquery-validate/lib/jquery.js +4376 -0
  98. data/public/javascripts/jquery-validate/lib/jquery.metadata.js +122 -0
  99. data/public/javascripts/jquery-validate/localization/messages_ar.js +24 -0
  100. data/public/javascripts/jquery-validate/localization/messages_bg.js +23 -0
  101. data/public/javascripts/jquery-validate/localization/messages_cn.js +23 -0
  102. data/public/javascripts/jquery-validate/localization/messages_cs.js +23 -0
  103. data/public/javascripts/jquery-validate/localization/messages_da.js +20 -0
  104. data/public/javascripts/jquery-validate/localization/messages_de.js +20 -0
  105. data/public/javascripts/jquery-validate/localization/messages_el.js +24 -0
  106. data/public/javascripts/jquery-validate/localization/messages_es.js +23 -0
  107. data/public/javascripts/jquery-validate/localization/messages_fa.js +23 -0
  108. data/public/javascripts/jquery-validate/localization/messages_fi.js +21 -0
  109. data/public/javascripts/jquery-validate/localization/messages_fr.js +23 -0
  110. data/public/javascripts/jquery-validate/localization/messages_he.js +23 -0
  111. data/public/javascripts/jquery-validate/localization/messages_hu.js +20 -0
  112. data/public/javascripts/jquery-validate/localization/messages_it.js +23 -0
  113. data/public/javascripts/jquery-validate/localization/messages_kk.js +23 -0
  114. data/public/javascripts/jquery-validate/localization/messages_lt.js +23 -0
  115. data/public/javascripts/jquery-validate/localization/messages_lv.js +23 -0
  116. data/public/javascripts/jquery-validate/localization/messages_nl.js +23 -0
  117. data/public/javascripts/jquery-validate/localization/messages_no.js +23 -0
  118. data/public/javascripts/jquery-validate/localization/messages_pl.js +23 -0
  119. data/public/javascripts/jquery-validate/localization/messages_ptbr.js +23 -0
  120. data/public/javascripts/jquery-validate/localization/messages_ptpt.js +23 -0
  121. data/public/javascripts/jquery-validate/localization/messages_ro.js +23 -0
  122. data/public/javascripts/jquery-validate/localization/messages_ru.js +23 -0
  123. data/public/javascripts/jquery-validate/localization/messages_se.js +21 -0
  124. data/public/javascripts/jquery-validate/localization/messages_sk.js +20 -0
  125. data/public/javascripts/jquery-validate/localization/messages_tr.js +23 -0
  126. data/public/javascripts/jquery-validate/localization/messages_tw.js +23 -0
  127. data/public/javascripts/jquery-validate/localization/messages_ua.js +23 -0
  128. data/public/javascripts/jquery-validate/localization/methods_de.js +12 -0
  129. data/public/javascripts/jquery-validate/localization/methods_nl.js +9 -0
  130. data/public/javascripts/jquery-validate/localization/methods_pt.js +9 -0
  131. data/public/javascripts/jquery-validate/todo +172 -0
  132. data/public/javascripts/jquery.cookie.js +96 -0
  133. data/public/javascripts/jquery.filedrop.js +253 -0
  134. data/public/javascripts/jquery.hotkeys.js +99 -0
  135. data/public/javascripts/jquery.js +6240 -0
  136. data/public/javascripts/jquery.jstree.js +3510 -0
  137. data/public/javascripts/jquery.uploadify.js +26 -0
  138. data/public/javascripts/jquery.validate.js +1147 -0
  139. data/public/javascripts/sitemap_jstree.js +329 -0
  140. data/public/javascripts/swfobject.js +4 -0
  141. data/public/jstree/_demo/_dump.sql +20 -0
  142. data/public/jstree/_demo/_inc/__mysql_errors.log +0 -0
  143. data/public/jstree/_demo/_inc/class._database.php +146 -0
  144. data/public/jstree/_demo/_inc/class._database_i.php +152 -0
  145. data/public/jstree/_demo/_inc/class.tree.php +602 -0
  146. data/public/jstree/_demo/_install.txt +6 -0
  147. data/public/jstree/_demo/config.php +14 -0
  148. data/public/jstree/_demo/index.html +262 -0
  149. data/public/jstree/_demo/server.php +69 -0
  150. data/public/jstree/_docs/!style.css +37 -0
  151. data/public/jstree/_docs/_drive.png +0 -0
  152. data/public/jstree/_docs/_html_data.html +2 -0
  153. data/public/jstree/_docs/_json_data.json +4 -0
  154. data/public/jstree/_docs/_search_data.json +6 -0
  155. data/public/jstree/_docs/_search_result.json +1 -0
  156. data/public/jstree/_docs/_xml_flat.xml +12 -0
  157. data/public/jstree/_docs/_xml_nest.xml +18 -0
  158. data/public/jstree/_docs/checkbox.html +148 -0
  159. data/public/jstree/_docs/contextmenu.html +120 -0
  160. data/public/jstree/_docs/cookies.html +96 -0
  161. data/public/jstree/_docs/core.html +622 -0
  162. data/public/jstree/_docs/crrm.html +315 -0
  163. data/public/jstree/_docs/dnd.html +197 -0
  164. data/public/jstree/_docs/hotkeys.html +81 -0
  165. data/public/jstree/_docs/html_data.html +174 -0
  166. data/public/jstree/_docs/index.html +75 -0
  167. data/public/jstree/_docs/json_data.html +240 -0
  168. data/public/jstree/_docs/languages.html +138 -0
  169. data/public/jstree/_docs/search.html +114 -0
  170. data/public/jstree/_docs/sort.html +84 -0
  171. data/public/jstree/_docs/syntax/!script.js +2232 -0
  172. data/public/jstree/_docs/syntax/!style.css +511 -0
  173. data/public/jstree/_docs/syntax/clipboard.swf +0 -0
  174. data/public/jstree/_docs/syntax/help.png +0 -0
  175. data/public/jstree/_docs/syntax/magnifier.png +0 -0
  176. data/public/jstree/_docs/syntax/page_white_code.png +0 -0
  177. data/public/jstree/_docs/syntax/page_white_copy.png +0 -0
  178. data/public/jstree/_docs/syntax/printer.png +0 -0
  179. data/public/jstree/_docs/syntax/wrapping.png +0 -0
  180. data/public/jstree/_docs/themeroller.html +98 -0
  181. data/public/jstree/_docs/themes.html +126 -0
  182. data/public/jstree/_docs/types.html +173 -0
  183. data/public/jstree/_docs/ui.html +188 -0
  184. data/public/jstree/_docs/unique.html +70 -0
  185. data/public/jstree/_docs/xml_data.html +214 -0
  186. data/public/jstree/_lib/jquery.cookie.js +96 -0
  187. data/public/jstree/_lib/jquery.hotkeys.js +99 -0
  188. data/public/jstree/_lib/jquery.js +6240 -0
  189. data/public/jstree/jquery.jstree.js +3510 -0
  190. data/public/jstree/jstree.html +237 -0
  191. data/public/jstree/themes/apple/bg.jpg +0 -0
  192. data/public/jstree/themes/apple/d.png +0 -0
  193. data/public/jstree/themes/apple/dot_for_ie.gif +0 -0
  194. data/public/jstree/themes/apple/style.css +60 -0
  195. data/public/jstree/themes/apple/throbber.gif +0 -0
  196. data/public/jstree/themes/classic/d.png +0 -0
  197. data/public/jstree/themes/classic/dot_for_ie.gif +0 -0
  198. data/public/jstree/themes/classic/style.css +59 -0
  199. data/public/jstree/themes/classic/throbber.gif +0 -0
  200. data/public/jstree/themes/default/d.gif +0 -0
  201. data/public/jstree/themes/default/d.png +0 -0
  202. data/public/jstree/themes/default/style.css +73 -0
  203. data/public/jstree/themes/default/throbber.gif +0 -0
  204. data/public/jstree/themes/default-rtl/d.gif +0 -0
  205. data/public/jstree/themes/default-rtl/d.png +0 -0
  206. data/public/jstree/themes/default-rtl/dots.gif +0 -0
  207. data/public/jstree/themes/default-rtl/style.css +83 -0
  208. data/public/jstree/themes/default-rtl/throbber.gif +0 -0
  209. data/public/stylesheets/sass/dreamy.sass +21 -56
  210. data/public/stylesheets/sass/menu.sass +43 -9
  211. data/public/stylesheets/sass/uploadify.sass +52 -0
  212. data/public/stylesheets/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
  213. data/public/stylesheets/ui-lightness/jquery-ui-1.8.4.custom.css +549 -0
  214. data/wheels.gemspec +187 -15
  215. metadata +188 -16
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.48
1
+ 0.0.49
@@ -1,8 +1,7 @@
1
1
  class AccessControlEntriesController < InheritedResources::Base
2
2
  ajax_loading
3
3
  before_filter :authenticate_user!
4
- belongs_to :user, :optional => true
5
- has_scope :by_resource, :using => [:resource_class, :resource_id]
4
+ belongs_to :page, :forum, :user, :role, :polymorphic => true
6
5
  has_scope :by_role, :using=>[:role_id]
7
6
  has_scope :by_class, :using=>[:class]
8
7
  respond_to :html, :js
@@ -11,10 +10,11 @@ class AccessControlEntriesController < InheritedResources::Base
11
10
  a = AccessControlEntry.new
12
11
  a.user_id = params[:user_id]
13
12
  a.role_id = params[:role_id]
14
- a.resource_class_name = params[:resource_class]
15
- a.options[:id] = params[:resource_id]
13
+ a.resource_type = params[:page_id] ? "Page" : (params[:forum_id] ? "Forum" : nil)
14
+ a.options[:id] = params[:page_id] || params[:forum_id]
16
15
  return a
17
16
  end
17
+
18
18
  helper_method :new_ace
19
19
  end
20
20
 
@@ -0,0 +1,5 @@
1
+ class ExternalLinksController < InheritedResources::Base
2
+ respond_to :html, :js
3
+ ajax_loading
4
+ end
5
+
@@ -0,0 +1,10 @@
1
+ class FeedbacksController < InheritedResources::Base
2
+ def create
3
+ create! do |format|
4
+ FeedbackMailer.submit_feedback(@feedback).deliver
5
+ flash[:notice] = "Thanks for your feedback!"
6
+ format.html { redirect_to "/" }
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,2 @@
1
+ class MenusController < InheritedResources::Base
2
+ end
@@ -1,9 +1,8 @@
1
1
  class PagesController < InheritedResources::Base
2
2
  respond_to :js, :html
3
3
  ajax_loading
4
- belongs_to :parent, :optional=>true, :collection_name => :children,
5
- :parent_class=>Page, :param=>:page_id, :instance_name=>:parent_page
6
4
  before_filter :set_collection_name
5
+ before_filter :parse_request_url, :only=>:show
7
6
 
8
7
  def set_collection_name
9
8
  if params[:page_id]
@@ -11,6 +10,13 @@ class PagesController < InheritedResources::Base
11
10
  end
12
11
  end
13
12
 
13
+ def parse_request_url
14
+ if params["level1"]
15
+ @sitemap = Sitemap.find_by_path(*[1,2,3,4].map{|i|params["level#{i}"]})
16
+ @page = @sitemap.resource
17
+ end
18
+ end
19
+
14
20
  before_filter :authenticate_user!, :except=>[:show]
15
21
  before_filter :maybe_authenticate, :only=>[:show]
16
22
  before_filter :resource, :only=>[:update, :show, :destroy, :edit]
@@ -22,13 +28,15 @@ class PagesController < InheritedResources::Base
22
28
  end
23
29
 
24
30
  def resource
25
- page_id = params[:id]
26
- if page_id.is_numeric?
27
- @page ||= Page.find(page_id)
28
- else
29
- @page ||= Page.where(["lower(pages.title) = ?", page_id.downcase.gsub(/[_]/, ' ')]).first
31
+ unless @page
32
+ page_id = params[:id]
33
+ if page_id.is_numeric?
34
+ @page ||= Page.find(page_id)
35
+ else
36
+ @page ||= Page.where(["lower(pages.title) = ?", page_id.downcase.gsub(/[_]/, ' ')]).first
37
+ end
38
+ @attachments ||= @page.attachments
30
39
  end
31
- @attachments ||= @page.attachments
32
40
  @page
33
41
  end
34
42
 
@@ -38,15 +46,8 @@ class PagesController < InheritedResources::Base
38
46
  end
39
47
  end
40
48
 
41
- def show
42
- show! do |format|
43
- set_children
44
- end
45
- end
46
-
47
49
  def edit
48
50
  edit! do |format|
49
- set_children
50
51
  @attachment = Attachment.new(:page=>@page)
51
52
  @s3provider = S3Provider.new(:key=>"attachments/#{current_user.id}")
52
53
  end
@@ -56,12 +57,6 @@ class PagesController < InheritedResources::Base
56
57
  create! { (@parent_page ? page_child_path(@parent_page, @page) : @page) }
57
58
  end
58
59
 
59
- def new
60
- new! do |format|
61
- set_children
62
- end
63
- end
64
-
65
60
  def update
66
61
  update! do |format|
67
62
  if params[:child_id]
@@ -72,13 +67,5 @@ class PagesController < InheritedResources::Base
72
67
  end
73
68
  end
74
69
  end
75
-
76
- def set_children
77
- if @parent_page
78
- @children = @parent_page.children
79
- else
80
- @children = @page.children
81
- end
82
- end
83
70
  end
84
71
 
@@ -0,0 +1,135 @@
1
+ class SitemapsController < InheritedResources::Base
2
+ ajax_loading
3
+ respond_to :html, :js, :json
4
+ before_filter :parse_request_url, :only=>:show
5
+ before_filter :resource, :except=>[:new, :create, :index]
6
+ before_filter :collection, :only=>[:index]
7
+ before_filter :new_resource, :only=>[:new, :create]
8
+ before_filter :authenticate_user!, :authorize_action!
9
+
10
+ def index
11
+ collection.reject!{|t| t==Sitemap.lost_and_found} if Sitemap.lost_and_found.children.empty?
12
+ index! do |format|
13
+ format.json{render :json=>collection.as_json}
14
+ end
15
+ end
16
+
17
+ def parse_request_url
18
+ if params[:level1]
19
+ @sitemap = Sitemap.find_by_path(*[1,2,3,4].map{|t|params["level#{i}".to_sym]})
20
+ end
21
+ end
22
+
23
+ def create
24
+ @sitemap = new_resource
25
+ @sitemap.resource = @sitemap.resource_type.constantize.new
26
+ @sitemap.save
27
+ respond_with @sitemap do |format|
28
+ format.json {render :json=> json_obj.as_json}
29
+ end
30
+ end
31
+
32
+ def json_obj
33
+ {
34
+ :status => @sitemap.errors.empty? ? 1 : 0,
35
+ :errors => @sitemap.errors,
36
+ :id => @sitemap.id,
37
+ :resource_type => @sitemap.resource_type,
38
+ :resource_id => @sitemap.resource_id,
39
+ :menu_text => @sitemap.menu_text,
40
+ }
41
+ end
42
+
43
+ def show
44
+ show! do |format|
45
+ format.html{
46
+ if resource.resource.is_a? ExternalLink
47
+ redirect_to resource.resource.url
48
+ elsif resource.resource.is_a? Page
49
+
50
+ end
51
+ }
52
+ format.json{render :json=>resource.as_json}
53
+ format.js{redirect_to(url_for(resource.resource)+'.js')}
54
+ end
55
+ end
56
+
57
+ def destroy
58
+ if resource.parent == Sitemap.lost_and_found
59
+ resource.destroy
60
+ else
61
+ resource.parent = Sitemap.lost_and_found
62
+ resource.save
63
+ end
64
+ respond_with resource
65
+ end
66
+
67
+ def update
68
+ resource.parent = parent
69
+ update! do |format|
70
+ if params[:sitemap]["position"]
71
+ childrunz = Array.new(parent.children.sort{|t,u| t.position <=> u.position})
72
+ childrunz.delete(resource)
73
+ childrunz.insert(params[:sitemap]["position"].to_i, resource)
74
+ childrunz.each_with_index do |child, idx|
75
+ child.position = idx
76
+ child.save
77
+ end
78
+ end
79
+ format.json {render :json=> json_obj.as_json}
80
+ end
81
+ end
82
+
83
+ def sort
84
+ params[:formula_herb_children].each_with_index do |id, index|
85
+ FormulaHerb.update_all(['position=?', index+1], ['id=?', id])
86
+ end
87
+ render :nothing => true
88
+ end
89
+
90
+
91
+
92
+ #helper methods
93
+
94
+ def authorize_action!
95
+ authorize! :manage, Sitemap
96
+ end
97
+
98
+ def resource
99
+ @sitemap ||= Sitemap.find(params[:id]) if params[:id]
100
+ end
101
+
102
+ def collection
103
+ @sitemaps ||= SitemapArray.new(parent.children)
104
+ end
105
+
106
+ def new_resource
107
+ @sitemap ||= Sitemap.new(params[:sitemap])
108
+ end
109
+
110
+ def parent
111
+ unless @parent
112
+ if params[:parent_id]
113
+ @parent = Sitemap.find(params[:parent_id])
114
+ else
115
+ if params[:action] == "index"
116
+ @parent = Sitemap.root
117
+ else
118
+ @parent = resource.try(:parent)
119
+ end
120
+ end
121
+ end
122
+ @parent
123
+ end
124
+
125
+ private
126
+ def resource_would_be_orphaned?
127
+ resource.resource.sitemaps.size==1 &&
128
+ resource.resource.sitemaps[0] == resource
129
+ end
130
+
131
+ def resource_is_in_lost_and_found?
132
+ resource.parent==Sitemap.lost_and_found
133
+ end
134
+ end
135
+
@@ -1,12 +1,13 @@
1
1
  module ApplicationHelper
2
- def menu_item(name, href)
3
- content_tag(:li, content_tag(:a, content_tag(:span, name), :href=>href))
2
+ load_main_menu
3
+ def menu_node(name, url)
4
+ content_tag(:li, content_tag(:a, content_tag(:span, name, :class=>name.underscore.gsub(/ /, '_')), :href=>url))
4
5
  end
5
6
  def include_ckeditor
6
7
  content_for :head do
7
8
  javascript_include_tag('/ckeditor/ckeditor.js',
8
9
  '/ckeditor/adapters/jquery.js',
9
- "galleries/configure_ckeditor.js")
10
+ "galleries/configure_ckeditor.js", 'ckeditor_loaded')
10
11
  end
11
12
  end
12
13
  end
@@ -0,0 +1,2 @@
1
+ module ExternalLinksHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module FeedbacksHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module MenusHelper
2
+ end
@@ -0,0 +1,12 @@
1
+ module SitemapsHelper
2
+ def authenticity_token_json
3
+ unless protect_against_forgery?
4
+ ''
5
+ else
6
+ %("#{request_forgery_protection_token.to_s}" : "#{form_authenticity_token}",\n)
7
+ end
8
+ end
9
+
10
+
11
+ end
12
+
@@ -0,0 +1,10 @@
1
+ class FeedbackMailer < ActionMailer::Base
2
+ default :from => "mailer-no-reply@cagym.com"
3
+
4
+ def submit_feedback(feedback)
5
+ @feedback = feedback
6
+ #attachments["rails.png"] = File.read("#{Rails.root}/public/images/rails.png")
7
+ mail(:to => "hipkin@pacbell.net", :subject => %(CAGYM.com user feedback: #{feedback.subject}))
8
+ end
9
+ end
10
+
@@ -11,7 +11,7 @@ class Ability
11
11
 
12
12
  def initialize(user)
13
13
  user ||= User.nobody
14
- puts all_aces_for(user).map{|t| "#{t.resource_class_name} #{t.options.inspect}"}.join("\n")
14
+ puts all_aces_for(user).map{|t| "#{t.resource_type} #{t.options.inspect}"}.join("\n")
15
15
  self.class.initializers.each{|t| self.send(t, user)}
16
16
  all_aces_for(user).each do |ace|
17
17
  ace.configure(self)
@@ -36,6 +36,7 @@ class Ability
36
36
  can :manage, Blog, :user_id => user.id
37
37
  can :edit, Profile, :user_id => user.id
38
38
  cannot :read, User
39
+ can :manage, User, :id => user.id
39
40
  end
40
41
  end
41
42
  end
@@ -1,31 +1,33 @@
1
1
  class AccessControlEntry < ActiveRecord::Base
2
2
  belongs_to :user
3
3
  belongs_to :role
4
+ belongs_to :resource, :polymorphic=>true
5
+ validates :resource_type, :presence=>true
4
6
 
5
- scope :by_resource, lambda {|resource_class_name, resource_id|
6
- where(:resource_class_name=>resource_class_name).
7
+ scope :by_resource, lambda {|resource_type, resource_id|
8
+ where(:resource_type=>resource_type).
7
9
  where(:resource_id=>resource_id)
8
10
  }
9
11
  scope :by_role, lambda {|role_id|
10
12
  where(:role_id=>role_id)
11
13
  }
12
14
  scope :by_class, lambda {|class_name|
13
- where(:resource_class_name=>class_name)
15
+ where(:resource_type=>class_name)
14
16
  }
15
17
 
16
- def resource
17
- @resource ||= self.resource_class_name.constantize
18
- end
18
+ # def resource
19
+ # @resource ||= self.resource_type.constantize if self.resource_type
20
+ # end
19
21
 
20
- def resource=(res)
21
- @resource = res
22
- if res.type==Class
23
- self.resource_class_name = res.name
24
- else
25
- self.options[:id] = res.id
26
- self.resource_class_name = res.class.name
27
- end
28
- end
22
+ # def resource=(res)
23
+ # @resource = res
24
+ # if res.type==Class
25
+ # self.resource_type = res.name
26
+ # else
27
+ # self.options[:id] = res.id
28
+ # self.resource_type = res.class.name
29
+ # end
30
+ # end
29
31
 
30
32
  def options
31
33
  @options ||= (self.serialized_options ? eval(self.serialized_options) : {})
@@ -0,0 +1,4 @@
1
+ class ExternalLink < ActiveRecord::Base
2
+ has_many :sitemaps, :as=>:resource
3
+ end
4
+
@@ -0,0 +1,13 @@
1
+ class Feedback < ActiveRecord::Base
2
+ validates :email, :presence=>true, :email=>true
3
+ validates :name, :presence=>true, :length=>{:minimum=>6}
4
+ validates :phone, :presence=>true
5
+ validates :subject, :presence=>true
6
+
7
+
8
+
9
+ def self.jq_validation
10
+ JQueryValidator.new
11
+ end
12
+ end
13
+
data/app/models/image.rb CHANGED
@@ -5,6 +5,6 @@ class Image < ActiveRecord::Base
5
5
  :storage => :s3,
6
6
  :s3_credentials => "#{Rails.root}/config/amazon_s3.yml",
7
7
  :path => "/images/:user_email/:style/:filename",
8
- :styles => {:medium => "300x300>", :thumb => "100x100>" }
8
+ :styles => {:large=>"700x700>", :medium => "300x300>", :thumb => "100x100>" }
9
9
  end
10
10
 
@@ -0,0 +1,4 @@
1
+ class Menu < ActiveRecord::Base
2
+ has_many :sitemaps, :as=>:resource
3
+ end
4
+
data/app/models/page.rb CHANGED
@@ -1,10 +1,7 @@
1
1
  class Page < ActiveRecord::Base
2
2
  has_many :attachments
3
- validates :title, :presence=>true
4
- belongs_to :parent, :class_name=>'Page', :foreign_key=>'parent_id'
5
- has_many :children, :class_name=>'Page', :foreign_key=>'parent_id'
3
+ has_many :sitemaps, :as=>:resource
4
+ has_many :access_control_entries, :as=>:resource
6
5
  acts_as_taggable
7
-
8
- scope :orphans, where(:parent_id=>nil)
9
6
  end
10
7
 
@@ -0,0 +1,153 @@
1
+ class Sitemap < ActiveRecord::Base
2
+ has_many :children, :class_name=>'Sitemap', :foreign_key=>'parent_id', :dependent => :destroy do
3
+ def sorted
4
+ sort{|t, u| t.position <=> u.position}
5
+ end
6
+ end
7
+
8
+ belongs_to :parent, :class_name=>'Sitemap', :foreign_key=>'parent_id'
9
+ belongs_to :resource, :polymorphic => true
10
+ before_create :create_resource
11
+ before_destroy :on_before_destroy
12
+ after_save :reload_root
13
+ validates :resource, :presence=>true
14
+ accepts_nested_attributes_for :children
15
+
16
+
17
+ def reload_root
18
+ Sitemap.instance_variable_set('@_root', nil)
19
+ end
20
+
21
+ def on_before_destroy
22
+ resource.destroy if resource && resource.sitemaps.size==1
23
+ end
24
+
25
+ scope :orphans, where(:parent_id=>nil).where("menu_text <> 'root'")
26
+
27
+ def as_json(*a)
28
+ {
29
+ :data=>{
30
+ :title=>self.menu_text,
31
+ :icon=>icon_name,
32
+ },
33
+ :attr=>{
34
+ :id=>"node_#{id}",
35
+ :rel=>resource_type.underscore,
36
+ :data_menu_text => self.menu_text,
37
+ :data_resource_type => self.resource_type,
38
+ :data_resource_id => self.resource_id,
39
+ :data_id => self.id
40
+ },
41
+ :state=>treeview_state,
42
+ :children=> children.sort{|t,u| t.position <=> u.position}
43
+ }.as_json(*a)
44
+ end
45
+
46
+ def resource_attributes=(attrib={})
47
+ raise "Cant build resource without resource_type" if resource_type.empty?
48
+ resource = create_resource
49
+ resource.attributes = attrib
50
+ resource.save
51
+ end
52
+
53
+ def create_resource
54
+ resource ||= resource_type.constantize.new unless resource_type.nil?
55
+ end
56
+
57
+ def url
58
+ if self == Sitemap.main_menu
59
+ '/'
60
+ elsif resource.is_a? ExternalLink
61
+ resource.url
62
+ else
63
+ "#{(a=parent.url)=='/'?'':a}/#{menu_text.gsub(/ /, '_')}"
64
+ end
65
+ end
66
+
67
+
68
+ #########################################################################
69
+ #
70
+ # Class Methods
71
+ #
72
+ #########################################################################
73
+
74
+ def self.root
75
+ @_root ||= Sitemap.find_by_menu_text_and_parent_id('root', nil)
76
+ end
77
+
78
+ def self.lost_and_found
79
+ root.children.select{|t| t.menu_text=='Lost + Found'}[0]
80
+ end
81
+
82
+ def self.main_menu
83
+ root.children.select{|t| t.menu_text=='Main Menu'}[0]
84
+ end
85
+
86
+ def self.find_by_path(*path_args)
87
+ path = path_args.reverse
88
+ path.delete(nil)
89
+ obj = Sitemap.main_menu
90
+ while (path_piece=path.pop)
91
+ obj = obj.children.select{|t| t.menu_text.downcase==path_piece.downcase.gsub(/_/, ' ')}[0]
92
+ raise "Path error '#{path_piece}' in '#{path_args.join('/')}'" unless obj
93
+ end
94
+ return obj
95
+ end
96
+
97
+ #########################################################################
98
+ #
99
+ # Private Methods
100
+ #
101
+ #########################################################################
102
+
103
+ private
104
+ def build_resource(params={})
105
+ if resource_class
106
+ a = resource_class.new(params)
107
+ self.resource = a
108
+ a
109
+ end
110
+ end
111
+
112
+ def create_resource(params={})
113
+ if resource_class
114
+ a = resource_class.create(params)
115
+ self.resource = a
116
+ a
117
+ end
118
+ end
119
+
120
+ def new_model
121
+ resource_class.new(:sitemaps=>[self]) if resource_class
122
+ end
123
+
124
+ def resource_class
125
+ resource_type.camelize.constantize unless resource_type.empty?
126
+ end
127
+
128
+ def icon_name
129
+ case resource_type
130
+ when "Page"
131
+ "page"
132
+ when "ExternalLink"
133
+ "folder"
134
+ when "Menu"
135
+ "drive"
136
+ end
137
+ end
138
+
139
+ def treeview_state
140
+ if resource.is_a?(ExternalLink) || children.empty?
141
+ "leaf"
142
+ else
143
+ "open"
144
+ end
145
+ end
146
+ end
147
+
148
+ class SitemapArray < Array
149
+ def to_json
150
+ "[" + map(&:to_json).join(",") + "]"
151
+ end
152
+ end
153
+
data/app/models/user.rb CHANGED
@@ -1,11 +1,16 @@
1
1
  class User < ActiveRecord::Base
2
- after_create :create_profile
3
2
  belongs_to :role
4
3
  has_many :blogs, :dependent => :destroy
5
4
  has_one :profile, :dependent => :destroy
6
5
  has_many :galleries, :dependent => :destroy
7
6
  has_many :access_control_entries, :dependent=>:destroy
8
7
 
8
+ accepts_nested_attributes_for :profile
9
+
10
+ def initialize(*args)
11
+ super(*args)
12
+ build_profile unless profile
13
+ end
9
14
 
10
15
  def self.nobody
11
16
  User.new(:role=>Role.nobody)
@@ -16,6 +21,7 @@ class User < ActiveRecord::Base
16
21
  end
17
22
 
18
23
  def create_profile
24
+
19
25
  Profile.create(:user=>self) unless self.profile
20
26
  end
21
27
 
@@ -0,0 +1,22 @@
1
+ require 'mail'
2
+ class EmailValidator < ActiveModel::EachValidator
3
+ def validate_each(record,attribute,value)
4
+ begin
5
+ m = Mail::Address.new(value)
6
+ # We must check that value contains a domain and that value is an email address
7
+ r = m.domain && m.address == value
8
+ t = m.__send__(:tree)
9
+ # We need to dig into treetop
10
+ # A valid domain must have dot_atom_text elements size > 1
11
+ # user@localhost is excluded
12
+ # treetop must respond to domain
13
+ # We exclude valid email values like <user@localhost.com>
14
+ # Hence we use m.__send__(tree).domain
15
+ r &&= (t.domain.dot_atom_text.elements.size > 1)
16
+ rescue Exception => e
17
+ r = false
18
+ end
19
+ record.errors[attribute] << (options[:message] || "is invalid") unless r
20
+ end
21
+ end
22
+
@@ -22,7 +22,7 @@
22
22
  = f.text_field :verb, :class=>"verb"
23
23
  %li
24
24
  .name Resource
25
- = f.select :resource_class_name, [["Forum", "Forum"], ["Page", "Page"]]
25
+ = f.select :resource_type, [["Forum", "Forum"], ["Page", "Page"]]
26
26
  = f.hidden_field :resource_id
27
27
  %li
28
28
  .name options
@@ -1,4 +1,4 @@
1
- %h1 Listing Access Control Entries for
1
+ %h1 Listing Access Control Entries for #{parent.class.name} #{parent.id}
2
2
 
3
3
  %ul.listing#ace_listing
4
4
  - @access_control_entries.each do |ace|
@@ -8,7 +8,7 @@
8
8
  %li= ace.role.name if ace.role
9
9
  %li= ace.can ? "Can" : "Cannot"
10
10
  %li= ace.verb
11
- %li= ace.resource_class_name
11
+ %li= ace.resource_type
12
12
  %li= ace.options_str if ace.options_str
13
13
  - if can? :edit, ace
14
14
  %li= link_to "Edit", edit_access_control_entry_path(ace), :remote=>true
@@ -35,7 +35,7 @@
35
35
  = f.text_field :verb, :class=>"verb"
36
36
  %li
37
37
  .name Resource
38
- = f.select :resource_class_name, [["Forum", "Forum"], ["Page", "Page"]]
38
+ = f.select :resource_type, [["Forum", "Forum"], ["Page", "Page"]]
39
39
  = f.hidden_field :resource_id
40
40
  %li
41
41
  .name options