releaf 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +15 -12
  3. data/Rakefile +8 -0
  4. data/app/assets/javascripts/releaf/controllers/base.js +0 -40
  5. data/app/assets/javascripts/releaf/include/field.type_date_or_datetime_or_time.js +43 -0
  6. data/app/assets/javascripts/releaf/include/nested_fields.js +58 -65
  7. data/app/assets/javascripts/releaf/include/sortable.js +19 -17
  8. data/app/assets/stylesheets/releaf/controllers/releaf/content.css.erb +6 -0
  9. data/app/assets/stylesheets/releaf/include/field.css.erb +37 -13
  10. data/app/controllers/releaf/admins_controller.rb +13 -6
  11. data/app/controllers/releaf/base_application_controller.rb +4 -1
  12. data/app/controllers/releaf/base_controller.rb +415 -154
  13. data/app/controllers/releaf/content_controller.rb +62 -45
  14. data/app/controllers/releaf/roles_controller.rb +11 -9
  15. data/app/controllers/releaf/sessions_controller.rb +23 -1
  16. data/app/controllers/releaf/translations_controller.rb +21 -25
  17. data/app/helpers/releaf/admin_helper.rb +0 -20
  18. data/app/models/releaf/admin.rb +9 -0
  19. data/app/models/releaf/blank_node_base.rb +29 -0
  20. data/app/models/releaf/node.rb +6 -5
  21. data/app/models/releaf/node_base.rb +9 -3
  22. data/app/models/releaf/role.rb +9 -2
  23. data/app/views/layouts/releaf/admin.html.haml +12 -6
  24. data/app/views/layouts/releaf/devise.html.haml +32 -0
  25. data/app/views/releaf/aliases/{_edit.body.haml → _edit.body.html.haml} +0 -0
  26. data/app/views/releaf/aliases/{_edit.header.haml → _edit.header.html.haml} +1 -1
  27. data/app/views/releaf/aliases/_index.row.html.haml +5 -0
  28. data/app/views/releaf/aliases/{_secondary_panel.haml → _secondary_panel.html.haml} +0 -0
  29. data/app/views/releaf/base/_edit.body.html.haml +11 -0
  30. data/app/views/releaf/base/_edit.field.html.haml +23 -0
  31. data/app/views/releaf/base/{_edit.field.type_autocomplete.haml → _edit.field_type_autocomplete.html.haml} +1 -1
  32. data/app/views/releaf/base/{_edit.field.type_checkbox.haml → _edit.field_type_boolean.html.haml} +1 -1
  33. data/app/views/releaf/base/{_edit.field.type_date.haml → _edit.field_type_date.html.haml} +0 -0
  34. data/app/views/releaf/base/{_edit.field.type_datetime.haml → _edit.field_type_datetime.html.haml} +0 -0
  35. data/app/views/releaf/base/{_edit.field.type_delete_nested.haml → _edit.field_type_delete_nested.html.haml} +0 -0
  36. data/app/views/releaf/base/{_edit.field.type_file.haml → _edit.field_type_file.html.haml} +0 -0
  37. data/app/views/releaf/base/_edit.field_type_image.html.haml +12 -0
  38. data/app/views/releaf/base/_edit.field_type_item.html.haml +31 -0
  39. data/app/views/releaf/base/{_edit.field.type_link.haml → _edit.field_type_link.html.haml} +0 -0
  40. data/app/views/releaf/base/_edit.field_type_link_i18n.html.haml +26 -0
  41. data/app/views/releaf/base/{_edit.field.type_password.haml → _edit.field_type_password.html.haml} +0 -0
  42. data/app/views/releaf/base/{_edit.field.type_richtext.haml → _edit.field_type_richtext.html.haml} +0 -0
  43. data/app/views/releaf/base/{_edit.field.type_richtext_i18n.haml → _edit.field_type_richtext_i18n.html.haml} +0 -0
  44. data/app/views/releaf/base/{_edit.field.type_text.haml → _edit.field_type_text.html.haml} +0 -0
  45. data/app/views/releaf/base/{_edit.field.type_text_i18n.haml → _edit.field_type_text_i18n.html.haml} +0 -0
  46. data/app/views/releaf/base/{_edit.field.type_textarea.haml → _edit.field_type_textarea.html.haml} +0 -0
  47. data/app/views/releaf/base/{_edit.field.type_textarea_i18n.haml → _edit.field_type_textarea_i18n.html.haml} +0 -0
  48. data/app/views/releaf/base/{_edit.field.type_time.haml → _edit.field_type_time.html.haml} +0 -0
  49. data/app/views/releaf/base/_edit.fields.association.html.haml +48 -0
  50. data/app/views/releaf/base/_edit.fields.has_many_template.html.haml +15 -0
  51. data/app/views/releaf/base/_edit.fields.html.haml +20 -0
  52. data/app/views/releaf/base/{_edit.footer.haml → _edit.footer.html.haml} +2 -2
  53. data/app/views/releaf/base/_edit.form.html.haml +4 -0
  54. data/app/views/releaf/base/_edit.header.html.haml +3 -0
  55. data/app/views/releaf/base/{_index.body.haml → _index.body.html.haml} +2 -2
  56. data/app/views/releaf/base/_index.cell.html.haml +20 -0
  57. data/app/views/releaf/base/_index.footer.html.haml +28 -0
  58. data/app/views/releaf/base/_index.header.html.haml +4 -0
  59. data/app/views/releaf/base/_index.row.html.haml +6 -0
  60. data/app/views/releaf/base/_index.search.html.haml +5 -0
  61. data/app/views/releaf/base/_index.table.html.haml +24 -0
  62. data/app/views/releaf/base/_secondary_panel.html.haml +10 -0
  63. data/app/views/releaf/base/_show.body.html.haml +3 -0
  64. data/app/views/releaf/base/_show.field.html.haml +20 -0
  65. data/app/views/releaf/base/_show.field_type_date.html.haml +9 -0
  66. data/app/views/releaf/base/_show.field_type_date_time.html.haml +9 -0
  67. data/app/views/releaf/base/_show.field_type_email.html.haml +6 -0
  68. data/app/views/releaf/base/_show.field_type_file.html.haml +7 -0
  69. data/app/views/releaf/base/_show.field_type_image.html.haml +10 -0
  70. data/app/views/releaf/base/_show.field_type_item.html.haml +11 -0
  71. data/app/views/releaf/base/_show.field_type_link.html.haml +14 -0
  72. data/app/views/releaf/base/_show.field_type_password.html.haml +6 -0
  73. data/app/views/releaf/base/_show.field_type_richtext.html.haml +6 -0
  74. data/app/views/releaf/base/_show.field_type_text.html.haml +6 -0
  75. data/app/views/releaf/base/_show.field_type_textarea.html.haml +6 -0
  76. data/app/views/releaf/base/_show.field_type_time.html.haml +9 -0
  77. data/app/views/releaf/base/_show.field_type_url.html.haml +7 -0
  78. data/app/views/releaf/base/_show.fields.association.html.haml +36 -0
  79. data/app/views/releaf/base/_show.fields.has_many_template.html.haml +12 -0
  80. data/app/views/releaf/base/_show.fields.html.haml +17 -0
  81. data/app/views/releaf/base/{_show.footer.haml → _show.footer.html.haml} +6 -4
  82. data/app/views/releaf/base/_show.header.html.haml +3 -0
  83. data/app/views/releaf/base/confirm_destroy.html.haml +17 -0
  84. data/app/views/releaf/base/edit.html.haml +1 -0
  85. data/app/views/releaf/base/index.html.haml +3 -0
  86. data/app/views/releaf/base/new.html.haml +1 -0
  87. data/app/views/releaf/base/show.html.haml +3 -0
  88. data/app/views/releaf/content/{_edit.body.haml → _edit.body.html.haml} +7 -6
  89. data/app/views/releaf/content/_edit.content_fields.html.haml +11 -0
  90. data/app/views/releaf/content/_edit.fields.html.haml +17 -0
  91. data/app/views/releaf/content/{_edit.slug.haml → _edit.slug.html.haml} +0 -0
  92. data/app/views/releaf/content/{_get_content_form.haml → _get_content_form.html.haml} +2 -2
  93. data/app/views/releaf/content/{_secondary_panel.haml → _secondary_panel.html.haml} +0 -0
  94. data/app/views/releaf/content/{_tree_level.haml → _tree_level.html.haml} +0 -0
  95. data/app/views/releaf/content/{ajax.new.haml → ajax.new.html.haml} +0 -0
  96. data/app/views/releaf/content/{index.haml → index.html.haml} +0 -0
  97. data/app/views/releaf/roles/_edit.field.permissions.html.haml +5 -0
  98. data/app/views/releaf/roles/{_show.field.default.haml → _show.field.default.html.haml} +1 -1
  99. data/app/views/releaf/roles/{_show.field.permissions.haml → _show.field.permissions.html.haml} +2 -2
  100. data/app/views/releaf/translations/{_edit.body.haml → _edit.body.html.haml} +0 -0
  101. data/app/views/releaf/translations/{_edit.header.haml → _edit.header.html.haml} +1 -1
  102. data/app/views/releaf/translations/_index.row.html.haml +5 -0
  103. data/app/views/releaf/translations/{_secondary_panel.haml → _secondary_panel.html.haml} +0 -0
  104. data/lib/generators/releaf/templates/initializers/releaf.rb +0 -39
  105. data/lib/generators/releaf/templates/initializers/releaf_i18n.rb +17 -0
  106. data/lib/generators/releaf/templates/javascripts/3rd_party/jquery.jcarousel.js +1058 -0
  107. data/lib/generators/releaf/templates/javascripts/lib/init_jcarousel.js +40 -0
  108. data/lib/generators/releaf/templates/migrations/create_releaf_roles.rb +1 -0
  109. data/lib/generators/releaf/templates/migrations/create_releaf_tinymce_assets.rb +1 -0
  110. data/lib/generators/releaf/templates/models/admin_ability.rb +1 -1
  111. data/lib/i18n/backend/releaf.rb +5 -4
  112. data/lib/i18n/backend/releaf/translation.rb +5 -0
  113. data/lib/i18n/backend/releaf/translation_data.rb +7 -0
  114. data/lib/i18n/backend/releaf/translation_group.rb +4 -0
  115. data/lib/releaf.rb +4 -0
  116. data/lib/releaf/boolean_at.rb +77 -0
  117. data/lib/releaf/globalize3/fallbacks.rb +19 -0
  118. data/lib/releaf/resources.rb +101 -0
  119. data/lib/releaf/slug.rb +99 -60
  120. data/lib/releaf/version.rb +1 -1
  121. data/spec/spec_helper.rb +6 -0
  122. data/templates/releaf/installer.rb +15 -4
  123. metadata +275 -329
  124. data/app/views/releaf/aliases/_index.row.haml +0 -5
  125. data/app/views/releaf/base/_edit.body.haml +0 -19
  126. data/app/views/releaf/base/_edit.field.haml +0 -96
  127. data/app/views/releaf/base/_edit.field.type_image.haml +0 -14
  128. data/app/views/releaf/base/_edit.field.type_select.haml +0 -11
  129. data/app/views/releaf/base/_edit.form.haml +0 -4
  130. data/app/views/releaf/base/_edit.has_many_associations.haml +0 -45
  131. data/app/views/releaf/base/_edit.header.haml +0 -3
  132. data/app/views/releaf/base/_index.cell.haml +0 -19
  133. data/app/views/releaf/base/_index.footer.haml +0 -22
  134. data/app/views/releaf/base/_index.header.haml +0 -4
  135. data/app/views/releaf/base/_index.row.haml +0 -6
  136. data/app/views/releaf/base/_index.search.haml +0 -5
  137. data/app/views/releaf/base/_index.table.haml +0 -8
  138. data/app/views/releaf/base/_secondary_panel.haml +0 -9
  139. data/app/views/releaf/base/_show.body.haml +0 -7
  140. data/app/views/releaf/base/_show.field.haml +0 -78
  141. data/app/views/releaf/base/_show.field.type_html.haml +0 -1
  142. data/app/views/releaf/base/_show.header.haml +0 -3
  143. data/app/views/releaf/base/confirm_destroy.haml +0 -10
  144. data/app/views/releaf/base/edit.haml +0 -1
  145. data/app/views/releaf/base/index.haml +0 -3
  146. data/app/views/releaf/base/new.haml +0 -1
  147. data/app/views/releaf/base/show.haml +0 -3
  148. data/app/views/releaf/content/_edit.content_fields.haml +0 -19
  149. data/app/views/releaf/content/_show.field.content.haml +0 -11
  150. data/app/views/releaf/roles/_edit.field.admins.haml +0 -0
  151. data/app/views/releaf/roles/_edit.field.permissions.haml +0 -5
  152. data/app/views/releaf/translations/_index.row.haml +0 -5
  153. data/spec/dummy/README.rdoc +0 -261
  154. data/spec/dummy/Rakefile +0 -7
  155. data/spec/dummy/app/assets/images/rails.png +0 -0
  156. data/spec/dummy/app/assets/javascripts/application.js +0 -15
  157. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  158. data/spec/dummy/app/controllers/application_controller.rb +0 -3
  159. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  160. data/spec/dummy/app/models/admin_ability.rb +0 -51
  161. data/spec/dummy/app/models/settings.rb +0 -2
  162. data/spec/dummy/app/views/layouts/application.html.haml +0 -10
  163. data/spec/dummy/config.ru +0 -4
  164. data/spec/dummy/config/application.rb +0 -68
  165. data/spec/dummy/config/boot.rb +0 -6
  166. data/spec/dummy/config/common_fields.yml.example +0 -17
  167. data/spec/dummy/config/database.yml +0 -42
  168. data/spec/dummy/config/environment.rb +0 -5
  169. data/spec/dummy/config/environments/development.rb +0 -37
  170. data/spec/dummy/config/environments/production.rb +0 -67
  171. data/spec/dummy/config/environments/test.rb +0 -37
  172. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  173. data/spec/dummy/config/initializers/devise.rb +0 -232
  174. data/spec/dummy/config/initializers/dragonfly.rb +0 -1
  175. data/spec/dummy/config/initializers/inflections.rb +0 -15
  176. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  177. data/spec/dummy/config/initializers/releaf.rb +0 -59
  178. data/spec/dummy/config/initializers/releaf_i18n.rb +0 -8
  179. data/spec/dummy/config/initializers/releaf_store_current_template.rb +0 -25
  180. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  181. data/spec/dummy/config/initializers/session_store.rb +0 -8
  182. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  183. data/spec/dummy/config/locales/devise.en.yml +0 -58
  184. data/spec/dummy/config/locales/en.yml +0 -5
  185. data/spec/dummy/config/routes.rb +0 -11
  186. data/spec/dummy/db/migrate/20130204164516_create_settings.rb +0 -17
  187. data/spec/dummy/db/migrate/20130204164523_create_releaf_nodes.rb +0 -25
  188. data/spec/dummy/db/migrate/20130204164524_create_releaf_roles.rb +0 -11
  189. data/spec/dummy/db/migrate/20130204164525_create_releaf_translations.rb +0 -31
  190. data/spec/dummy/db/migrate/20130204164526_create_releaf_admins.rb +0 -53
  191. data/spec/dummy/db/schema.rb +0 -112
  192. data/spec/dummy/db/seeds.rb +0 -64
  193. data/spec/dummy/doc/README_FOR_APP +0 -2
  194. data/spec/dummy/log/development.log +0 -74
  195. data/spec/dummy/log/test.log +0 -129
  196. data/spec/dummy/public/404.html +0 -26
  197. data/spec/dummy/public/422.html +0 -26
  198. data/spec/dummy/public/500.html +0 -25
  199. data/spec/dummy/public/favicon.ico +0 -0
  200. data/spec/dummy/script/rails +0 -6
  201. data/spec/dummy/tmp/cache/9C5/660/settings%3Ai18n_updated_at +0 -1
@@ -1,14 +1,20 @@
1
1
  module Releaf
2
2
  class ContentController < BaseController
3
+ helper_method :content_fields_to_display
3
4
 
4
- def columns( view = nil )
5
- if view == 'show'
6
- return %w[name parent_id visible protected content]
5
+ def content_fields_to_display obj_class
6
+ if obj_class.respond_to? :releaf_fields_to_display
7
+ obj_class.releaf_fields_to_display params[:action]
7
8
  else
8
- return super
9
+ obj_class.column_names - %w[id created_at updated_at position]
9
10
  end
10
11
  end
11
12
 
13
+ def fields_to_display
14
+ return super unless params[:action] == 'show'
15
+ return %w[name parent_id visible protected content]
16
+ end
17
+
12
18
  def build_secondary_panel_variables
13
19
  @nodes = Node.roots
14
20
  super
@@ -24,12 +30,11 @@ module Releaf
24
30
  def create
25
31
  content_type = _node_params[:content_type].constantize
26
32
  authorize! :create, content_type
27
- @item = current_object_class.new(_node_params)
28
- @item.assign_attributes(_node_common_fields_params)
33
+ @resource = resource_class.new(_node_params)
29
34
 
30
35
  respond_to do |format|
31
- if @item.save
32
- format.html { redirect_to url_for(:action => "index", :controller => 'content')}
36
+ if @resource.save
37
+ format.html { redirect_to url_for(:action => "edit", :controller => 'content', :id => @resource.id)}
33
38
  else
34
39
  form_extras
35
40
  @order_nodes = Node.where(:parent_id => (params[:parent_id] ? params[:parent_id] : nil))
@@ -39,40 +44,39 @@ module Releaf
39
44
  end
40
45
 
41
46
  def generate_url
42
- tmp_item = nil
47
+ tmp_resource = nil
43
48
 
44
49
  if params[:id]
45
- tmp_item = Node.find(params[:id])
50
+ tmp_resource = Node.find(params[:id])
46
51
  elsif params[:parent_id].blank? == false
47
52
  parent = Node.find(params[:parent_id])
48
- tmp_item = parent.children.new
53
+ tmp_resource = parent.children.new
49
54
  else
50
- tmp_item = Node.new
55
+ tmp_resource = Node.new
51
56
  end
52
57
 
53
- tmp_item.name = params[:name]
54
- tmp_item.slug = nil
58
+ tmp_resource.name = params[:name]
59
+ tmp_resource.slug = nil
55
60
  # FIXME calling private method
56
- tmp_item.send(:ensure_unique_url)
61
+ tmp_resource.send(:ensure_unique_url)
57
62
 
58
63
  respond_to do |format|
59
- format.js { render :text => tmp_item.slug }
64
+ format.js { render :text => tmp_resource.slug }
60
65
  end
61
66
  end
62
67
 
63
68
  def update
64
- @item = current_object_class.find(params[:id])
65
- authorize! :edit, @item
69
+ @resource = resource_class.find(params[:id])
70
+ authorize! :edit, @resource
66
71
 
67
72
  form_extras
68
- @order_nodes = Node.where(:parent_id => (@item.parent_id ? @item.parent_id : nil)).where('id != :id', :id => params[:id])
73
+ @order_nodes = Node.where(:parent_id => (@resource.parent_id ? @resource.parent_id : nil)).where('id != :id', :id => params[:id])
69
74
 
70
- @item.assign_attributes(_node_params)
71
- @item.assign_attributes(_node_common_fields_params)
75
+ @resource.assign_attributes(_node_params)
72
76
 
73
77
 
74
78
  respond_to do |format|
75
- if @item.save
79
+ if @resource.save
76
80
  format.html { redirect_to url_for(:action => "edit") }
77
81
  else
78
82
  format.html { render action: "edit" }
@@ -81,12 +85,12 @@ module Releaf
81
85
  end
82
86
 
83
87
  def new
84
- authorize! :create, current_object_class
88
+ authorize! :create, resource_class
85
89
  unless params[:ajax] == '1'
86
90
  super
87
91
  @order_nodes = Node.where(:parent_id => (params[:parent_id] ? params[:parent_id] : nil))
88
92
  @position = 1
89
- @item.parent_id = params[:parent_id]
93
+ @resource.parent_id = params[:parent_id]
90
94
  form_extras
91
95
  else
92
96
  Rails.application.eager_load!
@@ -97,10 +101,10 @@ module Releaf
97
101
 
98
102
  def edit
99
103
  super
100
- @order_nodes = Node.where(:parent_id => (@item.parent_id ? @item.parent_id : nil)).where('id != :id', :id => params[:id])
104
+ @order_nodes = Node.where(:parent_id => (@resource.parent_id ? @resource.parent_id : nil)).where('id != :id', :id => params[:id])
101
105
 
102
- if @item.higher_item
103
- @position = @item.higher_item.position
106
+ if @resource.higher_item
107
+ @position = @resource.position
104
108
  else
105
109
  @position = 1
106
110
  end
@@ -108,13 +112,18 @@ module Releaf
108
112
  form_extras
109
113
  end
110
114
 
115
+ def setup
116
+ super
117
+ @features[:show] = false
118
+ end
119
+
111
120
  def get_content_form
112
121
  Rails.application.eager_load!
113
- raise ArgumentError unless NodeBase.node_classes.map { |nc| nc.name }.include? params[:content_type]
114
- @node = current_object_class.find(params[:id])
115
- authorize! :edit, @item
122
+ raise ArgumentError unless content_type_class_names.include? params[:content_type]
123
+ @node = resource_class.find(params[:id])
124
+ authorize! :edit, @resource
116
125
 
117
- @item = params[:content_type].constantize.new
126
+ @resource = params[:content_type].constantize.new
118
127
 
119
128
  respond_to do |format|
120
129
  format.html { render :partial => 'get_content_form', :layout => false }
@@ -122,25 +131,26 @@ module Releaf
122
131
 
123
132
  end
124
133
 
125
-
126
- def current_object_class
134
+ def resource_class
127
135
  Node
128
136
  end
129
137
 
130
138
  protected
131
139
 
132
- def _node_common_fields_params
133
- allowed_params = (@item.common_field_names).map { |f| f.sub(/_uid$/, '') }
134
- params.require(current_object_class_name).permit(*allowed_params)
135
- end
136
-
137
140
  def _node_params
138
- allowed_params = (%w[parent_id name content_type slug position data visible protected content_object_attributes]).map { |f| f.sub(/_uid$/, '') }
139
- params.require(current_object_class_name).permit(*allowed_params)
141
+ params.require(:resource).permit!
140
142
  end
141
143
 
142
144
  private
143
145
 
146
+ def content_type_class_names
147
+ content_type_classes.map { |nc| nc.name }.sort
148
+ end
149
+
150
+ def content_type_classes
151
+ NodeBase.node_classes + BlankNodeBase.node_classes
152
+ end
153
+
144
154
  def form_extras
145
155
  Rails.application.eager_load!
146
156
  get_base_models
@@ -148,18 +158,25 @@ module Releaf
148
158
  new_content_if_needed
149
159
  end
150
160
 
151
- def node_params(action)
152
- # make sure none of actions, that are defined by BaseController can update item
161
+ def resource_params
153
162
  []
154
163
  end
155
164
 
156
165
  def new_content_if_needed
157
- return if @item.content
158
- @item.content = @item.content_type.constantize.new if get_base_models.map { |bm| bm.name }.include? @item.content_type
166
+ return if @resource.content
167
+ if params[:content_type]
168
+ if get_base_models.map { |bm| bm.name }.include? params[:content_type]
169
+ @resource.content_type = params[:content_type]
170
+ content_class = @resource.content_type.constantize
171
+ if content_class.node_type == 'Releaf::NodeBase'
172
+ @resource.content = @resource.content_type.constantize.new
173
+ end
174
+ end
175
+ end
159
176
  end
160
177
 
161
178
  def get_base_models
162
- @base_models ||= NodeBase.node_classes
179
+ @base_models ||= content_type_classes
163
180
  end
164
181
 
165
182
  end
@@ -1,25 +1,27 @@
1
1
  module Releaf
2
2
  class RolesController < BaseController
3
3
 
4
- def current_object_class
4
+ def resource_class
5
5
  Releaf::Role
6
6
  end
7
7
 
8
- def columns( view = nil )
9
- fields = (super(view) - ['default']).insert(1, 'default')
10
- if view == 'index'
11
- fields - ['permissions'] + ['admin_permission']
8
+ def fields_to_display
9
+ case params[:action].to_sym
10
+ when :index
11
+ %w[name default_controller default]
12
+ when :create, :edit, :new, :update, :show
13
+ %w[name default default_controller permissions]
12
14
  else
13
- fields
15
+ []
14
16
  end
15
17
  end
16
18
 
17
19
  protected
18
20
 
19
- def role_params( action )
20
- return [] unless [:update, :create].include? action
21
+ def resource_params
22
+ return [] unless %w[update create].include? params[:action]
21
23
 
22
- fields = ['name', 'default']
24
+ fields = ['name', 'default', 'default_controller']
23
25
  AdminAbility::PERMISSIONS.each do |permission|
24
26
  if permission.is_a? String
25
27
  fields.push "#{permission}_permission"
@@ -1,5 +1,27 @@
1
1
  module Releaf
2
2
  class SessionsController < Devise::SessionsController
3
- layout "releaf/admin"
3
+ layout "releaf/devise"
4
+
5
+ def after_sign_in_path_for(resource)
6
+ controller_name = resource.role.default_controller
7
+
8
+ if controller_name
9
+ if controller_name == 'content'
10
+ default_path = releaf_nodes_path
11
+ elsif controller_name == 'translations'
12
+ default_path = releaf_translation_groups_path
13
+ else
14
+ default_path = send("admin_#{controller_name}_path")
15
+ end
16
+ else
17
+ default_path = releaf_nodes_path
18
+ end
19
+
20
+ return default_path
21
+ end
22
+
23
+ def full_controller_name
24
+ self.class.name.sub(/Controller$/, '').underscore
25
+ end
4
26
  end
5
27
  end
@@ -1,14 +1,7 @@
1
1
  module Releaf
2
2
  class TranslationsController < BaseController
3
3
 
4
- def setup
5
- super
6
- @object_class = I18n::Backend::Releaf::TranslationGroup
7
- @features[:show] = false
8
- @continuous_scroll = true
9
- end
10
-
11
- def current_object_class
4
+ def resource_class
12
5
  @object_class
13
6
  end
14
7
 
@@ -23,7 +16,7 @@ module Releaf
23
16
 
24
17
  def index
25
18
  authorize! :manage, I18n::Backend::Releaf::Translation
26
- @list = @object_class = I18n::Backend::Releaf::Translation.includes(:translation_data).filter(:search => params[:search])
19
+ @resources = @object_class = I18n::Backend::Releaf::Translation.includes(:translation_data).filter(:search => params[:search])
27
20
  if !params[:ajax].blank?
28
21
  render :layout => false
29
22
  end
@@ -31,23 +24,18 @@ module Releaf
31
24
 
32
25
  def edit
33
26
  authorize! :manage, I18n::Backend::Releaf::Translation
34
- @item = current_object_class.find(params[:id])
35
- end
36
-
37
- def show
38
- authorize! :manage, I18n::Backend::Releaf::Translation
39
- redirect_to url_for( :action => "edit", :id => params[:id] )
27
+ @resource = resource_class.find(params[:id])
40
28
  end
41
29
 
42
30
  def create
43
31
  authorize! :manage, I18n::Backend::Releaf::Translation
44
- @item = current_object_class.new(item_params)
32
+ @resource = resource_class.new(resource_params)
45
33
 
46
34
  respond_to do |format|
47
- if @item.save
35
+ if @resource.save
48
36
  update_translations
49
37
  Settings.i18n_updated_at = Time.now
50
- format.html { redirect_to url_for(:action => "edit", :id => @item.id) }
38
+ format.html { redirect_to url_for(:action => "edit", :id => @resource.id) }
51
39
  else
52
40
  format.html { render :action => "new" }
53
41
  end
@@ -56,22 +44,30 @@ module Releaf
56
44
 
57
45
  def update
58
46
  authorize! :manage, I18n::Backend::Releaf::Translation
59
- @item = current_object_class.find(params[:id])
47
+ @resource = resource_class.find(params[:id])
60
48
 
61
49
  unless params[:translations].blank?
62
50
  ids_to_keep = update_translations
63
- @item.translations.where('id NOT IN (?)', ids_to_keep).destroy_all
51
+ @resource.translations.where('id NOT IN (?)', ids_to_keep).destroy_all
64
52
  else
65
- @item.translations.destroy_all
53
+ @resource.translations.destroy_all
66
54
  end
67
55
  Settings.i18n_updated_at = Time.now
68
56
 
69
57
 
70
58
  respond_to do |format|
71
- format.html { redirect_to url_for(:action => "edit", :id => @item.id) }
59
+ format.html { redirect_to url_for(:action => "edit", :id => @resource.id) }
72
60
  end
73
61
  end
74
62
 
63
+ protected
64
+
65
+ def setup
66
+ super
67
+ @object_class = I18n::Backend::Releaf::TranslationGroup
68
+ @features[:show] = false
69
+ @continuous_scroll = true
70
+ end
75
71
 
76
72
  private
77
73
 
@@ -86,7 +82,7 @@ module Releaf
86
82
  if id =~ /\A\d+\z/
87
83
  translation = I18n::Backend::Releaf::Translation.find(id)
88
84
  else
89
- translation = @item.translations.new
85
+ translation = @resource.translations.new
90
86
  end
91
87
 
92
88
  translation.key = params[:translation_group][:scope] + '.' + t['key']
@@ -113,8 +109,8 @@ module Releaf
113
109
  return ids_to_keep
114
110
  end
115
111
 
116
- def item_params
117
- params.require(current_object_class_name).permit(:scope)
112
+ def resource_params
113
+ params.require(:resource).permit(:scope)
118
114
  end
119
115
 
120
116
  end
@@ -1,26 +1,6 @@
1
1
  module Releaf
2
2
  module AdminHelper
3
3
 
4
- def polymorphic_association_names obj
5
- poly_asoc = obj.class.reflect_on_all_associations.map { |r| r.options[:polymorphic] ? r.name : nil }
6
- poly_asoc.delete(nil)
7
- poly_asoc.map { |pa| pa.to_s }
8
- end
9
-
10
- def has_many_association_names obj
11
- reflect_all_asoc = obj.reflect_on_all_associations(:has_many)
12
- has_many_asoc_names = reflect_all_asoc.map { |asoc| asoc.name }
13
-
14
- reflect_all_asoc.each do |asoc|
15
- next unless asoc.options.has_key?(:through)
16
- has_many_asoc_names.delete(asoc.name)
17
- end
18
-
19
- # don't show translations associaton which is created by globalize3
20
- has_many_asoc_names - [:translations]
21
- end
22
-
23
-
24
4
  def is_this_main_menu_item_active? releaf_main_menu_item
25
5
  _check_if_this_is_valid_releaf_main_menu_item releaf_main_menu_item
26
6
 
@@ -14,6 +14,15 @@ module Releaf
14
14
 
15
15
  image_accessor :avatar
16
16
 
17
+ attr_accessible \
18
+ :avater,
19
+ :name,
20
+ :surname,
21
+ :role_id,
22
+ :email,
23
+ :password,
24
+ :password_confirmation
25
+
17
26
  scope :filter, lambda {|params|
18
27
  fields = []
19
28
  values = {}
@@ -0,0 +1,29 @@
1
+ module Releaf
2
+ class BlankNodeBase
3
+ # returns only bottom level, not /^Releaf::/ subclasses
4
+ def self.node_classes
5
+ return _node_classes(self).reject { |n| n.name =~ /^Releaf::/ }
6
+ end
7
+
8
+ def self.releaf_fields_to_display action
9
+ []
10
+ end
11
+
12
+ def self.node_type
13
+ "Releaf::BlankNodeBase"
14
+ end
15
+
16
+ private
17
+
18
+ def self._node_classes(klass)
19
+ classes = [klass]
20
+
21
+ klass.subclasses.each do |sublcass|
22
+ classes += _node_classes(sublcass)
23
+ end
24
+
25
+ return classes
26
+ end
27
+
28
+ end
29
+ end