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
@@ -10,10 +10,13 @@ module Alchemy::Language::Code
10
10
  end
11
11
 
12
12
  module ClassMethods
13
+
13
14
  def find_by_code(code)
14
15
  codes = code.split('-')
15
- codes << nil if codes.length == 1
16
+ codes << '' if codes.length == 1
16
17
  find_by_language_code_and_country_code *codes
17
18
  end
19
+
18
20
  end
21
+
19
22
  end
@@ -12,13 +12,27 @@
12
12
  module Alchemy
13
13
  class Message
14
14
 
15
- @@config = Config.get(:mailer)
16
-
17
15
  extend ::ActiveModel::Naming
18
16
  include ::ActiveModel::Validations
19
17
  include ::ActiveModel::Conversion
20
18
  include ::ActiveModel::MassAssignmentSecurity
21
19
 
20
+ def self.attr_accessor(*vars)
21
+ @attributes ||= {}
22
+ vars.map { |v| @attributes[v] = nil}
23
+ super(*vars)
24
+ end
25
+
26
+ def self.attributes
27
+ @attributes
28
+ end
29
+
30
+ def attributes
31
+ self.class.attributes
32
+ end
33
+
34
+ @@config = Config.get(:mailer)
35
+
22
36
  attr_accessor :contact_form_id, :ip
23
37
  attr_accessible :contact_form_id
24
38
 
@@ -39,8 +53,10 @@ module Alchemy
39
53
  end
40
54
 
41
55
  def initialize(attributes = {})
56
+ @attributes ||= {}
42
57
  attributes.keys.each do |a|
43
58
  send("#{a}=", attributes[a])
59
+ @attributes[a] = attributes[a]
44
60
  end
45
61
  end
46
62
 
@@ -48,7 +64,7 @@ module Alchemy
48
64
  false
49
65
  end
50
66
 
51
- private
67
+ private
52
68
 
53
69
  def email_is_filled #:nodoc:
54
70
  !email.blank?
@@ -56,8 +56,8 @@ module Alchemy
56
56
  before_save :set_language_code, :unless => :systempage?
57
57
  before_save :set_restrictions_to_child_pages, :if => proc { |page| !page.systempage? && page.restricted_changed? }
58
58
  before_save :inherit_restricted_status, :if => proc { |page| !page.systempage? && page.parent && page.parent.restricted? }
59
- after_create :autogenerate_elements, :unless => proc { |page| page.systempage? || page.do_not_autogenerate }
60
59
  after_create :create_cells, :unless => :systempage?
60
+ after_create :autogenerate_elements, :unless => proc { |page| page.systempage? || page.do_not_autogenerate }
61
61
 
62
62
  scope :language_roots, where(:language_root => true)
63
63
  scope :layoutpages, where(:layoutpage => true)
@@ -141,12 +141,7 @@ module Alchemy
141
141
  end
142
142
 
143
143
  def elements_grouped_by_cells
144
- group = ::ActiveSupport::OrderedHash.new
145
- self.cells.each { |cell| group[cell] = cell.elements.not_trashed }
146
- if element_names_not_in_cell.any?
147
- group[Cell.new({:name => 'for_other_elements'})] = elements.not_trashed.not_in_cell
148
- end
149
- return group
144
+ elements.not_trashed.in_cell.group_by(&:cell)
150
145
  end
151
146
 
152
147
  def element_names_from_cells
@@ -161,27 +156,25 @@ module Alchemy
161
156
  # Options:
162
157
  # => :restricted => boolean (standard: nil) - next restricted page (true), skip restricted pages (false), ignore restriction (nil)
163
158
  # => :public => boolean (standard: true) - next public page (true), skip public pages (false)
164
- def previous_page(options = {})
165
- default_options = {
159
+ def previous(options = {})
160
+ next_or_previous(:previous, {
166
161
  :restricted => nil,
167
162
  :public => true
168
- }
169
- options = default_options.merge(options)
170
- find_next_or_previous_page("previous", options)
163
+ }.merge(options))
171
164
  end
165
+ alias_method :previous_page, :previous
172
166
 
173
167
  # Finds the next page on the same structure level. Otherwise it returns nil.
174
168
  # Options:
175
169
  # => :restricted => boolean (standard: nil) - next restricted page (true), skip restricted pages (false), ignore restriction (nil)
176
170
  # => :public => boolean (standard: true) - next public page (true), skip public pages (false)
177
- def next_page(options = {})
178
- default_options = {
171
+ def next(options = {})
172
+ next_or_previous(:next, {
179
173
  :restricted => nil,
180
174
  :public => true
181
- }
182
- options = default_options.merge(options)
183
- find_next_or_previous_page("next", options)
175
+ }.merge(options))
184
176
  end
177
+ alias_method :next_page, :next
185
178
 
186
179
  def find_first_public(page)
187
180
  if (page.public == true)
@@ -372,7 +365,7 @@ module Alchemy
372
365
 
373
366
  def set_restrictions_to_child_pages
374
367
  descendants.each do |child|
375
- child.update_attribute(:restricted, self.restricted?)
368
+ child.update_attributes(:restricted => self.restricted?)
376
369
  end
377
370
  end
378
371
 
@@ -427,7 +420,7 @@ module Alchemy
427
420
  end
428
421
  return page
429
422
  else
430
- raise page.errors.full_messages
423
+ raise "`#{page.name}`: #{page.errors.full_messages}"
431
424
  end
432
425
  end
433
426
 
@@ -451,11 +444,11 @@ module Alchemy
451
444
  return layoutroot if layoutroot
452
445
  language = Language.find(language_id)
453
446
  layoutroot = Page.new({
454
- :name => "Layoutroot for #{language.name}",
455
- :layoutpage => true,
456
- :language => language,
457
- :do_not_autogenerate => true
458
- })
447
+ :name => "Layoutroot for #{language.name}",
448
+ :layoutpage => true,
449
+ :language => language,
450
+ :do_not_autogenerate => true
451
+ })
459
452
  if layoutroot.save(:validate => false)
460
453
  layoutroot.move_to_child_of(Page.root)
461
454
  return layoutroot
@@ -536,23 +529,22 @@ module Alchemy
536
529
 
537
530
  private
538
531
 
539
- def find_next_or_previous_page(direction = "next", options = {})
540
- if direction == "previous"
541
- step_direction = ["pages.lft < ?", self.lft]
532
+ def next_or_previous(direction = :next, options = {})
533
+ pages = self.class.scoped
534
+ if direction == :previous
535
+ step_direction = ["#{self.class.table_name}.lft < ?", self.lft]
542
536
  order_direction = "lft DESC"
543
537
  else
544
- step_direction = ["pages.lft > ?", self.lft]
538
+ step_direction = ["#{self.class.table_name}.lft > ?", self.lft]
545
539
  order_direction = "lft"
546
540
  end
547
- conditions = Page.merge_conditions(
548
- {:parent_id => self.parent_id},
549
- {:public => options[:public]},
550
- step_direction
551
- )
541
+ pages = pages.where(:public => options[:public])
542
+ pages = pages.where(:parent_id => self.parent_id)
543
+ pages = pages.where(step_direction)
552
544
  if !options[:restricted].nil?
553
- conditions = Page.merge_conditions(conditions, {:restricted => options[:restricted]})
545
+ pages = pages.where(:restricted => options[:restricted])
554
546
  end
555
- return Page.where(conditions).order(order_direction).limit(1)
547
+ pages.order(order_direction).limit(1).first
556
548
  end
557
549
 
558
550
  # Converts the given nbame into an url friendly string
@@ -563,14 +555,27 @@ module Alchemy
563
555
  return url_name
564
556
  end
565
557
 
566
- # Looks in the layout_descripion, if there are elements to autogenerate.
567
- # If so, it generates them.
558
+ # Looks in the page_layout descripion, if there are elements to autogenerate.
559
+ #
560
+ # And if so, it generates them.
561
+ #
562
+ # If the page has cells, it looks if there are elements to generate.
563
+ #
568
564
  def autogenerate_elements
569
565
  elements = self.layout_description["autogenerate"]
570
- unless (elements.blank?)
566
+ if elements.present?
571
567
  elements.each do |element|
572
- element = Element.create_from_scratch({'page_id' => self.id, 'name' => element})
573
- element.move_to_bottom if element
568
+ if self.has_cells? && (cell_definition = cell_definitions.detect { |c| c['elements'].include?(element) })
569
+ cell = self.cells.find_by_name(cell_definition['name'])
570
+ if cell
571
+ attributes = {'page_id' => self.id, 'cell_id' => cell.id, 'name' => element}
572
+ else
573
+ raise "Cell not found for page #{self.inspect}"
574
+ end
575
+ else
576
+ attributes = {'page_id' => self.id, 'name' => element}
577
+ end
578
+ Element.create_from_scratch(attributes)
574
579
  end
575
580
  end
576
581
  end
@@ -1,6 +1,11 @@
1
1
  module Alchemy
2
2
  class Picture < ActiveRecord::Base
3
3
 
4
+ has_many :essence_pictures, :class_name => 'Alchemy::EssencePicture', :foreign_key => 'picture_id'
5
+ has_many :contents, :through => :essence_pictures
6
+ has_many :elements, :through => :contents
7
+ has_many :pages, :through => :elements
8
+
4
9
  acts_as_fleximage do
5
10
  image_directory 'uploads/pictures'
6
11
  image_storage_format Config.get(:image_store_format).to_sym
@@ -15,18 +20,30 @@ module Alchemy
15
20
  end
16
21
  end
17
22
 
23
+ acts_as_taggable
24
+
18
25
  attr_accessible(
19
26
  :image_file,
20
27
  :image_filename,
21
28
  :image_height,
22
29
  :image_width,
23
- :name
30
+ :name,
31
+ :upload_hash,
32
+ :tag_list
24
33
  )
25
34
 
26
35
  stampable(:stamper_class_name => 'Alchemy::User')
27
36
 
37
+ scope :recent, where("#{self.table_name}.created_at > ?", Time.now-24.hours).order(:created_at)
38
+
28
39
  def self.find_paginated(params, per_page)
29
- Picture.where("name LIKE '%#{params[:query]}%'").page(params[:page] || 1).per(per_page).order(:name)
40
+ Picture.where("name LIKE ?", "%#{params[:query]}%").page(params[:page] || 1).per(per_page).order(:name)
41
+ end
42
+
43
+ def self.last_upload
44
+ last_picture = Picture.last
45
+ return Picture.scoped unless last_picture
46
+ Picture.where(:upload_hash => last_picture.upload_hash)
30
47
  end
31
48
 
32
49
  # Returning the filepath relative to Rails.root public folder.
@@ -119,5 +136,10 @@ module Alchemy
119
136
  "#{new_x.round}x#{new_y.round}"
120
137
  end
121
138
 
139
+ # Checks if the picture is restricted, because it is attached on restricted pages only
140
+ def restricted?
141
+ pages.any? && pages.not_restricted.blank?
142
+ end
143
+
122
144
  end
123
145
  end
@@ -33,10 +33,9 @@ module Alchemy
33
33
  end
34
34
 
35
35
  def is_admin?
36
- true if self.role == "admin"
36
+ self.role == "admin"
37
37
  end
38
-
39
- alias :admin? :is_admin?
38
+ alias_method :admin?, :is_admin?
40
39
 
41
40
  def unlock_pages
42
41
  for page in pages_locked_by_me
@@ -2,19 +2,19 @@
2
2
  <div id="overlay_toolbar">
3
3
  <div class="button_with_label">
4
4
  <%= link_to_overlay_window(
5
- content_tag('span', '', :class => 'icon upload'),
6
- alchemy.new_admin_attachment_path(
7
- :content_id => @content.blank? ? nil : @content.id,
8
- :swap => @swap,
9
- :options => @options
10
- ),
11
- {
12
- :title => t('upload_file'),
13
- :size => '540x550'
14
- },
5
+ render_icon('upload'),
6
+ alchemy.new_admin_attachment_path(
7
+ :content_id => @content.blank? ? nil : @content.id,
8
+ :swap => @swap,
9
+ :options => @options
10
+ ),
11
+ {
15
12
  :title => t('upload_file'),
16
- :class => 'icon_button'
17
- ) %>
13
+ :size => '540x550'
14
+ },
15
+ :title => t('upload_file'),
16
+ :class => 'icon_button'
17
+ ) %>
18
18
  <label><%= t('upload_file') %></label>
19
19
  </div>
20
20
  <%= js_filter_field(:onkeyup => "Alchemy.ListFilter('.assign_file_file')") %>
@@ -48,7 +48,7 @@
48
48
  alchemy.edit_admin_attachment_path(attachment, :query => params[:query], :page => params[:page]),
49
49
  {
50
50
  :title => t('rename_file'),
51
- :size => '380x100'
51
+ :size => '410x180'
52
52
  },
53
53
  :class => 'icon file_edit',
54
54
  :title => t('rename_file')
@@ -4,5 +4,6 @@
4
4
  <%- else -%>
5
5
  $('#archive_all').html('<%= escape_javascript(render(:partial => "files_list")) %>');
6
6
  Alchemy.growl('<%= @message %>');
7
+ Alchemy.overlayObserver('#archive_all');
7
8
  <%- end -%>
8
9
  })(jQuery);
@@ -2,11 +2,17 @@
2
2
  <table>
3
3
  <tr>
4
4
  <td class="label"><%= f.label 'name', :class => "short" %></td>
5
- <td class="input"><%= f.text_field 'name', :class => 'thin_border very_long' %></td>
5
+ <td class="input"><%= f.text_field 'name', :class => 'thin_border very_long', :autofocus => true %></td>
6
6
  </tr>
7
7
  <tr>
8
- <td></td>
9
- <td class="submit"><%= f.button t('save'), :class => 'button' %></td>
8
+ <td class="label"><%= f.label 'filename', :class => "short" %>*</td>
9
+ <td class="input"><%= f.text_field 'filename', :class => 'thin_border very_long' %></td>
10
+ </tr>
11
+ <tr>
12
+ <td colspan="2" class="submit">
13
+ <%= f.button t('save'), :class => 'button' %>
14
+ </td>
10
15
  </tr>
11
16
  </table>
17
+ <p class="foot_note"><%= t(:attachment_filename_notice) %></p>
12
18
  <% end %>
@@ -14,5 +14,6 @@
14
14
  }
15
15
  ]
16
16
  ) %>
17
-
18
- <%= render :partial => 'files_list' %>
17
+ <div id="archive_all">
18
+ <%= render :partial => 'files_list' %>
19
+ </div>
@@ -15,7 +15,7 @@
15
15
  ),
16
16
  :method => 'post',
17
17
  :remote => true,
18
- :class => 'button'
18
+ :class => 'small button'
19
19
  ) %>
20
20
  </p>
21
21
  </div>
@@ -0,0 +1,54 @@
1
+ (function() {
2
+
3
+ <% if params[:was_missing] %>
4
+
5
+ $("#element_<%= @element.id %>_content_missing").replaceWith('<%= escape_javascript(
6
+ render(
7
+ :partial => "alchemy/essences/#{@content.essence_partial_name}_editor",
8
+ :locals => @locals
9
+ )
10
+ ) %>');
11
+
12
+ <% else %>
13
+
14
+ $("<%= @content_dom_id %>").before('<%= escape_javascript(
15
+ render(
16
+ :partial => "alchemy/essences/#{@content.essence_partial_name}_editor",
17
+ :locals => @locals
18
+ )
19
+ ) %>');
20
+ Alchemy.enableButton('.disabled.button');
21
+ Alchemy.overlayObserver('#<%= content_dom_id(@content) %>');
22
+ Alchemy.growl('<%= t("Successfully added content") % {:content => @content.name_for_label} %>')
23
+
24
+ <% end %>
25
+
26
+ <% if @content.essence_type == "Alchemy::EssencePicture" %>
27
+
28
+ $('#picture_to_assign_<%= @content.ingredient.id %> a').attr('href', '#').off('click');
29
+
30
+ <% if @contents_of_this_type.length > 1 %>
31
+ $('#element_<%= @element.id %>_contents .essence_picture_editor').addClass('dragable_picture');
32
+ <% end %>
33
+
34
+ <% if !max_image_count.blank? && @contents_of_this_type.length >= max_image_count %>
35
+ $("#add_picture_<%= @element.id %>").remove();
36
+ <% end %>
37
+
38
+ Alchemy.SortableContents('#element_<%= @element.id %>_contents', '<%= form_authenticity_token %>');
39
+
40
+ <% elsif @content.essence_type == "Alchemy::EssenceDate" %>
41
+
42
+ Alchemy.Datepicker('#element_<%= @element.id %> input.date');
43
+
44
+ <% elsif @content.essence_type == "Alchemy::EssenceRichtext" %>
45
+
46
+ Alchemy.Tinymce.addEditor('contents_content_<%= @content.id %>_body');
47
+
48
+ <% end %>
49
+
50
+ Alchemy.reloadPreview();
51
+ Alchemy.closeCurrentWindow();
52
+ Alchemy.SelectBox("#element_<%= @element.id %>");
53
+
54
+ })()
@@ -3,11 +3,16 @@
3
3
  <%= f.hidden_field :element_id %>
4
4
  <table>
5
5
  <tr>
6
- <td>
7
- <%= f.select 'name', @contents.map { |a| [t("content_names.#{a['name']}"), a['name']] }, {}, {:class => 'alchemy_selectbox'} %>
8
- <%= hidden_field_tag('options', @options) %>
6
+ <td class="label"><%= f.label :name, t('name') %></td>
7
+ <td class="select">
8
+ <%= f.select('name', @contents.map { |a|
9
+ [t("content_names.#{a['name']}"), a['name']]
10
+ }, {}, {:class => 'alchemy_selectbox'}) %>
9
11
  </td>
10
- <td class="submit">
12
+ </tr>
13
+ <tr>
14
+ <td class="submit" colspan="2">
15
+ <%= hidden_field_tag('options', @options) %>
11
16
  <%= f.button t(:create), :class => 'button' %>
12
17
  </td>
13
18
  </tr>