spree_multi_slideshow 1.1.8 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/README.md +3 -3
  2. data/app/assets/images/store/slides/bg-gallery.png +0 -0
  3. data/app/assets/images/store/slides/bg-text02.png +0 -0
  4. data/app/assets/javascripts/admin/slides/index.js +1 -1
  5. data/app/assets/javascripts/admin/slides/new.js +1 -1
  6. data/app/assets/javascripts/admin/spree_multi_slideshow.js +1 -1
  7. data/app/assets/javascripts/store/spree_multi_slideshow.js +211 -537
  8. data/app/assets/stylesheets/admin/spree_multi_slideshow.css +16 -0
  9. data/app/assets/stylesheets/store/carousel_slideshow.css.scss +73 -0
  10. data/app/assets/stylesheets/store/spree_multi_slideshow.css +3 -47
  11. data/app/controllers/spree/admin/slides_controller.rb +5 -3
  12. data/app/controllers/spree/admin/slideshow_types_controller.rb +1 -5
  13. data/app/controllers/spree/slides_controller.rb +5 -0
  14. data/app/controllers/spree/slideshow_types_controller.rb +5 -0
  15. data/app/helpers/spree/slides_helper.rb +4 -0
  16. data/app/helpers/spree/slideshow_types_helper.rb +46 -44
  17. data/app/models/spree/slide.rb +27 -39
  18. data/app/models/spree/slideshow_type.rb +10 -4
  19. data/app/overrides/slideshow_type_admin_tab.rb +1 -6
  20. data/app/views/spree/admin/shared/_slideshow_type_tabs.html.erb +6 -8
  21. data/app/views/spree/admin/slides/_form.html.erb +9 -22
  22. data/app/views/spree/admin/slides/edit.html.erb +7 -7
  23. data/app/views/spree/admin/slides/index.html.erb +31 -30
  24. data/app/views/spree/admin/slides/new.html.erb +2 -2
  25. data/app/views/spree/admin/slideshow_types/_form.html.erb +8 -30
  26. data/app/views/spree/admin/slideshow_types/edit.html.erb +7 -6
  27. data/app/views/spree/admin/slideshow_types/index.html.erb +29 -30
  28. data/app/views/spree/admin/slideshow_types/new.html.erb +5 -33
  29. data/config/locales/en.yml +0 -1
  30. data/config/locales/it.yml +0 -1
  31. data/config/routes.rb +0 -1
  32. data/db/migrate/20120116081431_create_slideshow_types.rb +4 -1
  33. data/db/migrate/20120116083546_create_slides.rb +1 -0
  34. data/lib/generators/spree_multi_slideshow/install/install_generator.rb +22 -2
  35. data/lib/spree_multi_slideshow.rb +2 -0
  36. metadata +110 -81
  37. data/app/assets/images/store/slides/pagination.png +0 -0
  38. data/app/assets/javascripts/admin/slide_settings.js +0 -31
  39. data/app/controllers/spree/admin/slide_settings_controller.rb +0 -51
  40. data/app/models/spree/app_configuration_decorator.rb +0 -8
  41. data/app/views/spree/admin/shared/_slide_setting_configurations_menu.html.erb +0 -4
  42. data/app/views/spree/admin/slide_settings/edit.html.erb +0 -48
  43. data/app/views/spree/admin/slide_settings/show.html.erb +0 -10
  44. data/app/views/spree/admin/slideshow_types/new.js.erb +0 -2
  45. data/db/migrate/20130114150224_add_enable_pagination.rb +0 -5
  46. data/db/migrate/20130226082756_add_enable_to_slide.rb +0 -8
@@ -0,0 +1,16 @@
1
+ /*
2
+ *= require formtastic
3
+ */
4
+
5
+ .formtastic input, .formtastic textarea, .formtastic select {
6
+ font-size: 100%;
7
+ padding: 5px;
8
+ }
9
+
10
+ .formtastic button {
11
+ margin: 0;
12
+ padding: 0 20px 0 0;
13
+ }
14
+ .formtastic button:hover {
15
+ text-shadow: #FFFFFF -1px -1px 0px;
16
+ }
@@ -0,0 +1,73 @@
1
+ .left {
2
+ float: left !important;
3
+ }
4
+ .right {
5
+ float: right !important;
6
+ }
7
+ .gallery {
8
+ position: relative;
9
+ overflow: hidden;
10
+ z-index:0;
11
+ color:#fff;
12
+ margin:auto;
13
+ }
14
+ .gallery .gallery-inner {
15
+ position:relative;
16
+ }
17
+ .gallery .gallery-inner ul {
18
+ position:absolute;
19
+ margin:0;
20
+ padding:0;
21
+ list-style:none;
22
+ }
23
+ .gallery .gallery-inner li {
24
+ position:absolute;
25
+ top:0;
26
+ left:0;
27
+ background: transparent;
28
+ }
29
+ .gallery .gallery-inner li.active {z-index:2;}
30
+ .gallery img {
31
+ display:block;
32
+ }
33
+ .gallery .text-holder {
34
+ position: absolute;
35
+ text-align:center;
36
+ }
37
+ .gallery-control {
38
+ font-size: 60px;
39
+ font-weight: 100;
40
+ line-height: 27px;
41
+ color: white;
42
+ text-align: center;
43
+ width: 40px;
44
+ height: 40px;
45
+ }
46
+ a.gallery-control:hover {
47
+ text-decoration: none;
48
+ color: white;
49
+ }
50
+ .carousel-control {
51
+ position: absolute;
52
+ top: 40%;
53
+ left: 15px;
54
+ width: 40px;
55
+ height: 40px;
56
+ margin-top: -20px;
57
+ font-size: 60px;
58
+ font-weight: 100;
59
+ line-height: 30px;
60
+ color: white;
61
+ text-align: center;
62
+ background: #222;
63
+ border: 3px solid white;
64
+ -webkit-border-radius: 23px;
65
+ -moz-border-radius: 23px;
66
+ border-radius: 23px;
67
+ opacity: 0.5;
68
+ filter: alpha(opacity=50);
69
+ }
70
+ .carousel-control.right {
71
+ left: auto;
72
+ right: 15px;
73
+ }
@@ -1,47 +1,3 @@
1
- #slides {
2
- margin-bottom: 25px;
3
- }
4
- .slides_container {
5
- width: 720px;
6
- height: 287px;
7
- }
8
- .slides_container .slide_list {
9
- width: 720px;
10
- height: 287px;
11
- display: block;
12
- position: relative;
13
- }
14
- .text-holder {
15
- position: absolute;
16
- right: 0px;
17
- top: 0px;
18
- height: 271px;
19
- padding: 8px;
20
- width: 200px;
21
- background: #EFEFEF;
22
- }
23
- .pagination {
24
- margin: 6px 0 0;
25
- float: right;
26
- list-style: none;
27
- }
28
- .pagination li {
29
- float: left;
30
- margin: 0 1px;
31
- }
32
- .pagination li a {
33
- display: block;
34
- width: 13px;
35
- height: 0;
36
- padding-top: 13px;
37
- background-image: url(slides/pagination.png);
38
- background-position: 0 0;
39
- float: left;
40
- overflow: hidden;
41
- }
42
- .pagination li a:hover {
43
- background-position: 0 -26px;
44
- }
45
- .pagination li.current a, .pagination li.current a:hover {
46
- background-position: 0 -13px;
47
- }
1
+ /*
2
+ *= require store/carousel_slideshow
3
+ */
@@ -1,14 +1,15 @@
1
1
  module Spree
2
2
  module Admin
3
3
  class SlidesController < ResourceController
4
- before_filter :load_data, :except => [:destroy]
4
+ before_filter :load_data, :only => [:index, :new, :show, :edit]
5
5
 
6
6
  def update_positions
7
7
  params[:positions].each do |id, index|
8
- Spree::Slide.where(:id => id).update_all(:position => index)
8
+ Spree::Slide.update_all(['position=?', index], ['id=?', id])
9
9
  end
10
10
 
11
11
  respond_to do |format|
12
+ format.html { redirect_to admin_slideshow_type_slides_url(@slideshow_type) }
12
13
  format.js { render :text => 'Ok' }
13
14
  end
14
15
  end
@@ -19,8 +20,9 @@ module Spree
19
20
  end
20
21
 
21
22
  def load_data
22
- @slideshow_type = Spree::SlideshowType.find(params[:slideshow_type_id])
23
+ @slideshow_type = Spree::SlideshowType.find(params[:slideshow_type_id].to_i)
23
24
  end
25
+
24
26
  end
25
27
  end
26
28
  end
@@ -1,11 +1,7 @@
1
1
  module Spree
2
2
  module Admin
3
3
  class SlideshowTypesController < ResourceController
4
-
5
- def show
6
- redirect_to(:action => :edit)
7
- end
8
-
4
+
9
5
  def location_after_save
10
6
  edit_admin_slideshow_type_url(@slideshow_type)
11
7
  end
@@ -0,0 +1,5 @@
1
+ module Spree
2
+ class SlidesController < BaseController
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Spree
2
+ class SlideshowTypesController < BaseController
3
+
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module Spree
2
+ module SlidesHelper
3
+ end
4
+ end
@@ -1,56 +1,58 @@
1
1
  # encoding: UTF-8
2
-
3
2
  module Spree
4
3
  module SlideshowTypesHelper
5
-
4
+
6
5
  def insert_slideshow(params={})
7
- params[:id] ||= "slides"
8
- params[:class] ||= "my_slide"
9
- params[:category] ||= "home"
10
- logger.info("#{params[:category]}")
11
- @@slideshow = Spree::SlideshowType.enable(params[:category]).try(:first)
12
- if @@slideshow.blank? || (!@@slideshow.blank? && @@slideshow.slides.empty?)
13
- return ''
6
+ @content_for_head_added ||= false
7
+ if not @content_for_head_added
8
+ content_for(:head) { stylesheet_link_tag 'store/spree_multi_slideshow.css' }
9
+ content_for(:head) { javascript_include_tag 'store/spree_multi_slideshow.js' }
10
+ @content_for_head_added = true
11
+ end
12
+ if slide_images(params)
13
+ navigation = enable_navigation(params)
14
+ content_tag(:div, navigation[:prev] + content_tag(:div, content_tag(:ul, raw(slide_images(params))), :class => "gallery-inner clearfix") + navigation[:succ], :class => "gallery #{params[:class]}", :style => "width: #{Spree::SlideshowType.enable(params[:category] || "home").first.slide_width}px; height: #{Spree::SlideshowType.enable(params[:category] || "home").first.slide_height}px;")
14
15
  end
15
- params[:pagination_class] ||= "pagination"
16
- params[:slide_speed] ||= 350
17
- res = []
18
-
19
- res << content_tag(:div, content_tag(:div, slide_images(params, @@slideshow), :class => "slides_container"), :id => params[:id], :class => params[:class])
20
- res << "<script type='text/javascript'>
21
- $(function() {
22
- $('##{params[:id]}').slides({
23
- play: 100000,
24
- preload: true,
25
- generateNextPrev: #{@@slideshow.enable_navigation},
26
- generatePagination: #{@@slideshow.enable_pagination},
27
- paginationClass: '#{params[:pagination_class]}',
28
- slideSpeed: #{params[:slide_speed]}
29
- });
30
- });
31
- </script>"
32
-
33
- res.join.html_safe
34
16
  end
35
17
 
36
- def slide_images(params, slideshow)
37
- params[:style] ||= "medium"
38
- params[:show_content] ||= false
39
- max = slideshow.slides.enable.count
40
- slides = slideshow.slides.enable.limit(max).sort_by { |slide| slide.position }
41
-
42
- slides.map do |slide|
43
- content_tag(:div, :class => "slide_list") do
44
- divs = []
45
-
46
- divs << link_to(image_tag(slide.attachment.url(params[:style].to_sym)), (slide.url.blank? ? "javascript: void(0)" : slide.url), { :title => slide.title })
47
- if params[:show_content]
48
- divs << content_tag(:div, content_tag(:strong, raw(slide.title)) + content_tag(:p, raw(slide.content)), :class => "text-holder")
18
+ def slide_images(params)
19
+ category = params[:category] || "home"
20
+ style = params[:style] || "custom"
21
+ slideshow = Spree::SlideshowType.enable(category)
22
+ if !slideshow.blank?
23
+ max = slideshow.first.slide_number || 4
24
+ slides = Spree::Slide.where("slideshow_type_id = ?", slideshow.first.id).limit(max).sort_by { |slide| slide.position }
25
+
26
+ slides.map do |slide|
27
+ if params[:enable_content]
28
+ link_content = content_tag(:div, content_tag(:strong, raw(slide.title)) + content_tag(:p, raw(slide.content)), :class => "text-holder")
29
+ else
30
+ link_content = ""
49
31
  end
50
-
51
- divs.join.html_safe
32
+ content_tag(:li, raw(link_to(image_tag(slide.attachment.url(style.to_sym)), slide.url, { :title => slide.title })) + raw(link_content))
33
+ end.join
34
+ else
35
+ false
36
+ end
37
+ end
38
+
39
+ def enable_navigation(params)
40
+ category = params[:category] || "home"
41
+ slideshow = Spree::SlideshowType.enable(category)
42
+ if !slideshow.blank?
43
+ if slideshow.first.enable_navigation
44
+ prev = link_to("‹", "#", :class => "gallery-control left")
45
+ succ = link_to("›", "#", :class => "gallery-control right")
46
+ else
47
+ prev = ""
48
+ succ = ""
52
49
  end
53
- end.join.html_safe
50
+
51
+ res = Hash.new()
52
+ res[:prev] = content_tag(:div, prev, :class => "carousel-control left")
53
+ res[:succ] = content_tag(:div, succ, :class => "carousel-control right")
54
+ return res
55
+ end
54
56
  end
55
57
 
56
58
  end
@@ -1,73 +1,61 @@
1
1
  module Spree
2
2
  class Slide < ActiveRecord::Base
3
3
  belongs_to :slideshow_type
4
+
4
5
  validate :no_attachment_errors
6
+ validates_presence_of :slideshow_type_id
7
+ validates_attachment_presence :attachment
8
+ validates_attachment_content_type :attachment, :content_type => ['image/jpeg', 'image/png', 'image/gif', 'image/jpg', 'image/x-png', 'image/pjpeg'], :message => "deve essere JPG, JPEG, PNG o GIF"
5
9
 
6
10
  attr_accessor :attachment_width, :attachment_height
7
- attr_accessible :title, :url, :attachment_width, :attachment_height, :content, :slideshow_type_id, :attachment, :enable
11
+ attr_accessible :title, :url, :attachment_width, :attachment_height, :content, :slideshow_type_id, :attachment
8
12
 
9
13
  has_attached_file :attachment,
10
14
  :url => "/spree/slides/:id/:style_:basename.:extension",
11
15
  :path => ":rails_root/public/spree/slides/:id/:style_:basename.:extension",
12
16
  :styles => lambda {|a|
13
17
  {
14
- :mini => "100x33#",
18
+ :thumbnail => "100x33#",
15
19
  :small => "300x100#",
16
20
  :medium => "600x200#",
17
- :large => "900x300#",
21
+ :slide => "900x300#",
18
22
  :custom => "#{a.instance.attachment_width}x#{a.instance.attachment_height}#"
19
23
  }
20
24
  },
21
25
  :convert_options => {
22
- :mini => "-gravity center",
26
+ :thumbnail => "-gravity center",
23
27
  :small => "-gravity center",
24
28
  :medium => "-gravity center",
25
- :large => "-gravity center",
29
+ :slide => "-gravity center",
26
30
  :custom => "-gravity center"
27
- }
28
-
29
- validates_presence_of :slideshow_type_id
30
- validates_attachment_presence :attachment
31
- validates_attachment_content_type :attachment, :content_type => ['image/jpeg', 'image/png', 'image/gif', 'image/jpg', 'image/x-png', 'image/pjpeg'], :message => "deve essere JPG, JPEG, PNG o GIF"
32
-
33
- default_scope order("position ASC")
34
- scope :enable, {:conditions => {:enable => true}}
35
- after_post_process :find_dimensions
31
+ }
36
32
 
37
- # Load user defined paperclip settings
38
- if Spree::Config[:use_s3]
39
- s3_creds = { :access_key_id => Spree::Config[:s3_access_key], :secret_access_key => Spree::Config[:s3_secret], :bucket => Spree::Config[:s3_bucket] }
40
- Spree::Slide.attachment_definitions[:attachment][:storage] = :s3
41
- Spree::Slide.attachment_definitions[:attachment][:s3_credentials] = s3_creds
42
- Spree::Slide.attachment_definitions[:attachment][:s3_headers] = ActiveSupport::JSON.decode(Spree::Config[:s3_headers])
43
- Spree::Slide.attachment_definitions[:attachment][:bucket] = Spree::Config[:s3_bucket]
44
- Spree::Slide.attachment_definitions[:attachment][:s3_protocol] = Spree::Config[:s3_protocol] unless Spree::Config[:s3_protocol].blank?
45
- Spree::Slide.attachment_definitions[:attachment][:s3_host_alias] = Spree::Config[:s3_host_alias] unless Spree::Config[:s3_host_alias].blank?
46
- end
33
+ #after_post_process :find_dimensions
34
+
35
+ include Spree::Core::S3Support
36
+ supports_s3 :attachment
47
37
 
48
- Spree::Slide.attachment_definitions[:attachment][:styles] = ActiveSupport::JSON.decode(Spree::Config[:slide_styles])
49
- Spree::Slide.attachment_definitions[:attachment][:path] = Spree::Config[:slide_path]
50
- Spree::Slide.attachment_definitions[:attachment][:url] = Spree::Config[:slide_url]
51
- Spree::Slide.attachment_definitions[:attachment][:default_url] = Spree::Config[:slide_default_url]
52
- Spree::Slide.attachment_definitions[:attachment][:default_style] = Spree::Config[:slide_default_style]
38
+ Spree::Slide.attachment_definitions[:attachment][:styles] = ActiveSupport::JSON.decode(Spree::Config[:attachment_styles])
39
+ Spree::Slide.attachment_definitions[:attachment][:path] = Spree::Config[:attachment_path]
40
+ Spree::Slide.attachment_definitions[:attachment][:url] = Spree::Config[:attachment_url]
41
+ Spree::Slide.attachment_definitions[:attachment][:default_url] = Spree::Config[:attachment_default_url]
42
+ Spree::Slide.attachment_definitions[:attachment][:default_style] = Spree::Config[:attachment_default_style]
53
43
 
54
44
  def initialize(*args)
55
45
  super(*args)
56
- last_slide = Spree::Slide.last
46
+ last_slide = Slide.last
57
47
  self.position = last_slide ? last_slide.position + 1 : 0
58
48
  end
59
49
 
60
50
  def find_dimensions
61
- if self.attachment_width.blank? && self.attachment_height.blank?
62
- temporary = attachment.queued_for_write[:original]
63
- filename = temporary.path unless temporary.nil?
64
- filename = attachment.path if filename.blank?
65
- geometry = Paperclip::Geometry.from_file(filename)
66
- self.attachment_width = geometry.width
67
- self.attachment_height = geometry.height
68
- end
51
+ temporary = attachment.queued_for_write[:original]
52
+ filename = temporary.path unless temporary.nil?
53
+ filename = attachment.path if filename.blank?
54
+ geometry = Paperclip::Geometry.from_file(filename)
55
+ self.attachment_width = geometry.width
56
+ self.attachment_height = geometry.height
69
57
  end
70
-
58
+
71
59
  # if there are errors from the plugin, then add a more meaningful message
72
60
  def no_attachment_errors
73
61
  unless attachment.errors.empty?
@@ -1,12 +1,18 @@
1
1
  module Spree
2
2
  class SlideshowType < ActiveRecord::Base
3
- has_many :slides, :dependent => :destroy
3
+ has_many :slides
4
4
 
5
- attr_accessible :category, :enable_navigation, :enabled, :enable_pagination
5
+ attr_accessible :category, :slide_width, :slide_height, :slide_number, :enable_navigation, :enabled
6
6
 
7
- validates :category, :presence => true
7
+ validates :slide_number, :slide_width, :slide_height, :presence => true
8
8
  validates_uniqueness_of :category
9
-
9
+ validates_numericality_of :slide_number, :only_integer => true
10
+
10
11
  scope :enable, lambda { |category| {:conditions => {:enabled => true, :category => category}} }
12
+
13
+ def initialize(*args)
14
+ super(*args)
15
+ end
16
+
11
17
  end
12
18
  end
@@ -1,9 +1,4 @@
1
1
  Deface::Override.new(:virtual_path => "spree/layouts/admin",
2
2
  :name => "slideshow_type_admin_tab",
3
3
  :insert_bottom => "[data-hook='admin_tabs']",
4
- :text => "<%= tab(:slideshow_types) %>")
5
-
6
- Deface::Override.new(:virtual_path => "spree/admin/configurations/index",
7
- :name => "add_slide_setting_to_configuration_menu",
8
- :insert_bottom => "[data-hook='admin_configurations_menu']",
9
- :partial => "spree/admin/shared/slide_setting_configurations_menu")
4
+ :text => "<%= tab(:slideshow_types) %>")