caboose-cms 0.5.224 → 0.5.225

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTFkNTBhZjQ0ZjIyZGYxMmFhN2U2ZmFlOTViNWUyZDgwYmUzMmRhMA==
4
+ NzhiODE1NTkwZWI3NTQ3M2RiZjZkOTVlMDUzN2NlZDYwN2JjZjZmZA==
5
5
  data.tar.gz: !binary |-
6
- MTYwMjE2ODUxYzVjNTA4OWI3NDRkZDA1ZWQ3ZmNkMWVlZTNhYTA3Mw==
6
+ NDNkZmY3YTRjZWRmZjlmMWQ0MDBkNDU2YmZhYjBlN2I2ZWU4ZmIwZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzhkZjRhMjc1ZDA2NDg2YjkyYWJmOGI0ZjMxZjdmNDBlMjQwYzUzMGNlMDZl
10
- NTFhNmVjYWEwMGVkNzAyODg5NTA3OWZiYzRlNWFmNzA1NzhmMjE2ODkyNTRk
11
- OTdiNzBkNmVkNTI4MTU0Yjg0ZTcyMTlhNGZmYjYzZDhmNjZhNGQ=
9
+ ZTJhZmRkNGQzY2U1MzQ1ZmFjOTgxYzMxMjMxOTUyYWZjYjNmNGNkOGJkMGYy
10
+ N2VlNDQ0YjI3MDU1MWFkOWE0MDI5N2IzZDFhNjEzMWM0OTEzOGUwYWM2Yzkz
11
+ N2NmMzcwMmI4YmYyNTQ4ODBhOTYxYzY2ZmQzOWEzYmMyZDBiMjg=
12
12
  data.tar.gz: !binary |-
13
- MjQ5MDYzMGFhNjU2NTYzNzlmMGZkMzYwMTgyNmI4ODZlOGY2MWIyMTdhMTE3
14
- NjBjNTBmNDc0ZWM2MmEzY2I2NzI4ZWQwOGI0NjJlYWUyMmNmOTJkZDg5MDAy
15
- MjgwZGRjMjJiOWQzNjBiYTI0NjE4ZWU4NWE1NzZiNDU0MzM1YTU=
13
+ YjQwN2ViNjZlNjZlMTNkNjdjMDk5OTQyZjUxNGY1ZmQwYWU3NjYzNzc3Nzgx
14
+ YWIxODc5OWEwZWI2NWRkNTkwNTdmMzhmOTY3OTQ0NWJkM2Y0NzRlZWEyNjU0
15
+ NDc2MDVlZGExMzg5OTc5ODgzNTZhY2Y1MWUzNGVkYjg4NzMzOWM=
@@ -0,0 +1,131 @@
1
+
2
+ var BlockMediaController = function(params) { this.init(params); };
3
+
4
+ BlockMediaController.prototype = {
5
+
6
+ post_id: false,
7
+ page_id: false,
8
+ block_parent_id: false,
9
+ block_id: false,
10
+ top_cat_id: false,
11
+ cat: false,
12
+ cat_id: false,
13
+
14
+ init: function(params) {
15
+ var that = this;
16
+ for (var i in params)
17
+ this[i] = params[i];
18
+ that.refresh();
19
+ },
20
+
21
+ refresh: function()
22
+ {
23
+ var that = this;
24
+ that.refresh_categories(function() {
25
+ that.refresh_media();
26
+ });
27
+ },
28
+
29
+ refresh_categories: function(after)
30
+ {
31
+ var that = this;
32
+ $.ajax({
33
+ url: '/admin/media-categories/flat-tree',
34
+ type: 'get',
35
+ async: false,
36
+ success: function(resp) {
37
+ that.categories = resp;
38
+ if (!that.cat_id)
39
+ that.cat_id = that.categories[0].id;
40
+ that.print_categories();
41
+ if (after) after();
42
+ }
43
+ });
44
+ },
45
+
46
+ refresh_media: function()
47
+ {
48
+ var that = this;
49
+ $.ajax({
50
+ url: '/admin/media/json',
51
+ type: 'get',
52
+ async: false,
53
+ data: { media_category_id: that.cat_id },
54
+ success: function(resp) {
55
+ that.cat = resp;
56
+ that.cat_id = that.cat.id;
57
+ that.selected_media = [];
58
+ that.print_media();
59
+ }
60
+ });
61
+ },
62
+
63
+ print_categories: function()
64
+ {
65
+ var that = this;
66
+ var ul = $('<ul/>');
67
+ if (that.categories.length > 0)
68
+ {
69
+ $.each(that.categories, function(i, cat) {
70
+ var li = $('<li/>')
71
+ .addClass('category')
72
+ .attr('id', 'cat' + cat.id)
73
+ .data('media_category_id', cat.id)
74
+ .append($('<a/>').attr('href', '#').html(cat.name + ' (' + cat.media_count + ')').click(function(e) { e.preventDefault(); that.select_category($(this).parent().data('media_category_id')); }));
75
+ if (cat.id == that.cat_id)
76
+ li.addClass('selected');
77
+ ul.append(li);
78
+ });
79
+ }
80
+ else
81
+ ul = $('<p/>').html("There are no media categories.");
82
+ $('#categories').empty().append(ul);
83
+ },
84
+
85
+ print_media: function()
86
+ {
87
+ var that = this;
88
+ var ul = $('<ul/>');
89
+ if (that.cat.media.length > 0)
90
+ {
91
+ $.each(that.cat.media, function(i, m) {
92
+ var li = $('<li/>')
93
+ .attr('id', 'media' + m.id)
94
+ .addClass('media')
95
+ .data('media_id', m.id)
96
+ .click(function(e) { that.select_media($(this).data('media_id')); })
97
+ .append($('<span/>').addClass('name').html(m.name));
98
+ if (m.image_urls)
99
+ li.append($('<img/>').attr('src', m.image_urls.tiny_url));
100
+ ul.append(li);
101
+ });
102
+ }
103
+ else
104
+ ul = $('<p/>').html("This category is empty.");
105
+ $('#media').empty().append(ul);
106
+ },
107
+
108
+ //============================================================================
109
+
110
+ select_media: function(media_id)
111
+ {
112
+ var that = this;
113
+ $.ajax({
114
+ url: '/admin/' + (that.page_id ? 'pages/' + that.page_id : 'posts/' + that.post_id) + '/blocks/' + that.block_id,
115
+ type: 'put',
116
+ data: { media_id: media_id },
117
+ success: function(resp) {
118
+ window.location = '/admin/pages/' + that.page_id + '/blocks/' + that.block_parent_id + '/edit';
119
+ }
120
+ });
121
+ },
122
+
123
+ select_category: function(cat_id)
124
+ {
125
+ var that = this;
126
+ that.cat_id = cat_id;
127
+ that.print_categories();
128
+ that.refresh_media();
129
+ }
130
+
131
+ };
@@ -0,0 +1,140 @@
1
+
2
+ BoundImage = BoundControl.extend({
3
+
4
+ //el: false,
5
+ //model: false,
6
+ //attribute: false,
7
+ //binder: false,
8
+
9
+ width: 100,
10
+ style: 'medium',
11
+ authenticity_token: false,
12
+
13
+ init: function(params) {
14
+ for (var thing in params)
15
+ this[thing] = params[thing];
16
+
17
+ this.el = this.el ? this.el : this.model.name.toLowerCase() + '_' + this.model.id + '_' + this.attribute.name;
18
+
19
+ if (!this.attribute.update_url)
20
+ this.attribute.update_url = this.model.update_url;
21
+
22
+ var this2 = this;
23
+ $('#'+this.el).wrap($('<div/>')
24
+ .attr('id', this.el + '_container')
25
+ .addClass('mb_container')
26
+ .css('position', 'relative')
27
+ );
28
+ $('#'+this.el+'_container').empty();
29
+
30
+ $('#'+this.el+'_container').append($('<img/>')
31
+ .attr('src', this.attribute.value)
32
+ .css('width', this.width)
33
+ .css('float', 'left')
34
+ .css('margin-right', 10)
35
+ );
36
+ $('#'+this.el+'_container')
37
+ .append($('<form target="' + this.el + '_iframe"></form>')
38
+ .attr('id', this.el + '_form')
39
+ .attr('action', this.attribute.update_url)
40
+ .attr('method', 'post')
41
+ .attr('enctype', 'multipart/form-data')
42
+ .attr('encoding', 'multipart/form-data')
43
+ //.attr('target', this.el + '_iframe')
44
+ .on('submit', function() {
45
+ $('#'+this2.el+'_message').html("<p class='loading'>Uploading...</p>");
46
+ $('#'+this2.el+'_iframe').on('load', function() { this2.post_upload(); });
47
+ return true;
48
+ })
49
+ .append($('<input/>').attr('type', 'hidden').attr('name', 'authenticity_token').val(this.binder.authenticity_token))
50
+ .append($('<div/>')
51
+ .attr('id', this.el + '_fake_file_input')
52
+ .addClass('mb_fake_file_input')
53
+ .append($('<input/>')
54
+ .attr('type', 'button')
55
+ .attr('id', this.el + '_update_button')
56
+ .val('Update ' + this.attribute.nice_name)
57
+ .click(function() { $('#'+this2.el+'_file').click(); })
58
+ )
59
+ .append($('<input/>')
60
+ .attr('type', 'file')
61
+ .attr('id', this.el + '_file')
62
+ .attr('name', this.attribute.name)
63
+ .change(function() { $('#'+this2.el+'_form').trigger('submit'); })
64
+ )
65
+ .append($('<input/>')
66
+ .attr('type', 'submit')
67
+ .val('Submit')
68
+ )
69
+ )
70
+ );
71
+ $('#'+this.el+'_container').append($('<div/>')
72
+ .attr('id', this.el + '_message')
73
+ );
74
+ iframe = $("<iframe name=\"" + this.el + "_iframe\" id=\"" + this.el + "_iframe\" src=''></iframe>");
75
+ if (this.attribute.debug)
76
+ iframe.css('width', '100%').css('height', 600).css('background', '#fff');
77
+ else
78
+ iframe.css('width', 0).css('height', 0).css('border', 0);
79
+ $('#'+this.el+'_container').append(iframe);
80
+ $('#'+this.el+'_container').append($('<br/>').css('clear', 'both'));
81
+
82
+ var w = $('#' + this.el + '_update_button').outerWidth(true);
83
+ $('#' + this.el + '_fake_file_input').css('width', '' + w + 'px');
84
+ },
85
+
86
+ post_upload: function() {
87
+ $('#'+this.el+'_message').empty();
88
+
89
+ var str = frames[this.el+'_iframe'].document.documentElement.innerHTML;
90
+ str = str.replace(/[\s\S]*?{([\s\S]*?)/, '{$1');
91
+ str = str.substr(0, str.lastIndexOf('}')+1);
92
+ var resp = $.parseJSON(str);
93
+ if (resp.success)
94
+ {
95
+ if (resp.attributes && resp.attributes[this.attribute.name])
96
+ for (var thing in resp.attributes[this.attribute.name])
97
+ this.attribute[thing] = resp.attributes[this.attribute.name][thing];
98
+ this.attribute.value_clean = this.attribute.value;
99
+ }
100
+
101
+ if (resp.error)
102
+ this.error(resp.error);
103
+ else
104
+ {
105
+ if (this.attribute.image_refresh_delay)
106
+ {
107
+ var that = this;
108
+ setTimeout(function() { that.refresh_image(); }, this.attribute.image_refresh_delay);
109
+ }
110
+ else
111
+ {
112
+ this.refresh_image();
113
+ }
114
+ }
115
+ },
116
+
117
+ refresh_image: function() {
118
+ var src = this.attribute.value;
119
+ if (src.indexOf('?') > 0)
120
+ src = src.split('?')[0];
121
+ src = src + '?' + Math.random();
122
+ $('#'+this.el+'_container img').attr('src', src);
123
+ },
124
+
125
+ error: function(str) {
126
+ if (!$('#'+this.el+'_message').length)
127
+ {
128
+ $('#'+this.el+'_container').append($('<div/>')
129
+ .attr('id', this.el + '_message')
130
+ .css('width', $('#'+this.el).outerWidth())
131
+ );
132
+ }
133
+ $('#'+this.el+'_message').hide();
134
+ $('#'+this.el+'_message').html("<p class='note error'>" + str + "</p>");
135
+ $('#'+this.el+'_message').slideDown();
136
+ var this2 = this;
137
+ setTimeout(function() { $('#'+this2.el+'_message').slideUp(function() { $(this).empty(); }); }, 3000);
138
+ }
139
+
140
+ });
@@ -0,0 +1,117 @@
1
+
2
+ #left_content {
3
+ width: 280px;
4
+ float: left;
5
+ }
6
+
7
+ #right_content {
8
+ margin-left: 300px;
9
+ max-height: 600px;
10
+ overflow-y: scroll;
11
+ }
12
+
13
+ #categories {
14
+ ul {
15
+ list-style: none;
16
+ margin: 0;
17
+ padding: 0;
18
+
19
+ li {
20
+ list-style: none;
21
+ margin: 0;
22
+ padding: 0;
23
+
24
+ a {
25
+ display: block;
26
+ margin: 0 0 2px 0;
27
+ padding: 4px 8px;
28
+ background: #ddd;
29
+ border: #999 1px solid;
30
+ color: #000;
31
+ text-decoration: none;
32
+
33
+ &:hover {
34
+ background-color: #fff799;
35
+ }
36
+ }
37
+
38
+ &.selected {
39
+ a {
40
+ font-weight: bold;
41
+ background-color: #90dbf9;
42
+ }
43
+ }
44
+ &.cat_hover {
45
+ a {
46
+ background-color: #fff799 !important;
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+
53
+ #controls {
54
+ #delete {
55
+ p.delete_dropper {
56
+ padding: 8px 8px;
57
+ background: #ddd;
58
+ border: #999 1px solid;
59
+ color: #000;
60
+ text-decoration: none;
61
+ }
62
+ &.hover {
63
+ p.delete_dropper {
64
+ background-color: #fff799 !important;
65
+ }
66
+ }
67
+ }
68
+ }
69
+
70
+ #the_uploader {
71
+ margin-bottom: 20px;
72
+ padding-right: 20px;
73
+ }
74
+
75
+ #media {
76
+ ul {
77
+ list-style: none;
78
+ margin: 0 0 20px 0;
79
+ padding: 0;
80
+
81
+ li {
82
+ position: relative;
83
+ list-style: none;
84
+ margin: 4px;
85
+ padding: 0;
86
+ display: inline-block;
87
+ width: 150px;
88
+ height: 150px;
89
+ overflow: hidden;
90
+ background-color: #666;
91
+ background-position: center;
92
+ background-size: contain;
93
+ background-repeat: no-repeat;
94
+ border: #666 4px solid;
95
+
96
+ span.name {
97
+ display: block;
98
+ position: absolute;
99
+ bottom: 4px;
100
+ width: 150px;
101
+ text-align: center;
102
+ color: #fff;
103
+ text-decoration: none !important;
104
+ }
105
+ &:hover {
106
+ background-color: #fff799;
107
+ border: #fff799 4px solid;
108
+ span { background-color: #fff799; color: #000; }
109
+ }
110
+ &.selected {
111
+ background-color: #90dbf9;
112
+ border: #90dbf9 4px solid;
113
+ span { background-color: #90dbf9; color: #000; }
114
+ }
115
+ }
116
+ }
117
+ }
@@ -206,11 +206,21 @@ module Caboose
206
206
  @document_domain = request.host
207
207
  @document_domain.gsub('http://', '')
208
208
  @document_domain.gsub('https://', '')
209
-
210
- begin
211
- render "caboose/blocks/admin_edit_#{@block.block_type.full_name}", :layout => 'caboose/modal'
212
- rescue
213
- render :layout => 'caboose/modal'
209
+
210
+ full_name = @block.block_type.full_name
211
+ begin
212
+ if full_name != 'image'
213
+ render "caboose/blocks/admin_edit_#{@block.block_type.full_name}", :layout => 'caboose/modal'
214
+ else
215
+ render :layout => 'caboose/modal'
216
+ end
217
+ rescue ActionView::MissingTemplate => ex
218
+ begin
219
+ render "caboose/blocks/admin_edit_#{@block.block_type.field_type}", :layout => 'caboose/modal'
220
+ rescue ActionView::MissingTemplate => ex
221
+ render :layout => 'caboose/modal'
222
+ Caboose.log('test4')
223
+ end
214
224
  end
215
225
  end
216
226
 
@@ -322,6 +332,7 @@ module Caboose
322
332
  when 'sort_order' then b.sort_order = v
323
333
  when 'constrain' then b.constrain = v
324
334
  when 'full_width' then b.full_width = v
335
+ when 'media_id' then b.media_id = v
325
336
  when 'name' then b.name = v
326
337
  when 'value' then
327
338
 
@@ -6,11 +6,10 @@ class Caboose::Block < ActiveRecord::Base
6
6
 
7
7
  belongs_to :post
8
8
  belongs_to :page
9
+ belongs_to :media
9
10
  belongs_to :block_type
10
11
  belongs_to :parent, :foreign_key => 'parent_id', :class_name => 'Caboose::Block'
11
12
  has_many :children, :foreign_key => 'parent_id', :class_name => 'Caboose::Block', :dependent => :delete_all, :order => 'sort_order'
12
- belongs_to :media_file
13
- belongs_to :media_image
14
13
  has_attached_file :file, :path => ':path_prefixuploads/:block_file_upload_name.:extension'
15
14
  do_not_validate_attachment_file_type :file
16
15
  has_attached_file :image,
@@ -55,7 +54,7 @@ class Caboose::Block < ActiveRecord::Base
55
54
  #end
56
55
  end
57
56
 
58
- def full_name
57
+ def full_name
59
58
  return self.name if parent_id.nil?
60
59
  return "#{parent.full_name}_#{self.name}"
61
60
  end
@@ -63,6 +62,14 @@ class Caboose::Block < ActiveRecord::Base
63
62
  def child_value(name)
64
63
  b = self.child(name)
65
64
  return nil if b.nil?
65
+ #if b.block_type.field_type == 'image'
66
+ # return b.media.image if b.media
67
+ # return b.image
68
+ #end
69
+ #if b.block_type.field_type == 'file'
70
+ # return b.media.file if b.media
71
+ # return b.file
72
+ #end
66
73
  return b.image if b.block_type.field_type == 'image'
67
74
  return b.file if b.block_type.field_type == 'file'
68
75
  return b.value
@@ -211,6 +218,7 @@ class Caboose::Block < ActiveRecord::Base
211
218
  "caboose/blocks/#{block.block_type.name}",
212
219
  "caboose/blocks/#{block.block_type.field_type}"
213
220
  ]
221
+ Caboose.log(arr)
214
222
  str = self.render_helper(view, options2, block, full_name, arr, 0)
215
223
 
216
224
  end
@@ -491,5 +499,36 @@ class Caboose::Block < ActiveRecord::Base
491
499
  end
492
500
  return str
493
501
  end
502
+
503
+ def migrate_media
504
+
505
+ if self.block_type.field_type == 'image' && !self.image_file_name.nil? && self.media_id.nil?
506
+
507
+ site_id = self.page_id ? self.page.site_id : self.post.site_id
508
+ cat = Caboose::MediaCategory.top_category(site_id)
509
+ m = Caboose::Media.create(:media_category_id => cat.id, :original_name => self.image_file_name, :name => Caboose::Media.upload_name(self.image_file_name))
510
+ m.image = URI.parse(self.image.url(:original))
511
+ m.processed = true
512
+ m.save
513
+
514
+ self.media_id = m.id
515
+ self.save
516
+
517
+ elsif self.block_type.field_type == 'file' && !self.file_file_name.nil? && self.media_id.nil?
518
+
519
+ site_id = self.page_id ? self.page.site_id : self.post.site_id
520
+ cat = Caboose::MediaCategory.top_category(site_id)
521
+ m = Caboose::Media.create(:media_category_id => cat.id, :original_name => self.file_file_name, :name => Caboose::Media.upload_name(self.file_file_name))
522
+ m.file = URI.parse(self.file.url)
523
+ m.processed = true
524
+ m.save
525
+
526
+ self.media_id = m.id
527
+ self.save
528
+
529
+ end
530
+
531
+ end
532
+
494
533
 
495
534
  end
@@ -32,7 +32,7 @@ class Caboose::BlockType < ActiveRecord::Base
32
32
  :share, # Whether or not to share the block type in the existing block store.
33
33
  :downloaded # Whether the full block type has been download or just the name and description.
34
34
 
35
- def full_name
35
+ def full_name
36
36
  return name if parent_id.nil?
37
37
  return "#{parent.full_name}_#{name}"
38
38
  end
@@ -90,5 +90,10 @@ class Caboose::Media < ActiveRecord::Base
90
90
  return '' if str.nil?
91
91
  return File.basename(str, File.extname(str)).downcase.gsub(' ', '-').gsub(/[^\w-]/, '')
92
92
  end
93
+
94
+ def file_url
95
+ return self.image.url(:original) if self.image && !self.image.url(:original).starts_with?('http://placehold.it')
96
+ return self.file.url
97
+ end
93
98
 
94
99
  end
@@ -149,10 +149,11 @@ class Caboose::Schema < Caboose::Utilities::Schema
149
149
  [ :page_id , :integer ],
150
150
  [ :post_id , :integer ],
151
151
  [ :parent_id , :integer ],
152
+ [ :media_id , :integer ],
152
153
  [ :block_type_id , :integer ],
153
154
  [ :sort_order , :integer , { :default => 0 }],
154
155
  [ :constrain , :boolean , { :default => false }],
155
- [ :full_width , :boolean , { :default => false }],
156
+ [ :full_width , :boolean , { :default => false }],
156
157
  [ :name , :string ],
157
158
  [ :value , :text ],
158
159
  [ :file , :attachment ],
@@ -925,10 +926,8 @@ class Caboose::Schema < Caboose::Utilities::Schema
925
926
 
926
927
  # Make sure a top-level media category for each site exists
927
928
  Caboose::Site.all.each do |site|
928
- cat = Caboose::MediaCategory.where("parent_id is null and site_id = ? and name = ?", site.id, 'Images').first
929
- Caboose::MediaCategory.create(:site_id => site.id, :name => 'Images') if cat.nil?
930
- cat = Caboose::MediaCategory.where("parent_id is null and site_id = ? and name = ?", site.id, 'Files').first
931
- Caboose::MediaCategory.create(:site_id => site.id, :name => 'Files') if cat.nil?
929
+ cat = Caboose::MediaCategory.where(:site_id => site.id, :parent_id => nil, :name => 'Media').first
930
+ Caboose::MediaCategory.create(:site_id => site.id, :parent_id => nil, :name => 'Media') if cat.nil?
932
931
  end
933
932
 
934
933
  # Make sure a default category exists for all products
@@ -1,11 +1,22 @@
1
1
  <%
2
- file = block.child_value('file')
3
- text = block.child_value('text')
4
-
5
- if editing && file && file.url.include?('missing.png')
6
- %><div id='block_<%= block.id %>'><p>Please upload a file.</p></div><%
7
- elsif file
8
- %><div id='block_<%= block.id %>'><p><a href="<%= raw file.url %>"><%= raw text %></a></p></div><%
2
+ url = nil
3
+ name = nil
4
+ if block.media
5
+ url = block.media.file_url
6
+ name = block.media.file_file_name
7
+ name = block.media.image_file_name if name.nil?
8
+ elsif block.file
9
+ url = block.file.url
10
+ name = block.file_file_name
9
11
  end
10
12
 
13
+ if editing
14
+ if url.nil? || url.starts_with?('http://placehold.it') || url.include?('missing')
15
+ %><div id='block_<%= block.id %>'><p>Please upload a file.</p></div><%
16
+ else
17
+ %><div id='block_<%= block.id %>'><p><a href="/admin/<%= block.page_id ? "pages/#{block.page_id}" : "posts/#{block.post_id}" %>/blocks/<%= block.id %>/edit"><%= name %></a></p></div><%
18
+ end
19
+ elsif url
20
+ %><div id='block_<%= block.id %>'><p><a href="<%= raw file.url %>">Download File</a></p></div><%
21
+ end
11
22
  %>
@@ -1,58 +1,14 @@
1
- <%
2
- img = block.child_value('image_src')
3
- img_style = block.child_value('image_style')
4
- link = block.child_value('link')
5
- align = block.child_value('align')
6
- width = block.child_value('width')
7
- height = block.child_value('height')
8
- mt = block.child_value('margin_top')
9
- mr = block.child_value('margin_right')
10
- mb = block.child_value('margin_bottom')
11
- ml = block.child_value('margin_left')
12
- mt.downcase! if mt
13
- mr.downcase! if mr
14
- mb.downcase! if mb
15
- ml.downcase! if ml
16
- url = img ? img.url(img_style.downcase.to_sym) : nil
17
-
18
- img = nil
19
- if url && !url.include?('missing.png')
20
- style = []
21
- if align == 'Center'
22
- ml = 'auto'
23
- mr = 'auto'
24
- style << "display: block"
25
- end
26
-
27
- ml = "#{ml}px" if ml && ml != 'auto' && !ml.ends_with?('px') && !ml.ends_with?('em') && !ml.ends_with?('%')
28
- mr = "#{mr}px" if mr && mr != 'auto' && !mr.ends_with?('px') && !mr.ends_with?('em') && !mr.ends_with?('%')
29
- mt = "#{mt}px" if mt && mt != 'auto' && !mt.ends_with?('px') && !mt.ends_with?('em') && !mt.ends_with?('%')
30
- mb = "#{mb}px" if mb && mb != 'auto' && !mb.ends_with?('px') && !mb.ends_with?('em') && !mb.ends_with?('%')
31
-
32
- style << "width: #{width}px" if width
33
- style << "max-height: #{height}px" if height
34
- style << "float: left" if align == 'Left'
35
- style << "float: right" if align == 'Right'
36
- style << "margin-left: #{ml}" if ml
37
- style << "margin-right: #{mr}" if mr
38
- style << "margin-top: #{mt}" if mt
39
- style << "margin-bottom: #{mb}" if mb
40
- style = style.join('; ')
41
-
42
- img = "<img src='#{url}' style='#{style}' id='block_#{block.id}' />"
43
- if link && link.strip.length > 0
44
- if editing
45
- img = "<a href='#'>#{img}</a>"
46
- else
47
- img = "<a href='#{link}'>#{img}</a>"
48
- end
49
- end
50
- end
51
-
52
- if editing && img.nil?
1
+ <%
2
+ url = nil
3
+ if block.media
4
+ url = block.media.image.url(:tiny)
5
+ elsif block.image
6
+ url = block.image.url(:tiny)
7
+ end
8
+
9
+ if editing && url.nil?
53
10
  %><p id='block_<%= block.id %>'>Please upload an image.</p><%
54
11
  else
55
- %><%= raw img %><%
12
+ %><img src='<%= raw url %>' id='block_<%= block.id %>' /><%
56
13
  end
57
-
58
14
  %>
@@ -0,0 +1,69 @@
1
+ <%
2
+ Caboose.log(block.id)
3
+ image_src = block.child('image_src')
4
+ Caboose.log(image_src)
5
+ Caboose.log(image_src.media_id)
6
+
7
+ img = block.child_value('image_src')
8
+ img_style = block.child_value('image_style')
9
+ link = block.child_value('link')
10
+ align = block.child_value('align')
11
+ width = block.child_value('width')
12
+ height = block.child_value('height')
13
+ mt = block.child_value('margin_top')
14
+ mr = block.child_value('margin_right')
15
+ mb = block.child_value('margin_bottom')
16
+ ml = block.child_value('margin_left')
17
+ mt.downcase! if mt
18
+ mr.downcase! if mr
19
+ mb.downcase! if mb
20
+ ml.downcase! if ml
21
+ url = img ? img.url(img_style.downcase.to_sym) : nil
22
+ url = nil
23
+
24
+ if image_src && image_src.media
25
+ url = image_src.media.image.url(img_style.downcase.to_sym)
26
+ elsif img
27
+ url = img.url(img_style.downcase.to_sym)
28
+ end
29
+
30
+ img = nil
31
+ alt = block.child_value('alt_text').blank? ? "" : block.child_value('alt_text')
32
+ if url && !url.include?('missing.png')
33
+ style = []
34
+ if align == 'Center'
35
+ ml = 'auto'
36
+ mr = 'auto'
37
+ style << "display: block"
38
+ end
39
+
40
+ ml = "#{ml}px" if ml && ml != 'auto' && !ml.ends_with?('px') && !ml.ends_with?('em') && !ml.ends_with?('%')
41
+ mr = "#{mr}px" if mr && mr != 'auto' && !mr.ends_with?('px') && !mr.ends_with?('em') && !mr.ends_with?('%')
42
+ mt = "#{mt}px" if mt && mt != 'auto' && !mt.ends_with?('px') && !mt.ends_with?('em') && !mt.ends_with?('%')
43
+ mb = "#{mb}px" if mb && mb != 'auto' && !mb.ends_with?('px') && !mb.ends_with?('em') && !mb.ends_with?('%')
44
+
45
+ style << "width: #{width}px" if width
46
+ style << "max-height: #{height}px" if height
47
+ style << "float: left" if align == 'Left'
48
+ style << "float: right" if align == 'Right'
49
+ style << "margin-left: #{ml}" if ml
50
+ style << "margin-right: #{mr}" if mr
51
+ style << "margin-top: #{mt}" if mt
52
+ style << "margin-bottom: #{mb}" if mb
53
+ style = style.join('; ')
54
+
55
+ img = "<img src='#{url}' style='#{style}' id='block_#{block.id}' alt='#{alt}' />"
56
+ if link && link.strip.length > 0
57
+ if editing
58
+ img = "<a href='#'>#{img}</a>"
59
+ else
60
+ img = "<a href='#{link}'>#{img}</a>"
61
+ end
62
+ end
63
+ end
64
+ if editing && img.nil?
65
+ %><p id='block_<%= block.id %>'>TPlease upload an image.</p><%
66
+ else
67
+ %><%= raw img %><%
68
+ end
69
+ %>
@@ -41,12 +41,12 @@ end
41
41
  <!-- Stop -->
42
42
  <% elsif @block.block_type.field_type != 'block' %>
43
43
  <p><div id='block_<%= @block.id %>_value'></div></p>
44
- <% else %>
44
+ <% else %>
45
45
  <% if @block.children.count > 0 %>
46
- <% @block.children.order(:sort_order).each do |b| %>
47
- <% if b.block_type.field_type != 'block' && b.block_type.field_type != 'richtext' %>
46
+ <% @block.children.order(:sort_order).each do |b| %>
47
+ <% if b.block_type.field_type != 'block' && b.block_type.field_type != 'richtext' && b.block_type.field_type != 'image' && b.block_type.field_type != 'file' %>
48
48
  <div style='margin-bottom: 10px;'><div id='block_<%= b.id %>_value'></div></div>
49
- <% else %>
49
+ <% else %>
50
50
  <%
51
51
  #Caboose.log(b.value)
52
52
  #Caboose.log(b.name)
@@ -0,0 +1,73 @@
1
+ <%
2
+ base_url = @block.page_id ? "/admin/pages/#{@block.page_id}/blocks" : "/admin/posts/#{@block.post_id}/blocks"
3
+ crumbs = []
4
+ b = @block
5
+ while b
6
+ href = b.id == @block.id ? "#" : "#{base_url}/#{b.id}/edit"
7
+ text = b.name ? "#{b.block_type.description} (#{b.name})" : b.block_type.description
8
+ crumbs << "<a href=\"#{href}\">#{text}</a>"
9
+ b = b.parent
10
+ end
11
+
12
+ url = nil
13
+ name = nil
14
+ if @block.media
15
+ url = @block.media.file_url
16
+ name = @block.media.file_file_name
17
+ name = @block.media.image_file_name if name.nil?
18
+ elsif @block.image
19
+ url = @block.file.url
20
+ name = @block.file_file_name
21
+ end
22
+
23
+ %>
24
+ <h2 style='margin-top: 0; padding-top: 0;'><%= raw crumbs.reverse.join(' > ') %></h2>
25
+
26
+ <div id='left_content'>
27
+ <div id='categories'></div>
28
+ <div id='controls'>
29
+ <% if url.nil? || url.include?('missing') %>
30
+ <p>Please select a file.</p>
31
+ <% else %>
32
+ <p>Current File</p>
33
+ <p><%= name %></p>
34
+ <% end %>
35
+ </div>
36
+ </div>
37
+ <div id='right_content'>
38
+ <div id='uploader'></div>
39
+ <div id='media'></div>
40
+ </div>
41
+
42
+ <p>
43
+ <input type='button' value='< Back' onclick="window.location='/admin/pages/<%= @block.page_id %>/blocks/<%= @block.parent_id %>/edit';" />
44
+ <input type='button' value='Close' onclick="parent.controller.render_blocks(); modal.close();" />
45
+ <input type='button' value='Manage Media' onclick="parent.window.location='/admin/media';" />
46
+ </p>
47
+
48
+ <% content_for :caboose_css do %>
49
+ <%= stylesheet_link_tag 'caboose/admin_block_edit_image' %>
50
+ <% end %>
51
+
52
+ <% content_for :caboose_js do %>
53
+ <%= javascript_include_tag "caboose/model/all" %>
54
+ <%= javascript_include_tag "caboose/block_media_controller" %>
55
+ <script type='text/javascript'>
56
+
57
+ var modal = false;
58
+ $(window).load(function() {
59
+ modal = new CabooseModal(800);
60
+ });
61
+
62
+ var controller = false;
63
+ $(document).ready(function() {
64
+ controller = new BlockMediaController({
65
+ <% if @block.page_id %>page_id: <%= @block.page_id %><% else %>post_id: <%= @block.post_id %><% end %>,
66
+ block_id: <%= @block.id %>,
67
+ block_parent_id: <%= @block.parent_id %>,
68
+ authenticity_token: '<%= form_authenticity_token %>'
69
+ });
70
+ });
71
+
72
+ </script>
73
+ <% end %>
@@ -0,0 +1,69 @@
1
+ <%
2
+ base_url = @block.page_id ? "/admin/pages/#{@block.page_id}/blocks" : "/admin/posts/#{@block.post_id}/blocks"
3
+ crumbs = []
4
+ b = @block
5
+ while b
6
+ href = b.id == @block.id ? "#" : "#{base_url}/#{b.id}/edit"
7
+ text = b.name ? "#{b.block_type.description} (#{b.name})" : b.block_type.description
8
+ crumbs << "<a href=\"#{href}\">#{text}</a>"
9
+ b = b.parent
10
+ end
11
+
12
+ url = nil
13
+ if @block.media
14
+ url = @block.media.image.url(:tiny)
15
+ elsif @block.image
16
+ url = @block.image.url(:tiny)
17
+ end
18
+
19
+ %>
20
+ <h2 style='margin-top: 0; padding-top: 0;'><%= raw crumbs.reverse.join(' > ') %></h2>
21
+
22
+ <div id='left_content'>
23
+ <div id='categories'></div>
24
+ <div id='controls'>
25
+ <% if url.nil? %>
26
+ <p>Please upload an image.</p>
27
+ <% else %>
28
+ <p>Current Image</p>
29
+ <p><img src='<%= raw url %>' /></p>
30
+ <% end %>
31
+ </div>
32
+ </div>
33
+ <div id='right_content'>
34
+ <div id='uploader'></div>
35
+ <div id='media'></div>
36
+ </div>
37
+
38
+ <p>
39
+ <input type='button' value='< Back' onclick="window.location='/admin/pages/<%= @block.page_id %>/blocks/<%= @block.parent_id %>/edit';" />
40
+ <input type='button' value='Close' onclick="parent.controller.render_blocks(); modal.close();" />
41
+ <input type='button' value='Manage Media' onclick="parent.window.location='/admin/media';" />
42
+ </p>
43
+
44
+ <% content_for :caboose_css do %>
45
+ <%= stylesheet_link_tag 'caboose/admin_block_edit_image' %>
46
+ <% end %>
47
+
48
+ <% content_for :caboose_js do %>
49
+ <%= javascript_include_tag "caboose/model/all" %>
50
+ <%= javascript_include_tag "caboose/block_media_controller" %>
51
+ <script type='text/javascript'>
52
+
53
+ var modal = false;
54
+ $(window).load(function() {
55
+ modal = new CabooseModal(800);
56
+ });
57
+
58
+ var controller = false;
59
+ $(document).ready(function() {
60
+ controller = new BlockMediaController({
61
+ <% if @block.page_id %>page_id: <%= @block.page_id %><% else %>post_id: <%= @block.post_id %><% end %>,
62
+ block_id: <%= @block.id %>,
63
+ block_parent_id: <%= @block.parent_id %>,
64
+ authenticity_token: '<%= form_authenticity_token %>'
65
+ });
66
+ });
67
+
68
+ </script>
69
+ <% end %>
@@ -1,3 +1,3 @@
1
1
  module Caboose
2
- VERSION = '0.5.224'
2
+ VERSION = '0.5.225'
3
3
  end
@@ -1,7 +1,14 @@
1
1
  require "caboose/version"
2
2
 
3
3
  namespace :caboose do
4
-
4
+
5
+ desc "Migrate block images to media"
6
+ task :migrate_block_images_to_media => :environment do
7
+ Caboose::Block.where("image_file_name is not null").reorder(:id).limit(1).all.each do |b|
8
+ b.migrate_media
9
+ end
10
+ end
11
+
5
12
  desc "Update expired caches and cache pages that aren't cached"
6
13
  task :cache_pages => :environment do
7
14
  Caboose::PageCacher.delay.refresh
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caboose-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.224
4
+ version: 0.5.225
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Barry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-29 00:00:00.000000000 Z
11
+ date: 2015-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -406,6 +406,7 @@ files:
406
406
  - app/assets/javascripts/caboose/admin_products.js
407
407
  - app/assets/javascripts/caboose/application.js
408
408
  - app/assets/javascripts/caboose/authorize.net.js
409
+ - app/assets/javascripts/caboose/block_media_controller.js
409
410
  - app/assets/javascripts/caboose/cart.js
410
411
  - app/assets/javascripts/caboose/cart_old.js
411
412
  - app/assets/javascripts/caboose/checkout.js
@@ -443,6 +444,7 @@ files:
443
444
  - app/assets/javascripts/caboose/model/bound_date_time.js
444
445
  - app/assets/javascripts/caboose/model/bound_file.js
445
446
  - app/assets/javascripts/caboose/model/bound_image.js
447
+ - app/assets/javascripts/caboose/model/bound_image_bak.js
446
448
  - app/assets/javascripts/caboose/model/bound_richtext.js
447
449
  - app/assets/javascripts/caboose/model/bound_s3_image.js
448
450
  - app/assets/javascripts/caboose/model/bound_select.js
@@ -538,6 +540,7 @@ files:
538
540
  - app/assets/javascripts/plupload/plupload.min.js
539
541
  - app/assets/javascripts/tinymce/plugins/caboose/plugin.js
540
542
  - app/assets/stylesheets/caboose/admin.css
543
+ - app/assets/stylesheets/caboose/admin_block_edit_image.css.scss
541
544
  - app/assets/stylesheets/caboose/admin_crumbtrail.css.scss
542
545
  - app/assets/stylesheets/caboose/admin_main.css
543
546
  - app/assets/stylesheets/caboose/admin_media_index.css.scss
@@ -779,6 +782,7 @@ files:
779
782
  - app/views/caboose/blocks/_heading.html.erb
780
783
  - app/views/caboose/blocks/_html.html.erb
781
784
  - app/views/caboose/blocks/_image.html.erb
785
+ - app/views/caboose/blocks/_image2.html.erb
782
786
  - app/views/caboose/blocks/_layout_basic.html.erb
783
787
  - app/views/caboose/blocks/_layout_basic_content.html.erb
784
788
  - app/views/caboose/blocks/_layout_basic_footer.html.erb
@@ -815,6 +819,7 @@ files:
815
819
  - app/views/caboose/blocks/admin_edit.html.erb
816
820
  - app/views/caboose/blocks/admin_edit_advanced.html.erb
817
821
  - app/views/caboose/blocks/admin_edit_custom.html.erb
822
+ - app/views/caboose/blocks/admin_edit_file.html.erb
818
823
  - app/views/caboose/blocks/admin_edit_h1.html.erb
819
824
  - app/views/caboose/blocks/admin_edit_h2.html.erb
820
825
  - app/views/caboose/blocks/admin_edit_h3.html.erb
@@ -822,6 +827,7 @@ files:
822
827
  - app/views/caboose/blocks/admin_edit_h5.html.erb
823
828
  - app/views/caboose/blocks/admin_edit_h6.html.erb
824
829
  - app/views/caboose/blocks/admin_edit_heading.html
830
+ - app/views/caboose/blocks/admin_edit_image.html.erb
825
831
  - app/views/caboose/blocks/admin_edit_richtextold.html.erb
826
832
  - app/views/caboose/blocks/admin_new.html.erb
827
833
  - app/views/caboose/blocks/admin_render_second_level.json.erb