caboose-cms 0.5.201 → 0.5.202

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +8 -8
  2. data/app/assets/javascripts/caboose/admin_block_edit.js +20 -10
  3. data/app/assets/javascripts/caboose/admin_post_edit_content.js +313 -0
  4. data/app/assets/stylesheets/caboose/admin_post_edit_content.css +46 -0
  5. data/app/controllers/caboose/admin_controller.rb +4 -4
  6. data/app/controllers/caboose/application_controller.rb +35 -0
  7. data/app/controllers/caboose/blocks_controller.rb +120 -78
  8. data/app/controllers/caboose/checkout_controller.rb +6 -0
  9. data/app/controllers/caboose/posts_controller.rb +87 -21
  10. data/app/controllers/caboose/sites_controller.rb +13 -1
  11. data/app/models/caboose/block.rb +14 -4
  12. data/app/models/caboose/caboose_plugin.rb +4 -0
  13. data/app/models/caboose/core_plugin.rb +1 -1
  14. data/app/models/caboose/post.rb +51 -7
  15. data/app/models/caboose/schema.rb +10 -3
  16. data/app/models/caboose/site.rb +5 -0
  17. data/app/views/caboose/admin/index.html.erb +43 -30
  18. data/app/views/caboose/application/show.html.erb +1 -1
  19. data/app/views/caboose/blocks/_layout_basic.html.erb +1 -1
  20. data/app/views/caboose/blocks/_layout_basic_content.html.erb +1 -1
  21. data/app/views/caboose/blocks/_layout_post.html.erb +28 -0
  22. data/app/views/caboose/blocks/_layout_post_content.html.erb +10 -0
  23. data/app/views/caboose/blocks/_layout_post_footer.html.erb +3 -0
  24. data/app/views/caboose/blocks/_layout_post_header.html.erb +3 -0
  25. data/app/views/caboose/blocks/_post.html.erb +30 -0
  26. data/app/views/caboose/blocks/admin_edit.html.erb +6 -7
  27. data/app/views/caboose/blocks/admin_new.html.erb +4 -3
  28. data/app/views/caboose/posts/_admin_header.html.erb +1 -0
  29. data/app/views/caboose/posts/admin_edit_content.html.erb +14 -21
  30. data/app/views/caboose/posts/admin_edit_content_old.html.erb +32 -0
  31. data/app/views/caboose/posts/admin_edit_general.html.erb +25 -12
  32. data/app/views/caboose/posts/admin_edit_layout.html.erb +48 -0
  33. data/app/views/caboose/posts/admin_edit_preview.html.erb +27 -0
  34. data/app/views/caboose/posts/show.html.erb +16 -0
  35. data/app/views/caboose/sites/admin_edit.html.erb +7 -5
  36. data/app/views/caboose/social/admin_edit.html.erb +1 -1
  37. data/app/views/layouts/caboose/application.html.erb +12 -6
  38. data/config/routes.rb +299 -278
  39. data/lib/caboose/version.rb +1 -1
  40. data/lib/tasks/caboose.rake +15 -1
  41. metadata +13 -2
@@ -8,13 +8,33 @@ module Caboose
8
8
  @posts = Post.where(:published => true).limit(5).order('created_at DESC')
9
9
  end
10
10
 
11
+ ## GET /posts/:id
12
+ #def detail
13
+ # @post = Post.find_by_id(params[:id])
14
+ # unless @post.present?
15
+ # flash[:notice] = 'The posts post you tried to access does not exist.'
16
+ # redirect_to action: :index
17
+ # end
18
+ #end
19
+
11
20
  # GET /posts/:id
12
- def detail
13
- @post = Post.find_by_id(params[:id])
14
- unless @post.present?
15
- flash[:notice] = 'The posts post you tried to access does not exist.'
16
- redirect_to action: :index
17
- end
21
+ # GET /posts/:year/:month/:day/:slug
22
+ def show
23
+
24
+ # Make sure we're not under construction or on a forwarded domain
25
+ return if under_construction_or_forwarding_domain?
26
+
27
+ if params[:id]
28
+ @post = Post.where(:id => params[:id]).first
29
+ else
30
+ # Find the page with an exact URI match
31
+ uri = "#{params[:year]}/#{params[:month]}/#{params[:day]}/#{params[:slug]}"
32
+ @post = Post.where(:site_id => @site.id, :uri => request.fullpath).first
33
+ end
34
+ render :file => "caboose/extras/error404" and return if @post.nil?
35
+
36
+ @post = Caboose.plugin_hook('post_content', @post)
37
+ @editmode = !params['edit'].nil? && user.is_allowed('posts', 'edit') ? true : false
18
38
  end
19
39
 
20
40
  #=============================================================================
@@ -37,6 +57,13 @@ module Caboose
37
57
  @posts = @gen.items
38
58
  render :layout => 'caboose/admin'
39
59
  end
60
+
61
+ # GET /admin/posts/:id/json
62
+ def admin_json_single
63
+ return if !user_is_allowed('posts', 'edit')
64
+ @post = Post.find(params[:id])
65
+ render :json => @post
66
+ end
40
67
 
41
68
  # GET /admin/posts/:id/edit
42
69
  def admin_edit_general
@@ -45,11 +72,27 @@ module Caboose
45
72
  render :layout => 'caboose/admin'
46
73
  end
47
74
 
75
+ # GET /admin/posts/:id/preview
76
+ def admin_edit_preview
77
+ return if !user_is_allowed('posts', 'edit')
78
+ @post = Post.find(params[:id])
79
+ render :layout => 'caboose/admin'
80
+ end
81
+
48
82
  # GET /admin/posts/:id/content
49
83
  def admin_edit_content
50
84
  return if !user_is_allowed('posts', 'edit')
51
85
  @post = Post.find(params[:id])
52
- render :layout => 'caboose/admin'
86
+ if @post.body
87
+ @post.preview = @post.body
88
+ @post.body = nil
89
+ @post.save
90
+ end
91
+ if @post.block.nil?
92
+ redirect_to "/admin/posts/#{@post.id}/layout"
93
+ return
94
+ end
95
+ @editing = true
53
96
  end
54
97
 
55
98
  # GET /admin/posts/:id/categories
@@ -63,10 +106,28 @@ module Caboose
63
106
  end
64
107
  render :layout => 'caboose/admin'
65
108
  end
109
+
110
+ # GET /admin/posts/:id/layout
111
+ def admin_edit_layout
112
+ return unless user_is_allowed('posts', 'edit')
113
+ @post = Post.find(params[:id])
114
+ render :layout => 'caboose/admin'
115
+ end
116
+
117
+ # PUT /admin/posts/:id/layout
118
+ def admin_update_layout
119
+ return unless user_is_allowed('posts', 'edit')
120
+ bt = BlockType.find(params[:block_type_id])
121
+ Block.where(:post_id => params[:id]).destroy_all
122
+ Block.create(:post_id => params[:id], :block_type_id => params[:block_type_id], :name => bt.name)
123
+ resp = Caboose::StdClass.new({
124
+ 'redirect' => "/admin/posts/#{params[:id]}/content"
125
+ })
126
+ render :json => resp
127
+ end
66
128
 
67
129
  # POST /admin/posts/:id
68
- def admin_update
69
- #Caboose.log(params)
130
+ def admin_update
70
131
  return if !user_is_allowed('posts', 'edit')
71
132
 
72
133
  resp = Caboose::StdClass.new({'attributes' => {}})
@@ -74,18 +135,22 @@ module Caboose
74
135
 
75
136
  save = true
76
137
  params.each do |name, value|
77
- case name
78
- when 'category_id' then post.category_id = value
79
- when 'title' then post.title = value
80
- when 'body' then post.body = value
81
- when 'published' then post.published = value.to_i == 1
82
- when 'created_at' then post.created_at = DateTime.parse(value)
138
+ case name
139
+ when 'site_id' then post.site_id = value.to_i
140
+ when 'slug' then post.set_slug_and_uri(value)
141
+ when 'title' then post.title = value
142
+ when 'subtitle' then post.subtitle = value
143
+ when 'author' then post.author = value
144
+ when 'body' then post.body = value
145
+ when 'preview' then post.preview = value
146
+ when 'hide' then post.hide = value
147
+ when 'image_url' then post.image_url = value
148
+ when 'published' then post.published = value
149
+ when 'created_at' then post.created_at = DateTime.parse(value)
150
+ when 'updated_at' then post.updated_at = DateTime.parse(value)
83
151
  end
84
152
  end
85
- resp.success = save && post.save
86
- if params[:image]
87
- resp.attributes['image'] = { 'value' => post.image.url(:thumb) }
88
- end
153
+ resp.success = save && post.save
89
154
  render :json => resp
90
155
  end
91
156
 
@@ -120,13 +185,14 @@ module Caboose
120
185
 
121
186
  post = Post.new
122
187
  post.site_id = @site.id
123
- post.title = params[:title]
188
+ post.title = params[:title]
124
189
  post.published = false
125
190
 
126
191
  if post.title == nil || post.title.length == 0
127
192
  resp.error = 'A title is required.'
128
193
  else
129
- post.save
194
+ post.save
195
+ post.set_slug_and_uri(post.title)
130
196
  resp.redirect = "/admin/posts/#{post.id}/edit"
131
197
  end
132
198
 
@@ -148,7 +148,8 @@ module Caboose
148
148
  when 'use_store' then site.use_store = value
149
149
  when 'use_retargeting' then site.use_retargeting = value
150
150
  when 'custom_css' then site.custom_css = value
151
- when 'custom_js' then site.custom_js = value
151
+ when 'custom_js' then site.custom_js = value
152
+ when 'default_layout_id' then site.default_layout_id = value
152
153
  end
153
154
  end
154
155
 
@@ -215,5 +216,16 @@ module Caboose
215
216
  render :json => options
216
217
  end
217
218
 
219
+ # GET /admin/sites/:id/default-layout-options
220
+ def admin_default_layout_options
221
+ return if !user_is_allowed('sites', 'view')
222
+ cat_ids = Caboose::BlockTypeCategory.layouts.collect{ |cat| cat.id }
223
+ block_types = Caboose::BlockType.includes(:block_type_site_memberships).where("block_type_category_id in (?) and block_type_site_memberships.site_id = ?", cat_ids, params[:id]).reorder(:description).all
224
+ options = block_types.collect do |bt|
225
+ { 'value' => bt.id, 'text' => bt.description }
226
+ end
227
+ render :json => options
228
+ end
229
+
218
230
  end
219
231
  end
@@ -79,6 +79,7 @@ class Caboose::Block < ActiveRecord::Base
79
79
  #end
80
80
  if self.child(bt2.name).nil?
81
81
  b = Caboose::Block.create(
82
+ :post_id => self.post_id,
82
83
  :page_id => self.page_id,
83
84
  :parent_id => self.id,
84
85
  :block_type_id => bt_id,
@@ -284,7 +285,8 @@ class Caboose::Block < ActiveRecord::Base
284
285
  kids = self.children.collect { |b| b.js_hash }
285
286
  bt = self.block_type
286
287
  return {
287
- 'id' => self.id,
288
+ 'id' => self.id,
289
+ 'post_id' => self.post_id,
288
290
  'page_id' => self.page_id,
289
291
  'parent_id' => self.parent_id,
290
292
  'parent_title' => self.parent ? self.parent.title : '',
@@ -347,10 +349,18 @@ class Caboose::Block < ActiveRecord::Base
347
349
  return if !self.block_type.is_global
348
350
  return if !Caboose::Block.includes(:page).where("blocks.id <> ? and block_type_id = ? and pages.site_id = ?", self.id, self.block_type_id, site_id).exists?
349
351
 
350
- sql = ["update blocks set value = ? where id in (
351
- select B.id from blocks B left join pages P on B.page_id = P.id
352
+ sql = nil
353
+ if self.page_id
354
+ sql = ["update blocks set value = ? where id in (
355
+ select B.id from blocks B left join pages P on B.page_id = P.id
356
+ where B.id <> ? and B.block_type_id = ? and P.site_id = ?
357
+ )", value, self.id, self.block_type_id, site_id]
358
+ elsif self.post_id
359
+ sql = ["update blocks set value = ? where id in (
360
+ select B.id from blocks B left join posts P on B.post_id = P.id
352
361
  where B.id <> ? and B.block_type_id = ? and P.site_id = ?
353
- )", value, self.id, self.block_type_id, site_id]
362
+ )", value, self.id, self.block_type_id, site_id]
363
+ end
354
364
  ActiveRecord::Base.connection.execute(ActiveRecord::Base.send(:sanitize_sql_array, sql))
355
365
  end
356
366
 
@@ -4,6 +4,10 @@ class Caboose::CaboosePlugin
4
4
  return str
5
5
  end
6
6
 
7
+ def self.post_content(post)
8
+ return post
9
+ end
10
+
7
11
  def self.admin_nav(nav, user, page, site)
8
12
  return nav
9
13
  end
@@ -10,7 +10,7 @@ class Caboose::CorePlugin < Caboose::CaboosePlugin
10
10
  item['children'] << { 'id' => 'blocktypes' , 'text' => 'AB Test Variants' , 'href' => '/admin/ab-variants' , 'modal' => false } if user.is_allowed('abvariants' , 'view')
11
11
  item['children'] << { 'id' => 'blocktypes' , 'text' => 'Block Types' , 'href' => '/admin/block-types' , 'modal' => false } if user.is_allowed('blocktypes' , 'view')
12
12
  item['children'] << { 'id' => 'redirects' , 'text' => 'Permanent Redirects' , 'href' => '/admin/redirects' , 'modal' => false } if user.is_allowed('redirects' , 'view')
13
- item['children'] << { 'id' => 'permissions' , 'text' => 'Permissions' , 'href' => '/admin/permissions' , 'modal' => false } if user.is_allowed('permissions' , 'view')
13
+ item['children'] << { 'id' => 'permissions' , 'text' => 'Permissions' , 'href' => '/admin/permissions' , 'modal' => false } if user.is_allowed('permissions' , 'view')
14
14
  item['children'] << { 'id' => 'roles' , 'text' => 'Roles' , 'href' => '/admin/roles' , 'modal' => false } if user.is_allowed('roles' , 'view')
15
15
  item['children'] << { 'id' => 'sites' , 'text' => 'Sites' , 'href' => '/admin/sites' , 'modal' => false } if user.is_allowed('sites' , 'view') if site.is_master == true
16
16
  item['children'] << { 'id' => 'smtp' , 'text' => 'SMTP (Mail)' , 'href' => '/admin/smtp' , 'modal' => false } if user.is_allowed('smtp' , 'view')
@@ -6,13 +6,19 @@ class Caboose::Post < ActiveRecord::Base
6
6
  has_many :post_categories, :through => :post_category_memberships
7
7
  belongs_to :site
8
8
 
9
- attr_accessible :id,
10
- :site_id,
11
- :category_id,
12
- :title,
13
- :body,
14
- :published,
15
- :created_at
9
+ attr_accessible :id,
10
+ :site_id ,
11
+ :title ,
12
+ :subtitle ,
13
+ :author ,
14
+ :body ,
15
+ :preview ,
16
+ :hide ,
17
+ :image_url ,
18
+ :published ,
19
+ :created_at ,
20
+ :updated_at
21
+
16
22
  has_attached_file :image,
17
23
  :path => ':path_prefixposts/:id_:style.:extension',
18
24
  :default_url => 'http://placehold.it/300x300',
@@ -22,5 +28,43 @@ class Caboose::Post < ActiveRecord::Base
22
28
  :large => '400x400>'
23
29
  }
24
30
  do_not_validate_attachment_file_type :image
31
+
32
+ def block
33
+ Caboose::Block.where("post_id = ? and parent_id is null", self.id).first
34
+ end
35
+
36
+ def top_level_blocks
37
+ Caboose::Block.where("post_id = ? and parent_id is null", self.id).reorder(:sort_order).all
38
+ end
39
+
40
+ def self.slug(str)
41
+ return str.downcase.gsub(' ', '-').gsub(/[^\w-]/, '')
42
+ end
43
+
44
+ def self.uri(post)
45
+ str = "/posts/#x{post.created_at.strftime('%Y/%m/%d')}/#{post.slug}"
46
+ i = 2
47
+ while Caboose::Post.where("site_id = ? and id <> ? and uri = ?", post.site_id, post.id, str).exists?
48
+ str = "/posts/#{post.created_at.strftime('%Y/%m/%d')}/#{post.slug}-#{i}"
49
+ i = i + 1
50
+ end
51
+ return str
52
+ end
53
+
54
+ def set_slug_and_uri(str)
55
+ d = self.created_at.strftime('%Y/%m/%d')
56
+ s = Caboose::Post.slug(str)
57
+ new_slug = "#{s}"
58
+ new_uri = "/posts/#{d}/#{new_slug}"
59
+ i = 2
60
+ while Caboose::Post.where("site_id = ? and id <> ? and uri = ?", self.site_id, self.id, new_uri).exists?
61
+ new_slug = "#{s}-#{i}"
62
+ new_uri = "/posts/#{d}/#{new_slug}"
63
+ i = i + 1
64
+ end
65
+ self.slug = new_slug
66
+ self.uri = new_uri
67
+ self.save
68
+ end
25
69
 
26
70
  end
@@ -147,6 +147,7 @@ class Caboose::Schema < Caboose::Utilities::Schema
147
147
  ],
148
148
  Caboose::Block => [
149
149
  [ :page_id , :integer ],
150
+ [ :post_id , :integer ],
150
151
  [ :parent_id , :integer ],
151
152
  [ :block_type_id , :integer ],
152
153
  [ :sort_order , :integer , { :default => 0 }],
@@ -446,14 +447,19 @@ class Caboose::Schema < Caboose::Utilities::Schema
446
447
  Caboose::Post => [
447
448
  [ :site_id , :integer ],
448
449
  [ :title , :text ],
450
+ [ :subtitle , :text ],
451
+ [ :author , :text ],
449
452
  [ :body , :text ],
453
+ [ :preview , :text ],
450
454
  [ :hide , :boolean ],
451
455
  [ :image_url , :text ],
452
456
  [ :published , :boolean ],
453
457
  [ :created_at , :datetime ],
454
458
  [ :updated_at , :datetime ],
455
- [ :image , :attachment ]
456
- ],
459
+ [ :image , :attachment ],
460
+ [ :slug , :string ],
461
+ [ :uri , :string ]
462
+ ],
457
463
  Caboose::PostCategory => [
458
464
  [ :site_id , :integer ],
459
465
  [ :name , :string ]
@@ -586,7 +592,8 @@ class Caboose::Schema < Caboose::Utilities::Schema
586
592
  [ :analytics_id , :string ],
587
593
  [ :use_retargeting , :boolean , { :default => false }],
588
594
  [ :date_js_updated , :datetime ],
589
- [ :date_css_updated , :datetime ]
595
+ [ :date_css_updated , :datetime ],
596
+ [ :default_layout_id , :integer ]
590
597
  ],
591
598
  Caboose::SiteMembership => [
592
599
  [ :site_id , :integer ],
@@ -20,6 +20,11 @@ class Caboose::Site < ActiveRecord::Base
20
20
  do_not_validate_attachment_file_type :logo
21
21
  attr_accessible :id, :name, :description, :under_construction_html
22
22
 
23
+ def default_layout
24
+ return Caboose::BlockType.where(:id => self.default_layout_id).first if self.default_layout_id
25
+ return Caboose::BlockType.where(:name => 'layout_basic').first
26
+ end
27
+
23
28
  def smtp_config
24
29
  c = Caboose::SmtpConfig.where(:site_id => self.id).first
25
30
  c = Caboose::SmtpConfig.create(:site_id => self.id) if c.nil?
@@ -1,38 +1,51 @@
1
+ <%
2
+ @nav = Caboose.plugin_hook('admin_nav', [], @logged_in_user, @page, @site)
3
+ return_url = session[:caboose_station_return_url].nil? ? '/' : session[:caboose_station_return_url]
4
+ return_url = '/' if return_url.starts_with?('/admin/') || return_url == '/admin'
5
+
6
+ width = 200
7
+ @nav.each {|item| width = 400 if item['id'] == @tab } if @tab
8
+ %>
9
+
1
10
  <h1>Admin</h1>
2
11
 
12
+ <ul>
13
+ <!--
14
+ <li id='nav_item_logout'><a href='/logout'><span class='icon'></span><span class='text'>Logout</span></a>
15
+ <li id='nav_item_myaccount'><a href='/my-account'><span class='icon'></span><span class='text'>My Account</span></a>
16
+ -->
17
+ <% i = 0 %>
18
+ <% @nav.each do |item| %>
19
+ <% id = item['id'].nil? ? i.to_s : item['id'] %>
20
+ <% href = item['href'].nil? ? '#' : item['href'] %>
21
+ <% modal = item['modal'].nil? ? false : item['modal'] %>
22
+ <li id='nav_item_<%= id %>'><a href='<%= href %>'<%= raw (modal ? " rel='modal'" : "") %>><span class='icon'></span><span class='text'><%= item['text'] %></span></a>
23
+ <% if (!item['children'].nil? && item['children'].count > 0) %>
24
+ <ul>
25
+ <% item['children'].each do |item2| %>
26
+ <% modal = item2['modal'].nil? ? false : item2['modal'] %>
27
+ <li><a href='<%= item2['href'] %>'<%= raw (modal ? " rel='modal'" : "") %>><%= item2['text'] %></a></li>
28
+ <% end %>
29
+ </ul>
30
+ <% end %>
31
+ </li>
32
+ <% i + 1 %>
33
+ <% end %>
34
+ </ul>
35
+
3
36
  <%= content_for :caboose_js do %>
37
+ <%= javascript_include_tag "caboose/station" %>
4
38
  <script type='text/javascript'>
5
-
39
+ var modal = false;
40
+ var station = false;
6
41
  $(document).ready(function() {
7
- open_colorbox();
42
+ modal = new CabooseModal(<%= width %>);
43
+ station = new CabooseStation(modal<%= raw @tab ? ", '#{@tab}'" : '' %>);
8
44
  });
9
-
10
- function open_colorbox() {
11
- $.colorbox({
12
- href: '/login?modal=1&return_url=<%= @return_url %>',
13
- iframe: true,
14
- innerWidth: 200,
15
- innerHeight: 50,
16
- scrolling: false,
17
- transition: 'fade',
18
- closeButton: false,
19
- onComplete: fix_colorbox,
20
- opacity: 0.50,
21
- onClosed: function() { open_colorbox(); }
22
- });
23
- }
24
-
25
- function fix_colorbox() {
26
- $("#cboxTopLeft" ).css('background', '#111');
27
- $("#cboxTopRight" ).css('background', '#111');
28
- $("#cboxBottomLeft" ).css('background', '#111');
29
- $("#cboxBottomRight" ).css('background', '#111');
30
- $("#cboxMiddleLeft" ).css('background', '#111');
31
- $("#cboxMiddleRight" ).css('background', '#111');
32
- $("#cboxTopCenter" ).css('background', '#111');
33
- $("#cboxBottomCenter" ).css('background', '#111');
34
- $("#cboxClose" ).hide();
35
- }
36
-
37
45
  </script>
46
+ <% end %>
47
+ <%= content_for :caboose_css do %>
48
+ <style type='text/css'>
49
+
50
+ </style>
38
51
  <% end %>