erp_forms 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. data/README.rdoc +8 -3
  2. data/app/controllers/erp_forms/erp_app/desktop/dynamic_forms/comments_controller.rb +16 -0
  3. data/app/controllers/erp_forms/erp_app/desktop/dynamic_forms/data_controller.rb +45 -8
  4. data/app/controllers/erp_forms/erp_app/desktop/dynamic_forms/forms_controller.rb +14 -5
  5. data/app/controllers/erp_forms/erp_app/desktop/dynamic_forms/models_controller.rb +2 -2
  6. data/app/models/dynamic_datum.rb +31 -21
  7. data/app/models/dynamic_form.rb +42 -35
  8. data/app/models/ticket.rb +16 -0
  9. data/config/routes.rb +1 -0
  10. data/db/data_migrations/20110608185830_create_default_dynamic_models_and_forms.rb +4 -4
  11. data/db/data_migrations/20120824013449_create_ticket_form.rb +65 -0
  12. data/db/data_migrations/{20110830170240_update_contact_form.rb → 20120904191738_update_contact_form.rb} +5 -6
  13. data/db/migrate/20120824012520_create_tickets.rb +18 -0
  14. data/lib/erp_forms/dynamic_form_field.rb +93 -20
  15. data/lib/erp_forms/dynamic_grid_column.rb +7 -5
  16. data/lib/erp_forms/engine.rb +1 -0
  17. data/lib/erp_forms/extensions/active_record/has_dynamic_forms.rb +5 -5
  18. data/lib/erp_forms/extensions/railties/action_view.rb +6 -3
  19. data/lib/erp_forms/version.rb +1 -1
  20. data/public/javascripts/erp_app/desktop/applications/dynamic_forms/dynamic_data_grid.js +165 -13
  21. data/public/javascripts/erp_app/desktop/applications/dynamic_forms/module.js +1 -2
  22. data/public/javascripts/erp_app/desktop/applications/dynamic_forms/west_region.js +26 -13
  23. data/public/javascripts/erp_app/shared/dynamic_forms/dynamic_form_fields.js +37 -0
  24. data/public/stylesheets/erp_app/desktop/applications/dynamic_forms/comments.css +15 -0
  25. metadata +16 -11
  26. data/db/data_migrations/20110822170240_update_contact_form_validation.rb +0 -22
data/README.rdoc CHANGED
@@ -74,13 +74,18 @@ Adding dynamic forms and data to an existing model
74
74
 
75
75
  Using the Knitkit DynamicForms widget
76
76
  Edit Section Layout, click Dynamic Forms widget icon and the following will be added to the layout:
77
- <%= render_widget :dynamic_forms, :params => {:model_name => 'MyDynamicModel', :width => '350'} %>
77
+ <%=raw render_widget :dynamic_forms, :params => {:model_name => 'MyDynamicModel', :width => '350'} %>
78
78
 
79
79
 
80
80
  == TODO
81
81
 
82
- Dynamic Forms desktop application featuring a Dynamic Grid for every DynamicFormModel as well as a Dynamic Form Builder.
83
-
82
+ Dynamic Form Builder
83
+ Search Dynamic Attributes via SOLR
84
+ Code Mirror form field
85
+ file attachments w/ has_file_assets and plupload
86
+ concatenated field
87
+ calculated field
88
+ related field with search ahead for relations with huge datasets
84
89
 
85
90
  ============================================================
86
91
  Copyright (c) 2011 Adam Hull
@@ -0,0 +1,16 @@
1
+ module ErpForms::ErpApp::Desktop::DynamicForms
2
+ class CommentsController < ErpForms::ErpApp::Desktop::DynamicForms::BaseController
3
+
4
+ def add
5
+ @myDynamicObject = DynamicFormModel.get_constant(params[:model_name]).find(params[:id])
6
+ @comment = @myDynamicObject.add_comment({
7
+ :commentor_name => current_user.party.description,
8
+ :email => current_user.email,
9
+ :comment => params[:comment]
10
+ })
11
+
12
+ render :json => (@comment.valid? ? {:success => true} : {:success => false})
13
+ end
14
+
15
+ end
16
+ end
@@ -1,4 +1,6 @@
1
- class ErpForms::ErpApp::Desktop::DynamicForms::DataController < ErpForms::ErpApp::Desktop::DynamicForms::BaseController
1
+ module ErpForms::ErpApp::Desktop::DynamicForms
2
+ class DataController < ErpForms::ErpApp::Desktop::DynamicForms::BaseController
3
+ @@datetime_format = "%m/%d/%Y %l:%M%P"
2
4
 
3
5
  # setup dynamic data grid
4
6
  def setup
@@ -7,22 +9,26 @@ class ErpForms::ErpApp::Desktop::DynamicForms::DataController < ErpForms::ErpApp
7
9
 
8
10
  columns = []
9
11
  definition.each do |field_hash|
10
- field_hash[:width] = 120
11
- columns << DynamicGridColumn.build_column(field_hash)
12
+ if field_hash[:display_in_grid]
13
+ field_hash[:width] = (field_hash[:width].to_f * 0.56).round.to_i # for some reason grid column widths are greater than form field widths
14
+ columns << DynamicGridColumn.build_column(field_hash)
15
+ end
12
16
  end
13
17
 
14
18
  columns << DynamicGridColumn.build_column({ :fieldLabel => "Updated By", :name => 'updated_username', :xtype => 'textfield' })
15
19
  columns << DynamicGridColumn.build_column({ :fieldLabel => "Created By", :name => 'created_username', :xtype => 'textfield' })
16
20
  columns << DynamicGridColumn.build_column({ :fieldLabel => "Created At", :name => 'created_at', :xtype => 'datefield', :width => 75 })
17
21
  columns << DynamicGridColumn.build_column({ :fieldLabel => "Updated At", :name => 'updated_at', :xtype => 'datefield', :width => 75 })
18
- columns << DynamicGridColumn.build_edit_column("Ext.getCmp('DynamicFormDataGridPanel').editRecord(rec,'#{params[:model_name]}');")
19
- columns << DynamicGridColumn.build_delete_column("Ext.getCmp('DynamicFormDataGridPanel').deleteRecord(rec,'#{params[:model_name]}');")
22
+ columns << DynamicGridColumn.build_edit_column("Ext.getCmp('#{params[:model_name]}').editRecord(rec,'#{params[:model_name]}');")
23
+ columns << DynamicGridColumn.build_delete_column("Ext.getCmp('#{params[:model_name]}').deleteRecord(rec,'#{params[:model_name]}');")
20
24
 
21
25
  definition << DynamicFormField.textfield({ :fieldLabel => "Updated By", :name => 'updated_username' })
22
26
  definition << DynamicFormField.textfield({ :fieldLabel => "Created By", :name => 'created_username' })
23
27
  definition << DynamicFormField.datefield({ :fieldLabel => "Created At", :name => 'created_at' })
24
28
  definition << DynamicFormField.datefield({ :fieldLabel => "Updated At", :name => 'updated_at' })
25
29
  definition << DynamicFormField.hidden({ :fieldLabel => "ID", :name => 'id' })
30
+ definition << DynamicFormField.hidden({ :fieldLabel => "Form ID", :name => 'form_id' })
31
+ definition << DynamicFormField.hidden({ :fieldLabel => "Model Name", :name => 'model_name' })
26
32
 
27
33
  render :inline => "{
28
34
  \"success\": true,
@@ -39,26 +45,56 @@ class ErpForms::ErpApp::Desktop::DynamicForms::DataController < ErpForms::ErpApp
39
45
  myDynamicObject = DynamicFormModel.get_constant(params[:model_name])
40
46
 
41
47
  dynamic_records = myDynamicObject.paginate(:page => page, :per_page => per_page, :order => "#{sort} #{dir}")
48
+ related_fields = dynamic_records.first.form.related_fields rescue []
42
49
 
43
50
  wi = []
44
51
  dynamic_records.each do |i|
45
- wihash = i.data.dynamic_attributes_without_prefix
46
- # puts i.data.created_by.inspect
52
+ wihash = i.data.dynamic_attributes_with_related_data(related_fields, false)
47
53
  wihash[:id] = i.id
48
54
  wihash[:created_username] = i.data.created_by.nil? ? '' : i.data.created_by.username
49
55
  wihash[:updated_username] = i.data.updated_by.nil? ? '' : i.data.updated_by.username
50
56
  wihash[:created_at] = i.data.created_at
51
57
  wihash[:updated_at] = i.data.updated_at
58
+ wihash[:form_id] = (i.data.updated_with_form_id ? i.data.updated_with_form_id : i.data.created_with_form_id)
59
+ wihash[:model_name] = params[:model_name]
52
60
  wi << wihash
53
61
  end
54
62
 
55
63
  render :inline => "{ total:#{dynamic_records.total_entries}, data:#{wi.to_json} }"
56
64
  end
57
65
 
66
+ def get
67
+ myDynamicObject = DynamicFormModel.get_constant(params[:model_name])
68
+ @record = myDynamicObject.find(params[:id])
69
+
70
+ related_fields = @record.form.related_fields
71
+ data = @record.data.dynamic_attributes_with_related_data(related_fields, true)
72
+
73
+ metadata = {
74
+ :created_username => (@record.data.created_by.nil? ? '' : @record.data.created_by.username),
75
+ :updated_username => (@record.data.updated_by.nil? ? '' : @record.data.updated_by.username),
76
+ :created_at => @record.data.created_at.getlocal.strftime(@@datetime_format),
77
+ :updated_at => @record.data.updated_at.getlocal.strftime(@@datetime_format)
78
+ }
79
+
80
+ result_hash = {:success => true, :data => data, :metadata => metadata}
81
+
82
+ if @record.respond_to?(:comments)
83
+ result_hash[:comments] = @record.comments.order('id ASC').all
84
+ result_hash[:comments].each_with_index do |c, i|
85
+ result_hash[:comments][i] = c.to_hash
86
+ result_hash[:comments][i][:created_at] = c.created_at.getlocal.strftime(@@datetime_format)
87
+ result_hash[:comments][i][:updated_at] = c.updated_at.getlocal.strftime(@@datetime_format)
88
+ end
89
+ end
90
+
91
+ render :json => @record ? result_hash : {:success => false}
92
+ end
93
+
58
94
  # create a dynamic data record
59
95
  def create
60
96
  @myDynamicObject = DynamicFormModel.get_instance(params[:model_name])
61
- puts current_user.inspect
97
+
62
98
  params[:created_by] = current_user unless current_user.nil?
63
99
  params[:created_with_form_id] = params[:dynamic_form_id] if params[:dynamic_form_id]
64
100
  @myDynamicObject = DynamicFormModel.save_all_attributes(@myDynamicObject, params, ErpForms::ErpApp::Desktop::DynamicForms::BaseController::IGNORED_PARAMS)
@@ -84,4 +120,5 @@ class ErpForms::ErpApp::Desktop::DynamicForms::DataController < ErpForms::ErpApp
84
120
  render :json => {:success => true}
85
121
  end
86
122
 
123
+ end
87
124
  end
@@ -53,20 +53,29 @@ class ErpForms::ErpApp::Desktop::DynamicForms::FormsController < ErpForms::ErpAp
53
53
 
54
54
  # get a single form
55
55
  def get
56
- if params[:id]
57
- dform = DynamicForm.find(params[:id])
58
- else
59
- dform = DynamicForm.find_by_model_name_and_default(params[:model_name], true)
56
+ dform = DynamicForm.find_by_id(params[:id]) if params[:id]
57
+ dform = DynamicForm.get_form(params[:model_name]) if dform.nil? and params[:model_name]
58
+
59
+ if dform.nil?
60
+ render :json => {:success => false, :error => "Don't know how to find form"} and return
60
61
  end
61
62
 
62
63
  form = dform.to_extjs_formpanel(
63
64
  { :url => "/erp_forms/erp_app/desktop/dynamic_forms/data/#{params[:form_action]}",
64
- :record_id => params[:id]
65
+ :record_id => params[:record_id]
65
66
  })
66
67
 
67
68
  render :json => form
68
69
  end
69
70
 
71
+ # get related data for a related field
72
+ def related_field
73
+ related_model = params[:model].camelize.constantize
74
+ data = related_model.all
75
+
76
+ render :inline => data.to_json(:only => [:id, params[:displayField].to_sym])
77
+ end
78
+
70
79
  # delete dynamic form
71
80
  def delete
72
81
 
@@ -8,7 +8,7 @@ class ErpForms::ErpApp::Desktop::DynamicForms::ModelsController < ErpForms::ErpA
8
8
  dynamic_form_models.each do |m|
9
9
  model_hash = {
10
10
  :id => m.id,
11
- :model_name => m.model_name,
11
+ :model_name => m.model_name
12
12
  }
13
13
 
14
14
  models << model_hash
@@ -22,7 +22,7 @@ class ErpForms::ErpApp::Desktop::DynamicForms::ModelsController < ErpForms::ErpA
22
22
  myDynamicObject = DynamicFormModel.get_constant(params[:model_name])
23
23
  myDynamicObject.set_default(params[:id])
24
24
 
25
- render :json => {success => true}
25
+ render :json => {:success => true}
26
26
  end
27
27
 
28
28
  # delete a dynamic form model
@@ -18,37 +18,48 @@ class DynamicDatum < ActiveRecord::Base
18
18
  attrs
19
19
  end
20
20
 
21
- =begin
22
- # this was used for sorting dynamic sttributes under Ruby 1.8.7 which did not have ordered hashes
23
- # it is now obsolete under Ruby 1.9
24
- # leave it here for reference for the time being in case we find that dynamic attributes are stored in the wrong order in the DB
25
- # using ordered hashes assumes that dynamic attributes are stored in order in the database
26
- def sorted_dynamic_attributes(with_prefix=true)
27
- if !self.updated_with_form.nil?
28
- form = self.updated_with_form
29
- elsif !self.created_with_form.nil?
30
- form = self.created_with_form
31
- else
32
- form = nil
21
+ def dynamic_attributes_with_related_data(related_fields=[], use_label=false)
22
+ key = (use_label ? :fieldLabel : :name)
23
+ data = sorted_dynamic_attributes(false, use_label)
24
+ related_fields.each do |r|
25
+ data.each do |k,v|
26
+ if k == r[key]
27
+ data[k] = r[:extraParams]['model'].camelize.constantize.find(v).send(r[:displayField]) rescue nil
28
+ end
29
+ end
33
30
  end
31
+
32
+ data
33
+ end
34
+
35
+ # we cannot assume that dynamic attributes are stored in order in the database as this is often not the case
36
+ # this method will sort them according to the order of the fields in the form definition
37
+ # method returns an ordered hash
38
+ # if with_prefix is false, you may choose to use the fieldLabel as the hash key, this is useful displaying data on a view screen
39
+ def sorted_dynamic_attributes(with_prefix=false, use_label=false)
40
+ form = self.updated_with_form if form.nil? and !self.updated_with_form.nil?
41
+ form = self.created_with_form if form.nil? and !self.created_with_form.nil?
42
+ form = DynamicForm.get_form(self.reference_type) if form.nil?
34
43
 
35
44
  unless form.nil?
36
45
  if with_prefix
37
46
  keys = form.definition_object.collect{|f| DYNAMIC_ATTRIBUTE_PREFIX + f[:name]}
38
- else
47
+ else
48
+ labels = form.definition_object.collect{|f| f[:fieldLabel]} if use_label
39
49
  keys = form.definition_object.collect{|f| f[:name]}
40
50
  end
41
51
 
42
- sorted = []
52
+ sorted = {}
53
+ i=0
43
54
  keys.each do |key|
44
- attribute = {}
45
55
  if with_prefix
46
- attribute[key] = self.dynamic_attributes[key]
56
+ sorted[key] = self.dynamic_attributes[key]
47
57
  else
48
- attribute[key] = self.dynamic_attributes_without_prefix[key]
49
- end
50
-
51
- sorted << attribute
58
+ index = (use_label ? labels[i] : key)
59
+ sorted[index] = self.dynamic_attributes_without_prefix[key]
60
+ end
61
+
62
+ i += 1
52
63
  end
53
64
 
54
65
  return sorted
@@ -60,6 +71,5 @@ class DynamicDatum < ActiveRecord::Base
60
71
  end
61
72
  end
62
73
  end
63
- =end
64
74
 
65
75
  end
@@ -4,24 +4,24 @@ class DynamicForm < ActiveRecord::Base
4
4
  validates_uniqueness_of :internal_identifier, :scope => :model_name
5
5
 
6
6
  def self.class_exists?(class_name)
7
- result = nil
8
- begin
9
- klass = Module.const_get(class_name)
10
- result = klass.is_a?(Class) ? ((klass.superclass == ActiveRecord::Base or klass.superclass == DynamicModel) ? true : nil) : nil
11
- rescue NameError
12
- result = nil
13
- end
14
- result
7
+ result = nil
8
+ begin
9
+ klass = Module.const_get(class_name)
10
+ result = klass.is_a?(Class) ? ((klass.superclass == ActiveRecord::Base or klass.superclass == DynamicModel) ? true : nil) : nil
11
+ rescue NameError
12
+ result = nil
13
+ end
14
+ result
15
15
  end
16
16
 
17
17
  def self.get_form(klass_name, internal_identifier='')
18
18
  result = nil
19
- if internal_identifier and internal_identifier != ''
20
- result = DynamicForm.find_by_model_name_and_internal_identifier(klass_name, internal_identifier)
21
- else
22
- result = DynamicForm.find_by_model_name_and_default(klass_name, true)
23
- end
24
- result
19
+ unless internal_identifier.blank?
20
+ result = DynamicForm.find_by_model_name_and_internal_identifier(klass_name, internal_identifier)
21
+ else
22
+ result = DynamicForm.find_by_model_name_and_default(klass_name, true)
23
+ end
24
+ result
25
25
  end
26
26
 
27
27
  # parse JSON definition into a ruby object
@@ -49,11 +49,21 @@ class DynamicForm < ActiveRecord::Base
49
49
  def_object
50
50
  end
51
51
 
52
+ # will return an array of field names that are of xtype 'related_combobox'
53
+ def related_fields
54
+ related_fields = []
55
+ definition_object.each do |f|
56
+ related_fields << f if f[:xtype] == 'related_combobox'
57
+ end
58
+
59
+ related_fields
60
+ end
61
+
52
62
  # check field against form definition to see if field still exists
53
63
  # returns true if field does not exist
54
64
  def deprecated_field?(field_name)
55
65
  result = true
56
- definition_object.each do |field|
66
+ definition_object.each do |field|
57
67
  result = false if field[:name] == field_name.to_s
58
68
  end
59
69
 
@@ -67,7 +77,7 @@ class DynamicForm < ActiveRecord::Base
67
77
  def to_extjs_formpanel(options={})
68
78
  form_hash = {
69
79
  :xtype => 'form',
70
- :id => 'dynamic_form_panel',
80
+ :id => "dynamic_form_panel_#{model_name}",
71
81
  :url => options[:url],
72
82
  :title => self.description,
73
83
  :frame => true,
@@ -80,20 +90,23 @@ class DynamicForm < ActiveRecord::Base
80
90
  form_hash[:baseParams][:dynamic_form_id] = self.id
81
91
  form_hash[:baseParams][:dynamic_form_model_id] = self.dynamic_form_model_id
82
92
  form_hash[:baseParams][:model_name] = self.model_name
83
- form_hash[:listeners] = {:afterrender => NonEscapeJsonString.new("function(form) {Ext.getCmp('dynamic_form_panel').getComponent(0).focus(false);}")}
93
+ form_hash[:listeners] = {
94
+ :afterrender => NonEscapeJsonString.new("function(form) {Ext.getCmp('dynamic_form_panel_#{model_name}').getComponent(0).focus(false);}")
95
+ }
84
96
  form_hash[:items] = definition_with_validation
85
97
  form_hash[:buttons] = []
86
98
  form_hash[:buttons][0] = {
87
99
  :text => 'Submit',
88
100
  :listeners => NonEscapeJsonString.new("{
89
101
  \"click\":function(button){
90
- var formPanel = Ext.getCmp('dynamic_form_panel');
102
+ var formPanel = Ext.getCmp('dynamic_form_panel_#{model_name}');
91
103
  formPanel.getForm().submit({
92
104
  reset:true,
93
105
  success:function(form, action){
94
- Ext.getCmp('dynamic_form_panel').findParentByType('window').close();
95
- if (Ext.getCmp('DynamicFormDataGridPanel')){
96
- Ext.getCmp('DynamicFormDataGridPanel').query('shared_dynamiceditablegrid')[0].store.load();
106
+ Ext.getCmp('dynamic_form_panel_#{model_name}').findParentByType('window').close();
107
+
108
+ if (Ext.getCmp('#{model_name}')){
109
+ Ext.getCmp('#{model_name}').query('shared_dynamiceditablegrid')[0].store.load();
97
110
  }
98
111
  },
99
112
  failure:function(form, action){
@@ -107,7 +120,7 @@ class DynamicForm < ActiveRecord::Base
107
120
  :text => 'Cancel',
108
121
  :listeners => NonEscapeJsonString.new("{
109
122
  \"click\":function(button){
110
- Ext.getCmp('dynamic_form_panel').findParentByType('window').close();
123
+ Ext.getCmp('dynamic_form_panel_#{model_name}').findParentByType('window').close();
111
124
  }
112
125
  }")
113
126
  }
@@ -126,12 +139,10 @@ class DynamicForm < ActiveRecord::Base
126
139
  options[:width] = "'auto'" if options[:width].nil?
127
140
 
128
141
  #NOTE: The random nbsp; forces IE to eval this javascript!
129
- javascript = "&nbsp<script type=\"text/javascript\">
130
- Ext.onReady(function(){
131
- Ext.QuickTips.init();
142
+ javascript = "Ext.QuickTips.init();
132
143
 
133
- var dynamic_form = Ext.create('Ext.form.Panel',{
134
- id: 'dynamic_form_panel',
144
+ Ext.create('Ext.form.Panel',{
145
+ id: 'dynamic_form_panel_#{model_name}',
135
146
  url:'#{options[:url]}',
136
147
  title: '#{self.description}',"
137
148
 
@@ -145,18 +156,17 @@ class DynamicForm < ActiveRecord::Base
145
156
  dynamic_form_model_id: #{self.dynamic_form_model_id},
146
157
  model_name: '#{self.model_name}'
147
158
  },
148
- items: #{definition_with_validation},
159
+ items: #{definition_with_validation.to_json},
149
160
  listeners: {
150
161
  afterrender: function(form) {
151
- Ext.getCmp('dynamic_form_panel').getComponent(0).focus(false);
162
+ Ext.getCmp('dynamic_form_panel_#{model_name}').getComponent(0).focus(false);
152
163
  }
153
164
  },
154
165
  buttons: [{
155
166
  text: 'Submit',
156
167
  listeners:{
157
168
  'click':function(button){
158
-
159
- var formPanel = Ext.getCmp('dynamic_form_panel');
169
+ var formPanel = Ext.getCmp('dynamic_form_panel_#{model_name}');
160
170
  formPanel.getForm().submit({
161
171
  reset:true,
162
172
  success:function(form, action){
@@ -180,10 +190,7 @@ class DynamicForm < ActiveRecord::Base
180
190
  },{
181
191
  text: 'Cancel'
182
192
  }]
183
- });
184
- });
185
-
186
- </script>"
193
+ });"
187
194
  #logger.info javascript
188
195
  javascript
189
196
  end
@@ -0,0 +1,16 @@
1
+ class Ticket < ActiveRecord::Base
2
+ belongs_to :user, :foreign_key => 'assigned_to_id'
3
+
4
+ has_dynamic_forms
5
+ has_dynamic_data
6
+ acts_as_commentable
7
+
8
+ def send_email(subject='')
9
+ begin
10
+ WebsiteInquiryMailer.inquiry(self, subject).deliver
11
+ rescue Exception => e
12
+ system_user = Party.find_by_description('Compass AE')
13
+ AuditLog.custom_application_log_message(system_user, e)
14
+ end
15
+ end
16
+ end
data/config/routes.rb CHANGED
@@ -3,4 +3,5 @@ ErpForms::Engine.routes.draw do
3
3
  match '/erp_app/desktop/dynamic_forms/data/:action(/:model_name)' => 'erp_app/desktop/dynamic_forms/data'
4
4
  match '/erp_app/desktop/dynamic_forms/forms/:action' => 'erp_app/desktop/dynamic_forms/forms'
5
5
  match '/erp_app/desktop/dynamic_forms/models/:action' => 'erp_app/desktop/dynamic_forms/models'
6
+ match '/erp_app/desktop/dynamic_forms/comments/:action' => 'erp_app/desktop/dynamic_forms/comments'
6
7
  end
@@ -6,10 +6,10 @@ class CreateDefaultDynamicModelsAndForms
6
6
 
7
7
  fields = []
8
8
 
9
- fields << DynamicFormField.textfield({:fieldLabel => 'First Name', :name => 'first_name', :width => 250, :allowblank => false })
10
- fields << DynamicFormField.textfield({:fieldLabel => 'Last Name', :name => 'last_name', :width => 250, :allowblank => false })
11
- fields << DynamicFormField.email({:fieldLabel => 'Email', :name => 'email', :width => 250, :allowblank => false })
12
- fields << DynamicFormField.textarea({:fieldLabel => 'Message', :name => 'message', :width => 400, :height => 200, :allowblank => false })
9
+ fields << DynamicFormField.textfield({:fieldLabel => 'First Name', :name => 'first_name', :width => 250, :allowBlank => false })
10
+ fields << DynamicFormField.textfield({:fieldLabel => 'Last Name', :name => 'last_name', :width => 250, :allowBlank => false })
11
+ fields << DynamicFormField.email({:fieldLabel => 'Email', :name => 'email', :width => 250, :allowBlank => false })
12
+ fields << DynamicFormField.textarea({:fieldLabel => 'Message', :name => 'message', :width => 400, :height => 200, :allowBlank => false })
13
13
 
14
14
  d = DynamicForm.new
15
15
  d.description = 'Contact Form'
@@ -0,0 +1,65 @@
1
+ class CreateTicketForm
2
+
3
+ def self.up
4
+ #insert data here
5
+ fields = []
6
+
7
+ fields << DynamicFormField.textfield({:fieldLabel => 'Title', :name => 'title', :width => 250, :allowBlank => false })
8
+ fields << DynamicFormField.combobox([['Open', 'Open'],['Closed', 'Closed']],{:fieldLabel => 'Status', :name => 'status', :width => 175, :allowBlank => false })
9
+ fields << DynamicFormField.combobox([ ['Defect', 'Defect'],
10
+ ['Feature', 'Feature'],
11
+ ['Issue', 'Issue'],
12
+ ['Task', 'Task'],
13
+ ],{:fieldLabel => 'Type', :name => 'type', :width => 175, :allowBlank => false })
14
+ fields << DynamicFormField.combobox([['High', 'High'],['Medium', 'Medium'],['Low', 'Low']],{:fieldLabel => 'Priority', :name => 'priority', :width => 175, :allowBlank => false })
15
+ fields << DynamicFormField.combobox([ ['compass_ae_console', 'compass_ae_console'],
16
+ ['compass_ae_starter_kit', 'compass_ae_starter_kit'],
17
+ ['data_migrator', 'data_migrator'],
18
+ ['erp_agreements', 'erp_agreements'],
19
+ ['erp_app', 'erp_app'],
20
+ ['erp_base_erp_svcs', 'erp_base_erp_svcs'],
21
+ ['erp_commerce', 'erp_commerce'],
22
+ ['erp_communication_events', 'erp_communication_events'],
23
+ ['erp_dev_svcs', 'erp_dev_svcs'],
24
+ ['erp_financial_accounting', 'erp_financial_accounting'],
25
+ ['erp_forms', 'erp_forms'],
26
+ ['erp_inventory', 'erp_inventory'],
27
+ ['erp_invoicing', 'erp_invoicing'],
28
+ ['erp_offers', 'erp_offers'],
29
+ ['erp_orders', 'erp_orders'],
30
+ ['erp_products', 'erp_products'],
31
+ ['erp_rules', 'erp_rules'],
32
+ ['erp_search', 'erp_search'],
33
+ ['erp_tech_svcs', 'erp_tech_svcs'],
34
+ ['erp_txns_and_accts', 'erp_txns_and_accts'],
35
+ ['erp_work_effort', 'erp_work_effort'],
36
+ ['erp_workflow', 'erp_workflow'],
37
+ ['knitkit', 'knitkit'],
38
+ ['master_data_management', 'master_data_management'],
39
+ ['prismpay', 'prismpay'],
40
+ ['rails_db_admin', 'rails_db_admin'],
41
+ ['tenancy', 'tenancy'],
42
+ ['timeshare', 'timeshare']
43
+ ],
44
+ {:fieldLabel => 'Product', :name => 'product', :width => 270, :allowBlank => true })
45
+ fields << DynamicFormField.combobox([['None', 'None']],{:fieldLabel => 'Project', :name => 'project', :width => 175, :allowBlank => true })
46
+ fields << DynamicFormField.related_combobox('User','username',{:fieldLabel => 'Assigned To', :name => 'assigned_to_id', :width => 175, :allowBlank => true })
47
+ fields << DynamicFormField.textarea({:fieldLabel => 'Body', :name => 'body', :width => 400, :height => 300, :allowBlank => false, :display_in_grid => false })
48
+
49
+ d = DynamicForm.new
50
+ d.description = 'Ticket Form'
51
+ d.definition = fields.to_json
52
+ d.model_name = 'Ticket'
53
+ d.internal_identifier = 'ticket'
54
+ d.default = true
55
+ d.dynamic_form_model = DynamicFormModel.create(:model_name => 'Ticket')
56
+ d.save
57
+ end
58
+
59
+ def self.down
60
+ #remove data here
61
+ DynamicForm.find_by_internal_identifier('ticket').destroy
62
+ DynamicFormModel.find_by_model_name('Ticket').destroy
63
+ end
64
+
65
+ end
@@ -3,21 +3,20 @@ class UpdateContactForm
3
3
  def self.up
4
4
  fields = []
5
5
 
6
- fields << DynamicFormField.textfield({:fieldLabel => 'First Name', :name => 'first_name', :width => 250, :allowblank => false })
7
- fields << DynamicFormField.textfield({:fieldLabel => 'Last Name', :name => 'last_name', :width => 250, :allowblank => false })
8
- fields << DynamicFormField.email({:fieldLabel => 'Email', :name => 'email', :width => 250, :allowblank => false })
9
- fields << DynamicFormField.textarea({:fieldLabel => 'Message', :name => 'message', :width => 400, :height => 200, :allowblank => false })
6
+ fields << DynamicFormField.textfield({:fieldLabel => 'First Name', :name => 'first_name', :width => 250, :allowBlank => false })
7
+ fields << DynamicFormField.textfield({:fieldLabel => 'Last Name', :name => 'last_name', :width => 250, :allowBlank => false })
8
+ fields << DynamicFormField.email({:fieldLabel => 'Email', :name => 'email', :width => 250, :allowBlank => false })
9
+ fields << DynamicFormField.textarea({:fieldLabel => 'Message', :name => 'message', :width => 400, :height => 200, :allowBlank => false })
10
10
 
11
11
  d = DynamicForm.find_by_internal_identifier('contact_us')
12
12
  unless d.nil?
13
- puts "updating form"
14
13
  d.definition = fields.to_json
15
14
  d.save
16
15
  end
17
16
  end
18
17
 
19
18
  def self.down
20
- # do nothing
19
+ #remove data here
21
20
  end
22
21
 
23
22
  end
@@ -0,0 +1,18 @@
1
+ class CreateTickets < ActiveRecord::Migration
2
+
3
+ def up
4
+ unless table_exists?(:tickets)
5
+ create_table :tickets do |t|
6
+ t.timestamps
7
+ end
8
+ end
9
+
10
+ end
11
+
12
+ def down
13
+ if table_exists?(:tickets)
14
+ drop_table :tickets
15
+ end
16
+ end
17
+
18
+ end