knitkit 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. data/GPL-3-LICENSE +674 -0
  2. data/README.md +6 -0
  3. data/Rakefile +30 -0
  4. data/app/assets/javascripts/knitkit/application.js +9 -0
  5. data/app/assets/stylesheets/knitkit/application.css +7 -0
  6. data/app/controllers/knitkit/articles_controller.rb +7 -0
  7. data/app/controllers/knitkit/base_controller.rb +45 -0
  8. data/app/controllers/knitkit/blogs_controller.rb +27 -0
  9. data/app/controllers/knitkit/comments_controller.rb +18 -0
  10. data/app/controllers/knitkit/erp_app/desktop/app_controller.rb +135 -0
  11. data/app/controllers/knitkit/erp_app/desktop/articles_controller.rb +144 -0
  12. data/app/controllers/knitkit/erp_app/desktop/comments_controller.rb +43 -0
  13. data/app/controllers/knitkit/erp_app/desktop/content_controller.rb +27 -0
  14. data/app/controllers/knitkit/erp_app/desktop/file_assets_controller.rb +145 -0
  15. data/app/controllers/knitkit/erp_app/desktop/image_assets_controller.rb +28 -0
  16. data/app/controllers/knitkit/erp_app/desktop/inquiries_controller.rb +68 -0
  17. data/app/controllers/knitkit/erp_app/desktop/position_controller.rb +20 -0
  18. data/app/controllers/knitkit/erp_app/desktop/theme_controller.rb +272 -0
  19. data/app/controllers/knitkit/erp_app/desktop/versions_controller.rb +135 -0
  20. data/app/controllers/knitkit/erp_app/desktop/website_controller.rb +177 -0
  21. data/app/controllers/knitkit/erp_app/desktop/website_nav_controller.rb +143 -0
  22. data/app/controllers/knitkit/erp_app/desktop/website_section_controller.rb +116 -0
  23. data/app/controllers/knitkit/unauthorized_controller.rb +8 -0
  24. data/app/controllers/knitkit/website_sections_controller.rb +17 -0
  25. data/app/helpers/application_helper.rb +132 -0
  26. data/app/models/article.rb +14 -0
  27. data/app/models/blog.rb +21 -0
  28. data/app/models/comment.rb +24 -0
  29. data/app/models/content.rb +158 -0
  30. data/app/models/extensions/user.rb +5 -0
  31. data/app/models/published_element.rb +9 -0
  32. data/app/models/published_website.rb +118 -0
  33. data/app/models/theme.rb +239 -0
  34. data/app/models/website.rb +457 -0
  35. data/app/models/website_host.rb +3 -0
  36. data/app/models/website_inquiry.rb +11 -0
  37. data/app/models/website_inquiry_mailer.rb +12 -0
  38. data/app/models/website_nav.rb +17 -0
  39. data/app/models/website_nav_item.rb +21 -0
  40. data/app/models/website_section.rb +152 -0
  41. data/app/models/website_section_content.rb +4 -0
  42. data/app/views/knitkit/articles/index.html.erb +3 -0
  43. data/app/views/knitkit/articles/show.html.erb +4 -0
  44. data/app/views/knitkit/blogs/_add_comment.html.erb +28 -0
  45. data/app/views/knitkit/blogs/_comment.html.erb +8 -0
  46. data/app/views/knitkit/blogs/index.html.erb +51 -0
  47. data/app/views/knitkit/blogs/index.rss.builder +23 -0
  48. data/app/views/knitkit/blogs/show.html.erb +22 -0
  49. data/app/views/knitkit/unauthorized/index.html.erb +4 -0
  50. data/app/views/knitkit/website_sections/index.html.erb +6 -0
  51. data/app/views/layouts/knitkit/base.html.erb +59 -0
  52. data/app/views/menus/knitkit/_default_menu.html.erb +23 -0
  53. data/app/views/menus/knitkit/_default_section_menu.html.erb +27 -0
  54. data/app/views/menus/knitkit/_default_sub_menu.html.erb +45 -0
  55. data/app/views/menus/knitkit/_default_sub_section_menu.html.erb +49 -0
  56. data/app/views/shared/knitkit/_bread_crumb.html.erb +7 -0
  57. data/app/views/shared/knitkit/_footer.html.erb +3 -0
  58. data/app/views/website_inquiry_mailer/inquiry.erb +3 -0
  59. data/app/widgets/contact_us/base.rb +86 -0
  60. data/app/widgets/contact_us/javascript/contact_us.js +13 -0
  61. data/app/widgets/contact_us/views/_contact_form.html.erb +36 -0
  62. data/app/widgets/contact_us/views/error.html.erb +10 -0
  63. data/app/widgets/contact_us/views/index.html.erb +1 -0
  64. data/app/widgets/contact_us/views/layouts/base.html.erb +7 -0
  65. data/app/widgets/contact_us/views/success.html.erb +4 -0
  66. data/app/widgets/google_map/base.rb +48 -0
  67. data/app/widgets/google_map/javascript/google_map.js +174 -0
  68. data/app/widgets/google_map/views/index.html.erb +41 -0
  69. data/app/widgets/login/base.rb +61 -0
  70. data/app/widgets/login/javascript/login.js +162 -0
  71. data/app/widgets/login/views/index.html.erb +37 -0
  72. data/app/widgets/login/views/layouts/base.html.erb +14 -0
  73. data/app/widgets/login/views/login_header.html.erb +9 -0
  74. data/app/widgets/login/views/reset_password.html.erb +26 -0
  75. data/app/widgets/manage_profile/base.rb +327 -0
  76. data/app/widgets/manage_profile/javascript/manage_profile.js +11 -0
  77. data/app/widgets/manage_profile/views/_contact_information_form.html.erb +180 -0
  78. data/app/widgets/manage_profile/views/_password_form.html.erb +20 -0
  79. data/app/widgets/manage_profile/views/_user_information_form.html.erb +30 -0
  80. data/app/widgets/manage_profile/views/contact_type_in_use.html.erb +4 -0
  81. data/app/widgets/manage_profile/views/default_type_error.html.erb +5 -0
  82. data/app/widgets/manage_profile/views/error.html.erb +3 -0
  83. data/app/widgets/manage_profile/views/index.html.erb +46 -0
  84. data/app/widgets/manage_profile/views/layouts/base.html.erb +1 -0
  85. data/app/widgets/manage_profile/views/password_blank.html.erb +4 -0
  86. data/app/widgets/manage_profile/views/password_invalid.html.erb +4 -0
  87. data/app/widgets/manage_profile/views/password_success.html.erb +3 -0
  88. data/app/widgets/manage_profile/views/success.html.erb +3 -0
  89. data/app/widgets/reset_password/base.rb +42 -0
  90. data/app/widgets/reset_password/javascript/reset_password.js +13 -0
  91. data/app/widgets/reset_password/views/index.html.erb +31 -0
  92. data/app/widgets/reset_password/views/layouts/base.html.erb +1 -0
  93. data/app/widgets/search/base.rb +80 -0
  94. data/app/widgets/search/javascript/search.js +31 -0
  95. data/app/widgets/search/views/_search.html.erb +39 -0
  96. data/app/widgets/search/views/index.html.erb +3 -0
  97. data/app/widgets/search/views/layouts/base.html.erb +24 -0
  98. data/app/widgets/search/views/show.html.erb +48 -0
  99. data/app/widgets/signup/base.rb +72 -0
  100. data/app/widgets/signup/javascript/signup.js +13 -0
  101. data/app/widgets/signup/views/_signup_form.html.erb +36 -0
  102. data/app/widgets/signup/views/error.html.erb +11 -0
  103. data/app/widgets/signup/views/index.html.erb +1 -0
  104. data/app/widgets/signup/views/layouts/base.html.erb +7 -0
  105. data/app/widgets/signup/views/success.html.erb +4 -0
  106. data/config/environment.rb +0 -0
  107. data/config/routes.rb +41 -0
  108. data/db/data_migrations/20110509223702_add_publisher_role.rb +11 -0
  109. data/db/data_migrations/20110816153456_add_knitkit_application.rb +31 -0
  110. data/db/data_migrations/upgrade/20111011203718_create_paths_for_sections.rb +13 -0
  111. data/db/data_migrations/upgrade/20111216192114_add_secured_models_to_menu_items.rb +18 -0
  112. data/db/data_migrations/upgrade/20111216202819_set_contents_iid_to_permalink_where_null.rb +12 -0
  113. data/db/migrate/20110211002317_setup_knitkit.rb +259 -0
  114. data/db/migrate/upgrade/20111014190442_update_contents.rb +25 -0
  115. data/db/migrate/upgrade/20111014201502_add_published_by_to_published_elements.rb +22 -0
  116. data/db/migrate/upgrade/20111017133851_add_iid_to_section.rb +21 -0
  117. data/db/migrate/upgrade/20111027145006_add_in_menu_to_section.rb +19 -0
  118. data/lib/knitkit.rb +12 -0
  119. data/lib/knitkit/engine.rb +26 -0
  120. data/lib/knitkit/extensions.rb +18 -0
  121. data/lib/knitkit/extensions/action_controller/theme_support/acts_as_themed_controller.rb +88 -0
  122. data/lib/knitkit/extensions/active_record/acts_as_commentable.rb +28 -0
  123. data/lib/knitkit/extensions/active_record/acts_as_publishable.rb +38 -0
  124. data/lib/knitkit/extensions/active_record/theme_support/has_many_themes.rb +34 -0
  125. data/lib/knitkit/extensions/compass/widgets/base.rb +53 -0
  126. data/lib/knitkit/extensions/core/array.rb +5 -0
  127. data/lib/knitkit/extensions/railties/action_view.rb +187 -0
  128. data/lib/knitkit/extensions/railties/theme_support/asset_tag_helper.rb +198 -0
  129. data/lib/knitkit/extensions/railties/theme_support/theme_file_resolver.rb +44 -0
  130. data/lib/knitkit/routing_filter/section_router.rb +55 -0
  131. data/lib/knitkit/syntax_validator.rb +32 -0
  132. data/lib/knitkit/version.rb +3 -0
  133. data/lib/tasks/knitkit_tasks.rake +4 -0
  134. data/public/images/knitkit/bullet.png +0 -0
  135. data/public/images/knitkit/content.png +0 -0
  136. data/public/images/knitkit/footer.png +0 -0
  137. data/public/images/knitkit/graphic.png +0 -0
  138. data/public/images/knitkit/greyFadeDown.png +0 -0
  139. data/public/images/knitkit/link.png +0 -0
  140. data/public/images/knitkit/logo.png +0 -0
  141. data/public/images/knitkit/menu.png +0 -0
  142. data/public/images/knitkit/menu_select.png +0 -0
  143. data/public/images/knitkit/search.png +0 -0
  144. data/public/javascripts/datepicker.js +440 -0
  145. data/public/javascripts/erp_app/desktop/applications/knitkit/articles_grid_panel.js +473 -0
  146. data/public/javascripts/erp_app/desktop/applications/knitkit/center_region.js +576 -0
  147. data/public/javascripts/erp_app/desktop/applications/knitkit/comments_grid_panel.js +217 -0
  148. data/public/javascripts/erp_app/desktop/applications/knitkit/east_region.js +26 -0
  149. data/public/javascripts/erp_app/desktop/applications/knitkit/file_assets_panel.js +109 -0
  150. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_data_view.js +30 -0
  151. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_panel.js +160 -0
  152. data/public/javascripts/erp_app/desktop/applications/knitkit/inquiries_grid_panel.js +46 -0
  153. data/public/javascripts/erp_app/desktop/applications/knitkit/module.js +46 -0
  154. data/public/javascripts/erp_app/desktop/applications/knitkit/publish_window.js +92 -0
  155. data/public/javascripts/erp_app/desktop/applications/knitkit/published_grid_panel.js +220 -0
  156. data/public/javascripts/erp_app/desktop/applications/knitkit/section_articles_grid_panel.js +613 -0
  157. data/public/javascripts/erp_app/desktop/applications/knitkit/themes_tree_panel.js +573 -0
  158. data/public/javascripts/erp_app/desktop/applications/knitkit/versions_grid_panel.js +664 -0
  159. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region.js +2161 -0
  160. data/public/javascripts/erp_app/desktop/applications/knitkit/widgets_panel.js +52 -0
  161. data/public/stylesheets/datepicker.css +121 -0
  162. data/public/stylesheets/erp_app/desktop/applications/knitkit/knitkit.css +114 -0
  163. data/public/stylesheets/extjs/resources/css/knitkit_extjs_4.css +219 -0
  164. data/public/stylesheets/knitkit/style.css +394 -0
  165. metadata +289 -0
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ #Knitkit CMS
2
+
3
+ Knitkit is an application that sits on top of the Compass AE framework that adds a fully functional CMS to Compass AE. It integrates with Amazon S3 and has extensions for our <a href="https://github.com/portablemind/Erp-Modules">Erp Modules</a>.
4
+
5
+ ![Logo](http://development.compassagile.com/sites/site-1/images/knitkit.png?1323038265)
6
+
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Knitkit'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require "rspec/core/rake_task"
29
+ RSpec::Core::RakeTask.new(:spec)
30
+ task :default => :spec
@@ -0,0 +1,9 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require jquery
8
+ //= require jquery_ujs
9
+ //= require_tree .
@@ -0,0 +1,7 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require_tree .
7
+ */
@@ -0,0 +1,7 @@
1
+ module Knitkit
2
+ class ArticlesController < BaseController
3
+ def index
4
+ @contents = Article.find_by_section_id(@website_section.id)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,45 @@
1
+ module Knitkit
2
+ class BaseController < ::ErpApp::ApplicationController
3
+ before_filter :set_website
4
+ before_filter :set_active_publication, :load_sections, :set_section, :except => [:view_current_publication]
5
+ acts_as_themed_controller :current_themes => lambda {|c| c.website.themes.active if c.website }
6
+
7
+ layout 'knitkit/base'
8
+
9
+ def website
10
+ @website
11
+ end
12
+
13
+ def view_current_publication
14
+ session[:website_version].delete_if{|item| item[:website_id] == @website.id}
15
+ redirect_to request.env["HTTP_REFERER"]
16
+ end
17
+
18
+ protected
19
+ def set_website
20
+ @website = Website.find_by_host(request.host_with_port)
21
+ end
22
+
23
+ def load_sections
24
+ @website_sections = @website.website_sections.positioned
25
+ end
26
+
27
+ def set_section
28
+ unless params[:section_id].nil?
29
+ @website_section = WebsiteSection.find(params[:section_id])
30
+ else
31
+ raise "No Id set"
32
+ end
33
+ end
34
+
35
+ def set_active_publication
36
+ @active_publication = @website.active_publication
37
+ if !session[:website_version].blank? && !session[:website_version].empty?
38
+ site_version_hash = session[:website_version].find{|item| item[:website_id] == @website.id}
39
+ unless site_version_hash.nil?
40
+ @active_publication = @website.published_websites.where('version = ?', site_version_hash[:version].to_f).first
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,27 @@
1
+ module Knitkit
2
+ class BlogsController < ArticlesController
3
+ PER_PAGE = 10
4
+
5
+ def index
6
+ @blog = Blog.find(params[:section_id])
7
+ params[:use_route] = 'blogs'
8
+
9
+ @contents = @blog.find_published_blog_posts(@active_publication).paginate(:page => params[:page], :per_page => PER_PAGE)
10
+ end
11
+
12
+ def tag
13
+ @blog = Blog.find(params[:section_id])
14
+ @tag = ActsAsTaggableOn::Tag.find(params[:tag_id])
15
+ params[:use_route] = 'blog_tag'
16
+
17
+ @contents = @blog.find_published_blog_posts_with_tag(@active_publication, @tag).paginate(:page => params[:page], :per_page => PER_PAGE)
18
+
19
+ render :index
20
+ end
21
+
22
+ def show
23
+ @blog = Blog.find(params[:section_id])
24
+ @published_content = @blog.find_published_blog_post(@active_publication, params[:id])
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ module Knitkit
2
+ class CommentsController < BaseController
3
+ def add
4
+ user = current_user
5
+ content = Content.find(params[:content_id])
6
+ comment = params[:comment]
7
+
8
+ @comment = content.add_comment({:commentor_name => user.party.description, :email => user.email, :comment => comment})
9
+
10
+ render :text => (@comment.valid? ? '<div class="sexysuccess">Comment pending approval.</span>' : '<div class="sexyerror">Error. Comment cannot be blank.</span>')
11
+ end
12
+
13
+ #no section to set
14
+ def set_section
15
+ return false
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,135 @@
1
+ module Knitkit
2
+ module ErpApp
3
+ module Desktop
4
+ class AppController < ::ErpApp::Desktop::BaseController
5
+ KNIT_KIT_ROOT = Knitkit::Engine.root.to_s
6
+
7
+ def websites
8
+ websites = Website.all
9
+
10
+ tree = []
11
+
12
+ websites.each do |website|
13
+ website_hash = {
14
+ :text => website.name,
15
+ :iconCls => 'icon-globe_disconnected',
16
+ :id => "website_#{website.id}",
17
+ :leaf => false,
18
+ :url => "http://#{website.hosts.first.attributes['host']}",
19
+ :name => website.name,
20
+ :title => website.title,
21
+ :subtitle => website.subtitle,
22
+ :isWebsite => true,
23
+ :email => website.email,
24
+ :siteName => website.name,
25
+ :emailInquiries => website.email_inquiries?,
26
+ :autoActivatePublication => website.auto_activate_publication?,
27
+ :children => []
28
+ }
29
+
30
+ #handle hosts
31
+ hosts_hash = {:text => 'Hosts', :iconCls => 'icon-gear', :isHostRoot => true, :websiteId => website.id, :leaf => false, :children => []}
32
+ website.hosts.each do |website_host|
33
+ hosts_hash[:children] << {:text => website_host.attributes['host'], :websiteHostId => website_host.id, :host => website_host.attributes['host'], :iconCls => 'icon-globe', :url => "http://#{website_host.attributes['host']}", :isHost => true, :leaf => true, :children => []}
34
+ end
35
+
36
+ website_hash[:children] << hosts_hash
37
+
38
+ #handle sections
39
+ sections_hash = {:text => 'Sections', :isSectionRoot => true, :websiteId => website.id, :iconCls => 'icon-content', :leaf => false, :children => []}
40
+ website.website_sections.positioned.each do |website_section|
41
+ sections_hash[:children] << build_section_hash(website_section, website)
42
+ end
43
+
44
+ website_hash[:children] << sections_hash
45
+
46
+
47
+ #handle menus
48
+ menus_hash = {:text => 'Menus', :iconCls => 'icon-content', :isMenuRoot => true, :websiteId => website.id, :leaf => false, :children => []}
49
+ website.website_navs.each do |website_nav|
50
+ menu_hash = {:text => website_nav.name, :websiteNavId => website_nav.id, :websiteId => website.id, :canAddMenuItems => true, :iconCls => 'icon-index', :isWebsiteNav => true, :leaf => false, :children => []}
51
+ menu_hash[:children] = website_nav.website_nav_items.positioned.map{|item|build_menu_item_hash(website, item)}
52
+ menus_hash[:children] << menu_hash
53
+ end
54
+
55
+ website_hash[:children] << menus_hash
56
+
57
+ #added website to main tree
58
+ tree << website_hash
59
+ end
60
+
61
+ render :json => tree
62
+ end
63
+
64
+ protected
65
+
66
+ def page
67
+ offset = params[:start].to_f
68
+ offset > 0 ? ((offset / params[:limit].to_f).to_i + 1) : 1
69
+ end
70
+
71
+ def per_page
72
+ params[:limit].nil? ? 20 : params[:limit].to_i
73
+ end
74
+
75
+ def build_menu_item_hash(website, item)
76
+ url = item.url
77
+ linked_to_item_id = nil
78
+ link_to_type = 'url'
79
+ unless item.linked_to_item.nil?
80
+ linked_to_item_id = item.linked_to_item_id
81
+ link_to_type = item.linked_to_item.class.to_s.underscore
82
+ url = "http://#{website.hosts.first.attributes['host']}" + item.linked_to_item.path
83
+ end
84
+
85
+ menu_item_hash = {
86
+ :text => item.title,
87
+ :linkToType => link_to_type,
88
+ :canAddMenuItems => true,
89
+ :websiteId => website.id,
90
+ :isSecured => !item.roles.empty?,
91
+ :linkedToId => linked_to_item_id,
92
+ :websiteNavItemId => item.id,
93
+ :url => url,
94
+ :iconCls => 'icon-document',
95
+ :isWebsiteNavItem => true,
96
+ :leaf => false
97
+ }
98
+
99
+ menu_item_hash[:children] = item.positioned_children.map{ |child| build_menu_item_hash(website, child)}
100
+
101
+ menu_item_hash
102
+ end
103
+
104
+ def build_section_hash(website_section, website)
105
+ website_section_hash = {
106
+ :text => website_section.title,
107
+ :siteName => website.name,
108
+ :siteId => website.id,
109
+ :type => website_section.type,
110
+ :isSecured => !website_section.roles.empty?,
111
+ :isSection => true,
112
+ :inMenu => website_section.in_menu,
113
+ :hasLayout => !website_section.layout.blank?,
114
+ :id => "section_#{website_section.id}",
115
+ :url => "http://#{website.hosts.first.attributes['host']}#{website_section.path}",
116
+ :internal_identifier => website_section.internal_identifier
117
+ }
118
+
119
+ if website_section.is_a?(Blog) || website_section.type == 'Blog'
120
+ website_section_hash[:isBlog] = true
121
+ website_section_hash[:iconCls] = 'icon-blog'
122
+ website_section_hash[:leaf] = true
123
+ else
124
+ website_section_hash[:leaf] = false
125
+ website_section_hash[:children] = website_section.positioned_children.map {|child| build_section_hash(child, website)}
126
+ website_section_hash[:isSecured] ? website_section_hash[:iconCls] = 'icon-document_lock' : website_section_hash[:iconCls] = 'icon-document'
127
+ end
128
+
129
+ website_section_hash
130
+ end
131
+
132
+ end#AppController
133
+ end#Desktop
134
+ end#ErpApp
135
+ end#Knitkit
@@ -0,0 +1,144 @@
1
+ module Knitkit
2
+ module ErpApp
3
+ module Desktop
4
+ class ArticlesController < Knitkit::ErpApp::Desktop::AppController
5
+
6
+ def new
7
+ result = {}
8
+ website_section_id = params[:section_id]
9
+ article = Article.new
10
+
11
+ article.tag_list = params[:tags].split(',').collect{|t| t.strip() } unless params[:tags].blank?
12
+ article.title = params[:title]
13
+ article.internal_identifier = params[:internal_identifier]
14
+ article.display_title = params[:display_title] == 'yes'
15
+ article.created_by = current_user
16
+
17
+ if article.save
18
+ unless website_section_id.blank?
19
+ website_section = WebsiteSection.find(website_section_id)
20
+ article.website_sections << website_section
21
+ article.update_content_area_and_position_by_section(website_section, params['content_area'], params['position'])
22
+ end
23
+
24
+ result[:success] = true
25
+ else
26
+ result[:success] = false
27
+ end
28
+
29
+
30
+ render :json => result
31
+ end
32
+
33
+ def update
34
+ result = {}
35
+ website_section_id = params[:section_id]
36
+ article = Article.find(params[:id])
37
+
38
+ article.tag_list = params[:tags].split(',').collect{|t| t.strip() } unless params[:tags].blank?
39
+ article.title = params[:title]
40
+ article.internal_identifier = params[:internal_identifier]
41
+ article.display_title = params[:display_title] == 'yes'
42
+ article.updated_by = current_user
43
+
44
+ if article.save
45
+ unless website_section_id.blank?
46
+ website_section = WebsiteSection.find(website_section_id)
47
+ article.update_content_area_and_position_by_section(website_section, params['content_area'], params['position'])
48
+ end
49
+
50
+ result[:success] = true
51
+ else
52
+ result[:success] = false
53
+ end
54
+
55
+ render :json => result
56
+ end
57
+
58
+ def delete
59
+ render :json => Article.destroy(params[:id]) ? {:success => true} : {:success => false}
60
+ end
61
+
62
+ def add_existing
63
+ website_section = WebsiteSection.find(params[:section_id])
64
+ website_section.contents << Article.find(params[:article_id])
65
+
66
+ render :json => {:success => true}
67
+ end
68
+
69
+ def existing_articles
70
+ render :inline => Article.all.to_json(:only => [:internal_identifier, :id])
71
+ end
72
+
73
+ def get
74
+ sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
75
+ sort = sort_hash[:property] || 'created_at'
76
+ dir = sort_hash[:direction] || 'DESC'
77
+ limit = params[:limit] || 10
78
+ start = params[:start] || 0
79
+
80
+ website_section_id = params[:section_id]
81
+ articles = Article.joins("INNER JOIN website_section_contents ON website_section_contents.content_id = contents.id").where("website_section_id = #{website_section_id}").order("contents.#{sort} #{dir}").limit(limit).offset(start)
82
+ total_count = Article.joins("INNER JOIN website_section_contents ON website_section_contents.content_id = contents.id").where("website_section_id = #{website_section_id}").count
83
+
84
+ Article.class_exec(website_section_id) do
85
+ @@website_section_id = website_section_id
86
+ def website_section_position
87
+ self.website_section_contents.find_by_website_section_id(@@website_section_id).position
88
+ end
89
+ end
90
+
91
+ articles_array = []
92
+ articles.each do |a|
93
+ articles_hash = {}
94
+ articles_hash[:content_area] = a.content_area_by_website_section(WebsiteSection.find(website_section_id))
95
+ articles_hash[:id] = a.id
96
+ articles_hash[:title] = a.title
97
+ articles_hash[:tag_list] = a.tag_list.join(', ')
98
+ articles_hash[:body_html] = a.body_html
99
+ articles_hash[:excerpt_html] = a.excerpt_html
100
+ articles_hash[:internal_identifier] = a.internal_identifier
101
+ articles_hash[:display_title] = a.display_title
102
+ articles_hash[:position] = a.position(website_section_id)
103
+ articles_array << articles_hash
104
+ end
105
+
106
+ render :inline => "{totalCount:#{total_count},data:#{articles_array.to_json(:only => [:content_area, :id, :title, :tag_list, :body_html, :excerpt_html, :position, :internal_identifier, :display_title], :methods => [:website_section_position])}}"
107
+ end
108
+
109
+ def all
110
+ Article.include_root_in_json = false
111
+ sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
112
+ sort = sort_hash[:property] || 'created_at'
113
+ dir = sort_hash[:direction] || 'DESC'
114
+ limit = params[:limit] || 40
115
+ start = params[:start] || 0
116
+
117
+ articles = params[:iid].blank? ? Article.order( "contents.#{sort} #{dir}").limit(limit).offset(start).all : Article.where('internal_identifier like ?', "%#{params[:iid]}%").order("contents.#{sort} #{dir}").limit(limit).offset(start)
118
+ total_count = Article.all.count
119
+
120
+ articles_array = []
121
+ articles.each do |a|
122
+ articles_hash = {}
123
+ articles_hash[:id] = a.id
124
+ articles_hash[:sections] = a.website_sections.collect{|section| section.title}.join(',')
125
+ articles_hash[:title] = a.title
126
+ articles_hash[:tag_list] = a.tag_list.join(', ')
127
+ articles_hash[:body_html] = a.body_html
128
+ articles_hash[:internal_identifier] = a.internal_identifier
129
+ articles_hash[:display_title] = a.display_title
130
+ articles_hash[:excerpt_html] = a.excerpt_html
131
+ articles_hash[:created_by] = a.created_by.login rescue ''
132
+ articles_hash[:last_update_by] = a.updated_by.login rescue ''
133
+
134
+ articles_array << articles_hash
135
+ end
136
+
137
+ render :inline => "{totalCount:#{total_count},data:#{articles_array.to_json(:only => [:content_area, :id, :title, :tag_list, :body_html, :excerpt_html, :sections, :internal_identifier, :display_title, :created_by, :last_update_by])}}"
138
+ end
139
+
140
+ end#ArticlesController
141
+ end#Desktop
142
+ end#ErpApp
143
+ end#Knitkit
144
+
@@ -0,0 +1,43 @@
1
+ module Knitkit
2
+ module ErpApp
3
+ module Desktop
4
+ class CommentsController < Knitkit::ErpApp::Desktop::AppController
5
+
6
+ def index
7
+ content = Content.find(params[:content_id])
8
+ sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
9
+ sort = sort_hash[:property] || 'created_at'
10
+ dir = sort_hash[:direction] || 'DESC'
11
+ limit = params[:limit] || 10
12
+ start = params[:start] || 0
13
+
14
+ Comment.class_eval do
15
+ def approved_by_username
16
+ approved_by.nil? ? '' : approved_by.username
17
+ end
18
+ end
19
+
20
+ #limit and offset are not working rails issue?
21
+ comments = content.comments.order("#{sort} #{dir}").offset(start).limit(limit)
22
+
23
+ render :inline => "{totalCount:#{comments.count}, comments:#{comments.to_json(:methods => [:approved?, :approved_by_username])}}"
24
+ end
25
+
26
+ def approve
27
+ comment = Comment.find(params[:id])
28
+ comment.approve(current_user)
29
+
30
+ render :json => {:success => true}
31
+ end
32
+
33
+ def delete
34
+ comment = Comment.find(params[:id])
35
+ comment.destroy
36
+
37
+ render :json => {:success => true}
38
+ end
39
+
40
+ end#CommentsController
41
+ end#Desktop
42
+ end#ErpApp
43
+ end#Knitkit