erp_forms 2.0.6 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/app/controllers/erp_forms/erp_app/desktop/dynamic_forms/base_controller.rb +4 -37
  2. data/app/controllers/erp_forms/erp_app/desktop/dynamic_forms/data_controller.rb +348 -82
  3. data/app/controllers/erp_forms/erp_app/desktop/dynamic_forms/forms_controller.rb +110 -15
  4. data/app/controllers/erp_forms/erp_app/desktop/dynamic_forms/models_controller.rb +19 -3
  5. data/app/mailers/dynamic_form_mailer.rb +35 -0
  6. data/app/models/dynamic_datum.rb +97 -22
  7. data/app/models/dynamic_form.rb +172 -98
  8. data/app/models/dynamic_form_document.rb +4 -11
  9. data/app/models/dynamic_form_model.rb +46 -22
  10. data/app/models/ticket.rb +4 -0
  11. data/app/views/dynamic_form_mailer/widget_email_with_attachments.html.erb +3 -0
  12. data/app/views/dynamic_form_mailer/widget_email_with_attachments.text.erb +3 -0
  13. data/app/widgets/dynamic_forms/base.rb +101 -19
  14. data/app/widgets/dynamic_forms/javascript/dynamic_forms.js +40 -38
  15. data/app/widgets/dynamic_forms/views/error.html.erb +1 -0
  16. data/db/data_migrations/20110608185830_create_default_dynamic_models_and_forms.rb +2 -0
  17. data/db/data_migrations/20120824013449_create_ticket_form.rb +1 -0
  18. data/db/data_migrations/20121026013449_update_ticket_form.rb +64 -0
  19. data/db/data_migrations/{20120904191738_update_contact_form.rb → 20121026191738_update_contact_form.rb} +4 -0
  20. data/db/migrate/20110530193446_dynamic_forms.rb +12 -0
  21. data/db/migrate/20121007022323_upgrade_dynamic_forms_table.rb +31 -0
  22. data/lib/erp_forms.rb +4 -0
  23. data/lib/erp_forms/dynamic_form_field.rb +31 -28
  24. data/lib/erp_forms/dynamic_grid_column.rb +2 -2
  25. data/lib/erp_forms/engine.rb +5 -0
  26. data/lib/erp_forms/extensions/active_record/acts_as_commentable.rb +33 -0
  27. data/lib/erp_forms/extensions/active_record/acts_as_dynamic_form_model.rb +80 -0
  28. data/lib/erp_forms/extensions/active_record/has_dynamic_forms.rb +4 -4
  29. data/lib/erp_forms/extensions/extensions.rb +2 -0
  30. data/lib/erp_forms/extensions/railties/action_view.rb +2 -2
  31. data/lib/erp_forms/version.rb +2 -2
  32. data/public/javascripts/erp_app/desktop/applications/dynamic_forms/center_region.js +2 -1
  33. data/public/javascripts/erp_app/desktop/applications/dynamic_forms/dynamic_data_grid.js +264 -82
  34. data/public/javascripts/erp_app/desktop/applications/dynamic_forms/form_builder.js +1476 -58
  35. data/public/javascripts/erp_app/desktop/applications/dynamic_forms/module.js +24 -1
  36. data/public/javascripts/erp_app/desktop/applications/dynamic_forms/west_region.js +493 -210
  37. data/public/javascripts/erp_app/shared/dynamic_forms/dynamic_form_fields.js +82 -20
  38. data/public/javascripts/erp_app/shared/dynamic_forms/dynamic_forms_validation.js +23 -3
  39. data/spec/dummy/config/application.rb +6 -2
  40. data/spec/dummy/config/environments/spec.rb +3 -0
  41. data/spec/dummy/db/data_migrations/20110109173616_create_capability_scope_types.erp_tech_svcs.rb +15 -0
  42. data/spec/dummy/db/data_migrations/20110525001935_add_usd_currency.erp_base_erp_svcs.rb +12 -0
  43. data/spec/dummy/db/data_migrations/20110608185830_create_default_dynamic_models_and_forms.erp_forms.rb +33 -0
  44. data/spec/dummy/db/data_migrations/20110609150135_add_iso_codes.erp_base_erp_svcs.rb +19 -0
  45. data/spec/dummy/db/data_migrations/20110728201729_erp_app_setup.erp_app.rb +252 -0
  46. data/spec/dummy/db/data_migrations/20110728201733_update_preferences.erp_app.rb +53 -0
  47. data/spec/dummy/db/data_migrations/20110802200222_schedule_delete_expired_sessions_job.erp_tech_svcs.rb +16 -0
  48. data/spec/dummy/db/data_migrations/20110816161238_create_desktop_app_audit_log_viewer.erp_app.rb +21 -0
  49. data/spec/dummy/db/data_migrations/20110817160743_add_file_manager_application.erp_app.rb +32 -0
  50. data/spec/dummy/db/data_migrations/20110828190913_create_desktop_app_dynamic_forms.erp_forms.rb +19 -0
  51. data/spec/dummy/db/data_migrations/20110913145838_setup_compass_ae_instance.erp_base_erp_svcs.rb +12 -0
  52. data/spec/dummy/db/data_migrations/20111108183739_add_default_capabilities.erp_app.rb +23 -0
  53. data/spec/dummy/db/data_migrations/20111108183740_add_new_contact_widgets.erp_app.rb +42 -0
  54. data/spec/dummy/db/data_migrations/20111111144706_setup_audit_log_types.erp_tech_svcs.rb +22 -0
  55. data/spec/dummy/db/data_migrations/20120109173616_create_download_capability_type.erp_tech_svcs.rb +14 -0
  56. data/spec/dummy/db/data_migrations/20120229160222_add_userinfo_widget.erp_app.rb +29 -0
  57. data/spec/dummy/db/data_migrations/20120405193721_create_party_and_role_type_for_communication_events.erp_app.rb +11 -0
  58. data/spec/dummy/db/data_migrations/20120411180756_create_user_management_mobile_application.erp_app.rb +19 -0
  59. data/spec/dummy/db/data_migrations/20120418164215_create_configuration_management_desktop_application.erp_app.rb +23 -0
  60. data/spec/dummy/db/data_migrations/20120824013449_create_ticket_form.erp_forms.rb +67 -0
  61. data/spec/dummy/db/data_migrations/20121026013449_update_ticket_form.erp_forms.rb +65 -0
  62. data/spec/dummy/db/data_migrations/20121026191738_update_contact_form.erp_forms.rb +27 -0
  63. data/spec/dummy/db/data_migrations/20121116155018_create_group_relationship_and_role_types.erp_tech_svcs.rb +20 -0
  64. data/spec/dummy/db/data_migrations/20121130201859_upgrade_remove_system_mgmt_app.erp_app.rb +16 -0
  65. data/spec/dummy/db/data_migrations/20121130212146_note_capabilities.erp_tech_svcs.rb +24 -0
  66. data/spec/dummy/db/data_migrations/20121218175028_create_security_management_desktop_application.erp_app.rb +23 -0
  67. data/spec/dummy/db/migrate/20121213234847_base_erp_services.erp_base_erp_svcs.rb +461 -0
  68. data/spec/dummy/db/migrate/20121213234848_base_tech_services.erp_tech_svcs.rb +255 -0
  69. data/spec/dummy/db/migrate/20121213234849_create_has_attribute_tables.erp_tech_svcs.rb +39 -0
  70. data/spec/dummy/db/migrate/20121213234850_base_app_framework.erp_app.rb +276 -0
  71. data/spec/dummy/db/migrate/20121213234851_dynamic_forms.erp_forms.rb +95 -0
  72. data/spec/dummy/db/migrate/20121213234852_create_tickets.erp_forms.rb +19 -0
  73. data/spec/dummy/db/migrate/20121213234853_upgrade_dynamic_forms_table.erp_forms.rb +32 -0
  74. data/spec/dummy/db/migrate/20130107181041_create_groups.erp_tech_svcs.rb +19 -0
  75. data/spec/dummy/db/migrate/20130107181042_upgrade_security.erp_tech_svcs.rb +54 -0
  76. data/spec/dummy/db/migrate/20130107181043_upgrade_security2.erp_tech_svcs.rb +270 -0
  77. data/spec/dummy/db/schema.rb +879 -0
  78. data/spec/dummy/db/spec.sqlite3 +0 -0
  79. data/spec/dummy/log/spec.log +13580 -0
  80. data/spec/models/dynamic_form_model_spec.rb +1 -1
  81. data/spec/spec_helper.rb +11 -3
  82. metadata +136 -14
@@ -1,6 +1,9 @@
1
1
  class UpdateContactForm
2
2
 
3
3
  def self.up
4
+ model = DynamicFormModel.find_by_model_name('WebsiteInquiry')
5
+ model.create_role
6
+
4
7
  fields = []
5
8
 
6
9
  fields << DynamicFormField.textfield({:fieldLabel => 'First Name', :name => 'first_name', :width => 250, :allowBlank => false })
@@ -11,6 +14,7 @@ class UpdateContactForm
11
14
  d = DynamicForm.find_by_internal_identifier('contact_us')
12
15
  unless d.nil?
13
16
  d.definition = fields.to_json
17
+ d.msg_target = 'qtip'
14
18
  d.save
15
19
  end
16
20
  end
@@ -3,6 +3,10 @@ class DynamicForms < ActiveRecord::Migration
3
3
  unless table_exists?(:dynamic_form_models)
4
4
  create_table :dynamic_form_models do |t|
5
5
  t.string :model_name
6
+ t.boolean :show_in_multitask, :default => false
7
+ t.boolean :allow_comments, :default => true
8
+ t.boolean :allow_files, :default => true
9
+ t.string :file_security_default, :default => 'private'
6
10
 
7
11
  t.timestamps
8
12
  end
@@ -28,6 +32,14 @@ class DynamicForms < ActiveRecord::Migration
28
32
  t.string :model_name
29
33
  t.string :internal_identifier
30
34
  t.boolean :default
35
+ t.string :widget_action, :default => 'save'
36
+ t.string :widget_email_recipients
37
+ t.boolean :focus_first_field, :default => true
38
+ t.boolean :submit_empty_text, :default => false
39
+ t.string :msg_target, :default => 'qtip'
40
+ t.string :submit_button_label, :default => 'Submit'
41
+ t.string :cancel_button_label, :default => 'Cancel'
42
+ t.text :comment
31
43
 
32
44
  t.integer :created_by_id
33
45
  t.integer :updated_by_id
@@ -0,0 +1,31 @@
1
+ class UpgradeDynamicFormsTable < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :dynamic_form_models, :show_in_multitask, :boolean, :default => false unless columns(:dynamic_form_models).collect {|c| c.name}.include?('show_in_multitask')
4
+ add_column :dynamic_form_models, :allow_comments, :boolean, :default => true unless columns(:dynamic_form_models).collect {|c| c.name}.include?('allow_comments')
5
+ add_column :dynamic_form_models, :allow_files, :boolean, :default => true unless columns(:dynamic_form_models).collect {|c| c.name}.include?('allow_files')
6
+ add_column :dynamic_form_models, :file_security_default, :string, :default => 'private' unless columns(:dynamic_form_models).collect {|c| c.name}.include?('file_security_default')
7
+ add_column :dynamic_forms, :widget_action, :string, :default => 'save' unless columns(:dynamic_forms).collect {|c| c.name}.include?('widget_action')
8
+ add_column :dynamic_forms, :widget_email_recipients, :string unless columns(:dynamic_forms).collect {|c| c.name}.include?('widget_email_recipients')
9
+ add_column :dynamic_forms, :focus_first_field, :boolean, :default => true unless columns(:dynamic_forms).collect {|c| c.name}.include?('focus_first_field')
10
+ add_column :dynamic_forms, :submit_empty_text, :boolean, :default => false unless columns(:dynamic_forms).collect {|c| c.name}.include?('submit_empty_text')
11
+ add_column :dynamic_forms, :msg_target, :string, :default => 'qtip' unless columns(:dynamic_forms).collect {|c| c.name}.include?('msg_target')
12
+ add_column :dynamic_forms, :submit_button_label, :string, :default => 'Submit' unless columns(:dynamic_forms).collect {|c| c.name}.include?('submit_button_label')
13
+ add_column :dynamic_forms, :cancel_button_label, :string, :default => 'Cancel' unless columns(:dynamic_forms).collect {|c| c.name}.include?('cancel_button_label')
14
+ add_column :dynamic_forms, :comment, :text unless columns(:dynamic_forms).collect {|c| c.name}.include?('comment')
15
+ end
16
+
17
+ def self.down
18
+ remove_column :dynamic_form_models, :show_in_multitask if columns(:dynamic_form_models).collect {|c| c.name}.include?('show_in_multitask')
19
+ remove_column :dynamic_form_models, :file_security_default if columns(:dynamic_form_models).collect {|c| c.name}.include?('file_security_default')
20
+ remove_column :dynamic_form_models, :allow_files if columns(:dynamic_form_models).collect {|c| c.name}.include?('allow_files')
21
+ remove_column :dynamic_form_models, :allow_comments if columns(:dynamic_form_models).collect {|c| c.name}.include?('allow_comments')
22
+ remove_column :dynamic_forms, :widget_action if columns(:dynamic_forms).collect {|c| c.name}.include?('widget_action')
23
+ remove_column :dynamic_forms, :widget_email_recipients if columns(:dynamic_forms).collect {|c| c.name}.include?('widget_email_recipients')
24
+ remove_column :dynamic_forms, :focus_first_field if columns(:dynamic_forms).collect {|c| c.name}.include?('focus_first_field')
25
+ remove_column :dynamic_forms, :submit_empty_text if columns(:dynamic_forms).collect {|c| c.name}.include?('submit_empty_text')
26
+ remove_column :dynamic_forms, :msg_target if columns(:dynamic_forms).collect {|c| c.name}.include?('msg_target')
27
+ remove_column :dynamic_forms, :submit_button_label if columns(:dynamic_forms).collect {|c| c.name}.include?('submit_button_label')
28
+ remove_column :dynamic_forms, :cancel_button_label if columns(:dynamic_forms).collect {|c| c.name}.include?('cancel_button_label')
29
+ remove_column :dynamic_forms, :comment if columns(:dynamic_forms).collect {|c| c.name}.include?('comment')
30
+ end
31
+ end
@@ -1,5 +1,9 @@
1
1
  #compass libraries
2
+ require 'erp_base_erp_svcs'
2
3
  require 'erp_tech_svcs'
4
+ require 'erp_app'
5
+
6
+ require "friendly_id"
3
7
 
4
8
  require 'erp_forms/version'
5
9
  require 'erp_forms/dynamic_form_field'
@@ -6,7 +6,6 @@ class DynamicFormField
6
6
  Field Types TODO
7
7
  special:
8
8
  codemirror
9
- file upload - use has_file_assets and plupload
10
9
  test password field
11
10
 
12
11
  complex (for future implementation):
@@ -23,14 +22,13 @@ class DynamicFormField
23
22
  # :readOnly => disabled true or false
24
23
  # :maxLength => maxLength integer
25
24
  # :width => size integer
26
- # :validation_regex => regex string
27
25
  # }
28
26
 
29
27
  ##################
30
28
  # SPECIAL FIELDS #
31
29
  ##################
32
30
  def self.email(options={})
33
- options[:validation_regex] = "^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$"
31
+ options[:validator_function] = 'validateEmail(v)'
34
32
  DynamicFormField.basic_field('textfield', options)
35
33
  end
36
34
 
@@ -71,8 +69,6 @@ class DynamicFormField
71
69
  { :name => displayField }
72
70
  ]
73
71
 
74
- options[:url] = '/erp_forms/erp_app/desktop/dynamic_forms/forms/related_field' if options[:url].blank?
75
-
76
72
  DynamicFormField.basic_field('related_combobox', options)
77
73
  end
78
74
 
@@ -137,10 +133,19 @@ class DynamicFormField
137
133
  DynamicFormField.basic_field('checkbox', options)
138
134
  end
139
135
 
136
+ def self.filefield(options={})
137
+ DynamicFormField.basic_field('filefield', options)
138
+ end
139
+
140
+ def self.hiddenfield(options={})
141
+ DynamicFormField.basic_field('hiddenfield', options)
142
+ end
143
+
144
+ # alias
140
145
  def self.hidden(options={})
141
- DynamicFormField.basic_field('hidden', options)
146
+ DynamicFormField.hiddenfield(options={})
142
147
  end
143
-
148
+
144
149
  def self.basic_field(xtype, options={}, selections=[])
145
150
  options = DynamicFormField.set_default_field_options(options)
146
151
 
@@ -154,53 +159,51 @@ class DynamicFormField
154
159
  :width =>options[:width],
155
160
  :height => options[:height],
156
161
  :labelWidth => options[:labelWidth],
157
- :display_in_grid => options[:display_in_grid]
162
+ :display_in_grid => options[:display_in_grid],
163
+ :searchable => options[:display_in_grid]
158
164
  }
159
165
 
166
+ field[:buttonText] = options[:buttonText] unless options[:buttonText].blank?
160
167
  field[:displayField] = options[:displayField] unless options[:displayField].blank?
168
+ field[:disabled] = options[:disabled] unless options[:disabled].nil?
169
+ field[:editable] = options[:editable] unless options[:editable].nil?
170
+ field[:emptyText] = options[:emptyText] unless options[:emptyText].blank?
161
171
  field[:extraParams] = options[:extraParams] unless options[:extraParams].blank?
162
- field[:url] = options[:url] unless options[:url].blank?
163
172
  field[:fields] = options[:fields] unless options[:fields].blank?
173
+ field[:forceSelection] = options[:forceSelection] unless options[:forceSelection].nil?
174
+ field[:hidden] = options[:hidden] unless options[:hidden].nil?
175
+ field[:hideTrigger] = options[:hideTrigger] unless options[:hideTrigger].nil?
176
+ field[:hideMode] = options[:hideMode] unless options[:hideMode].blank?
177
+ field[:labelAlign] = options[:labelAlign] unless options[:labelAlign].blank?
164
178
  field[:mapping] = options[:mapping] unless options[:mapping].blank?
165
179
  field[:minLength] = options[:minLength] unless options[:minLength].nil?
166
180
  field[:maxLength] = options[:maxLength] unless options[:maxLength].nil?
167
181
  field[:minValue] = options[:minValue] unless options[:minValue].nil?
168
182
  field[:maxValue] = options[:maxValue] unless options[:maxValue].nil?
169
- field[:hideTrigger] = options[:hideTrigger] unless options[:hideTrigger].nil?
170
-
171
- if selections and selections != []
172
- field[:store] = selections
173
- end
174
-
175
- if !options[:validation_regex].blank? or !options[:validator_function].blank?
176
- field[:validateOnBlur] = true
177
- end
178
-
179
- if options[:validation_regex] and options[:validation_regex] != ''
180
- field[:validation_regex] = options[:validation_regex]
181
- end
183
+ field[:msgTarget] = options[:msgTarget] unless options[:msgTarget].blank?
184
+ field[:regexText] = options[:regexText] unless options[:regexText].blank?
185
+ field[:url] = options[:url] unless options[:url].blank?
186
+ field[:vtype] = options[:vtype] unless options[:vtype].blank?
187
+ field[:validation_regex] = options[:validation_regex] unless options[:validation_regex].blank?
188
+ field[:validator_function] = options[:validator_function] unless options[:validator_function].blank?
182
189
 
183
- if options[:validator_function] and options[:validator_function] != ''
184
- field[:validator_function] = options[:validator_function]
185
- end
190
+ field[:store] = selections if selections and selections != []
186
191
 
187
192
  field
188
193
  end
189
194
 
190
195
  def self.set_default_field_options(options={})
191
-
192
196
  options[:fieldLabel] = '' if options[:fieldLabel].nil?
193
197
  options[:name] = '' if options[:name].nil?
194
198
  options[:allowBlank] = true if options[:allowBlank].nil?
195
- options[:value] = '' if options[:value].nil?
196
199
  options[:readOnly] = false if options[:readOnly].nil?
197
200
  options[:minLength] = nil if options[:minLength].nil?
198
201
  options[:maxLength] = nil if options[:maxLength].nil?
199
202
  options[:width] = 200 if options[:width].nil?
200
203
  options[:height] = nil if options[:height].nil?
201
- options[:validation_regex] = '' if options[:validation_regex].nil?
202
204
  options[:labelWidth] = 75 if options[:labelWidth].nil?
203
205
  options[:display_in_grid] = true if options[:display_in_grid].nil?
206
+ options[:searchable] = true if options[:searchable].nil?
204
207
 
205
208
  options
206
209
  end
@@ -14,8 +14,8 @@ class DynamicGridColumn
14
14
  :dataIndex => data_index,
15
15
  :sortable => sortable
16
16
  }
17
-
18
- col[:width] = field_hash[:width] if field_hash[:width]
17
+
18
+ col[:width] = field_hash[:width] unless field_hash[:width].nil?
19
19
  col[:renderer] = renderer unless renderer.blank?
20
20
 
21
21
  if field_hash[:editor]
@@ -9,8 +9,10 @@ module ErpForms
9
9
  end
10
10
 
11
11
  ActiveSupport.on_load(:active_record) do
12
+ include ErpForms::Extensions::ActiveRecord::ActsAsDynamicFormModel
12
13
  include ErpForms::Extensions::ActiveRecord::HasDynamicData
13
14
  include ErpForms::Extensions::ActiveRecord::HasDynamicForms
15
+ include ErpForms::Extensions::ActiveRecord::ActsAsCommentable
14
16
  end
15
17
 
16
18
  ErpBaseErpSvcs.register_as_compass_ae_engine(config, self)
@@ -19,6 +21,9 @@ module ErpForms
19
21
  config.to_prepare do
20
22
  #dynamic_attributes patch
21
23
  require "erp_forms/dynamic_attributes_patch"
24
+
25
+ # setup sunspot for all dynamic form models if we're using solr
26
+ DynamicFormModel.sunspot_setup_all if ($USE_SOLR_FOR_DYNAMIC_FORM_MODELS && ActiveRecord::Base.connection.table_exists?('dynamic_form_models'))
22
27
  end
23
28
 
24
29
  end
@@ -0,0 +1,33 @@
1
+ module ErpForms
2
+ module Extensions
3
+ module ActiveRecord
4
+ module ActsAsCommentable
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+
11
+ def acts_as_commentable
12
+ has_many :comments, :as => :commented_record, :dependent => :destroy
13
+
14
+ extend ActsAsCommentable::SingletonMethods
15
+ include ActsAsCommentable::InstanceMethods
16
+ end
17
+
18
+ end
19
+
20
+ module SingletonMethods
21
+ end
22
+
23
+ module InstanceMethods
24
+
25
+ def add_comment(options={})
26
+ self.comments.create(options)
27
+ end
28
+
29
+ end
30
+ end #ActsAsCommentable
31
+ end #ActiveRecord
32
+ end #Extensions
33
+ end #Knitkit
@@ -0,0 +1,80 @@
1
+ module ErpForms
2
+ module Extensions
3
+ module ActiveRecord
4
+ module ActsAsDynamicFormModel
5
+
6
+ def self.included(base)
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+
12
+ def acts_as_dynamic_form_model
13
+ include ActsAsDynamicFormModel::InstanceMethods
14
+ end
15
+
16
+ end
17
+
18
+ module InstanceMethods
19
+
20
+ def dynamic_model
21
+ self.respond_to?(:dynamic_form_model) ? dynamic_form_model : DynamicFormModel.find_by_model_name(self.class.name)
22
+ end
23
+
24
+ def role_iid
25
+ dynamic_model.role_iid
26
+ end
27
+
28
+ def role
29
+ dynamic_model.role
30
+ end
31
+
32
+ def allow_comments?
33
+ dynamic_model.allow_comments
34
+ end
35
+
36
+ def allow_files?
37
+ dynamic_model.allow_files
38
+ end
39
+
40
+ def file_security_default
41
+ dynamic_model.file_security_default
42
+ end
43
+
44
+ def show_in_multitask
45
+ dynamic_model.show_in_multitask
46
+ end
47
+
48
+ # handles both static and dynamic attributes
49
+ def assign_all_attributes(params, ignored_params=[])
50
+ params.each do |k,v|
51
+ k = k.to_s
52
+ unless ignored_params.include?(k) or k == '' or k == '_'
53
+ if self.attributes.include?(k)
54
+ self.send(k + '=', v)
55
+ else
56
+ if ['created_by','updated_by','created_at','updated_at','created_with_form_id','updated_with_form_id'].include?(k)
57
+ key = k + '='
58
+ else
59
+ key = DynamicDatum::DYNAMIC_ATTRIBUTE_PREFIX + k + '='
60
+ end
61
+
62
+ self.data.send(key, v)
63
+ end
64
+ end
65
+ end
66
+
67
+ self
68
+ end
69
+
70
+ # handles both static and dynamic attributes
71
+ def save_all_attributes(params, ignored_params=[])
72
+ self.assign_all_attributes(params, ignored_params)
73
+ (self.valid? and self.save) ? self : nil
74
+ end
75
+
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -15,8 +15,8 @@ module ErpForms
15
15
  include HasDynamicForms::InstanceMethods
16
16
 
17
17
  def set_default(form_id)
18
- DynamicForm.update_all({ :default => false }, conditions={ :model_name => self.class_name.to_s })
19
- DynamicForm.update_all({ :default => true }, conditions={ :id => form_id })
18
+ DynamicForm.update_all({ :default => false }, { :model_name => self.name })
19
+ DynamicForm.update_all({ :default => true }, { :id => form_id })
20
20
  end
21
21
  end
22
22
 
@@ -59,8 +59,8 @@ module ErpForms
59
59
  end
60
60
 
61
61
  def set_default(internal_identifier)
62
- DynamicForm.update_all('default=0', conditions="model_name=#{self.class.to_s}")
63
- DynamicForm.update_all('default=1', conditions="model_name=#{self.class.to_s} AND internal_identifier=#{internal_identifier}")
62
+ DynamicForm.update_all({:default => false}, "model_name=#{self.class.to_s}")
63
+ DynamicForm.update_all({:default => true}, "model_name=#{self.class.to_s} AND internal_identifier=#{internal_identifier}")
64
64
  end
65
65
 
66
66
  end
@@ -2,5 +2,7 @@
2
2
  require 'erp_forms/extensions/railties/action_view'
3
3
 
4
4
  #active_record extensions
5
+ require 'erp_forms/extensions/active_record/acts_as_commentable'
6
+ require 'erp_forms/extensions/active_record/acts_as_dynamic_form_model'
5
7
  require 'erp_forms/extensions/active_record/has_dynamic_data'
6
8
  require 'erp_forms/extensions/active_record/has_dynamic_forms'
@@ -7,7 +7,7 @@ ActionView::Base.class_eval do
7
7
  # :width => 'width of form in pixels'
8
8
  # }
9
9
  def render_dynamic_form(name, options={})
10
- output = raw '&nbsp<script type="text/javascript">'
10
+ output = raw '&nbsp<script type="text/javascript">Ext.onReady(function() {'
11
11
  output += raw "Compass.ErpApp.Utility.JsLoader.load(['/javascripts/erp_app/shared/dynamic_forms/dynamic_form_fields.js'], function(){"
12
12
 
13
13
  output += raw DynamicForm.get_form(name.to_s, options[:internal_identifier]).to_extjs_widget(
@@ -16,7 +16,7 @@ ActionView::Base.class_eval do
16
16
  :width => options[:width]
17
17
  })
18
18
 
19
- output += raw '});</script>'
19
+ output += raw '}); });</script>'
20
20
  output
21
21
  end
22
22
 
@@ -1,8 +1,8 @@
1
1
  module ErpForms
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 2
4
- MINOR = 0
5
- TINY = 6
4
+ MINOR = 1
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
8
8
  end
@@ -3,7 +3,8 @@ Ext.define("Compass.ErpApp.Desktop.Applications.DynamicForms.CenterRegion",{
3
3
  alias:'widget.dynamic_forms_centerregion',
4
4
 
5
5
  constructor : function(config) {
6
- this.workArea = new Ext.TabPanel({
6
+ this.workArea = Ext.create('Ext.tab.Panel',{
7
+ id: 'dynamic_formsTabPanel',
7
8
  autoDestroy:true,
8
9
  region:'center'
9
10
  });
@@ -1,3 +1,110 @@
1
+ Ext.define("Compass.ErpApp.Desktop.Applications.DynamicForms.FileTree",{
2
+ extend: "Compass.ErpApp.Shared.FileManagerTree",
3
+ alias: 'widget.dynamic_forms_DynamicFormsFileTree',
4
+ loadMask: true,
5
+ autoLoadRoot:false,
6
+ collapsible:false,
7
+ title:'Files',
8
+ rootText:'Files',
9
+ allowDownload:true,
10
+ addViewContentsToContextMenu:false,
11
+ rootVisible:true,
12
+ multiSelect:true,
13
+ containerScroll: true,
14
+ listeners:{
15
+ 'load':function(store){
16
+ store.getRootNode().expand();
17
+ },
18
+ 'allowdelete':function(){
19
+ return true;
20
+ },
21
+ 'allowupload':function(){
22
+ return true;
23
+ },
24
+ 'itemclick':function(view, record, item, index, e){
25
+ e.stopEvent();
26
+ return false;
27
+ },
28
+ 'fileDeleted':function(fileTreePanel, node){},
29
+ 'fileUploaded':function(fileTreePanel, node){},
30
+ 'downloadfile':function(fileTreePanel, node){
31
+ window.open("/download/"+node.data.text+"?path=" + node.data.downloadPath,'mywindow','width=400,height=200');
32
+ return false;
33
+ }
34
+ },
35
+
36
+ changeSecurityOnFile : function(node, secure, fileTree){
37
+ var msg = secure ? 'Securing file...' : 'Unsecuring file...';
38
+ var waitMsg = Ext.Msg.wait("Please Wait", msg);
39
+ Ext.Ajax.request({
40
+ url: '/erp_forms/erp_app/desktop/dynamic_forms/data/update_file_security',
41
+ method: 'POST',
42
+ params:{
43
+ path: node.get('id'),
44
+ secure: secure,
45
+ model_name: fileTree.extraPostData.model_name,
46
+ id: fileTree.extraPostData.id
47
+ },
48
+ success: function(response) {
49
+ var obj = Ext.decode(response.responseText);
50
+ if(obj.success){
51
+ waitMsg.hide();
52
+ if(secure){
53
+ node.set('iconCls', 'icon-document_lock');
54
+ }
55
+ else{
56
+ node.set('iconCls', 'icon-document');
57
+ }
58
+ node.set('isSecured',secure);
59
+ node.commit();
60
+ }
61
+ else{
62
+ Ext.Msg.alert('Error', 'Error securing file.');
63
+ }
64
+ },
65
+ failure: function(response) {
66
+ waitMsg.hide();
67
+ Ext.Msg.alert('Error', 'Error securing file.');
68
+ }
69
+ });
70
+ },
71
+
72
+ constructor:function (config) {
73
+ var self = this;
74
+
75
+ config = Ext.apply({
76
+ autoDestroy:true,
77
+ title: 'Files',
78
+ itemId: config.itemId,
79
+ region: config.region,
80
+ margins: 0,
81
+ autoScroll: true,
82
+ autoLoadRoot:false,
83
+ showNewFileMenuItem:false,
84
+ showNewFolderMenuItem:false,
85
+ showRenameMenuItem:false,
86
+ enableViewContents:false,
87
+ additionalContextMenuItems:[{
88
+ nodeType:'leaf',
89
+ text:'Update Security',
90
+ iconCls:'icon-document_lock',
91
+ listeners:{
92
+ scope:self,
93
+ 'click':function(){
94
+ var node = self.selectedNode;
95
+ self.changeSecurityOnFile(node, !node.get('isSecured'), self);
96
+ }
97
+ }
98
+ }],
99
+ controllerPath:'/erp_forms/erp_app/desktop/dynamic_forms/data',
100
+ standardUploadUrl:'/erp_forms/erp_app/desktop/dynamic_forms/data/upload_file',
101
+ url:'/erp_forms/erp_app/desktop/dynamic_forms/data/get_files'
102
+ }, config);
103
+
104
+ this.callParent([config]);
105
+ }
106
+ });
107
+
1
108
  Ext.define("Compass.ErpApp.Desktop.Applications.DynamicForms.DynamicDataGridPanel",{
2
109
  extend:"Compass.ErpApp.Shared.DynamicEditableGridLoaderPanel",
3
110
  alias:'widget.dynamic_forms_DynamicDataGridPanel',
@@ -17,7 +124,6 @@ Ext.define("Compass.ErpApp.Desktop.Applications.DynamicForms.DynamicDataGridPane
17
124
  listeners:{
18
125
  'click':function(button){
19
126
  var formPanel = button.findParentByType('form');
20
- //self.setWindowStatus('Adding Comment ...');
21
127
  formPanel.getForm().submit({
22
128
  params:{
23
129
  id:record_id,
@@ -25,25 +131,24 @@ Ext.define("Compass.ErpApp.Desktop.Applications.DynamicForms.DynamicDataGridPane
25
131
  },
26
132
  reset:false,
27
133
  success:function(form, action){
28
- //self.clearWindowStatus();
29
134
  var obj = Ext.decode(action.response.responseText);
30
135
  if(obj.success){
31
- var randomnumber=Math.floor(Math.random()*1024)
136
+ var randomnumber = Math.floor(Math.random()*1024);
32
137
  var target_div = 'new-comment-'+randomnumber;
33
138
  string = '<div id="'+target_div+'" class="comment">';
34
139
  string += '<i>by you, just now</i><br />';
35
140
  string += formPanel.getForm().findField('comment').getValue();
36
141
  string += '</div>';
37
142
  document.getElementById(comment_div_id).innerHTML += string;
38
- Ext.getCmp('commentWindow_'+model_name+record_id).close();
143
+ button.findParentByType('window').close();
39
144
  codemirrorHighlight(target_div);
145
+ Ext.getCmp('commentsPanel'+model_name+record_id).doLayout();
40
146
  }
41
147
  else{
42
148
  Ext.Msg.alert("Error", obj.msg);
43
149
  }
44
150
  },
45
151
  failure:function(form, action){
46
- //self.clearWindowStatus();
47
152
  var obj = Ext.decode(action.response.responseText);
48
153
  if(Compass.ErpApp.Utility.isBlank(obj.message)){
49
154
  Ext.Msg.alert("Error", 'Error adding comment.');
@@ -56,7 +161,7 @@ Ext.define("Compass.ErpApp.Desktop.Applications.DynamicForms.DynamicDataGridPane
56
161
  }
57
162
  }
58
163
  }]
59
- }
164
+ };
60
165
 
61
166
  var commentWindow = Ext.create('Ext.window.Window',{
62
167
  id: 'commentWindow_'+model_name+record_id,
@@ -65,145 +170,224 @@ Ext.define("Compass.ErpApp.Desktop.Applications.DynamicForms.DynamicDataGridPane
65
170
  autoDestroy:true
66
171
  });
67
172
 
68
- commentWindow.show();
69
-
173
+ commentWindow.show();
70
174
  },
71
175
 
72
- viewRecord : function(rec, gridpanel_id){
176
+ viewRecord : function(rec, formPanel){
73
177
  var self = this;
74
- Ext.getCmp('westregionPanel').setWindowStatus('Getting data ...');
178
+ var gridpanel_id = self.id;
179
+ var record_id = (Ext.isEmpty(rec.model_name) ? rec.get("id") : rec.id);
180
+ var model_name = (Ext.isEmpty(rec.model_name) ? rec.get("model_name") : rec.model_name);
181
+
182
+ // check and see if tab already open
183
+ var center_region = self.findParentByType('dynamic_forms_centerregion');
184
+ var tab = center_region.workArea.query('#'+model_name+'-'+record_id).first();
185
+ if (tab){
186
+ center_region.workArea.setActiveTab(center_region.workArea.items.length - 1);
187
+ return;
188
+ }
189
+
190
+ Ext.getCmp('dynamic_forms_westregion').setWindowStatus('Getting data ...');
75
191
  Ext.Ajax.request({
76
192
  url: '/erp_forms/erp_app/desktop/dynamic_forms/data/get',
77
193
  method: 'POST',
78
194
  params:{
79
- id:rec.get("id"),
80
- model_name:rec.get("model_name")
195
+ id:record_id,
196
+ model_name:model_name
81
197
  },
82
198
  success: function(response) {
83
- Ext.getCmp('westregionPanel').clearWindowStatus();
199
+ Ext.getCmp('dynamic_forms_westregion').clearWindowStatus();
84
200
  var response_text = Ext.decode(response.responseText);
85
201
  var center_region = self.findParentByType('dynamic_forms_centerregion');
86
-
87
202
  var ticket_div_id = gridpanel_id+'_ticket';
88
203
 
89
- string = '<div id="'+ticket_div_id+'" style="padding: 10px;">';
90
- string += '<div class="metadata">';
91
- string += 'Created by '+response_text.metadata.created_username+' at '+response_text.metadata.created_at+'<br/>';
92
- string += 'Updated';
93
- if (response_text.metadata.updated_username){
94
- string += ' by '+response_text.metadata.updated_username;
95
- }
96
- if (response_text.metadata.updated_at){
97
- string += ' at '+response_text.metadata.updated_at;
98
- }
99
- string += '</div>';
100
- for(var index in response_text.data) {
101
- string += '<b>'+ index + ':</b> ' + response_text.data[index] + '<br />';
204
+ var leftPanelItems = [formPanel];
205
+
206
+ //comments
207
+ if (response_text.comments){
208
+ var comment_div_id = gridpanel_id+'_comments';
209
+ comments_string = '<div id="'+comment_div_id+'" class="comments">';
210
+ Ext.each(response_text.comments, function(comment){
211
+ comments_string += '<div class="comment">';
212
+ comments_string += '<i>by '+comment.commentor_name+ ', '+comment.created_at+'</i><br />';
213
+ comments_string += comment.comment;
214
+ comments_string += '</div>';
215
+ });
216
+ comments_string += '</div>';
217
+
218
+ var commentsPanel = {
219
+ id: 'commentsPanel'+model_name+record_id,
220
+ xtype: 'panel',
221
+ title: 'Comments',
222
+ html: comments_string,
223
+ tbar: [{
224
+ xtype: 'button',
225
+ text: 'Add Comment',
226
+ iconCls: 'icon-add',
227
+ listeners:{
228
+ click: function(button){
229
+ Ext.getCmp(gridpanel_id).addCommentWindow(record_id, model_name, comment_div_id);
230
+ }
231
+ }
232
+ }]
233
+ };
234
+ leftPanelItems.push(commentsPanel);
102
235
  }
103
- string += '</div>';
104
236
 
105
- var comment_div_id = gridpanel_id+'_comments';
237
+ var leftPanel = {
238
+ xtype: 'panel',
239
+ autoScroll: true,
240
+ items: leftPanelItems,
241
+ region: 'center'
242
+ };
106
243
 
107
- if (response_text.comments){
108
- string += '<div id="'+comment_div_id+'" class="comments"><h1>Comments ';
109
- string += '<a onclick="javascript: Ext.getCmp(\''+gridpanel_id+'\').addCommentWindow('+rec.get("id")+',\''+rec.get("model_name")+'\',\''+comment_div_id+'\');" href="#">Add Comment</a></h1>';
244
+ var metaDataPanel = {
245
+ xtype: 'form',
246
+ title: 'MetaData',
247
+ bodyPadding: 10,
248
+ items:[
249
+ {
250
+ xtype: 'displayfield',
251
+ fieldLabel: 'Created By',
252
+ value: response_text.metadata.created_username
253
+ },
254
+ {
255
+ xtype: 'displayfield',
256
+ fieldLabel: 'Created At',
257
+ value: response_text.metadata.created_at
258
+ },
259
+ {
260
+ xtype: 'displayfield',
261
+ fieldLabel: 'Updated By',
262
+ value: response_text.metadata.updated_username
263
+ },
264
+ {
265
+ xtype: 'displayfield',
266
+ fieldLabel: 'Updated At',
267
+ value: response_text.metadata.updated_at
268
+ }
269
+ ]
270
+ };
110
271
 
111
- Ext.each(response_text.comments, function(comment){
112
- string += '<div class="comment">';
113
- string += '<i>by '+comment.commentor_name+ ', '+comment.created_at+'</i><br />';
114
- string += comment.comment;
115
- string += '</div>';
272
+ var rightPanelItems = [metaDataPanel];
273
+
274
+ if (response_text.has_file_assets){
275
+ var fileTree = Ext.create('Compass.ErpApp.Desktop.Applications.DynamicForms.FileTree', {
276
+ width: 250,
277
+ minHeight: 800,
278
+ listeners:{
279
+ 'beforeload':function(store){
280
+ store.getProxy().extraParams.id = record_id;
281
+ store.getProxy().extraParams.model_name = model_name;
282
+ },
283
+ 'load':function(store){
284
+ store.getRootNode().expand();
285
+ },
286
+ 'afterrender':function(panel){
287
+ setTimeout(function(){
288
+ panel.getStore().load();
289
+ },100);
290
+ }
291
+ }
116
292
  });
117
-
118
- string += '</div>';
293
+ fileTree.extraPostData = {
294
+ id: record_id,
295
+ model_name: model_name
296
+ };
297
+
298
+ rightPanelItems.push(fileTree);
119
299
  }
120
300
 
121
- var viewPanel = {
301
+ var rightPanel = {
122
302
  xtype: 'panel',
123
- title: rec.get("model_name")+' '+rec.get("id"),
303
+ items: rightPanelItems,
304
+ region: 'east',
305
+ width: 250
306
+ };
307
+
308
+ var viewPanel = Ext.create('Ext.panel.Panel',{
309
+ itemId: model_name+'-'+record_id,
310
+ layout: 'border',
311
+ title: model_name+' '+record_id,
124
312
  closable: true,
125
313
  autoScroll: true,
126
- record: rec,
127
- html: string,
128
- items: [],
314
+ record: rec,
315
+ items: [leftPanel, rightPanel],
129
316
  listeners:{
130
- 'afterrender':function(){
317
+ 'afterrender':function(panel){
131
318
  codemirrorHighlight(ticket_div_id);
132
319
  codemirrorHighlight(comment_div_id);
133
- }
320
+ panel.query('dynamic_form_panel').first().addListener('afterupdate', function(){
321
+ // update status bar with save message
322
+ // reload grid
323
+ var tabPanel = panel.findParentByType('tabpanel');
324
+ tabPanel.query('#'+model_name).first().query('shared_dynamiceditablegrid').first().getStore().load({});
325
+ });
326
+ }
134
327
  }
135
- }
136
-
328
+ });
137
329
  center_region.workArea.add(viewPanel);
330
+ viewPanel.query('form').first().getForm().loadRecord(response_text);
138
331
  center_region.workArea.setActiveTab(center_region.workArea.items.length - 1);
139
332
  },
140
333
  failure: function(response) {
141
- Ext.getCmp('westregionPanel').clearWindowStatus();
334
+ Ext.getCmp('dynamic_forms_westregion').clearWindowStatus();
142
335
  Ext.Msg.alert('Error', 'Error getting data');
143
336
  }
144
337
  });
145
338
  },
146
-
147
- editRecord : function(rec, model_name){
339
+
340
+ editRecord : function(rec){
148
341
  var self = this;
149
- Ext.getCmp('westregionPanel').setWindowStatus('Getting update form...');
342
+ Ext.getCmp('dynamic_forms_westregion').setWindowStatus('Getting update form...');
150
343
  Ext.Ajax.request({
151
344
  url: '/erp_forms/erp_app/desktop/dynamic_forms/forms/get',
152
345
  method: 'POST',
153
- params:{
154
- id:rec.get("form_id"),
155
- record_id:rec.get("id"),
156
- model_name:model_name,
346
+ params:{ // params can come from create response or grid store
347
+ id:(Ext.isEmpty(rec.model_name) ? rec.get("form_id") : rec.form_id),
348
+ record_id:(Ext.isEmpty(rec.model_name) ? rec.get("id") : rec.id),
349
+ model_name:(Ext.isEmpty(rec.model_name) ? rec.get("model_name") : rec.model_name),
157
350
  form_action: 'update'
158
351
  },
159
- success: function(response) {
160
- Ext.getCmp('westregionPanel').clearWindowStatus();
161
- form_definition = Ext.decode(response.responseText);
162
- if (form_definition.success == false){
163
- Ext.Msg.alert('Error', form_definition.error);
352
+ success: function(response, options){
353
+ Ext.getCmp('dynamic_forms_westregion').clearWindowStatus();
354
+ formPanel = Ext.decode(response.responseText);
355
+ if (formPanel.success === false){
356
+ Ext.Msg.alert('Error', formPanel.error);
164
357
  }else{
165
- var editRecordWindow = Ext.create("Ext.window.Window",{
166
- layout:'fit',
167
- title:'Update Record',
168
- y: 100, // this fixes chrome and safari rendering the window at the bottom of the screen
169
- plain: true,
170
- buttonAlign:'center',
171
- items: form_definition
172
- });
173
- Ext.getCmp('dynamic_form_panel_'+model_name).getForm().loadRecord(rec);
174
- editRecordWindow.show();
358
+ self.viewRecord(rec, formPanel);
175
359
  }
176
360
  },
177
- failure: function(response) {
178
- Ext.getCmp('westregionPanel').clearWindowStatus();
361
+ failure: function(response, options){
362
+ Ext.getCmp('dynamic_forms_westregion').clearWindowStatus();
179
363
  Ext.Msg.alert('Error', 'Error getting form');
180
364
  }
181
365
  });
182
- },
366
+ },
183
367
 
184
368
  deleteRecord : function(rec, model_name){
185
369
  var self = this;
186
- Ext.getCmp('westregionPanel').setWindowStatus('Deleting record...');
370
+ Ext.getCmp('dynamic_forms_westregion').setWindowStatus('Deleting record...');
187
371
  Ext.Ajax.request({
188
372
  url: '/erp_forms/erp_app/desktop/dynamic_forms/data/delete',
189
373
  method: 'POST',
190
374
  params:{
191
375
  id:rec.get("id"),
192
- model_name:model_name
376
+ model_name:rec.get("model_name")
193
377
  },
194
378
  success: function(response) {
195
379
  var obj = Ext.decode(response.responseText);
196
380
  if(obj.success){
197
- Ext.getCmp('westregionPanel').clearWindowStatus();
381
+ Ext.getCmp('dynamic_forms_westregion').clearWindowStatus();
198
382
  self.query('shared_dynamiceditablegrid')[0].store.load();
199
383
  }
200
384
  else{
201
385
  Ext.Msg.alert('Error', 'Error deleting record');
202
- Ext.getCmp('westregionPanel').clearWindowStatus();
386
+ Ext.getCmp('dynamic_forms_westregion').clearWindowStatus();
203
387
  }
204
388
  },
205
389
  failure: function(response) {
206
- Ext.getCmp('westregionPanel').clearWindowStatus();
390
+ Ext.getCmp('dynamic_forms_westregion').clearWindowStatus();
207
391
  Ext.Msg.alert('Error', 'Error deleting record');
208
392
  }
209
393
  });
@@ -212,7 +396,6 @@ Ext.define("Compass.ErpApp.Desktop.Applications.DynamicForms.DynamicDataGridPane
212
396
  constructor : function(config) {
213
397
  config = Ext.apply({
214
398
  id:config.id,
215
- //title:'Dynamic Data',
216
399
  editable:false,
217
400
  page:true,
218
401
  pageSize: 20,
@@ -220,7 +403,7 @@ Ext.define("Compass.ErpApp.Desktop.Applications.DynamicForms.DynamicDataGridPane
220
403
  emptyMsg:'Empty',
221
404
  grid_listeners:{
222
405
  'itemdblclick':function(view, record){
223
- Ext.getCmp(config.id).viewRecord(record, config.id);
406
+ Ext.getCmp(config.id).editRecord(record);
224
407
  }
225
408
  }
226
409
  }, config);
@@ -228,4 +411,3 @@ Ext.define("Compass.ErpApp.Desktop.Applications.DynamicForms.DynamicDataGridPane
228
411
  this.callParent([config]);
229
412
  }
230
413
  });
231
-