netzke-basepack 0.3.1 → 0.3.3

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 (35) hide show
  1. data/CHANGELOG +22 -0
  2. data/Manifest +6 -4
  3. data/README.rdoc +2 -2
  4. data/Rakefile +1 -1
  5. data/generators/netzke_form_panel/templates/create_netzke_form_panel_fields.rb +5 -6
  6. data/generators/netzke_grid_panel/templates/create_netzke_grid_panel_columns.rb +2 -1
  7. data/javascripts/basepack.js +2 -0
  8. data/lib/app/models/netzke_form_panel_field.rb +35 -3
  9. data/lib/app/models/netzke_grid_panel_column.rb +39 -2
  10. data/lib/netzke-basepack.rb +0 -1
  11. data/lib/netzke/accordion_panel.rb +51 -15
  12. data/lib/netzke/ar_ext.rb +14 -6
  13. data/lib/netzke/basic_app.rb +5 -5
  14. data/lib/netzke/border_layout_panel.rb +19 -4
  15. data/lib/netzke/container.rb +2 -6
  16. data/lib/netzke/db_fields.rb +40 -0
  17. data/lib/netzke/fields_configurator.rb +10 -18
  18. data/lib/netzke/form_panel.rb +42 -128
  19. data/lib/netzke/form_panel_extras/interface.rb +49 -0
  20. data/lib/netzke/form_panel_extras/js_builder.rb +131 -0
  21. data/lib/netzke/grid_panel.rb +20 -12
  22. data/lib/netzke/grid_panel_extras/interface.rb +181 -0
  23. data/lib/netzke/grid_panel_extras/js_builder.rb +322 -0
  24. data/lib/netzke/table_editor.rb +110 -0
  25. data/lib/netzke/wrapper.rb +1 -3
  26. data/netzke-basepack.gemspec +8 -8
  27. data/test/app_root/db/migrate/20090102223811_create_netzke_grid_panel_columns.rb +3 -1
  28. data/test/border_layout_panel_test.rb +8 -12
  29. data/test/grid_panel_test.rb +3 -3
  30. data/test/test_helper.rb +8 -0
  31. metadata +15 -11
  32. data/lib/netzke/column.rb +0 -50
  33. data/lib/netzke/grid_panel_interface.rb +0 -167
  34. data/lib/netzke/grid_panel_js_builder.rb +0 -298
  35. data/test/column_test.rb +0 -27
@@ -1,298 +0,0 @@
1
- module Netzke::GridPanelJsBuilder
2
- def self.included(base)
3
- base.extend ClassMethods
4
- end
5
-
6
- def js_config
7
- res = super
8
- # we pass column config at the time of instantiating the JS class
9
- res.merge!(:columns => get_columns || config[:columns]) # first try to get columns from DB, then from config
10
- res.merge!(:data_class_name => config[:data_class_name])
11
- res
12
- end
13
-
14
- module ClassMethods
15
-
16
- def js_base_class
17
- 'Ext.grid.EditorGridPanel'
18
- end
19
-
20
- def js_bbar
21
- <<-JS.l
22
- (config.rowsPerPage) ? new Ext.PagingToolbar({
23
- pageSize:config.rowsPerPage,
24
- items:config.actions,
25
- store:ds,
26
- emptyMsg:'Empty'}) : config.actions
27
- JS
28
- end
29
-
30
- def js_default_config
31
- super.merge({
32
- :store => "ds".l,
33
- :cm => "cm".l,
34
- :sel_model => "new Ext.grid.RowSelectionModel()".l,
35
- :auto_scroll => true,
36
- :click_to_edit => 2,
37
- :track_mouse_over => true,
38
- # :bbar => "config.actions".l,
39
- :bbar => js_bbar,
40
- :plugins => "plugins".l,
41
-
42
- #custom configs
43
- :auto_load_data => true
44
- })
45
- end
46
-
47
- def js_before_constructor
48
- <<-JS
49
- var plugins = [];
50
- if (!config.columns) this.feedback('No columns defined for grid '+config.id);
51
- this.recordConfig = [];
52
- Ext.each(config.columns, function(column){this.recordConfig.push({name:column.name})}, this);
53
- this.Row = Ext.data.Record.create(this.recordConfig);
54
-
55
- var ds = new Ext.data.Store({
56
- proxy: this.proxy = new Ext.data.HttpProxy({url:config.interface.getData}),
57
- reader: new Ext.data.ArrayReader({root: "data", totalProperty: "total", successProperty: "succes", id:0}, this.Row),
58
- remoteSort: true,
59
- listeners:{'loadexception':{
60
- fn:this.loadExceptionHandler,
61
- scope:this
62
- }}
63
- });
64
-
65
- this.cmConfig = [];
66
- Ext.each(config.columns, function(c){
67
- var editor = (c.readOnly || !config.permissions.update) ? null : Ext.netzke.editors[c.editor](c, config);
68
- var renderer = Ext.netzke.renderer(c.renderer);
69
-
70
- if (c.editor == 'checkbox') {
71
- var plugin = new Ext.grid.CheckColumn({
72
- header: c.label || c.name,
73
- dataIndex: c.name,
74
- disabled: c.readOnly,
75
- hidden: c.hidden,
76
- width: c.width
77
- });
78
- plugins.push(plugin);
79
- this.cmConfig.push(plugin);
80
-
81
- } else {
82
- this.cmConfig.push({
83
- header: c.label || c.name,
84
- dataIndex: c.name,
85
- hidden: c.hidden,
86
- width: c.width,
87
- editor: editor,
88
- renderer: renderer,
89
- sortable: true
90
- })
91
- }
92
-
93
- }, this);
94
-
95
- var cm = new Ext.grid.ColumnModel(this.cmConfig);
96
-
97
- this.addEvents("refresh");
98
-
99
- // Filters
100
- if (config.enableColumnFilters) {
101
- var filters = []
102
- Ext.each(config.columns, function(c){
103
- filters.push({type:Ext.netzke.filterMap[c.editor], dataIndex:c.name})
104
- })
105
- var gridFilters = new Ext.grid.GridFilters({filters:filters});
106
- plugins.push(gridFilters);
107
- }
108
-
109
- JS
110
- end
111
-
112
- def js_listeners
113
- super.merge({
114
- :columnresize => {:fn => "this.onColumnResize".l, :scope => this},
115
- :columnmove => {:fn => "this.onColumnMove".l, :scope => this}
116
- })
117
- end
118
-
119
- def js_extend_properties
120
- {
121
- :on_widget_load => <<-JS.l,
122
- function(){
123
- // auto-load
124
- if (this.initialConfig.autoLoadData) {
125
- // if we have a paging toolbar, load the first page, otherwise
126
- if (this.getBottomToolbar().changePage) this.getBottomToolbar().changePage(0); else this.store.load();
127
- }
128
- }
129
- JS
130
-
131
- :load_exception_handler => <<-JS.l,
132
- function(proxy, options, response, error){
133
- if (response.status == 200 && (responseObject = Ext.decode(response.responseText)) && responseObject.flash){
134
- this.feedback(responseObject.flash)
135
- } else {
136
- if (error){
137
- this.feedback(error.message);
138
- } else {
139
- this.feedback(response.statusText)
140
- }
141
- }
142
- }
143
- JS
144
-
145
- :add => <<-JS.l,
146
- function(){
147
- var rowConfig = {};
148
- Ext.each(this.initialConfig.columns, function(c){
149
- rowConfig[c.name] = c.defaultValue || ''; // FIXME: if the user is happy with all the defaults, the record won't be 'dirty'
150
- }, this);
151
-
152
- var r = new this.Row(rowConfig); // TODO: add default values
153
- r.set('id', -r.id); // to distinguish new records by negative values
154
- this.stopEditing();
155
- this.store.add(r);
156
- this.store.newRecords = this.store.newRecords || []
157
- this.store.newRecords.push(r);
158
- // console.info(this.store.newRecords);
159
- this.tryStartEditing(this.store.indexOf(r));
160
- }
161
- JS
162
-
163
- :edit => <<-JS.l,
164
- function(){
165
- var row = this.getSelectionModel().getSelected();
166
- if (row){
167
- this.tryStartEditing(this.store.indexOf(row))
168
- }
169
- }
170
- JS
171
-
172
- # try editing the first editable (not hidden, not read-only) sell
173
- :try_start_editing => <<-JS.l,
174
- function(row){
175
- if (row == null) return;
176
- var editableColumns = this.getColumnModel().getColumnsBy(function(columnConfig, index){
177
- return !columnConfig.hidden && !!columnConfig.editor;
178
- });
179
- // console.info(editableColumns);
180
- var firstEditableColumn = editableColumns[0];
181
- if (firstEditableColumn){
182
- this.startEditing(row, firstEditableColumn.id);
183
- }
184
- }
185
- JS
186
-
187
- :delete => <<-JS.l,
188
- function() {
189
- if (this.getSelectionModel().hasSelection()){
190
- Ext.Msg.confirm('Confirm', 'Are you sure?', function(btn){
191
- if (btn == 'yes') {
192
- var records = []
193
- this.getSelectionModel().each(function(r){
194
- records.push(r.get('id'));
195
- }, this);
196
- Ext.Ajax.request({
197
- url: this.initialConfig.interface.deleteData,
198
- params: {records: Ext.encode(records)},
199
- success:function(r){
200
- var m = Ext.decode(r.responseText);
201
- this.store.reload();
202
- // this.loadWithFeedback();
203
- this.feedback(m.flash);
204
- },
205
- scope:this
206
- });
207
- }
208
- }, this);
209
- }
210
- }
211
- JS
212
- :submit => <<-JS.l,
213
- function(){
214
-
215
- var newRecords = [];
216
- if (this.store.newRecords){
217
- Ext.each(this.store.newRecords, function(r){
218
- newRecords.push(r.getChanges())
219
- r.commit() // commit the changes, so that they are not picked up by getModifiedRecords() further down
220
- }, this);
221
- delete this.store.newRecords;
222
- }
223
-
224
- var updatedRecords = [];
225
- Ext.each(this.store.getModifiedRecords(),
226
- function(record) {
227
- var completeRecordData = {};
228
- Ext.apply(completeRecordData, Ext.apply(record.getChanges(), {id:record.get('id')}));
229
- updatedRecords.push(completeRecordData);
230
- },
231
- this);
232
-
233
- if (newRecords.length > 0 || updatedRecords.length > 0) {
234
- Ext.Ajax.request({
235
- url:this.initialConfig.interface.postData,
236
- params: {
237
- updated_records: Ext.encode(updatedRecords),
238
- created_records: Ext.encode(newRecords),
239
- filters: this.store.baseParams.filters
240
- },
241
- success:function(response){
242
- var m = Ext.decode(response.responseText);
243
- if (m.success) {
244
- this.store.reload();
245
- // this.loadWithFeedback();
246
- this.store.commitChanges();
247
- this.feedback(m.flash);
248
- } else {
249
- this.feedback(m.flash);
250
- }
251
- },
252
- failure:function(response){
253
- this.feedback('Bad response from server');
254
- },
255
- scope:this
256
- });
257
- }
258
-
259
- }
260
- JS
261
-
262
- :refresh_click => <<-JS.l,
263
- function() {
264
- // console.info(this);
265
- // if (this.fireEvent('refresh', this) !== false) this.loadWithFeedback();
266
- if (this.fireEvent('refresh', this) !== false) this.store.reload();
267
- }
268
- JS
269
-
270
- :on_column_resize => <<-JS.l,
271
- function(index, size){
272
- Ext.Ajax.request({
273
- url:this.initialConfig.interface.resizeColumn,
274
- params:{
275
- index:index,
276
- size:size
277
- }
278
- })
279
- }
280
- JS
281
-
282
- :on_column_move => <<-JS.l
283
- function(oldIndex, newIndex){
284
- Ext.Ajax.request({
285
- url:this.initialConfig.interface.moveColumn,
286
- params:{
287
- old_index:oldIndex,
288
- new_index:newIndex
289
- }
290
- })
291
- }
292
- JS
293
-
294
- }
295
- end
296
-
297
- end
298
- end
data/test/column_test.rb DELETED
@@ -1,27 +0,0 @@
1
- require 'test_helper'
2
-
3
- require 'netzke/ar_ext'
4
-
5
- ActiveRecord::Base.class_eval do
6
- include Netzke::ActiveRecordExtensions
7
- end
8
-
9
- require 'netzke/column'
10
-
11
- class ColumnTest < ActiveSupport::TestCase
12
- test "default columns" do
13
- stub_widget = Object.new
14
- def stub_widget.config
15
- {:name => 'widget', :data_class_name => 'Book', :columns => [:title, {:name => :amount, :read_only => true}, :recent]}
16
- end
17
-
18
- columns = Netzke::Column.default_columns_for_widget(stub_widget)
19
-
20
- assert_equal(false, columns[0][:read_only])
21
- assert_equal(true, columns[1][:read_only])
22
- assert_equal("Amount", columns[1][:label])
23
- assert_equal("Recent", columns[2][:label])
24
- assert_equal(true, columns[2][:read_only]) # read_only specified in the model itself
25
- # puts "!!! columns: #{columns.inspect}"
26
- end
27
- end