spree_multi_slideshow 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/README.md +14 -12
  2. data/app/assets/images/store/bx_loader.gif +0 -0
  3. data/app/assets/images/store/controls.png +0 -0
  4. data/app/assets/javascripts/admin/slide_settings.js.erb +41 -0
  5. data/app/assets/javascripts/admin/slides/index.js.coffee +15 -0
  6. data/app/assets/javascripts/admin/slides/new.js.coffee +7 -0
  7. data/app/assets/javascripts/admin/spree_multi_slideshow.js +3 -1
  8. data/app/assets/javascripts/store/spree_multi_slideshow.js +1284 -1
  9. data/app/assets/stylesheets/store/spree_multi_slideshow.css +197 -3
  10. data/app/controllers/spree/admin/slide_settings_controller.rb +50 -0
  11. data/app/controllers/spree/admin/slides_controller.rb +15 -14
  12. data/app/controllers/spree/admin/slideshows_controller.rb +31 -0
  13. data/app/helpers/spree/slideshows_helper.rb +68 -0
  14. data/app/models/spree/app_configuration_decorator.rb +25 -0
  15. data/app/models/spree/product_decorator.rb +3 -0
  16. data/app/models/spree/slide.rb +23 -25
  17. data/app/models/spree/slideshow.rb +17 -0
  18. data/app/models/spree/taxon_decorator.rb +3 -0
  19. data/app/overrides/slideshow_admin_tab.rb +10 -0
  20. data/app/views/spree/admin/shared/_slideshow_sub_menu.html.erb +6 -0
  21. data/app/views/spree/admin/shared/_slideshow_tabs.html.erb +21 -0
  22. data/app/views/spree/admin/slide_settings/edit.html.erb +74 -0
  23. data/app/views/spree/admin/slides/_form.html.erb +29 -9
  24. data/app/views/spree/admin/slides/edit.html.erb +26 -16
  25. data/app/views/spree/admin/slides/index.html.erb +47 -31
  26. data/app/views/spree/admin/slides/new.html.erb +12 -9
  27. data/app/views/spree/admin/slideshows/_form.html.erb +59 -0
  28. data/app/views/spree/admin/slideshows/edit.html.erb +17 -0
  29. data/app/views/spree/admin/slideshows/index.html.erb +51 -0
  30. data/app/views/spree/admin/slideshows/new.html.erb +80 -0
  31. data/app/views/spree/admin/slideshows/new.js.erb +2 -0
  32. data/config/locales/en.yml +53 -85
  33. data/config/locales/it.yml +56 -90
  34. data/config/routes.rb +3 -1
  35. data/db/migrate/20120116081431_create_slideshows.rb +17 -0
  36. data/db/migrate/20120116083546_create_slides.rb +5 -4
  37. data/db/migrate/20120323164044_multi_slideshow_namespace.rb +1 -1
  38. data/lib/generators/spree_multi_slideshow/install/install_generator.rb +1 -21
  39. data/lib/spree_multi_slideshow.rb +0 -2
  40. metadata +26 -73
  41. data/app/assets/images/store/slides/bg-gallery.png +0 -0
  42. data/app/assets/images/store/slides/bg-text02.png +0 -0
  43. data/app/assets/images/store/slides/sprite01.png +0 -0
  44. data/app/assets/javascripts/admin/slides/index.js +0 -10
  45. data/app/assets/javascripts/admin/slides/new.js +0 -5
  46. data/app/assets/javascripts/store/fadeGallery.js +0 -229
  47. data/app/assets/stylesheets/admin/spree_multi_slideshow.css +0 -16
  48. data/app/assets/stylesheets/store/carousel_slideshow.css.scss +0 -73
  49. data/app/controllers/spree/admin/slideshow_types_controller.rb +0 -11
  50. data/app/controllers/spree/slides_controller.rb +0 -5
  51. data/app/controllers/spree/slideshow_types_controller.rb +0 -5
  52. data/app/helpers/spree/slides_helper.rb +0 -4
  53. data/app/helpers/spree/slideshow_types_helper.rb +0 -53
  54. data/app/models/spree/slideshow_type.rb +0 -18
  55. data/app/overrides/slideshow_type_admin_tab.rb +0 -4
  56. data/app/views/spree/admin/shared/_slideshow_type_tabs.html.erb +0 -16
  57. data/app/views/spree/admin/slideshow_types/_form.html.erb +0 -8
  58. data/app/views/spree/admin/slideshow_types/edit.html.erb +0 -8
  59. data/app/views/spree/admin/slideshow_types/index.html.erb +0 -32
  60. data/app/views/spree/admin/slideshow_types/new.html.erb +0 -7
  61. data/db/migrate/20120116081431_create_slideshow_types.rb +0 -15
@@ -1,3 +1,197 @@
1
- /*
2
- *= require store/carousel_slideshow
3
- */
1
+ /**
2
+ * BxSlider v4.0 - Fully loaded, responsive content slider
3
+ * http://bxslider.com
4
+ *
5
+ * Written by: Steven Wanderski, 2012
6
+ * http://stevenwanderski.com
7
+ * (while drinking Belgian ales and listening to jazz)
8
+ *
9
+ * CEO and founder of bxCreative, LTD
10
+ * http://bxcreative.com
11
+ */
12
+
13
+
14
+ /** RESET AND LAYOUT
15
+ ===================================*/
16
+
17
+ .bx-wrapper {
18
+ position: relative;
19
+ margin: 0 0 60px;
20
+ padding: 0;
21
+ *zoom: 1;
22
+ }
23
+
24
+ .bx-wrapper img {
25
+ width: 100%;
26
+ display: block;
27
+ }
28
+
29
+ /** THEME
30
+ ===================================*/
31
+
32
+ .bx-wrapper .bx-viewport {
33
+ -moz-box-shadow: 0 0 5px #ccc;
34
+ -webkit-box-shadow: 0 0 5px #ccc;
35
+ box-shadow: 0 0 5px #ccc;
36
+ border: solid #fff 5px;
37
+ left: -5px;
38
+ background: #fff;
39
+ }
40
+
41
+ .bx-wrapper .bx-pager,
42
+ .bx-wrapper .bx-controls-auto {
43
+ position: absolute;
44
+ bottom: -30px;
45
+ width: 100%;
46
+ }
47
+
48
+ /* LOADER */
49
+
50
+ .bx-wrapper .bx-loading {
51
+ min-height: 50px;
52
+ background: url(/assets/store/bx_loader.gif) center center no-repeat #fff;
53
+ height: 100%;
54
+ width: 100%;
55
+ position: absolute;
56
+ top: 0;
57
+ left: 0;
58
+ z-index: 2000;
59
+ }
60
+
61
+ /* PAGER */
62
+
63
+ .bx-wrapper .bx-pager {
64
+ text-align: center;
65
+ font-size: .85em;
66
+ font-family: Arial;
67
+ font-weight: bold;
68
+ color: #666;
69
+ padding-top: 20px;
70
+ }
71
+
72
+ .bx-wrapper .bx-pager .bx-pager-item,
73
+ .bx-wrapper .bx-controls-auto .bx-controls-auto-item {
74
+ display: inline-block;
75
+ *zoom: 1;
76
+ *display: inline;
77
+ }
78
+
79
+ .bx-wrapper .bx-pager.bx-default-pager a {
80
+ background: #666;
81
+ text-indent: -9999px;
82
+ display: block;
83
+ width: 10px;
84
+ height: 10px;
85
+ margin: 0 5px;
86
+ outline: 0;
87
+ -moz-border-radius: 5px;
88
+ -webkit-border-radius: 5px;
89
+ border-radius: 5px;
90
+ }
91
+
92
+ .bx-wrapper .bx-pager.bx-default-pager a:hover,
93
+ .bx-wrapper .bx-pager.bx-default-pager a.active {
94
+ background: #000;
95
+ }
96
+
97
+ /* DIRECTION CONTROLS (NEXT / PREV) */
98
+
99
+ .bx-wrapper .bx-prev {
100
+ left: 10px;
101
+ background: url(/assets/store/controls.png) no-repeat 0 -32px;
102
+ }
103
+
104
+ .bx-wrapper .bx-next {
105
+ right: 10px;
106
+ background: url(/assets/store/controls.png) no-repeat -43px -32px;
107
+ }
108
+
109
+ .bx-wrapper .bx-prev:hover {
110
+ background-position: 0 0;
111
+ }
112
+
113
+ .bx-wrapper .bx-next:hover {
114
+ background-position: -43px 0;
115
+ }
116
+
117
+ .bx-wrapper .bx-controls-direction a {
118
+ position: absolute;
119
+ top: 50%;
120
+ margin-top: -16px;
121
+ outline: 0;
122
+ width: 32px;
123
+ height: 32px;
124
+ text-indent: -9999px;
125
+ z-index: 9999;
126
+ }
127
+
128
+ .bx-wrapper .bx-controls-direction a.disabled {
129
+ display: none;
130
+ }
131
+
132
+ /* AUTO CONTROLS (START / STOP) */
133
+
134
+ .bx-wrapper .bx-controls-auto {
135
+ text-align: center;
136
+ }
137
+
138
+ .bx-wrapper .bx-controls-auto .bx-start {
139
+ display: block;
140
+ text-indent: -9999px;
141
+ width: 10px;
142
+ height: 11px;
143
+ outline: 0;
144
+ background: url(/assets/store/controls.png) -86px -11px no-repeat;
145
+ margin: 0 3px;
146
+ }
147
+
148
+ .bx-wrapper .bx-controls-auto .bx-start:hover,
149
+ .bx-wrapper .bx-controls-auto .bx-start.active {
150
+ background-position: -86px 0;
151
+ }
152
+
153
+ .bx-wrapper .bx-controls-auto .bx-stop {
154
+ display: block;
155
+ text-indent: -9999px;
156
+ width: 9px;
157
+ height: 11px;
158
+ outline: 0;
159
+ background: url(/assets/store/controls.png) -86px -44px no-repeat;
160
+ margin: 0 3px;
161
+ }
162
+
163
+ .bx-wrapper .bx-controls-auto .bx-stop:hover,
164
+ .bx-wrapper .bx-controls-auto .bx-stop.active {
165
+ background-position: -86px -33px;
166
+ }
167
+
168
+ /* PAGER WITH AUTO-CONTROLS HYBRID LAYOUT */
169
+
170
+ .bx-wrapper .bx-controls.bx-has-controls-auto.bx-has-pager .bx-pager {
171
+ text-align: left;
172
+ width: 80%;
173
+ }
174
+
175
+ .bx-wrapper .bx-controls.bx-has-controls-auto.bx-has-pager .bx-controls-auto {
176
+ right: 0;
177
+ width: 35px;
178
+ }
179
+
180
+ /* IMAGE CAPTIONS */
181
+
182
+ .bx-wrapper .bx-caption {
183
+ position: absolute;
184
+ bottom: 0;
185
+ left: 0;
186
+ background: #666\9;
187
+ background: rgba(80, 80, 80, 0.75);
188
+ width: 100%;
189
+ }
190
+
191
+ .bx-wrapper .bx-caption span {
192
+ color: #fff;
193
+ font-family: Arial;
194
+ display: block;
195
+ font-size: .85em;
196
+ padding: 10px;
197
+ }
@@ -0,0 +1,50 @@
1
+ module Spree
2
+ module Admin
3
+ class SlideSettingsController < Spree::Admin::BaseController
4
+
5
+ def show
6
+ redirect_to( :action => :edit )
7
+ end
8
+
9
+ def edit
10
+ @styles = ActiveSupport::JSON.decode(Spree::Config[:slide_styles])
11
+ end
12
+
13
+ def update
14
+ update_styles(params)
15
+
16
+ Spree::Config.set(params[:preferences])
17
+ update_paperclip_settings
18
+
19
+ respond_to do |format|
20
+ format.html {
21
+ flash[:success] = t(:slide_settings_updated)
22
+ redirect_to edit_admin_slide_settings_path
23
+ }
24
+ end
25
+ end
26
+
27
+
28
+ private
29
+
30
+ def update_styles(params)
31
+ params[:new_slide_styles].each do |index, style|
32
+ params[:slide_styles][style[:name]] = style[:value] unless style[:value].empty?
33
+ end if params[:new_slide_styles].present?
34
+
35
+ styles = params[:slide_styles]
36
+
37
+ Spree::Config[:slide_styles] = ActiveSupport::JSON.encode(styles) unless styles.nil?
38
+ end
39
+
40
+ def update_paperclip_settings
41
+
42
+ Spree::Slide.attachment_definitions[:attachment][:styles] = ActiveSupport::JSON.decode(Spree::Config[:slide_styles])
43
+ Spree::Slide.attachment_definitions[:attachment][:path] = Spree::Config[:slide_path]
44
+ Spree::Slide.attachment_definitions[:attachment][:default_url] = Spree::Config[:slide_default_url]
45
+ Spree::Slide.attachment_definitions[:attachment][:default_style] = Spree::Config[:slide_default_style]
46
+ end
47
+ end
48
+ end
49
+ end
50
+
@@ -1,26 +1,27 @@
1
1
  module Spree
2
2
  module Admin
3
3
  class SlidesController < ResourceController
4
- before_filter :load_data, :only => [:index, :new, :show, :edit]
4
+ before_filter :load_data
5
5
 
6
- def update_positions
7
- params[:positions].each do |id, index|
8
- Spree::Slide.update_all(['position=?', index], ['id=?', id])
9
- end
6
+ create.before :set_slideshow
7
+ update.before :set_slideshow
8
+ destroy.before :destroy_before
10
9
 
11
- respond_to do |format|
12
- format.html { redirect_to admin_slideshow_type_slides_url(@slideshow_type) }
13
- format.js { render :text => 'Ok' }
14
- end
15
- end
16
-
17
- protected
10
+ private
18
11
  def location_after_save
19
- admin_slideshow_type_slides_url(@slideshow_type)
12
+ admin_slideshow_slides_url(@slideshow)
20
13
  end
21
14
 
22
15
  def load_data
23
- @slideshow_type = Spree::SlideshowType.find(params[:slideshow_type_id].to_i)
16
+ @slideshow = Spree::Slideshow.find(params[:slideshow_id])
17
+ end
18
+
19
+ def set_slideshow
20
+ @slide.slideshow_id = params[:slideshow_id]
21
+ end
22
+
23
+ def destroy_before
24
+ @viewable = @slide.slideshow
24
25
  end
25
26
 
26
27
  end
@@ -0,0 +1,31 @@
1
+ module Spree
2
+ module Admin
3
+ class SlideshowsController < ResourceController
4
+ def index
5
+ respond_with(@collection)
6
+ end
7
+
8
+ def show
9
+ redirect_to( :action => :edit )
10
+ end
11
+
12
+ protected
13
+ def find_resource
14
+ Spree::Slideshow.find(params[:id])
15
+ end
16
+
17
+ def location_after_save
18
+ edit_admin_slideshow_url(@slideshow)
19
+ end
20
+
21
+ def collection
22
+ return @collection if @collection.present?
23
+ params[:q] ||= {}
24
+ params[:q][:s] ||= "category asc"
25
+
26
+ @search = super.ransack(params[:q])
27
+ @collection = @search.result
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,68 @@
1
+ # encoding: UTF-8
2
+ module Spree
3
+ module SlideshowsHelper
4
+
5
+ def insert_slideshow(params={})
6
+ params[:id] ||= "slideshow"
7
+ params[:class] ||= "first_slideshow"
8
+ params[:category] ||= "home"
9
+ params[:auto] ||= false
10
+ params[:next_text] ||= '>>'
11
+ params[:prev_text] ||= '<<'
12
+ params[:next_selector] ||= 'bx-next'
13
+ params[:prev_selector] ||= 'bx-prev'
14
+ @@slideshow = Spree::Slideshow.enable(params[:category]).try(:first)
15
+ if @@slideshow.blank? || (!@@slideshow.blank? && @@slideshow.slides.enable.empty?)
16
+ return ''
17
+ end
18
+ params[:pagination_class] ||= ""
19
+ res = []
20
+
21
+ res << content_tag(:ul, slide_images(params, @@slideshow), :class => "bxslider #{params[:class]}", :id => params[:id])
22
+ res << "<script type='text/javascript'>
23
+ $(function() {
24
+ $('##{params[:id]}').bxSlider({
25
+ auto: #{params[:auto]},
26
+ adaptiveHeight: true,
27
+ autoStart: #{@@slideshow.auto_start},
28
+ mode: '#{@@slideshow.mode}',
29
+ controls: #{@@slideshow.enable_navigation},
30
+ nextText: '#{params[:next_text]}',
31
+ nextSelector: '#{params[:next_selector]}',
32
+ prevText: '#{params[:prev_text]}',
33
+ prevSelector: '#{params[:prev_selector]}',
34
+ speed: 2000,
35
+ pager: #{@@slideshow.enable_pagination},
36
+ infiniteLoop: #{@@slideshow.infinite_loop},
37
+ hideControlOnEnd: #{@@slideshow.hide_control_on_end},
38
+ autoHover: true,
39
+ useCSS: true,
40
+ pagerSelector: '#{params[:pagination_class]}'
41
+ });
42
+ });
43
+ </script>"
44
+
45
+ res.join.html_safe
46
+ end
47
+
48
+ def slide_images(params, slideshow)
49
+ params[:style] ||= "medium"
50
+ params[:show_content] ||= false
51
+ slides = slideshow.slides.enable.sort_by { |slide| slide.position }
52
+
53
+ slides.map do |slide|
54
+ content_tag(:li, :class => "slides") do
55
+ divs = []
56
+
57
+ divs << link_to(image_tag(slide.attachment.url(params[:style].to_sym)), (slide.url.blank? ? "javascript: void(0)" : slide.url), { :title => slide.title })
58
+ if params[:show_content]
59
+ divs << content_tag(:div, content_tag(:strong, raw(slide.title)) + content_tag(:p, raw(slide.presentation)), :class => "caption")
60
+ end
61
+
62
+ divs.join.html_safe
63
+ end
64
+ end.join.html_safe
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,25 @@
1
+ # This is the primary location for defining spree preferences
2
+ #
3
+ # The expectation is that this is created once and stored in
4
+ # the spree environment
5
+ #
6
+ # setters:
7
+ # a.color = :blue
8
+ # a[:color] = :blue
9
+ # a.set :color = :blue
10
+ # a.preferred_color = :blue
11
+ #
12
+ # getters:
13
+ # a.color
14
+ # a[:color]
15
+ # a.get :color
16
+ # a.preferred_color
17
+ #
18
+ Spree::AppConfiguration.class_eval do
19
+ # Preferences related to slide settings
20
+ preference :slide_default_url, :string, :default => '/spree/slides/:id/:style/:basename.:extension'
21
+ preference :slide_path, :string, :default => ':rails_root/public/spree/slides/:id/:style/:basename.:extension'
22
+ preference :slide_url, :string, :default => '/spree/slides/:id/:style/:basename.:extension'
23
+ preference :slide_styles, :string, :default => "{\"mini\":\"60x60#\",\"small\":\"300x100#\",\"medium\":\"600x200#\",\"large\":\"900x300#\"}"
24
+ preference :slide_default_style, :string, :default => 'medium'
25
+ end
@@ -0,0 +1,3 @@
1
+ Spree::Product.class_eval do
2
+ has_many :slides, :as => :slideable
3
+ end
@@ -1,49 +1,47 @@
1
1
  module Spree
2
2
  class Slide < ActiveRecord::Base
3
- belongs_to :slideshow_type
3
+ belongs_to :slideshow
4
+
5
+ belongs_to :slideable, :polymorphic => true
4
6
 
5
7
  validate :no_attachment_errors
6
- validates_presence_of :slideshow_type_id
8
+ validates_presence_of :slideshow_id
7
9
  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"
10
+ validates_attachment_content_type :attachment, :content_type => ['image/jpeg', 'image/png', 'image/gif', 'image/jpg', 'image/x-png', 'image/pjpeg'], :message => I18n.t(:images_only)
9
11
 
10
12
  attr_accessor :attachment_width, :attachment_height
11
- attr_accessible :title, :url, :attachment_width, :attachment_height, :content, :slideshow_type_id, :attachment
13
+ attr_accessible :title, :url, :enabled, :presentation, :slideshow_id, :attachment
12
14
 
13
15
  has_attached_file :attachment,
14
16
  :url => "/spree/slides/:id/:style_:basename.:extension",
15
17
  :path => ":rails_root/public/spree/slides/:id/:style_:basename.:extension",
16
- :styles => lambda {|a|
17
- {
18
- :thumbnail => "100x33#",
18
+ :styles => lambda {|a|{
19
+ :mini => "60x60#",
19
20
  :small => "300x100#",
20
21
  :medium => "600x200#",
21
- :slide => "900x300#",
22
+ :large => "900x300#",
22
23
  :custom => "#{a.instance.attachment_width}x#{a.instance.attachment_height}#"
23
- }
24
- },
25
- :convert_options => {
26
- :thumbnail => "-gravity center",
27
- :small => "-gravity center",
28
- :medium => "-gravity center",
29
- :slide => "-gravity center",
30
- :custom => "-gravity center"
31
- }
24
+ }},
25
+ :convert_options => { :all => '-strip -auto-orient' }
26
+ # save the w,h of the original image (from which others can be calculated)
27
+ # we need to look at the write-queue for images which have not been saved yet
28
+ after_post_process :find_dimensions
32
29
 
33
- #after_post_process :find_dimensions
30
+ default_scope order("position ASC")
31
+ scope :enable, {:conditions => {:enabled => true}}
34
32
 
35
33
  include Spree::Core::S3Support
36
34
  supports_s3 :attachment
37
35
 
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]
36
+ Spree::Slide.attachment_definitions[:attachment][:styles] = ActiveSupport::JSON.decode(Spree::Config[:slide_styles])
37
+ Spree::Slide.attachment_definitions[:attachment][:path] = Spree::Config[:slide_path]
38
+ Spree::Slide.attachment_definitions[:attachment][:url] = Spree::Config[:slide_url]
39
+ Spree::Slide.attachment_definitions[:attachment][:default_url] = Spree::Config[:slide_default_url]
40
+ Spree::Slide.attachment_definitions[:attachment][:default_style] = Spree::Config[:slide_default_style]
43
41
 
44
42
  def initialize(*args)
45
43
  super(*args)
46
- last_slide = Slide.last
44
+ last_slide = Spree::Slide.last
47
45
  self.position = last_slide ? last_slide.position + 1 : 0
48
46
  end
49
47
 
@@ -52,7 +50,7 @@ module Spree
52
50
  filename = temporary.path unless temporary.nil?
53
51
  filename = attachment.path if filename.blank?
54
52
  geometry = Paperclip::Geometry.from_file(filename)
55
- self.attachment_width = geometry.width
53
+ self.attachment_width = geometry.width
56
54
  self.attachment_height = geometry.height
57
55
  end
58
56