rails_db_admin 3.0.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/{public → app/assets}/images/icons/rails_db_admin/rails_db_admin_16x16.png +0 -0
  3. data/{public → app/assets}/images/icons/rails_db_admin/rails_db_admin_24x24.png +0 -0
  4. data/{public → app/assets}/images/icons/rails_db_admin/rails_db_admin_32x32.png +0 -0
  5. data/{public → app/assets}/images/icons/rails_db_admin/rails_db_admin_64x64.png +0 -0
  6. data/{public → app/assets}/images/icons/rails_db_admin/rails_db_admin_light_16x16.png +0 -0
  7. data/app/assets/images/splash/db_admin_splash.png +0 -0
  8. data/{public → app/assets}/images/splash/images/console-icon.png +0 -0
  9. data/{public → app/assets}/images/splash/images/data-model-icon.png +0 -0
  10. data/app/assets/javascripts/erp_app/desktop/applications/rails_db_admin/app.js +20 -0
  11. data/{public → app/assets}/javascripts/erp_app/desktop/applications/rails_db_admin/database_combo.js +1 -1
  12. data/{public → app/assets}/javascripts/erp_app/desktop/applications/rails_db_admin/module.js +227 -135
  13. data/{public → app/assets}/javascripts/erp_app/desktop/applications/rails_db_admin/queries_tree_menu.js +6 -6
  14. data/app/assets/javascripts/erp_app/desktop/applications/rails_db_admin/query_panel.js +383 -0
  15. data/{public → app/assets}/javascripts/erp_app/desktop/applications/rails_db_admin/readonly_table_data_grid.js +0 -0
  16. data/app/assets/javascripts/erp_app/desktop/applications/rails_db_admin/reports/ParamWindow.js +426 -0
  17. data/app/assets/javascripts/erp_app/desktop/applications/rails_db_admin/reports/ParamsManager.js +177 -0
  18. data/app/assets/javascripts/erp_app/desktop/applications/rails_db_admin/reports/RolesPanel.js +95 -0
  19. data/app/assets/javascripts/erp_app/desktop/applications/rails_db_admin/reports/SetDefaultWindow.js +244 -0
  20. data/app/assets/javascripts/erp_app/desktop/applications/rails_db_admin/reports/Settings.js +155 -0
  21. data/app/assets/javascripts/erp_app/desktop/applications/rails_db_admin/reports/TreePanel.js +391 -0
  22. data/app/assets/javascripts/erp_app/desktop/applications/rails_db_admin/splash_screen.js +163 -0
  23. data/{public → app/assets}/javascripts/erp_app/desktop/applications/rails_db_admin/tables_tree_menu.js +5 -3
  24. data/app/assets/javascripts/erp_app/shared/MultiOption.js +151 -0
  25. data/app/assets/javascripts/erp_app/shared/ReportsParams.js +289 -0
  26. data/app/assets/javascripts/erp_app/shared/rails_db_admin_shared.js +13 -0
  27. data/{public/stylesheets/erp_app/desktop/applications/rails_db_admin/rails_db_admin.css → app/assets/stylesheets/erp_app/shared/rails_db_admin_shared.css} +5 -10
  28. data/app/controllers/rails_db_admin/erp_app/desktop/base_controller.rb +7 -6
  29. data/app/controllers/rails_db_admin/erp_app/desktop/queries_controller.rb +88 -74
  30. data/app/controllers/rails_db_admin/erp_app/desktop/reports_controller.rb +361 -30
  31. data/app/controllers/rails_db_admin/reports/base_controller.rb +105 -22
  32. data/app/mailers/report_mailer.rb +15 -0
  33. data/app/models/report.rb +227 -14
  34. data/app/views/rails_db_admin/reports/base/error_report.erb +27 -0
  35. data/app/views/report_mailer/email_report.html.erb +255 -0
  36. data/config/routes.rb +2 -1
  37. data/db/data_migrations/20110816005525_rails_db_admin_application.rb +6 -14
  38. data/db/data_migrations/20151015093724_add_report_role_type.rb +15 -0
  39. data/db/migrate/20121210160131_add_reports.rb +2 -0
  40. data/db/migrate/20150926061259_add_meta_data_to_reports.rb +9 -0
  41. data/lib/rails_db_admin.rb +4 -2
  42. data/lib/rails_db_admin/engine.rb +12 -4
  43. data/lib/rails_db_admin/erp_string_parser.rb +26 -0
  44. data/lib/rails_db_admin/extensions/railties/action_view/helpers/report_helper.rb +167 -10
  45. data/lib/rails_db_admin/extjs/json_data_builder.rb +36 -20
  46. data/lib/rails_db_admin/query_params.rb +14 -0
  47. data/lib/rails_db_admin/query_support.rb +56 -46
  48. data/lib/rails_db_admin/services/report_helper.rb +241 -0
  49. data/lib/rails_db_admin/version.rb +1 -1
  50. metadata +41 -30
  51. data/app/assets/javascripts/rails_db_admin/application.js +0 -9
  52. data/app/assets/stylesheets/rails_db_admin/application.css +0 -7
  53. data/app/views/rails_db_admin/reports/base/show_report.erb +0 -11
  54. data/db/migrate/20131112013053_add_rails_db_admin_missing_indexes.rb +0 -17
  55. data/lib/rails_db_admin/report_support.rb +0 -52
  56. data/public/images/splash/splash.png +0 -0
  57. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/query_panel.js +0 -223
  58. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/report_panel.js +0 -78
  59. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/reports_tree_panel.js +0 -237
  60. data/public/javascripts/erp_app/desktop/applications/rails_db_admin/splash_screen.js +0 -136
@@ -61,13 +61,13 @@ Ext.define("Compass.ErpApp.Desktop.Applications.RailsDbAdmin.QueriesMenuTreePane
61
61
  contextMenu = new Ext.menu.Menu({
62
62
  items:[
63
63
  {
64
- text:"New Query",
65
- iconCls:'icon-sql',
66
- listeners:{
67
- 'click':function(){
68
- self.initialConfig.module.addNewQueryTab();
64
+ text:"New Query",
65
+ iconCls:'icon-sql',
66
+ listeners:{
67
+ 'click':function(){
68
+ self.initialConfig.module.addNewQueryTab();
69
+ }
69
70
  }
70
- }
71
71
  }
72
72
  ]
73
73
  });
@@ -0,0 +1,383 @@
1
+ Ext.define("Compass.ErpApp.Desktop.Applications.RailsDbAdmin.QueryPanel", {
2
+ extend: "Ext.panel.Panel",
3
+ alias: 'widget.railsdbadmin_querypanel',
4
+ isReportQuery: false,
5
+ isNewQuery: false,
6
+ report: null,
7
+
8
+ getSql: function() {
9
+ return this.down('codemirror').getValue();
10
+ },
11
+
12
+ initComponent: function() {
13
+ var me = this;
14
+ var messageBox = null;
15
+
16
+ var savedQueriesJsonStore = Ext.create('Ext.data.Store', {
17
+ proxy: {
18
+ type: 'ajax',
19
+ url: '/rails_db_admin/erp_app/desktop/queries/saved_queries',
20
+ reader: {
21
+ type: 'json',
22
+ root: 'data'
23
+ }
24
+ },
25
+ fields: [{
26
+ name: 'value'
27
+ }, {
28
+ name: 'display'
29
+ }]
30
+ });
31
+
32
+ var tbarItems = [{
33
+ text: 'Execute',
34
+ iconCls: 'icon-playpause',
35
+ handler: function(button) {
36
+ if (me.paramPanelIsValid()) {
37
+ var textarea = me.query('.codemirror')[0];
38
+ var sql = textarea.getValue();
39
+ var selected_sql = textarea.getSelection();
40
+ var cursor_pos = textarea.getCursor().line;
41
+ var database = me.module.getDatabase();
42
+
43
+ var reportParams = null;
44
+ if (me.isReportQuery) {
45
+ reportParams = me.down('reportparamspanel').getReportParams();
46
+ }
47
+
48
+ messageBox = Ext.Msg.wait('Status', 'Executing..');
49
+
50
+ Ext.Ajax.request({
51
+ method: 'POST',
52
+ url: '/rails_db_admin/erp_app/desktop/queries/execute_query',
53
+ timeout: 120000,
54
+ params: {
55
+ database: database,
56
+ cursor_pos: cursor_pos
57
+ },
58
+ jsonData: {
59
+ sql: sql,
60
+ selected_sql: selected_sql,
61
+ report_params: reportParams
62
+ },
63
+ success: function(responseObject) {
64
+ messageBox.hide();
65
+ var response = Ext.decode(responseObject.responseText);
66
+
67
+ if (response.success) {
68
+ var columns = response.columns;
69
+ var fields = response.fields;
70
+ var data = response.data;
71
+
72
+ if (!Ext.isEmpty(me.down('railsdbadmin_readonlytabledatagrid'))) {
73
+ var jsonStore = new Ext.data.JsonStore({
74
+ fields: fields,
75
+ data: data
76
+ });
77
+
78
+ me.down('railsdbadmin_readonlytabledatagrid').reconfigure(jsonStore, columns);
79
+ } else {
80
+ var readOnlyDataGrid = Ext.create('Compass.ErpApp.Desktop.Applications.RailsDbAdmin.ReadOnlyTableDataGrid', {
81
+ layout: 'fit',
82
+ columns: columns,
83
+ fields: fields,
84
+ data: data
85
+ });
86
+
87
+ var cardPanel = me.down('#resultCardPanel');
88
+ cardPanel.removeAll(true);
89
+ cardPanel.add(readOnlyDataGrid);
90
+ cardPanel.getLayout().setActiveItem(readOnlyDataGrid);
91
+ }
92
+ } else {
93
+ Ext.Msg.error("Error", response.message);
94
+ }
95
+
96
+ },
97
+ failure: function() {
98
+ messageBox.hide();
99
+ Ext.Msg.error('Status', 'Error loading grid');
100
+ }
101
+ });
102
+ }
103
+ }
104
+ }, {
105
+ text: 'Save Query',
106
+ iconCls: 'icon-save',
107
+ itemId: 'saveQueryBtn',
108
+ hidden: this.isNewQuery,
109
+ handler: function(btn) {
110
+ var textarea = me.query('.codemirror')[0];
111
+ var sql = textarea.getValue();
112
+ var waitMsg;
113
+
114
+ if (me.report && me.report.get('reportId')) {
115
+ waitMsg = Ext.Msg.wait("Saving Report...", "Status");
116
+ Ext.Ajax.request({
117
+ url: '/rails_db_admin/erp_app/desktop/reports/save_query',
118
+ params: {
119
+ id: me.report.get('reportId'),
120
+ query: sql
121
+ },
122
+ success: function(responseObject) {
123
+ waitMsg.close();
124
+ var obj = Ext.decode(responseObject.responseText);
125
+ if (!obj.success) {
126
+ Ext.Msg.alert('Status', 'Error saving report');
127
+ }
128
+ },
129
+ failure: function() {
130
+ waitMsg.close();
131
+ Ext.Msg.alert('Status', 'Error saving report');
132
+ }
133
+ });
134
+ } else {
135
+ waitMsg = Ext.Msg.wait("Saving Query...", "Status");
136
+ Ext.Ajax.request({
137
+ url: '/rails_db_admin/erp_app/desktop/queries/save_query',
138
+ params: {
139
+ query: sql,
140
+ query_name: me.initialConfig.title
141
+ },
142
+ success: function(responseObject) {
143
+ waitMsg.close();
144
+ var obj = Ext.decode(responseObject.responseText);
145
+ if (!obj.success) {
146
+ Ext.Msg.alert('Status', 'Error saving report');
147
+ }
148
+ },
149
+ failure: function() {
150
+ waitMsg.close();
151
+ Ext.Msg.alert('Status', 'Error saving report');
152
+ }
153
+ });
154
+ }
155
+ }
156
+ }];
157
+
158
+ if (this.initialConfig['isReportQuery']) {
159
+ tbarItems.push({
160
+ text: 'Preview Report',
161
+ iconCls: 'icon-document',
162
+ handler: function() {
163
+ if (me.paramPanelIsValid()) {
164
+ var reportParamsPanel = me.down('reportparamspanel'),
165
+ reportParamsWithValues = encodeURIComponent(JSON.stringify(reportParamsPanel.getReportParams())),
166
+
167
+ reportTitle = "Preview" + " (" + me.report.get('reportName') + ")";
168
+ me.openIframeInTab(reportTitle, '/reports/display/' + me.report.get('internalIdentifier') + '?report_params=' + reportParamsWithValues);
169
+ }
170
+ }
171
+ });
172
+
173
+ tbarItems.push({
174
+ text: 'Download CSV',
175
+ iconCls: 'icon-website-export',
176
+ handler: function() {
177
+ if (me.paramPanelIsValid()) {
178
+ var reportParamsPanel = me.down('reportparamspanel'),
179
+ reportParamsWithValues = encodeURIComponent(JSON.stringify(reportParamsPanel.getReportParams())),
180
+ url = '/reports/display/' + me.report.get('internalIdentifier') + '.csv?report_params=' + reportParamsWithValues;
181
+ window.open(url);
182
+ }
183
+ }
184
+ });
185
+
186
+ tbarItems.push({
187
+ text: 'Download PDF',
188
+ iconCls: 'icon-website-export',
189
+ handler: function() {
190
+ if (me.paramPanelIsValid()) {
191
+ var reportParamsPanel = me.down('reportparamspanel'),
192
+ reportParamsWithValues = encodeURIComponent(JSON.stringify(reportParamsPanel.getReportParams())),
193
+ url = '/reports/display/' + me.report.get('internalIdentifier') + '.pdf?report_params=' + reportParamsWithValues;
194
+ window.open(url, '_blank');
195
+ }
196
+ }
197
+ });
198
+ }
199
+
200
+ if (!this.initialConfig['hideSave'] && this.isNewQuery) {
201
+ tbarItems.push({
202
+ text: 'Save',
203
+ iconCls: 'icon-save',
204
+ itemId: 'saveBtn',
205
+ handler: function() {
206
+ var textarea = me.down('.codemirror');
207
+
208
+ Ext.widget('window', {
209
+ layout: 'fit',
210
+ width: 375,
211
+ title: 'Save Query',
212
+ height: 125,
213
+ buttonAlign: 'center',
214
+ closeAction: 'hide',
215
+ plain: true,
216
+ items: {
217
+ xtype: 'form',
218
+ frame: false,
219
+ bodyStyle: 'padding:5px 5px 0',
220
+ width: 500,
221
+ items: [{
222
+ xtype: 'combo',
223
+ fieldLabel: 'Query Name',
224
+ name: 'query_name',
225
+ allowBlank: false,
226
+ store: savedQueriesJsonStore,
227
+ valueField: 'value',
228
+ displayField: 'display',
229
+ triggerAction: 'all',
230
+ forceSelection: false,
231
+ mode: 'remote'
232
+ }, {
233
+ xtype: 'hidden',
234
+ value: textarea.getValue(),
235
+ name: 'query'
236
+ }, {
237
+ xtype: 'hidden',
238
+ value: me.module.getDatabase(),
239
+ name: 'database'
240
+ }]
241
+ },
242
+ buttons: [{
243
+ text: 'Save',
244
+ handler: function(btn) {
245
+ var fp = this.up('window').down('.form');
246
+ if (fp.getForm().isValid()) {
247
+ var queryName = fp.getForm().findField('query_name').getValue();
248
+ fp.getForm().submit({
249
+ url: '/rails_db_admin/erp_app/desktop/queries/save_query',
250
+ waitMsg: 'Saving Query...',
251
+ success: function(fp, o) {
252
+ Ext.Msg.alert('Success', 'Saved Query');
253
+ var database = me.module.getDatabase();
254
+ me.module.queriesTreePanel().store.setProxy({
255
+ type: 'ajax',
256
+ url: '/rails_db_admin/erp_app/desktop/queries/saved_queries_tree',
257
+ extraParams: {
258
+ database: database
259
+ }
260
+ });
261
+ me.isNewQuery = false;
262
+ me.down('#saveBtn').hide();
263
+ me.down('#saveQueryBtn').show();
264
+ me.setTitle(queryName);
265
+ me.module.queriesTreePanel().store.load();
266
+ btn.up('window').hide();
267
+ }
268
+ });
269
+ }
270
+ }
271
+ }, {
272
+ text: 'Cancel',
273
+ handler: function(btn) {
274
+ btn.up('window').hide();
275
+ }
276
+ }]
277
+
278
+ }).show();
279
+ }
280
+ });
281
+ }
282
+
283
+ var codeMirrorPanel = {
284
+ region: 'center',
285
+ xtype: 'codemirror',
286
+ mode: 'sql',
287
+ split: true,
288
+ tbarItems: tbarItems,
289
+ sourceCode: this.initialConfig['sqlQuery'],
290
+ disableSave: true
291
+ };
292
+
293
+ me.items = [];
294
+ // if this a report query show the report params
295
+ if (me.isReportQuery) {
296
+ me.items.push({
297
+ xtype: 'reportparamspanel',
298
+ region: 'north',
299
+ params: me.report.get('reportMetaData').params
300
+ });
301
+ }
302
+ me.items.push(codeMirrorPanel);
303
+
304
+
305
+ if (!Ext.isEmpty(me.initialConfig['southRegion'])) {
306
+ me.items.push(me.initialConfig['southRegion']);
307
+ } else {
308
+ me.items.push({
309
+ layout: 'card',
310
+ region: 'south',
311
+ margins: '0 0 0 0',
312
+ autoScroll: true,
313
+ split: true,
314
+ collapsible: true,
315
+ collapseDirection: 'bottom',
316
+ height: '50%',
317
+ itemId: 'resultCardPanel',
318
+ items: []
319
+ });
320
+ }
321
+
322
+ this.callParent(arguments);
323
+ },
324
+
325
+ constructor: function(config) {
326
+ config = Ext.applyIf({
327
+ layout: 'border',
328
+ border: false,
329
+ closable: true
330
+ }, config);
331
+ if (config.title == null) {
332
+ config = Ext.applyIf({
333
+ title: 'New Query'
334
+ }, config);
335
+ }
336
+ this.callParent([config]);
337
+ },
338
+
339
+ openIframeInTab: function(title, url) {
340
+ var centerRegion = Ext.getCmp('rails_db_admin').down('#centerRegion');
341
+ var itemId = Compass.ErpApp.Utility.Encryption.MD5(url);
342
+ var item = centerRegion.getComponent(itemId);
343
+
344
+ if (Compass.ErpApp.Utility.isBlank(item)) {
345
+ item = Ext.create('Ext.panel.Panel', {
346
+ iframeId: 'tutorials_iframe',
347
+ itemId: itemId,
348
+ closable: true,
349
+ bodyPadding: '5px',
350
+ layout: 'fit',
351
+ title: title,
352
+ html: '<iframe id="reports_iframe" height="100%" width="100%" frameBorder="0" src="' + url + '"></iframe>',
353
+ dockedItems: [{
354
+ xtype: 'toolbar',
355
+ items: [{
356
+ xtype: 'button',
357
+ iconCls: 'icon-refresh',
358
+ text: 'Refresh',
359
+ handler: function(btn) {
360
+ btn.up('panel').el.query('iframe').first().contentWindow.location.reload();
361
+ }
362
+ }]
363
+ }]
364
+ });
365
+ centerRegion.add(item);
366
+ } else {
367
+ Ext.Msg.wait('Updating preview..', 'Status');
368
+ window.setTimeout(function() {
369
+ item.update('<iframe id="reports_iframe" height="100%" width="100%" frameBorder="0" src="' + url + '"></iframe>');
370
+ Ext.Msg.hide();
371
+ }, 300);
372
+ }
373
+ centerRegion.setActiveTab(item);
374
+ },
375
+
376
+ paramPanelIsValid: function() {
377
+ if (this.down('reportparamspanel')) {
378
+ return this.down('reportparamspanel').isValid();
379
+ } else {
380
+ return true;
381
+ }
382
+ }
383
+ });
@@ -0,0 +1,426 @@
1
+ Ext.define("Compass.ErpApp.Desktop.Applications.RailsDbAdmin.Reports.ParamWindow", {
2
+ extend: 'Ext.window.Window',
3
+ alias: 'widget.railsdbadminreportsparamwindow',
4
+ title: 'Add Param',
5
+ modal: true,
6
+ height: 500,
7
+ width: 400,
8
+ buttonAlign: 'center',
9
+
10
+ isAdd: false,
11
+ paramsManager: null,
12
+ param: null,
13
+
14
+ buttons: [{
15
+ text: 'Add',
16
+ itemId: 'okBtn',
17
+ handler: function(btn) {
18
+ var me = btn.up('window');
19
+
20
+ var grid = me.paramsManager.down('grid');
21
+ var form = me.down('form');
22
+
23
+ if (form.isValid()) {
24
+ var values = form.getValues();
25
+
26
+ var options = {};
27
+ for (var key in values) {
28
+ if (key.match(/options_.+/)) {
29
+ options[key.split('_').last()] = values[key];
30
+ }
31
+ }
32
+
33
+ if (me.isAdd) {
34
+ grid.getStore().add({
35
+ display_name: values.display_name,
36
+ name: values.name,
37
+ type: values.type,
38
+ required: (values.required == 'on'),
39
+ options: options
40
+ });
41
+ } else {
42
+ me.param.set('display_name', values.display_name);
43
+ me.param.set('name', values.name);
44
+ me.param.set('type', values.type);
45
+ me.param.set('required', (values.required == 'on'));
46
+ me.param.set('default_value', values.default_value);
47
+ me.param.set('options', options);
48
+ me.param.commit(false);
49
+ }
50
+
51
+ me.paramsManager.save();
52
+
53
+ me.hide();
54
+ }
55
+ }
56
+ }, {
57
+ text: 'Cancel',
58
+ handler: function(btn) {
59
+ var window = btn.up('window');
60
+
61
+ window.hide();
62
+ }
63
+ }],
64
+
65
+ initComponent: function() {
66
+ var me = this;
67
+
68
+ var fieldTypeStore = Ext.create('Ext.data.Store', {
69
+ fields: ['name', 'type'],
70
+ data: [{
71
+ name: 'Text',
72
+ type: 'text'
73
+ }, {
74
+ name: 'Date',
75
+ type: 'date'
76
+ }, {
77
+ name: 'Time',
78
+ type: 'time'
79
+ }, {
80
+ name: 'Select',
81
+ type: 'select'
82
+ }, {
83
+ name: 'Data Record',
84
+ type: 'data_record'
85
+ }, {
86
+ name: 'Service',
87
+ type: 'service'
88
+ }]
89
+ });
90
+
91
+ me.items = [{
92
+ xtype: 'form',
93
+ bodyPadding: 10,
94
+ layout: 'form',
95
+ items: [{
96
+ xtype: 'textfield',
97
+ fieldLabel: 'Display Name',
98
+ itemId: 'paramDisplayName',
99
+ name: 'display_name',
100
+ allowBlank: false
101
+ }, {
102
+ xtype: 'textfield',
103
+ fieldLabel: 'Name',
104
+ itemId: 'paramName',
105
+ regex: /^(?!.*\s).*$/,
106
+ regexText: 'Spaces not allowed',
107
+ name: 'name',
108
+ allowBlank: false
109
+ }, {
110
+ xtype: 'checkbox',
111
+ fieldLabel: 'Required',
112
+ name: 'required'
113
+ }, {
114
+ xtype: 'combobox',
115
+ fieldLabel: 'Type',
116
+ itemId: 'paramType',
117
+ name: 'type',
118
+ allowBlank: false,
119
+ store: fieldTypeStore,
120
+ queryMode: 'local',
121
+ displayField: 'name',
122
+ valueField: 'type',
123
+ value: 'text',
124
+ listeners: {
125
+ select: function(combo, records, eOpts) {
126
+ me.selectType(records[0].get('type'));
127
+ }
128
+ }
129
+ }, {
130
+ xtype: 'container',
131
+ itemId: 'optionsContainer',
132
+ layout: 'form'
133
+ }]
134
+ }];
135
+
136
+ this.callParent(arguments);
137
+
138
+ if (!me.isAdd) {
139
+ me.down('form').getForm().setValues(me.param.data);
140
+ me.down('#okBtn').setText('Save');
141
+ me.setTitle('Edit Param');
142
+ me.selectType(me.param.get('type'));
143
+ }
144
+
145
+ me.on('show', function() {
146
+ me.down('#paramDisplayName').focus();
147
+ });
148
+ },
149
+
150
+ selectType: function(type) {
151
+ var me = this;
152
+ var form = me.down('form');
153
+ var defaultsContainer = form.down('#defaultsContainer');
154
+ var optionsContainer = form.down('#optionsContainer');
155
+
156
+ optionsContainer.removeAll();
157
+
158
+ switch (type) {
159
+ case 'text':
160
+ optionsContainer.show();
161
+ break;
162
+ case 'date':
163
+ optionsContainer.add(me.buildOptionsDateField(optionsContainer));
164
+ optionsContainer.show();
165
+ break;
166
+ case 'time':
167
+ optionsContainer.show();
168
+ break;
169
+ case 'select':
170
+ optionsContainer.add(me.buildOptionsSelectField(optionsContainer));
171
+ optionsContainer.show();
172
+ break;
173
+ case 'data_record':
174
+ optionsContainer.add(me.buildOptionsDataRecordField(optionsContainer));
175
+ optionsContainer.show();
176
+ break;
177
+ case 'service':
178
+ optionsContainer.add(me.buildOptionsServiceUrlField(optionsContainer));
179
+ optionsContainer.show();
180
+ break;
181
+ }
182
+ },
183
+
184
+ /**
185
+ * Build options for Date field
186
+ * @param container (Object) Container component
187
+ */
188
+ buildOptionsDateField: function(container) {
189
+ var options = {},
190
+ me = this;
191
+
192
+ if (me.param) {
193
+ options = me.param.get('options');
194
+ }
195
+
196
+ return [{
197
+ xtype: 'checkbox',
198
+ fieldLabel: 'Only allow week selection',
199
+ name: 'options_onlyWeeks',
200
+ itemId: 'optionOnlyWeeks',
201
+ value: options.onlyWeeks,
202
+ listeners: {
203
+ change: function(field, newValue) {
204
+ if (newValue) {
205
+ field.up('form').down('#optionOnlyMonths').setValue(false);
206
+ }
207
+ }
208
+ }
209
+ }, {
210
+ xtype: 'checkbox',
211
+ fieldLabel: 'Only allow month selection',
212
+ name: 'options_onlyMonths',
213
+ itemId: 'optionOnlyMonths',
214
+ value: options.onlyMonths,
215
+ listeners: {
216
+ change: function(field, newValue) {
217
+ if (newValue) {
218
+ field.up('form').down('#optionOnlyWeeks').setValue(false);
219
+ }
220
+ }
221
+ }
222
+ }];
223
+ },
224
+
225
+ /**
226
+ * Builds applicationmanagementmultioptions (grid panel)
227
+ * @param container (Object) Container component
228
+ */
229
+ buildOptionsSelectField: function(container) {
230
+ var options = {
231
+ values: []
232
+ },
233
+ me = this;
234
+
235
+ if (me.param) {
236
+ options = me.param.get('options');
237
+ }
238
+
239
+ return [{
240
+ xtype: 'checkbox',
241
+ fieldLabel: 'Multi-Select',
242
+ name: 'options_multiSelect',
243
+ value: options.multiSelect
244
+ }, {
245
+ xtype: 'container',
246
+ layout: 'form',
247
+ items: [{
248
+ xtype: 'applicationmanagementmultioptions',
249
+ header: false,
250
+ name: 'options_values',
251
+ field: {
252
+ xtype: 'combo',
253
+ internalIdentifier: 'select',
254
+ store: Ext.create('Ext.data.Store', {
255
+ fields: ['display'],
256
+ data: Ext.Array.map(eval(options.values || '[]'), function(item) {
257
+ return {
258
+ display: item
259
+ };
260
+ })
261
+ }),
262
+ queryMode: 'local'
263
+ }
264
+ }]
265
+ }];
266
+ },
267
+
268
+ /**
269
+ * Builds two select fields Select Application and Select Module
270
+ * @param container (Object) Container component
271
+ */
272
+ buildOptionsDataRecordField: function(container) {
273
+ var options = {},
274
+ me = this;
275
+
276
+ if (me.param) {
277
+ options = me.param.get('options');
278
+ }
279
+
280
+ return [{
281
+ xtype: 'checkbox',
282
+ fieldLabel: 'Multi-Select',
283
+ name: 'options_multiSelect',
284
+ value: options.multiSelect
285
+ }, {
286
+ xtype: 'combo',
287
+ name: 'options_appType',
288
+ itemId: 'applicationSelect',
289
+ fieldLabel: 'App',
290
+ emptyText: 'Select Application',
291
+ allowBlank: false,
292
+ store: {
293
+ autoLoad: true,
294
+ proxy: {
295
+ type: 'ajax',
296
+ method: 'GET',
297
+ url: '/api/v1/applications',
298
+ reader: {
299
+ type: 'json',
300
+ root: 'applications'
301
+ },
302
+ extraParams: {
303
+ types: 'app'
304
+ },
305
+ },
306
+ fields: [
307
+ 'description',
308
+ 'id'
309
+ ],
310
+ listeners: {
311
+ load: function() {
312
+ if (options.appType) {
313
+ var appSelect = container.down('#applicationSelect');
314
+ appSelect.setValue(options.appType);
315
+ }
316
+ }
317
+ }
318
+ },
319
+ forceSelection: true,
320
+ typeAhead: true,
321
+ queryMode: 'remote',
322
+ displayField: 'description',
323
+ valueField: 'id',
324
+ listeners: {
325
+ select: function(combo, records, eOpts) {
326
+ container.down('#businessModule').enable();
327
+ container.down('#businessModule').store.load({
328
+ params: {
329
+ application_id: records[0].get('id')
330
+ }
331
+ });
332
+ },
333
+ change: function(combo, newValue, oldValue, eOpts) {
334
+ container.down('#businessModule').enable();
335
+ container.down('#businessModule').store.load({
336
+ params: {
337
+ application_id: newValue
338
+ }
339
+ });
340
+ }
341
+ }
342
+ }, {
343
+ xtype: 'combo',
344
+ name: 'options_businessModule',
345
+ itemId: 'businessModule',
346
+ disabled: true,
347
+ forceSelection: true,
348
+ emptyText: 'Select Module',
349
+ store: {
350
+ autoLoad: false,
351
+ proxy: {
352
+ url: '/erp_app/desktop/application_management/business_modules/existing_application_modules',
353
+ type: 'ajax',
354
+ reader: {
355
+ type: 'json',
356
+ root: 'business_modules'
357
+ }
358
+ },
359
+ fields: [{
360
+ name: 'description'
361
+ }, {
362
+ name: 'internalIdentifier',
363
+ mapping: 'internal_identifier'
364
+ }],
365
+ listeners: {
366
+ load: function() {
367
+ if (options.businessModule) {
368
+ var moduleType = container.down('#businessModule');
369
+ moduleType.setValue(options.businessModule);
370
+ }
371
+ }
372
+ }
373
+ },
374
+ displayField: 'description',
375
+ valueField: 'internalIdentifier',
376
+ fieldLabel: 'Module',
377
+ allowBlank: false,
378
+ triggerAction: 'all',
379
+ queryMode: 'local'
380
+ }];
381
+ },
382
+
383
+ /**
384
+ * Build options for Service Url field
385
+ * @param container (Object) Container component
386
+ */
387
+ buildOptionsServiceUrlField: function(container) {
388
+ var options = {},
389
+ me = this;
390
+
391
+ if (me.param) {
392
+ options = me.param.get('options');
393
+ }
394
+
395
+ return [{
396
+ xtype: 'checkbox',
397
+ fieldLabel: 'Multi-Select',
398
+ name: 'options_multiSelect',
399
+ value: options.multiSelect
400
+ }, {
401
+ xtype: 'textfield',
402
+ fieldLabel: 'URL',
403
+ allowBlank: false,
404
+ name: 'options_url',
405
+ value: options.url
406
+ }, {
407
+ xtype: 'textfield',
408
+ fieldLabel: 'Root',
409
+ allowBlank: false,
410
+ name: 'options_root',
411
+ value: options.root
412
+ }, {
413
+ xtype: 'textfield',
414
+ fieldLabel: 'Display Field',
415
+ allowBlank: false,
416
+ name: 'options_displayField',
417
+ value: options.displayField
418
+ }, {
419
+ xtype: 'textfield',
420
+ fieldLabel: 'Value Field',
421
+ allowBlank: false,
422
+ name: 'options_valueField',
423
+ value: options.valueField
424
+ }];
425
+ }
426
+ });