knitkit 3.0.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. checksums.yaml +4 -4
  2. data/{public → app/assets}/images/check.png +0 -0
  3. data/{public → app/assets}/images/credit_card.png +0 -0
  4. data/{public → app/assets}/images/inline_edit/close.png +0 -0
  5. data/{public → app/assets}/images/knitkit/icons/document.png +0 -0
  6. data/{public → app/assets}/images/knitkit/icons/multi_doc.png +0 -0
  7. data/{public → app/assets}/images/knitkit/logo.png +0 -0
  8. data/{public → app/assets}/images/knitkit/splash/images/add-site.png +0 -0
  9. data/app/assets/images/knitkit/splash/images/add_website_105x105-active.png +0 -0
  10. data/app/assets/images/knitkit/splash/images/add_website_105x105.png +0 -0
  11. data/{public → app/assets}/images/knitkit/splash/images/adjust-site.png +0 -0
  12. data/{public → app/assets}/images/knitkit/splash/images/browse-site.png +0 -0
  13. data/app/assets/images/knitkit/splash/images/browse_db_105x105-active.png +0 -0
  14. data/app/assets/images/knitkit/splash/images/browse_db_105x105.png +0 -0
  15. data/app/assets/images/knitkit/splash/images/console_105x105-active.png +0 -0
  16. data/app/assets/images/knitkit/splash/images/console_105x105.png +0 -0
  17. data/{public → app/assets}/images/knitkit/splash/images/find-themes.png +0 -0
  18. data/app/assets/images/knitkit/splash/images/find_themes_105x105-active.png +0 -0
  19. data/app/assets/images/knitkit/splash/images/find_themes_105x105.png +0 -0
  20. data/app/assets/images/knitkit/splash/images/learn_more_105x105-active.png +0 -0
  21. data/app/assets/images/knitkit/splash/images/learn_more_105x105.png +0 -0
  22. data/{public → app/assets}/images/knitkit/splash/images/settings.png +0 -0
  23. data/{public → app/assets}/images/knitkit/splash/images/tutorials.png +0 -0
  24. data/app/assets/images/knitkit/splash/splash.png +0 -0
  25. data/app/assets/images/widgets/manage_profile/contact_information.png +0 -0
  26. data/app/assets/images/widgets/manage_profile/password.png +0 -0
  27. data/app/assets/images/widgets/manage_profile/user_information.png +0 -0
  28. data/app/assets/javascripts/erp_app/desktop/applications/knitkit/app.js +24 -0
  29. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/articles_grid_panel.js +15 -12
  30. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/center_region.js +69 -48
  31. data/app/assets/javascripts/erp_app/desktop/applications/knitkit/comments_grid_panel.js +214 -0
  32. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/east_region/east_region.js +0 -0
  33. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/east_region/file_assets_panel.js +17 -19
  34. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/east_region/image_assets_data_view.js +13 -3
  35. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/east_region/image_assets_panel.js +59 -48
  36. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/east_region/widgets_panel.js +0 -0
  37. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/inquiries_grid_panel.js +2 -2
  38. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/module.js +2 -2
  39. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/publish_window.js +0 -0
  40. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/published_grid_panel.js +1 -1
  41. data/app/assets/javascripts/erp_app/desktop/applications/knitkit/splash_screen.js +268 -0
  42. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/top_menu/main_menu.js +85 -33
  43. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/top_menu/websites_combo.js +0 -0
  44. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/versions_grid_panel.js +5 -28
  45. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/article.js +22 -8
  46. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/document.js +143 -25
  47. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/host.js +5 -1
  48. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/menu.js +2 -0
  49. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/section.js +181 -65
  50. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/website_nav_items.js +0 -0
  51. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/west_region/hosts_tree_panel.js +0 -0
  52. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/west_region/menu_tree_panel.js +0 -0
  53. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/west_region/site_contents_tree_panel.js +121 -116
  54. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/west_region/themes_tree_panel.js +101 -10
  55. data/{public → app/assets}/javascripts/erp_app/desktop/applications/knitkit/west_region/west_region.js +9 -5
  56. data/app/assets/javascripts/knitkit-web.js +22 -0
  57. data/app/assets/javascripts/knitkit/additional-methods.min.js +4 -0
  58. data/app/assets/javascripts/knitkit/bootstrap.min.js +7 -0
  59. data/app/assets/javascripts/knitkit/captcha.js +154 -0
  60. data/{public → app/assets}/javascripts/knitkit/confirm-bootstrap.js +1 -1
  61. data/{public → app/assets}/javascripts/knitkit/inline_editing.js +1 -1
  62. data/{public → app/assets}/javascripts/knitkit/jquery.maskedinput.min.js +0 -0
  63. data/app/assets/javascripts/knitkit/jquery.validate.min.js +4 -0
  64. data/app/assets/javascripts/knitkit/js.cookie.js +145 -0
  65. data/{public → app/assets}/javascripts/knitkit/theme.js +0 -0
  66. data/app/assets/stylesheets/erp_app/desktop/applications/knitkit/app.css +12 -0
  67. data/{public → app/assets}/stylesheets/erp_app/desktop/applications/knitkit/knitkit.css +23 -33
  68. data/app/assets/stylesheets/erp_app/shared/knitkit_shared.css +21 -0
  69. data/app/assets/stylesheets/fonts/glyphicons-halflings-regular.eot +0 -0
  70. data/app/assets/stylesheets/fonts/glyphicons-halflings-regular.svg +288 -0
  71. data/app/assets/stylesheets/fonts/glyphicons-halflings-regular.ttf +0 -0
  72. data/app/assets/stylesheets/fonts/glyphicons-halflings-regular.woff +0 -0
  73. data/app/assets/stylesheets/fonts/glyphicons-halflings-regular.woff2 +0 -0
  74. data/app/assets/stylesheets/knitkit-web.css +16 -0
  75. data/app/assets/stylesheets/knitkit/bootstrap.min.css +5 -0
  76. data/app/assets/stylesheets/knitkit/captcha.css +59 -0
  77. data/app/assets/stylesheets/knitkit/custom.css +144 -0
  78. data/{public → app/assets}/stylesheets/knitkit/inline_editing.css +0 -0
  79. data/app/assets/stylesheets/knitkit/submenu.css +93 -0
  80. data/app/controllers/api/v1/websites_controller.rb +14 -0
  81. data/app/controllers/captcha_controller.rb +53 -0
  82. data/app/controllers/knitkit/base_controller.rb +1 -5
  83. data/app/controllers/knitkit/erp_app/desktop/app_controller.rb +2 -9
  84. data/app/controllers/knitkit/erp_app/desktop/articles_controller.rb +20 -7
  85. data/app/controllers/knitkit/erp_app/desktop/file_assets_controller.rb +38 -28
  86. data/app/controllers/knitkit/erp_app/desktop/image_assets_controller.rb +16 -9
  87. data/app/controllers/knitkit/erp_app/desktop/online_document_sections_controller.rb +69 -15
  88. data/app/controllers/knitkit/erp_app/desktop/position_controller.rb +45 -58
  89. data/app/controllers/knitkit/erp_app/desktop/theme_controller.rb +64 -29
  90. data/app/controllers/knitkit/erp_app/desktop/website_controller.rb +36 -13
  91. data/app/controllers/knitkit/erp_app/desktop/website_host_controller.rb +12 -0
  92. data/app/controllers/knitkit/erp_app/desktop/website_nav_controller.rb +4 -11
  93. data/app/controllers/knitkit/erp_app/desktop/website_nav_item_controller.rb +2 -9
  94. data/app/controllers/knitkit/erp_app/desktop/website_section_controller.rb +56 -20
  95. data/app/controllers/knitkit/online_document_sections_controller.rb +9 -3
  96. data/app/mailers/website_inquiry_mailer.rb +11 -3
  97. data/app/models/content.rb +16 -6
  98. data/app/models/documented_item.rb +12 -1
  99. data/app/models/online_document_section.rb +54 -20
  100. data/app/models/published_website.rb +16 -0
  101. data/app/models/theme.rb +53 -47
  102. data/app/models/website.rb +172 -191
  103. data/app/models/website_section.rb +64 -30
  104. data/app/views/knitkit/blogs/show.html.erb +5 -2
  105. data/app/views/layouts/knitkit/base.html.erb +54 -51
  106. data/app/views/menus/knitkit/_default_menu.html.erb +11 -11
  107. data/app/views/menus/knitkit/_default_section_menu.html.erb +2 -2
  108. data/app/views/menus/knitkit/_default_sub_menu.erb +27 -0
  109. data/app/views/menus/knitkit/_default_sub_section_menu.html.erb +30 -0
  110. data/app/views/website_inquiry_mailer/inquiry.html.erb +266 -0
  111. data/app/widgets/contact_us/base.rb +26 -16
  112. data/app/widgets/contact_us/javascript/contact_us.js +1 -1
  113. data/app/widgets/contact_us/views/error.html.erb +7 -3
  114. data/app/widgets/contact_us/views/index.html.erb +36 -28
  115. data/app/widgets/google_map/javascript/google_map.js +1 -1
  116. data/app/widgets/google_map/views/index.html.erb +1 -1
  117. data/app/widgets/login/javascript/login.js +1 -1
  118. data/app/widgets/login/views/index.html.erb +1 -1
  119. data/app/widgets/manage_profile/base.rb +141 -112
  120. data/app/widgets/manage_profile/javascript/manage_profile.js +2 -2
  121. data/app/widgets/manage_profile/views/_password_form.html.erb +1 -1
  122. data/app/widgets/manage_profile/views/_user_information_form.html.erb +1 -30
  123. data/app/widgets/manage_profile/views/index.html.erb +42 -40
  124. data/app/widgets/reset_password/base.rb +39 -8
  125. data/app/widgets/reset_password/javascript/reset_password.js +1 -1
  126. data/app/widgets/reset_password/views/index.html.erb +3 -3
  127. data/app/widgets/reset_password/views/invalid_reset_token.html.erb +7 -0
  128. data/app/widgets/reset_password/views/layouts/base.html.erb +1 -1
  129. data/app/widgets/reset_password/views/reset_password.html.erb +39 -0
  130. data/app/widgets/reset_password/views/reset_success.html.erb +5 -0
  131. data/app/widgets/search/base.rb +5 -5
  132. data/app/widgets/search/javascript/search.js +6 -6
  133. data/app/widgets/search/views/_inline_search_form.html.erb +23 -12
  134. data/app/widgets/search/views/_search_form.html.erb +34 -30
  135. data/app/widgets/search/views/layouts/base.html.erb +6 -1
  136. data/app/widgets/signup/base.rb +73 -30
  137. data/app/widgets/signup/javascript/signup.js +1 -1
  138. data/app/widgets/signup/views/_signup_form.html.erb +2 -1
  139. data/app/widgets/signup/views/layouts/base.html.erb +1 -1
  140. data/app/widgets/signup/views/success.html.erb +2 -3
  141. data/config/routes.rb +25 -4
  142. data/db/data_migrations/20110509223702_add_publisher_role.rb +0 -2
  143. data/db/data_migrations/20110816153456_add_knitkit_application.rb +7 -15
  144. data/db/data_migrations/20120127150505_create_website_default_configuration.rb +63 -3
  145. data/db/data_migrations/20150118180450_add_website_member_roles.rb +12 -0
  146. data/db/data_migrations/20150414150359_nest_knitkit_security_roles.rb +35 -0
  147. data/db/data_migrations/20150414173437_move_website_roles_under_website_builder.rb +19 -0
  148. data/db/migrate/20110211002317_setup_knitkit.rb +86 -39
  149. data/lib/knitkit.rb +8 -2
  150. data/lib/knitkit/config.rb +2 -3
  151. data/lib/knitkit/engine.rb +35 -4
  152. data/lib/knitkit/extensions.rb +2 -1
  153. data/lib/knitkit/extensions/action_controller/theme_support/acts_as_themed_controller.rb +1 -1
  154. data/lib/knitkit/extensions/action_mailer/theme_support/acts_as_themed_mailer.rb +1 -1
  155. data/lib/knitkit/extensions/compass_ae/mailers/user_mailer.rb +31 -0
  156. data/lib/knitkit/extensions/compass_ae/widgets/base.rb +1 -1
  157. data/lib/knitkit/extensions/railties/action_controller/captcha_helper.rb +43 -0
  158. data/lib/knitkit/extensions/railties/action_view/helpers/content_helper.rb +1 -1
  159. data/lib/knitkit/extensions/railties/action_view/helpers/menu_helper.rb +11 -1
  160. data/lib/knitkit/extensions/railties/theme_support/asset_tag_helper.rb +83 -0
  161. data/lib/knitkit/routing_filter/section_router.rb +24 -14
  162. data/lib/knitkit/version.rb +1 -1
  163. data/lib/tasks/knitkit_tasks.rake +89 -4
  164. data/lib/tasks/theme_parser.rake +85 -0
  165. data/public/fonts/glyphicons-halflings-regular.eot +0 -0
  166. data/public/fonts/glyphicons-halflings-regular.svg +288 -0
  167. data/public/fonts/glyphicons-halflings-regular.ttf +0 -0
  168. data/public/fonts/glyphicons-halflings-regular.woff +0 -0
  169. data/public/fonts/glyphicons-halflings-regular.woff2 +0 -0
  170. data/public/paypal-button.min.js +7 -0
  171. metadata +161 -82
  172. data/app/assets/javascripts/knitkit/application.js +0 -9
  173. data/app/assets/stylesheets/knitkit/application.css +0 -7
  174. data/app/mailers/document_mailer.rb +0 -10
  175. data/app/views/document_mailer/email_document.html.erb +0 -12
  176. data/app/views/knitkit/mobile/index.html.erb +0 -162
  177. data/app/views/knitkit/online_document_sections/index.html.erb +0 -279
  178. data/app/views/layouts/knitkit/online_document_sections.html.erb +0 -80
  179. data/app/views/website_inquiry_mailer/inquiry.erb +0 -24
  180. data/db/data_migrations/20120127150506_add_primary_host_to_website_configuration.rb +0 -33
  181. data/db/data_migrations/20120316150424_add_is_template_to_default_website_config.rb +0 -16
  182. data/db/data_migrations/20120809020508_update_website_and_configuration.rb +0 -82
  183. data/db/data_migrations/20121129185611_upgrade_website_role_iid.rb +0 -20
  184. data/db/migrate/20130405184234_add_use_markdown_to_section.rb +0 -19
  185. data/db/migrate/20131112013052_add_knitkit_missing_indexes.rb +0 -33
  186. data/db/migrate/20140622212723_update_website_inquiries.rb +0 -22
  187. data/db/migrate/20140911185022_add_publishing_to_website.rb +0 -5
  188. data/db/migrate/20141013073349_add_custom_fields_to_documents.rb +0 -12
  189. data/db/migrate/20141016101936_upgrade_remove_dynamic_attributes.rb +0 -13
  190. data/lib/knitkit/extensions/railties/theme_support/theme_file_resolver.rb +0 -49
  191. data/public/images/knitkit/close_window.png +0 -0
  192. data/public/images/knitkit/splash/splash.png +0 -0
  193. data/public/javascripts/erp_app/desktop/applications/knitkit/comments_grid_panel.js +0 -215
  194. data/public/javascripts/erp_app/desktop/applications/knitkit/select_roles_window.js +0 -108
  195. data/public/javascripts/erp_app/desktop/applications/knitkit/splash_screen.js +0 -170
  196. data/public/javascripts/knitkit/bootstrap-datepicker.js +0 -474
  197. data/public/javascripts/knitkit/bootstrap.min.js +0 -7
  198. data/public/javascripts/knitkit/mobile/app/view/Main.js +0 -108
  199. data/public/javascripts/knitkit/mobile/ux/slidenavigation/View.js +0 -734
  200. data/public/stylesheets/knitkit/bootstrap-responsive.min.css +0 -10
  201. data/public/stylesheets/knitkit/bootstrap.min.css +0 -7
  202. data/public/stylesheets/knitkit/custom.css +0 -122
  203. data/public/stylesheets/knitkit/datepicker.css +0 -182
@@ -1,3 +1,19 @@
1
+ # create_table :published_websites do |t|
2
+ # t.references :website
3
+ # t.text :comment
4
+ # t.decimal :version, :precision => 18, :scale => 6
5
+ # t.boolean :active
6
+ # t.integer :published_by_id
7
+ #
8
+ # t.timestamps
9
+ # end
10
+ #
11
+ # #indexes
12
+ # add_index :published_websites, :website_id
13
+ # add_index :published_websites, :version
14
+ # add_index :published_websites, :active
15
+ # add_index :published_websites, :published_by_id
16
+
1
17
  class PublishedWebsite < ActiveRecord::Base
2
18
  attr_protected :created_at, :updated_at
3
19
 
@@ -4,15 +4,17 @@ require 'fileutils'
4
4
  class Theme < ActiveRecord::Base
5
5
  attr_protected :created_at, :updated_at
6
6
 
7
- THEME_STRUCTURE = ['stylesheets', 'javascripts', 'images', 'templates']
7
+ THEME_STRUCTURE = ['stylesheets', 'javascripts', 'images', 'templates', 'fonts']
8
8
  class << self
9
9
  attr_accessor :base_layouts_views_path, :knitkit_website_stylesheets_path,
10
- :knitkit_website_images_path, :knitkit_website_javascripts_path
10
+ :knitkit_website_images_path, :knitkit_website_javascripts_path,
11
+ :knitkit_website_fonts_path
11
12
  end
12
13
  @base_layouts_views_path = "#{Knitkit::Engine.root.to_s}/app/views"
13
- @knitkit_website_stylesheets_path = "#{Knitkit::Engine.root.to_s}/public/stylesheets/knitkit"
14
- @knitkit_website_javascripts_path = "#{Knitkit::Engine.root.to_s}/public/javascripts/knitkit"
14
+ @knitkit_website_stylesheets_path = "#{Knitkit::Engine.root.to_s}/app/assets/stylesheets/knitkit"
15
+ @knitkit_website_javascripts_path = "#{Knitkit::Engine.root.to_s}/app/assets/javascripts/knitkit"
15
16
  @knitkit_website_images_path = "#{Knitkit::Engine.root.to_s}/public/images/knitkit"
17
+ @knitkit_website_fonts_path = "#{Knitkit::Engine.root.to_s}/app/assets/fonts/knitkit"
16
18
 
17
19
  protected_with_capabilities
18
20
  has_file_assets
@@ -39,12 +41,12 @@ class Theme < ActiveRecord::Base
39
41
  data = ''
40
42
  entry.get_input_stream { |io| data = io.read }
41
43
  data = StringIO.new(data) if data.present?
42
- theme_file = self.files.where("name = ? and directory = ?", File.basename(name), File.join(self.url,File.dirname(name))).first
44
+ theme_file = self.files.where("name = ? and directory = ?", File.basename(name), File.join(self.url, File.dirname(name))).first
43
45
  unless theme_file.nil?
44
46
  theme_file.data = data
45
47
  theme_file.save
46
48
  else
47
- self.add_file(data, File.join(file_support.root, self.url,name)) rescue next
49
+ self.add_file(data, File.join(file_support.root, self.url, name)) rescue next
48
50
  end
49
51
  end
50
52
  end
@@ -54,12 +56,12 @@ class Theme < ActiveRecord::Base
54
56
 
55
57
  class << self
56
58
  def import_download_item(tempfile, website)
57
- name_and_id = tempfile.gsub(/(^.*(\\|\/))|(\.zip$)/, '')
58
- theme_name = name_and_id.split('[').first
59
- theme_id = name_and_id.split('[').last.gsub(']','')
60
- Theme.create(:name => theme_name.sub(/-theme/, ''), :theme_id => theme_id, :website_id => website.id).tap do |theme|
61
- theme.import_download_item_file(tempfile)
62
- end
59
+ name_and_id = tempfile.gsub(/(^.*(\\|\/))|(\.zip$)/, '')
60
+ theme_name = name_and_id.split('[').first
61
+ theme_id = name_and_id.split('[').last.gsub(']', '')
62
+ Theme.create(:name => theme_name.sub(/-theme/, ''), :theme_id => theme_id, :website_id => website.id).tap do |theme|
63
+ theme.import_download_item_file(tempfile)
64
+ end
63
65
  end
64
66
 
65
67
 
@@ -77,7 +79,6 @@ class Theme < ActiveRecord::Base
77
79
  end
78
80
 
79
81
 
80
-
81
82
  def root_dir
82
83
  @@root_dir ||= "#{Rails.root}/public"
83
84
  end
@@ -89,11 +90,13 @@ class Theme < ActiveRecord::Base
89
90
  def import(file, website)
90
91
  name_and_id = file.original_filename.to_s.gsub(/(^.*(\\|\/))|(\.zip$)/, '')
91
92
  theme_name = name_and_id.split('[').first
92
- theme_id = name_and_id.split('[').last.gsub(']','')
93
+ theme_id = name_and_id.split('[').last.gsub(']', '')
93
94
  return false unless valid_theme?(file)
94
- Theme.create(:name => theme_name, :theme_id => theme_id, :website => website).tap do |theme|
95
+ theme = Theme.create(:name => theme_name, :theme_id => theme_id, :website => website).tap do |theme|
95
96
  theme.import(file)
96
97
  end
98
+
99
+ theme
97
100
  end
98
101
 
99
102
  def make_tmp_dir
@@ -119,6 +122,7 @@ class Theme < ActiveRecord::Base
119
122
 
120
123
  extend FriendlyId
121
124
  friendly_id :name, :use => [:slugged, :scoped], :slug_column => :theme_id, :scope => [:website_id]
125
+
122
126
  def should_generate_new_friendly_id?
123
127
  new_record?
124
128
  end
@@ -147,18 +151,18 @@ class Theme < ActiveRecord::Base
147
151
  def themed_widgets
148
152
  Rails.application.config.erp_app.widgets.select do |widget_hash|
149
153
  !(self.files.where("directory like '#{File.join(self.url, 'widgets', widget_hash[:name])}%'").all.empty?)
150
- end.collect{|item| item[:name]}
154
+ end.collect { |item| item[:name] }
151
155
  end
152
156
 
153
157
  def non_themed_widgets
154
158
  already_themed_widgets = self.themed_widgets
155
159
  Rails.application.config.erp_app.widgets.select do |widget_hash|
156
160
  !already_themed_widgets.include?(widget_hash[:name])
157
- end.collect{|item| item[:name]}
161
+ end.collect { |item| item[:name] }
158
162
  end
159
163
 
160
164
  def create_layouts_for_widget(widget)
161
- widget_hash = Rails.application.config.erp_app.widgets.find{|item| item[:name] == widget}
165
+ widget_hash = Rails.application.config.erp_app.widgets.find { |item| item[:name] == widget }
162
166
  widget_hash[:view_files].each do |view_file|
163
167
  save_theme_file(view_file[:path], :widgets, {:path_to_replace => view_file[:path].split('/views')[0], :widget_name => widget})
164
168
  end
@@ -193,17 +197,19 @@ class Theme < ActiveRecord::Base
193
197
  self.homepage = about['homepage'] if about['homepage']
194
198
  self.summary = about['summary'] if about['summary']
195
199
  else
196
- name = entry.name.sub(/__MACOSX\//, '')
197
- name = Theme.strip_path(name, theme_root)
198
- data = ''
199
- entry.get_input_stream { |io| data = io.read }
200
- data = StringIO.new(data) if data.present?
201
- theme_file = self.files.where("name = ? and directory = ?", File.basename(name), File.join(self.url,File.dirname(name))).first
202
- unless theme_file.nil?
203
- theme_file.data = data
204
- theme_file.save
205
- else
206
- self.add_file(data, File.join(file_support.root, self.url,name)) rescue next
200
+ if entry.file?
201
+ name = entry.name.sub(/__MACOSX\//, '')
202
+ name = Theme.strip_path(name, theme_root)
203
+ data = ''
204
+ entry.get_input_stream { |io| data = io.read }
205
+ data = StringIO.new(data) if data.present?
206
+ theme_file = self.files.where("name = ? and directory = ?", File.basename(name), File.join(self.url, File.dirname(name))).first
207
+ unless theme_file.nil?
208
+ theme_file.data = data
209
+ theme_file.save
210
+ else
211
+ self.add_file(data, File.join(file_support.root, self.url, name)) rescue next
212
+ end
207
213
  end
208
214
  end
209
215
  end
@@ -217,13 +223,13 @@ class Theme < ActiveRecord::Base
217
223
  (tmp_dir + "#{name}[#{theme_id}].zip").tap do |file_name|
218
224
  file_name.unlink if file_name.exist?
219
225
  Zip::ZipFile.open(file_name.to_s, Zip::ZipFile::CREATE) do |zip|
220
- files.each {|file|
221
- contents = file_support.get_contents(File.join(file_support.root,file.directory,file.name))
222
- relative_path = file.directory.sub("#{url}",'')
223
- path = FileUtils.mkdir_p(File.join(tmp_dir,relative_path))
224
- full_path = File.join(path,file.name)
225
- File.open(full_path, 'wb+') {|f| f.puts(contents) }
226
- zip.add(File.join(relative_path[1..relative_path.length],file.name), full_path) if ::File.exists?(full_path)
226
+ files.each { |file|
227
+ contents = file_support.get_contents(File.join(file_support.root, file.directory, file.name))
228
+ relative_path = file.directory.sub("#{url}", '')
229
+ path = FileUtils.mkdir_p(File.join(tmp_dir, relative_path))
230
+ full_path = File.join(path, file.name)
231
+ File.open(full_path, 'wb+') { |f| f.puts(contents) }
232
+ zip.add(File.join(relative_path[1..relative_path.length], file.name), full_path) if ::File.exists?(full_path)
227
233
  }
228
234
  ::File.open(tmp_dir + 'about.yml', 'wb+') { |f| f.puts(about.to_yaml) }
229
235
  zip.add('about.yml', tmp_dir + 'about.yml')
@@ -232,7 +238,7 @@ class Theme < ActiveRecord::Base
232
238
  end
233
239
 
234
240
  def has_template?(directory, name)
235
- self.templates.find{|item| item.directory == File.join(path,directory).gsub(Rails.root.to_s, '') and item.name == name}
241
+ self.templates.find { |item| item.directory == File.join(path, directory).gsub(Rails.root.to_s, '') and item.name == name }
236
242
  end
237
243
 
238
244
  class << self
@@ -269,7 +275,7 @@ class Theme < ActiveRecord::Base
269
275
 
270
276
  def delete_theme_files!
271
277
  file_support = ErpTechSvcs::FileSupport::Base.new(:storage => ErpTechSvcs::Config.file_storage)
272
- file_support.delete_file(File.join(file_support.root,self.url), :force => true)
278
+ file_support.delete_file(File.join(file_support.root, self.url), :force => true)
273
279
  end
274
280
 
275
281
  def create_theme_files!
@@ -278,40 +284,40 @@ class Theme < ActiveRecord::Base
278
284
  create_theme_files_for_directory_node(file_support.build_tree(Theme.knitkit_website_stylesheets_path, :preload => true), :stylesheets, :path_to_replace => Theme.knitkit_website_stylesheets_path)
279
285
  create_theme_files_for_directory_node(file_support.build_tree(Theme.knitkit_website_javascripts_path, :preload => true), :javascripts, :path_to_replace => Theme.knitkit_website_javascripts_path)
280
286
  create_theme_files_for_directory_node(file_support.build_tree(Theme.knitkit_website_images_path, :preload => true), :images, :path_to_replace => Theme.knitkit_website_images_path)
287
+ create_theme_files_for_directory_node(file_support.build_tree(Theme.knitkit_website_fonts_path, :preload => true), :fonts, :path_to_replace => Theme.knitkit_website_fonts_path)
281
288
  end
282
289
 
283
290
  private
284
291
 
285
292
  def create_theme_files_for_directory_node(node, type, options={})
286
- node[:children].each do |child_node|
287
- child_node[:leaf] ? save_theme_file(child_node[:id], type, options) : create_theme_files_for_directory_node(child_node, type, options)
293
+ if node
294
+ node[:children].each do |child_node|
295
+ child_node[:leaf] ? save_theme_file(child_node[:id], type, options) : create_theme_files_for_directory_node(child_node, type, options)
296
+ end
288
297
  end
289
298
  end
290
299
 
291
300
  def save_theme_file(path, type, options)
292
301
  ignored_css = [
293
302
  'bootstrap.min.css',
294
- 'bootstrap-responsive.min.css',
295
- 'datepicker.css',
296
303
  'inline_editing.css',
297
304
  ]
298
305
 
299
306
  ignored_js = [
307
+ 'additional-methods.min',
300
308
  'bootstrap.min.js',
301
- 'bootstrap-datepicker.js',
302
309
  'confirm-bootstrap.js',
303
310
  'inline_editing.js',
304
311
  'jquery.maskedinput.min.js',
305
- 'Main.js',
306
- 'View.js'
312
+ 'jquery.validate.min.js'
307
313
  ]
308
314
 
309
315
  ignored_files = (ignored_css | ignored_js).flatten
310
316
 
311
317
  unless ignored_files.any? { |w| path =~ /#{w}/ }
312
318
  contents = IO.read(path)
313
- contents.gsub!("<%= static_stylesheet_link_tag 'knitkit/custom.css' %>","<%= theme_stylesheet_link_tag '#{self.theme_id}','custom.css' %>") unless path.scan('base.html.erb').empty?
314
- contents.gsub!("<%= static_javascript_include_tag 'knitkit/theme.js' %>","<%= theme_javascript_include_tag '#{self.theme_id}','theme.js' %>") unless path.scan('base.html.erb').empty?
319
+ contents.gsub!("<%= stylesheet_link_tag 'knitkit/custom' %>", "<%= theme_stylesheet_link_tag '#{self.theme_id}','custom.css' %>") unless path.scan('base.html.erb').empty?
320
+ contents.gsub!("<%= javascript_include_tag 'knitkit/theme' %>", "<%= theme_javascript_include_tag '#{self.theme_id}','theme.js' %>") unless path.scan('base.html.erb').empty?
315
321
 
316
322
  path = case type
317
323
  when :widgets
@@ -1,8 +1,20 @@
1
+ # create_table :websites do |t|
2
+ # t.string :name
3
+ # t.string :title
4
+ # t.string :subtitle
5
+ # t.string :internal_identifier
6
+ # t.boolean :publishing, :default => false
7
+ #
8
+ # t.timestamps
9
+ # end
10
+ #
11
+ # add_index :websites, :internal_identifier, :name => 'websites_internal_identifier_idx'
12
+
1
13
  class Website < ActiveRecord::Base
2
14
  attr_protected :created_at, :updated_at
3
15
 
4
16
  after_destroy :remove_sites_directory, :remove_website_role
5
- before_destroy :destroy_sections
17
+ before_destroy :destroy_sections, :destroy_website_security_role, :destroy_website_party_roles
6
18
  after_create :setup_website
7
19
 
8
20
  protected_with_capabilities
@@ -67,6 +79,18 @@ class Website < ActiveRecord::Base
67
79
  parents.each { |parent| parent.destroy }
68
80
  end
69
81
 
82
+ def destroy_website_security_role
83
+ ActiveRecord::Base.connection.execute("delete from parties_security_roles where security_role_id = #{self.role.id}")
84
+ end
85
+
86
+ def destroy_website_party_roles
87
+ ActiveRecord::Base.connection.execute("delete from website_party_roles where website_id = #{self.id}")
88
+ end
89
+
90
+ def dba_organization
91
+ self.website_party_roles.where(role_type_id: RoleType.iid('dba_org')).first.party
92
+ end
93
+
70
94
  def publishing?
71
95
  self.publishing
72
96
  end
@@ -98,15 +122,6 @@ class Website < ActiveRecord::Base
98
122
  config_value('email_inquiries') == 'yes'
99
123
  end
100
124
 
101
- def self.find_by_host(host)
102
- website = nil
103
- unless host.nil?
104
- website_host = WebsiteHost.find_by_host(host)
105
- website = website_host.website unless website_host.nil?
106
- end
107
- website
108
- end
109
-
110
125
  def deactivate_themes!
111
126
  themes.each do |theme|
112
127
  theme.deactivate!
@@ -153,7 +168,12 @@ class Website < ActiveRecord::Base
153
168
 
154
169
  def setup_website
155
170
  PublishedWebsite.create(:website => self, :version => 0, :active => true, :comment => 'New Site Created')
156
- SecurityRole.create(:description => "Website #{self.title}", :internal_identifier => website_role_iid) if self.role.nil?
171
+
172
+ if self.role.nil?
173
+ website_role = SecurityRole.create(:description => "Website #{self.title}", :internal_identifier => website_role_iid)
174
+ website_role.move_to_child_of(SecurityRole.iid('website_builder'))
175
+ end
176
+
157
177
  configuration = ::Configuration.find_template('default_website_configuration').clone(true, "Website #{self.title} Configuration", "Website #{self.title} Configuration".underscore)
158
178
  configuration.update_configuration_item(ConfigurationItemType.find_by_internal_identifier('login_url'), '/login')
159
179
  configuration.update_configuration_item(ConfigurationItemType.find_by_internal_identifier('homepage_url'), '/home')
@@ -187,9 +207,18 @@ class Website < ActiveRecord::Base
187
207
  profile_page = nil
188
208
  widget_classes.each do |widget_class|
189
209
  website_section = WebsiteSection.new
190
- website_section.title = widget_class.title
191
- website_section.in_menu = true unless ["Login", "Sign Up", "Reset Password"].include?(widget_class.title)
192
- website_section.layout = widget_class.base_layout
210
+
211
+ # AE-194: Inline Search is active, so no need for search page, take search layout
212
+ # but change section name for the Search Results page
213
+ # and change layout so render widget to calls search action
214
+ website_section.in_menu = true unless ["Login", "Sign Up", "Reset Password", "Search"].include?(widget_class.title)
215
+ if widget_class.title == 'Search'
216
+ website_section.title = 'Search Results'
217
+ website_section.layout = widget_class.base_layout.gsub(":search", ":search, :action => 'search'")
218
+ else
219
+ website_section.title = widget_class.title
220
+ website_section.layout = widget_class.base_layout
221
+ end
193
222
  website_section.save
194
223
 
195
224
  profile_page = website_section if widget_class.title == 'Manage Profile'
@@ -211,7 +240,8 @@ class Website < ActiveRecord::Base
211
240
  :sections => [],
212
241
  :images => [],
213
242
  :files => [],
214
- :website_navs => []
243
+ :website_navs => [],
244
+ :members => []
215
245
  }
216
246
 
217
247
  #TODO update to handle configurations
@@ -235,6 +265,13 @@ class Website < ActiveRecord::Base
235
265
  setup_hash[:files] << {:path => file_asset.directory, :name => file_asset.name, :roles => file_asset.roles.uniq.collect { |r| r.internal_identifier }}
236
266
  end
237
267
 
268
+ # get all members of the website
269
+ self.website_party_roles.where('role_type_id = ?', RoleType.find_by_ancestor_iids(['website', 'member'])).each do |website_party_role|
270
+ party = website_party_role.party
271
+
272
+ setup_hash[:members] << party.user.username
273
+ end
274
+
238
275
  setup_hash
239
276
  end
240
277
 
@@ -329,9 +366,9 @@ class Website < ActiveRecord::Base
329
366
 
330
367
  def export_template
331
368
  tmp_dir = Website.make_tmp_dir
332
- template_zip_path = export
369
+ website_zip_path = export
333
370
 
334
- if !themes.active.first.is_a?(Theme)
371
+ unless themes.active.first.is_a?(Theme)
335
372
  return false
336
373
  end
337
374
 
@@ -340,36 +377,75 @@ class Website < ActiveRecord::Base
340
377
  zip_file_name = File.join(tmp_dir, self.iid + '-composite.zip')
341
378
 
342
379
  Zip::ZipFile.open(zip_file_name, Zip::ZipFile::CREATE) do |zip_file|
343
- zip_file.add(File.basename(template_zip_path, '.zip') + '-template.zip', template_zip_path)
380
+ zip_file.add(File.basename(website_zip_path, '.zip') + '-website.zip', website_zip_path)
344
381
  zip_file.add(File.basename(theme_zip_path, '.zip') + '-theme.zip', theme_zip_path)
345
382
  end
346
383
 
347
384
  File.join(tmp_dir, self.iid + '-composite.zip')
348
385
  end
349
386
 
387
+ def website_role_iid
388
+ "website_#{self.iid}_access"
389
+ end
390
+
391
+ def to_data_hash
392
+ to_hash(only: [:id, :name, :title, :subtitle,
393
+ :internal_identifier, :created_at, :updated_at])
394
+ end
395
+
350
396
  class << self
397
+
398
+ # Scope websites by passed dba_organization(s)
399
+ #
400
+ # @param dba_organization [Party, Array] Either a single dba_organization to scope by
401
+ # or an array of dba_organizations to scope by
402
+ # @return [ActiveRecord::Relation] Websites scope by ba_organization(s)
403
+ def scope_by_dba_organization(dba_organization)
404
+ joins(website_party_roles: [:party, :role_type])
405
+ .where(role_types: {internal_identifier: 'dba_org'})
406
+ .where(parties: {id: dba_organization})
407
+ end
408
+
409
+ def find_by_host(host)
410
+ website = nil
411
+ unless host.nil?
412
+ website_host = WebsiteHost.find_by_host(host)
413
+ website = website_host.website unless website_host.nil?
414
+ end
415
+ website
416
+ end
417
+
351
418
  def make_tmp_dir
352
419
  Pathname.new(File.join(Rails.root, "/tmp/website_export/tmp_#{Time.now.to_i.to_s}")).tap do |dir|
353
420
  FileUtils.mkdir_p(dir) unless dir.exist?
354
421
  end
355
422
  end
356
423
 
357
- def import(file, current_user)
424
+ def import(file_path, current_user)
358
425
  file_support = ErpTechSvcs::FileSupport::Base.new(:storage => Rails.application.config.erp_tech_svcs.file_storage)
359
426
  message = ''
360
427
  website = nil
361
428
 
362
- file = ActionController::UploadedTempfile.new("uploaded-theme").tap do |f|
363
- f.puts file.read
364
- f.original_filename = file.original_filename
365
- f.read # no idea why we need this here, otherwise the zip can't be opened
366
- end unless file.path
429
+ # if the path to the file is passed just use it else get the path from
430
+ # the File object that was passed
431
+ unless file_path.is_a?(String)
432
+ if file_path.path
433
+ file_path = file_path.path
434
+ else
435
+ file = ActionController::UploadedTempfile.new("uploaded-website").tap do |f|
436
+ f.puts file_path.read
437
+ f.original_filename = file_path.original_filename
438
+ f.read # no idea why we need this here, otherwise the zip can't be opened
439
+ end
440
+ file_path = file.path
441
+ end
442
+ end
367
443
 
368
444
  entries = []
369
445
  setup_hash = nil
370
446
 
371
447
  tmp_dir = Website.make_tmp_dir
372
- Zip::ZipFile.open(file.path) do |zip|
448
+ Zip::ZipFile.open(file_path) do |zip|
373
449
  zip.each do |entry|
374
450
  f_path = File.join(tmp_dir.to_s, entry.name)
375
451
  FileUtils.mkdir_p(File.dirname(f_path))
@@ -417,13 +493,6 @@ class Website < ActiveRecord::Base
417
493
 
418
494
  begin
419
495
  #handle images
420
- # entries.each do |entry|
421
- # puts "entry type '#{entry[:type]}'"
422
- # puts "entry name '#{entry[:name]}'"
423
- # puts "entry path '#{entry[:path]}'"
424
- # puts "entry data #{!entry[:data].blank?}"
425
- # end
426
- # puts "------------------"
427
496
  setup_hash[:images].each do |image_asset|
428
497
  filename = 'images' + image_asset[:path] + '/' + image_asset[:name]
429
498
  #puts "image_asset '#{filename}'"
@@ -433,10 +502,29 @@ class Website < ActiveRecord::Base
433
502
  end
434
503
  end
435
504
 
505
+ if setup_hash[:members]
506
+ #handle members
507
+ website_role_type_parent = RoleType.find_or_create('website', 'Website')
508
+ website_member_role = RoleType.find_or_create('member', 'Member', website_role_type_parent)
509
+
510
+ setup_hash[:members].each do |member|
511
+ user = User.find_by_username(member)
512
+
513
+ if user
514
+ # add website security role to user
515
+ user.add_role(website.role)
516
+
517
+ # create website_party_role for this user as a member of the site
518
+ WebsitePartyRole.create(party: user.party, website: website, role_type: website_member_role)
519
+
520
+ user.save
521
+ end
522
+ end
523
+ end
524
+
436
525
  #handle files
437
526
  setup_hash[:files].each do |file_asset|
438
527
  filename = 'files' + file_asset[:path] + '/' + file_asset[:name]
439
- #puts "file_asset '#{filename}'"
440
528
  content = entries.find { |entry| entry[:type] == 'files' and entry[:path] == filename }
441
529
  unless content.nil?
442
530
  file = website.add_file(content[:data], File.join(file_support.root, file_asset[:path], file_asset[:name]))
@@ -488,6 +576,11 @@ class Website < ActiveRecord::Base
488
576
  end
489
577
 
490
578
  website.save
579
+
580
+ # set the currents users dba_org as the dba_org for this website
581
+ WebsitePartyRole.create(website: website,
582
+ party: current_user.party.dba_organization,
583
+ role_type: RoleType.iid('dba_org'))
491
584
  else
492
585
  message = 'Website already exists with that internal_identifier'
493
586
  end
@@ -495,177 +588,64 @@ class Website < ActiveRecord::Base
495
588
  return website, message
496
589
  end
497
590
 
498
- def import_template_director(file, current_user)
499
- file_object = file.tempfile
500
- file_path = file_object.path
591
+ def import_template(file, current_user)
592
+ file = ActionController::UploadedTempfile.new("uploaded-template").tap do |f|
593
+ f.puts file.read
594
+ f.original_filename = file.original_filename
595
+ f.read # no idea why we need this here, otherwise the zip can't be opened
596
+ end unless file.path
597
+
598
+ result = {website: nil, theme: nil, success: false}
501
599
 
502
600
  entries = []
503
601
  begin
504
- Zip::ZipFile.open(file_path) { |zip_file|
505
- zip_file.each { |f|
506
- f_path=File.join('public/waste', f.name)
602
+ Zip::ZipFile.open(file.path) do |zip_file|
603
+ zip_file.each do |f|
604
+ f_path = File.join('tmp/template_import', f.name)
507
605
  FileUtils.mkdir_p(File.dirname(f_path))
508
606
  zip_file.extract(f, f_path) unless File.exist?(f_path)
509
- entries << f.name
510
- }
511
- }
512
-
513
- entries.each do |entry|
514
- if entry.match(/-template.zip/)
515
- @website_result = import_template('public/waste/' + entry, current_user)
607
+ entries << {name: f.name, path: f_path}
516
608
  end
517
609
  end
610
+
518
611
  entries.each do |entry|
519
- if entry.match(/-theme.zip/)
520
- Theme.import_download_item('public/waste/' + entry, @website_result[0])
612
+ if entry[:name].match(/-website.zip/)
613
+ result[:website], result[:message] = import(entry[:path], current_user)
521
614
  end
522
615
  end
523
- return @website_result[0], @website_result[1]
524
- rescue Exception => e
525
- return false, "Error"
526
- end
527
- end
528
616
 
529
- def import_template(file, current_user)
530
- file_support = ErpTechSvcs::FileSupport::Base.new(:storage => Rails.application.config.erp_tech_svcs.file_storage)
531
- message = ''
532
- website = nil
533
-
534
- entries = []
535
- setup_hash = nil
536
-
537
- tmp_dir = Website.make_tmp_dir
538
-
539
- Zip::ZipFile.open(file) do |zip|#passing in a file
540
- #Zip::ZipFile.open(file.path) do |zip|
541
- zip.each do |entry|
542
- f_path = File.join(tmp_dir.to_s, entry.name)
543
- FileUtils.mkdir_p(File.dirname(f_path))
544
- zip.extract(entry, f_path) unless File.exist?(f_path)
545
-
546
- next if entry.name =~ /__MACOSX\//
547
- if entry.name =~ /setup.yml/
548
- data = ''
549
- entry.get_input_stream { |io| data = io.read }
550
- data = StringIO.new(data) if data.present?
551
- setup_hash = YAML.load(data)
552
- else
553
- type = entry.name.split('/')[0]
554
- name = entry.name.split('/').last
555
- next if name.nil?
556
-
557
- if File.exist?(f_path) and !File.directory?(f_path)
558
- entry_hash = {:type => type, :name => name, :path => entry.name}
559
- entries << entry_hash unless name == 'sections' || name == 'articles' || name == 'excerpts' || name == 'documented contents'
560
- entry_hash[:data] = File.open(f_path, "rb") { |io| io.read }
617
+ if result[:website]
618
+ entries.each do |entry|
619
+ if entry[:name].match(/-theme.zip/)
620
+ result[:theme] = Theme.import(entry[:path], result[:website], true)
561
621
  end
562
622
  end
563
-
623
+ else
624
+ raise result[:message]
564
625
  end
565
- end
566
- entries.uniq!
567
- FileUtils.rm_rf(tmp_dir.to_s)
568
626
 
569
- if Website.find_by_internal_identifier(setup_hash[:internal_identifier]).nil?
570
- website = Website.new(
571
- :name => setup_hash[:name],
572
- :title => setup_hash[:title],
573
- :subtitle => setup_hash[:subtitle],
574
- :internal_identifier => setup_hash[:internal_identifier]
575
- )
576
-
577
- #TODO update to handle configurations
578
-
579
- website.save!
580
-
581
- #set default publication published by user
582
- first_publication = website.published_websites.first
583
- first_publication.published_by = current_user
584
- first_publication.save
585
-
586
- begin
587
- #handle images
588
- # entries.each do |entry|
589
- # puts "entry type '#{entry[:type]}'"
590
- # puts "entry name '#{entry[:name]}'"
591
- # puts "entry path '#{entry[:path]}'"
592
- # puts "entry data #{!entry[:data].blank?}"
593
- # end
594
- # puts "------------------"
595
- setup_hash[:images].each do |image_asset|
596
- filename = 'images' + image_asset[:path] + '/' + image_asset[:name]
597
- #puts "image_asset '#{filename}'"
598
- content = entries.find { |entry| entry[:type] == 'images' and entry[:path] == filename }
599
- unless content.nil?
600
- website.add_file(content[:data], File.join(file_support.root, image_asset[:path], image_asset[:name]))
601
- end
602
- end
603
-
604
- #handle files
605
- setup_hash[:files].each do |file_asset|
606
- filename = 'files' + file_asset[:path] + '/' + file_asset[:name]
607
- #puts "file_asset '#{filename}'"
608
- content = entries.find { |entry| entry[:type] == 'files' and entry[:path] == filename }
609
- unless content.nil?
610
- file = website.add_file(content[:data], File.join(file_support.root, file_asset[:path], file_asset[:name]))
611
-
612
- #handle security
613
- unless file_asset[:roles].empty?
614
- capability = file.add_capability(:download)
615
- file_asset[:roles].each do |role_iid|
616
- role = SecurityRole.find_by_internal_identifier(role_iid)
617
- role.add_capability(capability)
618
- end
619
- end
620
- end
621
- end
622
-
623
- #handle hosts
624
- if WebsiteHost.last
625
- setup_hash.merge(:hosts => 'localhost:3000')
626
- end
627
+ FileUtils.rm_rf('tmp/template_import')
627
628
 
628
- if !setup_hash[:hosts].blank? and !setup_hash[:hosts].empty?
629
- #set first host as primary host in configuration
630
- website.configurations.first.update_configuration_item(ConfigurationItemType.find_by_internal_identifier('primary_host'), 'localhost:3000')
631
- website.save
632
- end
633
-
634
- #handle sections
635
- setup_hash[:sections].each do |section_hash|
636
- build_section(section_hash, entries, website, current_user)
637
- end
638
- website.website_sections.update_paths!
639
-
640
- #handle website_navs
641
- setup_hash[:website_navs].each do |website_nav_hash|
642
- website_nav = WebsiteNav.new(:name => website_nav_hash[:name])
643
- website_nav_hash[:items].each do |item|
644
- website_nav.website_nav_items << build_menu_item(item)
645
- end
646
- website.website_navs << website_nav
647
- end
648
-
649
- website.publish("Website Imported", current_user)
629
+ result[:success] = true
630
+ rescue Exception => e
631
+ Rails.logger.error(e.message)
632
+ Rails.logger.error(e.backtrace.join("\n"))
650
633
 
651
- rescue Exception => ex
652
- Rails.logger.error "#{ex.inspect} #{ex.backtrace}"
653
- website.destroy unless website.nil?
654
- raise ex
634
+ if result[:website]
635
+ result[:website].destroy
636
+ result[:website] = nil
655
637
  end
656
638
 
657
- website.save
658
- else
659
- message = 'Website already exists with that internal_identifier'
639
+ result[:message] = 'Error importing theme'
640
+ result[:success] = false
660
641
  end
661
642
 
662
- return website, message
643
+ result
663
644
  end
664
645
 
665
-
666
646
  def find_site_entry_in_zip(file)
667
647
  zf = Zip::ZipFile.open(file)
668
- zf.each_with_index { |entry, index|
648
+ zf.each_with_index { |entry, index|
669
649
  if entry.name.match(/-template.zip/) && !entry.name.match(/_./)
670
650
  return entry
671
651
  end
@@ -675,7 +655,7 @@ class Website < ActiveRecord::Base
675
655
  def find_theme_entries_in_zip(file)
676
656
  entries = []
677
657
  zf = Zip::ZipFile.new(file)
678
- zf.each_with_index { |entry, index|
658
+ zf.each_with_index { |entry, index|
679
659
  if entry.name.match(/-theme.zip/) && !entry.name.match(/_./)
680
660
  entries << entry
681
661
  end
@@ -683,10 +663,8 @@ class Website < ActiveRecord::Base
683
663
  entries
684
664
  end
685
665
 
686
-
687
666
  protected
688
667
 
689
-
690
668
  def build_menu_item(hash)
691
669
  website_item = WebsiteNavItem.new(
692
670
  :title => hash[:title],
@@ -718,17 +696,20 @@ class Website < ActiveRecord::Base
718
696
  klass = hash[:type].constantize
719
697
  section = klass.new(:title => hash[:name],
720
698
  :in_menu => hash[:in_menu],
721
- :render_base_layout => hash[:render_base_layout],
722
699
  :position => hash[:position],
723
700
  :render_base_layout => hash[:render_base_layout])
724
701
  section.internal_identifier = hash[:internal_identifier]
725
- section.permalink = hash[:permalink]
726
- section.path = hash[:path]
727
702
  content = entries.find do |entry|
728
703
  entry[:type] == 'sections' and entry[:name] == "#{hash[:permalink]}.rhtml" and entry[:path].split('.')[0] == "sections#{hash[:path]}"
729
704
  end
730
705
 
731
706
  section.layout = content[:data] unless content.nil?
707
+ section.save
708
+
709
+ # force the update of permalink and path
710
+ section.permalink = hash[:permalink]
711
+ section.path = hash[:path]
712
+ section.save
732
713
 
733
714
  hash[:articles].each do |article_hash|
734
715
  article = Article.find_by_internal_identifier(article_hash[:internal_identifier])
@@ -741,13 +722,17 @@ class Website < ActiveRecord::Base
741
722
  unless content.nil?
742
723
  article.excerpt_html = content[:data]
743
724
  end
725
+
726
+ # set the currents users dba_org as the dba_org for this content
727
+ article.add_party_with_role(current_user.party.dba_organization,
728
+ RoleType.iid('dba_org'))
744
729
  end
745
730
  section.contents << article
746
- section.save
747
731
  article.update_content_area_and_position_by_section(section, article_hash[:content_area], article_hash[:position])
748
732
  end
749
733
  website.website_sections << section
750
- section.save
734
+ website.save
735
+
751
736
  if hash[:sections]
752
737
  hash[:sections].each do |section_hash|
753
738
  child_section = build_section(section_hash, entries, website, current_user)
@@ -793,10 +778,6 @@ class Website < ActiveRecord::Base
793
778
  section
794
779
  end
795
780
 
796
-
797
781
  end
798
782
 
799
- def website_role_iid
800
- "website_#{self.iid}_access"
801
- end
802
783
  end