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
@@ -8,23 +8,21 @@ module Knitkit
8
8
  websites = Website.order('name ASC').all
9
9
 
10
10
  tree = []
11
-
12
11
  websites.each do |website|
12
+ @website_primary_host = website.config_value('primary_host')
13
+
13
14
  website_hash = {
14
15
  :text => website.name,
15
16
  :configurationId => website.configurations.first.id,
16
17
  :iconCls => 'icon-globe_disconnected',
17
18
  :id => "website_#{website.id}",
18
19
  :leaf => false,
19
- :url => "http://#{website.hosts.first.attributes['host']}",
20
+ :url => "http://#{@website_primary_host}",
20
21
  :name => website.name,
21
22
  :title => website.title,
22
23
  :subtitle => website.subtitle,
23
24
  :isWebsite => true,
24
- :email => website.email,
25
25
  :siteName => website.name,
26
- :emailInquiries => website.email_inquiries?,
27
- :autoActivatePublication => website.auto_activate_publication?,
28
26
  :children => []
29
27
  }
30
28
 
@@ -44,7 +42,6 @@ module Knitkit
44
42
 
45
43
  website_hash[:children] << sections_hash
46
44
 
47
-
48
45
  #handle menus
49
46
  menus_hash = {:text => 'Menus', :iconCls => 'icon-content', :isMenuRoot => true, :websiteId => website.id, :leaf => false, :children => []}
50
47
  website.website_navs.each do |website_nav|
@@ -80,7 +77,7 @@ module Knitkit
80
77
  unless item.linked_to_item.nil?
81
78
  linked_to_item_id = item.linked_to_item_id
82
79
  link_to_type = item.linked_to_item.class.to_s.underscore
83
- url = "http://#{website.hosts.first.attributes['host']}" + item.linked_to_item.path
80
+ url = "http://#{@website_primary_host}" + item.linked_to_item.path
84
81
  end
85
82
 
86
83
  menu_item_hash = {
@@ -116,7 +113,7 @@ module Knitkit
116
113
  :renderWithBaseLayout => website_section.render_base_layout?,
117
114
  :hasLayout => !website_section.layout.blank?,
118
115
  :id => "section_#{website_section.id}",
119
- :url => "http://#{website.hosts.first.attributes['host']}#{website_section.path}",
116
+ :url => "http://#{@website_primary_host}#{website_section.path}",
120
117
  :internal_identifier => website_section.internal_identifier
121
118
  }
122
119
  if (website_section.is_a?(OnlineDocumentSection) || website_section.type == 'OnlineDocumentSection')
@@ -61,14 +61,14 @@ module Knitkit
61
61
  else
62
62
  result[:success] = false
63
63
  end
64
-
64
+
65
65
  render :json => result
66
66
  end
67
67
  rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
68
68
  render :json => {:success => false, :message => ex.message}
69
69
  end
70
70
  end
71
-
71
+
72
72
  def delete
73
73
  model = DesktopApplication.find_by_internal_identifier('knitkit')
74
74
  begin
@@ -103,12 +103,12 @@ module Knitkit
103
103
  section = WebsiteSection.find(website_section_id)
104
104
 
105
105
  if section.type == 'Blog'
106
- sort_default = 'created_at'
106
+ sort_default = 'contents.created_at'
107
107
  dir_default = 'DESC'
108
108
  else
109
109
  sort_default = 'title'
110
110
  dir_default = 'ASC'
111
- end
111
+ end
112
112
 
113
113
  sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
114
114
  sort = sort_hash[:property] || sort_default
@@ -146,7 +146,7 @@ module Knitkit
146
146
 
147
147
  render :inline => "{total:#{total_count},data:#{articles_array.to_json}}"
148
148
  end
149
-
149
+
150
150
  def all
151
151
  Article.include_root_in_json = false
152
152
  sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
@@ -157,7 +157,10 @@ module Knitkit
157
157
 
158
158
  articles = Article.includes(:website_section_contents)
159
159
  articles = articles.where( :website_section_contents => { :content_id => nil } ) if params[:show_orphaned] == 'true'
160
- articles = articles.where('internal_identifier like ?', "%#{params[:iid]}%") unless params[:iid].blank?
160
+ articles = articles.where("UPPER(contents.internal_identifier) LIKE UPPER('%#{params[:iid]}%')") unless params[:iid].blank?
161
+ articles = articles.where("UPPER(contents.title) LIKE UPPER('%#{params[:title]}%')") unless params[:title].blank?
162
+ articles = articles.where("UPPER(contents.body_html) LIKE UPPER('%#{params[:content]}%')
163
+ OR UPPER(contents.excerpt_html) LIKE UPPER('%#{params[:content]}%')") unless params[:content].blank?
161
164
  articles = articles.order("contents.#{sort} #{dir}")
162
165
  total_count = articles.count
163
166
  articles = articles.limit(limit).offset(start)
@@ -195,7 +198,7 @@ module Knitkit
195
198
  article = Article.find(params[:article_id])
196
199
  attributes = article.attribute_values
197
200
  attributes = attributes.slice(start.to_i, limit.to_i)
198
-
201
+
199
202
  if dir == "DESC"
200
203
  if sort == "data_type" or sort == "description"
201
204
  attributes = attributes.sort {|x,y| x.attribute_type.send(sort) <=> y.attribute_type.send(sort)}
@@ -277,7 +280,7 @@ module Knitkit
277
280
 
278
281
  render :json => result
279
282
  end
280
-
283
+
281
284
  end#ArticlesController
282
285
  end#Desktop
283
286
  end#ErpApp
@@ -4,6 +4,7 @@ module Knitkit
4
4
 
5
5
  class ContentController < Knitkit::ErpApp::Desktop::AppController
6
6
  def update
7
+ result = {:success => true}
7
8
  model = DesktopApplication.find_by_internal_identifier('knitkit')
8
9
  begin
9
10
  current_user.with_capability(model, 'edit_html', 'Article') do
@@ -11,8 +12,19 @@ module Knitkit
11
12
  html = params[:html]
12
13
  content = Content.find(id)
13
14
  content.body_html = html
14
-
15
- render :json => (content.save ? {:success => true} : {:success => false})
15
+
16
+ if content.save
17
+ if params[:site_id]
18
+ website = Website.find(params[:site_id])
19
+ content.publish(website, 'Auto Publish', content.version, current_user) if website.publish_on_save?
20
+ end
21
+ #added for inline editing
22
+ result[:last_update] = content.updated_at.strftime("%m/%d/%Y %I:%M%p")
23
+ else
24
+ result = {:success => false}
25
+ end
26
+
27
+ render :json => result
16
28
  end
17
29
  rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
18
30
  render :json => {:success => false, :message => ex.message}
@@ -20,6 +32,7 @@ module Knitkit
20
32
  end
21
33
 
22
34
  def save_excerpt
35
+ result = {:success => true}
23
36
  model = DesktopApplication.find_by_internal_identifier('knitkit')
24
37
  begin
25
38
  current_user.with_capability(model, 'edit_excerpt', 'Article') do
@@ -27,8 +40,17 @@ module Knitkit
27
40
  html = params[:html]
28
41
  content = Content.find(id)
29
42
  content.excerpt_html = html
30
-
31
- render :json => (content.save ? {:success => true} : {:success => false})
43
+
44
+ if content.save
45
+ if params[:site_id]
46
+ website = Website.find(params[:site_id])
47
+ content.publish(website, 'Auto Publish', content.version, current_user) if website.publish_on_save?
48
+ end
49
+ else
50
+ result = {:success => false}
51
+ end
52
+
53
+ render :json => result
32
54
  end
33
55
  rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
34
56
  render :json => {:success => false, :message => ex.message}
@@ -59,12 +59,12 @@ module Knitkit
59
59
  begin
60
60
  current_user.with_capability(model, capability_type, capability_resource) do
61
61
  result = {}
62
- upload_path = request.env['HTTP_X_DIRECTORY'].blank? ? params[:directory] : request.env['HTTP_X_DIRECTORY']
63
- name = request.env['HTTP_X_FILE_NAME'].blank? ? params[:file_data].original_filename : request.env['HTTP_X_FILE_NAME']
64
- data = request.env['HTTP_X_FILE_NAME'].blank? ? params[:file_data] : request.raw_post
62
+ upload_path = params[:directory]
63
+ name = params[:name]
64
+ data = request.raw_post
65
65
 
66
66
  begin
67
- upload_path == 'root_node' ? @assets_model.add_file(data, File.join(@file_support.root,base_path,name)) : @assets_model.add_file(data, File.join(@file_support.root,upload_path,name))
67
+ upload_path == 'root_node' ? @assets_model.add_file(data, File.join(base_path,name)) : @assets_model.add_file(data, File.join(@file_support.root,upload_path,name))
68
68
  result = {:success => true}
69
69
  rescue Exception=>ex
70
70
  logger.error ex.message
@@ -81,24 +81,32 @@ module Knitkit
81
81
  end
82
82
 
83
83
  def save_move
84
- result = {}
85
- path = params[:node]
84
+ messages = []
85
+ result = {}
86
+ path = params[:node]
86
87
  new_parent_path = params[:parent_node]
87
88
  new_parent_path = @root_node if new_parent_path == ROOT_NODE
88
-
89
- if Rails.application.config.erp_tech_svcs.file_storage == :filesystem and !File.exists?(File.join(@file_support.root, path))
90
- result = {:success => false, :msg => 'File does not exist.'}
91
- else
92
- #path = path[1..path.length] if path[0] == "/"
93
- file = @assets_model.files.find(:first, :conditions => ['name = ? and directory = ?', ::File.basename(path), ::File.dirname(path)])
94
- file.move(new_parent_path)
95
- result = {:success => true, :msg => "#{File.basename(path)} was moved to #{new_parent_path} successfully"}
89
+
90
+ nodes_to_move = (params[:selected_nodes] ? JSON(params[:selected_nodes]) : [params[:node]])
91
+ begin
92
+ nodes_to_move.each do |path|
93
+ if ErpTechSvcs::Config.file_storage == :filesystem and !File.exists?(File.join(@file_support.root, path))
94
+ result = {:success => false, :msg => 'File does not exist.'}
95
+ else
96
+ file = @assets_model.files.find(:first, :conditions => ['name = ? and directory = ?', ::File.basename(path), ::File.dirname(path)])
97
+ result, message = file.move(new_parent_path)
98
+ end
99
+ messages << message
100
+ end
101
+ render :json => {:success => true, :msg => messages.join(',')}
102
+ rescue Exception => e
103
+ render :json => {:success => false, :msg => e.message}
96
104
  end
97
-
98
- render :json => result
99
105
  end
100
106
 
101
107
  def delete_file
108
+ messages = []
109
+
102
110
  if @context == Website
103
111
  capability_type = "view"
104
112
  capability_resource = "SiteFileAsset"
@@ -107,26 +115,33 @@ module Knitkit
107
115
  capability_resource = "GlobalFileAsset"
108
116
  end
109
117
 
118
+ nodes_to_delete = (params[:selected_nodes] ? JSON(params[:selected_nodes]) : [params[:node]])
119
+
110
120
  model = DesktopApplication.find_by_internal_identifier('knitkit')
111
121
  begin
112
- current_user.with_capability(model, capability_type, capability_resource) do
113
- path = params[:node]
114
- path = "#{path}/" if params[:leaf] == 'false' and path.match(/\/$/).nil?
115
- result = {}
116
- begin
117
- name = File.basename(path)
118
- result, message, is_folder = @file_support.delete_file(File.join(@file_support.root,path))
119
- if result && !is_folder
120
- file = @assets_model.files.find(:first, :conditions => ['name = ? and directory = ?', ::File.basename(path), ::File.dirname(path)])
121
- file.destroy
122
+ result = false
123
+ nodes_to_delete.each do |path|
124
+ current_user.with_capability(model, capability_type, capability_resource) do
125
+ path = "#{path}/" if params[:leaf] == 'false' and path.match(/\/$/).nil?
126
+ begin
127
+ name = File.basename(path)
128
+ result, message, is_folder = @file_support.delete_file(File.join(@file_support.root,path))
129
+ if result and !is_folder
130
+ file = @assets_model.files.find(:first, :conditions => ['name = ? and directory = ?', ::File.basename(path), ::File.dirname(path)])
131
+ file.destroy
132
+ end
133
+ messages << message
134
+ rescue Exception=>ex
135
+ Rails.logger.error ex.message
136
+ Rails.logger.error ex.backtrace.join("\n")
137
+ render :json => {:success => false, :error => "Error deleting #{name}"} and return
122
138
  end
123
- result = {:success => result, :error => message}
124
- rescue Exception=>ex
125
- logger.error ex.message
126
- logger.error ex.backtrace.join("\n")
127
- result = {:success => false, :error => "Error deleting #{name}"}
128
- end
129
- render :json => result
139
+ end # end current_user.with_capability
140
+ end # end nodes_to_delete.each
141
+ if result
142
+ render :json => {:success => true, :message => messages.join(',')}
143
+ else
144
+ render :json => {:success => false, :error => messages.join(',')}
130
145
  end
131
146
  rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
132
147
  render :json => {:success => false, :message => ex.message}
@@ -209,8 +224,7 @@ module Knitkit
209
224
  @context = params[:context].to_sym
210
225
 
211
226
  if @context == :website
212
- #get website id this can be an xhr request or regular
213
- website_id = request.env['HTTP_X_WEBSITEID'].blank? ? params[:website_id] : request.env['HTTP_X_WEBSITEID']
227
+ website_id = params[:website_id]
214
228
  (@assets_model = website_id.blank? ? nil : Website.find(website_id))
215
229
 
216
230
  render :inline => {:success => false, :error => "No Website Selected"}.to_json if (@assets_model.nil? && params[:action] != "base_path")
@@ -23,12 +23,12 @@ module Knitkit
23
23
  begin
24
24
  current_user.with_capability(model, capability_type, capability_resource) do
25
25
  result = {}
26
- upload_path = request.env['HTTP_X_DIRECTORY'].blank? ? params[:directory] : request.env['HTTP_X_DIRECTORY']
27
- name = request.env['HTTP_X_FILE_NAME'].blank? ? params[:file_data].original_filename : request.env['HTTP_X_FILE_NAME']
28
- data = request.env['HTTP_X_FILE_NAME'].blank? ? params[:file_data] : request.raw_post
26
+ upload_path = params[:directory]
27
+ name = params[:name]
28
+ data = request.raw_post
29
29
 
30
30
  begin
31
- upload_path == 'root_node' ? @assets_model.add_file(data, File.join(@file_support.root,base_path,name)) : @assets_model.add_file(data, File.join(@file_support.root,upload_path,name))
31
+ upload_path == 'root_node' ? @assets_model.add_file(data, File.join(base_path,name)) : @assets_model.add_file(data, File.join(@file_support.root,upload_path,name))
32
32
  result = {:success => true}
33
33
  rescue Exception=>ex
34
34
  logger.error ex.message
@@ -45,6 +45,8 @@ module Knitkit
45
45
  end
46
46
 
47
47
  def delete_file
48
+ messages = []
49
+
48
50
  if @context == Website
49
51
  capability_type = "view"
50
52
  capability_resource = "SiteImageAsset"
@@ -53,26 +55,33 @@ module Knitkit
53
55
  capability_resource = "GlobalImageAsset"
54
56
  end
55
57
 
58
+ nodes_to_delete = (params[:selected_nodes] ? JSON(params[:selected_nodes]) : [params[:node]])
59
+
56
60
  model = DesktopApplication.find_by_internal_identifier('knitkit')
57
61
  begin
58
- current_user.with_capability(model, capability_type, capability_resource) do
59
- path = params[:node]
60
- path = "#{path}/" if params[:leaf] == 'false' and path.match(/\/$/).nil?
61
- result = {}
62
- begin
63
- name = File.basename(path)
64
- result, message, is_folder = @file_support.delete_file(File.join(@file_support.root,path))
65
- if result && !is_folder
66
- file = @assets_model.files.find(:first, :conditions => ['name = ? and directory = ?', ::File.basename(path), ::File.dirname(path)])
67
- file.destroy
62
+ result = false
63
+ nodes_to_delete.each do |path|
64
+ current_user.with_capability(model, capability_type, capability_resource) do
65
+ path = "#{path}/" if params[:leaf] == 'false' and path.match(/\/$/).nil?
66
+ begin
67
+ name = File.basename(path)
68
+ result, message, is_folder = @file_support.delete_file(File.join(@file_support.root,path))
69
+ if result and !is_folder
70
+ file = @assets_model.files.find(:first, :conditions => ['name = ? and directory = ?', ::File.basename(path), ::File.dirname(path)])
71
+ file.destroy
72
+ end
73
+ messages << message
74
+ rescue Exception=>ex
75
+ Rails.logger.error ex.message
76
+ Rails.logger.error ex.backtrace.join("\n")
77
+ render :json => {:success => false, :error => "Error deleting #{name}"} and return
68
78
  end
69
- result = {:success => result, :error => message}
70
- rescue Exception=>ex
71
- logger.error ex.message
72
- logger.error ex.backtrace.join("\n")
73
- result = {:success => false, :error => "Error deleting #{name}"}
74
- end
75
- render :json => result
79
+ end # end current_user.with_capability
80
+ end # end nodes_to_delete.each
81
+ if result
82
+ render :json => {:success => true, :message => messages.join(',')}
83
+ else
84
+ render :json => {:success => false, :error => messages.join(',')}
76
85
  end
77
86
  rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
78
87
  render :json => {:success => false, :message => ex.message}
@@ -155,23 +155,25 @@ module Knitkit
155
155
  end
156
156
 
157
157
  def save_move
158
+ result = {}
159
+ nodes_to_move = (params[:selected_nodes] ? JSON(params[:selected_nodes]) : [params[:node]])
158
160
  model = DesktopApplication.find_by_internal_identifier('knitkit')
159
161
  begin
160
- current_user.with_capability(model, 'view', 'Theme') do
161
- result = {}
162
- path = File.join(@file_support.root, params[:node])
163
- new_parent_path = File.join(@file_support.root, params[:parent_node])
164
-
165
- unless @file_support.exists? path
166
- result = {:success => false, :msg => 'File does not exist.'}
167
- else
168
- theme_file = get_theme_file(path)
169
- theme_file.move(params[:parent_node])
170
- result = {:success => true, :msg => "#{File.basename(path)} was moved to #{new_parent_path} successfully"}
162
+ nodes_to_move.each do |node|
163
+ current_user.with_capability(model, 'view', 'Theme') do
164
+ path = File.join(@file_support.root, node)
165
+ new_parent_path = File.join(@file_support.root, params[:parent_node])
166
+
167
+ unless @file_support.exists? path
168
+ result = {:success => false, :msg => 'File does not exist.'}
169
+ else
170
+ theme_file = get_theme_file(path)
171
+ theme_file.move(params[:parent_node])
172
+ result = {:success => true, :msg => "#{File.basename(path)} was moved to #{new_parent_path} successfully"}
173
+ end
171
174
  end
172
-
173
- render :json => result
174
175
  end
176
+ render :json => result
175
177
  rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
176
178
  render :json => {:success => false, :message => ex.message}
177
179
  end
@@ -207,9 +209,9 @@ module Knitkit
207
209
  begin
208
210
  current_user.with_capability(model, 'view', 'Theme') do
209
211
  result = {}
210
- upload_path = request.env['HTTP_EXTRAPOSTDATA_DIRECTORY'].blank? ? params[:directory] : request.env['HTTP_EXTRAPOSTDATA_DIRECTORY']
211
- name = request.env['HTTP_X_FILE_NAME'].blank? ? params[:file_data].original_filename : request.env['HTTP_X_FILE_NAME']
212
- data = request.env['HTTP_X_FILE_NAME'].blank? ? params[:file_data] : request.raw_post
212
+ upload_path = params[:directory]
213
+ name = params[:name]
214
+ data = request.raw_post
213
215
 
214
216
  theme = get_theme(upload_path)
215
217
  name = File.join(@file_support.root, upload_path, name)
@@ -231,25 +233,32 @@ module Knitkit
231
233
  end
232
234
 
233
235
  def delete_file
236
+ messages = []
237
+ nodes_to_delete = (params[:selected_nodes] ? JSON(params[:selected_nodes]) : [params[:node]])
234
238
  model = DesktopApplication.find_by_internal_identifier('knitkit')
235
239
  begin
236
- current_user.with_capability(model, 'view', 'Theme') do
237
- path = params[:node]
238
- result = {}
239
- begin
240
- name = File.basename(path)
241
- result, message, is_folder = @file_support.delete_file(File.join(@file_support.root,path))
242
- if result && !is_folder
243
- theme_file = get_theme_file(path)
244
- theme_file.destroy
240
+ result = false
241
+ nodes_to_delete.each do |path|
242
+ current_user.with_capability(model, 'view', 'Theme') do
243
+ begin
244
+ name = File.basename(path)
245
+ result, message, is_folder = @file_support.delete_file(File.join(@file_support.root,path))
246
+ if result && !is_folder
247
+ theme_file = get_theme_file(path)
248
+ theme_file.destroy
249
+ end
250
+ messages << message
251
+ rescue Exception=>ex
252
+ Rails.logger.error ex.message
253
+ Rails.logger.error ex.backtrace.join("\n")
254
+ render :json => {:success => false, :error => "Error deleting #{name}"} and return
245
255
  end
246
- result = {:success => result, :error => message}
247
- rescue Exception=>ex
248
- logger.error ex.message
249
- logger.error ex.backtrace.join("\n")
250
- result = {:success => false, :error => "Error deleting #{name}"}
251
- end
252
- render :json => result
256
+ end # end current_user.with_capability
257
+ end # end nodes_to_delete.each
258
+ if result
259
+ render :json => {:success => true, :message => messages.join(',')}
260
+ else
261
+ render :json => {:success => false, :error => messages.join(',')}
253
262
  end
254
263
  rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
255
264
  render :json => {:success => false, :message => ex.message}