knitkit 2.1.0 → 2.1.1

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.
@@ -0,0 +1,111 @@
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
+ plain: true,
8
+ buttonAlign:'center',
9
+ items: Ext.create("Ext.form.Panel",{
10
+ labelWidth: 100,
11
+ frame:false,
12
+ bodyStyle:'padding:5px 5px 0',
13
+ defaults: {
14
+ width: 325
15
+ },
16
+ items: [
17
+ {
18
+ xtype:'combo',
19
+ value:'',
20
+ loadingText:'Retrieving Dynamic Form Models ...',
21
+ store:Ext.create('Ext.data.Store',{
22
+ proxy:{
23
+ type:'ajax',
24
+ reader:{
25
+ type:'json',
26
+ root: 'dynamic_form_model'
27
+ },
28
+ url:'/erp_forms/erp_app/desktop/dynamic_forms/models/index'
29
+ },
30
+ fields:[
31
+ {
32
+ name:'id'
33
+ },
34
+ {
35
+ name:'model_name'
36
+ }
37
+ ]
38
+ }),
39
+ forceSelection:true,
40
+ editable:true,
41
+ fieldLabel:'Model Name',
42
+ autoSelect:true,
43
+ mode: 'remote',
44
+ name: 'model_name',
45
+ displayField:'model_name',
46
+ valueField:'model_name',
47
+ triggerAction: 'all',
48
+ allowBlank:false,
49
+ plugins: [new helpQtip("Dynamic Form Model Name (Class)")]
50
+ },
51
+ {
52
+ xtype:'textfield',
53
+ fieldLabel:'Form Width',
54
+ name: 'form_width',
55
+ allowBlank:true,
56
+ plugins: [new helpQtip("Form Width in Pixels. Leave blank for auto width.")]
57
+ }
58
+ ]
59
+ }),
60
+ buttons: [{
61
+ text:'Submit',
62
+ listeners:{
63
+ 'click':function(button){
64
+ var tpl = null;
65
+ var content = null;
66
+ var formPanel = button.findParentByType('window').query('form').first();
67
+ var basicForm = formPanel.getForm();
68
+ var WidgetDynamicFormModelName = basicForm.findField('model_name');
69
+ var WidgetDynamicFormWidth = basicForm.findField('form_width');
70
+ if (basicForm.isValid()){
71
+ var data = {
72
+ WidgetDynamicFormModelName: WidgetDynamicFormModelName.getValue(),
73
+ WidgetDynamicFormWidth: WidgetDynamicFormWidth.getValue()
74
+ };
75
+
76
+ tpl = new Ext.XTemplate(
77
+ "<% # Optional Parameters:\n",
78
+ " # internal_identifier: Models can have multiple forms\n",
79
+ " # Leave blank if you want to use the default form\n",
80
+ " # Specify internal_identifier to choose a specific form %>\n",
81
+ "<%= render_widget :dynamic_forms,\n",
82
+ " :params => {:model_name => '{WidgetDynamicFormModelName}',\n",
83
+ " :internal_identifier => ''",
84
+ '<tpl if="WidgetDynamicFormWidth">',
85
+ ",\n :width => {WidgetDynamicFormWidth} ",
86
+ '</tpl>',
87
+ "} %>");
88
+ content = tpl.apply(data);
89
+
90
+ //add rendered template to center region editor
91
+ Ext.getCmp('knitkitCenterRegion').addContentToActiveCodeMirror(content);
92
+ addDynamicFormWidgetWindow.close();
93
+ }
94
+ }
95
+ }
96
+ },{
97
+ text: 'Close',
98
+ handler: function(){
99
+ addDynamicFormWidgetWindow.close();
100
+ }
101
+ }]
102
+ });
103
+ addDynamicFormWidgetWindow.show();
104
+ }
105
+ };
106
+
107
+ Compass.ErpApp.Widgets.AvailableWidgets.push({
108
+ name:'Dynamic Forms',
109
+ iconUrl:'/images/icons/document_text/document_text_48x48.png',
110
+ onClick:Compass.ErpApp.Widgets.DynamicForms.addDynamicForm
111
+ });
@@ -0,0 +1,5 @@
1
+ <div>
2
+ <h1>An Error Occurred</h1>
3
+ <%= message unless message.nil? %>
4
+
5
+ </div>
@@ -0,0 +1,8 @@
1
+ <div id="<%=widget_result_id %>"></div>
2
+
3
+ <%=raw render_dynamic_form(params[:model_name], {
4
+ :internal_identifier => params[:internal_identifier],
5
+ :width => (params[:width] ? params[:width].to_i : nil)
6
+ }) %>
7
+
8
+ <div id="dynamic_form_target"></div>
@@ -0,0 +1,4 @@
1
+ <div>
2
+ <h1>Thank you.</h1>
3
+ <p>Your form has been processed successfully.</p>
4
+ </div>
@@ -0,0 +1,130 @@
1
+ module Widgets
2
+ module DynamicGrid
3
+ class Base < ErpApp::Widgets::Base
4
+
5
+ def index
6
+ @model_name = params[:model_name]
7
+ @title = params[:title] || params[:model_name]
8
+ @width = params[:width] || '100%'
9
+ @height = params[:height] || 500
10
+ @page = params[:page] || true
11
+ @page_size = params[:page_size] || 10
12
+ @display_msg = params[:display_msg] || 'Displaying {0} - {1} of {2}'
13
+ @empty_msg = params[:empty_msg] || 'Empty'
14
+
15
+ render :view => :index
16
+ end
17
+
18
+ def setup
19
+ begin
20
+ form = DynamicForm.get_form(params[:model_name])
21
+ raise "No Default Form found for this model." if form.nil?
22
+ definition = form.definition_object
23
+
24
+ columns = []
25
+ definition.each do |field_hash|
26
+ if field_hash[:display_in_grid]
27
+ # for some reason grid column widths are greater than form field widths
28
+ field_hash[:width] = (field_hash[:width].to_f * 0.56).round.to_i unless field_hash[:width].nil?
29
+ columns << DynamicGridColumn.build_column(field_hash)
30
+ end
31
+ end
32
+
33
+ columns << DynamicGridColumn.build_column({ :fieldLabel => "Created By", :name => 'created_username', :xtype => 'textfield', :width => 100 })
34
+ columns << DynamicGridColumn.build_column({ :fieldLabel => "Created At", :name => 'created_at', :xtype => 'datefield', :width => 115 })
35
+ columns << DynamicGridColumn.build_column({ :fieldLabel => "Updated By", :name => 'updated_username', :xtype => 'textfield', :width => 100 })
36
+ columns << DynamicGridColumn.build_column({ :fieldLabel => "Updated At", :name => 'updated_at', :xtype => 'datefield', :width => 115 })
37
+
38
+ definition << DynamicFormField.textfield({ :fieldLabel => "Created By", :name => 'created_username' })
39
+ definition << DynamicFormField.datefield({ :fieldLabel => "Created At", :name => 'created_at' })
40
+ definition << DynamicFormField.textfield({ :fieldLabel => "Updated By", :name => 'updated_username' })
41
+ definition << DynamicFormField.datefield({ :fieldLabel => "Updated At", :name => 'updated_at' })
42
+ definition << DynamicFormField.hiddenfield({ :fieldLabel => "ID", :name => 'id' })
43
+ definition << DynamicFormField.hiddenfield({ :fieldLabel => "Form ID", :name => 'form_id' })
44
+ definition << DynamicFormField.hiddenfield({ :fieldLabel => "Model Name", :name => 'model_name' })
45
+
46
+ render :inline => "{
47
+ \"success\": true,
48
+ \"use_ext_forms\":false,
49
+ \"inline_edit\":false,
50
+ \"columns\": [#{columns.join(',')}],
51
+ \"fields\": #{definition.to_json}
52
+ }"
53
+
54
+ rescue Exception => e
55
+ Rails.logger.error e.message
56
+ Rails.logger.error e.backtrace.join("\n")
57
+ render :inline => {
58
+ :success => false,
59
+ :message => e.message
60
+ }.to_json
61
+ end
62
+ end
63
+
64
+ def data
65
+ begin
66
+ sort = (params[:sort] || 'created_at').downcase
67
+ dir = (params[:dir] || 'desc').downcase
68
+ page = params[:page]
69
+ per_page = params[:per_page]
70
+
71
+ query_filter = params[:query_filter].strip rescue nil
72
+
73
+ myDynamicObject = DynamicFormModel.get_constant(params[:model_name])
74
+
75
+ if $USE_SOLR_FOR_DYNAMIC_FORM_MODELS and myDynamicObject.is_searchable?
76
+ solr_search_results = myDynamicObject.search do
77
+ keywords query_filter unless params[:query_filter].blank?
78
+ paginate(:page => page, :per_page => per_page)
79
+ order_by(sort.to_sym, dir.to_sym)
80
+ end
81
+ dynamic_records = solr_search_results.results
82
+ else
83
+ dynamic_records = myDynamicObject.paginate(:page => page, :per_page => per_page, :order => "#{sort} #{dir}")
84
+ dynamic_records = dynamic_records.joins(:dynamic_data).where("UPPER(dynamic_data.dynamic_attributes) LIKE UPPER('%#{query_filter}%')") unless params[:query_filter].blank?
85
+ end
86
+
87
+ related_fields = dynamic_records.first.form.related_fields rescue []
88
+
89
+ wi = []
90
+ dynamic_records.each do |i|
91
+ wihash = i.data.dynamic_attributes_with_related_data(related_fields, false)
92
+ wihash[:id] = i.id
93
+ wihash[:created_username] = i.data.created_by.nil? ? '' : i.data.created_by.username
94
+ wihash[:updated_username] = i.data.updated_by.nil? ? '' : i.data.updated_by.username
95
+ wihash[:created_at] = i.data.created_at.getlocal.strftime("%m/%d/%Y")
96
+ wihash[:updated_at] = i.data.updated_at.getlocal.strftime("%m/%d/%Y")
97
+ wihash[:form_id] = (i.data.updated_with_form_id ? i.data.updated_with_form_id : i.data.created_with_form_id)
98
+ wihash[:model_name] = params[:model_name]
99
+ wi << wihash
100
+ end
101
+
102
+ render :inline => "{ total:#{dynamic_records.total_entries}, data:#{wi.to_json} }"
103
+ rescue Exception => e
104
+ Rails.logger.error e.message
105
+ Rails.logger.error e.backtrace.join("\n")
106
+ render :inline => {
107
+ :success => false,
108
+ :message => e.message
109
+ }.to_json
110
+ end
111
+ end
112
+
113
+ #should not be modified
114
+ #modify at your own risk
115
+ def locate
116
+ File.dirname(__FILE__)
117
+ end
118
+
119
+ class << self
120
+ def title
121
+ "Dynamic Grid"
122
+ end
123
+
124
+ def widget_name
125
+ File.basename(File.dirname(__FILE__))
126
+ end
127
+ end
128
+ end#Base
129
+ end#DynamicGrid
130
+ end#Widgets
@@ -0,0 +1,3 @@
1
+ module DynamicGridControllerHelper
2
+ #add helper methods for you engines controller
3
+ end
@@ -0,0 +1,3 @@
1
+ module DynamicGridViewHelper
2
+ #add helper methods for your engines views
3
+ end
@@ -0,0 +1,178 @@
1
+ Compass.ErpApp.Widgets.DynamicGrid = {
2
+ addWidget:function () {
3
+ Ext.create("Ext.window.Window", {
4
+ title:'Add Dynamic Grid',
5
+ plain:true,
6
+ buttonAlign:'center',
7
+ items:Ext.create("Ext.form.Panel", {
8
+ labelWidth:100,
9
+ frame:false,
10
+ bodyStyle:'padding:5px 5px 0',
11
+ defaults:{
12
+ width:325
13
+ },
14
+ items:[
15
+ {
16
+ xtype:'combo',
17
+ value:'',
18
+ loadingText:'Retrieving Dynamic Form Models ...',
19
+ store:Ext.create('Ext.data.Store', {
20
+ proxy:{
21
+ type:'ajax',
22
+ reader:{
23
+ type:'json',
24
+ root:'dynamic_form_model'
25
+ },
26
+ url:'/erp_forms/erp_app/desktop/dynamic_forms/models/index'
27
+ },
28
+ fields:[
29
+ {
30
+ name:'id'
31
+ },
32
+ {
33
+ name:'model_name'
34
+ }
35
+ ]
36
+ }),
37
+ forceSelection:true,
38
+ editable:true,
39
+ fieldLabel:'Model Name',
40
+ autoSelect:true,
41
+ mode:'remote',
42
+ name:'model_name',
43
+ displayField:'model_name',
44
+ valueField:'model_name',
45
+ triggerAction:'all',
46
+ allowBlank:false,
47
+ plugins:[new helpQtip("Dynamic Form Model Name (Class)")],
48
+ listeners:{
49
+ select:function(){
50
+ this.up('form').down('fieldset').enable();
51
+ }
52
+ }
53
+ },
54
+ {
55
+ xtype:'fieldset',
56
+ title:'Grid Options',
57
+ disabled:true,
58
+ items:[
59
+ {
60
+ xtype:'textfield',
61
+ name:'title',
62
+ fieldLabel:'Title'
63
+ },
64
+ {
65
+ xtype:'textfield',
66
+ name:'width',
67
+ value:500,
68
+ fieldLabel:'Width'
69
+ },
70
+ {
71
+ xtype:'textfield',
72
+ name:'height',
73
+ value:500,
74
+ fieldLabel:'Height'
75
+ },
76
+ {
77
+ xtype:'fieldcontainer',
78
+ defaultType:'radiofield',
79
+ width:200,
80
+ defaults:{
81
+ flex:1
82
+ },
83
+ layout:'hbox',
84
+ fieldLabel:'Page Results',
85
+ toolTip:'Page results.',
86
+ items:[
87
+ {
88
+ boxLabel:'Yes',
89
+ name:'page_results',
90
+ checked:true,
91
+ inputValue:'y'
92
+ },
93
+ {
94
+ boxLabel:'No',
95
+ name:'page_results',
96
+ inputValue:'n'
97
+ }
98
+ ]
99
+ },
100
+ {
101
+ xtype:'textfield',
102
+ name:'pageSize',
103
+ value:20,
104
+ fieldLabel:'Rows per Page'
105
+ },
106
+ {
107
+ xtype:'textfield',
108
+ name:'displayMsg',
109
+ value:'Displaying {0} - {1} of {2}',
110
+ fieldLabel:'Paging Display Message'
111
+ },
112
+ {
113
+ xtype:'textfield',
114
+ name:'emptyMsg',
115
+ value:'Empty',
116
+ fieldLabel:'Empty Message'
117
+ }
118
+ ]
119
+ }
120
+ ]
121
+ }),
122
+ buttons:[
123
+ {
124
+ text:'Submit',
125
+ listeners:{
126
+ 'click':function (button) {
127
+ var tpl = new Ext.XTemplate("<%= render_widget :dynamic_grid, :params => {:model_name => '{model_name}',\n",
128
+ " :grid => {\n",
129
+ " :title => '{title}',\n",
130
+ " :width => {width},\n",
131
+ " :height => {height},\n",
132
+ " :page => {page_results:this.toBoolean},\n",
133
+ " :page_size => {pageSize},\n",
134
+ " :display_msg => '{displayMsg}',\n",
135
+ " :empty_msg => '{emptyMsg}'\n",
136
+ " }\n",
137
+ "} %>",
138
+ {
139
+ toBoolean:function (value) {
140
+ var result = 'false';
141
+ if (value == 'y') {
142
+ result = 'true';
143
+ }
144
+ return result;
145
+ }
146
+ }),
147
+ content = null,
148
+ window = button.findParentByType('window'),
149
+ formPanel = window.query('form')[0],
150
+ grid = formPanel.down('grid'),
151
+ basicForm = formPanel.getForm(),
152
+ values = basicForm.getValues();
153
+
154
+ content = tpl.apply(values);
155
+
156
+ //add rendered template to center region editor
157
+ Ext.getCmp('knitkitCenterRegion').addContentToActiveCodeMirror(content);
158
+ button.up('window').close();
159
+ }
160
+ }
161
+ },
162
+ {
163
+ text:'Close',
164
+ handler:function (btn) {
165
+ btn.up('window').close();
166
+ }
167
+ }
168
+ ]
169
+ }).show();
170
+ }
171
+ }
172
+
173
+ Compass.ErpApp.Widgets.AvailableWidgets.push({
174
+ name:'Dynamic Grid',
175
+ iconUrl:'/images/icons/grid/grid_48x48.png',
176
+ onClick:Compass.ErpApp.Widgets.DynamicGrid.addWidget,
177
+ about:'Add grid for dynamic model'
178
+ });