erp_forms 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/GPL-3-LICENSE +674 -0
- data/README.rdoc +2 -0
- data/Rakefile +30 -0
- data/app/assets/javascripts/erp_forms/application.js +9 -0
- data/app/assets/stylesheets/erp_forms/application.css +7 -0
- data/app/controllers/erp_forms/erp_app/desktop/dynamic_forms/base_controller.rb +47 -0
- data/app/controllers/erp_forms/erp_app/desktop/dynamic_forms/data_controller.rb +87 -0
- data/app/controllers/erp_forms/erp_app/desktop/dynamic_forms/forms_controller.rb +79 -0
- data/app/controllers/erp_forms/erp_app/desktop/dynamic_forms/models_controller.rb +45 -0
- data/app/helpers/erp_forms/application_helper.rb +4 -0
- data/app/models/dynamic_datum.rb +65 -0
- data/app/models/dynamic_form.rb +191 -0
- data/app/models/dynamic_form_document.rb +29 -0
- data/app/models/dynamic_form_model.rb +42 -0
- data/app/views/layouts/application.html.erb +14 -0
- data/app/views/layouts/erp_forms/application.html.erb +14 -0
- data/app/widgets/dynamic_forms/base.rb +61 -0
- data/app/widgets/dynamic_forms/javascript/dynamic_forms.js +109 -0
- data/app/widgets/dynamic_forms/views/error.html.erb +4 -0
- data/app/widgets/dynamic_forms/views/index.html.erb +8 -0
- data/app/widgets/dynamic_forms/views/success.html.erb +4 -0
- data/config/routes.rb +6 -0
- data/db/data_migrations/20110608185830_create_default_dynamic_models_and_forms.rb +30 -0
- data/db/data_migrations/20110822170240_update_contact_form_validation.rb +22 -0
- data/db/data_migrations/20110828190913_create_desktop_app_dynamic_forms.rb +18 -0
- data/db/data_migrations/20110830170240_update_contact_form.rb +23 -0
- data/db/migrate/20110530193446_dynamic_forms.rb +82 -0
- data/lib/erp_forms/dynamic_attributes_patch.rb +10 -0
- data/lib/erp_forms/dynamic_form_field.rb +130 -0
- data/lib/erp_forms/dynamic_grid_column.rb +108 -0
- data/lib/erp_forms/engine.rb +22 -0
- data/lib/erp_forms/extensions/active_record/has_dynamic_data.rb +54 -0
- data/lib/erp_forms/extensions/active_record/has_dynamic_forms.rb +70 -0
- data/lib/erp_forms/extensions/extensions.rb +6 -0
- data/lib/erp_forms/extensions/railties/action_view.rb +20 -0
- data/lib/erp_forms/version.rb +3 -0
- data/lib/erp_forms.rb +11 -0
- data/lib/tasks/erp_forms_tasks.rake +4 -0
- data/public/javascripts/erp_app/desktop/applications/dynamic_forms/center_region.js +23 -0
- data/public/javascripts/erp_app/desktop/applications/dynamic_forms/dynamic_data_grid.js +81 -0
- data/public/javascripts/erp_app/desktop/applications/dynamic_forms/form_builder.js +93 -0
- data/public/javascripts/erp_app/desktop/applications/dynamic_forms/module.js +37 -0
- data/public/javascripts/erp_app/desktop/applications/dynamic_forms/west_region.js +468 -0
- data/public/javascripts/erp_app/shared/dynamic_forms/dynamic_forms_validation.js +4 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +45 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +8 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/spec.rb +27 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/models/dynamic_datum_spec.rb +9 -0
- data/spec/models/dynamic_form_document_spec.rb +11 -0
- data/spec/models/dynamic_form_model_spec.rb +11 -0
- data/spec/models/dynamic_form_spec.rb +11 -0
- data/spec/spec_helper.rb +60 -0
- metadata +183 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
module Widgets
|
2
|
+
module DynamicForms
|
3
|
+
class Base < ErpApp::Widgets::Base
|
4
|
+
def index
|
5
|
+
render
|
6
|
+
end
|
7
|
+
|
8
|
+
def new
|
9
|
+
@website = Website.find_by_host(request.host_with_port)
|
10
|
+
|
11
|
+
@myDynamicObject = DynamicFormModel.get_instance(params[:model_name])
|
12
|
+
|
13
|
+
params[:created_by] = current_user unless current_user.nil?
|
14
|
+
params[:created_with_form_id] = params[:dynamic_form_id] if params[:dynamic_form_id] and params[:is_html_form].blank?
|
15
|
+
params[:website_id] = @website.id
|
16
|
+
@myDynamicObject = DynamicFormModel.save_all_attributes(@myDynamicObject, params, ErpApp::Widgets::Base::IGNORED_PARAMS)
|
17
|
+
|
18
|
+
if @myDynamicObject
|
19
|
+
render :json => {
|
20
|
+
:success => true,
|
21
|
+
:response => render_to_string(:template => "success", :layout => false)
|
22
|
+
}
|
23
|
+
else
|
24
|
+
render :json => {
|
25
|
+
:success => false,
|
26
|
+
:response => render_to_string(:template => "error", :layout => false)
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
#should not be modified
|
32
|
+
#modify at your own risk
|
33
|
+
def locate
|
34
|
+
File.dirname(__FILE__)
|
35
|
+
end
|
36
|
+
|
37
|
+
class << self
|
38
|
+
def title
|
39
|
+
"Dynamic Forms"
|
40
|
+
end
|
41
|
+
|
42
|
+
def views_location
|
43
|
+
File.join(File.dirname(__FILE__),"/views")
|
44
|
+
end
|
45
|
+
|
46
|
+
def widget_name
|
47
|
+
File.basename(File.dirname(__FILE__))
|
48
|
+
end
|
49
|
+
|
50
|
+
def base_layout
|
51
|
+
begin
|
52
|
+
file = File.join(File.dirname(__FILE__),"/views/layouts/base.html.erb")
|
53
|
+
IO.read(file)
|
54
|
+
rescue
|
55
|
+
return nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
Compass.ErpApp.Widgets.DynamicForms = {
|
2
|
+
addDynamicForm:function(){
|
3
|
+
var addDynamicFormWidgetWindow = Ext.create("Ext.window.Window",{
|
4
|
+
layout:'fit',
|
5
|
+
width:375,
|
6
|
+
title:'Add DynamicForm Widget',
|
7
|
+
height:190,
|
8
|
+
plain: true,
|
9
|
+
buttonAlign:'center',
|
10
|
+
items: Ext.create("Ext.form.Panel",{
|
11
|
+
labelWidth: 100,
|
12
|
+
frame:false,
|
13
|
+
bodyStyle:'padding:5px 5px 0',
|
14
|
+
defaults: {
|
15
|
+
width: 325
|
16
|
+
},
|
17
|
+
items: [
|
18
|
+
{
|
19
|
+
xtype:'combo',
|
20
|
+
id:'WidgetDynamicFormModelName',
|
21
|
+
value:'',
|
22
|
+
loadingText:'Retrieving Dynamic Form Models ...',
|
23
|
+
store:Ext.create('Ext.data.Store',{
|
24
|
+
proxy:{
|
25
|
+
type:'ajax',
|
26
|
+
reader:{
|
27
|
+
type:'json',
|
28
|
+
root: 'dynamic_form_model'
|
29
|
+
},
|
30
|
+
url:'/erp_forms/erp_app/desktop/dynamic_forms/models/index'
|
31
|
+
},
|
32
|
+
fields:[
|
33
|
+
{
|
34
|
+
name:'id'
|
35
|
+
},
|
36
|
+
{
|
37
|
+
name:'model_name'
|
38
|
+
|
39
|
+
}
|
40
|
+
]
|
41
|
+
}),
|
42
|
+
forceSelection:true,
|
43
|
+
editable:true,
|
44
|
+
fieldLabel:'Dynamic Form Model Name (Class)',
|
45
|
+
autoSelect:true,
|
46
|
+
typeAhead: true,
|
47
|
+
mode: 'remote',
|
48
|
+
displayField:'model_name',
|
49
|
+
valueField:'model_name',
|
50
|
+
triggerAction: 'all',
|
51
|
+
allowBlank:false
|
52
|
+
},
|
53
|
+
{
|
54
|
+
xtype:'textfield',
|
55
|
+
fieldLabel:'Form Width in Pixels',
|
56
|
+
allowBlank:false,
|
57
|
+
value:'410',
|
58
|
+
id:'WidgetDynamicFormWidth'
|
59
|
+
}
|
60
|
+
]
|
61
|
+
}),
|
62
|
+
buttons: [{
|
63
|
+
text:'Submit',
|
64
|
+
listeners:{
|
65
|
+
'click':function(button){
|
66
|
+
var tpl = null;
|
67
|
+
var content = null;
|
68
|
+
var window = button.findParentByType('window');
|
69
|
+
var formPanel = window.query('form')[0];
|
70
|
+
var basicForm = formPanel.getForm();
|
71
|
+
|
72
|
+
var WidgetDynamicFormModelName = basicForm.findField('WidgetDynamicFormModelName');
|
73
|
+
var data = {};
|
74
|
+
data.WidgetDynamicFormModelName = WidgetDynamicFormModelName.getValue();
|
75
|
+
|
76
|
+
var WidgetDynamicFormWidth = basicForm.findField('WidgetDynamicFormWidth');
|
77
|
+
data.WidgetDynamicFormWidth = WidgetDynamicFormWidth.getValue();
|
78
|
+
tpl = new Ext.XTemplate(
|
79
|
+
"<% # Optional Parameters:\n",
|
80
|
+
" # internal_identifier: Models can have multiple forms\n",
|
81
|
+
" # Leave blank if you want to use the default form\n",
|
82
|
+
" # Specify internal_identifier to choose a specific form %>\n",
|
83
|
+
"<%= render_widget :dynamic_forms,\n",
|
84
|
+
" :params => {:model_name => '{WidgetDynamicFormModelName}',\n",
|
85
|
+
" :internal_identifier => '',\n",
|
86
|
+
" :width => {WidgetDynamicFormWidth}} %>");
|
87
|
+
content = tpl.apply(data);
|
88
|
+
|
89
|
+
//add rendered template to center region editor
|
90
|
+
Ext.getCmp('knitkitCenterRegion').addContentToActiveCodeMirror(content);
|
91
|
+
addDynamicFormWidgetWindow.close();
|
92
|
+
}
|
93
|
+
}
|
94
|
+
},{
|
95
|
+
text: 'Close',
|
96
|
+
handler: function(){
|
97
|
+
addDynamicFormWidgetWindow.close();
|
98
|
+
}
|
99
|
+
}]
|
100
|
+
});
|
101
|
+
addDynamicFormWidgetWindow.show();
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
Compass.ErpApp.Widgets.AvailableWidgets.push({
|
106
|
+
name:'Dynamic Forms',
|
107
|
+
iconUrl:'/images/icons/document_text/document_text_48x48.png',
|
108
|
+
onClick:Compass.ErpApp.Widgets.DynamicForms.addDynamicForm
|
109
|
+
});
|
data/config/routes.rb
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
ErpForms::Engine.routes.draw do
|
2
|
+
#dynamic_forms
|
3
|
+
match '/erp_app/desktop/dynamic_forms/data/:action(/:model_name)' => 'erp_app/desktop/dynamic_forms/data'
|
4
|
+
match '/erp_app/desktop/dynamic_forms/forms/:action' => 'erp_app/desktop/dynamic_forms/forms'
|
5
|
+
match '/erp_app/desktop/dynamic_forms/models/:action' => 'erp_app/desktop/dynamic_forms/models'
|
6
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class CreateDefaultDynamicModelsAndForms
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
#insert data here
|
5
|
+
DynamicFormModel.create(:model_name => 'DynamicFormDocument')
|
6
|
+
|
7
|
+
fields = []
|
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 })
|
13
|
+
|
14
|
+
d = DynamicForm.new
|
15
|
+
d.description = 'Contact Form'
|
16
|
+
d.definition = fields.to_json
|
17
|
+
d.model_name = 'WebsiteInquiry'
|
18
|
+
d.internal_identifier = 'contact_us'
|
19
|
+
d.default = true
|
20
|
+
d.dynamic_form_model = DynamicFormModel.create(:model_name => 'WebsiteInquiry')
|
21
|
+
d.save
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.down
|
25
|
+
#remove data here
|
26
|
+
DynamicFormModel.delete_all
|
27
|
+
DynamicForm.delete_all
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class UpdateContactFormValidation
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
fields = []
|
5
|
+
|
6
|
+
fields << DynamicFormField.textfield({:fieldLabel => 'First Name', :name => 'first_name', :width => '200' })
|
7
|
+
fields << DynamicFormField.textfield({:fieldLabel => 'Last Name', :name => 'last_name', :width => '200' })
|
8
|
+
fields << DynamicFormField.email({:fieldLabel => 'Email', :name => 'email', :width => '200' })
|
9
|
+
fields << DynamicFormField.textarea({:fieldLabel => 'Message', :name => 'message', :width => '200' })
|
10
|
+
|
11
|
+
d = DynamicForm.find_by_internal_identifier('contact_us')
|
12
|
+
unless d.nil?
|
13
|
+
d.definition = fields.to_json
|
14
|
+
d.save
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.down
|
19
|
+
# do nothing
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateDesktopAppDynamicForms
|
2
|
+
def self.up
|
3
|
+
app = DesktopApplication.create(
|
4
|
+
:description => 'Dynamic Forms',
|
5
|
+
:icon => 'icon-document',
|
6
|
+
:javascript_class_name => 'Compass.ErpApp.Desktop.Applications.DynamicForms',
|
7
|
+
:internal_identifier => 'dynamic_forms',
|
8
|
+
:shortcut_id => 'dynamic_forms-win'
|
9
|
+
)
|
10
|
+
app.preference_types << PreferenceType.iid('desktop_shortcut')
|
11
|
+
app.preference_types << PreferenceType.iid('autoload_application')
|
12
|
+
app.save #probably redundant
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
DesktopApplication.destroy_all(['internal_identifier = ?','dynamic_forms'])
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class UpdateContactForm
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
fields = []
|
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 })
|
10
|
+
|
11
|
+
d = DynamicForm.find_by_internal_identifier('contact_us')
|
12
|
+
unless d.nil?
|
13
|
+
puts "updating form"
|
14
|
+
d.definition = fields.to_json
|
15
|
+
d.save
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.down
|
20
|
+
# do nothing
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
class DynamicForms < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
unless table_exists?(:dynamic_form_models)
|
4
|
+
create_table :dynamic_form_models do |t|
|
5
|
+
t.string :model_name
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
unless table_exists?(:dynamic_form_documents)
|
12
|
+
create_table :dynamic_form_documents do |t|
|
13
|
+
t.integer :dynamic_form_model_id
|
14
|
+
t.string :type
|
15
|
+
|
16
|
+
t.timestamps
|
17
|
+
end
|
18
|
+
|
19
|
+
add_index :dynamic_form_documents, :dynamic_form_model_id
|
20
|
+
add_index :dynamic_form_documents, :type
|
21
|
+
end
|
22
|
+
|
23
|
+
unless table_exists?(:dynamic_forms)
|
24
|
+
create_table :dynamic_forms do |t|
|
25
|
+
t.string :description
|
26
|
+
t.text :definition
|
27
|
+
t.integer :dynamic_form_model_id
|
28
|
+
t.string :model_name
|
29
|
+
t.string :internal_identifier
|
30
|
+
t.boolean :default
|
31
|
+
|
32
|
+
t.integer :created_by_id
|
33
|
+
t.integer :updated_by_id
|
34
|
+
|
35
|
+
t.timestamps
|
36
|
+
end
|
37
|
+
|
38
|
+
add_index :dynamic_forms, :created_by_id
|
39
|
+
add_index :dynamic_forms, :updated_by_id
|
40
|
+
add_index :dynamic_forms, :dynamic_form_model_id
|
41
|
+
add_index :dynamic_forms, :model_name
|
42
|
+
add_index :dynamic_forms, :internal_identifier
|
43
|
+
end
|
44
|
+
|
45
|
+
unless table_exists?(:dynamic_data)
|
46
|
+
create_table :dynamic_data do |t|
|
47
|
+
t.string :reference_type
|
48
|
+
t.integer :reference_id
|
49
|
+
t.text :dynamic_attributes
|
50
|
+
|
51
|
+
t.integer :created_with_form_id
|
52
|
+
t.integer :updated_with_form_id
|
53
|
+
|
54
|
+
t.integer :created_by_id
|
55
|
+
t.integer :updated_by_id
|
56
|
+
|
57
|
+
t.timestamps
|
58
|
+
end
|
59
|
+
|
60
|
+
add_index :dynamic_data, :created_with_form_id
|
61
|
+
add_index :dynamic_data, :updated_with_form_id
|
62
|
+
add_index :dynamic_data, :created_by_id
|
63
|
+
add_index :dynamic_data, :updated_by_id
|
64
|
+
add_index :dynamic_data, :reference_type
|
65
|
+
add_index :dynamic_data, :reference_id
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.down
|
71
|
+
[ :dynamic_form_models,
|
72
|
+
:dynamic_form_documents,
|
73
|
+
:dynamic_forms,
|
74
|
+
:dynamic_data
|
75
|
+
].each do |tbl|
|
76
|
+
if table_exists?(tbl)
|
77
|
+
drop_table tbl
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
|
2
|
+
DynamicAttributes.module_eval do
|
3
|
+
# Overrides the initializer to take dynamic attributes into account
|
4
|
+
def initialize(attributes = nil, options = {})
|
5
|
+
dynamic_attributes = {}
|
6
|
+
(attributes ||= {}).each{|att,value| dynamic_attributes[att] = value if att.to_s.starts_with?(self.dynamic_attribute_prefix) }
|
7
|
+
super(attributes.except(*dynamic_attributes.keys), options)
|
8
|
+
set_dynamic_attributes(dynamic_attributes)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
class DynamicFormField
|
2
|
+
=begin
|
3
|
+
Field Options TODO
|
4
|
+
searchable
|
5
|
+
|
6
|
+
Field Types TODO
|
7
|
+
special:
|
8
|
+
password
|
9
|
+
file upload
|
10
|
+
|
11
|
+
complex (for future implementation):
|
12
|
+
concatenated
|
13
|
+
calculated
|
14
|
+
related
|
15
|
+
=end
|
16
|
+
|
17
|
+
# options = {
|
18
|
+
# :fieldLabel => Field label text string
|
19
|
+
# :name => Field variable name string
|
20
|
+
# :allowblank => required true or false
|
21
|
+
# :value => prepopulated default value string
|
22
|
+
# :readonly => disabled true or false
|
23
|
+
# :maxlength => maxLength integer
|
24
|
+
# :width => size integer
|
25
|
+
# :validation_regex => regex string
|
26
|
+
# }
|
27
|
+
|
28
|
+
##################
|
29
|
+
# SPECIAL FIELDS #
|
30
|
+
##################
|
31
|
+
def self.email(options={})
|
32
|
+
options[:validation_regex] = "^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$"
|
33
|
+
DynamicFormField.basic_field('textfield', options)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.numberfield(options={})
|
37
|
+
DynamicFormField.basic_field('numberfield', options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.datefield(options={})
|
41
|
+
DynamicFormField.basic_field('datefield', options)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.timefield(options={})
|
45
|
+
DynamicFormField.basic_field('timefield', options)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.yesno(selections=[], options={})
|
49
|
+
selections = [['yes', 'Yes'],['no', 'No']]
|
50
|
+
DynamicFormField.basic_field('combo', options, selections)
|
51
|
+
end
|
52
|
+
|
53
|
+
################
|
54
|
+
# BASIC FIELDS #
|
55
|
+
################
|
56
|
+
# selections is an array of tuples, i.e. [['AL', 'Alabama'],['AK', 'Alaska']] - [value, text]
|
57
|
+
def self.combobox(selections=[], options={})
|
58
|
+
DynamicFormField.basic_field('combo', options, selections)
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.textfield(options={})
|
62
|
+
DynamicFormField.basic_field('textfield', options)
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.textarea(options={})
|
66
|
+
options[:height] = 100 if options[:height].nil?
|
67
|
+
DynamicFormField.basic_field('textarea', options)
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.checkbox(options={})
|
71
|
+
DynamicFormField.basic_field('checkbox', options)
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.hidden(options={})
|
75
|
+
DynamicFormField.basic_field('hidden', options)
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.basic_field(xtype, options={}, selections=[])
|
79
|
+
options = DynamicFormField.set_default_field_options(options)
|
80
|
+
|
81
|
+
field = {
|
82
|
+
:xtype => xtype,
|
83
|
+
:fieldLabel => options[:fieldLabel],
|
84
|
+
:name => options[:name],
|
85
|
+
:value => options[:value],
|
86
|
+
:allowBlank => options[:allowblank],
|
87
|
+
:readOnly => options[:readonly],
|
88
|
+
:width =>options[:width],
|
89
|
+
:height => options[:height],
|
90
|
+
:labelWidth => options[:labelwidth]
|
91
|
+
}
|
92
|
+
|
93
|
+
field[:maxLength] = options[:maxlength] unless options[:maxlength].nil?
|
94
|
+
|
95
|
+
if selections and selections != []
|
96
|
+
field[:store] = selections.to_json
|
97
|
+
end
|
98
|
+
|
99
|
+
if options[:validation_regex] or options[:validator_function]
|
100
|
+
field[:validateOnBlur] = true
|
101
|
+
end
|
102
|
+
|
103
|
+
if options[:validation_regex] and options[:validation_regex] != ''
|
104
|
+
field[:validation_regex] = options[:validation_regex]
|
105
|
+
end
|
106
|
+
|
107
|
+
if options[:validator_function] and options[:validator_function] != ''
|
108
|
+
field[:validator_function] = options[:validator_function]
|
109
|
+
end
|
110
|
+
|
111
|
+
field
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.set_default_field_options(options={})
|
115
|
+
|
116
|
+
options[:fieldLabel] = '' if options[:fieldLabel].nil?
|
117
|
+
options[:name] = '' if options[:name].nil?
|
118
|
+
options[:allowblank] = true if options[:allowblank].nil?
|
119
|
+
options[:value] = '' if options[:value].nil?
|
120
|
+
options[:readonly] = false if options[:readonly].nil?
|
121
|
+
options[:maxlength] = nil if options[:maxlength].nil?
|
122
|
+
options[:width] = 200 if options[:width].nil?
|
123
|
+
options[:height] = nil if options[:height].nil?
|
124
|
+
options[:validation_regex] = '' if options[:validation_regex].nil?
|
125
|
+
options[:labelwidth] = 75 if options[:labelwidth].nil?
|
126
|
+
|
127
|
+
options
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
class DynamicGridColumn
|
2
|
+
|
3
|
+
def self.build_column(field_hash, options={})
|
4
|
+
field_hash.symbolize_keys!
|
5
|
+
header = field_hash[:fieldLabel]
|
6
|
+
type = DynamicGridColumn.convert_xtype_to_column_type(field_hash[:xtype])
|
7
|
+
data_index = field_hash[:name]
|
8
|
+
|
9
|
+
if type == 'date'
|
10
|
+
renderer = "Ext.util.Format.dateRenderer('m/d/Y')"
|
11
|
+
else
|
12
|
+
renderer = ''
|
13
|
+
end
|
14
|
+
|
15
|
+
col = "{
|
16
|
+
\"header\":\"#{header}\",
|
17
|
+
\"type\":\"#{type}\",
|
18
|
+
\"dataIndex\":\"#{data_index}\""
|
19
|
+
|
20
|
+
if options[:width]
|
21
|
+
col << ",\"width\":#{options[:width]}"
|
22
|
+
end
|
23
|
+
|
24
|
+
col += ",
|
25
|
+
\"renderer\": #{renderer}" if renderer != ''
|
26
|
+
|
27
|
+
if options[:editor]
|
28
|
+
readonly = field_hash[:readonly].blank? ? false : field_hash[:readonly]
|
29
|
+
col += ",
|
30
|
+
{
|
31
|
+
\"xtype\": \"#{field_hash[:xtype]}\",
|
32
|
+
\"readOnly\": \"#{readonly}\""
|
33
|
+
|
34
|
+
if field_hash[:validation_regex] and field_hash[:validation_regex] != ''
|
35
|
+
col += ",
|
36
|
+
\"validateOnBlur\": true,
|
37
|
+
\"validator\": function(v){
|
38
|
+
var pattern = /#{field_hash[:validation_regex]}/;
|
39
|
+
var regex = new RegExp(pattern);
|
40
|
+
return regex.test(v);
|
41
|
+
}"
|
42
|
+
end
|
43
|
+
col += "}"
|
44
|
+
end
|
45
|
+
|
46
|
+
col += "}"
|
47
|
+
|
48
|
+
col
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.build_delete_column(action='')
|
52
|
+
action = "var messageBox = Ext.MessageBox.confirm(
|
53
|
+
'Confirm', 'Are you sure?',
|
54
|
+
function(btn){
|
55
|
+
if (btn == 'yes'){
|
56
|
+
#{action}
|
57
|
+
}
|
58
|
+
});"
|
59
|
+
DynamicGridColumn.build_action_column("Delete", "/images/icons/delete/delete_16x16.png", action)
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.build_view_column(action='')
|
63
|
+
DynamicGridColumn.build_action_column("View", "/images/icons/document_view/document_view_16x16.png", action)
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.build_edit_column(action='')
|
67
|
+
DynamicGridColumn.build_action_column("Edit", "/images/icons/document_edit/document_edit_16x16.png", action)
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.build_action_column(header, icon, action)
|
71
|
+
col = '{
|
72
|
+
"menuDisabled":true,
|
73
|
+
"resizable":false,
|
74
|
+
"xtype":"actioncolumn",
|
75
|
+
"header":"'+header+'",
|
76
|
+
"align":"center",
|
77
|
+
"width":50,
|
78
|
+
"items":[{
|
79
|
+
"icon":"'+icon+'",
|
80
|
+
"tooltip":"'+header+'",
|
81
|
+
"handler" :function(grid, rowIndex, colIndex){
|
82
|
+
var rec = grid.getStore().getAt(rowIndex);
|
83
|
+
'+action+'
|
84
|
+
}
|
85
|
+
}]
|
86
|
+
}'
|
87
|
+
|
88
|
+
col
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.convert_xtype_to_column_type(xtype)
|
92
|
+
case xtype
|
93
|
+
when 'textfield'
|
94
|
+
return 'string'
|
95
|
+
when 'datefield'
|
96
|
+
return 'date'
|
97
|
+
when 'textarea'
|
98
|
+
return 'string'
|
99
|
+
when 'numberfield'
|
100
|
+
return 'number'
|
101
|
+
when 'actioncolumn'
|
102
|
+
return 'actioncolumn'
|
103
|
+
else
|
104
|
+
return 'string'
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'dynamic_attributes'
|
2
|
+
|
3
|
+
module ErpForms
|
4
|
+
class Engine < Rails::Engine
|
5
|
+
isolate_namespace ErpForms
|
6
|
+
|
7
|
+
initializer "erp_forms.merge_public" do |app|
|
8
|
+
app.middleware.insert_before Rack::Lock, ::ActionDispatch::Static, "#{root}/public"
|
9
|
+
end
|
10
|
+
|
11
|
+
ActiveSupport.on_load(:active_record) do
|
12
|
+
include ErpForms::Extensions::ActiveRecord::HasDynamicData
|
13
|
+
include ErpForms::Extensions::ActiveRecord::HasDynamicForms
|
14
|
+
end
|
15
|
+
|
16
|
+
config.to_prepare do
|
17
|
+
#dynamic_attributes patch
|
18
|
+
require "erp_forms/dynamic_attributes_patch"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|