spud_banners 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/Rakefile +40 -0
  3. data/Readme.markdown +128 -0
  4. data/app/assets/javascripts/spud/admin/banners/application.js +2 -0
  5. data/app/assets/javascripts/spud/admin/banners/banner_sets.js +102 -0
  6. data/app/assets/javascripts/spud/admin/banners/banners.js +161 -0
  7. data/app/assets/stylesheets/spud/admin/banners/application.css +4 -0
  8. data/app/assets/stylesheets/spud/admin/banners/banner_sets.css +27 -0
  9. data/app/assets/stylesheets/spud/admin/banners/banners.css +36 -0
  10. data/app/controllers/spud/admin/banner_sets_controller.rb +71 -0
  11. data/app/controllers/spud/admin/banners_controller.rb +104 -0
  12. data/app/helpers/spud/admin/banner_sets_helper.rb +2 -0
  13. data/app/helpers/spud/admin/banners_helper.rb +2 -0
  14. data/app/helpers/spud_banners_helper.rb +37 -0
  15. data/app/models/spud_banner.rb +51 -0
  16. data/app/models/spud_banner_set.rb +30 -0
  17. data/app/observers/spud_banner_sweeper.rb +44 -0
  18. data/app/views/spud/admin/banner_sets/_banner_set.html.erb +8 -0
  19. data/app/views/spud/admin/banner_sets/_form.html.erb +32 -0
  20. data/app/views/spud/admin/banner_sets/create.html.erb +1 -0
  21. data/app/views/spud/admin/banner_sets/edit.html.erb +1 -0
  22. data/app/views/spud/admin/banner_sets/index.html.erb +12 -0
  23. data/app/views/spud/admin/banner_sets/new.html.erb +1 -0
  24. data/app/views/spud/admin/banner_sets/show.html.erb +11 -0
  25. data/app/views/spud/admin/banners/_banner.html.erb +7 -0
  26. data/app/views/spud/admin/banners/_form.html.erb +47 -0
  27. data/app/views/spud/admin/banners/edit.html.erb +1 -0
  28. data/app/views/spud/admin/banners/legacy.js.erb +5 -0
  29. data/app/views/spud/admin/banners/new.html.erb +1 -0
  30. data/app/views/spud/admin/banners/show.html.erb +1 -0
  31. data/config/routes.rb +14 -0
  32. data/db/migrate/20121116195139_create_spud_banners.rb +15 -0
  33. data/db/migrate/20121116195312_create_spud_banner_sets.rb +12 -0
  34. data/lib/responds_to_parent.rb +69 -0
  35. data/lib/spud_banners/configuration.rb +10 -0
  36. data/lib/spud_banners/engine.rb +25 -0
  37. data/lib/spud_banners/liquid_tags.rb +32 -0
  38. data/lib/spud_banners/version.rb +5 -0
  39. data/lib/spud_banners.rb +8 -0
  40. data/lib/tasks/spud_banners_tasks.rake +4 -0
  41. data/test/dummy/README.rdoc +261 -0
  42. data/test/dummy/Rakefile +7 -0
  43. data/test/dummy/app/assets/javascripts/application.js +15 -0
  44. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  45. data/test/dummy/app/controllers/application_controller.rb +3 -0
  46. data/test/dummy/app/helpers/application_helper.rb +2 -0
  47. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  48. data/test/dummy/config/application.rb +59 -0
  49. data/test/dummy/config/boot.rb +10 -0
  50. data/test/dummy/config/database.yml +25 -0
  51. data/test/dummy/config/environment.rb +5 -0
  52. data/test/dummy/config/environments/development.rb +37 -0
  53. data/test/dummy/config/environments/production.rb +67 -0
  54. data/test/dummy/config/environments/test.rb +37 -0
  55. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  56. data/test/dummy/config/initializers/inflections.rb +15 -0
  57. data/test/dummy/config/initializers/mime_types.rb +5 -0
  58. data/test/dummy/config/initializers/secret_token.rb +7 -0
  59. data/test/dummy/config/initializers/session_store.rb +8 -0
  60. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  61. data/test/dummy/config/locales/en.yml +5 -0
  62. data/test/dummy/config/routes.rb +4 -0
  63. data/test/dummy/config.ru +4 -0
  64. data/test/dummy/public/404.html +26 -0
  65. data/test/dummy/public/422.html +26 -0
  66. data/test/dummy/public/500.html +25 -0
  67. data/test/dummy/public/favicon.ico +0 -0
  68. data/test/dummy/script/rails +6 -0
  69. data/test/fixtures/spud_banner_sets.yml +15 -0
  70. data/test/fixtures/spud_banners.yml +15 -0
  71. data/test/functional/spud/admin/banner_sets_controller_test.rb +7 -0
  72. data/test/functional/spud/admin/banners_controller_test.rb +7 -0
  73. data/test/integration/navigation_test.rb +10 -0
  74. data/test/spud_banners_test.rb +7 -0
  75. data/test/test_helper.rb +15 -0
  76. data/test/unit/helpers/spud/admin/banner_sets_helper_test.rb +4 -0
  77. data/test/unit/helpers/spud/admin/banners_helper_test.rb +4 -0
  78. data/test/unit/spud_banner_set_test.rb +7 -0
  79. data/test/unit/spud_banner_test.rb +7 -0
  80. metadata +234 -0
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/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 = 'SpudBanners'
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("../test/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
data/Readme.markdown ADDED
@@ -0,0 +1,128 @@
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
+ Spud::Photos.configure do |config|
24
+ config.paperclip_storage = :filesystem #use :s3 to use s3 storage (aws gem required)
25
+ config.s3_credentials = "#{Rails.root}/config/s3.yml"
26
+ config.storage_path = ":rails_root/public/system/spud_banners/:id/:style/:basename.:extension"
27
+ config.storage_url = "/system/spud_banners/:id/:style/:basename.:extension"
28
+ end
29
+
30
+ ## Creating a Banner Set
31
+
32
+ Banner Sets are created in the Spud admin. When creating a Set, you have the following options:
33
+
34
+ - **Name:** The unique identifier used to render this set
35
+ - **Width:** Maximum width of uploaded banners
36
+ - **Height:** Maximum height of uploaded banners
37
+ - **Cropped:** Whether or not banners should be cropped to fit into the above Width/Height constraints
38
+
39
+ ## Managing Banners
40
+
41
+ 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.
42
+
43
+ ## View Helpers
44
+
45
+ A number of view helpers are provided for displaying banners in your templates.
46
+
47
+ `spud_banners_for_set(set_or_identifier)`
48
+
49
+ Accepts the banner set name as a String or Symbol and returns an html template. Optionally takes a block argument for rendering custom html.
50
+
51
+ `spud_banner_tag(banner)`
52
+
53
+ 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.
54
+
55
+ `spud_banner_image_tag(banner)`
56
+
57
+ Accepts a banner model and returns only the image tag, no link.
58
+
59
+ ## Examples
60
+
61
+ Displaying banners using the standard helper.
62
+
63
+ <div id="banners">
64
+ <%= spud_banners_for_set(:promotions) %>
65
+ </div>
66
+
67
+ Displaying banners using the helper, with a block for custom html.
68
+
69
+ <ul id="slides">
70
+ <% spud_banners_for_set(:promotions) do |banner| %>
71
+ <li class="custom_slide">
72
+ <%= spud_banner_tag(banner) %>
73
+ </li>
74
+ <% end %>
75
+ </ul>
76
+
77
+ Displaying banners using the helper, with a block for even more custom html.
78
+
79
+ <ul id="slides">
80
+ <% spud_banners_for_set(:promotions) do |banner| %>
81
+ <li class="custom_slide">
82
+ <h3><%= link_to banner.link_to, banner.title, :target => banner.link_target %></h3>
83
+ <%= image_tag(banner.banner.url(:banner), :alt => banner.alt, :title => banner.title) %>
84
+ </li>
85
+ <% end %>
86
+ </ul>
87
+
88
+ ## Liquid
89
+
90
+ 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.
91
+
92
+ Usage:
93
+
94
+ <%= raw Liquid::Template.parse("{% spud_banner_set Promotions %}").render %>
95
+
96
+ ## Slideshows
97
+
98
+ 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.
99
+
100
+ Below is an example of integration with [SlidesJs][slidesjs], a jQuery plugin.
101
+
102
+ <style type="text/css" media="screen">
103
+ .spud_banner_set {
104
+ width: 600px;
105
+ height: 200px;
106
+ }
107
+ .spud_banner_set_banner {
108
+ width: 600px;
109
+ height: 200px;
110
+ display: block;
111
+ }
112
+ </style>
113
+ <div id="banners">
114
+ <%= spud_banners_for_set(:promotions) %>
115
+ </div>
116
+ <script src="/slides.jquery.js" type="text/javascript"></script>
117
+ <script>
118
+ $(document).ready(function(){
119
+ $("#banners").slides({
120
+ play: 5000,
121
+ container: 'spud_banner_set'
122
+ });
123
+ });
124
+ </script>
125
+
126
+ [spud]:https://github.com/davydotcom/spud_core_admin
127
+ [slidesjs]:http://www.slidesjs.com
128
+ [liquid]:https://github.com/Shopify/liquid
@@ -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,161 @@
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
+ this.init = function(){
11
+ if(typeof(FormData) != 'undefined'){
12
+ html5upload = true;
13
+ }
14
+ $('.spud_banner_add_new').on('click', self.clickedAddNewBanner);
15
+ $('.spud_banner_set_banners_container').on('click', '.spud_banner_set_banner_item_edit', self.clickedEditBanner);
16
+ $('.spud_banner_set_banners_container').on('click', '.spud_banner_set_banner_item_delete', self.clickedDeleteBanner);
17
+ $('.modal-body').on('submit', '.spud_banner_form', self.submittedBannerForm);
18
+
19
+ $('.spud_banner_set_banners_container').sortable({
20
+ stop: self.sortedBanners
21
+ });
22
+ };
23
+
24
+ self.clickedAddNewBanner = function(e){
25
+ e.preventDefault();
26
+ bannerEditId = false;
27
+ $.ajax({
28
+ url: $(this).attr('href'),
29
+ dataType: 'html',
30
+ success: function(html, textStatus, jqXHR){
31
+ displayModalDialogWithOptions({
32
+ title: 'Upload Banner',
33
+ html: html
34
+ });
35
+ }
36
+ });
37
+ };
38
+
39
+ self.clickedEditBanner = function(e){
40
+ e.preventDefault();
41
+ bannerEditId = parseInt($(this).parents('.spud_banner_set_banner_item').attr('data-id'), 10);
42
+ $.ajax({
43
+ url: $(this).attr('href'),
44
+ dataType: 'html',
45
+ success: function(html, textStatus, jqXHR){
46
+ displayModalDialogWithOptions({
47
+ title: 'Edit Banner',
48
+ html: html
49
+ });
50
+ }
51
+ });
52
+ };
53
+
54
+ self.clickedDeleteBanner = function(e){
55
+ e.preventDefault();
56
+ var el = $(this);
57
+ $.ajax({
58
+ url: el.attr('href'),
59
+ type: 'post',
60
+ data: {'_method':'delete'},
61
+ complete: function(jqXHR, textStatus){
62
+ var parent = el.parents('.spud_banner_set_banner_item');
63
+ parent.fadeOut(200, function(){
64
+ parent.remove();
65
+ });
66
+ if(textStatus != 'success'){
67
+ console.warn('Something went wrong:', jqXHR);
68
+ }
69
+ }
70
+ });
71
+ };
72
+
73
+ self.submittedBannerForm = function(e){
74
+ if(html5upload){
75
+ e.preventDefault();
76
+
77
+ var form = $(this);
78
+ var fd = new FormData();
79
+ fd.append('_method', form.find('[name=_method]').val());
80
+ fd.append('authenticity_token', form.find('[name=authenticity_token]').val());
81
+ fd.append('spud_banner[link_to]', form.find('#spud_banner_link_to').val());
82
+ fd.append('spud_banner[link_target]', form.find('#spud_banner_target').val());
83
+ fd.append('spud_banner[title]', form.find('#spud_banner_title').val());
84
+ fd.append('spud_banner[alt]', form.find('#spud_banner_alt').val());
85
+
86
+ var file = form.find('#spud_banner_banner')[0].files[0];
87
+ if(file){
88
+ fd.append('spud_banner[banner]', file);
89
+ $('.spud_banner_upload_progress').show();
90
+ }
91
+
92
+ var xhr = new XMLHttpRequest();
93
+ xhr.upload.addEventListener('progress', self.onFileUploadProgress);
94
+ xhr.addEventListener('load', self.onFileUploadComplete);
95
+ xhr.addEventListener('error', self.onFileUploadError);
96
+ xhr.addEventListener('abort', self.onFileUploadAbort);
97
+ xhr.open('POST', form.attr('action'));
98
+ xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
99
+ xhr.send(fd);
100
+ return false;
101
+ }
102
+ };
103
+
104
+ self.onFileUploadProgress = function(e){
105
+ var percent = Math.round(e.loaded * 100 / e.total);
106
+ var progress = $('.spud_banner_upload_progress');
107
+ progress.find('.bar').css({width: percent + '%'});
108
+ if(percent == 100){
109
+ progress.addClass('progress-success');
110
+ }
111
+ };
112
+
113
+ self.onFileUploadComplete = function(e){
114
+ switch(this.status){
115
+ case 200:
116
+ self.onLegacyUploadComplete(e.target.response);
117
+ break;
118
+ case 422:
119
+ self.onLegacyUploadError(e.target.response);
120
+ break;
121
+ default:
122
+ window.alert("Whoops! Something has gone wrong.");
123
+ }
124
+ };
125
+
126
+ self.onFileUploadError = function(e){
127
+
128
+ };
129
+
130
+ self.onFileUploadAbort = function(e){
131
+
132
+ };
133
+
134
+ // Non-html5 upload
135
+ self.onLegacyUploadComplete = function(html){
136
+ if(bannerEditId){
137
+ var item = $('.spud_admin_banner_item[data-id="'+bannerEditId+'"]');
138
+ item.replaceWith(html);
139
+ }
140
+ else{
141
+ $('.spud_banner_set_banners_container').append(html);
142
+ }
143
+ hideModalDialog();
144
+ };
145
+
146
+ self.onLegacyUploadError = function(html){
147
+ $('.spud_banner_form').replaceWith(html);
148
+ };
149
+
150
+ self.sortedBanners = function(e, ui){
151
+ var ids = [];
152
+ $('.spud_banner_set_banner_item').each(function(){
153
+ ids.push($(this).attr('data-id'));
154
+ });
155
+ $.ajax({
156
+ url: '/spud/admin/banners/sort',
157
+ type: 'post',
158
+ data: {spud_banner_ids:ids, _method:'put'}
159
+ });
160
+ };
161
+ }();
@@ -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,71 @@
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
+ status = 200
52
+ else
53
+ status = 422
54
+ end
55
+ render :nothing => true, :status => status
56
+ end
57
+
58
+ private
59
+
60
+ def get_record
61
+ begin
62
+ logger.debug "Looking for banner set with id: #{params[:id]}"
63
+ @banner_set = SpudBannerSet.find(params[:id])
64
+ rescue ActiveRecord::RecordNotFound => e
65
+ flash.now[:error] = "Could not find the requested BannerSet"
66
+ redirect_to spud_admin_banner_sets_path
67
+ return false
68
+ end
69
+ end
70
+
71
+ end
@@ -0,0 +1,104 @@
1
+ class Spud::Admin::BannersController < Spud::Admin::ApplicationController
2
+
3
+ include RespondsToParent
4
+
5
+ cache_sweeper :spud_banner_sweeper, :only => [:create, :update, :destroy]
6
+ before_filter :get_set, :only => [:new, :create]
7
+ before_filter :get_record, :only => [:edit, :update, :destroy]
8
+ respond_to :html
9
+ layout false
10
+
11
+ def new
12
+ @banner = @banner_set.banners.new
13
+ respond_with @banner
14
+ end
15
+
16
+ def create
17
+ @banner = @banner_set.banners.build
18
+ @banner.attributes = params[:spud_banner]
19
+
20
+ last_banner = SpudBanner.select('sort_order').where(:spud_banner_set_id => @banner_set.id).order('sort_order desc').first
21
+ if last_banner
22
+ @banner.sort_order = last_banner.sort_order + 1
23
+ end
24
+
25
+ if request.xhr?
26
+ if @banner.save
27
+ flash.now[:notice] = 'SpudBanner created successfully'
28
+ render 'show'
29
+ else
30
+ render 'new', :status => 422
31
+ end
32
+ else
33
+ @banner.save
34
+ respond_to_parent do
35
+ render 'legacy', :formats => [:js]
36
+ end
37
+ end
38
+ end
39
+
40
+ def edit
41
+ respond_with @banner
42
+ end
43
+
44
+ def update
45
+ if request.xhr?
46
+ if @banner.update_attributes(params[:spud_banner])
47
+ flash.now[:notice] = 'SpudBanner created successfully'
48
+ render 'show'
49
+ else
50
+ render 'edit', :status => 422
51
+ end
52
+ else
53
+ @banner.update_attributes(params[:spud_banner])
54
+ respond_to_parent do
55
+ render 'legacy', :formats => [:js]
56
+ end
57
+ end
58
+ end
59
+
60
+ def destroy
61
+ if @banner.destroy
62
+ flash.now[:notice] = 'SpudBanner deleted successfully'
63
+ status = 200
64
+ else
65
+ status = 422
66
+ end
67
+ render :nothing => true, :status => status
68
+ end
69
+
70
+ def sort
71
+ banner_ids = params[:spud_banner_ids]
72
+ banners = SpudBanner.where(:id => banner_ids).to_a
73
+ SpudBanner.transaction do
74
+ banner_ids.each_with_index do |id, index|
75
+ banner = banners.select{ |b| b.id == id.to_i }.first
76
+ banner.update_attribute(:sort_order, index)
77
+ end
78
+ end
79
+ render :nothing => true, :status => 200
80
+ end
81
+
82
+ private
83
+
84
+ def get_set
85
+ begin
86
+ @banner_set = SpudBannerSet.find(params[:banner_set_id])
87
+ rescue ActiveRecord::RecordNotFound => e
88
+ flash.now[:error] = "Could not find the requested SpudBannerSet"
89
+ render :nothing => true, :status => 404
90
+ return false
91
+ end
92
+ end
93
+
94
+ def get_record
95
+ begin
96
+ @banner = SpudBanner.find(params[:id])
97
+ rescue ActiveRecord::RecordNotFound => e
98
+ flash.now[:error] = "Could not find the requested SpudBanner"
99
+ redirect_to spud_admin_banner_sets_path
100
+ return false
101
+ end
102
+ end
103
+
104
+ end