erp_forms 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/GPL-3-LICENSE +674 -0
  2. data/README.rdoc +2 -0
  3. data/Rakefile +30 -0
  4. data/app/assets/javascripts/erp_forms/application.js +9 -0
  5. data/app/assets/stylesheets/erp_forms/application.css +7 -0
  6. data/app/controllers/erp_forms/erp_app/desktop/dynamic_forms/base_controller.rb +47 -0
  7. data/app/controllers/erp_forms/erp_app/desktop/dynamic_forms/data_controller.rb +87 -0
  8. data/app/controllers/erp_forms/erp_app/desktop/dynamic_forms/forms_controller.rb +79 -0
  9. data/app/controllers/erp_forms/erp_app/desktop/dynamic_forms/models_controller.rb +45 -0
  10. data/app/helpers/erp_forms/application_helper.rb +4 -0
  11. data/app/models/dynamic_datum.rb +65 -0
  12. data/app/models/dynamic_form.rb +191 -0
  13. data/app/models/dynamic_form_document.rb +29 -0
  14. data/app/models/dynamic_form_model.rb +42 -0
  15. data/app/views/layouts/application.html.erb +14 -0
  16. data/app/views/layouts/erp_forms/application.html.erb +14 -0
  17. data/app/widgets/dynamic_forms/base.rb +61 -0
  18. data/app/widgets/dynamic_forms/javascript/dynamic_forms.js +109 -0
  19. data/app/widgets/dynamic_forms/views/error.html.erb +4 -0
  20. data/app/widgets/dynamic_forms/views/index.html.erb +8 -0
  21. data/app/widgets/dynamic_forms/views/success.html.erb +4 -0
  22. data/config/routes.rb +6 -0
  23. data/db/data_migrations/20110608185830_create_default_dynamic_models_and_forms.rb +30 -0
  24. data/db/data_migrations/20110822170240_update_contact_form_validation.rb +22 -0
  25. data/db/data_migrations/20110828190913_create_desktop_app_dynamic_forms.rb +18 -0
  26. data/db/data_migrations/20110830170240_update_contact_form.rb +23 -0
  27. data/db/migrate/20110530193446_dynamic_forms.rb +82 -0
  28. data/lib/erp_forms/dynamic_attributes_patch.rb +10 -0
  29. data/lib/erp_forms/dynamic_form_field.rb +130 -0
  30. data/lib/erp_forms/dynamic_grid_column.rb +108 -0
  31. data/lib/erp_forms/engine.rb +22 -0
  32. data/lib/erp_forms/extensions/active_record/has_dynamic_data.rb +54 -0
  33. data/lib/erp_forms/extensions/active_record/has_dynamic_forms.rb +70 -0
  34. data/lib/erp_forms/extensions/extensions.rb +6 -0
  35. data/lib/erp_forms/extensions/railties/action_view.rb +20 -0
  36. data/lib/erp_forms/version.rb +3 -0
  37. data/lib/erp_forms.rb +11 -0
  38. data/lib/tasks/erp_forms_tasks.rake +4 -0
  39. data/public/javascripts/erp_app/desktop/applications/dynamic_forms/center_region.js +23 -0
  40. data/public/javascripts/erp_app/desktop/applications/dynamic_forms/dynamic_data_grid.js +81 -0
  41. data/public/javascripts/erp_app/desktop/applications/dynamic_forms/form_builder.js +93 -0
  42. data/public/javascripts/erp_app/desktop/applications/dynamic_forms/module.js +37 -0
  43. data/public/javascripts/erp_app/desktop/applications/dynamic_forms/west_region.js +468 -0
  44. data/public/javascripts/erp_app/shared/dynamic_forms/dynamic_forms_validation.js +4 -0
  45. data/spec/dummy/Rakefile +7 -0
  46. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  47. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  48. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  49. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  50. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  51. data/spec/dummy/config/application.rb +45 -0
  52. data/spec/dummy/config/boot.rb +10 -0
  53. data/spec/dummy/config/database.yml +8 -0
  54. data/spec/dummy/config/environment.rb +5 -0
  55. data/spec/dummy/config/environments/spec.rb +27 -0
  56. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  57. data/spec/dummy/config/initializers/inflections.rb +10 -0
  58. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  59. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  60. data/spec/dummy/config/initializers/session_store.rb +8 -0
  61. data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
  62. data/spec/dummy/config/locales/en.yml +5 -0
  63. data/spec/dummy/config/routes.rb +4 -0
  64. data/spec/dummy/config.ru +4 -0
  65. data/spec/dummy/public/404.html +26 -0
  66. data/spec/dummy/public/422.html +26 -0
  67. data/spec/dummy/public/500.html +26 -0
  68. data/spec/dummy/public/favicon.ico +0 -0
  69. data/spec/dummy/script/rails +6 -0
  70. data/spec/models/dynamic_datum_spec.rb +9 -0
  71. data/spec/models/dynamic_form_document_spec.rb +11 -0
  72. data/spec/models/dynamic_form_model_spec.rb +11 -0
  73. data/spec/models/dynamic_form_spec.rb +11 -0
  74. data/spec/spec_helper.rb +60 -0
  75. metadata +183 -0
@@ -0,0 +1,54 @@
1
+ module ErpForms
2
+ module Extensions
3
+ module ActiveRecord
4
+ module HasDynamicData
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+ def has_dynamic_data
11
+ include HasDynamicData::InstanceMethods
12
+
13
+ after_save :save_dynamic_data
14
+ after_initialize :initialize_dynamic_data
15
+
16
+ has_one :dynamic_data, :as => :reference, :class_name => 'DynamicDatum', :dependent => :destroy
17
+
18
+ [:reference_type,:reference_type=,
19
+ :reference_id,:reference_id=,
20
+ :dynamic_attributes,:dynamic_attributes=,
21
+ ].each { |m| delegate m, :to => :dynamic_data }
22
+
23
+ end
24
+ end
25
+
26
+ module InstanceMethods
27
+
28
+ def data
29
+ self.dynamic_data
30
+ end
31
+
32
+ def save_dynamic_data
33
+ self.dynamic_data.save
34
+ end
35
+
36
+ def initialize_dynamic_data
37
+ if self.new_record? and self.dynamic_data.nil?
38
+ t = DynamicDatum.new
39
+ self.dynamic_data = t
40
+ t.reference = self
41
+ end
42
+
43
+ if self.class == DynamicFormDocument or self.class.superclass == DynamicFormDocument
44
+ if self.dynamic_form_model_id.nil?
45
+ dfm = DynamicFormModel.find_by_model_name(self.class.to_s)
46
+ self.dynamic_form_model_id = dfm.id unless dfm.nil?
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,70 @@
1
+ module ErpForms
2
+ module Extensions
3
+ module ActiveRecord
4
+ module HasDynamicForms
5
+
6
+ def self.included(base)
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+
12
+ def has_dynamic_forms
13
+ attr_accessor :dynamic_form
14
+
15
+ include HasDynamicForms::InstanceMethods
16
+
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 })
20
+ end
21
+ end
22
+
23
+ end
24
+
25
+ module InstanceMethods
26
+
27
+ def new_form
28
+ d = DynamicForm.new
29
+ d.model_name = self.class.to_s
30
+ d.dynamic_form_model_id = self.dynamic_form_model_id
31
+ return self.dynamic_form = d
32
+ end
33
+
34
+ def form
35
+ unless self.dynamic_form.nil?
36
+ return self.dynamic_form
37
+ else
38
+ current_form = default_form
39
+ unless current_form.nil?
40
+ return current_form
41
+ else
42
+ return new_form
43
+ end
44
+ end
45
+ end
46
+
47
+ def default_form
48
+ get_form
49
+ end
50
+
51
+ # get active form by type and active columns
52
+ def get_form(internal_identifier='')
53
+ self.dynamic_form = DynamicForm.get_form(self.class.to_s, internal_identifier)
54
+ end
55
+
56
+ # get all forms by type
57
+ def forms
58
+ DynamicForm.find_all_by_model_name(self.class_name)
59
+ end
60
+
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}")
64
+ end
65
+
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,6 @@
1
+ #railties
2
+ require 'erp_forms/extensions/railties/action_view'
3
+
4
+ #active_record extensions
5
+ require 'erp_forms/extensions/active_record/has_dynamic_data'
6
+ require 'erp_forms/extensions/active_record/has_dynamic_forms'
@@ -0,0 +1,20 @@
1
+ ActionView::Base.class_eval do
2
+
3
+ # name is ClassName of form you want
4
+ # options are optional
5
+ # options = {
6
+ # :internal_identifier => 'iid of exact form you want' (a model can have multiple forms)
7
+ # :width => 'width of form in pixels'
8
+ # }
9
+ def render_dynamic_form(name, options={})
10
+
11
+ form = DynamicForm.get_form(name.to_s, options[:internal_identifier]).to_extjs_widget(
12
+ { :url => build_widget_url(:new),
13
+ :widget_result_id => widget_result_id,
14
+ :width => options[:width]
15
+ })
16
+
17
+ form
18
+ end
19
+
20
+ end
@@ -0,0 +1,3 @@
1
+ module ErpForms
2
+ VERSION = "2.0.0"
3
+ end
data/lib/erp_forms.rb ADDED
@@ -0,0 +1,11 @@
1
+ #compass libraries
2
+ require 'erp_tech_svcs'
3
+
4
+ require 'erp_forms/dynamic_form_field'
5
+ require 'erp_forms/dynamic_grid_column'
6
+ require 'erp_forms/dynamic_form_field'
7
+ require 'erp_forms/extensions/extensions'
8
+ require "erp_forms/engine"
9
+
10
+ module ErpForms
11
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :erp_forms do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,23 @@
1
+ Ext.define("Compass.ErpApp.Desktop.Applications.DynamicForms.CenterRegion",{
2
+ extend:"Ext.panel.Panel",
3
+ alias:'widget.dynamic_forms_centerregion',
4
+
5
+ constructor : function(config) {
6
+ this.workArea = new Ext.TabPanel({
7
+ autoDestroy:true,
8
+ region:'center'
9
+ });
10
+
11
+ config = Ext.apply({
12
+ id:'dynamic_formsCenterRegion',
13
+ autoDestroy:true,
14
+ layout:'border',
15
+ region:'center',
16
+ split:true,
17
+ items:[this.workArea]
18
+ }, config);
19
+
20
+ this.callParent([config]);
21
+ }
22
+ });
23
+
@@ -0,0 +1,81 @@
1
+ Ext.define("Compass.ErpApp.Desktop.Applications.DynamicForms.DynamicDataGridPanel",{
2
+ extend:"Compass.ErpApp.Shared.DynamicEditableGridLoaderPanel",
3
+ alias:'widget.dynamic_forms_DynamicDataGridPanel',
4
+
5
+ editRecord : function(rec, model_name){
6
+ var self = this;
7
+ Ext.getCmp('westregionPanel').setWindowStatus('Getting update form...');
8
+ var conn = new Ext.data.Connection();
9
+ conn.request({
10
+ url: '/erp_forms/erp_app/desktop/dynamic_forms/forms/get',
11
+ method: 'POST',
12
+ params:{
13
+ id:rec.get("id"),
14
+ model_name:model_name,
15
+ form_action: 'update'
16
+ },
17
+ success: function(response) {
18
+ Ext.getCmp('westregionPanel').clearWindowStatus();
19
+ form_definition = Ext.decode(response.responseText);
20
+ var editRecordWindow = Ext.create("Ext.window.Window",{
21
+ layout:'fit',
22
+ title:'Update Record',
23
+ y: 100, // this fixes chrome and safari rendering the window at the bottom of the screen
24
+ plain: true,
25
+ buttonAlign:'center',
26
+ items: form_definition
27
+ });
28
+ Ext.getCmp('dynamic_form_panel').getForm().loadRecord(rec);
29
+ editRecordWindow.show();
30
+ },
31
+ failure: function(response) {
32
+ Ext.getCmp('westregionPanel').clearWindowStatus();
33
+ Ext.Msg.alert('Error', 'Error getting form');
34
+ }
35
+ });
36
+ },
37
+
38
+ deleteRecord : function(rec, model_name){
39
+ var self = this;
40
+ Ext.getCmp('westregionPanel').setWindowStatus('Deleting record...');
41
+ var conn = new Ext.data.Connection();
42
+ conn.request({
43
+ url: '/erp_forms/erp_app/desktop/dynamic_forms/data/delete',
44
+ method: 'POST',
45
+ params:{
46
+ id:rec.get("id"),
47
+ model_name:model_name
48
+ },
49
+ success: function(response) {
50
+ var obj = Ext.decode(response.responseText);
51
+ if(obj.success){
52
+ Ext.getCmp('westregionPanel').clearWindowStatus();
53
+ self.query('shared_dynamiceditablegrid')[0].store.load();
54
+ }
55
+ else{
56
+ Ext.Msg.alert('Error', 'Error deleting record');
57
+ Ext.getCmp('westregionPanel').clearWindowStatus();
58
+ }
59
+ },
60
+ failure: function(response) {
61
+ Ext.getCmp('westregionPanel').clearWindowStatus();
62
+ Ext.Msg.alert('Error', 'Error deleting record');
63
+ }
64
+ });
65
+ },
66
+
67
+ constructor : function(config) {
68
+ config = Ext.apply({
69
+ id:'DynamicFormDataGridPanel',
70
+ title:'Dynamic Data',
71
+ editable:false,
72
+ page:true,
73
+ pageSize: 20,
74
+ displayMsg:'Displaying {0} - {1} of {2}',
75
+ emptyMsg:'Empty'
76
+ }, config);
77
+
78
+ this.callParent([config]);
79
+ }
80
+ });
81
+
@@ -0,0 +1,93 @@
1
+ Ext.define("Compass.ErpApp.Desktop.Applications.DynamicForms.FormBuilder",{
2
+ extend:"Ext.window.Window",
3
+ alias:'widget.dynamic_forms_FormBuilder',
4
+ initComponent : function() {
5
+
6
+ this.addEvents(
7
+ /**
8
+ * @event publish_success
9
+ * Fired after success response is recieved from server
10
+ * @param {Compass.ErpApp.Applications.Desktop.PublishWindow} this Object
11
+ * @param {Object} Server Response
12
+ */
13
+ "publish_success",
14
+ /**
15
+ * @event publish_failure
16
+ * Fired after response is recieved from server with error
17
+ * @param {Compass.ErpApp.Applications.Desktop.PublishWindow} this Object
18
+ * @param {Object} Server Response
19
+ */
20
+ "publish_failure"
21
+ );
22
+
23
+ this.callParent(arguments);
24
+ },
25
+
26
+ constructor : function(config) {
27
+ config = Ext.apply({
28
+ layout:'fit',
29
+ title:'Form Builder',
30
+ autoHeight:true,
31
+ iconCls:'icon-document',
32
+ width:400,
33
+ height:300,
34
+ buttonAlign:'center',
35
+ plain: true,
36
+ items: new Ext.form.FormPanel({
37
+ timeout: 130000,
38
+ // baseParams:config['baseParams'],
39
+ autoHeight:true,
40
+ labelWidth:110,
41
+ frame:false,
42
+ layout:'fit',
43
+ // url:config['url'],
44
+ defaults: {
45
+ width: 225
46
+ },
47
+ items: [{
48
+ xtype: 'textarea',
49
+ hideLabel:true,
50
+ name:'comment'
51
+ }]
52
+ }),
53
+ buttons: [{
54
+ text:'Submit',
55
+ listeners:{
56
+ 'click':function(button){
57
+ var win = button.findParentByType('dynamic_forms_form_builer');
58
+ var formPanel = win.findByType('form')[0];
59
+ formPanel.getForm().submit({
60
+ method:'POST',
61
+ waitMsg:'Publishing...',
62
+ success:function(form, action){
63
+ var response = Ext.util.JSON.decode(action.response.responseText);
64
+ win.fireEvent('publish_success', win, response);
65
+ win.close();
66
+ },
67
+ failure:function(form, action){
68
+ var response = Ext.util.JSON.decode(action.response.responseText);
69
+ win.fireEvent('publish_failure', win, response);
70
+ win.close();
71
+ }
72
+ });
73
+ }
74
+ }
75
+ },
76
+ {
77
+ text: 'Cancel',
78
+ listeners:{
79
+ 'click':function(button){
80
+ var win = button.findParentByType('dynamic_forms_form_builer');
81
+ var form = win.findByType('form')[0];
82
+ form.getForm().reset();
83
+ win.close();
84
+ }
85
+ }
86
+ }]
87
+ }, config);
88
+
89
+ this.callParent([config]);
90
+ }
91
+
92
+ });
93
+
@@ -0,0 +1,37 @@
1
+ Ext.define("Compass.ErpApp.Desktop.Applications.DynamicForms",{
2
+ extend:"Ext.ux.desktop.Module",
3
+ id:'dynamic_forms-win',
4
+ init : function(){
5
+ this.launcher = {
6
+ text: 'Dynamic Forms',
7
+ iconCls:'icon-document',
8
+ handler: this.createWindow,
9
+ scope: this
10
+ }
11
+ },
12
+
13
+ createWindow : function(){
14
+ var desktop = this.app.getDesktop();
15
+ var win = desktop.getWindow('dynamic_forms');
16
+ this.centerRegion = new Compass.ErpApp.Desktop.Applications.DynamicForms.CenterRegion();
17
+ if(!win){
18
+ win = desktop.createWindow({
19
+ id: 'dynamic_forms',
20
+ title:'Dynamic Forms',
21
+ width:1150,
22
+ height:550,
23
+ iconCls: 'icon-document',
24
+ shim:false,
25
+ animCollapse:false,
26
+ constrainHeader:true,
27
+ layout: 'border',
28
+ items:[this.centerRegion,{
29
+ xtype:'dynamic_forms_westregion',
30
+ centerRegion:this.centerRegion,
31
+ module:this
32
+ }]
33
+ });
34
+ }
35
+ win.show();
36
+ }
37
+ });