netzke-basepack 0.5.5.1 → 0.5.6

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.
Files changed (41) hide show
  1. data/CHANGELOG.rdoc +16 -1
  2. data/README.rdoc +31 -56
  3. data/Rakefile +2 -2
  4. data/TODO.rdoc +3 -0
  5. data/javascripts/basepack.js +70 -30
  6. data/lib/app/models/netzke_auto_column.rb +1 -53
  7. data/lib/app/models/netzke_auto_field.rb +4 -0
  8. data/lib/app/models/netzke_auto_table.rb +61 -0
  9. data/lib/netzke-basepack.rb +13 -7
  10. data/lib/netzke/active_record/basepack.rb +28 -0
  11. data/lib/netzke/active_record/data_accessor.rb +2 -0
  12. data/lib/netzke/basic_app.rb +3 -4
  13. data/lib/netzke/{basic_app_extras → basic_app}/statusbar_ext.js +0 -0
  14. data/lib/netzke/data_accessor.rb +2 -0
  15. data/lib/netzke/ext.rb +1 -1
  16. data/lib/netzke/fields_configurator.rb +22 -6
  17. data/lib/netzke/form_panel.rb +20 -11
  18. data/lib/netzke/form_panel/form_panel_api.rb +78 -0
  19. data/lib/netzke/form_panel/form_panel_js.rb +143 -0
  20. data/lib/netzke/{form_panel_extras → form_panel}/javascripts/netzkefileupload.js +0 -0
  21. data/lib/netzke/{form_panel_extras → form_panel}/javascripts/xcheckbox.js +0 -0
  22. data/lib/netzke/grid_panel.rb +33 -24
  23. data/lib/netzke/grid_panel/grid_panel_api.rb +358 -0
  24. data/lib/netzke/grid_panel/grid_panel_js.rb +747 -0
  25. data/lib/netzke/{grid_panel_extras → grid_panel}/javascripts/filters.js +0 -0
  26. data/lib/netzke/{grid_panel_extras → grid_panel}/javascripts/rows-dd.js +0 -0
  27. data/lib/netzke/grid_panel/record_form_window.rb +44 -0
  28. data/lib/netzke/panel.rb +1 -3
  29. data/lib/netzke/property_editor.rb +2 -0
  30. data/lib/netzke/{property_editor_extras → property_editor}/helper_model.rb +2 -2
  31. data/lib/netzke/search_panel.rb +3 -3
  32. data/lib/netzke/window.rb +9 -3
  33. data/test/unit/grid_panel_test.rb +0 -2
  34. data/test/unit/helper_model_test.rb +2 -2
  35. metadata +16 -15
  36. data/lib/netzke/field_model.rb +0 -131
  37. data/lib/netzke/form_panel_api.rb +0 -78
  38. data/lib/netzke/form_panel_js.rb +0 -141
  39. data/lib/netzke/grid_panel_api.rb +0 -356
  40. data/lib/netzke/grid_panel_extras/record_form_window.rb +0 -46
  41. data/lib/netzke/grid_panel_js.rb +0 -725
@@ -1,46 +0,0 @@
1
- module Netzke::GridPanelExtras
2
- class RecordFormWindow < Window
3
- def actions
4
- {:ok => {:text => "OK"}, :cancel => {:text => "Cancel"}}
5
- end
6
-
7
- def initial_config
8
- super.deep_merge({
9
- :ext_config => {
10
- :modal => true,
11
- :width => "60%",
12
- :height => "90%",
13
- :fbar => [:ok, :cancel]
14
- }
15
- })
16
- end
17
-
18
- def self.js_extend_properties
19
- {
20
- :button_align => "right",
21
-
22
- :init_component => <<-END_OF_JAVASCRIPT.l,
23
- function(){
24
- #{js_full_class_name}.superclass.initComponent.call(this);
25
- this.getWidget().on("submitsuccess", function(){this.closeRes = "ok"; this.close();}, this);
26
- }
27
- END_OF_JAVASCRIPT
28
-
29
- :on_ok => <<-END_OF_JAVASCRIPT.l,
30
- function(){
31
- this.getWidget().onApply();
32
- // this.closeRes = "ok",
33
- // this.close();
34
- }
35
- END_OF_JAVASCRIPT
36
-
37
- :on_cancel => <<-END_OF_JAVASCRIPT.l,
38
- function(){
39
- this.close();
40
- }
41
- END_OF_JAVASCRIPT
42
-
43
- }
44
- end
45
- end
46
- end
@@ -1,725 +0,0 @@
1
- module Netzke
2
- module GridPanelJs
3
- def self.included(base)
4
- base.extend ClassMethods
5
- end
6
-
7
- def js_config
8
- res = super
9
- res.merge!(:clmns => columns)
10
- res.merge!(:data_class_name => config[:data_class_name])
11
- res.merge!(:inline_data => get_data) if ext_config[:load_inline_data]
12
- res
13
- end
14
-
15
- module ClassMethods
16
-
17
- def js_base_class
18
- 'Ext.grid.EditorGridPanel'
19
- end
20
-
21
- # Ext.Component#initComponent, built up from pices (dependent on class configuration)
22
- def js_init_component
23
-
24
- # Optional "edit in form"-related events
25
- edit_in_form_events = <<-END_OF_JAVASCRIPT if config[:edit_in_form_available]
26
- if (this.enableEditInForm) {
27
- this.getSelectionModel().on('selectionchange', function(selModel){
28
- // Disable "edit in form" button if new record is present in selection
29
- var disabled = !selModel.each(function(r){
30
- if (r.isNew) { return false; }
31
- });
32
- this.actions.editInForm.setDisabled(disabled);
33
- }, this);
34
- }
35
- END_OF_JAVASCRIPT
36
-
37
- # Result
38
- <<-END_OF_JAVASCRIPT
39
- function(){
40
- if (!this.clmns) {this.feedback('No columns defined for grid '+this.id);}
41
-
42
- /* Process columns - all in sake of creating the column model */
43
- // Normalize columns passed in the config
44
- var normClmns = [];
45
- Ext.each(this.clmns, function(c){
46
- if (!c.excluded) {
47
- // normalize columns
48
- if (typeof c == 'string') {
49
- normClmns.push({name:c});
50
- } else {
51
- normClmns.push(c);
52
- }
53
- }
54
- });
55
-
56
- delete this.clmns; // we don't need them anymore
57
-
58
- var cmConfig = []; // column model config - we'll use it later to create the ColumnModel
59
- this.plugins = []; // checkbox colums is a special case, being a plugin
60
-
61
- var filters = [];
62
-
63
- // Run through columns
64
- Ext.each(normClmns, function(c){
65
- // Apply default column config
66
- Ext.applyIf(c, this.defaultColumnConfig);
67
-
68
- // setting dataIndex separately
69
- c.dataIndex = c.name;
70
-
71
- // Automatically calculated default values
72
- if (!c.header) {c.header = c.name.humanize()}
73
-
74
- // normalize editor
75
- if (c.editor) {
76
- c.editor = Netzke.isObject(c.editor) ? c.editor : {xtype:c.editor};
77
- } else {
78
- c.editor = {xtype: 'textfield'}
79
- }
80
-
81
- // collect filters
82
- // Not compatible with Ext 3.0
83
- //if (c.withFilters){
84
- // filters.push({type:Ext.netzke.filterMap[c.editor.xtype], dataIndex:c.name});
85
- //}
86
-
87
- if (c.editor && c.editor.xtype == 'checkbox') {
88
- // Special case of checkbox column
89
- var plugin = new Ext.ux.grid.CheckColumn(c);
90
- this.plugins.push(plugin);
91
- cmConfig.push(plugin);
92
- } else {
93
- // a "normal" column, not a plugin
94
- if (!c.readOnly && !this.prohibitUpdate) {
95
- // c.editor contains complete config of the editor
96
- var xtype = c.editor.xtype;
97
- c.editor = Ext.ComponentMgr.create(Ext.apply({
98
- parentId: this.id,
99
- name: c.name,
100
- selectOnFocus:true
101
- }, c.editor));
102
- } else {
103
- c.editor = null;
104
- }
105
-
106
- // set the renderer
107
- var renderer = Ext.netzke.normalizedRenderer(c.renderer);
108
- if (renderer != null) c.renderer = renderer;
109
-
110
- // add to the list
111
- cmConfig.push(c);
112
- }
113
-
114
- }, this);
115
-
116
- // Finally, create the ColumnModel based on processed columns
117
- this.cm = new Ext.grid.ColumnModel(cmConfig);
118
-
119
- // Hidden change event
120
- if (this.persistentConfig) {this.cm.on('hiddenchange', this.onColumnHiddenChange, this);}
121
-
122
- /* ... and done with columns */
123
-
124
- // Filters
125
- // Not compatible with Ext 3.0
126
- // if (this.enableColumnFilters) {
127
- // this.plugins.push(new Ext.grid.GridFilters({filters:filters}));
128
- // }
129
-
130
- // Create Ext.data.Record constructor specific for our particular column configuration
131
- this.recordConfig = [];
132
- Ext.each(normClmns, function(column){this.recordConfig.push({name:column.name});}, this);
133
- this.Row = Ext.data.Record.create(this.recordConfig);
134
-
135
- // Drag'n'Drop
136
- if (this.enableRowsReordering){
137
- this.ddPlugin = new Ext.ux.dd.GridDragDropRowOrder({
138
- scrollable: true // enable scrolling support (default is false)
139
- });
140
- this.plugins.push(this.ddPlugin);
141
- }
142
-
143
- // Explicitely create the connection to get grid's data,
144
- // because we don't want the app-wide Ext.Ajax to be used,
145
- // as we are going to subscribe to its events
146
- var connection = new Ext.data.Connection({
147
- url:this.id+"__get_data",
148
- extraParams : {
149
- authenticity_token : Ext.authenticityToken
150
- },
151
-
152
- // inform Ext.Ajax about our events
153
- listeners: {
154
- beforerequest: function(){
155
- Ext.Ajax.fireEvent('beforerequest', arguments);
156
- },
157
- requestexception: function(){
158
- Ext.Ajax.fireEvent('requestexception', arguments);
159
- },
160
- requestcomplete: function(){
161
- Ext.Ajax.fireEvent('requestcomplete', arguments);
162
- }
163
- }
164
- });
165
-
166
- // besides getting data into the store, we may also get commands to execute
167
- connection.on('requestcomplete', function(conn, r){
168
- var response = Ext.decode(r.responseText);
169
-
170
- // delete data-related properties
171
- Ext.each(['data', 'total', 'success'], function(property){delete response[property];});
172
- this.bulkExecute(response);
173
- }, this);
174
-
175
- // HttpProxy that uses our custom connection
176
- var httpProxy = new Ext.data.HttpProxy(connection);
177
-
178
- // Data store
179
- this.store = new Ext.data.Store({
180
- proxy: this.proxy = httpProxy,
181
- reader: new Ext.data.ArrayReader({root: "data", totalProperty: "total", successProperty: "success", id:0}, this.Row),
182
- remoteSort: true,
183
- listeners:{'loadexception':{
184
- fn:this.loadExceptionHandler,
185
- scope:this
186
- }}
187
- });
188
-
189
- // Normalize bottom bar
190
- this.bbar = (this.enablePagination) ? new Ext.PagingToolbar({
191
- pageSize : this.rowsPerPage,
192
- items : this.bbar ? ["-"].concat(this.bbar) : [],
193
- store : this.store,
194
- emptyMsg: 'Empty'
195
- }) : this.bbar;
196
-
197
- // Selection model
198
- this.sm = new Ext.grid.RowSelectionModel();
199
-
200
- // Now let Ext.grid.EditorGridPanel do the rest
201
- // Original initComponent
202
- #{js_full_class_name}.superclass.initComponent.call(this);
203
-
204
- // Inform the server part about column operations
205
- if (this.persistentConfig) {
206
- this.on('columnresize', this.onColumnResize, this);
207
- this.on('columnmove', this.onColumnMove, this);
208
- }
209
-
210
- // Context menu
211
- if (this.enableContextMenu) {
212
- this.on('rowcontextmenu', this.onRowContextMenu, this);
213
- }
214
-
215
- // Load data AFTER the toolbar is bound to the store, which will provide for correct page number
216
- if (this.loadInlineData) {
217
- this.getStore().loadData(this.inlineData);
218
-
219
- // If rows per page specified, fake store.lastOptions as if the data was loaded
220
- // by PagingToolbar (for correct functionning of refresh tool and extended search)
221
- if (this.rowsPerPage) {
222
- this.getStore().lastOptions = {params:{limit:this.rowsPerPage, start:0}}; // this is how PagingToolbar does it...
223
- }
224
-
225
- // inlineData may also contain commands (TODO: make it DRY)
226
- // delete data-related properties
227
- Ext.each(['data', 'total', 'success'], function(property){delete this.inlineData[property];}, this);
228
- this.bulkExecute(this.inlineData);
229
- }
230
-
231
- // Process selectionchange event
232
- this.getSelectionModel().on('selectionchange', function(selModel){
233
- // enable/disable actions
234
- this.actions.del.setDisabled(!selModel.hasSelection() || this.prohibitDelete);
235
- this.actions.edit.setDisabled(selModel.getCount() != 1 || this.prohibitUpdate);
236
- }, this);
237
-
238
- // Drag n Drop event
239
- if (this.enableRowsReordering){
240
- this.ddPlugin.on('afterrowmove', this.onAfterRowMove, this);
241
- }
242
-
243
- // GridView
244
- this.getView().getRowClass = this.defaultGetRowClass;
245
-
246
- #{edit_in_form_events}
247
- }
248
-
249
- END_OF_JAVASCRIPT
250
-
251
- end
252
-
253
- def js_extend_properties
254
- res = super
255
-
256
- # Generic (non-optional) functionality
257
- res.merge!(
258
- {
259
- :track_mouse_over => true,
260
- :load_mask => true,
261
- :auto_scroll => true,
262
-
263
- :default_column_config => config_columns.inject({}){ |r, c| c.is_a?(Hash) ? r.merge(c[:name] => c[:default]) : r },
264
-
265
- :init_component => js_init_component.l,
266
-
267
- # Handlers for actions
268
- #
269
-
270
- :on_add => <<-END_OF_JAVASCRIPT.l,
271
- function(){
272
- var rowConfig = {};
273
- var r = new this.Row(rowConfig); // TODO: add default values
274
- r.isNew = true; // to distinguish new records
275
- r.set('id', r.id); // otherwise later r.get('id') returns empty string
276
- this.stopEditing();
277
- this.store.add(r);
278
- this.tryStartEditing(this.store.indexOf(r));
279
- }
280
- END_OF_JAVASCRIPT
281
-
282
- :on_edit => <<-END_OF_JAVASCRIPT.l,
283
- function(){
284
- var row = this.getSelectionModel().getSelected();
285
- if (row){
286
- this.tryStartEditing(this.store.indexOf(row));
287
- }
288
- }
289
- END_OF_JAVASCRIPT
290
-
291
- :on_del => <<-END_OF_JAVASCRIPT.l,
292
- function() {
293
- Ext.Msg.confirm('Confirm', 'Are you sure?', function(btn){
294
- if (btn == 'yes') {
295
- var records = [];
296
- this.getSelectionModel().each(function(r){
297
- if (r.isNew) {
298
- // this record is not know to server - simply remove from store
299
- this.store.remove(r);
300
- } else {
301
- records.push(r.get('id'));
302
- }
303
- }, this);
304
-
305
- if (records.length > 0){
306
- // call API
307
- this.deleteData({records: Ext.encode(records)});
308
- }
309
- }
310
- }, this);
311
- }
312
- END_OF_JAVASCRIPT
313
-
314
- :on_apply => <<-END_OF_JAVASCRIPT.l,
315
- function(){
316
- var newRecords = [];
317
- var updatedRecords = [];
318
-
319
- Ext.each(this.store.getModifiedRecords(),
320
- function(r) {
321
- if (r.isNew) {
322
- newRecords.push(Ext.apply(r.getChanges(), {id:r.get('id')}));
323
- } else {
324
- updatedRecords.push(Ext.apply(r.getChanges(), {id:r.get('id')}));
325
- }
326
- },
327
- this);
328
-
329
- if (newRecords.length > 0 || updatedRecords.length > 0) {
330
- var params = {};
331
-
332
- if (newRecords.length > 0) {
333
- params.created_records = Ext.encode(newRecords);
334
- }
335
-
336
- if (updatedRecords.length > 0) {
337
- params.updated_records = Ext.encode(updatedRecords);
338
- }
339
-
340
- if (this.store.baseParams !== {}) {
341
- params.base_params = Ext.encode(this.store.baseParams);
342
- }
343
-
344
- this.postData(params);
345
- }
346
-
347
- }
348
- END_OF_JAVASCRIPT
349
-
350
- # Handlers for tools
351
- #
352
-
353
- :on_refresh => <<-END_OF_JAVASCRIPT.l,
354
- function() {
355
- if (this.fireEvent('refresh', this) !== false) {
356
- this.store.reload();
357
- }
358
- }
359
- END_OF_JAVASCRIPT
360
-
361
- # Event handlers
362
- #
363
-
364
- :on_column_resize => <<-END_OF_JAVASCRIPT.l,
365
- function(index, size){
366
- this.resizeColumn({
367
- index:index,
368
- size:size
369
- });
370
- }
371
- END_OF_JAVASCRIPT
372
-
373
- :on_column_hidden_change => <<-END_OF_JAVASCRIPT.l,
374
- function(cm, index, hidden){
375
- this.hideColumn({
376
- index:index,
377
- hidden:hidden
378
- });
379
- }
380
- END_OF_JAVASCRIPT
381
-
382
- :on_column_move => <<-END_OF_JAVASCRIPT.l,
383
- function(oldIndex, newIndex){
384
- this.moveColumn({
385
- old_index:oldIndex,
386
- new_index:newIndex
387
- });
388
-
389
- var newRecordConfig = [];
390
- Ext.each(this.getColumnModel().config, function(c){newRecordConfig.push({name: c.name})});
391
- delete this.Row; // old record constructor
392
- this.Row = Ext.data.Record.create(newRecordConfig);
393
- this.getStore().reader.recordType = this.Row;
394
- }
395
- END_OF_JAVASCRIPT
396
-
397
- :on_row_context_menu => <<-END_OF_JAVASCRIPT.l,
398
- function(grid, rowIndex, e){
399
- e.stopEvent();
400
- var coords = e.getXY();
401
-
402
- if (!grid.getSelectionModel().isSelected(rowIndex)) {
403
- grid.getSelectionModel().selectRow(rowIndex);
404
- }
405
-
406
- var menu = new Ext.menu.Menu({
407
- items: this.contextMenu
408
- });
409
-
410
- menu.showAt(coords);
411
- }
412
- END_OF_JAVASCRIPT
413
-
414
- :on_after_row_move => <<-END_OF_JAVASCRIPT.l,
415
- function(dt, oldIndex, newIndex, records){
416
- var ids = [];
417
- // collect records ids
418
- Ext.each(records, function(r){ids.push(r.get('id'))});
419
- // call GridPanel's API
420
- this.moveRows({ids:Ext.encode(ids), new_index: newIndex});
421
- }
422
- END_OF_JAVASCRIPT
423
-
424
- # Other methods
425
- #
426
-
427
- :load_exception_handler => <<-END_OF_JAVASCRIPT.l,
428
- function(proxy, options, response, error){
429
- if (response.status == 200 && (responseObject = Ext.decode(response.responseText)) && responseObject.flash){
430
- this.feedback(responseObject.flash);
431
- } else {
432
- if (error){
433
- this.feedback(error.message);
434
- } else {
435
- this.feedback(response.statusText);
436
- }
437
- }
438
- }
439
- END_OF_JAVASCRIPT
440
-
441
- :update => <<-END_OF_JAVASCRIPT.l,
442
- function(){
443
- this.store.reload();
444
- }
445
- END_OF_JAVASCRIPT
446
-
447
- :load_store_data => <<-END_OF_JAVASCRIPT.l,
448
- function(data){
449
- this.store.loadData(data);
450
- Ext.each(['data', 'total', 'success'], function(property){delete data[property];}, this);
451
- this.bulkExecute(data);
452
- }
453
- END_OF_JAVASCRIPT
454
-
455
- # try editing the first editable (i.e. not hidden, not read-only) sell
456
- :try_start_editing => <<-END_OF_JAVASCRIPT.l,
457
- function(row){
458
- var editableIndex = 0;
459
- Ext.each(this.getColumnModel().config, function(c){
460
- if (!c.hidden && c.editor && (c.editor.xtype !== 'checkbox')) {
461
- return false;
462
- }
463
- editableIndex++;
464
- });
465
- if (editableIndex < this.getColumnModel().config.length) {this.startEditing(row, editableIndex);}
466
- }
467
- END_OF_JAVASCRIPT
468
-
469
- # Called by the server side to update newly created records
470
- :update_new_records => <<-END_OF_JAVASCRIPT.l,
471
- function(records){
472
- this.updateRecords(records);
473
- }
474
- END_OF_JAVASCRIPT
475
-
476
- # Called by the server side to update modified records
477
- :update_mod_records => <<-END_OF_JAVASCRIPT.l,
478
- function(records){
479
- this.updateRecords(records, true);
480
- }
481
- END_OF_JAVASCRIPT
482
-
483
- # Updates modified or newly created records
484
- # Example of the records argument:
485
- # {1098 => [1, 'value1', 'value2'], 1099 => [2, 'value1', 'value2']}
486
- :update_records => <<-END_OF_JAVASCRIPT.l,
487
- function(records, mod){
488
- if (!mod) {mod = false;}
489
- var modRecordsInGrid = [].concat(this.store.getModifiedRecords()); // there must be a better way to clone an array...
490
-
491
- // replace arrays of data in the args object with Ext.data.Record objects
492
- for (var k in records){
493
- records[k] = this.store.reader.readRecords([records[k]]).records[0];
494
- }
495
-
496
- // for each new record write the data returned by the server, and commit the record
497
- Ext.each(modRecordsInGrid, function(recordInGrid){
498
- if (mod ^ recordInGrid.isNew) {
499
- // new data that the server sent us to update this record
500
- var newData = records[recordInGrid.get('id')];
501
-
502
- if (newData){
503
- for (var k in newData.data){
504
- recordInGrid.set(k, newData.get(k));
505
- }
506
-
507
- recordInGrid.isNew = false;
508
- recordInGrid.commit();
509
- }
510
-
511
- }
512
- });
513
-
514
- // clear the selections
515
- this.getSelectionModel().clearSelections();
516
-
517
- // check if there are still records with errors
518
- var modRecords = this.store.getModifiedRecords();
519
- if (modRecords.length == 0) {
520
- // if all records are accepted, reload the grid (so that eventual order/filtering is correct)
521
- this.store.reload();
522
-
523
- // ... and set default getRowClass function
524
- this.getView().getRowClass = this.defaultGetRowClass;
525
- } else {
526
- this.getView().getRowClass = function(r){
527
- return r.dirty ? "grid-dirty-record" : ""
528
- }
529
- }
530
-
531
- this.getView().refresh();
532
- }
533
- END_OF_JAVASCRIPT
534
-
535
- :default_get_row_class => <<-END_OF_JAVASCRIPT.l,
536
- function(r){
537
- return r.isNew ? "grid-dirty-record" : ""
538
- }
539
- END_OF_JAVASCRIPT
540
-
541
- :select_first_row => <<-END_OF_JAVASCRIPT.l,
542
- function(){
543
- this.getSelectionModel().suspendEvents();
544
- this.getSelectionModel().selectRow(0);
545
- this.getSelectionModel().resumeEvents();
546
- }
547
- END_OF_JAVASCRIPT
548
-
549
- # :reorder_columns => <<-END_OF_JAVASCRIPT.l,
550
- # function(columns){
551
- # columnsInNewShipment = [];
552
- # Ext.each(columns, function(c){
553
- # columnsInNewShipment.push({name:c});
554
- # });
555
- # newRecordType = Ext.data.Record.create(columnsInNewShipment);
556
- # this.store.reader.recordType = newRecordType; // yes, recordType is a protected property, but that's the only way we can do it, and it seems to work for now
557
- # }
558
- # END_OF_JAVASCRIPT
559
- }
560
- )
561
-
562
- # Optional edit in form functionality
563
- res.merge!(
564
- {
565
- :on_successfull_record_creation => <<-END_OF_JAVASCRIPT.l,
566
- function(){
567
- this.formWindow.hide();
568
- this.getStore().reload();
569
- }
570
- END_OF_JAVASCRIPT
571
-
572
- :on_successfull_edit => <<-END_OF_JAVASCRIPT.l,
573
- function(){
574
- this.editFormWindow.close();
575
- delete this.editFormWindow;
576
- this.getStore().reload();
577
- }
578
- END_OF_JAVASCRIPT
579
-
580
- :on_edit_in_form => <<-END_OF_JAVASCRIPT.l,
581
- function(){
582
- // create the window
583
- delete this.editFormWindow;
584
- this.editFormWindow = new Ext.Window({
585
- title: 'Edit',
586
- layout: 'fit',
587
- modal: true,
588
- width: 400,
589
- height: Ext.lib.Dom.getViewHeight() *0.9,
590
- buttons:[{
591
- text: 'OK',
592
- handler: function(){
593
- this.ownerCt.ownerCt.getWidget().onApply();
594
- }
595
- },{
596
- text:'Cancel',
597
- handler:function(){
598
- this.ownerCt.ownerCt.hide();
599
- }
600
- }]
601
- });
602
-
603
- // show it and load the correct aggregatee in it
604
- this.editFormWindow.show(null, function(){
605
- var selModel = this.getSelectionModel();
606
- if (selModel.getCount() > 1) {
607
-
608
- // multiedit
609
- this.editFormWindow.setTitle('Multi-edit');
610
- this.loadAggregatee({
611
- id: "multiEditForm",
612
- container: this.editFormWindow.id,
613
- callback: function(aggr){
614
- // on apply attach ids of selected rows
615
- aggr.on('apply', function(){
616
- var ids = [];
617
- selModel.each(function(r){
618
- ids.push(r.get('id'));
619
- });
620
- aggr.baseParams = {ids: Ext.encode(ids)}
621
- }, this);
622
- },
623
- scope: this
624
- });
625
- } else {
626
-
627
- // single edit
628
- this.editFormWindow.setTitle('Edit');
629
- var recordId = selModel.getSelected().get('id');
630
- this.loadAggregatee({
631
- id: "editForm",
632
- container: this.editFormWindow.id,
633
- params: {
634
- record_id: recordId
635
- }
636
- });
637
- }
638
- }, this);
639
-
640
- }
641
- END_OF_JAVASCRIPT
642
-
643
- :on_add_in_form => <<-END_OF_JAVASCRIPT.l,
644
- function(){
645
- this.loadAggregatee({id: "addForm", callback: function(form){
646
- form.on('close', function(){
647
- if (form.closeRes === "ok") {
648
- this.store.reload();
649
- }
650
- }, this);
651
- }, scope: this});
652
- }
653
- END_OF_JAVASCRIPT
654
- }
655
- ) if config[:edit_in_form_available]
656
-
657
- # Optional extended search functionality
658
- res.merge!(
659
- {
660
- :on_search => <<-END_OF_JAVASCRIPT.l,
661
- function(){
662
- if (!this.searchWindow){
663
- this.searchWindow = new Ext.Window({
664
- title:'Advanced search',
665
- layout:'fit',
666
- modal: true,
667
- width: 400,
668
- height: Ext.lib.Dom.getViewHeight() *0.9,
669
- closeAction:'hide',
670
- buttons:[{
671
- text: 'OK',
672
- handler: function(){
673
- this.ownerCt.ownerCt.closePositively();
674
- }
675
- },{
676
- text:'Cancel',
677
- handler:function(){
678
- this.ownerCt.ownerCt.closeNegatively();
679
- }
680
- }],
681
- closePositively : function(){
682
- this.conditions = this.getWidget().getForm().getValues();
683
- this.closeRes = 'OK';
684
- this.hide();
685
- },
686
- closeNegatively: function(){
687
- this.closeRes = 'cancel';
688
- this.hide();
689
- }
690
-
691
- });
692
-
693
- this.searchWindow.on('hide', function(){
694
- if (this.searchWindow.closeRes == 'OK'){
695
- this.getStore().baseParams = {extra_conditions: Ext.encode(this.searchWindow.conditions)};
696
- this.getStore().reload();
697
- }
698
- }, this);
699
-
700
- this.searchWindow.on('add', function(container, searchPanel){
701
- searchPanel.on('apply', function(widget){
702
- this.searchWindow.closePositively();
703
- return false; // stop the event
704
- }, this);
705
- }, this);
706
- }
707
-
708
- this.searchWindow.show(null, function(){
709
- this.searchWindow.closeRes = 'cancel';
710
- if (!this.searchWindow.getWidget()){
711
- this.loadAggregatee({id:"searchPanel", container:this.searchWindow.id});
712
- }
713
- }, this);
714
-
715
- }
716
- END_OF_JAVASCRIPT
717
-
718
- }
719
- ) if config[:extended_search_available]
720
-
721
- res
722
- end
723
- end
724
- end
725
- end