caboose-cms 0.9.229 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. checksums.yaml +5 -5
  2. data/app/assets/javascripts/caboose/admin.js +1 -1
  3. data/app/assets/javascripts/caboose/admin/application.js +20 -0
  4. data/app/assets/javascripts/caboose/admin_main.js +13 -3
  5. data/app/assets/javascripts/caboose/admin_media_index.js +158 -161
  6. data/app/assets/javascripts/caboose/application.js +7 -8
  7. data/app/assets/javascripts/caboose/block_content_controller_dragdrop.js +4 -60
  8. data/app/assets/javascripts/caboose/block_modal_controllers/block_dd_modal_controller.js +2 -3
  9. data/app/assets/javascripts/caboose/block_modal_controllers/media_modal_controller.js +6 -17
  10. data/app/assets/javascripts/caboose/model/all.js +1 -5
  11. data/app/assets/stylesheets/caboose/admin/_config.scss +102 -0
  12. data/app/assets/stylesheets/caboose/admin/application.css +11 -0
  13. data/app/assets/stylesheets/caboose/admin/component.css +183 -0
  14. data/app/assets/stylesheets/caboose/admin/froala.min.css +91 -0
  15. data/app/assets/stylesheets/caboose/admin/ie.scss +67 -0
  16. data/app/assets/stylesheets/caboose/admin/integrations/main.scss +6 -0
  17. data/app/assets/stylesheets/caboose/admin/integrations/shopify.scss +128 -0
  18. data/app/assets/stylesheets/caboose/admin/jquery-ui-subnav-theme.min.css +5 -0
  19. data/app/assets/stylesheets/caboose/admin/layout.scss +150 -0
  20. data/app/assets/stylesheets/caboose/admin/main.scss +34 -0
  21. data/app/assets/stylesheets/caboose/admin/modules/body.scss +176 -0
  22. data/app/assets/stylesheets/caboose/admin/modules/buttons.scss +120 -0
  23. data/app/assets/stylesheets/caboose/admin/modules/countdown.css +21 -0
  24. data/app/assets/stylesheets/caboose/admin/modules/crumbtrail.scss +80 -0
  25. data/app/assets/stylesheets/caboose/admin/modules/data_table.scss +92 -0
  26. data/app/assets/stylesheets/caboose/admin/modules/footer.scss +62 -0
  27. data/app/assets/stylesheets/caboose/admin/modules/forms.scss +72 -0
  28. data/app/assets/stylesheets/caboose/admin/modules/functions.scss +31 -0
  29. data/app/assets/stylesheets/caboose/admin/modules/grid.scss +108 -0
  30. data/app/assets/stylesheets/caboose/admin/modules/header.scss +77 -0
  31. data/app/assets/stylesheets/caboose/admin/modules/headings.scss +38 -0
  32. data/app/assets/stylesheets/caboose/admin/modules/main_nav.scss +73 -0
  33. data/app/assets/stylesheets/caboose/admin/modules/message_boxes.scss +55 -0
  34. data/app/assets/stylesheets/caboose/admin/modules/model_binder.scss +189 -0
  35. data/app/assets/stylesheets/caboose/admin/modules/navigation.scss +261 -0
  36. data/app/assets/stylesheets/caboose/admin/modules/order_bumps.scss +57 -0
  37. data/app/assets/stylesheets/caboose/admin/modules/pager.scss +34 -0
  38. data/app/assets/stylesheets/caboose/admin/modules/product_images.scss +21 -0
  39. data/app/assets/stylesheets/caboose/admin/modules/products.css +86 -0
  40. data/app/assets/stylesheets/caboose/admin/modules/search.scss +49 -0
  41. data/app/assets/stylesheets/caboose/admin/modules/selects.scss +12 -0
  42. data/app/assets/stylesheets/caboose/admin/modules/subnav_tabs.scss +34 -0
  43. data/app/assets/stylesheets/caboose/admin/modules/tabs.scss +140 -0
  44. data/app/assets/stylesheets/caboose/admin/page_edit/block_anchors.scss +48 -0
  45. data/app/assets/stylesheets/caboose/admin/page_edit/block_overlays.scss +182 -0
  46. data/app/assets/stylesheets/caboose/admin/page_edit/device_selector.scss +65 -0
  47. data/app/assets/stylesheets/caboose/admin/page_edit/froala.scss +81 -0
  48. data/app/assets/stylesheets/caboose/admin/page_edit/group_overlay.scss +115 -0
  49. data/app/assets/stylesheets/caboose/admin/page_edit/layout.scss +128 -0
  50. data/app/assets/stylesheets/caboose/admin/page_edit/main.scss +18 -0
  51. data/app/assets/stylesheets/caboose/admin/page_edit/modal.scss +11 -0
  52. data/app/assets/stylesheets/caboose/admin/page_edit/preview.scss +25 -0
  53. data/app/assets/stylesheets/caboose/admin/page_edit/publish.scss +25 -0
  54. data/app/assets/stylesheets/caboose/admin/page_edit/revisions.scss +58 -0
  55. data/app/assets/stylesheets/caboose/admin/page_edit/subnav.scss +273 -0
  56. data/app/assets/stylesheets/caboose/admin/page_edit/top_nav.scss +109 -0
  57. data/app/assets/stylesheets/caboose/admin/pages/assets_index.css +48 -0
  58. data/app/assets/stylesheets/caboose/admin/pages/block_edit_image.css.scss +386 -0
  59. data/app/assets/stylesheets/caboose/admin/pages/media_index.css.scss +300 -0
  60. data/app/assets/stylesheets/caboose/admin/pages/new_block.css +9 -0
  61. data/app/assets/stylesheets/caboose/admin/pages/page_edit.scss +960 -0
  62. data/app/assets/stylesheets/caboose/admin/pages/page_edit_content.scss +103 -0
  63. data/app/assets/stylesheets/caboose/admin/pages/pages_index.scss +79 -0
  64. data/app/assets/stylesheets/caboose/admin/pages/post_edit_content.css +46 -0
  65. data/app/assets/stylesheets/caboose/admin/print.css +3 -0
  66. data/app/assets/stylesheets/caboose/admin/slack.scss +51 -0
  67. data/app/assets/stylesheets/caboose/admin_block_edit_image.css.scss +1 -2
  68. data/app/assets/stylesheets/caboose/admin_edit_page_content_dragdrop.scss +15 -71
  69. data/app/assets/stylesheets/caboose/admin_main.css.scss +29 -25
  70. data/app/assets/stylesheets/caboose/admin_media_index.css.scss +5 -26
  71. data/app/assets/stylesheets/caboose/application.css +5 -11
  72. data/app/assets/stylesheets/caboose/login.scss +0 -1
  73. data/app/assets/stylesheets/caboose/modal_main.css +19 -21
  74. data/app/assets/stylesheets/caboose/model_binder.css +4 -13
  75. data/app/assets/stylesheets/caboose/page_bar_generator.css +1 -2
  76. data/app/controllers/caboose/admin_controller.rb +4 -3
  77. data/app/controllers/caboose/application_controller.rb +19 -16
  78. data/app/controllers/caboose/assets_controller.rb +65 -0
  79. data/app/controllers/caboose/block_types_controller.rb +6 -8
  80. data/app/controllers/caboose/cart_controller.rb +2 -2
  81. data/app/controllers/caboose/fonts_controller.rb +2 -139
  82. data/app/controllers/caboose/invoices_controller.rb +4 -5
  83. data/app/controllers/caboose/login_logs_controller.rb +7 -5
  84. data/app/controllers/caboose/media_categories_controller.rb +2 -16
  85. data/app/controllers/caboose/media_controller.rb +11 -14
  86. data/app/controllers/caboose/pages_controller.rb +42 -104
  87. data/app/controllers/caboose/posts_controller.rb +7 -53
  88. data/app/controllers/caboose/products_controller.rb +1 -1
  89. data/app/controllers/caboose/sites_controller.rb +6 -25
  90. data/app/controllers/caboose/sns_controller.rb +3 -3
  91. data/app/controllers/caboose/themes_controller.rb +0 -30
  92. data/app/controllers/caboose/users_controller.rb +10 -17
  93. data/app/controllers/caboose/variants_controller.rb +9 -9
  94. data/app/models/caboose/ab_variant.rb +1 -1
  95. data/app/models/caboose/asset.rb +23 -0
  96. data/app/models/caboose/asset_manager.rb +92 -0
  97. data/app/models/caboose/asset_manifest.rb +91 -0
  98. data/app/models/caboose/block.rb +24 -100
  99. data/app/models/caboose/block_cache.rb +105 -0
  100. data/app/models/caboose/block_cache_file.rb +22 -0
  101. data/app/models/caboose/block_cache_image.rb +53 -0
  102. data/app/models/caboose/block_type.rb +3 -4
  103. data/app/models/caboose/block_type_category.rb +2 -2
  104. data/app/models/caboose/block_type_parser.rb +1 -1
  105. data/app/models/caboose/block_type_source.rb +2 -2
  106. data/app/models/caboose/calendar_event_group.rb +2 -2
  107. data/app/models/caboose/category.rb +2 -2
  108. data/app/models/caboose/comment_routes.rb +8 -7
  109. data/app/models/caboose/core_plugin.rb +3 -4
  110. data/app/models/caboose/export.rb +1 -1
  111. data/app/models/caboose/font.rb +2 -7
  112. data/app/models/caboose/font_variant.rb +0 -12
  113. data/app/models/caboose/invoice.rb +14 -14
  114. data/app/models/caboose/line_item.rb +4 -4
  115. data/app/models/caboose/media.rb +4 -15
  116. data/app/models/caboose/media_category.rb +7 -5
  117. data/app/models/caboose/modification.rb +2 -2
  118. data/app/models/caboose/page.rb +54 -325
  119. data/app/models/caboose/page_bar_generator.rb +10 -20
  120. data/app/models/caboose/page_cache.rb +12 -0
  121. data/app/models/caboose/page_cacher.rb +137 -0
  122. data/app/models/caboose/post.rb +8 -108
  123. data/app/models/caboose/product.rb +5 -5
  124. data/app/models/caboose/product_image.rb +1 -1
  125. data/app/models/caboose/role.rb +2 -2
  126. data/app/models/caboose/schema.rb +72 -73
  127. data/app/models/caboose/site.rb +1 -203
  128. data/app/models/caboose/theme.rb +5 -70
  129. data/app/views/caboose/admin/_content.html.erb +44 -0
  130. data/app/views/caboose/admin/_fonts.html.erb +47 -0
  131. data/app/views/caboose/admin/_footer.html.erb +1 -0
  132. data/app/views/caboose/admin/_header.html.erb +12 -0
  133. data/app/views/caboose/admin/_icons.html.erb +6 -0
  134. data/app/views/caboose/admin/_mobile_navigation.html.erb +22 -0
  135. data/app/views/caboose/admin/_post.html.erb +74 -0
  136. data/app/views/caboose/admin/index.html.erb +33 -36
  137. data/app/views/caboose/block_types/admin_edit.html.erb +8 -6
  138. data/app/views/caboose/blocks/_file.html.erb +2 -2
  139. data/app/views/caboose/blocks/_ga.html.erb +2 -1
  140. data/app/views/caboose/blocks/_image.html.erb +0 -4
  141. data/app/views/caboose/blocks/_render_function.html.erb +4 -9
  142. data/app/views/caboose/fonts/admin_index.html.erb +10 -55
  143. data/app/views/caboose/invoices_mailer/customer_status_updated.html.erb +14 -5
  144. data/app/views/caboose/login_logs/admin_index_for_user.html.erb +1 -1
  145. data/app/views/caboose/media/admin_index.html.erb +24 -14
  146. data/app/views/caboose/my_account/index.html.erb +0 -1
  147. data/app/views/caboose/pages/_admin_header.html.erb +0 -5
  148. data/app/views/caboose/pages/admin_edit_content.html.erb +2 -6
  149. data/app/views/caboose/pages/admin_edit_general.html.erb +4 -32
  150. data/app/views/caboose/pages/admin_new_old.html.erb +46 -0
  151. data/app/views/caboose/pages/test.html.erb +64 -0
  152. data/app/views/caboose/posts/_admin_header.html.erb +0 -5
  153. data/app/views/caboose/posts/admin_delete_form.html.erb +1 -1
  154. data/app/views/caboose/posts/admin_edit_content.html.erb +2 -6
  155. data/app/views/caboose/products/admin_group_variants.html.erb +1 -1
  156. data/app/views/caboose/products/admin_sort.html copy.erb +1 -1
  157. data/app/views/caboose/sites/admin_edit.html.erb +0 -21
  158. data/app/views/caboose/themes/admin_edit.html.erb +3 -7
  159. data/app/views/caboose/users/_admin_header.html.erb +0 -4
  160. data/app/views/caboose/users/admin_edit_roles.html.erb +0 -1
  161. data/app/views/caboose/variants/admin_group.html.erb +1 -1
  162. data/app/views/layouts/caboose/admin.html.erb +2 -9
  163. data/app/views/layouts/caboose/application.html.erb +92 -62
  164. data/config/routes.rb +1 -4
  165. data/lib/caboose/version.rb +1 -1
  166. data/lib/tasks/caboose.rake +14 -3
  167. metadata +238 -57
  168. data/app/controllers/caboose/change_logs_controller.rb +0 -13
  169. data/app/models/caboose/change_log.rb +0 -97
  170. data/app/views/caboose/blocks/_cached_block.html.erb +0 -28
  171. data/app/views/caboose/change_logs/admin_index.html.erb +0 -65
  172. data/app/views/caboose/fonts/admin_family_edit.html.erb +0 -63
  173. data/app/views/caboose/fonts/admin_family_index.html.erb +0 -42
  174. data/app/views/caboose/fonts/admin_variant_edit.html.erb +0 -84
  175. data/app/views/caboose/pages/admin_change_logs.html.erb +0 -56
  176. data/app/views/caboose/pages/compiled_asset.css.erb +0 -0
  177. data/app/views/caboose/pages/compiled_asset.js.erb +0 -0
  178. data/app/views/caboose/posts/admin_change_logs.html.erb +0 -56
  179. data/app/views/caboose/sites/compiled_asset.css.erb +0 -0
  180. data/app/views/caboose/sites/compiled_asset.js.erb +0 -0
  181. data/app/views/caboose/themes/admin_error_log.html.erb +0 -9
  182. data/app/views/caboose/themes/admin_js.html.erb +0 -131
  183. data/app/views/caboose/users/admin_change_logs.html.erb +0 -63
  184. data/app/views/layouts/caboose/css.css.erb +0 -44
  185. data/app/views/layouts/caboose/footer_css.css.erb +0 -41
  186. data/app/views/layouts/caboose/footer_js.js.erb +0 -31
  187. data/app/views/layouts/caboose/js.js.erb +0 -34
@@ -4,8 +4,8 @@ class Caboose::BlockType < ActiveRecord::Base
4
4
 
5
5
  belongs_to :default_child_block_type, :foreign_key => 'default_child_block_type_id', :class_name => 'Caboose::BlockType'
6
6
  belongs_to :block_type_category
7
- belongs_to :parent, :foreign_key => 'parent_id', :class_name => 'Caboose::BlockType'
8
- has_many :children, :foreign_key => 'parent_id', :class_name => 'Caboose::BlockType', :dependent => :destroy
7
+ belongs_to :parent, :foreign_key => 'parent_id', :class_name => 'Caboose::BlockType'
8
+ has_many :children, -> { order(:sort_order) }, :foreign_key => 'parent_id', :class_name => 'Caboose::BlockType', :dependent => :destroy
9
9
  has_many :sites, :through => :block_type_site_memberships
10
10
  has_many :block_type_site_memberships
11
11
  attr_accessible :id,
@@ -32,7 +32,6 @@ class Caboose::BlockType < ActiveRecord::Base
32
32
  :default_included,
33
33
  :custom_sass,
34
34
  :latest_error,
35
- :is_dynamic,
36
35
  :share, # Whether or not to share the block type in the existing block store.
37
36
  :downloaded # Whether the full block type has been download or just the name and description.
38
37
 
@@ -76,7 +75,7 @@ class Caboose::BlockType < ActiveRecord::Base
76
75
  end
77
76
 
78
77
  def parse_api_hash(h)
79
- #Caboose.log(h)
78
+ Caboose.log(h)
80
79
  self.name = h['name']
81
80
  self.description = h['description']
82
81
  self.block_type_category_id = h['block_type_category_id']
@@ -2,8 +2,8 @@
2
2
  class Caboose::BlockTypeCategory < ActiveRecord::Base
3
3
  self.table_name = "block_type_categories"
4
4
 
5
- belongs_to :parent, :foreign_key => 'parent_id', :class_name => 'Caboose::BlockTypeCategory'
6
- has_many :children, :foreign_key => 'parent_id', :class_name => 'Caboose::BlockTypeCategory', :dependent => :destroy, :order => :sort_order
5
+ belongs_to :parent, :foreign_key => 'parent_id', :class_name => 'Caboose::BlockTypeCategory'
6
+ has_many :children, -> { order(:name) }, :foreign_key => 'parent_id', :class_name => 'Caboose::BlockTypeCategory', :dependent => :destroy
7
7
  has_many :block_types
8
8
  attr_accessible :id,
9
9
  :parent_id,
@@ -132,7 +132,7 @@ module Caboose
132
132
  cv.margin_right = img.styles['margin-right' ] if img.styles['margin-right' ]
133
133
  cv.margin_top = img.styles['margin-top' ] if img.styles['margin-top' ]
134
134
 
135
- # Caboose.log(cv)
135
+ Caboose.log(cv)
136
136
 
137
137
  v = StdClass.new({
138
138
  :name => name,
@@ -2,8 +2,8 @@ require 'httparty'
2
2
 
3
3
  class Caboose::BlockTypeSource < ActiveRecord::Base
4
4
  self.table_name = "block_type_sources"
5
-
6
- has_many :block_types, :class_name => 'Caboose::BlockType', :order => 'name'
5
+
6
+ has_many :block_types, -> { order(:name) }, :class_name => 'Caboose::BlockType'
7
7
  attr_accessible :id,
8
8
  :name,
9
9
  :url,
@@ -51,12 +51,12 @@ module Caboose
51
51
  while d <= self.date_end
52
52
  (0..6).each do |i|
53
53
  d = d + 1
54
- # Caboose.log("d = #{d}")
54
+ Caboose.log("d = #{d}")
55
55
  next if d < self.date_start
56
56
  break if d > self.date_end
57
57
  w = d.strftime('%w').to_i
58
58
  if (w == 0 && self.sun) || (w == 1 && self.mon) || (w == 2 && self.tue) || (w == 3 && self.wed) || (w == 4 && self.thu) || (w == 5 && self.fri) || (w == 6 && self.sat)
59
- # Caboose.log("Found a day")
59
+ Caboose.log("Found a day")
60
60
  if !CalendarEvent.where("calendar_event_group_id = ? and cast(begin_date as date) = ?", self.id, d).exists?
61
61
  e.duplicate(d)
62
62
  end
@@ -10,8 +10,8 @@ module Caboose
10
10
 
11
11
  belongs_to :site
12
12
  belongs_to :parent, :class_name => 'Category', :foreign_key => 'parent_id'
13
- has_many :children, :class_name => 'Category', :foreign_key => 'parent_id', :order => 'name'
14
- has_many :products, :through => :category_memberships, :order => 'title'
13
+ has_many :children, -> { order(:name) }, :class_name => 'Category', :foreign_key => 'parent_id'
14
+ has_many :products, -> { order(:title) }, :through => :category_memberships
15
15
  has_many :category_memberships
16
16
 
17
17
  has_attached_file :image,
@@ -17,14 +17,14 @@ module Caboose
17
17
  end
18
18
 
19
19
  classes = {'zzz_all_domains' => []}
20
- controller_paths.each do |controller_path|
20
+ controller_paths.each do |controller_path|
21
21
  #files = Dir.glob(Rails.root.join(controller_path, '*.rb'))
22
22
  #files = controller ? Dir.glob(Rails.root.join(controller_path, "#{controller}_controller.rb")) : Dir.glob(Rails.root.join(controller_path, '**/*.rb'))
23
23
  #files = controller ? Dir.glob(Rails.root.join(controller_path, "#{controller}_controller.rb")) : Dir.glob(Rails.root.join(controller_path, '*.rb'))
24
24
  #files = controller ? Dir.glob("#{controller_path}/#{controller}_controller.rb") : Dir.glob("#{controller_path}/*.rb")
25
25
  files = controller ? Dir.glob("#{controller_path}/**/#{controller.gsub(/(.*?)::(.*?)/, '\2')}_controller.rb") : Dir.glob("#{controller_path}/**/*_controller.rb")
26
26
  #files = Dir.glob("#{controller_path}/**/*_controller.rb")
27
- for file in files
27
+ for file in files
28
28
  f2 = File.open(file, "r")
29
29
 
30
30
  domains = []
@@ -39,15 +39,16 @@ module Caboose
39
39
  f2.each_line do |line|
40
40
  line = line.strip
41
41
  if line =~ /^module (.*?)$/
42
- module_name = line.gsub(/^module (.*?)$/, '\1').gsub(/([A-Z])/, '_\1').downcase
43
- module_name[0] = '' if module_name[0] == '_'
42
+ this_module_name = line.gsub(/^module (.*?)$/, '\1').gsub(/([A-Z])/, '_\1').downcase
43
+ this_module_name[0] = '' if this_module_name[0] == '_'
44
+ module_name = module_name ? "#{module_name}/#{this_module_name}" : this_module_name
44
45
  elsif line =~ /^(.*?)class (.*?)Controller(.*?)$/
45
46
  class_name = line.gsub(/^(.*?)class (.*?)Controller(.*?)$/, '\2').gsub(/([A-Z])/, '_\1').downcase
46
47
  class_name[0] = '' if class_name[0] == '_'
47
- class_name = "#{module_name}::#{class_name}" if module_name
48
- elsif line =~ /# @route_domain (.*?)$/
48
+ class_name = "#{module_name}/#{class_name}" if module_name
49
+ elsif line =~ /# @route_domain (.*?)$/
49
50
  # Ignore if we have a domain constrainer
50
- if domains.is_a?(Array)
51
+ if domains.is_a?(Array)
51
52
  domain = line.gsub(/# @route_domain (.*?)$/, '\1')
52
53
  domains << domain if !domains.include?(domain)
53
54
  end
@@ -14,10 +14,9 @@ class Caboose::CorePlugin < Caboose::CaboosePlugin
14
14
  nav << item if item['children'].count > 0
15
15
 
16
16
  item = { 'id' => 'core', 'text' => 'Settings', 'children' => [] }
17
- item['children'] << { 'id' => 'settings' , 'icon' => 'settings', 'text' => 'Site Settings' , 'href' => "/admin/sites/#{site.id}" , 'modal' => false } if user.is_allowed('site_settings', 'edit')
17
+ item['children'] << { 'id' => 'settings' , 'icon' => 'settings', 'text' => 'Site Settings' , 'href' => "/admin/sites/#{site.id}" , 'modal' => false } if user.is_super_admin?
18
18
  item['children'] << { 'id' => 'theme-files' , 'icon' => 'custom', 'text' => 'Theme Files' , 'href' => '/admin/theme-files' , 'modal' => false } if user.is_super_admin? && site.is_master == true
19
19
  item['children'] << { 'id' => 'blocktypes' , 'text' => 'Block Types' , 'href' => '/admin/block-types' , 'modal' => false } if user.is_allowed('blocktypes' , 'view') && site.is_master == true
20
- item['children'] << { 'id' => 'font-families' , 'text' => 'Font Families' , 'icon' => 'info', 'href' => '/admin/font-families' , 'modal' => false } if user.is_allowed('fonts' , 'view') && site.is_master == true
21
20
  item['children'] << { 'icon' => 'star', 'id' => 'fonts' , 'text' => 'Fonts' , 'href' => '/admin/fonts' , 'modal' => false } if user.is_allowed('fonts' , 'view') && site.use_fonts == true
22
21
  item['children'] << { 'id' => 'redirects' , 'text' => 'Permanent Redirects' , 'href' => '/admin/redirects' , 'modal' => false } if user.is_allowed('redirects' , 'view')
23
22
  item['children'] << { 'id' => 'permissions' , 'text' => 'Permissions' , 'href' => '/admin/permissions' , 'modal' => false } if user.is_allowed('permissions' , 'view') && site.is_master == true
@@ -32,8 +31,8 @@ class Caboose::CorePlugin < Caboose::CaboosePlugin
32
31
  item['children'] << { 'id' => 'users' , 'text' => 'Users' , 'href' => '/admin/users' , 'modal' => false } if user.is_allowed('users' , 'view')
33
32
  item['children'] << { 'id' => 'code' , 'icon' => 'stack', 'text' => 'Custom Code' , 'href' => '/admin/code' , 'modal' => false } if user.is_allowed('code' , 'edit')
34
33
  item['children'] << { 'id' => 'contactinfo' , 'icon' => 'plane', 'text' => 'Contact Information' , 'href' => "/admin/sites/#{site.id}/contact" , 'modal' => false } if user.is_allowed('contactinfo' , 'edit')
35
- item['children'] << { 'id' => 'theme' , 'icon' => 'sites', 'text' => 'Theme' , 'href' => '/admin/theme' , 'modal' => false } if user.is_allowed('theme', 'edit') && !site.theme.nil?
36
- item['children'] << { 'id' => 'logs' , 'icon' => 'monitor', 'text' => 'Change Logs' , 'href' => '/admin/logs' , 'modal' => false } if user.is_allowed('logs' , 'view') && site.use_change_logs
34
+ item['children'] << { 'id' => 'theme' , 'icon' => 'sites', 'text' => 'Theme' , 'href' => '/admin/theme' , 'modal' => false } if user.is_allowed('theme' , 'view') if !site.theme.nil? && user.is_super_admin?
35
+ # item['children'] << { 'id' => 'variables' , 'text' => 'Variables' , 'href' => '/admin/settings' , 'modal' => false } if user.is_allowed('settings' , 'view')
37
36
  item['children'] << { 'id' => 'my-account' , 'text' => 'My Account' , 'href' => '/my-account' , 'modal' => false }
38
37
  nav << item if item['children'].count > 0
39
38
 
@@ -1,4 +1,4 @@
1
- require 'aws'
1
+ #require 'aws'
2
2
 
3
3
  module Caboose
4
4
  class Export < ActiveRecord::Base
@@ -1,12 +1,7 @@
1
1
  class Caboose::Font < ActiveRecord::Base
2
2
  self.table_name = "fonts"
3
3
 
4
- belongs_to :site, :class_name => 'Caboose::Site'
5
-
6
- attr_accessible :id, :site_id, :name, :family, :variant, :url, :variant_id
7
-
8
- def var
9
- Caboose::FontVariant.where(:id => self.variant_id).first
10
- end
4
+ belongs_to :site, :class_name => 'Caboose::Site'
5
+ attr_accessible :id, :site_id, :name, :family, :variant, :url
11
6
 
12
7
  end
@@ -1,17 +1,5 @@
1
1
  class Caboose::FontVariant < ActiveRecord::Base
2
-
3
2
  self.table_name = "font_variants"
4
-
5
3
  belongs_to :font_family, :class_name => 'Caboose::FontFamily'
6
-
7
- has_attached_file :ttf_file,
8
- :path => 'caboose_fonts/:id_ttf.:extension'
9
- do_not_validate_attachment_file_type :ttf_file
10
-
11
- has_attached_file :woff_file,
12
- :path => 'caboose_fonts/:id_woff.:extension'
13
- do_not_validate_attachment_file_type :woff_file
14
-
15
4
  attr_accessible :id, :ttf_url, :font_family_id, :variant, :weight, :style, :sort_order
16
-
17
5
  end
@@ -11,8 +11,8 @@ module Caboose
11
11
  belongs_to :customer, :class_name => 'Caboose::User'
12
12
  belongs_to :shipping_address, :class_name => 'Caboose::Address'
13
13
  belongs_to :billing_address, :class_name => 'Caboose::Address'
14
- has_many :discounts
15
- has_many :line_items, :order => :id
14
+ has_many :discounts
15
+ has_many :line_items, -> { order(:id) }
16
16
  has_many :invoice_packages, :class_name => 'Caboose::InvoicePackage'
17
17
  has_many :invoice_transactions
18
18
 
@@ -86,18 +86,18 @@ module Caboose
86
86
 
87
87
  #
88
88
  # Scopes
89
- #
90
- scope :cart , where('status = ?', 'cart')
91
- scope :pending , where('status = ?', 'pending')
92
- scope :canceled , where('status = ?', 'canceled')
93
- scope :shipped , where('status = ?', 'shipped')
94
- scope :paid , where('status = ?', 'paid')
95
- scope :test , where('status = ?', 'testing')
96
-
97
- scope :authorized , where('financial_status = ?', 'authorized')
98
- scope :captured , where('financial_status = ?', 'captured')
99
- scope :refunded , where('financial_status = ?', 'refunded')
100
- scope :voided , where('financial_status = ?', 'voided')
89
+ #
90
+ scope :cart , -> { where('status = ?', 'cart') }
91
+ scope :pending , -> { where('status = ?', 'pending') }
92
+ scope :canceled , -> { where('status = ?', 'canceled') }
93
+ scope :shipped , -> { where('status = ?', 'shipped') }
94
+ scope :paid , -> { where('status = ?', 'paid') }
95
+ scope :test , -> { where('status = ?', 'testing') }
96
+
97
+ scope :authorized , -> { where('financial_status = ?', 'authorized') }
98
+ scope :captured , -> { where('financial_status = ?', 'captured') }
99
+ scope :refunded , -> { where('financial_status = ?', 'refunded') }
100
+ scope :voided , -> { where('financial_status = ?', 'voided') }
101
101
 
102
102
  after_initialize :check_nil_fields
103
103
 
@@ -37,10 +37,10 @@ module Caboose
37
37
 
38
38
  #
39
39
  # Scopes
40
- #
41
- scope :pending , where('status = ?', 'pending')
42
- scope :fulfilled , where('status = ?', 'shipped')
43
- scope :unfulfilled , where('status != ?', 'shipped')
40
+ #
41
+ scope :pending , -> { where('status = ?' , 'pending') }
42
+ scope :fulfilled , -> { where('status = ?' , 'shipped') }
43
+ scope :unfulfilled , -> { where('status != ?', 'shipped') }
44
44
 
45
45
  #validates :quantity, :numericality => { :greater_than_or_equal_to => 0 }
46
46
  #validate :quantity_in_stock
@@ -33,8 +33,7 @@ class Caboose::Media < ActiveRecord::Base
33
33
  :image_updated_at,
34
34
  :file_file_name,
35
35
  :file_file_size,
36
- :file_updated_at,
37
- :deleted
36
+ :file_updated_at
38
37
 
39
38
  has_attached_file :sample
40
39
 
@@ -43,11 +42,6 @@ class Caboose::Media < ActiveRecord::Base
43
42
  # self.sample.options.merge({ :s3_headers => { "Content-Disposition" => "attachment; filename=#{self.name}" }})
44
43
  #end
45
44
 
46
- # def self.delete_id(media_id)
47
- # ProductImage.where(:media_id => media_id).destroy_all
48
- # Media.where(:id => media_id).destroy_all
49
- # end
50
-
51
45
  def process
52
46
  #return if self.processed
53
47
 
@@ -129,7 +123,7 @@ class Caboose::Media < ActiveRecord::Base
129
123
  end
130
124
 
131
125
  def download_file_from_url(url)
132
- self.file = URI.parse(url)
126
+ self.image = URI.parse(url)
133
127
  self.processed = true
134
128
  self.save
135
129
  end
@@ -178,11 +172,6 @@ class Caboose::Media < ActiveRecord::Base
178
172
  def reprocess_image
179
173
  self.image.reprocess!
180
174
  end
181
-
182
- def self.title_for_id(mid)
183
- m = Caboose::Media.where(:id => mid).first
184
- return m ? m.original_name : nil
185
- end
186
175
 
187
176
  def duplicate(site_id)
188
177
  cat = Caboose::MediaCategory.top_category(site_id)
@@ -201,8 +190,8 @@ class Caboose::Media < ActiveRecord::Base
201
190
  :file_updated_at => self.file_updated_at ,
202
191
  :processed => false
203
192
  )
204
- m.delay(:queue => 'general').download_image_from_url(self.image.url(:original)) if self.image
205
- m.delay(:queue => 'general').download_file_from_url(self.file.url) if self.file
193
+ m.delay(:queue => 'caboose_media').download_image_from_url(self.image.url(:original)) if self.image
194
+ m.delay(:queue => 'caboose_media').download_file_from_url(self.file.url) if self.file
206
195
  return m
207
196
  end
208
197
 
@@ -1,9 +1,9 @@
1
1
  class Caboose::MediaCategory < ActiveRecord::Base
2
2
 
3
3
  self.table_name = "media_categories"
4
- belongs_to :parent, :class_name => 'Caboose::MediaCategory'
5
- has_many :children, :class_name => 'Caboose::MediaCategory', :foreign_key => 'parent_id', :order => 'name'
6
- has_many :media, :class_name => 'Caboose::Media', :order => 'sort_order'
4
+ belongs_to :parent, :class_name => 'Caboose::MediaCategory'
5
+ has_many :children, -> { order(:name) }, :class_name => 'Caboose::MediaCategory', :foreign_key => 'parent_id'
6
+ has_many :media, -> { order(:sort_order) }, :class_name => 'Caboose::Media'
7
7
  attr_accessible :id, :site_id, :parent_id, :name
8
8
 
9
9
  def self.top_category(site_id)
@@ -24,7 +24,7 @@ class Caboose::MediaCategory < ActiveRecord::Base
24
24
  end
25
25
 
26
26
  def self.tree(site_id)
27
- return Caboose::MediaCategory.where(:parent_id => nil, :site_id => site_id).reorder("name").all
27
+ return self.where(:parent_id => nil, :site_id => site_id).reorder("name").all
28
28
  end
29
29
 
30
30
  def self.flat_tree(site_id, prefix = '-')
@@ -44,7 +44,8 @@ class Caboose::MediaCategory < ActiveRecord::Base
44
44
  :id => cat.id,
45
45
  :parent_id => cat.parent_id,
46
46
  :site_id => cat.site_id,
47
- :name => cat.name
47
+ :name => cat.name,
48
+ :media_count => cat.media.count
48
49
  }]
49
50
  cat.children.each do |cat2|
50
51
  arr += self.flat_tree_helper(cat2, prefix, "#{str}#{prefix}")
@@ -63,6 +64,7 @@ class Caboose::MediaCategory < ActiveRecord::Base
63
64
  return {
64
65
  :id => cat.id,
65
66
  :name => cat.name,
67
+ :media_count => cat.media.count,
66
68
  :children => (cat.name == 'Products' ? [] : cat.children.collect{ |kid| self.tree_hash_helper(kid) })
67
69
  }
68
70
  end
@@ -4,8 +4,8 @@ module Caboose
4
4
  self.table_name = 'store_modifications'
5
5
  self.primary_key = 'id'
6
6
 
7
- belongs_to :product, :class_name => 'Caboose::Product'
8
- has_many :modification_values, :class_name => 'Caboose::ModificationValue', :order => 'sort_order'
7
+ belongs_to :product, :class_name => 'Caboose::Product'
8
+ has_many :modification_values, -> { order(:sort_order) }, :class_name => 'Caboose::ModificationValue'
9
9
  attr_accessible :id,
10
10
  :product_id,
11
11
  :sort_order,
@@ -3,11 +3,12 @@ class Caboose::Page < ActiveRecord::Base
3
3
  self.table_name = "pages"
4
4
 
5
5
  belongs_to :site, :class_name => 'Caboose::Site'
6
- belongs_to :parent, :class_name => 'Caboose::Page'
7
- has_many :children, :class_name => 'Caboose::Page', :foreign_key => 'parent_id', :order => 'sort_order, title'
8
- has_many :page_permissions
9
- has_many :blocks, :order => 'sort_order'
10
- has_many :page_tags, :class_name => 'Caboose::PageTag', :dependent => :delete_all, :order => 'tag'
6
+ belongs_to :parent, :class_name => 'Caboose::Page'
7
+ has_many :children, -> { order('sort_order, title') }, :class_name => 'Caboose::Page', :foreign_key => 'parent_id'
8
+ has_many :page_permissions
9
+ has_many :blocks, -> { order(:sort_order) }
10
+ has_many :page_tags, -> { order(:tag) }, :class_name => 'Caboose::PageTag', :dependent => :delete_all
11
+ has_one :page_cache
11
12
  has_many :page_custom_field_values
12
13
  attr_accessible :id ,
13
14
  :site_id ,
@@ -19,10 +20,13 @@ class Caboose::Page < ActiveRecord::Base
19
20
  :uri ,
20
21
  :redirect_url ,
21
22
  :hide ,
23
+ :content_format ,
22
24
  :custom_css ,
23
25
  :custom_css_files ,
24
26
  :custom_js ,
25
27
  :custom_js_files ,
28
+ :linked_resources ,
29
+ :layout ,
26
30
  :sort_order ,
27
31
  :custom_sort_children ,
28
32
  :seo_title ,
@@ -32,8 +36,11 @@ class Caboose::Page < ActiveRecord::Base
32
36
  :canonical_url ,
33
37
  :fb_description ,
34
38
  :gp_description ,
35
- :css_digest ,
36
- :js_digest
39
+ :status
40
+
41
+ CONTENT_FORMAT_HTML = 1
42
+ CONTENT_FORMAT_TEXT = 2
43
+ CONTENT_FORMAT_RUBY = 3
37
44
 
38
45
  def order_title
39
46
  return "" + menu_title + title unless menu_title.nil? || title.nil?
@@ -45,15 +52,15 @@ class Caboose::Page < ActiveRecord::Base
45
52
  def block
46
53
  Caboose::Block.where("page_id = ? and parent_id is null", self.id).first
47
54
  end
48
-
49
- def self.title_for_id(page_id)
50
- p = Caboose::Page.where(:id => page_id).first
51
- return p ? p.title : nil
52
- end
53
55
 
54
56
  def top_level_blocks
55
57
  Caboose::Block.where("page_id = ? and parent_id is null", self.id).reorder(:sort_order).all
56
58
  end
59
+
60
+ #def content
61
+ # return "" if self.blocks.nil? || self.blocks.count == 0
62
+ # self.blocks.collect { |b| b.render }.join("\n")
63
+ #end
57
64
 
58
65
  def self.find_with_fields(page_id, fields)
59
66
  return self.where(:id => page_id).select(fields).first
@@ -67,143 +74,9 @@ class Caboose::Page < ActiveRecord::Base
67
74
  Caboose::Block.where(:page_id => self.id).where('status != ?','published').count == 0 if !self.id.nil?
68
75
  end
69
76
 
70
- # Returns an array of block IDs for all descendant blocks of the homepage footer
71
- def self.home_page_footer_block_ids(page)
72
- home_page = Caboose::Page.index_page(page.site_id)
73
- home_footer = home_page ? home_page.block.child('footer') : nil
74
- if home_footer
75
- footer_ids = [home_footer.id]
76
- home_footer.children.where("name is null").each do |f1|
77
- footer_ids << f1.id
78
- f1.children.where("name is null").each do |f2|
79
- footer_ids << f2.id
80
- f2.children.where("name is null").each do |f3|
81
- footer_ids << f3.id
82
- f3.children.where("name is null").each do |f4|
83
- footer_ids << f4.id
84
- f4.children.where("name is null").each do |f5|
85
- footer_ids << f5.id
86
- end
87
- end
88
- end
89
- end
90
- end
91
- return footer_ids
92
- else
93
- return [0]
94
- end
95
- end
96
-
97
- def update_cached_blocks(block_ids)
98
- blocks = block_ids && block_ids.count > 0 ? Caboose::Block.where("id in (?)", block_ids).order(:id).all : []
99
- blocks.each do |b|
100
- b.use_cache = false
101
- b.save
102
- b.delay(:queue => 'caching', :priority => 6).update_cache
103
- end
104
- end
105
-
106
- def cached_css
107
- str = ''
108
- return str if self.site.nil? || !self.site.use_caching
109
- blocks = Caboose::Block.includes(:block_type).where("blocks.page_id = ?",self.id).where("blocks.cached_css IS NOT NULL").where("block_types.is_dynamic = false").order("blocks.id").all
110
- blocks.each do |b|
111
- str << b.cached_css
112
- end
113
-
114
- # Add any CSS for referenced Block Copy blocks
115
- bt = Caboose::BlockType.where(:name => 'source_block_id').first
116
- if bt
117
- ref_ids = Caboose::Block.where("value is not null").where(:block_type_id => bt.id, :page_id => self.id).pluck(:value)
118
- if ref_ids && ref_ids.count > 0
119
- Caboose::Block.includes(:block_type).where("blocks.id in (?)", ref_ids).order("blocks.id").all.each do |b|
120
- str << b.cached_css if !b.cached_css.blank? && !b.block_type.is_dynamic
121
- b.children.where("name is null").each do |b1|
122
- str << b1.cached_css if !b1.cached_css.blank? && !b1.block_type.is_dynamic
123
- b1.children.where("name is null").each do |b2|
124
- str << b2.cached_css if !b2.cached_css.blank? && !b2.block_type.is_dynamic
125
- b2.children.where("name is null").each do |b3|
126
- str << b3.cached_css if !b3.cached_css.blank? && !b3.block_type.is_dynamic
127
- b3.children.where("name is null").each do |b4|
128
- str << b4.cached_css if !b4.cached_css.blank? && !b4.block_type.is_dynamic
129
- end
130
- end
131
- end
132
- end
133
- end
134
- end
135
- end
136
-
137
- return str.blank? ? '' : str.gsub(/<\/style>(\s*)<style>/,'')
138
- end
139
-
140
- def cached_js
141
- str = ''
142
- return str if self.site.nil? || !self.site.use_caching
143
- blocks = Caboose::Block.includes(:block_type).where("blocks.page_id = ?",self.id).where("blocks.cached_js IS NOT NULL").where("block_types.is_dynamic = false").order("blocks.id").all
144
- blocks.each do |b|
145
- str << b.cached_js
146
- end
147
-
148
- # Add any JS for referenced Block Copy blocks
149
- bt = Caboose::BlockType.where(:name => 'source_block_id').first
150
- if bt
151
- ref_ids = Caboose::Block.where("value is not null").where(:block_type_id => bt.id, :page_id => self.id).pluck(:value)
152
- if ref_ids && ref_ids.count > 0
153
- Caboose::Block.includes(:block_type).where("blocks.id in (?)", ref_ids).order("blocks.id").all.each do |b|
154
- str << b.cached_js if !b.cached_js.blank? && !b.block_type.is_dynamic
155
- b.children.where("name is null").each do |b1|
156
- str << b1.cached_js if !b1.cached_js.blank? && !b1.block_type.is_dynamic
157
- b1.children.where("name is null").each do |b2|
158
- str << b2.cached_js if !b2.cached_js.blank? && !b2.block_type.is_dynamic
159
- b2.children.where("name is null").each do |b3|
160
- str << b3.cached_js if !b3.cached_js.blank? && !b3.block_type.is_dynamic
161
- b3.children.where("name is null").each do |b4|
162
- str << b4.cached_js if !b4.cached_js.blank? && !b4.block_type.is_dynamic
163
- end
164
- end
165
- end
166
- end
167
- end
168
- end
169
- end
170
-
171
- host = Rails.env.production? ? "https://#{ActionController::Base.asset_host}" : ""
172
- return str.blank? ? '' : str.gsub('"/assets/',"\"#{host}/assets/")
173
- end
174
-
175
- def publish(user_id)
77
+ def publish
176
78
  if !self.id.nil?
177
- use_caching = self.site.use_caching
178
- changed_ids = []
179
79
  Caboose::Block.where(:page_id => self.id).where('status = ? OR status = ?','edited','added').all.each do |b|
180
- if self.site && self.site.use_change_logs
181
- if b.new_parent_id.blank? && b.new_value.blank? && b.new_media_id.blank? && b.sort_order == b.new_sort_order && b.status == 'edited'
182
- # This one just got moved because something else was added
183
- else
184
- cl = Caboose::ChangeLog.create(:site_id => self.site_id, :user_id => user_id, :page_id => self.id, :block_id => b.id, :block_parent_id => b.parent_id, :timestamp => DateTime.now, :action => b.status)
185
- desc = ""
186
- desc += b.parent.parent.block_type.description + " -> " if b.parent && b.parent.parent && b.parent.parent.block_type && b.parent.parent.block_type.description != "Content" && !b.parent.parent.block_type.name.include?('layout')
187
- pos = b.parent && b.parent.block_type && b.parent.block_type.name == 'flex_grid_unit' ? b.parent.sort_order + 1 : nil
188
- desc += b.parent.block_type.description + " #{pos} -> " if b.parent && b.parent.block_type && b.parent.block_type.description != "Content" && !b.parent.block_type.name.include?('layout')
189
- desc += b.block_type.description if b.block_type
190
- cl.description = desc
191
- cl.is_field = true if !b.name.blank?
192
- ov = ['page','page_id'].include?(b.name) ? Caboose::Page.title_for_id(b.value) : b.value
193
- nv = ['page','page_id'].include?(b.name) ? Caboose::Page.title_for_id(b.new_value) : b.new_value
194
- if b.new_value.blank? && !b.new_media_id.blank?
195
- ov = Caboose::Media.title_for_id(b.media_id)
196
- nv = Caboose::Media.title_for_id(b.new_media_id)
197
- end
198
- cl.old_value = ov
199
- cl.new_value = nv
200
- cl.old_sort_order = b.sort_order
201
- cl.new_sort_order = b.new_sort_order
202
- cl.old_parent_id = b.parent_id
203
- cl.new_parent_id = b.new_parent_id
204
- cl.save
205
- end
206
- end
207
80
  if b.new_value == 'EMPTY'
208
81
  b.value = nil
209
82
  elsif !b.new_value.blank?
@@ -219,41 +92,16 @@ class Caboose::Page < ActiveRecord::Base
219
92
  b.status = 'published'
220
93
  b.new_value = nil
221
94
  b.new_media_id = nil
222
- b.new_sort_order = b.sort_order
95
+ b.new_sort_order = nil
223
96
  b.new_parent_id = nil
224
97
  b.save
225
- # Update cached value for the closest cached ancestor of this block
226
- changed_ids << b.cached_ancestor if use_caching
227
- end
228
- if use_caching # Catch published blocks that have never been cached before
229
- content = self.block.child('content')
230
- Caboose::Block.includes(:block_type).where(:parent_id => content.id, :status => 'published', :cached_value => nil, :name => nil).where("block_types.is_dynamic = false").all.each do |b|
231
- changed_ids << b.cached_ancestor
232
- end
233
98
  end
234
99
  deleted_blocks = Caboose::Block.where(:page_id => self.id, :status => 'deleted').pluck(:id)
235
100
  dids = deleted_blocks.blank? ? 0 : deleted_blocks
236
- if self.site && self.site.use_change_logs
237
- Caboose::Block.where("id in (?)",dids).all.each do |b|
238
- cl = Caboose::ChangeLog.create(:site_id => self.site_id, :user_id => user_id, :page_id => self.id, :block_id => b.id, :block_parent_id => b.parent_id, :timestamp => DateTime.now, :action => 'deleted')
239
- cl.old_value = b.new_value.blank? ? b.value : b.new_value
240
- cl.description = b.block_type.description if b.block_type
241
- cl.is_field = true if !b.name.blank?
242
- cl.save
243
- end
244
- end
245
101
  Caboose::Block.where("id in (?) or parent_id in (?)",dids,dids).destroy_all
246
102
  Caboose::Block.where(:page_id => self.id, :status => nil).update_all(:status => 'published')
247
- if use_caching
248
- index_page = Caboose::Page.index_page(self.site_id)
249
- self.update_cached_blocks(changed_ids)
250
- self.delay(:queue => 'caching', :priority => 7).update_css_file
251
- self.delay(:queue => 'caching', :priority => 7).update_js_file
252
- if index_page && self.id == index_page.id
253
- self.site.delay(:queue => 'caching', :priority => 8).update_footer_css_file
254
- self.site.delay(:queue => 'caching', :priority => 8).update_footer_js_file
255
- end
256
- end
103
+ self.status = 'published'
104
+ self.save
257
105
  end
258
106
  end
259
107
 
@@ -261,28 +109,8 @@ class Caboose::Page < ActiveRecord::Base
261
109
  if !self.id.nil?
262
110
  Caboose::Block.where(:page_id => self.id).where(:status => 'added').destroy_all
263
111
  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")
264
- end
265
- end
266
-
267
- def refresh_css
268
- begin
269
- rad = rand(999)
270
- dom = Rails.env.production? ? self.site.public_domain : self.site.dev_domain.domain
271
- uri = URI("http://#{dom}/api/page_#{self.id}.css?#{rad}")
272
- css = Net::HTTP.get(uri)
273
- rescue
274
- Caboose.log("Couldn't generate page CSS")
275
- end
276
- end
277
-
278
- def refresh_js
279
- begin
280
- rad = rand(999)
281
- dom = Rails.env.production? ? self.site.public_domain : self.site.dev_domain.domain
282
- uri = URI("http://#{dom}/api/page_#{self.id}.js?#{rad}")
283
- css = Net::HTTP.get(uri)
284
- rescue
285
- Caboose.log("Couldn't generate page JS")
112
+ self.status = 'published'
113
+ self.save
286
114
  end
287
115
  end
288
116
 
@@ -307,15 +135,15 @@ class Caboose::Page < ActiveRecord::Base
307
135
  page_id = !page_ids.nil? && page_ids.count > 0 ? page_ids[0] : false
308
136
 
309
137
  # Search for the page
310
- if page_id
138
+ if page_id
311
139
  page_id = self.page_with_uri_helper(parts, 1, page_id)
312
- else
313
- parent_id = self.index_page(site_id)
140
+ else
141
+ parent_id = self.index_page(site_id).id
314
142
  page_id = self.page_with_uri_helper(parts, 0, parent_id)
315
143
  end
316
144
 
317
145
  return false if page_id.nil?
318
-
146
+
319
147
  page = self.find(page_id)
320
148
 
321
149
  if (!get_closest_parent) # // Look for an exact match
@@ -429,13 +257,13 @@ class Caboose::Page < ActiveRecord::Base
429
257
  user = Caboose::User.find(user)
430
258
  end
431
259
  ids = []
432
- user.roles.each do |role|
433
- ids << Caboose::PagePermission.where({
260
+ user.roles.each do |role|
261
+ ids + Caboose::PagePermission.where({
434
262
  :role_id => role.id,
435
263
  :action => action
436
264
  }).pluck(:page_id)
437
265
  end
438
- return ids.flatten
266
+ return ids.uniq
439
267
  end
440
268
 
441
269
  def self.crumb_trail(page)
@@ -511,119 +339,6 @@ class Caboose::Page < ActiveRecord::Base
511
339
  end
512
340
  return block
513
341
  end
514
-
515
-
516
- def css_path(digest = self.css_digest)
517
- return "assets/pages/page_#{self.id}_#{digest}.css"
518
- end
519
-
520
- def css_url
521
- rad = rand(999)
522
- old = "/api/page_#{self.id}.css?#{rad}"
523
- return old if self.css_digest.blank?
524
- if Rails.env.production?
525
- return "https://#{Caboose::cdn_domain}/#{css_path}"
526
- else
527
- path = File.join(Rails.root, 'public', "#{css_path}")
528
- if File.file?(path)
529
- return "#{ActionController::Base.asset_host}/#{css_path}"
530
- else
531
- return "https://#{Caboose::cdn_domain}/#{css_path}"
532
- end
533
- end
534
- end
535
-
536
- def update_css_file
537
- str = ""
538
- css_digest = SecureRandom.urlsafe_base64.to_s
539
- old_digest = self.css_digest
540
- css = self.refresh_css
541
- if css && !css.blank?
542
- begin
543
- if Rails.env.production?
544
- config = YAML.load(File.read(Rails.root.join('config', 'aws.yml')))[Rails.env]
545
- AWS.config(:access_key_id => config['access_key_id'], :secret_access_key => config['secret_access_key'])
546
- bucket = AWS::S3.new.buckets[config['bucket']]
547
- bucket.objects[self.css_path(css_digest)].write(css, :acl => 'public-read', :content_type => 'text/css', :cache_control => 'public, max-age=86400')
548
- if !old_digest.blank? && old_digest != 'empty'
549
- key = self.css_path(old_digest)
550
- obj = bucket.objects[key]
551
- obj.delete
552
- end
553
- else
554
- file_path = File.join(Rails.root, 'public', 'assets', 'pages')
555
- FileUtils.mkdir_p(file_path) unless File.directory?(file_path)
556
- File.open(File.join(Rails.root, 'public', self.css_path(css_digest)), 'wb+') { |f| f.write( css ) }
557
- if !old_digest.blank? && old_digest != 'empty'
558
- path = File.join(Rails.root, 'public', self.css_path(old_digest))
559
- File.delete(path) if File.file?(path)
560
- end
561
- end
562
- self.update_column('css_digest', css_digest)
563
- rescue
564
- self.update_column('css_digest', old_digest)
565
- end
566
- else
567
- self.update_column('css_digest', 'empty')
568
- end
569
- end
570
-
571
- def js_path(digest = self.js_digest)
572
- return "assets/pages/page_#{self.id}_#{digest}.js"
573
- end
574
-
575
- def js_url
576
- rad = rand(999)
577
- old = "/api/page_#{self.id}.js?#{rad}"
578
- return old if self.js_digest.blank?
579
- if Rails.env.production?
580
- return "https://#{Caboose::cdn_domain}/#{js_path}"
581
- else
582
- path = File.join(Rails.root, 'public', "#{js_path}")
583
- if File.file?(path)
584
- return "#{ActionController::Base.asset_host}/#{js_path}"
585
- else
586
- return "https://#{Caboose::cdn_domain}/#{js_path}"
587
- end
588
- end
589
- end
590
-
591
- def update_js_file
592
- str = ""
593
- js_digest = SecureRandom.urlsafe_base64.to_s
594
- old_digest = self.js_digest
595
- js = self.refresh_js
596
- if js && !js.blank?
597
- begin
598
- if Rails.env.production?
599
- config = YAML.load(File.read(Rails.root.join('config', 'aws.yml')))[Rails.env]
600
- AWS.config(:access_key_id => config['access_key_id'], :secret_access_key => config['secret_access_key'])
601
- bucket = AWS::S3.new.buckets[config['bucket']]
602
- bucket.objects[self.js_path(js_digest)].write(js, :acl => 'public-read', :content_type => 'text/javascript', :cache_control => 'public, max-age=86400')
603
- if !old_digest.blank? && old_digest != 'empty'
604
- key = self.js_path(old_digest)
605
- obj = bucket.objects[key]
606
- obj.delete
607
- end
608
- else
609
- file_path = File.join(Rails.root, 'public', 'assets', 'pages')
610
- FileUtils.mkdir_p(file_path) unless File.directory?(file_path)
611
- File.open(File.join(Rails.root, 'public', self.js_path(js_digest)), 'wb+') { |f| f.write( js ) }
612
- if !old_digest.blank? && old_digest != 'empty'
613
- path = File.join(Rails.root, 'public', self.js_path(old_digest))
614
- File.delete(path) if File.file?(path)
615
- end
616
- end
617
- self.update_column('js_digest', js_digest)
618
- rescue
619
- self.update_column('js_digest', old_digest)
620
- end
621
- else
622
- self.update_column('js_digest', 'empty')
623
- end
624
- end
625
-
626
-
627
342
 
628
343
  def self.url(page_id)
629
344
  arr = []
@@ -677,6 +392,21 @@ class Caboose::Page < ActiveRecord::Base
677
392
  def is_child_of?(parent_id)
678
393
  return Caboose::Page.is_child(parent_id, self.id)
679
394
  end
395
+
396
+ def linked_resources_map
397
+ resources = { js: [], css: [] }
398
+ return resources if self.linked_resources.nil?
399
+ self.linked_resources.each_line do |r|
400
+ r.chomp!
401
+ case r
402
+ when /\.js$/
403
+ resources[:js] << r
404
+ when /\.css$/
405
+ resources[:css] << r
406
+ end
407
+ end
408
+ return resources
409
+ end
680
410
 
681
411
  def head_title
682
412
  str = ""
@@ -714,7 +444,7 @@ class Caboose::Page < ActiveRecord::Base
714
444
  end
715
445
  end
716
446
 
717
- def duplicate(site_id, parent_id, duplicate_children = false, block_type_id = nil, child_block_type_id = nil, user_id = nil)
447
+ def duplicate(site_id, parent_id, duplicate_children = false, block_type_id = nil, child_block_type_id = nil)
718
448
 
719
449
  if parent_id.to_i == -1
720
450
  p = Caboose::Page.index_page(site_id)
@@ -729,15 +459,16 @@ class Caboose::Page < ActiveRecord::Base
729
459
  p = Caboose::Page.create(:site_id => site_id, :parent_id => parent_id)
730
460
  end
731
461
 
732
- site = Caboose::Site.where(:id => site_id).first
733
-
734
462
  p.title = "Copy of " + self.title
735
463
  p.menu_title = self.menu_title
736
464
  p.alias = self.alias
737
465
  p.redirect_url = self.redirect_url
738
- p.hide = true
466
+ p.hide = true
467
+ p.content_format = self.content_format
739
468
  p.custom_css = self.custom_css
740
- p.custom_js = self.custom_js
469
+ p.custom_js = self.custom_js
470
+ p.linked_resources = self.linked_resources
471
+ p.layout = self.layout
741
472
  p.sort_order = self.sort_order
742
473
  p.custom_sort_children = self.custom_sort_children
743
474
  p.seo_title = self.seo_title
@@ -757,8 +488,6 @@ class Caboose::Page < ActiveRecord::Base
757
488
  end while (Caboose::Page.where(:uri => p.uri, :site_id => site_id).count > 0 && i < 10)
758
489
 
759
490
  p.save
760
-
761
- Caboose::ChangeLog.create(:site_id => site_id, :description => p.title, :user_id => user_id, :page_id => p.id, :timestamp => DateTime.now, :action => 'created') if site && site.use_change_logs
762
491
 
763
492
  self.page_tags.each{ |tag| Caboose::PageTag.create(:page_id => p.id, :tag => tag.tag) }
764
493
 
@@ -777,7 +506,7 @@ class Caboose::Page < ActiveRecord::Base
777
506
 
778
507
  if duplicate_children && !p.is_child_of?(self.id)
779
508
  self.children.each do |p2|
780
- p2.duplicate(site_id, p.id, duplicate_children, child_block_type_id, child_block_type_id, user_id)
509
+ p2.duplicate(site_id, p.id, duplicate_children, child_block_type_id, child_block_type_id)
781
510
  end
782
511
  end
783
512
  return p