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
@@ -0,0 +1,135 @@
1
+ module Knitkit
2
+ module ErpApp
3
+ module Desktop
4
+ class VersionsController < Knitkit::ErpApp::Desktop::AppController
5
+ #content
6
+
7
+ def content_versions
8
+ content = Content.find(params[:id])
9
+ website = Website.find(params[:site_id])
10
+ sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
11
+ sort = sort_hash[:property] || 'version'
12
+ dir = sort_hash[:direction] || 'DESC'
13
+ limit = params[:limit] || 15
14
+ start = params[:start] || 0
15
+
16
+ versions = content.versions.order("#{sort} #{dir}").offset(start).limit(limit)
17
+
18
+ Content::Version.class_exec(website) do
19
+ cattr_accessor :website
20
+ self.website = website
21
+ def active
22
+ published_site_id = self.website.active_publication.id
23
+ !PublishedElement.includes([:published_website]).where('published_websites.id = ? and published_element_record_id = ? and published_element_record_type = ? and published_elements.version = ?', published_site_id, self.content_id, 'Content', self.version).first.nil?
24
+ end
25
+
26
+ def published_element
27
+ PublishedElement.where('published_element_record_id = ? and published_element_record_type = ? and published_elements.version = ?', self.content_id, 'Content', self.version).first
28
+ end
29
+
30
+ def published
31
+ !published_element.nil?
32
+ end
33
+
34
+ def publisher
35
+ published_element.published_by_username if published
36
+ end
37
+ end
38
+
39
+ render :inline => "{\"totalCount\":#{content.versions.count},data:#{versions.to_json(
40
+ :only => [:id, :version, :title, :body_html, :excerpt_html, :updated_at],
41
+ :methods => [:active, :published, :publisher])}}"
42
+ end
43
+
44
+ def non_published_content_versions
45
+ content = Content.find(params[:id])
46
+ sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
47
+ sort = sort_hash[:property] || 'version'
48
+ dir = sort_hash[:direction] || 'DESC'
49
+ limit = params[:limit] || 15
50
+ start = params[:start] || 0
51
+
52
+ versions = content.versions.order("#{sort} #{dir}").offset(start).limit(limit)
53
+
54
+ render :inline => "{\"totalCount\":#{content.versions.count},data:#{versions.to_json(:only => [:id, :version, :title, :body_html, :excerpt_html, :updated_at])}}"
55
+ end
56
+
57
+ def publish_content
58
+ content = Content.find(Content::Version.find(params[:id]).content_id)
59
+ content.publish(Website.find(params[:site_id]), params[:comment], params[:version], current_user)
60
+
61
+ render :json => {:success => true}
62
+ end
63
+
64
+ def revert_content
65
+ content = Content.find(Content::Version.find(params[:id]).content_id)
66
+ version = params[:version]
67
+ content.revert_to(version)
68
+ content.save!
69
+
70
+ render :json => {:success => true}
71
+ end
72
+
73
+ #website section layouts
74
+
75
+ def website_section_layout_versions
76
+ website_section = WebsiteSection.find(params[:id])
77
+ website = Website.find(params[:site_id])
78
+ sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
79
+ sort = sort_hash[:property] || 'version'
80
+ dir = sort_hash[:direction] || 'DESC'
81
+ limit = params[:limit] || 15
82
+ start = params[:start] || 0
83
+
84
+ versions = website_section.versions.order("#{sort} #{dir}").offset(start).limit(limit)
85
+
86
+ WebsiteSection::Version.class_exec(website) do
87
+ cattr_accessor :website
88
+ self.website = website
89
+ def active
90
+ published_site_id = self.website.active_publication.id
91
+ !PublishedElement.includes([:published_website]).where('published_websites.id = ? and published_element_record_id = ? and published_element_record_type = ? and published_elements.version = ?', published_site_id, self.website_section_id, 'WebsiteSection', self.version).first.nil?
92
+ end
93
+
94
+ def published_element
95
+ PublishedElement.where('published_element_record_id = ? and published_element_record_type = ? and published_elements.version = ?', self.website_section_id, 'WebsiteSection', self.version).first
96
+ end
97
+
98
+ def published
99
+ !published_element.nil?
100
+ end
101
+
102
+ def publisher
103
+ published_element.published_by_username if published
104
+ end
105
+ end
106
+
107
+ render :inline => "{\"totalCount\":#{website_section.versions.count},data:#{versions.to_json(
108
+ :only => [:id, :version, :title, :updated_at],
109
+ :methods => [:active, :published, :publisher])}}"
110
+ end
111
+
112
+ def get_website_section_version
113
+ render :text => WebsiteSection::Version.find(params[:id]).layout
114
+ end
115
+
116
+ def publish_website_section
117
+ website_section = WebsiteSection.find(WebsiteSection::Version.find(params[:id]).website_section_id)
118
+ website_section.publish(Website.find(params[:site_id]), params[:comment], params[:version], current_user)
119
+
120
+ render :json => {:success => true}
121
+ end
122
+
123
+ def revert_website_section
124
+ website_section = WebsiteSection.find(WebsiteSection::Version.find(params[:id]).website_section_id)
125
+ version = params[:version]
126
+ website_section.revert_to(version)
127
+ website_section.save!
128
+
129
+ render :text => {:success => true, :body_html => website_section.layout}.to_json
130
+ end
131
+
132
+ end#VersionsController
133
+ end#Desktop
134
+ end#ErpApp
135
+ end#Knitkit
@@ -0,0 +1,177 @@
1
+ module Knitkit
2
+ module ErpApp
3
+ module Desktop
4
+ class WebsiteController < Knitkit::ErpApp::Desktop::AppController
5
+ IGNORED_PARAMS = %w{action controller id}
6
+
7
+ before_filter :set_website, :only => [:export, :website_publications, :set_viewing_version, :activate_publication, :publish, :update, :delete]
8
+
9
+ def index
10
+ render :json => {:sites => Website.all}
11
+ end
12
+
13
+ def website_publications
14
+ sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
15
+ sort = sort_hash[:property] || 'version'
16
+ dir = sort_hash[:direction] || 'DESC'
17
+ limit = params[:limit] || 9
18
+ start = params[:start] || 0
19
+
20
+ published_websites = @website.published_websites.order("#{sort} #{dir}").limit(limit).offset(start)
21
+
22
+ #set site_version. User can view different versions. Check if they are viewing another version
23
+ site_version = @website.active_publication.version
24
+ if !session[:website_version].blank? && !session[:website_version].empty?
25
+ site_version_hash = session[:website_version].find{|item| item[:website_id] == @website.id}
26
+ site_version = site_version_hash[:version].to_f unless site_version_hash.nil?
27
+ end
28
+
29
+ PublishedWebsite.class_exec(site_version) do
30
+ cattr_accessor :site_version
31
+ self.site_version = site_version
32
+ def viewing
33
+ self.version == self.site_version
34
+ end
35
+ end
36
+
37
+ render :inline => "{\"success\":true, \"results\":#{published_websites.count},
38
+ \"totalCount\":#{@website.published_websites.count},
39
+ \"data\":#{published_websites.to_json(
40
+ :only => [:comment, :id, :version, :created_at, :active],
41
+ :methods => [:viewing, :published_by_username])} }"
42
+ end
43
+
44
+ def activate_publication
45
+ @website.set_publication_version(params[:version].to_f, current_user)
46
+
47
+ render :json => {:success => true}
48
+ end
49
+
50
+ def set_viewing_version
51
+ if session[:website_version].blank?
52
+ session[:website_version] = []
53
+ session[:website_version] << {:website_id => @website.id, :version => params[:version]}
54
+ else
55
+ session[:website_version].delete_if{|item| item[:website_id] == @website.id}
56
+ session[:website_version] << {:website_id => @website.id, :version => params[:version]}
57
+ end
58
+
59
+ render :json => {:success => true}
60
+ end
61
+
62
+ def publish
63
+ @website.publish(params[:comment], current_user)
64
+
65
+ render :json => {:success => true}
66
+ end
67
+
68
+ def new
69
+ result = {}
70
+ website = Website.new
71
+ website.subtitle = params[:subtitle]
72
+ website.title = params[:title]
73
+ website.name = params[:name]
74
+ website.email = params[:email]
75
+ website.auto_activate_publication = params[:auto_activate_publication] == 'yes'
76
+ website.email_inquiries = params[:email_inquiries] == 'yes'
77
+
78
+ # create homepage
79
+ website_section = WebsiteSection.new
80
+ website_section.title = "Home"
81
+ website_section.in_menu = true
82
+ website.website_sections << website_section
83
+ if website.save
84
+ website.setup_default_pages
85
+
86
+ #set default publication published by user
87
+ first_publication = website.published_websites.first
88
+ first_publication.published_by = current_user
89
+ first_publication.save
90
+
91
+ website.hosts << WebsiteHost.create(:host => params[:host])
92
+ website.save
93
+
94
+ website.publish("Publish Default Sections", current_user)
95
+ PublishedWebsite.activate(website, 1, current_user)
96
+
97
+ result[:success] = true
98
+ else
99
+ result[:success] = false
100
+ end
101
+
102
+ render :json => result
103
+ end
104
+
105
+ def update
106
+ @website.email = params[:email]
107
+ @website.name = params[:name]
108
+ @website.title = params[:title]
109
+ @website.subtitle = params[:subtitle]
110
+ @website.auto_activate_publication = params[:auto_activate_publication] == 'yes'
111
+ @website.email_inquiries = params[:email_inquiries] == 'yes'
112
+
113
+ render :json => @website.save ? {:success => true} : {:success => false}
114
+ end
115
+
116
+
117
+ def delete
118
+ render :json => @website.destroy ? {:success => true} : {:success => false}
119
+ end
120
+
121
+ def export
122
+ zip_path = @website.export
123
+ send_file(zip_path.to_s, :stream => false) rescue raise "Error sending #{zip_path} file"
124
+ ensure
125
+ FileUtils.rm_r File.dirname(zip_path) rescue nil
126
+ end
127
+
128
+ def import
129
+ result, message = Website.import(params[:website_data], current_user)
130
+
131
+ render :inline => {:success => result, :message => message}.to_json
132
+ ensure
133
+ FileUtils.rm_r File.dirname(zip_path) rescue nil
134
+ end
135
+
136
+ def add_host
137
+ website = Website.find(params[:id])
138
+ website_host = WebsiteHost.create(:host => params[:host])
139
+ website.hosts << website_host
140
+ website.save
141
+
142
+ render :json => {
143
+ :success => true,
144
+ :node => {
145
+ :text => website_host.attributes['host'],
146
+ :websiteHostId => website_host.id,
147
+ :host => website_host.attributes['host'],
148
+ :iconCls => 'icon-globe',
149
+ :url => "http://#{website_host.attributes['host']}",
150
+ :isHost => true,
151
+ :leaf => true,
152
+ :children => []}
153
+ }
154
+ end
155
+
156
+ def update_host
157
+ website_host = WebsiteHost.find(params[:id])
158
+ website_host.host = params[:host]
159
+ website_host.save
160
+
161
+ render :json => {:success => true}
162
+ end
163
+
164
+ def delete_host
165
+ render :json => WebsiteHost.destroy(params[:id]) ? {:success => true} : {:success => false}
166
+ end
167
+
168
+ protected
169
+
170
+ def set_website
171
+ @website = Website.find(params[:id])
172
+ end
173
+
174
+ end#WebsiteController
175
+ end#Desktop
176
+ end#ErpApp
177
+ end#Knitkit
@@ -0,0 +1,143 @@
1
+ module Knitkit
2
+ module ErpApp
3
+ module Desktop
4
+ class WebsiteNavController < Knitkit::ErpApp::Desktop::AppController
5
+ def new
6
+ result = {}
7
+ website = Website.find(params[:website_id])
8
+ website_nav = WebsiteNav.new(:name => params[:name])
9
+ website.website_navs << website_nav
10
+
11
+ if website_nav.save
12
+ result[:success] = true
13
+ result[:node] = {:text => params[:name],
14
+ :websiteNavId => website_nav.id,
15
+ :websiteId => website.id,
16
+ :iconCls => 'icon-index',
17
+ :canAddMenuItems => true,
18
+ :isWebsiteNav => true,
19
+ :leaf => false,
20
+ :children => []}
21
+ else
22
+ result[:success] = false
23
+ end
24
+
25
+ render :json => result
26
+ end
27
+
28
+ def update
29
+ website_nav = WebsiteNav.find(params[:website_nav_id])
30
+ website_nav.name = params[:name]
31
+
32
+ render :json => (website_nav.save ? {:success => true} : {:success => false})
33
+ end
34
+
35
+ def delete
36
+ render :json => (WebsiteNav.destroy(params[:id]) ? {:success => true} : {:success => false})
37
+ end
38
+
39
+ def add_menu_item
40
+ result = {}
41
+ klass = params[:klass].constantize
42
+ parent = klass.find(params[:id])
43
+ website_nav = parent.is_a?(WebsiteNav) ? parent : parent.website_nav
44
+ website_nav_item = WebsiteNavItem.new(:title => params[:title])
45
+
46
+ url = params[:url]
47
+ if(params[:link_to] != 'url')
48
+ #user wants to see Section so this is needed
49
+ params[:link_to] = 'WebsiteSection' if params[:link_to] == 'website_section'
50
+
51
+ #get link to item can be Article or Section
52
+ linked_to_id = params["#{params[:link_to].underscore}_id".to_sym]
53
+ link_to_item = params[:link_to].constantize.find(linked_to_id)
54
+ #setup link
55
+ website_nav_item.url = '/' + link_to_item.permalink
56
+ website_nav_item.linked_to_item = link_to_item
57
+ url = "http://#{website_nav.website.hosts.first.host}/" + link_to_item.permalink
58
+ else
59
+ website_nav_item.url = url
60
+ end
61
+
62
+ if website_nav_item.save
63
+ if parent.is_a?(WebsiteNav)
64
+ parent.website_nav_items << website_nav_item
65
+ else
66
+ website_nav_item.move_to_child_of(parent)
67
+ end
68
+
69
+ result[:success] = true
70
+ result[:node] = {:text => params[:title],
71
+ :linkToType => params[:link_to].underscore,
72
+ :linkedToId => linked_to_id,
73
+ :websiteId => website_nav.website.id,
74
+ :url => url,
75
+ :isSecure => false,
76
+ :canAddMenuItems => true,
77
+ :websiteNavItemId => website_nav_item.id,
78
+ :iconCls => 'icon-document',
79
+ :isWebsiteNavItem => true,
80
+ :leaf => false,
81
+ :children => []}
82
+ else
83
+ result[:success] = false
84
+ end
85
+
86
+ render :json => result
87
+ end
88
+
89
+ def update_menu_item
90
+ result = {}
91
+ website_nav_item = WebsiteNavItem.find(params[:website_nav_item_id])
92
+ website_nav_item.title = params[:title]
93
+
94
+ url = params[:url]
95
+ linked_to_id = nil
96
+ if(params[:link_to] != 'url')
97
+ #user wants to see Section so this is needed
98
+ params[:link_to] = 'WebsiteSection' if params[:link_to] == 'website_section'
99
+
100
+ #get link to item can be Article or Section
101
+ linked_to_id = params["#{params[:link_to].underscore}_id".to_sym]
102
+ link_to_item = params[:link_to].constantize.find(linked_to_id)
103
+ #setup link
104
+ website_nav_item.url = '/' + link_to_item.permalink
105
+ website_nav_item.linked_to_item = link_to_item
106
+ url = "http://#{website_nav_item.website_nav.website.hosts.first.host}/" + link_to_item.permalink
107
+ else
108
+ website_nav_item.url = url
109
+ end
110
+
111
+ if website_nav_item.save
112
+ result[:success] = true
113
+ result[:title] = params[:title]
114
+ result[:linkedToId] = linked_to_id
115
+ result[:linkToType] = params[:link_to].underscore
116
+ result[:url] = url
117
+ else
118
+ result[:success] = false
119
+ end
120
+
121
+ render :json => result
122
+ end
123
+
124
+ def update_security
125
+ website_nav_item = WebsiteNavItem.find(params[:id])
126
+ website = Website.find(params[:site_id])
127
+ if(params[:secure] == "true")
128
+ website_nav_item.add_role(website.role)
129
+ else
130
+ website_nav_item.remove_role(website.role)
131
+ end
132
+
133
+ render :json => {:success => true}
134
+ end
135
+
136
+ def delete_menu_item
137
+ render :json => (WebsiteNavItem.destroy(params[:id]) ? {:success => true} : {:success => false})
138
+ end
139
+
140
+ end#WebsiteNavController
141
+ end#Desktop
142
+ end#ErpApp
143
+ end#Knitkit