alchemy_cms 2.2.4 → 2.3.rc5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) hide show
  1. data/.gitignore +1 -1
  2. data/.travis.yml +3 -4
  3. data/Gemfile +1 -0
  4. data/README.md +10 -6
  5. data/alchemy_cms.gemspec +5 -2
  6. data/app/assets/images/alchemy/icons.png +0 -0
  7. data/app/assets/images/sassy-ie-overlay.png +0 -0
  8. data/app/assets/javascripts/alchemy/alchemy.base.js +50 -59
  9. data/app/assets/javascripts/alchemy/alchemy.buttons.js +14 -4
  10. data/app/assets/javascripts/alchemy/alchemy.datepicker.js +8 -2
  11. data/app/assets/javascripts/alchemy/alchemy.elements_window.js +11 -3
  12. data/app/assets/javascripts/alchemy/alchemy.gui.js.coffee +1 -1
  13. data/app/assets/javascripts/alchemy/alchemy.link_overlay.js.coffee +14 -1
  14. data/app/assets/javascripts/alchemy/alchemy.preview.js +1 -1
  15. data/app/assets/javascripts/alchemy/alchemy.preview_window.js +12 -4
  16. data/app/assets/javascripts/alchemy/alchemy.uploader.js +4 -1
  17. data/app/assets/javascripts/alchemy/alchemy.windows.js +18 -8
  18. data/app/assets/stylesheets/alchemy/_defaults.scss +84 -120
  19. data/app/assets/stylesheets/alchemy/alchemy.css +2 -2
  20. data/app/assets/stylesheets/alchemy/archive.css.scss +288 -0
  21. data/app/assets/stylesheets/alchemy/base.css.scss +95 -390
  22. data/app/assets/stylesheets/alchemy/dashboard.css.scss +4 -4
  23. data/app/assets/stylesheets/alchemy/elements.css.scss +83 -118
  24. data/app/assets/stylesheets/alchemy/flash.css.scss +1 -1
  25. data/app/assets/stylesheets/alchemy/form_elements.css.scss +528 -0
  26. data/app/assets/stylesheets/alchemy/frame.css.scss +13 -39
  27. data/app/assets/stylesheets/alchemy/icons.css.scss +217 -228
  28. data/app/assets/stylesheets/alchemy/jquery-ui.alchemy.css.scss +48 -50
  29. data/app/assets/stylesheets/alchemy/jquery.Jcrop.css.scss +1 -1
  30. data/app/assets/stylesheets/alchemy/login.css.scss +1 -5
  31. data/app/assets/stylesheets/alchemy/menubar.css.scss +19 -29
  32. data/app/assets/stylesheets/alchemy/pagination.css.scss +3 -4
  33. data/app/assets/stylesheets/alchemy/sitemap.css.scss +81 -81
  34. data/app/assets/stylesheets/alchemy/tables.css.scss +63 -57
  35. data/app/assets/stylesheets/alchemy/tinymce_dialog.css.scss +57 -57
  36. data/app/assets/stylesheets/alchemy/upload.css.scss +6 -6
  37. data/app/assets/stylesheets/tiny_mce/plugins/inlinepopups/skins/alchemy/window.css.scss +6 -10
  38. data/app/controllers/alchemy/admin/attachments_controller.rb +5 -4
  39. data/app/controllers/alchemy/admin/base_controller.rb +1 -9
  40. data/app/controllers/alchemy/admin/contents_controller.rb +4 -6
  41. data/app/controllers/alchemy/admin/elements_controller.rb +2 -2
  42. data/app/controllers/alchemy/admin/pages_controller.rb +2 -2
  43. data/app/controllers/alchemy/admin/pictures_controller.rb +74 -15
  44. data/app/controllers/alchemy/attachments_controller.rb +8 -2
  45. data/app/controllers/alchemy/base_controller.rb +47 -5
  46. data/app/controllers/alchemy/elements_controller.rb +1 -1
  47. data/app/controllers/alchemy/messages_controller.rb +12 -12
  48. data/app/controllers/alchemy/pages_controller.rb +5 -1
  49. data/app/controllers/alchemy/pictures_controller.rb +9 -4
  50. data/app/controllers/alchemy/user_sessions_controller.rb +2 -4
  51. data/app/helpers/alchemy/admin/base_helper.rb +98 -19
  52. data/app/helpers/alchemy/admin/contents_helper.rb +2 -2
  53. data/app/helpers/alchemy/admin/elements_helper.rb +2 -3
  54. data/app/helpers/alchemy/base_helper.rb +6 -5
  55. data/app/helpers/alchemy/elements_helper.rb +2 -2
  56. data/app/helpers/alchemy/essences_helper.rb +4 -5
  57. data/app/helpers/alchemy/pages_helper.rb +15 -79
  58. data/app/helpers/alchemy/url_helper.rb +67 -0
  59. data/app/mailers/alchemy/messages.rb +1 -1
  60. data/app/mailers/alchemy/notifications.rb +1 -1
  61. data/app/models/alchemy/attachment.rb +11 -2
  62. data/app/models/alchemy/cell.rb +20 -10
  63. data/app/models/alchemy/content.rb +4 -3
  64. data/app/models/alchemy/element.rb +170 -178
  65. data/app/models/alchemy/language/code.rb +4 -1
  66. data/app/models/alchemy/message.rb +19 -3
  67. data/app/models/alchemy/page.rb +45 -40
  68. data/app/models/alchemy/picture.rb +24 -2
  69. data/app/models/alchemy/user.rb +2 -3
  70. data/app/views/alchemy/admin/attachments/_archive_overlay.html.erb +12 -12
  71. data/app/views/alchemy/admin/attachments/_attachment.html.erb +1 -1
  72. data/app/views/alchemy/admin/attachments/create.js.erb +1 -0
  73. data/app/views/alchemy/admin/attachments/edit.html.erb +9 -3
  74. data/app/views/alchemy/admin/attachments/index.html.erb +3 -2
  75. data/app/views/alchemy/admin/contents/_missing.html.erb +1 -1
  76. data/app/views/alchemy/admin/contents/create.js.erb +54 -0
  77. data/app/views/alchemy/admin/contents/new.html.erb +9 -4
  78. data/app/views/alchemy/admin/elements/{_add_content.html.erb → _add_picture.html.erb} +4 -4
  79. data/app/views/alchemy/admin/elements/_elements_select.html.erb +2 -1
  80. data/app/views/alchemy/admin/elements/_new_element_form.html.erb +1 -1
  81. data/app/views/alchemy/admin/elements/{_picture_editor.html.erb → _picture_gallery_editor.html.erb} +7 -11
  82. data/app/views/alchemy/admin/elements/fold.js.erb +46 -0
  83. data/app/views/alchemy/admin/elements/index.html.erb +24 -24
  84. data/app/views/alchemy/admin/elements/list.js.erb +11 -9
  85. data/app/views/alchemy/admin/essence_files/assign.js.erb +3 -1
  86. data/app/views/alchemy/admin/essence_pictures/destroy.js.erb +28 -0
  87. data/app/views/alchemy/admin/pages/_contactform_links.html.erb +8 -6
  88. data/app/views/alchemy/admin/pages/_external_link.html.erb +11 -9
  89. data/app/views/alchemy/admin/pages/_file_link.html.erb +10 -8
  90. data/app/views/alchemy/admin/pages/_internal_link.html.erb +14 -10
  91. data/app/views/alchemy/admin/pages/_new_page_form.html.erb +1 -1
  92. data/app/views/alchemy/admin/pages/_page.html.erb +1 -1
  93. data/app/views/alchemy/admin/pages/_page_for_links.html.erb +32 -21
  94. data/app/views/alchemy/admin/pages/configure.html.erb +2 -2
  95. data/app/views/alchemy/admin/pages/configure_external.html.erb +13 -13
  96. data/app/views/alchemy/admin/pages/edit.html.erb +2 -2
  97. data/app/views/alchemy/admin/pages/index.html.erb +26 -24
  98. data/app/views/alchemy/admin/pages/link.html.erb +2 -5
  99. data/app/views/alchemy/admin/partials/_upload_form.html.erb +28 -12
  100. data/app/views/alchemy/admin/pictures/_archive.html.erb +54 -0
  101. data/app/views/alchemy/admin/pictures/_archive_overlay.html.erb +10 -7
  102. data/app/views/alchemy/admin/pictures/_filter_and_size_bar.html.erb +21 -22
  103. data/app/views/alchemy/admin/pictures/_filter_bar.html.erb +31 -0
  104. data/app/views/alchemy/admin/pictures/_overlay_picture_list.html.erb +9 -0
  105. data/app/views/alchemy/admin/pictures/_picture.html.erb +36 -6
  106. data/app/views/alchemy/admin/pictures/_tag_list.html.erb +27 -0
  107. data/app/views/alchemy/admin/pictures/archive_overlay.js.erb +3 -1
  108. data/app/views/alchemy/admin/pictures/create.js.erb +4 -5
  109. data/app/views/alchemy/admin/pictures/edit.html.erb +26 -0
  110. data/app/views/alchemy/admin/pictures/edit_multiple.html.erb +39 -0
  111. data/app/views/alchemy/admin/pictures/index.html.erb +81 -70
  112. data/app/views/alchemy/admin/pictures/index.js.erb +3 -0
  113. data/app/views/alchemy/admin/pictures/new.html.erb +1 -0
  114. data/app/views/alchemy/admin/resources/index.html.erb +3 -1
  115. data/app/views/alchemy/admin/users/_table.html.erb +1 -1
  116. data/app/views/alchemy/admin/users/index.html.erb +27 -23
  117. data/app/views/alchemy/elements/_article_editor.html.erb +7 -2
  118. data/app/views/alchemy/elements/_bild_editor.html.erb +1 -1
  119. data/app/views/alchemy/elements/_bild_text_editor.html.erb +6 -1
  120. data/app/views/alchemy/elements/_bild_text_view.html.erb +3 -3
  121. data/app/views/alchemy/elements/_image_mosaic_editor.html.erb +1 -1
  122. data/app/views/alchemy/elements/_image_mosaic_view.html.erb +2 -2
  123. data/app/views/alchemy/elements/_intro_image_text_view.html.erb +4 -4
  124. data/app/views/alchemy/elements/_searchresult_editor.html.erb +4 -1
  125. data/app/views/alchemy/essences/_essence_boolean_editor.html.erb +1 -1
  126. data/app/views/alchemy/essences/_essence_picture_editor.html.erb +2 -3
  127. data/app/views/alchemy/essences/_essence_picture_tools.html.erb +1 -1
  128. data/app/views/alchemy/search/_form.html.erb +8 -0
  129. data/app/views/alchemy/search/_result.html.erb +3 -2
  130. data/app/views/alchemy/search/_results.html.erb +28 -0
  131. data/app/views/alchemy/user_sessions/leave.html.erb +4 -4
  132. data/app/views/alchemy/user_sessions/login.html.erb +1 -2
  133. data/app/views/layouts/alchemy/admin.html.erb +30 -10
  134. data/app/views/layouts/alchemy/login.html.erb +2 -39
  135. data/config/alchemy/elements.yml +1 -2
  136. data/config/alchemy/page_layouts.yml +8 -5
  137. data/config/authorization_rules.rb +27 -18
  138. data/config/initializers/localeapp.rb +9 -0
  139. data/config/locales/alchemy.de.yml +93 -56
  140. data/config/locales/alchemy.en.yml +73 -50
  141. data/config/routes.rb +3 -1
  142. data/db/migrate/20120704181529_add_upload_hash_to_alchemy_picture.rb +5 -0
  143. data/db/migrate/20120705214247_acts_as_taggable_on_migration.rb +28 -0
  144. data/db/migrate/20120728185830_add_cached_tag_list_to_alchemy_pictures.rb +5 -0
  145. data/db/migrate/20120831135441_set_alchemy_languages_country_code_default_to_empty_string.rb +9 -0
  146. data/lib/alchemy/capistrano.rb +2 -2
  147. data/lib/alchemy/essence.rb +14 -0
  148. data/lib/alchemy/page_layout.rb +0 -6
  149. data/lib/alchemy/resource.rb +9 -15
  150. data/lib/alchemy/upgrader.rb +18 -3
  151. data/lib/alchemy/version.rb +5 -1
  152. data/lib/alchemy_cms.rb +4 -1
  153. data/lib/rails/generators/alchemy/deploy_script/deploy_script_generator.rb +16 -6
  154. data/lib/rails/generators/alchemy/deploy_script/templates/deploy.rb.tt +17 -3
  155. data/lib/rails/generators/alchemy/elements/elements_generator.rb +6 -1
  156. data/lib/rails/generators/alchemy/elements/templates/editor.html.erb +10 -1
  157. data/lib/rails/generators/alchemy/elements/templates/view.html.erb +17 -18
  158. data/lib/rails/generators/alchemy/scaffold/files/pages.html.erb +4 -2
  159. data/lib/tasks/fleximage.rake +2 -2
  160. data/spec/controllers/admin/contents_controller_spec.rb +2 -2
  161. data/spec/controllers/admin/elements_controller_spec.rb +30 -1
  162. data/spec/controllers/admin/pages_controller_spec.rb +35 -18
  163. data/spec/controllers/admin/trash_controller_spec.rb +40 -16
  164. data/spec/controllers/attachments_controller_spec.rb +62 -0
  165. data/spec/controllers/base_controller_spec.rb +43 -42
  166. data/spec/controllers/elements_controller_spec.rb +30 -0
  167. data/spec/controllers/pages_controller_spec.rb +22 -5
  168. data/spec/controllers/pictures_controller_spec.rb +82 -0
  169. data/spec/dummy/app/models/event.rb +2 -1
  170. data/spec/dummy/config/database.yml +3 -2
  171. data/spec/dummy/db/schema.rb +51 -27
  172. data/spec/factories.rb +29 -8
  173. data/spec/helpers/admin/base_helper_spec.rb +134 -21
  174. data/spec/helpers/admin/contents_helper_spec.rb +2 -2
  175. data/spec/helpers/admin/elements_helper_spec.rb +17 -9
  176. data/spec/helpers/admin/essences_helper_spec.rb +7 -6
  177. data/spec/helpers/essences_helper_spec.rb +8 -7
  178. data/spec/helpers/pages_helper_spec.rb +208 -325
  179. data/spec/helpers/url_helper_spec.rb +171 -0
  180. data/spec/integration/admin/link_overlay_spec.rb +53 -0
  181. data/spec/integration/admin/modules_integration_spec.rb +22 -26
  182. data/spec/integration/admin/pages_controller_spec.rb +10 -19
  183. data/spec/integration/admin/picture_library_integration_spec.rb +52 -0
  184. data/spec/integration/admin/resources_integration_spec.rb +68 -75
  185. data/spec/integration/pages_controller_spec.rb +70 -61
  186. data/spec/integration/security_spec.rb +3 -5
  187. data/spec/integration/translation_integration_spec.rb +56 -0
  188. data/spec/libraries/essence_spec.rb +18 -0
  189. data/spec/libraries/resource_spec.rb +101 -79
  190. data/spec/libraries/resources_helper_spec.rb +3 -0
  191. data/spec/models/content_spec.rb +63 -60
  192. data/spec/models/element_spec.rb +203 -93
  193. data/spec/models/language_spec.rb +90 -65
  194. data/spec/models/page_layout_spec.rb +37 -0
  195. data/spec/models/page_spec.rb +181 -113
  196. data/spec/models/picture_spec.rb +73 -26
  197. data/spec/models/resource_spec.rb +52 -23
  198. data/spec/support/alchemy/specs_helpers.rb +2 -0
  199. data/spec/support/image.png +0 -0
  200. data/spec/{helpers/url_helpers_spec.rb → url_helpers_spec.rb} +0 -0
  201. data/vendor/assets/javascripts/jquery_plugins/jquery.selectBoxIt.js +1909 -0
  202. data/vendor/assets/javascripts/jquery_plugins/preloadCssImages.jQuery_v5.js +152 -0
  203. metadata +106 -33
  204. data/app/assets/stylesheets/alchemy/buttons.css.scss +0 -361
  205. data/app/assets/stylesheets/alchemy/jquery.sb.css.scss +0 -260
  206. data/app/views/alchemy/admin/contents/create.js.coffee +0 -49
  207. data/app/views/alchemy/admin/elements/fold.js.coffee +0 -37
  208. data/app/views/alchemy/admin/essence_pictures/destroy.js.coffee +0 -19
  209. data/app/views/alchemy/admin/pictures/_pictures_list.html.erb +0 -16
  210. data/app/views/alchemy/admin/pictures/update.js.erb +0 -3
  211. data/spec/dummy/config/locales/en.yml +0 -5
  212. data/spec/dummy/config/locales/fo.yml +0 -5
  213. data/spec/page_layout_spec.rb +0 -35
  214. data/vendor/assets/javascripts/jquery_plugins/jquery.in-place-edit.js +0 -172
  215. data/vendor/assets/javascripts/jquery_plugins/jquery.sb.min.js +0 -14
@@ -14,15 +14,7 @@ module Alchemy
14
14
 
15
15
  layout 'alchemy/admin'
16
16
 
17
- private
18
-
19
- # Setting the Alchemy GUI translation to users preffered language, or taking default translation.
20
- # You can set the default translation in your +config/application.rb+ file
21
- def set_translation
22
- if current_user && current_user.language
23
- ::I18n.locale = current_user.language
24
- end
25
- end
17
+ private
26
18
 
27
19
  # Handles exceptions
28
20
  def exception_handler(e)
@@ -15,13 +15,13 @@ module Alchemy
15
15
  @options = params[:options] || {}
16
16
  @html_options = params[:html_options] || {}
17
17
  if @options.is_a?(String)
18
- @options = JSON.parse(@options)
18
+ @options = @options.present? ? JSON.parse(@options) : {}
19
19
  end
20
20
  if @content.essence_type == "Alchemy::EssencePicture"
21
- @content_dom_id = "#add_content_#{@element.id}"
21
+ @content_dom_id = "#add_picture_#{@element.id}"
22
22
  @content.essence.picture_id = params[:picture_id]
23
23
  @content.essence.save
24
- @contents_of_this_type = @element.contents.find_all_by_essence_type('Alchemy::EssencePicture')
24
+ @contents_of_this_type = @element.contents.gallery_pictures
25
25
  @dragable = @contents_of_this_type.length > 1
26
26
  @options = @options.merge(:dragable => @dragable)
27
27
  else
@@ -50,9 +50,7 @@ module Alchemy
50
50
  def destroy
51
51
  @content = Content.find(params[:id])
52
52
  @content_dup = @content.clone
53
- element = @content.element
54
- content_name = @content.name
55
- @notice = t("Successfully deleted content", :content => content_name)
53
+ @notice = t("Successfully deleted content", :content => @content.name_for_label)
56
54
  @content.destroy
57
55
  end
58
56
 
@@ -37,6 +37,7 @@ module Alchemy
37
37
  # Creates a element as discribed in config/alchemy/elements.yml on page via AJAX.
38
38
  def create
39
39
  @page = Page.find(params[:element][:page_id])
40
+ @element_name = params[:element][:name] # storing the original element name, because the model alters the params hash
40
41
  @paste_from_clipboard = !params[:paste_from_clipboard].blank?
41
42
  if @paste_from_clipboard
42
43
  source_element = Element.find(element_from_clipboard[:id])
@@ -50,7 +51,6 @@ module Alchemy
50
51
  @element = Element.new_from_scratch(params[:element])
51
52
  end
52
53
  put_element_in_cell if @page.can_have_cells?
53
- @element.page = @page
54
54
  if @element.save
55
55
  render :action => :create
56
56
  else
@@ -103,7 +103,7 @@ module Alchemy
103
103
  private
104
104
 
105
105
  def put_element_in_cell
106
- element_with_cell_name = @paste_from_clipboard ? params[:paste_from_clipboard] : params[:element][:name]
106
+ element_with_cell_name = @paste_from_clipboard ? params[:paste_from_clipboard] : @element_name
107
107
  cell_definition = Cell.definition_for(element_with_cell_name.split('#').last) if !element_with_cell_name.blank?
108
108
  if cell_definition
109
109
  @cell = @page.cells.find_or_create_by_name(cell_definition['name'])
@@ -101,7 +101,6 @@ module Alchemy
101
101
  name = @page.name
102
102
  @page_id = @page.id
103
103
  @layoutpage = @page.layoutpage?
104
- session[:language_id] = @page.language_id
105
104
  if @page.destroy
106
105
  @page_root = Page.language_root_for(session[:language_id])
107
106
  @message = t("Page deleted", :name => name)
@@ -109,6 +108,8 @@ module Alchemy
109
108
  respond_to do |format|
110
109
  format.js
111
110
  end
111
+ # remove from clipboard
112
+ get_clipboard.remove(:pages, @page_id)
112
113
  end
113
114
  end
114
115
 
@@ -121,7 +122,6 @@ module Alchemy
121
122
  end
122
123
  @area_name = params[:area_name]
123
124
  @content_id = params[:content_id]
124
- @link_target_options = Page.link_target_options
125
125
  @attachments = Attachment.all.collect { |f| [f.name, download_attachment_path(:id => f.id, :name => f.name)] }
126
126
  if params[:link_urls_for] == "newsletter"
127
127
  # TODO: links in newsletters has to go through statistic controller. therfore we have to put a string inside the content_rtfs and replace this string with recipient.id before sending the newsletter.
@@ -8,8 +8,16 @@ module Alchemy
8
8
  respond_to :html, :js
9
9
 
10
10
  def index
11
- @size = params[:size] || 'medium'
12
- @pictures = Picture.find_paginated(params, pictures_per_page_for_size(@size))
11
+ @size = params[:size].present? ? params[:size] : 'medium'
12
+ @pictures = Picture.scoped
13
+ @pictures = @pictures.tagged_with(params[:tagged_with], :any => true) if params[:tagged_with].present?
14
+ case params[:filter]
15
+ when 'recent'
16
+ @pictures = @pictures.recent
17
+ when 'last_upload'
18
+ @pictures = @pictures.last_upload
19
+ end
20
+ @pictures = @pictures.find_paginated(params, pictures_per_page_for_size(@size))
13
21
  if in_overlay?
14
22
  archive_overlay
15
23
  else
@@ -23,7 +31,7 @@ module Alchemy
23
31
  @size = params[:size] || 'medium'
24
32
  if in_overlay?
25
33
  @while_assigning = true
26
- @content = Content.find(params[:content_id], :select => 'id') if !params[:content_id].blank?
34
+ @content = Content.find_by_id(params[:content_id], :select => 'id')
27
35
  @element = Element.find(params[:element_id], :select => 'id')
28
36
  @options = hashified_options
29
37
  @page = params[:page]
@@ -33,7 +41,10 @@ module Alchemy
33
41
  end
34
42
 
35
43
  def create
36
- @picture = Picture.new(:image_file => params[:Filedata])
44
+ @picture = Picture.new(
45
+ :image_file => params[:Filedata],
46
+ :upload_hash => params[:upload_hash]
47
+ )
37
48
  @picture.name = @picture.humanized_name
38
49
  @picture.save
39
50
  @size = params[:size] || 'medium'
@@ -52,17 +63,55 @@ module Alchemy
52
63
  flash[:notice] = @message
53
64
  #redirect_to :back
54
65
  #TODO temporary workaround; has to be fixed.
55
- redirect_to admin_pictures_path
66
+ redirect_to admin_pictures_path(:filter => 'last_upload')
56
67
  end
57
68
  end
58
69
 
70
+ def edit
71
+ @picture = Picture.find(params[:id])
72
+ render :layout => !request.xhr?
73
+ end
74
+
75
+ def edit_multiple
76
+ @pictures = Picture.find(params[:picture_ids])
77
+ render :layout => !request.xhr?
78
+ end
79
+
59
80
  def update
60
- @size = params[:size] || 'medium'
61
81
  @picture = Picture.find(params[:id])
62
- oldname = @picture.name
63
- @picture.name = params[:name]
64
- @picture.save
65
- @message = t("Picture renamed successfully", :from => oldname, :to => @picture.name)
82
+
83
+ if @picture.update_attributes(params[:picture])
84
+ flash[:notice] = t('picture_updated_successfully', :name => @picture.name)
85
+ else
86
+ flash[:error] = t('picture_update_failed')
87
+ end
88
+ redirect_to_index
89
+ end
90
+
91
+ def update_multiple
92
+ @pictures = Picture.find(params[:picture_ids])
93
+ @pictures.each do |picture|
94
+ # Do not delete name from multiple pictures, if the form field is blank!
95
+ picture.name = params[:pictures_name] if params[:pictures_name].present?
96
+ picture.tag_list = params[:pictures_tag_list]
97
+ picture.save
98
+ end
99
+ flash[:notice] = t("Pictures updated successfully")
100
+ redirect_to_index
101
+ end
102
+
103
+ def delete_multiple
104
+ if request.delete? && params[:picture_ids].present?
105
+ pictures = Picture.find(params[:picture_ids])
106
+ names = pictures.map(&:name).to_sentence
107
+ pictures.each do |picture|
108
+ picture.destroy
109
+ end
110
+ flash[:notice] = t("Pictures deleted successfully", :names => names)
111
+ else
112
+ flash[:notice] = t("Could not delete Pictures")
113
+ end
114
+ redirect_to_index
66
115
  end
67
116
 
68
117
  def destroy
@@ -84,16 +133,16 @@ module Alchemy
84
133
  render :layout => false
85
134
  end
86
135
 
87
- private
136
+ private
88
137
 
89
138
  def pictures_per_page_for_size(size)
90
139
  case size
91
140
  when 'small'
92
- per_page = in_overlay? ? 35 : (per_page_value_for_screen_size * 2.9).floor # 50
141
+ per_page = in_overlay? ? 37 : (per_page_value_for_screen_size * 2.9).floor
93
142
  when 'large'
94
- per_page = in_overlay? ? 4 : (per_page_value_for_screen_size / 1.7).floor # 8
143
+ per_page = in_overlay? ? 4 : (per_page_value_for_screen_size / 1.7).floor + 1
95
144
  else
96
- per_page = in_overlay? ? 12 : (per_page_value_for_screen_size / 0.8).ceil # 18
145
+ per_page = in_overlay? ? 9 : (per_page_value_for_screen_size / 1.0).ceil + 1
97
146
  end
98
147
  return per_page
99
148
  end
@@ -111,11 +160,21 @@ module Alchemy
111
160
  render :partial => 'archive_overlay'
112
161
  }
113
162
  format.js {
114
- render :action => :archive_overlay
163
+ render :action => 'archive_overlay'
115
164
  }
116
165
  end
117
166
  end
118
167
 
168
+ def redirect_to_index
169
+ redirect_to(
170
+ :action => :index,
171
+ :query => params[:query],
172
+ :tagged_with => params[:tagged_with],
173
+ :size => params[:size],
174
+ :filter => params[:filter]
175
+ )
176
+ end
177
+
119
178
  end
120
179
  end
121
180
  end
@@ -1,9 +1,10 @@
1
1
  module Alchemy
2
2
  class AttachmentsController < Alchemy::BaseController
3
3
 
4
+ filter_access_to [:show, :download], :attribute_check => true, :model => Alchemy::Attachment, :load_method => :load_attachment
5
+
4
6
  # sends file inline. i.e. for viewing pdfs/movies in browser
5
7
  def show
6
- @attachment = Attachment.find(params[:id])
7
8
  send_file(
8
9
  @attachment.public_filename,
9
10
  {
@@ -16,7 +17,6 @@ module Alchemy
16
17
 
17
18
  # sends file as attachment. aka download
18
19
  def download
19
- @attachment = Attachment.find(params[:id])
20
20
  send_file(
21
21
  @attachment.full_filename, {
22
22
  :name => @attachment.filename,
@@ -26,5 +26,11 @@ module Alchemy
26
26
  )
27
27
  end
28
28
 
29
+ private
30
+
31
+ def load_attachment
32
+ @attachment = Attachment.find(params[:id])
33
+ end
34
+
29
35
  end
30
36
  end
@@ -39,7 +39,29 @@ module Alchemy
39
39
  ::Alchemy::I18n.t(key, *args)
40
40
  end
41
41
 
42
- private
42
+ private
43
+
44
+ # Sets Alchemy's GUI translation to users preffered language and stores it in the session.
45
+ #
46
+ # Guesses the language from browser locale. If not successful it takes the default.
47
+ #
48
+ # You can set the default translation in your +config/application.rb+ file, via Rails +default_locale+ config option.
49
+ #
50
+ # If one passes a locale parameter the locale is set to its value
51
+ #
52
+ def set_translation
53
+ if params[:locale].blank? && session[:current_locale].present?
54
+ ::I18n.locale = session[:current_locale]
55
+ elsif params[:locale].present? && ::I18n.available_locales.include?(params[:locale].to_sym)
56
+ session[:current_locale] = ::I18n.locale = params[:locale]
57
+ elsif current_user && current_user.language.present?
58
+ ::I18n.locale = current_user.language
59
+ elsif Rails.env == 'test' # OMG I hate to do this. But it helps...
60
+ ::I18n.locale = 'en'
61
+ else
62
+ ::I18n.locale = request.env['HTTP_ACCEPT_LANGUAGE'].try(:scan, /^[a-z]{2}/).try(:first)
63
+ end
64
+ end
43
65
 
44
66
  # Sets the language for rendering pages in pages controller
45
67
  def set_language
@@ -101,9 +123,29 @@ module Alchemy
101
123
  end
102
124
  end
103
125
 
126
+ # Handles the layout rendering
127
+ #
128
+ # Can be used inside the controller´s +layout+ class method
129
+ #
130
+ # === Example:
131
+ # layout :layout_for_page
132
+ #
133
+ # === Usage:
134
+ # 1. You can pass none or false as url parameter to avoid any layout rendering.
135
+ # 2. You can pass a layout name of any existing layout file in +app/views/layouts+ folder.
136
+ #
137
+ # If no layout name is given, Alchemy tries to render +app/views/layouts/application/+ layout.
138
+ # If that is not present, Alchemy tries to render +app/views/layouts/alchemy/pages+ layout.
139
+ #
104
140
  def layout_for_page
105
- if !params[:layout].blank? && params[:layout] != 'none'
106
- params[:layout]
141
+ if params[:layout] == 'none' || params[:layout] == 'false'
142
+ false
143
+ elsif !params[:layout].blank?
144
+ if File.exist?(Rails.root.join('app/views/layouts', "#{params[:layout]}.html.erb"))
145
+ params[:layout]
146
+ else
147
+ raise_not_found_error
148
+ end
107
149
  elsif File.exist?(Rails.root.join('app/views/layouts', 'application.html.erb'))
108
150
  'application'
109
151
  else
@@ -116,10 +158,10 @@ module Alchemy
116
158
  logger.info "Rendering 404: #{exception.message}"
117
159
  end
118
160
  @page = Page.language_root_for(session[:language_id])
119
- render :file => "#{Rails.root}/public/404", :status => 404, :layout => !@page.nil?
161
+ render :file => Rails.root.join("public/404.html"), :status => 404, :layout => !@page.nil?
120
162
  end
121
163
 
122
- protected
164
+ protected
123
165
 
124
166
  def permission_denied
125
167
  if current_user
@@ -13,7 +13,7 @@ module Alchemy
13
13
  end
14
14
  end
15
15
 
16
- private
16
+ private
17
17
 
18
18
  def load_element
19
19
  @element = Element.find(params[:id])
@@ -1,6 +1,6 @@
1
1
  # == Sending Messages:
2
2
  # To send Messages via contact forms you can create your form fields in the config.yml
3
- #
3
+ #
4
4
  # === Example:
5
5
  # Make an Element with this options inside your @elements.yml file:
6
6
  #
@@ -17,9 +17,9 @@
17
17
  #
18
18
  # The fields +mail_to+, +mail_from+, +subject+ and +success_page+ are recommended.
19
19
  # The +Alchemy::MessagesController+ uses them to send your mails. So your customer has full controll of these values inside his contactform element.
20
- #
20
+ #
21
21
  # Then make a page layout for your contact page in the +page_layouts.yml+ file:
22
- #
22
+ #
23
23
  # - name: contact
24
24
  # unique: true
25
25
  # cache: false
@@ -29,12 +29,12 @@
29
29
  # Disabling the page caching is stronlgy recommended!
30
30
  #
31
31
  # The editor view for your element should have this layout:
32
- #
32
+ #
33
33
  # <%= render_essence_editor_by_name(element, 'mail_from') %>
34
34
  # <%= render_essence_editor_by_name(element, 'mail_to') %>
35
35
  # <%= render_essence_editor_by_name(element, 'subject') %>
36
36
  # <%= page_selector(element, 'success_page', :page_attribute => :urlname) %>
37
- #
37
+ #
38
38
  # Please have a look at the +alchemy/config/config.yml+ file for further Message settings.
39
39
 
40
40
  module Alchemy
@@ -76,26 +76,26 @@ module Alchemy
76
76
  def mail_to
77
77
  @element.ingredient("mail_to")
78
78
  rescue
79
- mailer_config[:mail_to]
79
+ mailer_config['mail_to']
80
80
  end
81
81
 
82
82
  def mail_from
83
83
  @element.ingredient("mail_from")
84
84
  rescue
85
- mailer_config[:mail_from]
85
+ mailer_config['mail_from']
86
86
  end
87
87
 
88
88
  def subject
89
89
  @element.ingredient("subject")
90
90
  rescue
91
- mailer_config[:subject]
91
+ mailer_config['subject']
92
92
  end
93
93
 
94
94
  def redirect_to_success_page
95
95
  if @element.ingredient("success_page")
96
96
  urlname = @element.ingredient("success_page")
97
- elsif mailer_config[:forward_to_page] && mailer_config[:mail_success_page]
98
- urlname = Page.find_by_urlname(mailer_config[:mail_success_page]).urlname
97
+ elsif mailer_config['forward_to_page'] && mailer_config['mail_success_page']
98
+ urlname = Page.find_by_urlname(mailer_config['mail_success_page']).urlname
99
99
  else
100
100
  flash[:notice] = t(:success, :scope => 'contactform.messages')
101
101
  urlname = Page.language_root_for(session[:language_id]).urlname
@@ -104,8 +104,8 @@ module Alchemy
104
104
  end
105
105
 
106
106
  def get_page
107
- @page = Page.find_by_page_layout_and_language_id(mailer_config[:page_layout_name], session[:language_id])
108
- raise "Page for page_layout #{mailer_config[:page_layout_name]} not found" if @page.blank?
107
+ @page = Page.find_by_page_layout_and_language_id(mailer_config['page_layout_name'], session[:language_id])
108
+ raise "Page for page_layout #{mailer_config['page_layout_name']} not found" if @page.blank?
109
109
  @root_page = @page.get_language_root
110
110
  end
111
111
 
@@ -66,7 +66,11 @@ module Alchemy
66
66
  store_language_in_session(@page.language) if @page.present?
67
67
  return @page
68
68
  else
69
- @page = Page.contentpages.find_by_urlname_and_language_id(params[:urlname], session[:language_id])
69
+ @page = Page.contentpages.where(
70
+ :urlname => params[:urlname],
71
+ :language_id => session[:language_id], # Make sure that the current language
72
+ :language_code => params[:lang] # matches the requested language code.
73
+ ).first
70
74
  end
71
75
  end
72
76
  end
@@ -3,10 +3,12 @@ module Alchemy
3
3
 
4
4
  caches_page :show, :thumbnail, :zoom
5
5
 
6
+ before_filter :load_picture
7
+
8
+ filter_access_to :show, :attribute_check => true, :model => Alchemy::Picture, :load_method => :load_picture
6
9
  filter_access_to :thumbnail
7
10
 
8
11
  def show
9
- @picture = Picture.find(params[:id])
10
12
  @size = params[:size]
11
13
  @crop = !params[:crop].nil?
12
14
  @crop_from = normalized_size(params[:crop_from])
@@ -22,7 +24,6 @@ module Alchemy
22
24
  end
23
25
 
24
26
  def thumbnail
25
- @picture = Picture.find(params[:id])
26
27
  case params[:size]
27
28
  when "small"
28
29
  @size = "80x60"
@@ -43,10 +44,10 @@ module Alchemy
43
44
  end
44
45
 
45
46
  def zoom
46
- @picture = Picture.find(params[:id])
47
+ #
47
48
  end
48
49
 
49
- private
50
+ private
50
51
 
51
52
  def normalized_size(size)
52
53
  return "" if size.blank?
@@ -55,5 +56,9 @@ module Alchemy
55
56
  end.join('x')
56
57
  end
57
58
 
59
+ def load_picture
60
+ @picture ||= Picture.find(params[:id])
61
+ end
62
+
58
63
  end
59
64
  end