knitkit 2.0.5 → 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/app/controllers/knitkit/erp_app/desktop/app_controller.rb +5 -8
  2. data/app/controllers/knitkit/erp_app/desktop/articles_controller.rb +11 -8
  3. data/app/controllers/knitkit/erp_app/desktop/content_controller.rb +26 -4
  4. data/app/controllers/knitkit/erp_app/desktop/file_assets_controller.rb +49 -35
  5. data/app/controllers/knitkit/erp_app/desktop/image_assets_controller.rb +30 -21
  6. data/app/controllers/knitkit/erp_app/desktop/theme_controller.rb +41 -32
  7. data/app/controllers/knitkit/erp_app/desktop/website_controller.rb +0 -6
  8. data/app/controllers/knitkit/erp_app/desktop/website_section_controller.rb +42 -6
  9. data/app/{models → mailers}/website_inquiry_mailer.rb +0 -0
  10. data/app/models/article.rb +4 -0
  11. data/app/models/content.rb +0 -4
  12. data/app/models/theme.rb +3 -3
  13. data/app/models/website.rb +44 -17
  14. data/app/views/knitkit/website_sections/index.html.erb +1 -1
  15. data/app/views/layouts/knitkit/base.html.erb +6 -0
  16. data/app/views/shared/knitkit/_footer.html.erb +2 -2
  17. data/app/widgets/signup/base.rb +0 -2
  18. data/db/data_migrations/20120809020508_update_website_and_configuration.rb +77 -0
  19. data/lib/knitkit/engine.rb +4 -0
  20. data/lib/knitkit/extensions.rb +4 -1
  21. data/lib/knitkit/extensions/action_controller/theme_support/acts_as_themed_controller.rb +36 -33
  22. data/lib/knitkit/extensions/action_mailer/theme_support/acts_as_themed_mailer.rb +60 -0
  23. data/lib/knitkit/extensions/active_record/acts_as_commentable.rb +9 -4
  24. data/lib/knitkit/extensions/active_record/acts_as_document.rb +1 -1
  25. data/lib/knitkit/extensions/compass_ae/widgets/base.rb +21 -1
  26. data/lib/knitkit/extensions/compass_ae/widgets/widget_proxy_controller.rb +26 -0
  27. data/lib/knitkit/extensions/railties/action_view/base.rb +11 -0
  28. data/lib/knitkit/extensions/railties/action_view/helpers/blog_helper.rb +62 -0
  29. data/lib/knitkit/extensions/railties/action_view/helpers/content_helper.rb +83 -0
  30. data/lib/knitkit/extensions/railties/action_view/helpers/knitkit_helper.rb +67 -0
  31. data/lib/knitkit/extensions/railties/action_view/helpers/menu_helper.rb +71 -0
  32. data/lib/knitkit/version.rb +1 -1
  33. data/public/images/knitkit/close.png +0 -0
  34. data/public/javascripts/erp_app/desktop/applications/knitkit/articles_grid_panel.js +150 -400
  35. data/public/javascripts/erp_app/desktop/applications/knitkit/center_region.js +687 -593
  36. data/public/javascripts/erp_app/desktop/applications/knitkit/east_region.js +1 -2
  37. data/public/javascripts/erp_app/desktop/applications/knitkit/file_assets_panel.js +39 -15
  38. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_data_view.js +1 -1
  39. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_panel.js +65 -126
  40. data/public/javascripts/erp_app/desktop/applications/knitkit/module.js +65 -1
  41. data/public/javascripts/erp_app/desktop/applications/knitkit/section_articles_grid_panel.js +265 -183
  42. data/public/javascripts/erp_app/desktop/applications/knitkit/themes_tree_panel.js +24 -9
  43. data/public/javascripts/erp_app/desktop/applications/knitkit/versions_grid_panel.js +631 -595
  44. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/document.js +265 -0
  45. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/host.js +133 -0
  46. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/menu.js +174 -0
  47. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/section.js +399 -0
  48. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/website.js +165 -0
  49. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/helpers/website_nav_items.js +266 -0
  50. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region/west_region.js +1224 -0
  51. data/public/javascripts/knitkit/inline_editing.js +136 -0
  52. data/public/stylesheets/extjs/resources/css/knitkit_extjs_4.css +1 -2
  53. data/public/stylesheets/knitkit/inline_editing.css +88 -0
  54. data/public/stylesheets/knitkit/style.css +1 -1
  55. metadata +47 -31
  56. data/lib/knitkit/extensions/railties/action_view.rb +0 -199
  57. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region.js +0 -2725
@@ -0,0 +1,60 @@
1
+ module Knitkit
2
+ module Extensions
3
+ module ActionMailer
4
+ module ThemeSupport
5
+ class Cache
6
+ cattr_accessor :theme_resolvers
7
+ end
8
+ module ActsAsThemedMailer
9
+ def self.included(base)
10
+ base.class_eval do
11
+ extend ActMacro
12
+ end
13
+ end
14
+
15
+ module ActMacro
16
+ def acts_as_themed_mailer
17
+ include InstanceMethods
18
+ end
19
+ end
20
+
21
+ module InstanceMethods
22
+ def add_theme_view_paths(website)
23
+ ThemeSupport::Cache.theme_resolvers = [] if ThemeSupport::Cache.theme_resolvers.nil?
24
+ current_theme_paths(website).each do |theme|
25
+ resolver = case Rails.application.config.erp_tech_svcs.file_storage
26
+ when :s3
27
+ path = File.join(theme[:url], "templates")
28
+ cached_resolver = ThemeSupport::Cache.theme_resolvers.find { |cached_resolver| cached_resolver.to_path == path }
29
+ if cached_resolver.nil?
30
+ resolver = ActionView::S3Resolver.new(path)
31
+ ThemeSupport::Cache.theme_resolvers << resolver
32
+ resolver
33
+ else
34
+ cached_resolver
35
+ end
36
+ when :filesystem
37
+ path = "#{theme[:path]}/templates"
38
+ cached_resolver = ThemeSupport::Cache.theme_resolvers.find { |cached_resolver| cached_resolver.to_path == path }
39
+ if cached_resolver.nil?
40
+ resolver = ActionView::ThemeFileResolver.new(path)
41
+ ThemeSupport::Cache.theme_resolvers << resolver
42
+ resolver
43
+ else
44
+ cached_resolver
45
+ end
46
+ end
47
+ prepend_view_path(resolver)
48
+ end
49
+ end
50
+
51
+ def current_theme_paths(website)
52
+ website.themes.active.map { |theme| {:path => theme.path.to_s, :url => theme.url.to_s} }
53
+ end
54
+
55
+ end #InstanceMethods
56
+ end #ActsAsThemedMailer
57
+ end #ThemeSupport
58
+ end #ActionMailer
59
+ end #Extensions
60
+ end #Knitkit
@@ -21,8 +21,13 @@ module Knitkit
21
21
  end
22
22
 
23
23
  module InstanceMethods
24
+
25
+ def add_comment(options={})
26
+ self.comments.create(options)
27
+ end
28
+
24
29
  end
25
- end
26
- end
27
- end
28
- end
30
+ end #ActsAsCommentable
31
+ end #ActiveRecord
32
+ end #Extensions
33
+ end #Knitkit
@@ -50,7 +50,7 @@ module Knitkit
50
50
  end
51
51
 
52
52
  def initialize_document
53
- if (self.document.nil?)
53
+ if self.new_record? and self.document.nil?
54
54
  self.document = Document.new
55
55
  self.document.document_record = self
56
56
  end
@@ -4,7 +4,8 @@
4
4
  paths = widget[:view_paths]
5
5
 
6
6
  website.themes.active.map{ |theme| {:path => theme.path.to_s, :url => theme.url.to_s}}.each do |theme|
7
- paths << File.join(theme[:url],'widgets',self.widget_name,'views')
7
+ path = File.join(theme[:path],'widgets',self.widget_name,'views')
8
+ paths << path unless paths.include?(path)
8
9
  end if website
9
10
 
10
11
  paths.reverse!
@@ -14,6 +15,25 @@
14
15
  end
15
16
 
16
17
  ::ErpApp::Widgets::Base.class_eval do
18
+ #adding ability to pass website
19
+ def initialize(proxy_controller=nil, name=nil, view=nil, uuid=nil, widget_params=nil, passed_website=nil)
20
+ ErpApp::Widgets::Base.view_resolver_cache = [] if ErpApp::Widgets::Base.view_resolver_cache.nil?
21
+ self.name = name
22
+ self.proxy_controller = proxy_controller
23
+ self.view = view
24
+ self.uuid = uuid
25
+ self.widget_params = widget_params
26
+ @website = passed_website
27
+ add_view_paths
28
+ store_widget_params
29
+ merge_params
30
+ end
31
+
32
+ #adding ability to get website
33
+ def website
34
+ @website
35
+ end
36
+
17
37
  private
18
38
 
19
39
  def add_view_paths
@@ -0,0 +1,26 @@
1
+ ErpApp::WidgetProxyController.class_eval do
2
+ attr_accessor :performed_redirect
3
+ before_filter :set_website
4
+
5
+ def index
6
+ @widget_name = params[:widget_name]
7
+ @widget_action = params[:widget_action]
8
+ @uuid = params[:uuid]
9
+
10
+ #get widget params
11
+ widget_params = nil
12
+ widget_params = JSON.parse(params[:widget_params]) unless params[:widget_params].blank?
13
+
14
+ widget_obj = "::Widgets::#{@widget_name.camelize}::Base".constantize.new(self, @widget_name, @widget_action, @uuid, widget_params, @website)
15
+
16
+ result = widget_obj.process(@widget_action)
17
+ result.nil? ? return : (render result)
18
+ end
19
+
20
+ protected
21
+ #setting website to pass to widgets
22
+ def set_website
23
+ @website = Website.find_by_host(request.host_with_port)
24
+ end
25
+
26
+ end
@@ -0,0 +1,11 @@
1
+ #require all ActionView helper files
2
+ Dir.entries(File.join(File.dirname(__FILE__),"helpers")).delete_if{|name| name =~ /^\./}.each do |file|
3
+ require "knitkit/extensions/railties/action_view/helpers/#{file}"
4
+ end
5
+
6
+ ActionView::Base.class_eval do
7
+ include Knitkit::Extensions::Railties::ActionView::Helpers::BlogHelper
8
+ include Knitkit::Extensions::Railties::ActionView::Helpers::ContentHelper
9
+ include Knitkit::Extensions::Railties::ActionView::Helpers::MenuHelper
10
+ include Knitkit::Extensions::Railties::ActionView::Helpers::KnitkitHelper
11
+ end
@@ -0,0 +1,62 @@
1
+ module Knitkit
2
+ module Extensions
3
+ module Railties
4
+ module ActionView
5
+ module Helpers
6
+ module BlogHelper
7
+
8
+ def blog_add_comment_form
9
+ render :partial => 'add_comment' unless current_user.nil?
10
+ end
11
+
12
+ def blog_topics(css_class='tag_link')
13
+ html = ''
14
+
15
+ @website_section.get_topics.each do |tag|
16
+ html += '<div class="'+css_class+'">'
17
+ html += link_to(tag.name, main_app.blog_tag_path(@website_section.id, tag.id))
18
+ html += '</div>'
19
+ end
20
+
21
+ raw html
22
+ end
23
+
24
+ def blog_rss_links(link_title='RSS Feed')
25
+ if params[:action] == 'tag'
26
+ return link_to link_title, main_app.blog_tag_url(params[:section_id], params[:tag_id], :rss)
27
+ else
28
+ return link_to link_title, main_app.blogs_url(params[:section_id], :rss)
29
+ end
30
+ end
31
+
32
+ def blog_recent_approved_comments
33
+ if @published_content.content.comments.recent.approved.empty?
34
+ return 'No Comments'
35
+ else
36
+ html = ''
37
+
38
+ @published_content.content.comments.recent.approved.each do |comment|
39
+ html += render :partial => 'comment', :locals => {:comment => comment}
40
+ end
41
+
42
+ return raw html
43
+ end
44
+ end
45
+
46
+ def blog_pagination(css_class, params)
47
+ return will_paginate @contents, :class => css_class, :params => {
48
+ :section_id => params[:section_id],
49
+ :per_page => params[:per_page],
50
+ :format => params[:format],
51
+ :only_path => true,
52
+ :use_route => params[:use_route],
53
+ :scope => main_app
54
+ }
55
+ end
56
+
57
+ end #BlogHelper
58
+ end #Helpers
59
+ end #ActionView
60
+ end #Railties
61
+ end #Extensions
62
+ end #Knitkit
@@ -0,0 +1,83 @@
1
+ module Knitkit
2
+ module Extensions
3
+ module Railties
4
+ module ActionView
5
+ module Helpers
6
+ module ContentHelper
7
+
8
+ def setup_inline_editing
9
+ if can_inline_edit?
10
+ raw "<script type='text/javascript'>
11
+ jQuery(document).ready(function() {
12
+ Knitkit.InlineEditing.setup(#{@website.id});
13
+ });
14
+ </script>"
15
+ end
16
+ end
17
+
18
+ def render_editable_content(content_version, additional_css_classes=[])
19
+ raw "<div class='knitkit_content #{additional_css_classes.join(' ')}'
20
+ contentid='#{content_version.content.id}'
21
+ lastupdate='#{content_version.content.updated_at.strftime("%m/%d/%Y %I:%M%p")}'>#{content_version.body_html}</div>"
22
+ end
23
+
24
+ # render a piece of content by internal identifier regardless if it belongs to a section or not
25
+ def render_content(iid)
26
+ content = Content.find_by_internal_identifier(iid)
27
+ content_version = Content.get_published_version(@active_publication, content) unless @active_publication.nil?
28
+ content_version = content if @active_publication.nil? or content_version.nil?
29
+
30
+ if content_version.nil?
31
+ ''
32
+ else
33
+ raw "<div class='knitkit_content'
34
+ contentid='#{content.id}'
35
+ lastupdate='#{content_version.content.updated_at.strftime("%m/%d/%Y %I:%M%p")}'>
36
+ #{(content_version.body_html.nil? ? '' : content_version.body_html)}</div>"
37
+ end
38
+ end
39
+
40
+ def render_content_area(name)
41
+ html = ''
42
+
43
+ section_contents = WebsiteSectionContent.includes(:content)
44
+ .where(:website_section_id => @website_section.id, :content_area => name.to_s)
45
+ .order(:position).all
46
+ published_contents = []
47
+ section_contents.each do |sc|
48
+ content_version = Content.get_published_version(@active_publication, sc.content)
49
+ published_contents << content_version unless content_version.nil?
50
+ end
51
+
52
+ published_contents.each do |content|
53
+ html << "<div class='knitkit_content'
54
+ contentid='#{content.content.id}'
55
+ lastupdate='#{content.updated_at.strftime("%m/%d/%Y %I:%M%p")}'>
56
+ #{(content.body_html.nil? ? '' : content.body_html)}</div>"
57
+
58
+ end
59
+
60
+ raw html
61
+ end
62
+
63
+ private
64
+
65
+ def can_inline_edit?
66
+ result = false
67
+ model = DesktopApplication.find_by_internal_identifier('knitkit')
68
+ unless ((current_user.nil? or current_user === false))
69
+ if ((current_user.has_capability?(model, 'edit_html', 'Article') rescue false))
70
+ if (@website.configurations.first.get_configuration_item(:auto_active_publications).options.first.value == 'yes' and @website.configurations.first.get_configuration_item(:publish_on_save).options.first.value == 'yes')
71
+ result = true
72
+ end #make sure auto acitvate and publish on save our set
73
+ end #make sure they have this capability
74
+ end #check for user
75
+ result
76
+ end
77
+
78
+ end #ContentHelper
79
+ end #Helpers
80
+ end #ActionView
81
+ end #Railties
82
+ end #Extensions
83
+ end #Knitkit
@@ -0,0 +1,67 @@
1
+ module Knitkit
2
+ module Extensions
3
+ module Railties
4
+ module ActionView
5
+ module Helpers
6
+ module KnitkitHelper
7
+
8
+ def published_content_created_by
9
+ "by #{@published_content.content.created_by.username}" rescue ''
10
+ end
11
+
12
+ def render_version_viewing
13
+ html = ''
14
+
15
+ if !session[:website_version].blank? && !session[:website_version].empty?
16
+ site_version_hash = session[:website_version].find{|item| item[:website_id] == @website.id}
17
+ unless site_version_hash.nil?
18
+ if site_version_hash[:version].to_f != @website.active_publication.version
19
+ html = "<div style='float:left;'>Viewing version #{site_version_hash[:version].to_f} <a href='/view_current_publication'>View current publication</a></div>"
20
+ end
21
+ end
22
+ end
23
+
24
+ raw html
25
+ end
26
+
27
+ #options
28
+ #nothing
29
+ # - uses current page to lookup section and go up tree
30
+ #menu
31
+ # - menu to look for menu title in
32
+ #menu_item
33
+ # - title of menu_item to start breadcrumbs at
34
+ #section_unique_name
35
+ # - sections permalink to start breadcrumbs at
36
+ def build_crumbs(options={})
37
+ links = []
38
+ if options[:menu]
39
+ menu = WebsiteNav.find_by_name(options[:menu])
40
+ raise "Menu with name #{options[:menu]} does not exist" if menu.nil?
41
+ menu_item = menu.website_nav_items.find(:first, :conditions => ["title = ?", options[:menu_item]])
42
+ raise "Menu Item with Title #{options[:menu]} does not exist" if menu_item.nil?
43
+ links = menu_item.self_and_ancestors.map{|child| {:url => child.path, :title => child.title}}
44
+ elsif options[:section_unique_name]
45
+ section = WebsiteSection.find_by_internal_identifier(options[:section_unique_name])
46
+ raise "Website Section with that unique name does not exist" if section.nil?
47
+ links = section.self_and_ancestors.map{|child| {:url => child.path, :title => child.title}}
48
+ else
49
+ links = @website_section.self_and_ancestors.collect{|child| {:url => child.path, :title => child.title}}
50
+ end
51
+ links
52
+
53
+ render :partial => 'shared/knitkit/bread_crumb', :locals => {:links => links}
54
+ end
55
+
56
+
57
+ def tool_tip(message, img_src=nil)
58
+ img_src = img_src || '/images/knitkit/tooltip.gif'
59
+ raw "<a href='#' class='tooltip'>&nbsp;<img src='#{img_src}' alt='ToolTip' /><span>#{message}</span></a>"
60
+ end
61
+
62
+ end #KnitkitHelper
63
+ end #Helpers
64
+ end #ActionView
65
+ end #Railties
66
+ end #Extensions
67
+ end #Knitkit
@@ -0,0 +1,71 @@
1
+ module Knitkit
2
+ module Extensions
3
+ module Railties
4
+ module ActionView
5
+ module Helpers
6
+ module MenuHelper
7
+
8
+ def menu_item_selected(menu_item)
9
+ result = false
10
+ result = request.path == menu_item.path
11
+ unless result
12
+ menu_item.descendants.each do |child|
13
+ result = request.path == child.path
14
+ break if result
15
+ end
16
+ end
17
+ result
18
+ end
19
+
20
+ #options
21
+ #menu
22
+ # - use a designed layout not sections
23
+ #layout
24
+ # - use defined layout
25
+ def render_menu(contents, options={})
26
+ locals = {:contents => contents}
27
+ if options[:menu]
28
+ menu = WebsiteNav.find_by_name_and_website_id(options[:menu], @website.id)
29
+ raise "Menu with name #{options[:menu]} does not exist" if menu.nil?
30
+ layout = options[:layout] ? "menus/#{options[:layout]}" : "menus/knitkit/default_menu"
31
+ locals[:menu_items] = menu.website_nav_items.positioned
32
+ else
33
+ layout = options[:layout] ? "menus/#{options[:layout]}" : "menus/knitkit/default_section_menu"
34
+ end
35
+
36
+ render :partial => layout, :locals => locals
37
+ end
38
+
39
+ #options
40
+ #menu
41
+ # - use a designed layout not sections
42
+ #menu_item
43
+ # - menu item title to start at
44
+ #section_unique_name
45
+ # - section to begin at
46
+ #layout
47
+ # - use defined layout
48
+ def render_sub_menu(contents, options={})
49
+ locals = {:contents => contents}
50
+ if options[:menu]
51
+ menu = WebsiteNav.find_by_name_and_website_id(options[:menu], @website.id)
52
+ raise "Menu with name #{options[:menu]} does not exist" if menu.nil?
53
+ locals[:menu_items] = (options[:menu_item].nil? ? menu.all_menu_items.find{|item| menu_item_selected(item)}.positioned_children : menu.all_menu_items.find{|item| item.title = options[:menu_item]}.positioned_children)
54
+ raise "No menu items exist" if locals[:menu_items].nil?
55
+ layout = options[:layout] ? "menus/#{options[:layout]}" : "menus/knitkit/default_sub_menu"
56
+ else
57
+ section = options[:section_unique_name].nil? ? @website_section : WebsiteSection.find_by_internal_identifier(options[:section_unique_name])
58
+ raise "No website sections exist" if section.nil?
59
+ locals[:section] = section
60
+ layout = options[:layout] ? "menus/#{options[:layout]}" : "menus/knitkit/default_sub_section_menu"
61
+ end
62
+
63
+ render :partial => layout, :locals => locals
64
+ end
65
+
66
+ end #MenuHelper
67
+ end #Helpers
68
+ end #ActionView
69
+ end #Railties
70
+ end #Extensions
71
+ end #Knitkit