tb_banners 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +15 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.markdown +144 -0
  4. data/Rakefile +40 -0
  5. data/app/assets/images/spud/admin/banners/banners.png +0 -0
  6. data/app/assets/images/spud/admin/banners/banners@2x.png +0 -0
  7. data/app/assets/javascripts/spud/admin/banners/application.js +2 -0
  8. data/app/assets/javascripts/spud/admin/banners/banner_sets.js +102 -0
  9. data/app/assets/javascripts/spud/admin/banners/banners.js +187 -0
  10. data/app/assets/stylesheets/spud/admin/banners/application.css +4 -0
  11. data/app/assets/stylesheets/spud/admin/banners/banner_sets.css +27 -0
  12. data/app/assets/stylesheets/spud/admin/banners/banners.css +36 -0
  13. data/app/controllers/spud/admin/banner_sets_controller.rb +68 -0
  14. data/app/controllers/spud/admin/banners_controller.rb +104 -0
  15. data/app/helpers/spud/admin/banner_sets_helper.rb +2 -0
  16. data/app/helpers/spud/admin/banners_helper.rb +2 -0
  17. data/app/helpers/spud_banners_helper.rb +38 -0
  18. data/app/models/spud_banner.rb +35 -0
  19. data/app/models/spud_banner_set.rb +30 -0
  20. data/app/observers/spud_banner_sweeper.rb +52 -0
  21. data/app/views/spud/admin/banner_sets/_banner_set.html.erb +8 -0
  22. data/app/views/spud/admin/banner_sets/_form.html.erb +38 -0
  23. data/app/views/spud/admin/banner_sets/create.html.erb +1 -0
  24. data/app/views/spud/admin/banner_sets/edit.html.erb +1 -0
  25. data/app/views/spud/admin/banner_sets/index.html.erb +12 -0
  26. data/app/views/spud/admin/banner_sets/new.html.erb +1 -0
  27. data/app/views/spud/admin/banner_sets/show.html.erb +11 -0
  28. data/app/views/spud/admin/banners/_banner.html.erb +7 -0
  29. data/app/views/spud/admin/banners/_form.html.erb +59 -0
  30. data/app/views/spud/admin/banners/edit.html.erb +1 -0
  31. data/app/views/spud/admin/banners/legacy.js.erb +5 -0
  32. data/app/views/spud/admin/banners/new.html.erb +1 -0
  33. data/app/views/spud/admin/banners/show.html.erb +1 -0
  34. data/config/routes.rb +14 -0
  35. data/db/migrate/20121116195139_create_spud_banners.rb +15 -0
  36. data/db/migrate/20121116195312_create_spud_banner_sets.rb +12 -0
  37. data/db/migrate/20130614132846_add_rich_text_to_spud_banners.rb +6 -0
  38. data/lib/spud_banners/configuration.rb +10 -0
  39. data/lib/spud_banners/engine.rb +25 -0
  40. data/lib/spud_banners/liquid_tags.rb +32 -0
  41. data/lib/spud_banners/version.rb +5 -0
  42. data/lib/tasks/spud_banners_tasks.rake +4 -0
  43. data/lib/tb_banners.rb +7 -0
  44. data/spec/controllers/spud/admin/banner_sets_controller_spec.rb +100 -0
  45. data/spec/dummy/README.rdoc +261 -0
  46. data/spec/dummy/Rakefile +7 -0
  47. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  48. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  49. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  50. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  51. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  52. data/spec/dummy/config/application.rb +59 -0
  53. data/spec/dummy/config/boot.rb +10 -0
  54. data/spec/dummy/config/database.yml +14 -0
  55. data/spec/dummy/config/environment.rb +5 -0
  56. data/spec/dummy/config/environments/development.rb +37 -0
  57. data/spec/dummy/config/environments/production.rb +67 -0
  58. data/spec/dummy/config/environments/test.rb +37 -0
  59. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  60. data/spec/dummy/config/initializers/inflections.rb +15 -0
  61. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  62. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  63. data/spec/dummy/config/initializers/session_store.rb +8 -0
  64. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  65. data/spec/dummy/config/locales/en.yml +5 -0
  66. data/spec/dummy/config/routes.rb +3 -0
  67. data/spec/dummy/config.ru +4 -0
  68. data/spec/dummy/db/migrate/20121127192246_create_spud_admin_permissions.spud_core.rb +12 -0
  69. data/spec/dummy/db/migrate/20121127192247_create_spud_users.spud_core.rb +30 -0
  70. data/spec/dummy/db/migrate/20121127192248_add_time_zone_to_spud_user.spud_core.rb +7 -0
  71. data/spec/dummy/db/migrate/20121127192249_add_scope_to_spud_admin_permissions.spud_core.rb +7 -0
  72. data/spec/dummy/db/migrate/20121127192250_create_spud_user_settings.spud_core.rb +12 -0
  73. data/spec/dummy/db/schema.rb +87 -0
  74. data/spec/dummy/log/development.log +72 -0
  75. data/spec/dummy/log/test.log +9059 -0
  76. data/spec/dummy/public/404.html +26 -0
  77. data/spec/dummy/public/422.html +26 -0
  78. data/spec/dummy/public/500.html +25 -0
  79. data/spec/dummy/public/favicon.ico +0 -0
  80. data/spec/dummy/script/rails +6 -0
  81. data/spec/spec_helper.rb +40 -0
  82. data/spec/support/authlogic_helper.rb +2 -0
  83. metadata +331 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YjNjOTQ4ZjZhOGZmYzJmMzdlNTlmY2UzMjhkODBjZmE2ZTE3YzYzYg==
5
+ data.tar.gz: !binary |-
6
+ ODY0OTE5ZTQxNTc2MTkzNmYxOWIwYmZjNDhhYTM2OTQyZDNmNDg4YQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZGU5N2FlNmYzNDk0ZDVkODE0ZDZjYTA4ZDg3ZjEyNWU0NzQ1YmQyYzUwODcx
10
+ OGMxMjZhMzI0OWY2OTViN2Q1MTU2OGVjODNjMWMwZDY5MTYzMmEwMWE2Mzcw
11
+ YjllNWUxNTQ0OTNkNTlkMWNhZjEwMDc2NjNkZWIwODBkNjQ1Zjg=
12
+ data.tar.gz: !binary |-
13
+ MjAyZjRjODc3ZWIyYTljMTczZWI3ZGI4NzJiNzhjNjNjZjM2YmYxN2ZmNDg3
14
+ ZThlMDQyY2Y4MzQyNTI4MTQ0NGZjNjk4MTM0NTlhM2E0OWQ4ZGI2NDFjYTc0
15
+ NmYzOThjMTQ5NWJhYmU1MTJhYzc5YzkwZjc0MDI1ZGE0YzRlOGI=
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,144 @@
1
+ # Spud Banners
2
+
3
+ Spud Banners is an engine for creating and managing rotating banner sets, designed for use with [Spud][spud].
4
+
5
+ ## Installation/Usage
6
+
7
+ 1. In your Gemfile add the following
8
+
9
+ gem 'spud_banners'
10
+
11
+ 2. Run bundle install
12
+ 3. Copy in database migrations to your new rails project
13
+
14
+ bundle exec rake railties:install:migrations
15
+ rake db:migrate
16
+
17
+ 4. Run a rails server instance and point your browser to `/spud/admin`
18
+
19
+ ## Configuration
20
+
21
+ Spud Banners accepts the following configuration options:
22
+
23
+ ```ruby
24
+ Spud::Banners.configure do |config|
25
+ config.paperclip_storage = :filesystem #use :s3 to use s3 storage (aws gem required)
26
+ config.s3_credentials = "#{Rails.root}/config/s3.yml"
27
+ config.storage_path = ":rails_root/public/system/spud_banners/:id/:style/:basename.:extension"
28
+ config.storage_url = "/system/spud_banners/:id/:style/:basename.:extension"
29
+ end
30
+ ```
31
+
32
+ ## Creating a Banner Set
33
+
34
+ Banner Sets are created in the Spud admin. When creating a Set, you have the following options:
35
+
36
+ - **Name:** The unique identifier used to render this set
37
+ - **Width:** Maximum width of uploaded banners
38
+ - **Height:** Maximum height of uploaded banners
39
+ - **Cropped:** Whether or not banners should be cropped to fit into the above Width/Height constraints
40
+
41
+ ## Managing Banners
42
+
43
+ Once a Set has been created, you can begin adding banners to it. Banners contain optional `link_to`, `link_target`, `title`, and `alt` options. Banners are also sortable via drag-and-drop.
44
+
45
+ ## View Helpers
46
+
47
+ A number of view helpers are provided for displaying banners in your templates.
48
+
49
+ `spud_banners_for_set(set_or_identifier, options)`
50
+
51
+ Accepts the banner set name as a String or Symbol and returns an html template. Options hash accepts a `:limit` parameter for limiting the number of banners returned. This helper also accepts a block argument for rendering custom html.
52
+
53
+ ```ruby
54
+ spud_banner_tag(banner)
55
+ ```
56
+
57
+ Accepts a banner model object and returns a banner image wrapped in a link tag. Link tag is omitted if the `link_to` property of the banner is blank.
58
+
59
+ ```ruby
60
+ spud_banner_image_tag(banner)
61
+ ```
62
+
63
+ Accepts a banner model and returns only the image tag, no link.
64
+
65
+ ## Examples
66
+
67
+ Displaying banners using the standard helper.
68
+
69
+ ```erb
70
+ <div id="banners">
71
+ <%= spud_banners_for_set(:promotions) %>
72
+ </div>
73
+ ```
74
+
75
+ Displaying banners using the helper, with a block for custom html.
76
+
77
+ ```erb
78
+ <ul id="slides">
79
+ <% spud_banners_for_set(:promotions) do |banner| %>
80
+ <li class="custom_slide">
81
+ <%= spud_banner_tag(banner) %>
82
+ </li>
83
+ <% end %>
84
+ </ul>
85
+ ```
86
+
87
+ Displaying banners using the helper, with a block for even more custom html.
88
+
89
+ ```erb
90
+ <ul id="slides">
91
+ <% spud_banners_for_set(:promotions) do |banner| %>
92
+ <li class="custom_slide">
93
+ <h3><%= link_to banner.link_to, banner.title, :target => banner.link_target %></h3>
94
+ <%= image_tag(banner.banner.url(:banner), :alt => banner.alt, :title => banner.title) %>
95
+ </li>
96
+ <% end %>
97
+ </ul>
98
+ ```
99
+
100
+ ## Liquid
101
+
102
+ Spud Banners comes with its own custom [Liquid][liquid] tag. For now the liquid tag only supports rendering the standard html as generated by the `spud_banners_for_set`. Will provide support more advanced options in the future.
103
+
104
+ Usage:
105
+
106
+ ```erb
107
+ <%= raw Liquid::Template.parse("{% spud_banner_set Promotions %}").render %>
108
+ ```
109
+
110
+ ## Slideshows
111
+
112
+ Spud Banners does not provide a built-in slideshow animation library. Instead, we make it easy for you to integrate into any number of popular JavaScript slideshow plugins available on the web, or even to write your own from scratch.
113
+
114
+ Below is an example of integration with [SlidesJs][slidesjs], a jQuery plugin.
115
+
116
+ ```erb
117
+ <style type="text/css" media="screen">
118
+ .spud_banner_set {
119
+ width: 600px;
120
+ height: 200px;
121
+ }
122
+ .spud_banner_set_banner {
123
+ width: 600px;
124
+ height: 200px;
125
+ display: block;
126
+ }
127
+ </style>
128
+ <div id="banners">
129
+ <%= spud_banners_for_set(:promotions) %>
130
+ </div>
131
+ <script src="/slides.jquery.js" type="text/javascript"></script>
132
+ <script>
133
+ $(document).ready(function(){
134
+ $("#banners").slides({
135
+ play: 5000,
136
+ container: 'spud_banner_set'
137
+ });
138
+ });
139
+ </script>
140
+ ```
141
+
142
+ [spud]:https://github.com/spud-rails/spud_core_admin
143
+ [slidesjs]:http://www.slidesjs.com
144
+ [liquid]:https://github.com/Shopify/liquid
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'TbBanners'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -0,0 +1,2 @@
1
+ //= require spud/admin/banners/banners
2
+ //= require spud/admin/banners/banner_sets
@@ -0,0 +1,102 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
3
+
4
+ spud.admin.banner_sets = new function(){
5
+
6
+ var self = this;
7
+ var bannerSetEditId = false;
8
+
9
+ this.init = function(){
10
+ $('.spud_banner_sets_add_new').on('click', self.clickedAddNewBannerSet);
11
+ $('.spud_admin_banner_sets_list').on('click', '.spud_banner_sets_edit', self.clickedEditBannerSet);
12
+ $('.spud_admin_banner_sets_list').on('click', '.spud_banner_sets_delete', self.clickedDeleteBannerSet);
13
+ $('.modal-body').on('submit', '.spud_banner_set_form', self.submittedBannerSetForm);
14
+ };
15
+
16
+ self.clickedAddNewBannerSet = function(e){
17
+ e.preventDefault();
18
+ bannerSetEditId = false;
19
+ $.ajax({
20
+ url: $(this).attr('href'),
21
+ dataType: 'html',
22
+ success: function(html, textStatus, jqXHR){
23
+ displayModalDialogWithOptions({
24
+ title: 'New Banner Set',
25
+ html: html
26
+ });
27
+ }
28
+ });
29
+ };
30
+
31
+ self.clickedEditBannerSet = function(e){
32
+ e.preventDefault();
33
+ bannerSetEditId = parseInt($(this).parents('li').attr('data-id'), 10);
34
+ $.ajax({
35
+ url: $(this).attr('href'),
36
+ dataType: 'html',
37
+ success: function(html, textStatus, jqXHR){
38
+ displayModalDialogWithOptions({
39
+ title: 'Edit Banner Set',
40
+ html: html
41
+ });
42
+ }
43
+ });
44
+ };
45
+
46
+ self.clickedDeleteBannerSet = function(e){
47
+ e.preventDefault();
48
+ if(window.confirm('Are you sure?')){
49
+ var el = $(this);
50
+ $.ajax({
51
+ url: el.attr('href'),
52
+ type: 'post',
53
+ data: {'_method':'delete'},
54
+ complete: function(jqXHR, textStatus){
55
+ var parent = el.parents('li');
56
+ parent.fadeOut(200, function(){
57
+ parent.remove();
58
+ });
59
+ if(textStatus != 'success'){
60
+ console.warn('Something went wrong:', jqXHR);
61
+ }
62
+ }
63
+ });
64
+ }
65
+ };
66
+
67
+ self.submittedBannerSetForm = function(e){
68
+ e.preventDefault();
69
+ var form = $(this);
70
+ $.ajax({
71
+ url: form.attr('action'),
72
+ data: form.serialize(),
73
+ type: 'post',
74
+ dataType: 'html',
75
+ success: self.savedBannerSetSuccess,
76
+ error: self.savedBannerSetError
77
+ });
78
+ };
79
+
80
+ self.savedBannerSetSuccess = function(html){
81
+ if(bannerSetEditId){
82
+ var item = $('.spud_admin_banner_sets_list_item[data-id="'+bannerSetEditId+'"]');
83
+ item.replaceWith(html);
84
+ }
85
+ else{
86
+ $('.spud_admin_banner_sets_list').append(html);
87
+ }
88
+ hideModalDialog();
89
+ };
90
+
91
+ self.savedBannerSetError = function(jqXHR, textStatus, errorThrown){
92
+ if(jqXHR.status == 422){
93
+ var html = jqXHR.responseText;
94
+ $('.spud_banner_set_form').replaceWith(html);
95
+ }
96
+ else{
97
+ if(window.console){
98
+ console.error('Oh Snap:', arguments);
99
+ }
100
+ }
101
+ };
102
+ }();
@@ -0,0 +1,187 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
3
+
4
+ spud.admin.banners = new function(){
5
+
6
+ var self = this;
7
+ var html5upload = false;
8
+ var bannerEditId = false;
9
+
10
+ // Index Page
11
+ /////////////
12
+
13
+ this.init = function(){
14
+ if(typeof(FormData) != 'undefined'){
15
+ html5upload = true;
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);
20
+ $('.modal-body').on('submit', '.spud_banner_form', self.submittedBannerForm);
21
+
22
+ $('.spud_banner_set_banners_container').sortable({
23
+ stop: self.sortedBanners
24
+ });
25
+ };
26
+
27
+ self.clickedAddNewBanner = function(e){
28
+ e.preventDefault();
29
+ bannerEditId = false;
30
+ $.ajax({
31
+ url: $(this).attr('href'),
32
+ dataType: 'html',
33
+ success: function(html, textStatus, jqXHR){
34
+ displayModalDialogWithOptions({
35
+ title: 'Upload Banner',
36
+ html: html
37
+ });
38
+ }
39
+ });
40
+ };
41
+
42
+ self.clickedEditBanner = function(e){
43
+ e.preventDefault();
44
+ bannerEditId = parseInt($(this).parents('.spud_banner_set_banner_item').attr('data-id'), 10);
45
+ $.ajax({
46
+ url: $(this).attr('href'),
47
+ dataType: 'html',
48
+ success: function(html, textStatus, jqXHR){
49
+ displayModalDialogWithOptions({
50
+ title: 'Edit Banner',
51
+ html: html
52
+ });
53
+ }
54
+ });
55
+ };
56
+
57
+ self.clickedDeleteBanner = function(e){
58
+ e.preventDefault();
59
+ var el = $(this);
60
+ $.ajax({
61
+ url: el.attr('href'),
62
+ type: 'post',
63
+ data: {'_method':'delete'},
64
+ complete: function(jqXHR, textStatus){
65
+ var parent = el.parents('.spud_banner_set_banner_item');
66
+ parent.fadeOut(200, function(){
67
+ parent.remove();
68
+ });
69
+ if(textStatus != 'success'){
70
+ console.warn('Something went wrong:', jqXHR);
71
+ }
72
+ }
73
+ });
74
+ };
75
+
76
+ self.submittedBannerForm = function(e){
77
+ if(html5upload){
78
+ e.preventDefault();
79
+
80
+ var form = $(this);
81
+ 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());
88
+
89
+ var richText = form.find('.spud_banner_rich_text');
90
+ if(richText){
91
+ fd.append('spud_banner[rich_text]', richText.val());
92
+ }
93
+
94
+ var file = form.find('#spud_banner_banner')[0].files[0];
95
+ if(file){
96
+ fd.append('spud_banner[banner]', file);
97
+ $('.spud_banner_upload_progress').show();
98
+ }
99
+
100
+ var xhr = new XMLHttpRequest();
101
+ xhr.upload.addEventListener('progress', self.onFileUploadProgress);
102
+ xhr.addEventListener('load', self.onFileUploadComplete);
103
+ xhr.addEventListener('error', self.onFileUploadError);
104
+ xhr.addEventListener('abort', self.onFileUploadAbort);
105
+ xhr.open('POST', form.attr('action'));
106
+ xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
107
+ xhr.send(fd);
108
+ return false;
109
+ }
110
+ };
111
+
112
+ self.onFileUploadProgress = function(e){
113
+ var percent = Math.round(e.loaded * 100 / e.total);
114
+ var progress = $('.spud_banner_upload_progress');
115
+ progress.find('.bar').css({width: percent + '%'});
116
+ if(percent == 100){
117
+ progress.addClass('progress-success');
118
+ }
119
+ };
120
+
121
+ self.onFileUploadComplete = function(e){
122
+ switch(this.status){
123
+ case 200:
124
+ self.onLegacyUploadComplete(e.target.response);
125
+ break;
126
+ case 422:
127
+ self.onLegacyUploadError(e.target.response);
128
+ break;
129
+ default:
130
+ window.alert("Whoops! Something has gone wrong.");
131
+ }
132
+ };
133
+
134
+ self.onFileUploadError = function(e){
135
+
136
+ };
137
+
138
+ self.onFileUploadAbort = function(e){
139
+
140
+ };
141
+
142
+ // Non-html5 upload
143
+ self.onLegacyUploadComplete = function(html){
144
+ if(bannerEditId){
145
+ var item = $('.spud_admin_banner_item[data-id="'+bannerEditId+'"]');
146
+ item.replaceWith(html);
147
+ }
148
+ else{
149
+ $('.spud_banner_set_banners_container').append(html);
150
+ }
151
+ hideModalDialog();
152
+ };
153
+
154
+ self.onLegacyUploadError = function(html){
155
+ $('.spud_banner_form').replaceWith(html);
156
+ };
157
+
158
+ self.sortedBanners = function(e, ui){
159
+ var ids = [];
160
+ $('.spud_banner_set_banner_item').each(function(){
161
+ ids.push($(this).attr('data-id'));
162
+ });
163
+ $.ajax({
164
+ url: '/spud/admin/banners/sort',
165
+ type: 'post',
166
+ data: {spud_banner_ids:ids, _method:'put'}
167
+ });
168
+ };
169
+
170
+ // Form Page
171
+ ////////////
172
+
173
+ this.form = function(){
174
+ var richText = $('.spud_banner_rich_text');
175
+ if(richText){
176
+ spud.admin.editor.init({
177
+ selector:'.spud_banner_rich_text',
178
+ buttons: [
179
+ ['bold','italic','underline','strikethrough','formatselect','|','bullist','numlist','outdent','indent','|','link','unlink','anchor'],
180
+ ['justifyleft','justifycenter','justifyright','justifyfull','|','cut','copy','paste','pastetext']
181
+ ],
182
+ height: 300,
183
+ width: 500
184
+ });
185
+ }
186
+ };
187
+ }();
@@ -0,0 +1,4 @@
1
+ /*
2
+ *= require spud/admin/banners/banners
3
+ *= require spud/admin/banners/banner_sets
4
+ */
@@ -0,0 +1,27 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
5
+
6
+ .spud_admin_banner_sets_list{
7
+ margin: 0;
8
+ padding: 0;
9
+ border: 1px solid #eee;
10
+ min-height: 40px;
11
+ }
12
+ .spud_admin_banner_sets_list_item{
13
+ clear: both;
14
+ overflow: hidden;
15
+ padding: 10px;
16
+ }
17
+ .spud_admin_banner_sets_list_item:nth-child(2n) {
18
+ background: #F1F1F1;
19
+ }
20
+ .spud_admin_banner_sets_list_item:hover{
21
+ background: #FFEDDF;
22
+ -webkit-transition: background 0.1s ease-in;
23
+ -moz-transition: background 0.1s ease-in;
24
+ }
25
+ .spud_admin_banner_sets_list_item_actions{
26
+ float: right;
27
+ }
@@ -0,0 +1,36 @@
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
+ }
@@ -0,0 +1,68 @@
1
+ class Spud::Admin::BannerSetsController < Spud::Admin::ApplicationController
2
+
3
+ cache_sweeper :spud_banner_sweeper, :only => [:create, :update, :destroy]
4
+ before_filter :get_record, :only => [:show, :edit, :update, :destroy]
5
+ respond_to :html
6
+ belongs_to_spud_app :banner_sets
7
+ add_breadcrumb 'Banner Sets', :spud_admin_banner_sets_path
8
+ layout false
9
+
10
+ def index
11
+ @banner_sets = SpudBannerSet.all
12
+ respond_with @banner_sets, :layout => 'spud/admin/detail'
13
+ end
14
+
15
+ def show
16
+ respond_with @banner_set, :layout => 'spud/admin/detail'
17
+ end
18
+
19
+ def new
20
+ @banner_set = SpudBannerSet.new
21
+ respond_with @banner_set
22
+ end
23
+
24
+ def create
25
+ @banner_set = SpudBannerSet.new(params[:spud_banner_set])
26
+ if @banner_set.save
27
+ flash.now[:notice] = 'BannerSet created successfully'
28
+ render 'create'
29
+ else
30
+ render 'new', :status => 422
31
+ end
32
+ end
33
+
34
+ def edit
35
+ respond_with @banner_set
36
+ end
37
+
38
+ def update
39
+ if @banner_set.update_attributes(params[:spud_banner_set])
40
+ flash.now[:notice] = 'BannerSet updated successfully'
41
+ @banner_set.reprocess_banners!
42
+ render 'create'
43
+ else
44
+ render 'edit', :status => 422
45
+ end
46
+ end
47
+
48
+ def destroy
49
+ if @banner_set.destroy
50
+ flash.now[:notice] = 'BannerSet deleted successfully'
51
+ end
52
+ render :nothing => true
53
+ end
54
+
55
+ private
56
+
57
+ def get_record
58
+ begin
59
+ logger.debug "Looking for banner set with id: #{params[:id]}"
60
+ @banner_set = SpudBannerSet.find(params[:id])
61
+ rescue ActiveRecord::RecordNotFound => e
62
+ flash.now[:error] = "Could not find the requested BannerSet"
63
+ redirect_to spud_admin_banner_sets_path
64
+ return false
65
+ end
66
+ end
67
+
68
+ end