erp_forms 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,2 +1,86 @@
1
1
  = ErpForms
2
2
 
3
+ ERP Forms adds dynamic forms to Compass using ExtJS.
4
+
5
+
6
+ == Models
7
+
8
+ DynamicFormModel - Used for keeping track of what models have forms. Every model that uses the has_dynamic_forms "mixin", extends DynamicFormDocument or simply wants to use DynamicForm, needs to be given a record in the dynamic_form_models table.
9
+
10
+ DynamicDatum - This is where dynamic attributes are stored. Any model that uses has_dynamic_data will store its data in the dynamic_data table.
11
+
12
+ DynamicForm - Handles dynamic forms. Each model can have many forms which are looked up by model_name. Every model must have a default form but any form can be retrieved using an internal_identifier. Form definition is a JSON string which is equivalent to an ExtJS form definition which is an array of hashes.
13
+
14
+ DynamicFormDocument - This model enables the creation of dynamic records using has_dynamic_forms and has_dynamic_data. DynamicFormDocument can explicitly be subclassed or a subclass can be declared on the fly using the "declare" class method.
15
+
16
+
17
+ == Mixins
18
+
19
+ has_dynamic_forms - Adds dynamic forms to any model.
20
+
21
+ has_dynamic_data - Adds dynamic data to any model
22
+
23
+
24
+ == Libraries
25
+
26
+ DynamicGridColumn - Builds ExtJS dynamic grid columns.
27
+
28
+ DynamicFormField - Builds ExtJS dynamic form fields. This is done in text in order to support validation. Outputs JSON strings which can be parsed into JSON Ruby objects. See the instance method "definition_object" on DynamicForm.
29
+
30
+
31
+ == Examples
32
+
33
+ Creating a DynamicFormModel
34
+ DynamicFormModel.create({ :model_name => "MyDynamicModel" })
35
+
36
+ Creating a DynamicForm
37
+ fields = []
38
+ fields << DynamicFormField.textfield({:fieldLabel => 'First Name', :name => 'first_name', :width => '200' })
39
+ fields << DynamicFormField.textfield({:fieldLabel => 'Last Name', :name => 'last_name', :width => '200' })
40
+ fields << DynamicFormField.email({:fieldLabel => 'Email', :name => 'email', :width => '200' })
41
+ fields << DynamicFormField.textarea({:fieldLabel => 'Message', :name => 'message', :width => '200' })
42
+
43
+ d = DynamicForm.new
44
+ d.description = 'My Dynamic Form'
45
+ d.definition = DynamicForm.concat_fields_to_build_definition(fields)
46
+ d.model_name = 'MyDynamicModel'
47
+ d.internal_identifier = 'my_dyn_model'
48
+ d.default = true
49
+ d.dynamic_form_model_id = DynamicFormModel.find_by_model_name('MyDynamicModel').id
50
+ d.save
51
+
52
+ Declaring a DynamicFormDocument on the fly
53
+ DynamicFormDocument.declare("MyDynamicModel")
54
+ @dyn_model = "MyDynamicModel".constantize.new
55
+ @dyn_model.data.created_with_form = @dyn_model.default_form
56
+
57
+ # create as many dynamic attributes as you need by prefixing them with "dyn_"
58
+ @dyn_model.data.dyn_my_dynamic_field = "hello world"
59
+
60
+ @dyn_model.data.created_by = current_user.id
61
+ @dyn_model.save
62
+
63
+ Subclassing DynamicFormDocument
64
+ class MyDynamicModel < DynamicFormDocument
65
+ # no need to declare mixins since they will be inherited from DynamicFormDocument
66
+ # so only reason to subclass is if you need custom methods
67
+ end
68
+
69
+ Adding dynamic forms and data to an existing model
70
+ class Party
71
+ has_dynamic_forms
72
+ has_dynamic_data
73
+ end
74
+
75
+ Using the Knitkit DynamicForms widget
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'} %>
78
+
79
+
80
+ == TODO
81
+
82
+ Dynamic Forms desktop application featuring a Dynamic Grid for every DynamicFormModel as well as a Dynamic Form Builder.
83
+
84
+
85
+ ============================================================
86
+ Copyright (c) 2011 Adam Hull
@@ -52,8 +52,14 @@ class ErpForms::ErpApp::Desktop::DynamicForms::FormsController < ErpForms::ErpAp
52
52
  end
53
53
 
54
54
  # get a single form
55
- def get
56
- form = DynamicForm.find(params[:id]).to_extjs_formpanel(
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)
60
+ end
61
+
62
+ form = dform.to_extjs_formpanel(
57
63
  { :url => "/erp_forms/erp_app/desktop/dynamic_forms/data/#{params[:form_action]}",
58
64
  :record_id => params[:id]
59
65
  })
@@ -29,7 +29,7 @@ class ErpForms::ErpApp::Desktop::DynamicForms::ModelsController < ErpForms::ErpA
29
29
  def delete
30
30
  DynamicFormModel.destroy(params[:id])
31
31
 
32
- render :json => {success => true}
32
+ render :json => {:success => true}
33
33
  end
34
34
 
35
35
  # create a dynamic form model
@@ -39,7 +39,7 @@ class ErpForms::ErpApp::Desktop::DynamicForms::ModelsController < ErpForms::ErpA
39
39
  :model_name => model_name
40
40
  })
41
41
 
42
- render :json => {success => true}
42
+ render :json => {:success => true}
43
43
  end
44
44
 
45
45
  end
@@ -12,7 +12,12 @@ class DynamicFormDocument < ActiveRecord::Base
12
12
  end
13
13
 
14
14
  def send_email
15
- WebsiteInquiryMailer.deliver_inquiry(self)
15
+ begin
16
+ WebsiteInquiryMailer.inquiry(self).deliver
17
+ rescue Exception => e
18
+ system_user = Party.find_by_description('Compass AE')
19
+ AuditLog.custom_application_log_message(system_user, e)
20
+ end
16
21
  end
17
22
 
18
23
  def self.class_exists?(class_name)
@@ -38,10 +38,6 @@ module Widgets
38
38
  def title
39
39
  "Dynamic Forms"
40
40
  end
41
-
42
- def views_location
43
- File.join(File.dirname(__FILE__),"/views")
44
- end
45
41
 
46
42
  def widget_name
47
43
  File.basename(File.dirname(__FILE__))
@@ -90,6 +90,7 @@ class DynamicFormField
90
90
  :labelWidth => options[:labelwidth]
91
91
  }
92
92
 
93
+ field[:mapping] = options[:mapping] unless options[:mapping].blank?
93
94
  field[:maxLength] = options[:maxlength] unless options[:maxlength].nil?
94
95
 
95
96
  if selections and selections != []
@@ -13,7 +13,10 @@ module ErpForms
13
13
  include ErpForms::Extensions::ActiveRecord::HasDynamicForms
14
14
  end
15
15
 
16
+ engine = self
16
17
  config.to_prepare do
18
+ ErpBaseErpSvcs.register_compass_ae_engine(engine)
19
+
17
20
  #dynamic_attributes patch
18
21
  require "erp_forms/dynamic_attributes_patch"
19
22
  end
@@ -1,3 +1,9 @@
1
1
  module ErpForms
2
- VERSION = "2.0.0"
2
+ module VERSION #:nodoc:
3
+ MAJOR = 2
4
+ MINOR = 0
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].compact.join('.')
8
+ end
3
9
  end
data/lib/erp_forms.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  #compass libraries
2
2
  require 'erp_tech_svcs'
3
3
 
4
+ require 'erp_forms/version'
4
5
  require 'erp_forms/dynamic_form_field'
5
6
  require 'erp_forms/dynamic_grid_column'
6
7
  require 'erp_forms/dynamic_form_field'
@@ -5,8 +5,7 @@ Ext.define("Compass.ErpApp.Desktop.Applications.DynamicForms.DynamicDataGridPane
5
5
  editRecord : function(rec, model_name){
6
6
  var self = this;
7
7
  Ext.getCmp('westregionPanel').setWindowStatus('Getting update form...');
8
- var conn = new Ext.data.Connection();
9
- conn.request({
8
+ Ext.Ajax.request({
10
9
  url: '/erp_forms/erp_app/desktop/dynamic_forms/forms/get',
11
10
  method: 'POST',
12
11
  params:{
@@ -38,8 +37,7 @@ Ext.define("Compass.ErpApp.Desktop.Applications.DynamicForms.DynamicDataGridPane
38
37
  deleteRecord : function(rec, model_name){
39
38
  var self = this;
40
39
  Ext.getCmp('westregionPanel').setWindowStatus('Deleting record...');
41
- var conn = new Ext.data.Connection();
42
- conn.request({
40
+ Ext.Ajax.request({
43
41
  url: '/erp_forms/erp_app/desktop/dynamic_forms/data/delete',
44
42
  method: 'POST',
45
43
  params:{
@@ -67,7 +65,7 @@ Ext.define("Compass.ErpApp.Desktop.Applications.DynamicForms.DynamicDataGridPane
67
65
  constructor : function(config) {
68
66
  config = Ext.apply({
69
67
  id:'DynamicFormDataGridPanel',
70
- title:'Dynamic Data',
68
+ //title:'Dynamic Data',
71
69
  editable:false,
72
70
  page:true,
73
71
  pageSize: 20,