knitkit 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/knitkit/erp_app/desktop/file_assets_controller.rb +1 -1
- data/app/controllers/knitkit/erp_app/desktop/theme_controller.rb +0 -2
- data/app/models/website.rb +76 -79
- data/app/widgets/dynamic_forms/base.rb +139 -0
- data/app/widgets/dynamic_forms/javascript/dynamic_forms.js +111 -0
- data/app/widgets/dynamic_forms/views/error.html.erb +5 -0
- data/app/widgets/dynamic_forms/views/index.html.erb +8 -0
- data/app/widgets/dynamic_forms/views/success.html.erb +4 -0
- data/app/widgets/dynamic_grid/base.rb +130 -0
- data/app/widgets/dynamic_grid/helpers/controller/dynamic_grid_controller_helper.rb +3 -0
- data/app/widgets/dynamic_grid/helpers/view/dynamic_grid_view_helper.rb +3 -0
- data/app/widgets/dynamic_grid/javascript/dynamic_grid.js +178 -0
- data/app/widgets/dynamic_grid/views/index.html.erb +14 -0
- data/app/widgets/scaffold/base.rb +83 -0
- data/app/widgets/scaffold/helpers/controller/scaffold_controller_helper.rb +3 -0
- data/app/widgets/scaffold/helpers/view/scaffold_view_helper.rb +3 -0
- data/app/widgets/scaffold/javascript/scaffold.js +339 -0
- data/app/widgets/scaffold/views/index.html.erb +15 -0
- data/lib/knitkit/extensions/action_controller/theme_support/acts_as_themed_controller.rb +1 -1
- data/lib/knitkit/extensions/railties/action_view/helpers/menu_helper.rb +2 -3
- data/lib/knitkit/version.rb +1 -1
- data/public/javascripts/erp_app/desktop/applications/knitkit/center_region.js +25 -1
- metadata +19 -10
@@ -212,7 +212,7 @@ module Knitkit
|
|
212
212
|
|
213
213
|
render :inline => {:success => false, :error => "No Website Selected"}.to_json if (@assets_model.nil? && params[:action] != "base_path")
|
214
214
|
else
|
215
|
-
@assets_model = CompassAeInstance.
|
215
|
+
@assets_model = CompassAeInstance.find_by_internal_identifier('base')
|
216
216
|
end
|
217
217
|
end
|
218
218
|
|
@@ -73,8 +73,6 @@ module Knitkit
|
|
73
73
|
theme = Theme.find(params[:id])
|
74
74
|
zip_path = theme.export
|
75
75
|
send_file(zip_path.to_s, :stream => false) rescue raise "Error sending #{zip_path} file"
|
76
|
-
ensure
|
77
|
-
FileUtils.rm_r File.dirname(zip_path) rescue nil
|
78
76
|
end
|
79
77
|
|
80
78
|
def change_status
|
data/app/models/website.rb
CHANGED
@@ -2,13 +2,14 @@ class Website < ActiveRecord::Base
|
|
2
2
|
attr_protected :created_at, :updated_at
|
3
3
|
|
4
4
|
after_destroy :remove_sites_directory, :remove_website_role
|
5
|
-
after_create
|
5
|
+
after_create :setup_website
|
6
6
|
|
7
7
|
protected_with_capabilities
|
8
8
|
has_file_assets
|
9
9
|
|
10
10
|
extend FriendlyId
|
11
11
|
friendly_id :name, :use => [:slugged], :slug_column => :internal_identifier
|
12
|
+
|
12
13
|
def should_generate_new_friendly_id?
|
13
14
|
new_record?
|
14
15
|
end
|
@@ -25,7 +26,7 @@ class Website < ActiveRecord::Base
|
|
25
26
|
end
|
26
27
|
has_many :website_sections, :dependent => :destroy, :order => :lft do
|
27
28
|
def paths
|
28
|
-
collect{|website_section| website_section.paths}.flatten
|
29
|
+
collect { |website_section| website_section.paths }.flatten
|
29
30
|
end
|
30
31
|
|
31
32
|
#have to do a sort by to override what awesome nested set does for the order by (lft)
|
@@ -34,7 +35,7 @@ class Website < ActiveRecord::Base
|
|
34
35
|
end
|
35
36
|
|
36
37
|
def update_paths!
|
37
|
-
all.each{|section| section.self_and_descendants.each{|_section| _section.update_path!}}
|
38
|
+
all.each { |section| section.self_and_descendants.each { |_section| _section.update_path! } }
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
@@ -68,7 +69,7 @@ class Website < ActiveRecord::Base
|
|
68
69
|
end
|
69
70
|
|
70
71
|
def all_section_paths
|
71
|
-
WebsiteSection.select(:path).where(:website_id => self.id).collect{|row| row['path']}
|
72
|
+
WebsiteSection.select(:path).where(:website_id => self.id).collect { |row| row['path'] }
|
72
73
|
end
|
73
74
|
|
74
75
|
def config_value(config_item_type_iid)
|
@@ -148,7 +149,7 @@ class Website < ActiveRecord::Base
|
|
148
149
|
def remove_sites_directory
|
149
150
|
file_support = ErpTechSvcs::FileSupport::Base.new(:storage => Rails.application.config.erp_tech_svcs.file_storage)
|
150
151
|
begin
|
151
|
-
file_support.delete_file(File.join(file_support.root,"sites/#{self.iid}"), :force => true)
|
152
|
+
file_support.delete_file(File.join(file_support.root, "sites/#{self.iid}"), :force => true)
|
152
153
|
rescue
|
153
154
|
#do nothing it may not exist
|
154
155
|
end
|
@@ -161,12 +162,12 @@ class Website < ActiveRecord::Base
|
|
161
162
|
def setup_default_pages
|
162
163
|
# create default sections for each widget using widget layout
|
163
164
|
widget_classes = [
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
165
|
+
::Widgets::ContactUs::Base,
|
166
|
+
::Widgets::Search::Base,
|
167
|
+
::Widgets::ManageProfile::Base,
|
168
|
+
::Widgets::Login::Base,
|
169
|
+
::Widgets::Signup::Base,
|
170
|
+
::Widgets::ResetPassword::Base
|
170
171
|
]
|
171
172
|
profile_page = nil
|
172
173
|
widget_classes.each do |widget_class|
|
@@ -187,15 +188,15 @@ class Website < ActiveRecord::Base
|
|
187
188
|
|
188
189
|
def export_setup
|
189
190
|
setup_hash = {
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
191
|
+
:name => name,
|
192
|
+
:hosts => hosts.collect(&:host),
|
193
|
+
:title => title,
|
194
|
+
:subtitle => subtitle,
|
195
|
+
:internal_identifier => internal_identifier,
|
196
|
+
:sections => [],
|
197
|
+
:images => [],
|
198
|
+
:files => [],
|
199
|
+
:website_navs => []
|
199
200
|
}
|
200
201
|
|
201
202
|
#TODO update to handle configurations
|
@@ -206,8 +207,8 @@ class Website < ActiveRecord::Base
|
|
206
207
|
|
207
208
|
setup_hash[:website_navs] = website_navs.collect do |website_nav|
|
208
209
|
{
|
209
|
-
|
210
|
-
|
210
|
+
:name => website_nav.name,
|
211
|
+
:items => website_nav.items.positioned.map { |website_nav_item| build_menu_item_hash(website_nav_item) }
|
211
212
|
}
|
212
213
|
end
|
213
214
|
|
@@ -226,52 +227,52 @@ class Website < ActiveRecord::Base
|
|
226
227
|
tmp_dir = Website.make_tmp_dir
|
227
228
|
file_support = ErpTechSvcs::FileSupport::Base.new(:storage => Rails.application.config.erp_tech_svcs.file_storage)
|
228
229
|
|
229
|
-
sections_path = Pathname.new(File.join(tmp_dir,'sections'))
|
230
|
+
sections_path = Pathname.new(File.join(tmp_dir, 'sections'))
|
230
231
|
FileUtils.mkdir_p(sections_path) unless sections_path.exist?
|
231
232
|
|
232
|
-
articles_path = Pathname.new(File.join(tmp_dir,'articles'))
|
233
|
+
articles_path = Pathname.new(File.join(tmp_dir, 'articles'))
|
233
234
|
FileUtils.mkdir_p(articles_path) unless articles_path.exist?
|
234
235
|
|
235
236
|
documented_contents_path = Pathname.new(File.join(tmp_dir, 'documented contents'))
|
236
237
|
FileUtils.mkdir_p(documented_contents_path) unless documented_contents_path.exist?
|
237
238
|
|
238
|
-
excerpts_path = Pathname.new(File.join(tmp_dir,'excerpts'))
|
239
|
+
excerpts_path = Pathname.new(File.join(tmp_dir, 'excerpts'))
|
239
240
|
FileUtils.mkdir_p(excerpts_path) unless excerpts_path.exist?
|
240
241
|
|
241
|
-
image_assets_path = Pathname.new(File.join(tmp_dir,'images'))
|
242
|
+
image_assets_path = Pathname.new(File.join(tmp_dir, 'images'))
|
242
243
|
FileUtils.mkdir_p(image_assets_path) unless image_assets_path.exist?
|
243
244
|
|
244
|
-
file_assets_path = Pathname.new(File.join(tmp_dir,'files'))
|
245
|
+
file_assets_path = Pathname.new(File.join(tmp_dir, 'files'))
|
245
246
|
FileUtils.mkdir_p(file_assets_path) unless file_assets_path.exist?
|
246
247
|
|
247
248
|
sections.each do |website_section|
|
248
249
|
unless website_section.layout.blank?
|
249
|
-
File.open(File.join(sections_path,"#{website_section.internal_identifier}.rhtml"), 'wb+') {|f| f.puts(website_section.layout) }
|
250
|
+
File.open(File.join(sections_path, "#{website_section.internal_identifier}.rhtml"), 'wb+') { |f| f.puts(website_section.layout) }
|
250
251
|
end
|
251
252
|
end
|
252
253
|
|
253
254
|
contents = sections.collect(&:contents).flatten.uniq
|
254
255
|
contents.each do |content|
|
255
|
-
File.open(File.join(articles_path,"#{content.internal_identifier}.html"), 'wb+') {|f| f.puts(content.body_html) }
|
256
|
+
File.open(File.join(articles_path, "#{content.internal_identifier}.html"), 'wb+') { |f| f.puts(content.body_html) }
|
256
257
|
unless content.excerpt_html.blank?
|
257
|
-
File.open(File.join(excerpts_path,"#{content.internal_identifier}.html"), 'wb+') {|f| f.puts(content.excerpt_html) }
|
258
|
+
File.open(File.join(excerpts_path, "#{content.internal_identifier}.html"), 'wb+') { |f| f.puts(content.excerpt_html) }
|
258
259
|
end
|
259
260
|
end
|
260
261
|
|
261
262
|
online_document_sections.each do |online_documented_section|
|
262
|
-
File.open(File.join(documented_contents_path,"#{online_documented_section.internal_identifier}.html"), 'wb+') {|f| f.puts(online_documented_section.documented_item_published_content_html(active_publication)) }
|
263
|
+
File.open(File.join(documented_contents_path, "#{online_documented_section.internal_identifier}.html"), 'wb+') { |f| f.puts(online_documented_section.documented_item_published_content_html(active_publication)) }
|
263
264
|
end
|
264
265
|
|
265
266
|
self.files.where("directory like '%/sites/#{self.iid}/images%'").all.each do |image_asset|
|
266
|
-
contents = file_support.get_contents(File.join(file_support.root,image_asset.directory,image_asset.name))
|
267
|
-
FileUtils.mkdir_p(File.join(image_assets_path,image_asset.directory))
|
268
|
-
File.open(File.join(image_assets_path,image_asset.directory,image_asset.name), 'wb+') {|f| f.puts(contents) }
|
267
|
+
contents = file_support.get_contents(File.join(file_support.root, image_asset.directory, image_asset.name))
|
268
|
+
FileUtils.mkdir_p(File.join(image_assets_path, image_asset.directory))
|
269
|
+
File.open(File.join(image_assets_path, image_asset.directory, image_asset.name), 'wb+') { |f| f.puts(contents) }
|
269
270
|
end
|
270
271
|
|
271
272
|
self.files.where("directory like '%/#{Rails.application.config.erp_tech_svcs.file_assets_location}/sites/#{self.iid}%'").all.each do |file_asset|
|
272
|
-
contents = file_support.get_contents(File.join(file_support.root,file_asset.directory,file_asset.name))
|
273
|
-
FileUtils.mkdir_p(File.join(file_assets_path,file_asset.directory))
|
274
|
-
File.open(File.join(file_assets_path,file_asset.directory,file_asset.name), 'wb+') {|f| f.puts(contents) }
|
273
|
+
contents = file_support.get_contents(File.join(file_support.root, file_asset.directory, file_asset.name))
|
274
|
+
FileUtils.mkdir_p(File.join(file_assets_path, file_asset.directory))
|
275
|
+
File.open(File.join(file_assets_path, file_asset.directory, file_asset.name), 'wb+') { |f| f.puts(contents) }
|
275
276
|
end
|
276
277
|
|
277
278
|
files = []
|
@@ -329,14 +330,14 @@ class Website < ActiveRecord::Base
|
|
329
330
|
data = StringIO.new(data) if data.present?
|
330
331
|
setup_hash = YAML.load(data)
|
331
332
|
else
|
332
|
-
type =
|
333
|
+
type = entry.name.split('/')[0]
|
333
334
|
name = entry.name.split('/').last
|
334
335
|
next if name.nil?
|
335
336
|
|
336
337
|
if File.exist?(f_path) and !File.directory?(f_path)
|
337
338
|
entry_hash = {:type => type, :name => name, :path => entry.name}
|
338
339
|
entries << entry_hash unless name == 'sections' || name == 'articles' || name == 'excerpts' || name == 'documented contents'
|
339
|
-
entry_hash[:data] = File.open(f_path,"rb") {|io| io.read}
|
340
|
+
entry_hash[:data] = File.open(f_path, "rb") { |io| io.read }
|
340
341
|
end
|
341
342
|
end
|
342
343
|
|
@@ -347,10 +348,10 @@ class Website < ActiveRecord::Base
|
|
347
348
|
|
348
349
|
if Website.find_by_internal_identifier(setup_hash[:internal_identifier]).nil?
|
349
350
|
website = Website.new(
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
351
|
+
:name => setup_hash[:name],
|
352
|
+
:title => setup_hash[:title],
|
353
|
+
:subtitle => setup_hash[:subtitle],
|
354
|
+
:internal_identifier => setup_hash[:internal_identifier]
|
354
355
|
)
|
355
356
|
|
356
357
|
#TODO update to handle configurations
|
@@ -374,7 +375,7 @@ class Website < ActiveRecord::Base
|
|
374
375
|
setup_hash[:images].each do |image_asset|
|
375
376
|
filename = 'images' + image_asset[:path] + '/' + image_asset[:name]
|
376
377
|
#puts "image_asset '#{filename}'"
|
377
|
-
content = entries.find{|entry| entry[:type] == 'images' and entry[:path] == filename }
|
378
|
+
content = entries.find { |entry| entry[:type] == 'images' and entry[:path] == filename }
|
378
379
|
unless content.nil?
|
379
380
|
website.add_file(content[:data], File.join(file_support.root, image_asset[:path], image_asset[:name]))
|
380
381
|
end
|
@@ -384,7 +385,7 @@ class Website < ActiveRecord::Base
|
|
384
385
|
setup_hash[:files].each do |file_asset|
|
385
386
|
filename = 'files' + file_asset[:path] + '/' + file_asset[:name]
|
386
387
|
#puts "file_asset '#{filename}'"
|
387
|
-
content = entries.find{|entry| entry[:type] == 'files' and entry[:path] == filename }
|
388
|
+
content = entries.find { |entry| entry[:type] == 'files' and entry[:path] == filename }
|
388
389
|
unless content.nil?
|
389
390
|
website.add_file(content[:data], File.join(file_support.root, file_asset[:path], file_asset[:name]))
|
390
391
|
end
|
@@ -419,7 +420,7 @@ class Website < ActiveRecord::Base
|
|
419
420
|
|
420
421
|
website.publish("Website Imported", current_user)
|
421
422
|
|
422
|
-
rescue Exception=>ex
|
423
|
+
rescue Exception => ex
|
423
424
|
Rails.logger.error "#{ex.inspect} #{ex.backtrace}"
|
424
425
|
website.destroy unless website.nil?
|
425
426
|
raise ex
|
@@ -439,9 +440,9 @@ class Website < ActiveRecord::Base
|
|
439
440
|
|
440
441
|
def build_menu_item(hash)
|
441
442
|
website_item = WebsiteNavItem.new(
|
442
|
-
|
443
|
-
|
444
|
-
|
443
|
+
:title => hash[:title],
|
444
|
+
:url => hash[:url],
|
445
|
+
:position => hash[:position]
|
445
446
|
)
|
446
447
|
unless hash[:linked_to_item_type].blank?
|
447
448
|
website_item.linked_to_item = WebsiteSection.find_by_path(hash[:linked_to_item_path])
|
@@ -451,36 +452,34 @@ class Website < ActiveRecord::Base
|
|
451
452
|
child_website_item = build_menu_item(item)
|
452
453
|
child_website_item.move_to_child_of(website_item)
|
453
454
|
end
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
end
|
458
|
-
end
|
455
|
+
#add role if is_secured
|
456
|
+
website_item.add_role(website.role) if hash[:is_secured]
|
457
|
+
|
459
458
|
website_item
|
460
459
|
end
|
461
460
|
|
462
461
|
def build_section(hash, entries, website, current_user)
|
463
462
|
klass = hash[:type].constantize
|
464
463
|
section = klass.new(:title => hash[:name],
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
464
|
+
:in_menu => hash[:in_menu],
|
465
|
+
:render_base_layout => hash[:render_base_layout],
|
466
|
+
:position => hash[:position],
|
467
|
+
:render_base_layout => hash[:render_base_layout])
|
469
468
|
section.internal_identifier = hash[:internal_identifier]
|
470
469
|
section.permalink = hash[:permalink]
|
471
470
|
section.path = hash[:path]
|
472
|
-
content = entries.find{|entry| entry[:type] == 'sections' and entry[:name] == "#{hash[:internal_identifier]}.rhtml"}
|
473
|
-
|
474
|
-
|
475
|
-
|
471
|
+
content = entries.find { |entry| entry[:type] == 'sections' and entry[:name] == "#{hash[:internal_identifier]}.rhtml" }
|
472
|
+
|
473
|
+
section.layout = content[:data] unless content.nil?
|
474
|
+
|
476
475
|
hash[:articles].each do |article_hash|
|
477
476
|
article = Article.find_by_internal_identifier(article_hash[:internal_identifier])
|
478
477
|
if article.nil?
|
479
478
|
article = Article.new(:title => article_hash[:name], :display_title => article_hash[:display_title])
|
480
479
|
article.created_by = current_user
|
481
|
-
article.tag_list = article_hash[:tag_list].split(',').collect{|t| t.strip() } unless article_hash[:tag_list].blank?
|
482
|
-
article.body_html = entries.find{|entry| entry[:type] == 'articles' and entry[:name] == "#{article_hash[:internal_identifier]}.html"}[:data]
|
483
|
-
content = entries.find{|entry| entry[:type] == 'excerpts' and entry[:name] == "#{article_hash[:internal_identifier]}.html"}
|
480
|
+
article.tag_list = article_hash[:tag_list].split(',').collect { |t| t.strip() } unless article_hash[:tag_list].blank?
|
481
|
+
article.body_html = entries.find { |entry| entry[:type] == 'articles' and entry[:name] == "#{article_hash[:internal_identifier]}.html" }[:data]
|
482
|
+
content = entries.find { |entry| entry[:type] == 'excerpts' and entry[:name] == "#{article_hash[:internal_identifier]}.html" }
|
484
483
|
unless content.nil?
|
485
484
|
article.excerpt_html = content[:data]
|
486
485
|
end
|
@@ -498,7 +497,7 @@ class Website < ActiveRecord::Base
|
|
498
497
|
end
|
499
498
|
end
|
500
499
|
if section.is_a? OnlineDocumentSection
|
501
|
-
entry_data = entries.find{|entry| entry[:type] == 'documented contents' and entry[:name] == "#{section.internal_identifier}.html"}[:data]
|
500
|
+
entry_data = entries.find { |entry| entry[:type] == 'documented contents' and entry[:name] == "#{section.internal_identifier}.html" }[:data]
|
502
501
|
documented_content = DocumentedContent.create(:title => section.title, :body_html => entry_data)
|
503
502
|
DocumentedItem.create(:documented_content_id => documented_content.id, :online_document_section_id => section.id)
|
504
503
|
end
|
@@ -507,16 +506,14 @@ class Website < ActiveRecord::Base
|
|
507
506
|
child_section = build_section(section_hash, entries, website, current_user)
|
508
507
|
child_section.move_to_child_of(section)
|
509
508
|
# CREATE THE DOCUMENTED CONTENT HERE
|
510
|
-
entry_data = entries.find{|entry| entry[:type] == 'documented contents' and entry[:name] == "#{child_section.internal_identifier}.html"}[:data]
|
509
|
+
entry_data = entries.find { |entry| entry[:type] == 'documented contents' and entry[:name] == "#{child_section.internal_identifier}.html" }[:data]
|
511
510
|
documented_content = DocumentedContent.create(:title => child_section.title, :body_html => entry_data)
|
512
511
|
DocumentedItem.create(:documented_content_id => documented_content.id, :online_document_section_id => child_section.id)
|
513
512
|
end
|
514
513
|
end
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
end
|
519
|
-
end
|
514
|
+
#add role if is_secured
|
515
|
+
section.add_role(website.role) if hash[:is_secured]
|
516
|
+
|
520
517
|
section
|
521
518
|
end
|
522
519
|
|
@@ -530,13 +527,13 @@ class Website < ActiveRecord::Base
|
|
530
527
|
|
531
528
|
def build_menu_item_hash(menu_item)
|
532
529
|
{
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
530
|
+
:title => menu_item.title,
|
531
|
+
:url => menu_item.url,
|
532
|
+
:is_secured => menu_item.is_secured?,
|
533
|
+
:linked_to_item_type => menu_item.linked_to_item_type,
|
534
|
+
:linked_to_item_path => menu_item.linked_to_item.nil? ? nil : menu_item.linked_to_item.path,
|
535
|
+
:position => menu_item.position,
|
536
|
+
:items => menu_item.children.collect { |child| build_menu_item_hash(child) }
|
540
537
|
}
|
541
538
|
end
|
542
539
|
|
@@ -0,0 +1,139 @@
|
|
1
|
+
module Widgets
|
2
|
+
module DynamicForms
|
3
|
+
class Base < ErpApp::Widgets::Base
|
4
|
+
def index
|
5
|
+
render
|
6
|
+
end
|
7
|
+
|
8
|
+
def new
|
9
|
+
begin
|
10
|
+
unless params[:file].nil?
|
11
|
+
# size check
|
12
|
+
if params[:file].tempfile.size > ErpTechSvcs::Config.max_file_size_in_mb.megabytes
|
13
|
+
raise "File cannot be larger than #{ErpTechSvcs::Config.max_file_size_in_mb}MB"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
form_data = JSON.parse(params[:form_data_json])
|
17
|
+
form_data[:dynamic_form_id] = params[:dynamic_form_id]
|
18
|
+
form_data[:model_name] = params[:model_name]
|
19
|
+
form_data.symbolize_keys!
|
20
|
+
@website = Website.find_by_host(request.host_with_port)
|
21
|
+
|
22
|
+
if form_data[:email_subject].blank?
|
23
|
+
subject = "#{form_data[:model_name]} Submission from #{@website.title}"
|
24
|
+
else
|
25
|
+
subject = strip_tags(form_data[:email_subject])
|
26
|
+
form_data.delete(:email_subject)
|
27
|
+
end
|
28
|
+
|
29
|
+
@myDynamicObject = DynamicFormModel.get_instance(form_data[:model_name])
|
30
|
+
|
31
|
+
form_data[:created_by] = current_user unless current_user.nil?
|
32
|
+
form_data[:created_with_form_id] = form_data[:dynamic_form_id] if form_data[:dynamic_form_id] and params[:is_html_form].blank?
|
33
|
+
form_data[:website] = @website.title
|
34
|
+
|
35
|
+
@myDynamicObject = @myDynamicObject.assign_all_attributes(form_data, ErpApp::Widgets::Base::IGNORED_PARAMS)
|
36
|
+
|
37
|
+
# get dynamic for from form_data[:created_with_form_id]
|
38
|
+
form = DynamicForm.find(form_data[:created_with_form_id])
|
39
|
+
|
40
|
+
# check widget_action from dynamic form
|
41
|
+
if !form.nil? and ['email', 'both'].include?(form.widget_action)
|
42
|
+
# email data
|
43
|
+
attachments = (params[:file].nil? ? [] : [params[:file]])
|
44
|
+
send_email(form, @myDynamicObject, subject, attachments)
|
45
|
+
end
|
46
|
+
|
47
|
+
if form.nil? or (!form.nil? and ['save', 'both'].include?(form.widget_action))
|
48
|
+
#save data
|
49
|
+
@myDynamicObject.save
|
50
|
+
save_file_asset(form_data) unless params[:file].nil?
|
51
|
+
end
|
52
|
+
|
53
|
+
output = render_to_string(:template => "success", :layout => false)
|
54
|
+
render :inline => {
|
55
|
+
:success => true,
|
56
|
+
:response => (file_upload_request? ? ERB::Util.html_escape(output) : output)
|
57
|
+
}.to_json
|
58
|
+
rescue Exception => e
|
59
|
+
Rails.logger.error e.message
|
60
|
+
Rails.logger.error e.backtrace.join("\n")
|
61
|
+
output = render_to_string(:template => "error", :layout => false, :locals => {:message => e.message})
|
62
|
+
render :inline => {
|
63
|
+
:success => false,
|
64
|
+
:response => (file_upload_request? ? ERB::Util.html_escape(output) : output)
|
65
|
+
}.to_json
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
protected
|
70
|
+
def file_upload_request?
|
71
|
+
request.env['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest'
|
72
|
+
end
|
73
|
+
|
74
|
+
def save_file_asset(form_data)
|
75
|
+
result = {}
|
76
|
+
name = params[:file].original_filename
|
77
|
+
data = params[:file].tempfile
|
78
|
+
set_file_support
|
79
|
+
|
80
|
+
begin
|
81
|
+
@root_node = File.join(ErpTechSvcs::Config.file_assets_location, form_data[:model_name], @myDynamicObject.id.to_s)
|
82
|
+
file = @myDynamicObject.add_file(data, File.join(@file_support.root, base_path, name))
|
83
|
+
|
84
|
+
roles = ['admin', @myDynamicObject.role_iid]
|
85
|
+
(@myDynamicObject.file_security_default == 'private') ? file.add_capability(:download, 'FileAsset', roles) : file.remove_all_capabilities
|
86
|
+
|
87
|
+
return {:success => true}
|
88
|
+
rescue Exception => e
|
89
|
+
Rails.logger.error e.message
|
90
|
+
Rails.logger.error e.backtrace
|
91
|
+
raise "Error uploading file. #{e.message}"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def base_path
|
96
|
+
@base_path = (@root_node.nil? ? nil : File.join(@file_support.root, @root_node))
|
97
|
+
end
|
98
|
+
|
99
|
+
def set_file_support
|
100
|
+
@file_support = ErpTechSvcs::FileSupport::Base.new(:storage => ErpTechSvcs::Config.file_storage)
|
101
|
+
end
|
102
|
+
|
103
|
+
def send_email(form, dynamicObject, subject='', attachments=[])
|
104
|
+
begin
|
105
|
+
DynamicFormMailer.widget_email_with_attachments(form, dynamicObject, subject, attachments).deliver
|
106
|
+
rescue Exception => e
|
107
|
+
Rails.logger.error e.message
|
108
|
+
Rails.logger.error e.backtrace
|
109
|
+
raise "Error sending email. #{e.message}"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
#should not be modified
|
114
|
+
#modify at your own risk
|
115
|
+
def locate
|
116
|
+
File.dirname(__FILE__)
|
117
|
+
end
|
118
|
+
|
119
|
+
class << self
|
120
|
+
def title
|
121
|
+
"Dynamic Forms"
|
122
|
+
end
|
123
|
+
|
124
|
+
def widget_name
|
125
|
+
File.basename(File.dirname(__FILE__))
|
126
|
+
end
|
127
|
+
|
128
|
+
def base_layout
|
129
|
+
begin
|
130
|
+
file = File.join(File.dirname(__FILE__),"/views/layouts/base.html.erb")
|
131
|
+
IO.read(file)
|
132
|
+
rescue
|
133
|
+
return nil
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|