tb_banners 1.1.6 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.markdown +3 -13
- data/Rakefile +2 -5
- data/app/assets/javascripts/admin/banners/banner_sets.js +91 -86
- data/app/assets/javascripts/admin/banners/banners.js +163 -187
- data/app/assets/stylesheets/admin/banners/banner_sets.css +0 -23
- data/app/assets/stylesheets/admin/banners/banners.css.scss +7 -5
- data/app/controllers/admin/banner_sets_controller.rb +15 -23
- data/app/controllers/admin/banners_controller.rb +32 -61
- data/app/helpers/spud_banners_helper.rb +24 -19
- data/app/models/spud_banner.rb +33 -20
- data/app/models/spud_banner_set.rb +16 -19
- data/app/views/admin/banner_sets/_banner_set.html.erb +8 -7
- data/app/views/admin/banner_sets/_form.html.erb +20 -20
- data/app/views/admin/banner_sets/index.html.erb +6 -4
- data/app/views/admin/banner_sets/show.html.erb +19 -14
- data/app/views/admin/banners/_banner.html.erb +8 -5
- data/app/views/admin/banners/_form.html.erb +14 -18
- data/db/migrate/20121116195139_create_spud_banners.rb +1 -1
- data/db/migrate/20121116195312_create_spud_banner_sets.rb +1 -1
- data/db/migrate/20130614132846_add_rich_text_to_spud_banners.rb +1 -1
- data/db/migrate/20140721142719_add_start_and_end_dates_to_spud_banners.rb +1 -1
- data/lib/spud_banners/configuration.rb +6 -5
- data/lib/spud_banners/engine.rb +13 -11
- data/lib/spud_banners/version.rb +1 -1
- data/lib/tb_banners.rb +1 -2
- data/spec/controllers/admin/banner_sets_controller_spec.rb +57 -58
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/config/application.rb +2 -3
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/environments/production.rb +1 -1
- data/spec/dummy/config/environments/test.rb +3 -4
- data/spec/dummy/config/initializers/secret_token.rb +0 -1
- data/spec/dummy/db/migrate/20121127192246_create_spud_admin_permissions.spud_core.rb +1 -1
- data/spec/dummy/db/migrate/20121127192247_create_spud_users.spud_core.rb +13 -13
- data/spec/dummy/db/migrate/20121127192248_add_time_zone_to_spud_user.spud_core.rb +1 -2
- data/spec/dummy/db/migrate/20121127192249_add_scope_to_spud_admin_permissions.spud_core.rb +1 -2
- data/spec/dummy/db/migrate/20121127192250_create_spud_user_settings.spud_core.rb +1 -1
- data/spec/dummy/db/migrate/20130920154442_create_spud_roles.tb_core.rb +1 -1
- data/spec/dummy/db/migrate/20130920154443_create_spud_permissions.tb_core.rb +4 -4
- data/spec/dummy/db/migrate/20130920154444_create_spud_role_permissions.tb_core.rb +3 -3
- data/spec/dummy/db/migrate/20130920154445_drop_spud_admin_permissions.tb_core.rb +1 -1
- data/spec/dummy/db/migrate/20160310164644_add_requires_password_change_to_spud_users.tb_core.rb +6 -0
- data/spec/dummy/db/schema.rb +70 -84
- data/spec/dummy/script/rails +2 -2
- data/spec/factories/spud_banner_sets.rb +9 -0
- data/spec/factories/spud_banners.rb +7 -0
- data/spec/models/spud_banner_spec.rb +27 -0
- data/spec/rails_helper.rb +81 -0
- data/spec/spec_helper.rb +77 -34
- metadata +81 -111
- data/app/views/admin/banners/legacy.js.erb +0 -5
- data/lib/spud_banners/liquid_tags.rb +0 -31
- data/spec/dummy/db/migrate/20130920154446_create_spud_banners.tb_banners.rb +0 -16
- data/spec/dummy/db/migrate/20130920154447_create_spud_banner_sets.tb_banners.rb +0 -13
- data/spec/dummy/db/migrate/20130920154448_add_rich_text_to_spud_banners.tb_banners.rb +0 -7
- data/spec/dummy/db/migrate/20140120174546_create_tb_liquid_spud_liquid_tags.tb_liquid.rb +0 -13
- data/spec/support/authlogic_helper.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e3a78e90e1242e80c10dfebdf922550e8883dc7f24c783a42b8b85c48cc67263
|
4
|
+
data.tar.gz: aa49eb68f74b9c070a83ba2be68110f00e904c5f10e7e9d02dc1c787ef9ed3e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36e529fa4ced38e9f632173d9bced428144a32e092836f09246f89e52d549da34a733569511175137665d0a5e0aea20b930543123dc47152959f9b413df07633
|
7
|
+
data.tar.gz: 1d2ab1f911dcaedc5ac572b216464f7d492c1354855d3bd3848d4c38aef7626be600b6cf972fb5ec92fb9721ee6aad0a85a37048e078e7a22bc3f468eb627328
|
data/README.markdown
CHANGED
@@ -24,6 +24,7 @@ TB Banners accepts the following configuration options:
|
|
24
24
|
Spud::Banners.configure do |config|
|
25
25
|
config.paperclip_storage = :filesystem #use :s3 to use s3 storage (aws gem required)
|
26
26
|
config.s3_credentials = "#{Rails.root}/config/s3.yml"
|
27
|
+
config.s3_protocol = 'https'
|
27
28
|
config.storage_path = ":rails_root/public/system/spud_banners/:id/:style/:basename.:extension"
|
28
29
|
config.storage_url = "/system/spud_banners/:id/:style/:basename.:extension"
|
29
30
|
end
|
@@ -102,21 +103,11 @@ Displaying banners using the helper, with a block for even more custom html.
|
|
102
103
|
</ul>
|
103
104
|
```
|
104
105
|
|
105
|
-
## Liquid
|
106
|
-
|
107
|
-
TB 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.
|
108
|
-
|
109
|
-
Usage:
|
110
|
-
|
111
|
-
```erb
|
112
|
-
<%= raw Liquid::Template.parse("{% spud_banner_set Promotions %}").render %>
|
113
|
-
```
|
114
|
-
|
115
106
|
## Rich Text
|
116
107
|
|
117
|
-
Banner Sets contain a configuration for rich text. Turning this feature on will enable a rich text editor on individual banners. The default setting for this option is off.
|
108
|
+
Banner Sets contain a configuration for rich text. Turning this feature on will enable a rich text editor on individual banners. The default setting for this option is off.
|
118
109
|
|
119
|
-
Rich text is intended to be more of an edge case feature, and should be used only if your banner needs to include an editable HTML block. The built-in helpers described earlier will not automatically include your rich text; If you want to use this feature, you should supply a block to the helper and render the rich text yourself.
|
110
|
+
Rich text is intended to be more of an edge case feature, and should be used only if your banner needs to include an editable HTML block. The built-in helpers described earlier will not automatically include your rich text; If you want to use this feature, you should supply a block to the helper and render the rich text yourself.
|
120
111
|
|
121
112
|
```erb
|
122
113
|
<ul id="slides">
|
@@ -165,4 +156,3 @@ Below is an example of integration with [SlidesJs][slidesjs], a jQuery plugin.
|
|
165
156
|
|
166
157
|
[tb]:https://bitbucket.org/westlakedesign/tb_core
|
167
158
|
[slidesjs]:http://www.slidesjs.com
|
168
|
-
[liquid]:https://github.com/Shopify/liquid
|
data/Rakefile
CHANGED
@@ -20,11 +20,9 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
20
20
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
21
|
end
|
22
22
|
|
23
|
-
APP_RAKEFILE = File.expand_path(
|
23
|
+
APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
|
24
24
|
load 'rails/tasks/engine.rake'
|
25
25
|
|
26
|
-
|
27
|
-
|
28
26
|
Bundler::GemHelper.install_tasks
|
29
27
|
|
30
28
|
require 'rake/testtask'
|
@@ -36,5 +34,4 @@ Rake::TestTask.new(:test) do |t|
|
|
36
34
|
t.verbose = false
|
37
35
|
end
|
38
36
|
|
39
|
-
|
40
|
-
task :default => :test
|
37
|
+
task default: :test
|
@@ -1,102 +1,107 @@
|
|
1
1
|
// Place all the behaviors and hooks related to the matching controller here.
|
2
2
|
// All this logic will automatically be available in application.js.
|
3
3
|
|
4
|
-
|
4
|
+
(function(){
|
5
5
|
|
6
|
-
|
7
|
-
var bannerSetEditId = false;
|
6
|
+
var bannerSetEditId = false;
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
$('.
|
12
|
-
$('.
|
13
|
-
$('.
|
14
|
-
|
8
|
+
spud.admin.banner_sets = {
|
9
|
+
init: function(){
|
10
|
+
$('.spud_banner_sets_add_new').on('click', clickedAddNewBannerSet);
|
11
|
+
$('.admin-banner-sets-list').on('click', '.admin-banner-set-edit', clickedEditBannerSet);
|
12
|
+
$('.admin-banner-sets-list').on('click', '.admin-banner-set-delete', clickedDeleteBannerSet);
|
13
|
+
$('.modal-body').on('submit', '.admin-banner-set-form', submittedBannerSetForm);
|
14
|
+
}
|
15
|
+
};
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
};
|
17
|
+
var clickedAddNewBannerSet = function(e){
|
18
|
+
e.preventDefault();
|
19
|
+
bannerSetEditId = false;
|
20
|
+
$.ajax({
|
21
|
+
url: $(this).attr('href'),
|
22
|
+
dataType: 'html',
|
23
|
+
success: function(html, textStatus, jqXHR){
|
24
|
+
spud.admin.modal.displayWithOptions({
|
25
|
+
title: 'New Banner Set',
|
26
|
+
html: html
|
27
|
+
});
|
28
|
+
}
|
29
|
+
});
|
30
|
+
};
|
45
31
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
parent.fadeOut(200, function(){
|
57
|
-
parent.remove();
|
58
|
-
});
|
59
|
-
if(textStatus != 'success'){
|
60
|
-
console.warn('Something went wrong:', jqXHR);
|
61
|
-
}
|
62
|
-
}
|
32
|
+
var clickedEditBannerSet = function(e){
|
33
|
+
e.preventDefault();
|
34
|
+
bannerSetEditId = parseInt($(this).parents('tr').attr('data-id'), 10);
|
35
|
+
$.ajax({
|
36
|
+
url: $(this).attr('href'),
|
37
|
+
dataType: 'html',
|
38
|
+
success: function(html, textStatus, jqXHR){
|
39
|
+
spud.admin.modal.displayWithOptions({
|
40
|
+
title: 'Edit Banner Set',
|
41
|
+
html: html
|
63
42
|
});
|
64
43
|
}
|
65
|
-
};
|
44
|
+
});
|
45
|
+
};
|
66
46
|
|
67
|
-
|
68
|
-
|
69
|
-
|
47
|
+
var clickedDeleteBannerSet = function(e){
|
48
|
+
e.preventDefault();
|
49
|
+
$.ajaxSetup({
|
50
|
+
headers: { 'X-CSRF-TOKEN': Rails.csrfToken() }
|
51
|
+
});
|
52
|
+
if(window.confirm('Are you sure?')){
|
53
|
+
var el = $(this);
|
70
54
|
$.ajax({
|
71
|
-
url:
|
72
|
-
data: form.serialize(),
|
55
|
+
url: el.attr('href'),
|
73
56
|
type: 'post',
|
74
|
-
|
75
|
-
|
76
|
-
|
57
|
+
data: {'_method':'delete'},
|
58
|
+
complete: function(jqXHR, textStatus){
|
59
|
+
var parent = el.parents('tr');
|
60
|
+
parent.fadeOut(200, function(){
|
61
|
+
parent.remove();
|
62
|
+
});
|
63
|
+
if(textStatus != 'success'){
|
64
|
+
console.warn('Something went wrong:', jqXHR);
|
65
|
+
}
|
66
|
+
}
|
77
67
|
});
|
78
|
-
}
|
68
|
+
}
|
69
|
+
};
|
79
70
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
71
|
+
var submittedBannerSetForm = function(e){
|
72
|
+
e.preventDefault();
|
73
|
+
var form = $(this);
|
74
|
+
$.ajax({
|
75
|
+
url: form.attr('action'),
|
76
|
+
data: form.serialize(),
|
77
|
+
type: 'post',
|
78
|
+
dataType: 'html',
|
79
|
+
success: savedBannerSetSuccess,
|
80
|
+
error: savedBannerSetError
|
81
|
+
});
|
82
|
+
};
|
90
83
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
84
|
+
var savedBannerSetSuccess = function(html){
|
85
|
+
if(bannerSetEditId){
|
86
|
+
var item = $('.admin-banner-sets-list-item[data-id="'+bannerSetEditId+'"]');
|
87
|
+
item.replaceWith(html);
|
88
|
+
}
|
89
|
+
else{
|
90
|
+
$('.admin-banner-sets-list').append(html);
|
91
|
+
}
|
92
|
+
spud.admin.modal.hide();
|
93
|
+
};
|
94
|
+
|
95
|
+
var savedBannerSetError = function(jqXHR, textStatus, errorThrown){
|
96
|
+
if(jqXHR.status == 422){
|
97
|
+
var html = jqXHR.responseText;
|
98
|
+
$('.admin-banner-set-form').replaceWith(html);
|
99
|
+
}
|
100
|
+
else{
|
101
|
+
if(window.console){
|
102
|
+
console.error('Oh Snap:', arguments);
|
100
103
|
}
|
101
|
-
}
|
102
|
-
}
|
104
|
+
}
|
105
|
+
};
|
106
|
+
|
107
|
+
})();
|
@@ -1,78 +1,37 @@
|
|
1
1
|
// Place all the behaviors and hooks related to the matching controller here.
|
2
2
|
// All this logic will automatically be available in application.js.
|
3
3
|
|
4
|
-
|
4
|
+
(function(){
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
var bannerEditId = false;
|
7
|
+
|
8
|
+
spud.admin.banners = {
|
9
9
|
|
10
10
|
// Index Page
|
11
11
|
/////////////
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
$('.admin-banner-set-items-container').sortable({
|
23
|
-
stop: self.sortedBanners,
|
24
|
-
helper: fixHelper
|
12
|
+
init: function(){
|
13
|
+
$('.admin-banner-set-item-add').on('click', clickedAddNewBanner);
|
14
|
+
$('.admin-banner-set-items-container').on('click', '.admin-banner-set-item-edit', clickedEditBanner);
|
15
|
+
$('.admin-banner-set-items-container').on('click', '.admin-banner-set-item-delete', clickedDeleteBanner);
|
16
|
+
$('.modal-body').on('submit', '.admin-banner-form', submittedBannerForm);
|
17
|
+
Sortable.create(document.querySelector('.admin-banner-set-items-container'), {
|
18
|
+
onUpdate: sortedBanners,
|
19
|
+
dragClass: 'banner-dragging',
|
20
|
+
handle: '.glyphicon-sort'
|
25
21
|
});
|
22
|
+
}
|
23
|
+
};
|
26
24
|
|
27
|
-
|
28
|
-
* Workaround for bug when using Bootstrap 2 + Tinymce 4 that prevents the creation of hyperlinks while
|
29
|
-
* running in a modal dialog
|
30
|
-
*
|
31
|
-
* See: http://stackoverflow.com/questions/18111582/tinymce-4-links-plugin-modal-in-not-editable
|
32
|
-
*
|
33
|
-
* NOTE: REMOVE THIS CODE WHEN UPGRADING TO BOOTSTRAP 3
|
34
|
-
*/
|
35
|
-
$(document).on('focusin', function(e) {
|
36
|
-
if($(e.target).closest(".mce-window").length){
|
37
|
-
e.stopImmediatePropagation();
|
38
|
-
}
|
39
|
-
});
|
40
|
-
};
|
41
|
-
|
42
|
-
// http://www.foliotek.com/devblog/make-table-rows-sortable-using-jquery-ui-sortable/
|
43
|
-
var fixHelper = function(e, ui) {
|
44
|
-
ui.children().each(function() {
|
45
|
-
$(this).width($(this).width());
|
46
|
-
});
|
47
|
-
return ui;
|
48
|
-
};
|
49
|
-
|
50
|
-
self.clickedAddNewBanner = function(e){
|
25
|
+
var clickedAddNewBanner = function(e){
|
51
26
|
e.preventDefault();
|
52
27
|
bannerEditId = false;
|
53
|
-
$.ajax({
|
54
|
-
url: $(this).attr('href'),
|
55
|
-
dataType: 'html',
|
56
|
-
success: function(html, textStatus, jqXHR){
|
57
|
-
spud.admin.modal.displayWithOptions({
|
58
|
-
title: 'Upload Banner',
|
59
|
-
html: html
|
60
|
-
});
|
61
|
-
initForm();
|
62
|
-
}
|
63
|
-
});
|
64
|
-
};
|
65
|
-
|
66
|
-
self.clickedEditBanner = function(e){
|
67
|
-
e.preventDefault();
|
68
28
|
spud.admin.editor.unload();
|
69
|
-
bannerEditId = parseInt($(this).parents('.admin-banner-set-item').attr('data-id'), 10);
|
70
29
|
$.ajax({
|
71
30
|
url: $(this).attr('href'),
|
72
31
|
dataType: 'html',
|
73
32
|
success: function(html, textStatus, jqXHR){
|
74
33
|
spud.admin.modal.displayWithOptions({
|
75
|
-
title: '
|
34
|
+
title: 'Upload Banner',
|
76
35
|
html: html
|
77
36
|
});
|
78
37
|
initForm();
|
@@ -80,138 +39,155 @@ spud.admin.banners = new function(){
|
|
80
39
|
});
|
81
40
|
};
|
82
41
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
});
|
95
|
-
if(textStatus != 'success'){
|
96
|
-
console.warn('Something went wrong:', jqXHR);
|
97
|
-
}
|
98
|
-
}
|
99
|
-
});
|
100
|
-
};
|
101
|
-
|
102
|
-
self.submittedBannerForm = function(e){
|
103
|
-
if(html5upload){
|
104
|
-
e.preventDefault();
|
105
|
-
|
106
|
-
var form = $(this);
|
107
|
-
var fd = new FormData();
|
108
|
-
|
109
|
-
$('input[type=text], input[type=hidden], select').each(function(index, element){
|
110
|
-
var input = $(element);
|
111
|
-
var name = input.attr('name');
|
112
|
-
var value = input.val();
|
113
|
-
fd.append(name, value);
|
42
|
+
var clickedEditBanner = function(e){
|
43
|
+
e.preventDefault();
|
44
|
+
bannerEditId = parseInt($(this).parents('.admin-banner-set-item').attr('data-id'), 10);
|
45
|
+
spud.admin.editor.unload();
|
46
|
+
$.ajax({
|
47
|
+
url: $(this).attr('href'),
|
48
|
+
dataType: 'html',
|
49
|
+
success: function(html, textStatus, jqXHR){
|
50
|
+
spud.admin.modal.displayWithOptions({
|
51
|
+
title: 'Edit Banner',
|
52
|
+
html: html
|
114
53
|
});
|
115
|
-
|
116
|
-
var richText = form.find('.spud_banner_rich_text');
|
117
|
-
if(richText.length > 0){
|
118
|
-
fd.append('spud_banner[rich_text]', richText.val());
|
119
|
-
}
|
120
|
-
else{
|
121
|
-
fd.append('spud_banner[rich_text]', '');
|
122
|
-
}
|
123
|
-
|
124
|
-
var file = form.find('#spud_banner_banner')[0].files[0];
|
125
|
-
if(file){
|
126
|
-
fd.append('spud_banner[banner]', file);
|
127
|
-
$('.spud_banner_upload_progress').show();
|
128
|
-
}
|
129
|
-
|
130
|
-
var xhr = new XMLHttpRequest();
|
131
|
-
xhr.upload.addEventListener('progress', self.onFileUploadProgress);
|
132
|
-
xhr.addEventListener('load', self.onFileUploadComplete);
|
133
|
-
xhr.addEventListener('error', self.onFileUploadError);
|
134
|
-
xhr.addEventListener('abort', self.onFileUploadAbort);
|
135
|
-
xhr.open('POST', form.attr('action'));
|
136
|
-
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
137
|
-
xhr.send(fd);
|
138
|
-
return false;
|
139
|
-
}
|
140
|
-
};
|
141
|
-
|
142
|
-
self.onFileUploadProgress = function(e){
|
143
|
-
var percent = Math.round(e.loaded * 100 / e.total);
|
144
|
-
var progress = $('.spud_banner_upload_progress');
|
145
|
-
progress.find('.bar').css({width: percent + '%'});
|
146
|
-
if(percent == 100){
|
147
|
-
progress.addClass('progress-success');
|
54
|
+
initForm();
|
148
55
|
}
|
149
|
-
};
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
}
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
};
|
171
|
-
|
172
|
-
// Non-html5 upload
|
173
|
-
self.onLegacyUploadComplete = function(html){
|
174
|
-
if(bannerEditId){
|
175
|
-
var item = $('.admin-banner-set-item[data-id="'+bannerEditId+'"]');
|
176
|
-
item.replaceWith(html);
|
56
|
+
});
|
57
|
+
};
|
58
|
+
|
59
|
+
var clickedDeleteBanner = function(e){
|
60
|
+
e.preventDefault();
|
61
|
+
$.ajaxSetup({
|
62
|
+
headers: { 'X-CSRF-TOKEN': Rails.csrfToken() }
|
63
|
+
});
|
64
|
+
var el = $(this);
|
65
|
+
$.ajax({
|
66
|
+
url: el.attr('href'),
|
67
|
+
type: 'post',
|
68
|
+
data: {'_method':'delete'},
|
69
|
+
complete: function(jqXHR, textStatus){
|
70
|
+
var parent = el.parents('.admin-banner-set-item');
|
71
|
+
parent.fadeOut(200, function(){
|
72
|
+
parent.remove();
|
73
|
+
});
|
74
|
+
if(textStatus != 'success'){
|
75
|
+
console.warn('Something went wrong:', jqXHR);
|
76
|
+
}
|
177
77
|
}
|
178
|
-
|
179
|
-
|
78
|
+
});
|
79
|
+
};
|
80
|
+
|
81
|
+
var submittedBannerForm = function(e){
|
82
|
+
e.preventDefault();
|
83
|
+
|
84
|
+
var form = $(this);
|
85
|
+
var fd = new FormData();
|
86
|
+
|
87
|
+
$('input[type=text], input[type=hidden], select').each(function(index, element){
|
88
|
+
var input = $(element);
|
89
|
+
var name = input.attr('name');
|
90
|
+
var value = input.val();
|
91
|
+
fd.append(name, value);
|
92
|
+
});
|
93
|
+
|
94
|
+
var richText = form.find('.admin-banner-rich-text');
|
95
|
+
if(richText.length > 0){
|
96
|
+
fd.append('spud_banner[rich_text]', richText.val());
|
97
|
+
}
|
98
|
+
else{
|
99
|
+
fd.append('spud_banner[rich_text]', '');
|
100
|
+
}
|
101
|
+
|
102
|
+
var file = form.find('#spud_banner_banner')[0].files[0];
|
103
|
+
if(file){
|
104
|
+
fd.append('spud_banner[banner]', file);
|
105
|
+
$('.admin-banner-upload-progress').show();
|
106
|
+
}
|
107
|
+
|
108
|
+
var xhr = new XMLHttpRequest();
|
109
|
+
xhr.upload.addEventListener('progress', onFileUploadProgress);
|
110
|
+
xhr.addEventListener('load', onFileUploadComplete);
|
111
|
+
xhr.addEventListener('error', onFileUploadError);
|
112
|
+
xhr.addEventListener('abort', onFileUploadAbort);
|
113
|
+
xhr.open('POST', form.attr('action'));
|
114
|
+
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
115
|
+
xhr.send(fd);
|
116
|
+
return false;
|
117
|
+
};
|
118
|
+
|
119
|
+
var onFileUploadProgress = function(e){
|
120
|
+
var percent = Math.round(e.loaded * 100 / e.total);
|
121
|
+
var progress = $('.admin-banner-upload-progress');
|
122
|
+
progress.find('.bar').css({width: percent + '%'});
|
123
|
+
if(percent == 100){
|
124
|
+
progress.addClass('progress-success');
|
125
|
+
}
|
126
|
+
};
|
127
|
+
|
128
|
+
var onFileUploadComplete = function(e){
|
129
|
+
switch(this.status){
|
130
|
+
case 200:
|
131
|
+
onUploadComplete(e.target.response);
|
132
|
+
break;
|
133
|
+
case 422:
|
134
|
+
onUploadError(e.target.response);
|
135
|
+
break;
|
136
|
+
default:
|
137
|
+
window.alert("Whoops! Something has gone wrong.");
|
138
|
+
}
|
139
|
+
};
|
140
|
+
|
141
|
+
var onFileUploadError = function(e){
|
142
|
+
|
143
|
+
};
|
144
|
+
|
145
|
+
var onFileUploadAbort = function(e){
|
146
|
+
|
147
|
+
};
|
148
|
+
|
149
|
+
var onUploadComplete = function(html){
|
150
|
+
if(bannerEditId){
|
151
|
+
var item = $('.admin-banner-set-item[data-id="'+bannerEditId+'"]');
|
152
|
+
item.replaceWith(html);
|
153
|
+
}
|
154
|
+
else{
|
155
|
+
$('.admin-banner-set-items-container').append(html);
|
156
|
+
}
|
157
|
+
spud.admin.modal.hide();
|
158
|
+
};
|
159
|
+
|
160
|
+
var onUploadError = function(html){
|
161
|
+
$('.admin-banner-form').replaceWith(html);
|
162
|
+
initForm();
|
163
|
+
};
|
164
|
+
|
165
|
+
var sortedBanners = function(e, ui){
|
166
|
+
var ids = [];
|
167
|
+
$('.admin-banner-set-item').each(function(){
|
168
|
+
ids.push($(this).attr('data-id'));
|
169
|
+
});
|
170
|
+
$.ajax({
|
171
|
+
headers: { 'X-CSRF-TOKEN': Rails.csrfToken() },
|
172
|
+
url: '/admin/banners/sort',
|
173
|
+
type: 'post',
|
174
|
+
data: { spud_banner_ids: ids, _method: 'put' }
|
175
|
+
});
|
176
|
+
};
|
177
|
+
|
178
|
+
var initForm = function(){
|
179
|
+
var richText = $('#admin-banner-rich-text');
|
180
|
+
if(richText){
|
181
|
+
if(typeof tinymce != "undefined"){
|
182
|
+
tinymce.EditorManager.execCommand('mceRemoveEditor', true, 'admin-banner-rich-text');
|
180
183
|
}
|
181
|
-
spud.admin.
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
initForm();
|
187
|
-
};
|
188
|
-
|
189
|
-
self.sortedBanners = function(e, ui){
|
190
|
-
var ids = [];
|
191
|
-
$('.admin-banner-set-item').each(function(){
|
192
|
-
ids.push($(this).attr('data-id'));
|
193
|
-
});
|
194
|
-
$.ajax({
|
195
|
-
url: '/admin/banners/sort',
|
196
|
-
type: 'post',
|
197
|
-
data: {spud_banner_ids:ids, _method:'put'}
|
184
|
+
spud.admin.editor.init({
|
185
|
+
selector: '#admin-banner-rich-text',
|
186
|
+
buttons: ['bold','italic','underline','formatselect','|','bullist','numlist','|','link','unlink','anchor', '|', 'code'],
|
187
|
+
height: 300,
|
188
|
+
width: 500
|
198
189
|
});
|
199
|
-
}
|
200
|
-
|
201
|
-
// Form Page
|
202
|
-
////////////
|
203
|
-
|
204
|
-
var initForm = function(){
|
205
|
-
var richText = $('#spud_banner_rich_text');
|
206
|
-
if(richText){
|
207
|
-
tinymce.EditorManager.execCommand('mceRemoveEditor', true, 'spud_banner_rich_text');
|
208
|
-
spud.admin.editor.init({
|
209
|
-
selector: '#spud_banner_rich_text',
|
210
|
-
buttons: ['bold','italic','underline','formatselect','|','bullist','numlist','|','link','unlink','anchor', '|', 'code'],
|
211
|
-
height: 300,
|
212
|
-
width: 500
|
213
|
-
});
|
214
|
-
}
|
215
|
-
};
|
190
|
+
}
|
191
|
+
};
|
216
192
|
|
217
|
-
}();
|
193
|
+
})();
|