tb_banners 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4c7779a7c8f87620ecddca6c2da15e4c561066f
4
- data.tar.gz: 430847fd679a36969272e2c00fb794ddc1c2856e
3
+ metadata.gz: ad452499d29ec9a3057ccd4cb8a36c033d63092d
4
+ data.tar.gz: e036c409580661b5e0de416b6742749fdbae9ba8
5
5
  SHA512:
6
- metadata.gz: 864e79857a1ee584d217fdf61a5ce2e85983dd8ab75be57482ddce596ad73e3c54ac3c52402da0a65a096b52893a36f52bb3e7e32e95d7f3b8103f2879a312b9
7
- data.tar.gz: 02894fdec03b82a9d3afe800225c49372f45af427d63f8be0cfb0ad15d956847af4a6ad48dfd28c08840cb56d8f2f2d3e000c2d6048c7cb42c42f79ed5ce5aea
6
+ metadata.gz: 1b7ba0b3b26f430ef451a377302ae412b7a9cbbf2cb3e2896b5fbdac9b9848359852a2805c18b6175c7a90fc766b33f8fc06935d94b6914c06ab8bb37bc3692d
7
+ data.tar.gz: 4af7f96c8d9b8724636bfea43af11c2bc1fe520ab03d0e0615b7d28c5d679b7bd937c25db52bc52568147a2149c2942bef5436de29dd88bde09d1f7af5fb1115
@@ -14,16 +14,25 @@ spud.admin.banners = new function(){
14
14
  if(typeof(FormData) != 'undefined'){
15
15
  html5upload = true;
16
16
  }
17
- $('.spud_banner_add_new').on('click', self.clickedAddNewBanner);
18
- $('.spud_banner_set_banners_container').on('click', '.spud_banner_set_banner_item_edit', self.clickedEditBanner);
19
- $('.spud_banner_set_banners_container').on('click', '.spud_banner_set_banner_item_delete', self.clickedDeleteBanner);
17
+ $('.admin-banner-set-item-add').on('click', self.clickedAddNewBanner);
18
+ $('.admin-banner-set-items-container').on('click', '.admin-banner-set-item-edit', self.clickedEditBanner);
19
+ $('.admin-banner-set-items-container').on('click', '.admin-banner-set-item-delete', self.clickedDeleteBanner);
20
20
  $('.modal-body').on('submit', '.spud_banner_form', self.submittedBannerForm);
21
21
 
22
- $('.spud_banner_set_banners_container').sortable({
23
- stop: self.sortedBanners
22
+ $('.admin-banner-set-items-container').sortable({
23
+ stop: self.sortedBanners,
24
+ helper: fixHelper
24
25
  });
25
26
  };
26
27
 
28
+ // http://www.foliotek.com/devblog/make-table-rows-sortable-using-jquery-ui-sortable/
29
+ var fixHelper = function(e, ui) {
30
+ ui.children().each(function() {
31
+ $(this).width($(this).width());
32
+ });
33
+ return ui;
34
+ };
35
+
27
36
  self.clickedAddNewBanner = function(e){
28
37
  e.preventDefault();
29
38
  bannerEditId = false;
@@ -41,7 +50,7 @@ spud.admin.banners = new function(){
41
50
 
42
51
  self.clickedEditBanner = function(e){
43
52
  e.preventDefault();
44
- bannerEditId = parseInt($(this).parents('.spud_banner_set_banner_item').attr('data-id'), 10);
53
+ bannerEditId = parseInt($(this).parents('.admin-banner-set-item').attr('data-id'), 10);
45
54
  $.ajax({
46
55
  url: $(this).attr('href'),
47
56
  dataType: 'html',
@@ -62,7 +71,7 @@ spud.admin.banners = new function(){
62
71
  type: 'post',
63
72
  data: {'_method':'delete'},
64
73
  complete: function(jqXHR, textStatus){
65
- var parent = el.parents('.spud_banner_set_banner_item');
74
+ var parent = el.parents('.admin-banner-set-item');
66
75
  parent.fadeOut(200, function(){
67
76
  parent.remove();
68
77
  });
@@ -79,12 +88,13 @@ spud.admin.banners = new function(){
79
88
 
80
89
  var form = $(this);
81
90
  var fd = new FormData();
82
- fd.append('_method', form.find('[name=_method]').val());
83
- fd.append('authenticity_token', form.find('[name=authenticity_token]').val());
84
- fd.append('spud_banner[link_to]', form.find('#spud_banner_link_to').val());
85
- fd.append('spud_banner[link_target]', form.find('#spud_banner_link_target').val());
86
- fd.append('spud_banner[title]', form.find('#spud_banner_title').val());
87
- fd.append('spud_banner[alt]', form.find('#spud_banner_alt').val());
91
+
92
+ $('input[type=text], input[type=hidden], select').each(function(index, element){
93
+ var input = $(element);
94
+ var name = input.attr('name');
95
+ var value = input.val();
96
+ fd.append(name, value);
97
+ });
88
98
 
89
99
  var richText = form.find('.spud_banner_rich_text');
90
100
  if(richText){
@@ -142,11 +152,11 @@ spud.admin.banners = new function(){
142
152
  // Non-html5 upload
143
153
  self.onLegacyUploadComplete = function(html){
144
154
  if(bannerEditId){
145
- var item = $('.spud_admin_banner_item[data-id="'+bannerEditId+'"]');
155
+ var item = $('.admin-banner-set-item[data-id="'+bannerEditId+'"]');
146
156
  item.replaceWith(html);
147
157
  }
148
158
  else{
149
- $('.spud_banner_set_banners_container').append(html);
159
+ $('.admin-banner-set-items-container').append(html);
150
160
  }
151
161
  hideModalDialog();
152
162
  };
@@ -157,7 +167,7 @@ spud.admin.banners = new function(){
157
167
 
158
168
  self.sortedBanners = function(e, ui){
159
169
  var ids = [];
160
- $('.spud_banner_set_banner_item').each(function(){
170
+ $('.admin-banner-set-item').each(function(){
161
171
  ids.push($(this).attr('data-id'));
162
172
  });
163
173
  $.ajax({
@@ -0,0 +1,27 @@
1
+ // Banner Management
2
+ .admin-banner-set-items-container{
3
+
4
+ }
5
+ .admin-banner-set-item{
6
+ cursor: move;
7
+ }
8
+ .admin-banner-set-item.ui-sortable-helper{
9
+ width: 940px;
10
+ display: block;
11
+ }
12
+ .admin-banner-set-item img{
13
+ display: block;
14
+ }
15
+ .admin-banner-set-item-nowrap{
16
+ white-space: nowrap;
17
+ }
18
+
19
+ // Banner Form
20
+ .spud_banner_upload_progress{
21
+ display: none;
22
+ }
23
+ .controls-banner-date-selects{
24
+ select{
25
+ width: 100px;
26
+ }
27
+ }
@@ -8,7 +8,7 @@ class Admin::BannersController < Admin::ApplicationController
8
8
  layout false
9
9
 
10
10
  def new
11
- @banner = @banner_set.banners.new
11
+ @banner = @banner_set.banners.new(:start_date => Date.today)
12
12
  respond_with @banner
13
13
  end
14
14
 
@@ -102,7 +102,7 @@ private
102
102
  end
103
103
 
104
104
  def banner_params
105
- params.require(:spud_banner).permit(:banner, :link_to, :link_target, :title, :alt, :sort_order, :rich_text)
105
+ params.require(:spud_banner).permit(:banner, :link_to, :link_target, :title, :alt, :sort_order, :rich_text, :start_date, :end_date)
106
106
  end
107
107
 
108
108
  end
@@ -1,5 +1,13 @@
1
1
  module SpudBannersHelper
2
2
 
3
+ # Returns banner html for a given identifier
4
+ # Generated HTML will be cached if your application uses fragment caching
5
+ #
6
+ # * set_or_identifier: A reference to a SpudBannerSet, or the name of a known banner set passed as a symbol (ie, :home)
7
+ # * options:
8
+ # - limit: Max number of banners to return
9
+ # - background_image: Pass true to return the banners as CSS background-image properties rather than <img/> tags
10
+ #
3
11
  def spud_banners_for_set(set_or_identifier, options = {})
4
12
  if set_or_identifier.is_a?(SpudBannerSet)
5
13
  banner_set = set_or_identifier
@@ -12,22 +20,42 @@ module SpudBannersHelper
12
20
  end
13
21
  end
14
22
 
23
+ # Returns banner html for a given banner_set
24
+ #
25
+ # * banner_set: A reference to a SpudBannerSet
26
+ # * options:
27
+ # - limit: Max number of banners to return
28
+ # - background_image: Pass true to return the banners as CSS background-image properties rather than <img/> tags
29
+ #
15
30
  def spud_banners_set_tag(banner_set, options = {})
16
- limit = options[:limit] || false
31
+ background_image = options.delete(:background_image)
32
+ limit = options.delete(:limit) || false
33
+ banners_query = banner_set.banners.active.limit(limit)
17
34
  if block_given?
18
- banner_set.banners.limit(limit).each do |banner|
35
+ banners_query.each do |banner|
19
36
  yield(banner)
20
37
  end
21
38
  else
22
- content_tag(:div, :class => 'spud_banner_set', 'data-id' => banner_set.id) do
23
- banner_set.banners.limit(limit).map do |banner|
24
- concat(content_tag(:div, :class => 'spud_banner_set_banner', 'data-id' => banner.id){ spud_banner_tag(banner) })
39
+ content_tag(:div, :class => "spud-banner-set #{options[:wrapper_class]}", 'data-id' => banner_set.id) do
40
+ banners_query.map do |banner|
41
+ if background_image
42
+ concat(content_tag(:div, :class => "spud-banner #{options[:banner_class]}", 'data-id' => banner.id, :style => "background:url('#{banner.banner.url(:banner)}') center center / 100% auto no-repeat;"){
43
+ if banner.rich_text
44
+ content_tag :div, raw(banner.rich_text), :class => 'spud-banner-rich-text'
45
+ end
46
+ })
47
+ else
48
+ concat(content_tag(:div, :class => "spud-banner #{options[:banner_class]}", 'data-id' => banner.id){ spud_banner_tag(banner, options) })
49
+ end
25
50
  end
26
51
  end
27
52
  end
28
53
  end
29
54
 
30
- def spud_banner_tag(banner)
55
+ # Returns an HTML tag for a single banner
56
+ # May return either an <img/> or an <a/> depending on the banner
57
+ #
58
+ def spud_banner_tag(banner, options={})
31
59
  if banner.link_to.blank?
32
60
  spud_banner_image_tag(banner)
33
61
  else
@@ -37,6 +65,8 @@ module SpudBannersHelper
37
65
  end
38
66
  end
39
67
 
68
+ # Returns an HTML <img/> tag for a single banner
69
+ #
40
70
  def spud_banner_image_tag(banner)
41
71
  image_tag(banner.banner.url(:banner), :alt => banner.alt, :title => banner.title)
42
72
  end
@@ -1,10 +1,14 @@
1
1
  class SpudBanner < ActiveRecord::Base
2
2
  belongs_to :owner, :class_name => 'SpudBannerSet', :foreign_key => 'spud_banner_set_id', :inverse_of => :banners, :touch => true
3
3
 
4
+ scope :active, ->{
5
+ where('(start_date IS NULL OR start_date <= ?) AND (end_date IS NULL OR end_date >= ?)', Date.today, Date.today)
6
+ }
7
+
4
8
  has_attached_file :banner,
5
9
  :styles => lambda { |attachment| attachment.instance.dynamic_styles },
6
10
  :convert_options => {
7
- :admin_small => '-strip -density 72x72',
11
+ :tiny => '-strip -density 72x72',
8
12
  :banner => '-strip -density 72x72'
9
13
  },
10
14
  :storage => Spud::Banners.paperclip_storage,
@@ -18,7 +22,7 @@ class SpudBanner < ActiveRecord::Base
18
22
 
19
23
  def dynamic_styles
20
24
  styles = {
21
- :spud_admin_small => '300x150'
25
+ :tiny => '150x150'
22
26
  }
23
27
  owner_style = nil
24
28
  if self.owner
@@ -33,4 +37,8 @@ class SpudBanner < ActiveRecord::Base
33
37
  return owner.name
34
38
  end
35
39
 
40
+ def is_expired?
41
+ return end_date.present? && end_date < Date.today
42
+ end
43
+
36
44
  end
@@ -1,10 +1,21 @@
1
1
  <% content_for :data_controls do %>
2
- <%= link_to 'Upload Banner', new_admin_banner_set_banner_path(@banner_set), :class => 'btn btn-primary spud_banner_add_new' %>
2
+ <%= link_to 'Upload Banner', new_admin_banner_set_banner_path(@banner_set), :class => 'btn btn-primary admin-banner-set-item-add' %>
3
3
  <% end %>
4
4
 
5
- <div class="spud_banner_set_banners_container">
6
- <%= render :partial => 'admin/banners/banner', :collection => @banner_set.banners %>
7
- </div>
5
+ <table class="table table-striped">
6
+ <thead>
7
+ <tr>
8
+ <th>Banner</th>
9
+ <th>Start Date</th>
10
+ <th>End Date</th>
11
+ <% if !@banner_set.has_rich_text %>
12
+ <th>Links to</th>
13
+ <% end %>
14
+ </tr>
15
+ </thead>
16
+ <tbody class="admin-banner-set-items-container">
17
+ <%= render :partial => 'admin/banners/banner', :collection => @banner_set.banners %>
18
+ </tbody>
8
19
 
9
20
  <script>
10
21
  $(document).ready(spud.admin.banners.init);
@@ -1,7 +1,27 @@
1
- <%= content_tag :div, 'data-id' => banner.id, :class => 'spud_banner_set_banner_item' do %>
2
- <%= image_tag banner.banner.url(:spud_admin_small) %>
3
- <div class="spud_banner_set_banner_item_actions">
4
- <%= link_to 'Edit', edit_admin_banner_path(banner), :class => 'spud_banner_set_banner_item_edit' %>
5
- <%= link_to 'Delete', admin_banner_path(banner), :class => 'spud_banner_set_banner_item_delete' %>
6
- </div>
7
- <% end %>
1
+ <%= content_tag :tr, 'data-id' => banner.id, :class => 'admin-banner-set-item' do %>
2
+ <td width="200">
3
+ <%= link_to banner.banner.url(:banner), :target => :blank do %>
4
+ <%= image_tag banner.banner.url(:tiny) %>
5
+ <% end %>
6
+ </td>
7
+ <td><%= banner.start_date.try(:strftime, '%m/%d/%Y') %></td>
8
+ <td class="admin-banner-set-item-nowrap">
9
+ <%= banner.end_date.try(:strftime, '%m/%d/%Y') %>
10
+ <% if banner.is_expired? %>
11
+ <span class="label">Expired</span>
12
+ <% end %>
13
+ </td>
14
+ <% if !banner.owner.has_rich_text %>
15
+ <td>
16
+ <% if banner.link_to.present? %>
17
+ <%= link_to banner.link_to, banner.link_to, :target => :blank %>
18
+ <% else %>
19
+ n/a
20
+ <% end %>
21
+ </td>
22
+ <% end %>
23
+ <td class="admin-banner-set-item-nowrap">
24
+ <%= link_to 'Edit', edit_admin_banner_path(banner), :class => 'admin-banner-set-item-edit btn btn-mini' %>
25
+ <%= link_to 'Delete', admin_banner_path(banner), :class => 'admin-banner-set-item-delete btn btn-mini btn-danger' %>
26
+ </td>
27
+ <% end %>
@@ -3,33 +3,6 @@
3
3
  <%= error_messages_for(f.object) %>
4
4
 
5
5
  <fieldset>
6
- <div class="control-group">
7
- <%= f.label :link_to, 'Link to', :class => 'control-label' %>
8
- <div class="controls">
9
- <%= f.text_field :link_to %>
10
- </div>
11
- </div>
12
- <div class="control-group">
13
- <%= f.label :link_target, 'Open Link in', :class => 'control-label' %>
14
- <div class="controls">
15
- <%= f.select :link_target, options_for_select([
16
- ['Same Window', '_self'],
17
- ['New Window', '_blank']
18
- ], @banner.link_target) %>
19
- </div>
20
- </div>
21
- <div class="control-group">
22
- <%= f.label :title, 'Image Title', :class => 'control-label' %>
23
- <div class="controls">
24
- <%= f.text_field :title %>
25
- </div>
26
- </div>
27
- <div class="control-group">
28
- <%= f.label :alt, 'Alt Text', :class => 'control-label' %>
29
- <div class="controls">
30
- <%= f.text_field :alt %>
31
- </div>
32
- </div>
33
6
  <div class="control-group">
34
7
  <%= f.label :banner, 'Banner', :class => 'control-label' %>
35
8
  <div class="controls">
@@ -43,7 +16,48 @@
43
16
  <%= f.text_area :rich_text, :class => 'spud_banner_rich_text' %>
44
17
  </div>
45
18
  </div>
19
+ <% else %>
20
+ <div class="control-group">
21
+ <%= f.label :link_to, 'Link to', :class => 'control-label' %>
22
+ <div class="controls">
23
+ <%= f.text_field :link_to %>
24
+ </div>
25
+ </div>
26
+ <div class="control-group">
27
+ <%= f.label :link_target, 'Open Link in', :class => 'control-label' %>
28
+ <div class="controls">
29
+ <%= f.select :link_target, options_for_select([
30
+ ['Same Window', '_self'],
31
+ ['New Window', '_blank']
32
+ ], @banner.link_target) %>
33
+ </div>
34
+ </div>
35
+ <div class="control-group">
36
+ <%= f.label :title, 'Image Title', :class => 'control-label' %>
37
+ <div class="controls">
38
+ <%= f.text_field :title %>
39
+ </div>
40
+ </div>
41
+ <div class="control-group">
42
+ <%= f.label :alt, 'Alt Text', :class => 'control-label' %>
43
+ <div class="controls">
44
+ <%= f.text_field :alt %>
45
+ </div>
46
+ </div>
46
47
  <% end %>
48
+ <div class="control-group">
49
+ <%= f.label :start_date, 'Start Date', :class => 'control-label' %>
50
+ <div class="controls controls-banner-date-selects">
51
+ <%= f.date_select :start_date, :start_year => Date.today.year %>
52
+ </div>
53
+ </div>
54
+ <div class="control-group">
55
+ <%= f.label :end_date, 'End Date', :class => 'control-label' %>
56
+ <div class="controls controls-banner-date-selects">
57
+ <%= f.date_select :end_date, :include_blank => true, :start_year => Date.today.year %>
58
+ <span class="help-block">Leave blank to never expire</span>
59
+ </div>
60
+ </div>
47
61
  </fieldset>
48
62
 
49
63
  <div class="progress progress-striped active spud_banner_upload_progress">
@@ -0,0 +1,6 @@
1
+ class AddStartAndEndDatesToSpudBanners < ActiveRecord::Migration
2
+ def change
3
+ add_column :spud_banners, :start_date, :date
4
+ add_column :spud_banners, :end_date, :date
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  module Spud
2
2
  module Banners
3
- VERSION = "1.1.1"
3
+ VERSION = "1.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tb_banners
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Westlake
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-17 00:00:00.000000000 Z
11
+ date: 2014-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -189,13 +189,12 @@ files:
189
189
  - README.markdown
190
190
  - Rakefile
191
191
  - app/assets/images/admin/banners/banners.png
192
- - app/assets/images/admin/banners/banners@2x.png
193
192
  - app/assets/javascripts/admin/banners/application.js
194
193
  - app/assets/javascripts/admin/banners/banner_sets.js
195
194
  - app/assets/javascripts/admin/banners/banners.js
196
195
  - app/assets/stylesheets/admin/banners/application.css
197
196
  - app/assets/stylesheets/admin/banners/banner_sets.css
198
- - app/assets/stylesheets/admin/banners/banners.css
197
+ - app/assets/stylesheets/admin/banners/banners.css.scss
199
198
  - app/controllers/admin/banner_sets_controller.rb
200
199
  - app/controllers/admin/banners_controller.rb
201
200
  - app/helpers/admin/banner_sets_helper.rb
@@ -220,6 +219,7 @@ files:
220
219
  - db/migrate/20121116195139_create_spud_banners.rb
221
220
  - db/migrate/20121116195312_create_spud_banner_sets.rb
222
221
  - db/migrate/20130614132846_add_rich_text_to_spud_banners.rb
222
+ - db/migrate/20140721142719_add_start_and_end_dates_to_spud_banners.rb
223
223
  - lib/spud_banners/configuration.rb
224
224
  - lib/spud_banners/engine.rb
225
225
  - lib/spud_banners/liquid_tags.rb
@@ -1,36 +0,0 @@
1
- /*
2
- Place all the styles related to the matching controller here.
3
- They will automatically be included in application.css.
4
- */
5
-
6
- /* Banner Management
7
- -------------------- */
8
- .spud_banner_set_banners_container{
9
-
10
- }
11
- .spud_banner_set_banner_item{
12
- padding: 0 10px 10px 0;
13
- position: relative;
14
- display: inline-block;
15
- cursor: move;
16
- float: left;
17
- }
18
- .spud_banner_set_banner_item img{
19
- display: inline-block;
20
- }
21
- .spud_banner_set_banner_item_actions{
22
- position: absolute;
23
- bottom: 10px;
24
- right: 10px;
25
- padding: 5px 10px;
26
- background: rgba(0, 0, 0, 0.5);
27
- }
28
- .spud_banner_set_banner_item_actions a{
29
- color: white;
30
- }
31
-
32
- /* Banner Form
33
- --------------- */
34
- .spud_banner_upload_progress{
35
- display: none;
36
- }