alchemy_cms 2.0.rc2 → 2.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/app/controllers/admin/attachments_controller.rb +47 -21
  2. data/app/controllers/admin/clipboard_controller.rb +2 -0
  3. data/app/controllers/admin/elements_controller.rb +2 -0
  4. data/app/controllers/admin/essence_files_controller.rb +7 -6
  5. data/app/controllers/admin/languages_controller.rb +1 -0
  6. data/app/controllers/admin/pictures_controller.rb +49 -34
  7. data/app/controllers/admin/users_controller.rb +2 -0
  8. data/app/controllers/admin_controller.rb +1 -0
  9. data/app/controllers/alchemy_controller.rb +9 -0
  10. data/app/helpers/alchemy_helper.rb +8 -2
  11. data/app/models/attachment.rb +5 -0
  12. data/app/models/element.rb +4 -0
  13. data/app/sweepers/pictures_sweeper.rb +2 -1
  14. data/app/views/admin/attachments/_archive_overlay.html.erb +25 -0
  15. data/app/views/admin/attachments/_file_to_assign.html.erb +2 -2
  16. data/app/views/admin/attachments/create.js.erb +4 -2
  17. data/app/views/admin/contents/create.js.erb +16 -7
  18. data/app/views/admin/elements/_add_content.html.erb +1 -3
  19. data/app/views/admin/essence_files/edit.html.erb +5 -5
  20. data/app/views/admin/essence_pictures/destroy.js.erb +6 -3
  21. data/app/views/admin/pages/edit.html.erb +1 -1
  22. data/app/views/admin/partials/_remote_search_form.html.erb +4 -3
  23. data/app/views/admin/partials/_upload_form.html.erb +1 -3
  24. data/app/views/admin/pictures/_archive_overlay.html.erb +18 -0
  25. data/app/views/admin/pictures/_filter_and_size_bar.html.erb +6 -17
  26. data/app/views/admin/pictures/_picture.html.erb +14 -16
  27. data/app/views/admin/pictures/_picture_to_assign.html.erb +27 -29
  28. data/app/views/admin/pictures/create.js.erb +10 -10
  29. data/app/views/admin/pictures/index.html.erb +35 -5
  30. data/app/views/essences/_essence_file_editor.html.erb +4 -4
  31. data/app/views/essences/_essence_picture_editor.html.erb +2 -2
  32. data/app/views/essences/_essence_picture_tools.html.erb +1 -3
  33. data/assets/javascripts/alchemy.js +2 -2
  34. data/assets/stylesheets/alchemy.css +127 -132
  35. data/assets/stylesheets/elements.css +19 -39
  36. data/config/routes.rb +6 -8
  37. data/lib/alchemy/remote_pagination_link_renderer.rb +12 -1
  38. data/lib/alchemy/version.rb +1 -1
  39. data/spec/dummy/public/stylesheets/alchemy/alchemy.css +197 -173
  40. data/spec/dummy/public/stylesheets/alchemy/elements.css +6 -6
  41. metadata +6 -8
  42. data/app/views/admin/attachments/archive_overlay.html.erb +0 -8
  43. data/app/views/admin/pictures/_archive_overlay_images.html.erb +0 -16
  44. data/app/views/admin/pictures/archive_overlay.html.erb +0 -3
  45. data/app/views/admin/pictures/update.js.erb +0 -11
@@ -2,22 +2,33 @@ class Admin::AttachmentsController < AlchemyController
2
2
 
3
3
  protect_from_forgery :except => [:create]
4
4
 
5
+ before_filter :set_translation
5
6
  filter_access_to :all
6
7
 
7
8
  def index
8
- cond = "name LIKE '%#{params[:query]}%' OR filename LIKE '%#{params[:query]}%'"
9
- if params[:per_page] == 'all'
10
- @attachments = Attachment.where(cond).order(:name)
9
+ if in_overlay?
10
+ archive_overlay
11
11
  else
12
- @attachments = Attachment.where(cond).paginate(
13
- :page => (params[:page] || 1),
14
- :per_page => (params[:per_page] || 20)
15
- ).order(:name)
12
+ cond = "name LIKE '%#{params[:query]}%' OR filename LIKE '%#{params[:query]}%'"
13
+ if params[:per_page] == 'all'
14
+ @attachments = Attachment.where(cond).order(:name)
15
+ else
16
+ @attachments = Attachment.where(cond).paginate(
17
+ :page => (params[:page] || 1),
18
+ :per_page => (params[:per_page] || 20)
19
+ ).order(:name)
20
+ end
16
21
  end
17
22
  end
18
23
 
19
24
  def new
20
25
  @attachment = Attachment.new
26
+ if in_overlay?
27
+ @while_assigning = true
28
+ @content = Content.find(params[:content_id], :select => 'id') if !params[:content_id].blank?
29
+ @swap = params[:swap]
30
+ @options = hashified_options
31
+ end
21
32
  render :layout => false
22
33
  end
23
34
 
@@ -34,7 +45,14 @@ class Admin::AttachmentsController < AlchemyController
34
45
  :per_page => (params[:per_page] || 20)
35
46
  ).order(:name)
36
47
  end
48
+ if in_overlay?
49
+ @while_assigning = true
50
+ @content = Content.find(params[:content_id], :select => 'id') if !params[:content_id].blank?
51
+ @swap = params[:swap]
52
+ @options = hashified_options
53
+ end
37
54
  @message = _('File %{name} uploaded succesfully') % {:name => @attachment.name}
55
+ # Are we using the Flash uploader? Or the plain html file uploader?
38
56
  if params[Rails.application.config.session_options[:key]].blank?
39
57
  flash[:notice] = @message
40
58
  redirect_to :action => :index
@@ -76,20 +94,6 @@ class Admin::AttachmentsController < AlchemyController
76
94
  end
77
95
  end
78
96
 
79
- def archive_overlay
80
- @content = Content.find(params[:content_id])
81
- @options = params[:options]
82
- if !params[:only].blank?
83
- condition = "filename LIKE '%.#{params[:only].join("' OR filename LIKE '%.")}'"
84
- elsif !params[:except].blank?
85
- condition = "filename NOT LIKE '%.#{params[:except].join("' OR filename NOT LIKE '%.")}'"
86
- else
87
- condition = ""
88
- end
89
- @attachments = Attachment.where(condition).order(:name)
90
- render :layout => false
91
- end
92
-
93
97
  def show
94
98
  @attachment = Attachment.find(params[:id])
95
99
  send_file(
@@ -113,4 +117,26 @@ class Admin::AttachmentsController < AlchemyController
113
117
  )
114
118
  end
115
119
 
120
+ private
121
+
122
+ def in_overlay?
123
+ !params[:content_id].blank?
124
+ end
125
+
126
+ def archive_overlay
127
+ @content = Content.find(params[:content_id])
128
+ @options = params[:options]
129
+ if !params[:only].blank?
130
+ condition = "filename LIKE '%.#{params[:only].join("' OR filename LIKE '%.")}'"
131
+ elsif !params[:except].blank?
132
+ condition = "filename NOT LIKE '%.#{params[:except].join("' OR filename NOT LIKE '%.")}'"
133
+ else
134
+ condition = ""
135
+ end
136
+ @attachments = Attachment.where(condition).order(:name)
137
+ respond_to do |format|
138
+ format.html { render :partial => 'archive_overlay' }
139
+ end
140
+ end
141
+
116
142
  end
@@ -2,6 +2,8 @@ class Admin::ClipboardController < AlchemyController
2
2
 
3
3
  filter_access_to :all
4
4
 
5
+ before_filter :set_translation
6
+
5
7
  def index
6
8
  clipboard = get_clipboard(params[:remarkable_type].tableize)
7
9
  @clipboard_items = params[:remarkable_type].classify.constantize.all_from_clipboard(clipboard)
@@ -1,5 +1,7 @@
1
1
  class Admin::ElementsController < AlchemyController
2
2
 
3
+ before_filter :set_translation
4
+
3
5
  filter_access_to [:new, :create, :order, :index], :attribute_check => false
4
6
 
5
7
  cache_sweeper :content_sweeper, :only => [:update]
@@ -12,8 +12,8 @@ class Admin::EssenceFilesController < AlchemyController
12
12
  @essence_file = EssenceFile.find(params[:id])
13
13
  @essence_file.update_attributes(params[:essence_file])
14
14
  render :update do |page|
15
- page << "Alchemy.closeCurrentWindow()"
16
- page << "Alchemy.reloadPreview()"
15
+ page.call "Alchemy.closeCurrentWindow"
16
+ page.call "Alchemy.reloadPreview"
17
17
  end
18
18
  end
19
19
 
@@ -23,11 +23,12 @@ class Admin::EssenceFilesController < AlchemyController
23
23
  @content.essence.attachment = @attachment
24
24
  @content.essence.save
25
25
  @content.save
26
+ @options = params[:options]
26
27
  render :update do |page|
27
- page.replace "#{@content.essence_type.underscore}_#{@content.id}", :partial => "essences/essence_file_editor", :locals => {:content => @content, :options => params[:options]}
28
- page << "Alchemy.closeCurrentWindow()"
29
- page << "Alchemy.reloadPreview()"
30
- page << "Alchemy.setElementDirty('#element_#{@content.element.id}')"
28
+ page << "jQuery('##{@content.essence_type.underscore}_#{@content.id}').replaceWith('#{escape_javascript(render(:partial => "essences/essence_file_editor.html.erb", :locals => {:content => @content, :options => @options}))}')"
29
+ page.call "Alchemy.closeCurrentWindow"
30
+ page.call "Alchemy.reloadPreview"
31
+ page.call "Alchemy.setElementDirty", "#element_#{@content.element.id}"
31
32
  end
32
33
  end
33
34
 
@@ -1,6 +1,7 @@
1
1
  class Admin::LanguagesController < AlchemyController
2
2
 
3
3
  filter_resource_access
4
+ before_filter :set_translation
4
5
 
5
6
  def index
6
7
  if !params[:query].blank?
@@ -1,29 +1,38 @@
1
1
  class Admin::PicturesController < AlchemyController
2
2
  protect_from_forgery :except => [:create]
3
3
 
4
+ before_filter :set_translation
5
+
4
6
  filter_access_to :all
5
7
 
6
8
  cache_sweeper :pictures_sweeper, :only => [:update, :destroy]
7
9
 
8
10
  def index
11
+ @size = params[:size] || 'medium'
9
12
  if params[:per_page] == 'all'
10
13
  @pictures = Picture.where("name LIKE '%#{params[:query]}%'").order(:name)
11
14
  else
12
15
  @pictures = Picture.where("name LIKE '%#{params[:query]}%'").paginate(
13
16
  :page => params[:page] || 1,
14
- :per_page => params[:per_page] || 32
17
+ :per_page => pictures_per_page_for_size(@size)
15
18
  ).order(:name)
16
19
  end
20
+ if in_overlay?
21
+ archive_overlay
22
+ else
23
+ # render index.html.erb
24
+ end
17
25
  end
18
26
 
19
27
  def new
20
28
  @picture = Picture.new
21
29
  @while_assigning = params[:while_assigning] == 'true'
22
- if @while_assigning
30
+ @size = params[:size] || 'medium'
31
+ if in_overlay?
32
+ @while_assigning = true
23
33
  @content = Content.find(params[:content_id], :select => 'id') if !params[:content_id].blank?
24
34
  @element = Element.find(params[:element_id], :select => 'id')
25
- @size = params[:size]
26
- @options = params[:options]
35
+ @options = hashified_options
27
36
  @page = params[:page]
28
37
  @per_page = params[:per_page]
29
38
  end
@@ -34,12 +43,12 @@ class Admin::PicturesController < AlchemyController
34
43
  @picture = Picture.new(:image_file => params[:Filedata])
35
44
  @picture.name = @picture.image_filename
36
45
  @picture.save
37
- @while_assigning = params[:while_assigning] == 'true'
38
- if @while_assigning
46
+ @size = params[:size] || 'medium'
47
+ if in_overlay?
48
+ @while_assigning = true
39
49
  @content = Content.find(params[:content_id], :select => 'id') if !params[:content_id].blank?
40
50
  @element = Element.find(params[:element_id], :select => 'id')
41
- @size = params[:size] || 'medium'
42
- @options = params[:options]
51
+ @options = hashified_options
43
52
  @page = params[:page] || 1
44
53
  @per_page = pictures_per_page_for_size(@size)
45
54
  end
@@ -48,10 +57,11 @@ class Admin::PicturesController < AlchemyController
48
57
  else
49
58
  @pictures = Picture.where("name LIKE '%#{params[:query]}%'").paginate(
50
59
  :page => (params[:page] || 1),
51
- :per_page => (params[:per_page] || @per_page || 32)
60
+ :per_page => pictures_per_page_for_size(@size)
52
61
  ).order(:name)
53
62
  end
54
63
  @message = _('Picture %{name} uploaded succesfully') % {:name => @picture.name}
64
+ # Are we using the Flash uploader? Or the plain html file uploader?
55
65
  if params[Rails.application.config.session_options[:key]].blank?
56
66
  flash[:notice] = @message
57
67
  redirect_to :back
@@ -60,33 +70,16 @@ class Admin::PicturesController < AlchemyController
60
70
  exception_handler(e)
61
71
  end
62
72
 
63
- def archive_overlay
64
- @content = Content.find_by_id(params[:content_id], :select => 'id')
65
- @element = Element.find_by_id(params[:element_id], :select => 'id')
66
- @size = params[:size] || 'medium'
67
- @pictures = Picture.where("name LIKE '%#{params[:query]}%'").paginate(
68
- :page => params[:page] || 1,
69
- :per_page => pictures_per_page_for_size(@size)
70
- ).order(:name)
71
- @options = params[:options].is_a?(String) ? Rack::Utils.parse_query(params[:options]) : params[:options]
72
- respond_to do |format|
73
- format.html {
74
- render :layout => false
75
- }
76
- format.js {
77
- render :update do |page|
78
- page << "jQuery('#alchemy_window_body').html('#{escape_javascript(render(:partial => 'archive_overlay_images'))}')"
79
- end
80
- }
81
- end
82
- end
83
-
84
73
  def update
74
+ @size = params[:size] || 'medium'
85
75
  @picture = Picture.find(params[:id])
86
76
  oldname = @picture.name
87
77
  @picture.name = params[:name]
88
78
  @picture.save
89
79
  @message = _("Image renamed successfully from: '%{from}' to '%{to}'") % {:from => oldname, :to => @picture.name}
80
+ render :update do |page|
81
+ page.call 'Alchemy.growl', @message
82
+ end
90
83
  rescue Exception => e
91
84
  exception_handler(e)
92
85
  end
@@ -121,12 +114,34 @@ private
121
114
 
122
115
  def pictures_per_page_for_size(size)
123
116
  case size
124
- when 'small' then per_page = 35
125
- when 'large' then per_page = 4
117
+ when 'small'
118
+ per_page = in_overlay? ? 35 : 55
119
+ when 'large'
120
+ per_page = in_overlay? ? 4 : 8
126
121
  else
127
- per_page = 12
122
+ per_page = in_overlay? ? 12 : 18
128
123
  end
129
124
  return per_page
130
125
  end
131
-
126
+
127
+ def in_overlay?
128
+ !params[:element_id].blank?
129
+ end
130
+
131
+ def archive_overlay
132
+ @content = Content.find_by_id(params[:content_id], :select => 'id')
133
+ @element = Element.find_by_id(params[:element_id], :select => 'id')
134
+ @options = hashified_options
135
+ respond_to do |format|
136
+ format.html {
137
+ render :partial => 'archive_overlay'
138
+ }
139
+ format.js {
140
+ render :update do |page|
141
+ page << "jQuery('#alchemy_window_body').replaceWith('#{escape_javascript(render(:partial => 'archive_overlay'))}')"
142
+ end
143
+ }
144
+ end
145
+ end
146
+
132
147
  end
@@ -3,6 +3,8 @@ class Admin::UsersController < AlchemyController
3
3
  filter_access_to [:edit, :update, :destroy], :attribute_check => true
4
4
  filter_access_to [:index, :new, :create], :attribute_check => false
5
5
 
6
+ before_filter :set_translation
7
+
6
8
  def index
7
9
  if !params[:query].blank?
8
10
  @users = User.where([
@@ -1,6 +1,7 @@
1
1
  class AdminController < AlchemyController
2
2
 
3
3
  filter_access_to :index
4
+ before_filter :set_translation
4
5
  before_filter :check_user_count, :only => :login
5
6
 
6
7
  layout 'alchemy'
@@ -142,6 +142,15 @@ private
142
142
  ActionMailer::Base.default_url_options[:host] = request.host_with_port
143
143
  end
144
144
 
145
+ def hashified_options
146
+ return nil if params[:options].blank?
147
+ if params[:options].is_a?(String)
148
+ Rack::Utils.parse_query(params[:options])
149
+ else
150
+ params[:options]
151
+ end
152
+ end
153
+
145
154
  protected
146
155
 
147
156
  def init_gettext#:nodoc:
@@ -726,7 +726,7 @@ module AlchemyHelper
726
726
  )
727
727
  filter_field << "<label for=\"search_field\">" + _("search") + "</label>"
728
728
  filter_field << "</div>"
729
- filter_field
729
+ filter_field.html_safe
730
730
  end
731
731
 
732
732
  def clipboard_select_tag(items, html_options = {})
@@ -1180,5 +1180,11 @@ module AlchemyHelper
1180
1180
  end
1181
1181
  "Alchemy CMS - #{title}"
1182
1182
  end
1183
-
1183
+
1184
+ def max_image_count
1185
+ return nil if !@options
1186
+ image_count = @options[:maximum_amount_of_images] || @options[:max_images]
1187
+ image_count.to_i unless image_count.blank?
1188
+ end
1189
+
1184
1190
  end
@@ -9,9 +9,14 @@ class Attachment < ActiveRecord::Base
9
9
  )
10
10
  validates_as_attachment
11
11
 
12
+ def name
13
+ read_attribute(:name).split('.').first
14
+ end
15
+
12
16
  def extension
13
17
  filename.split(".").last
14
18
  end
19
+ alias_method :suffix, :extension
15
20
 
16
21
  def icon_css_class
17
22
  case content_type
@@ -263,6 +263,10 @@ class Element < ActiveRecord::Base
263
263
  content.ingredient
264
264
  end
265
265
 
266
+ def has_ingredient?(name)
267
+ !self.ingredient(name).blank?
268
+ end
269
+
266
270
  def save_contents(params)
267
271
  contents.each do |content|
268
272
  unless content.save_essence(params[:contents]["content_#{content.id}"], :public => !params["public"].nil?)
@@ -12,9 +12,10 @@ class PicturesSweeper < ActionController::Caching::Sweeper
12
12
  private
13
13
 
14
14
  def expire_cache_for(picture)
15
+ # Removing all variants of the picture with FileUtils.
15
16
  FileUtils.rm_rf("#{Rails.root}/public/pictures/show/#{picture.id}")
16
17
  FileUtils.rm_rf("#{Rails.root}/public/pictures/thumbnails/#{picture.id}")
17
- expire_page(:controller => '/pictures', :action => 'zoom', :id => picture.id)
18
+ expire_page(zoom_picture_path(picture, :format => 'png'))
18
19
  end
19
20
 
20
21
  end
@@ -0,0 +1,25 @@
1
+ <div id="alchemy_window_body">
2
+ <div id="overlay_toolbar">
3
+ <div class="button_with_label">
4
+ <%= link_to_overlay_window(
5
+ content_tag('span', '', :class => 'icon upload'),
6
+ new_admin_attachment_path(
7
+ :content_id => @content.blank? ? nil : @content.id,
8
+ :swap => @swap,
9
+ :options => @options
10
+ ),
11
+ {
12
+ :title => _('upload_file'),
13
+ :size => '540x480'
14
+ },
15
+ :title => _('upload_file'),
16
+ :class => 'icon_button'
17
+ ) %><br />
18
+ <label><%= _('upload_file') %></label>
19
+ </div>
20
+ <%= js_filter_field(:onkeyup => "Alchemy.ListFilter('.assign_file_file')") %>
21
+ </div>
22
+ <div id="assign_file_list" class="with_padding">
23
+ <%= render :partial => 'file_to_assign', :collection => @attachments %>
24
+ </div>
25
+ </div>
@@ -2,7 +2,7 @@
2
2
  prefix = "<div class=\"assign_file_file_icon\">"
3
3
  suffix = "</div><div class=\"assign_file_file_name\">#{file_to_assign.filename}</div>"
4
4
  -%>
5
- <%- img_tag = "#{prefix}#{render_icon(file_to_assign.icon_css_class)}#{suffix}" -%>
5
+ <%- img_tag = "#{prefix}#{render_icon(file_to_assign.icon_css_class)}#{suffix}".html_safe -%>
6
6
  <div class="assign_file_file" name="<%= file_to_assign.filename %>">
7
7
  <%= link_to(
8
8
  img_tag,
@@ -14,7 +14,7 @@
14
14
  :options => @options
15
15
  },
16
16
  :remote => true,
17
- :method => 'post',
17
+ :method => 'put',
18
18
  :title => file_to_assign.filename
19
19
  ) %>
20
20
  </div>