caboose-cms 0.9.133 → 0.9.134

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/caboose/admin_block_edit.js +1 -1
  3. data/app/assets/javascripts/caboose/block_content_controller.js +11 -3
  4. data/app/assets/javascripts/caboose/block_content_controller_dragdrop.js +126 -6
  5. data/app/assets/javascripts/caboose/block_modal_controllers/block_dd_modal_controller.js +5 -5
  6. data/app/assets/javascripts/caboose/block_modal_controllers/block_modal_controller.js +9 -4
  7. data/app/assets/javascripts/caboose/model/attribute.js +1 -1
  8. data/app/assets/javascripts/caboose/model/model_binder.js +3 -1
  9. data/app/assets/stylesheets/caboose/admin_edit_page_content.scss +69 -14
  10. data/app/assets/stylesheets/caboose/admin_edit_page_content_dragdrop.scss +101 -11
  11. data/app/controllers/caboose/application_controller.rb +1 -1
  12. data/app/controllers/caboose/blocks_controller.rb +209 -74
  13. data/app/controllers/caboose/pages_controller.rb +34 -0
  14. data/app/controllers/caboose/posts_controller.rb +27 -0
  15. data/app/models/caboose/block.rb +134 -30
  16. data/app/models/caboose/page.rb +42 -1
  17. data/app/models/caboose/post.rb +42 -1
  18. data/app/models/caboose/schema.rb +10 -3
  19. data/app/views/caboose/admin/index.html.erb +0 -1
  20. data/app/views/caboose/pages/admin_edit_content.html.erb +19 -2
  21. data/app/views/caboose/pages/admin_preview.html.erb +1 -0
  22. data/app/views/caboose/posts/admin_edit_content.html.erb +18 -3
  23. data/app/views/caboose/posts/admin_preview_post.html.erb +1 -0
  24. data/app/views/layouts/caboose/admin.html.erb +1 -1
  25. data/lib/caboose/version.rb +1 -1
  26. metadata +3 -1
@@ -145,6 +145,22 @@ module Caboose
145
145
  #===========================================================================
146
146
  # Admin actions
147
147
  #===========================================================================
148
+
149
+ # @route GET /admin/pages/:id/publish
150
+ def admin_publish
151
+ return unless user_is_allowed('pages', 'edit')
152
+ page = Page.find(params[:id])
153
+ page.publish
154
+ redirect_to "/admin/pages/#{page.id}/content"
155
+ end
156
+
157
+ # @route GET /admin/pages/:id/revert
158
+ def admin_revert
159
+ return unless user_is_allowed('pages', 'edit')
160
+ page = Page.find(params[:id])
161
+ page.revert
162
+ redirect_to "/admin/pages/#{page.id}/content"
163
+ end
148
164
 
149
165
  # @route GET /admin/pages
150
166
  def admin_index
@@ -205,7 +221,25 @@ module Caboose
205
221
  redirect_to "/admin/pages/#{@page.id}/layout"
206
222
  return
207
223
  end
224
+ Caboose::Block.where(:page_id => @page.id, :new_sort_order => nil).update_all('new_sort_order = sort_order')
225
+ Caboose::Block.where(:page_id => @page.id, :status => nil).update_all(:status => 'published')
226
+ # Caboose::Block.where(:page_id => @page.id, :new_parent_id => nil).update_all('new_parent_id = parent_id')
227
+ @editing = true
228
+ @preview = false
229
+ end
230
+
231
+ # @route GET /admin/pages/:id/preview
232
+ def admin_preview
233
+ @page = Page.find(params[:id])
234
+ redirect_to "/login?return_url=/admin/pages/#{@page.id}/preview" and return if @logged_in_user.nil?
235
+ condition = @logged_in_user && (@logged_in_user.is_super_admin? || (@logged_in_user.site_id == @page.site_id && ( @logged_in_user.is_allowed('all','all') || @logged_in_user.is_allowed('pages','edit') && Page.permissible_actions(@logged_in_user, @page.id).include?('edit'))))
236
+ redirect_to "/admin/pages" and return unless condition
237
+ if @page.block.nil?
238
+ redirect_to "/admin/pages/#{@page.id}/layout"
239
+ return
240
+ end
208
241
  @editing = true
242
+ @preview = true
209
243
  end
210
244
 
211
245
  # @route GET /admin/pages/:id/layout
@@ -75,6 +75,22 @@ module Caboose
75
75
  @post = Post.find(params[:id])
76
76
  render :layout => 'caboose/admin'
77
77
  end
78
+
79
+ # @route GET /admin/posts/:id/publish
80
+ def admin_publish
81
+ return unless user_is_allowed('posts', 'edit')
82
+ post = Post.find(params[:id])
83
+ post.publish
84
+ redirect_to "/admin/posts/#{post.id}/content"
85
+ end
86
+
87
+ # @route GET /admin/posts/:id/revert
88
+ def admin_revert
89
+ return unless user_is_allowed('posts', 'edit')
90
+ post = Post.find(params[:id])
91
+ post.revert
92
+ redirect_to "/admin/posts/#{post.id}/content"
93
+ end
78
94
 
79
95
  # @route GET /admin/posts/:id/content
80
96
  def admin_edit_content
@@ -89,7 +105,18 @@ module Caboose
89
105
  redirect_to "/admin/posts/#{@post.id}/layout"
90
106
  return
91
107
  end
108
+ Caboose::Block.where(:post_id => @post.id, :new_sort_order => nil).update_all('new_sort_order = sort_order')
109
+ Caboose::Block.where(:post_id => @post.id, :status => nil).update_all(:status => 'published')
110
+ @editing = true
111
+ @preview = false
112
+ end
113
+
114
+ # @route GET /admin/posts/:id/preview-post
115
+ def admin_preview_post
116
+ return if !user_is_allowed('posts', 'edit')
117
+ @post = Post.find(params[:id])
92
118
  @editing = true
119
+ @preview = true
93
120
  end
94
121
 
95
122
  # @route GET /admin/posts/:id/categories
@@ -9,7 +9,7 @@ class Caboose::Block < ActiveRecord::Base
9
9
  belongs_to :media
10
10
  belongs_to :block_type
11
11
  belongs_to :parent, :foreign_key => 'parent_id', :class_name => 'Caboose::Block'
12
- has_many :children, :foreign_key => 'parent_id', :class_name => 'Caboose::Block', :dependent => :delete_all, :order => 'sort_order'
12
+ has_many :children, :foreign_key => 'parent_id', :class_name => 'Caboose::Block', :order => 'sort_order, id' # :dependent => :delete_all
13
13
  has_attached_file :file, :path => ':caboose_prefixuploads/:block_file_upload_name.:extension'
14
14
  do_not_validate_attachment_file_type :file
15
15
  has_attached_file :image,
@@ -33,7 +33,12 @@ class Caboose::Block < ActiveRecord::Base
33
33
  :constrain,
34
34
  :full_width,
35
35
  :name,
36
- :value
36
+ :value,
37
+ :status,
38
+ :new_parent_id,
39
+ :new_sort_order,
40
+ :new_value,
41
+ :new_media_id
37
42
 
38
43
  after_initialize :caste_value
39
44
  before_save :caste_value
@@ -70,10 +75,35 @@ class Caboose::Block < ActiveRecord::Base
70
75
  if b.block_type.field_type == 'file'
71
76
  return b.media.file if b.media
72
77
  return b.file
73
- end
78
+ end
74
79
  #return b.image if b.block_type.field_type == 'image'
75
- #return b.file if b.block_type.field_type == 'file'
76
- return b.value
80
+ #return b.file if b.block_type.field_type == 'file'
81
+ return b.value
82
+ end
83
+
84
+ def cv(editing, name)
85
+ editing = defined?(editing) ? editing : false
86
+ b = self.child(name)
87
+ return nil if b.nil?
88
+ if b.block_type.field_type == 'image' && !editing
89
+ return b.media.image if b.media
90
+ return b.image
91
+ end
92
+ if b.block_type.field_type == 'image' && editing
93
+ mid = b.new_media_id.blank? ? b.media_id : b.new_media_id
94
+ return Caboose::Media.find(mid).image if Caboose::Media.where(:id => mid).exists?
95
+ return (mid != 0 ? b.image : nil)
96
+ end
97
+ if b.block_type.field_type == 'file' && !editing
98
+ return b.media.file if b.media
99
+ return b.file
100
+ end
101
+ if b.block_type.field_type == 'file' && editing
102
+ mid = b.new_media_id.blank? ? b.media_id : b.new_media_id
103
+ return Caboose::Media.find(mid).file if Caboose::Media.where(:id => mid).exists?
104
+ return (mid != 0 ? b.file : nil)
105
+ end
106
+ return (editing && !b.new_value.blank?) ? (b.new_value == 'EMPTY' ? nil : b.new_value) : b.value
77
107
  end
78
108
 
79
109
  def rendered_child_value(name, options)
@@ -95,8 +125,19 @@ class Caboose::Block < ActiveRecord::Base
95
125
  def child(name)
96
126
  Caboose::Block.where("parent_id = ? and name = ?", self.id, name).first
97
127
  end
128
+
129
+ def filtered_children(editing, sort_by_id = false)
130
+ blocks = []
131
+ if editing
132
+ sortby = sort_by_id ? 'block_type_id' : 'new_sort_order,id'
133
+ blocks = Caboose::Block.where("new_parent_id = ? or (parent_id = ? and new_parent_id is null)", self.id, self.id).order(sortby)
134
+ else
135
+ blocks = Caboose::Block.where(:parent_id => self.id).order('sort_order,id')
136
+ end
137
+ return blocks
138
+ end
98
139
 
99
- def create_children(block_type_override = nil)
140
+ def create_children(block_type_override: nil, status: 'published')
100
141
  bt = block_type_override ? block_type_override : block_type
101
142
  bt.children.each do |bt2|
102
143
  bt_id = bt2.id
@@ -110,9 +151,10 @@ class Caboose::Block < ActiveRecord::Base
110
151
  :parent_id => self.id,
111
152
  :block_type_id => bt_id,
112
153
  :name => bt2.name,
113
- :value => bt2.default
154
+ :value => bt2.default,
155
+ :status => status
114
156
  )
115
- b.create_children(bt2)
157
+ b.create_children(block_type_override: bt2, status: status)
116
158
  end
117
159
  end
118
160
  end
@@ -246,8 +288,41 @@ class Caboose::Block < ActiveRecord::Base
246
288
  "caboose/blocks/#{block.block_type.name}",
247
289
  "caboose/blocks/#{block.block_type.field_type}"
248
290
  ]
249
- #Caboose.log(arr)
250
- str = self.render_helper(view, options2, block, full_name, arr, 0)
291
+
292
+ # Caboose.log("editing: " + options2[:editing].to_s)
293
+
294
+ if options2[:editing] == true
295
+ if !block.new_value.blank? && block.new_value != 'EMPTY'
296
+ block.value = block.new_value
297
+ elsif block.new_value == 'EMPTY'
298
+ block.value = nil
299
+ end
300
+ block.media_id = block.new_media_id if !block.new_media_id.nil?
301
+ # block.sort_order = block.new_sort_order if !block.new_sort_order.blank?
302
+ # block.parent_id = block.new_parent_id if !block.new_parent_id.blank?
303
+ # Caboose.log("temp setting #{block.id}")
304
+ # block.children.each do |bc|
305
+ # Caboose.log("temp setting #{bc.id}")
306
+ # bc.value = bc.new_value if !bc.new_value.blank?
307
+ # bc.sort_order = bc.new_sort_order if !bc.new_sort_order.blank?
308
+ # bc.parent_id = bc.new_parent_id if !bc.new_parent_id.blank?
309
+ # Caboose.log("bc value: #{bc.value}")
310
+ # end
311
+
312
+ # if block && block.id == 430363
313
+ # Caboose.log( block.value )
314
+ # end
315
+
316
+ if block.status != 'deleted' #&& ( block.new_parent_id.blank? || options2[:is_new] )
317
+ str = self.render_helper(view, options2, block, full_name, arr, 0)
318
+ end
319
+ # str.gsub('child_value','edited_child_value')
320
+ else
321
+ if block.status != 'added'
322
+ str = self.render_helper(view, options2, block, full_name, arr, 0)
323
+ end
324
+ end
325
+
251
326
 
252
327
  end
253
328
  return str
@@ -461,20 +536,27 @@ class Caboose::Block < ActiveRecord::Base
461
536
  end
462
537
  return current_value.join('|')
463
538
  end
539
+
540
+ # block siblings (in editing mode)
541
+ def siblings(min_sort_order=0)
542
+ Caboose::Block.where(:name => nil).where('new_sort_order >= ?',min_sort_order).where("(new_parent_id is null and parent_id = ? and status != ?) OR (new_parent_id = ? and status != ?)",self.parent_id,'deleted',self.parent_id,'deleted').order(:new_sort_order, :id).all
543
+ end
464
544
 
465
545
  # Move a block up
466
546
  def move_up
467
- siblings = Caboose::Block.where(:parent_id => self.parent_id).reorder(:sort_order).all
468
- siblings.each_with_index do |b2, i|
469
- b2.sort_order = i
547
+ sibs = self.siblings
548
+ sibs.each_with_index do |b2, i|
549
+ b2.new_sort_order = i
550
+ b2.status = 'edited' if b2.status == 'published'
470
551
  b2.save
471
552
  end
472
553
  changed = false
473
- siblings.each_with_index do |b2, i|
554
+ sibs.each_with_index do |b2, i|
474
555
  if i > 0 && b2.id == self.id
475
- siblings[i-1].sort_order = i
476
- siblings[i-1].save
477
- b2.sort_order = i - 1
556
+ sibs[i-1].new_sort_order = i
557
+ sibs[i-1].save
558
+ b2.new_sort_order = i - 1
559
+ b2.status = 'edited' if b2.status == 'published'
478
560
  b2.save
479
561
  changed = true
480
562
  end
@@ -484,23 +566,35 @@ class Caboose::Block < ActiveRecord::Base
484
566
 
485
567
  # Move a block down
486
568
  def move_down
487
- siblings = Caboose::Block.where(:parent_id => self.parent_id).reorder(:sort_order).all
488
- siblings.each_with_index do |b2, i|
489
- b2.sort_order = i
569
+ sibs = self.siblings
570
+ sibs.each_with_index do |b2, i|
571
+ b2.new_sort_order = i
572
+ b2.status = 'edited' if b2.status == 'published'
490
573
  b2.save
491
574
  end
492
575
  changed = false
493
- siblings.each_with_index do |b2, i|
494
- if i < (siblings.count-1) && b2.id == self.id
495
- siblings[i+1].sort_order = i
496
- siblings[i+1].save
497
- b2.sort_order = i + 1
576
+ sibs.each_with_index do |b2, i|
577
+ if i < (sibs.count-1) && b2.id == self.id
578
+ sibs[i+1].new_sort_order = i
579
+ sibs[i+1].save
580
+ b2.new_sort_order = i + 1
581
+ b2.status = 'edited' if b2.status == 'published'
498
582
  b2.save
499
583
  changed = true
500
584
  end
501
585
  end
502
586
  return changed
503
587
  end
588
+
589
+ # fix sort orders
590
+ def reorganize
591
+ sibs = self.siblings
592
+ sibs.each_with_index do |b2, i|
593
+ b2.new_sort_order = i
594
+ b2.status = 'edited' if b2.status == 'published'
595
+ b2.save
596
+ end
597
+ end
504
598
 
505
599
  def constrain_all
506
600
  self.children.each do |b|
@@ -623,14 +717,24 @@ class Caboose::Block < ActiveRecord::Base
623
717
  :post_id => post_id,
624
718
  :parent_id => new_parent_id,
625
719
  :media_id => self.media_id,
720
+ :new_media_id => self.new_media_id,
626
721
  :block_type_id => self.block_type_id,
627
- :sort_order => self.sort_order + 1,
722
+ :sort_order => (self.new_sort_order.blank? ? (self.sort_order) : (self.new_sort_order)),
723
+ :new_sort_order => (self.new_sort_order.blank? ? (self.sort_order) : (self.new_sort_order)),
628
724
  :constrain => self.constrain,
629
725
  :full_width => self.full_width,
630
726
  :name => self.name,
631
- :value => self.value
727
+ :value => self.value,
728
+ :new_value => self.new_value,
729
+ :status => 'added'
632
730
  )
633
- self.children.each do |b2|
731
+
732
+ if b.name.nil?
733
+ # Caboose.log("moving block #{b.id} down, parent_id is #{b.parent_id}")
734
+ b.reorganize
735
+ end
736
+
737
+ self.filtered_children(true).each do |b2|
634
738
  if b2.name
635
739
  # The block is part of the block type, so we have to find the corresponding child block in the new block type
636
740
  bt = Caboose::BlockType.where(:parent_id => self.block_type_id, :name => b2.name).first
@@ -650,7 +754,7 @@ class Caboose::Block < ActiveRecord::Base
650
754
  def modal_js_block_names
651
755
  arr = []
652
756
  arr << self.block_type.name if self.block_type.use_js_for_modal
653
- self.children.each do |b2|
757
+ self.filtered_children(true).each do |b2|
654
758
  self.modal_js_controllers_helper(b2, arr)
655
759
  end
656
760
  return arr
@@ -659,7 +763,7 @@ class Caboose::Block < ActiveRecord::Base
659
763
  def modal_js_controllers_helper(b, arr)
660
764
  bt = b.block_type
661
765
  arr << bt.name if bt.use_js_for_modal
662
- b.children.each do |b2|
766
+ b.filtered_children(true).each do |b2|
663
767
  self.modal_js_controllers_helper(b2, arr)
664
768
  end
665
769
  end
@@ -35,7 +35,8 @@ class Caboose::Page < ActiveRecord::Base
35
35
  :meta_robots ,
36
36
  :canonical_url ,
37
37
  :fb_description ,
38
- :gp_description
38
+ :gp_description ,
39
+ :status
39
40
 
40
41
  CONTENT_FORMAT_HTML = 1
41
42
  CONTENT_FORMAT_TEXT = 2
@@ -68,6 +69,46 @@ class Caboose::Page < ActiveRecord::Base
68
69
  def self.index_page(site_id)
69
70
  return self.where(:site_id => site_id, :parent_id => -1).first
70
71
  end
72
+
73
+ def is_published
74
+ Caboose::Block.where(:page_id => self.id).where('status != ?','published').count == 0
75
+ end
76
+
77
+ def publish
78
+ Caboose::Block.where(:page_id => self.id).where('status = ? OR status = ?','edited','added').all.each do |b|
79
+ if b.new_value == 'EMPTY'
80
+ b.value = nil
81
+ elsif !b.new_value.blank?
82
+ b.value = b.new_value
83
+ end
84
+ if b.new_media_id == 0
85
+ b.media_id = nil
86
+ elsif !b.new_media_id.blank?
87
+ b.media_id = b.new_media_id
88
+ end
89
+ b.sort_order = b.new_sort_order if !b.new_sort_order.blank?
90
+ b.parent_id = b.new_parent_id if !b.new_parent_id.blank?
91
+ b.status = 'published'
92
+ b.new_value = nil
93
+ b.new_media_id = nil
94
+ b.new_sort_order = nil
95
+ b.new_parent_id = nil
96
+ b.save
97
+ end
98
+ deleted_blocks = Caboose::Block.where(:page_id => self.id, :status => 'deleted').pluck(:id)
99
+ dids = deleted_blocks.blank? ? 0 : deleted_blocks
100
+ Caboose::Block.where("id in (?) or parent_id in (?)",dids,dids).destroy_all
101
+ Caboose::Block.where(:page_id => self.id, :status => nil).update_all(:status => 'published')
102
+ self.status = 'published'
103
+ self.save
104
+ end
105
+
106
+ def revert
107
+ Caboose::Block.where(:page_id => self.id).where(:status => 'added').destroy_all
108
+ Caboose::Block.where(:page_id => self.id).update_all("status = 'published', new_value = null, new_media_id = null, new_sort_order = sort_order, new_parent_id = null")
109
+ self.status = 'published'
110
+ self.save
111
+ end
71
112
 
72
113
  def self.page_with_uri(host_with_port, uri, get_closest_parent = true)
73
114
 
@@ -18,7 +18,8 @@ class Caboose::Post < ActiveRecord::Base
18
18
  :image_url ,
19
19
  :published ,
20
20
  :created_at ,
21
- :updated_at
21
+ :updated_at ,
22
+ :status
22
23
 
23
24
  has_attached_file :image,
24
25
  :path => ':caboose_prefixposts/:id_:style.:extension',
@@ -43,6 +44,46 @@ class Caboose::Post < ActiveRecord::Base
43
44
  def self.slug(str)
44
45
  return str.downcase.gsub(' ', '-').gsub(/[^\w-]/, '')
45
46
  end
47
+
48
+ def is_published
49
+ Caboose::Block.where(:post_id => self.id).where('status != ?','published').count == 0
50
+ end
51
+
52
+ def publish
53
+ Caboose::Block.where(:post_id => self.id).where('status = ? OR status = ?','edited','added').all.each do |b|
54
+ if b.new_value == 'EMPTY'
55
+ b.value = nil
56
+ elsif !b.new_value.blank?
57
+ b.value = b.new_value
58
+ end
59
+ if b.new_media_id == 0
60
+ b.media_id = nil
61
+ elsif !b.new_media_id.blank?
62
+ b.media_id = b.new_media_id
63
+ end
64
+ b.sort_order = b.new_sort_order if !b.new_sort_order.blank?
65
+ b.parent_id = b.new_parent_id if !b.new_parent_id.blank?
66
+ b.status = 'published'
67
+ b.new_value = nil
68
+ b.new_media_id = nil
69
+ b.new_sort_order = nil
70
+ b.new_parent_id = nil
71
+ b.save
72
+ end
73
+ deleted_blocks = Caboose::Block.where(:post_id => self.id, :status => 'deleted').pluck(:id)
74
+ dids = deleted_blocks.blank? ? 0 : deleted_blocks
75
+ Caboose::Block.where("id in (?) or parent_id in (?)",dids,dids).destroy_all
76
+ Caboose::Block.where(:post_id => self.id, :status => nil).update_all(:status => 'published')
77
+ self.status = 'published'
78
+ self.save
79
+ end
80
+
81
+ def revert
82
+ Caboose::Block.where(:post_id => self.id).where(:status => 'added').destroy_all
83
+ Caboose::Block.where(:post_id => self.id).update_all("status = 'published', new_value = null, new_media_id = null, new_sort_order = sort_order, new_parent_id = null")
84
+ self.status = 'published'
85
+ self.save
86
+ end
46
87
 
47
88
  def self.uri(post)
48
89
  str = "/posts/#x{post.created_at.strftime('%Y/%m/%d')}/#{post.slug}"