netzke-basepack 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Ext.ux.form.XCheckbox - checkbox with configurable submit values
3
+ *
4
+ * @author Ing. Jozef Sakalos
5
+ * @version $Id: Ext.ux.form.XCheckbox.js 441 2009-01-12 11:10:10Z jozo $
6
+ * @date 10. February 2008
7
+ *
8
+ *
9
+ * @license Ext.ux.form.XCheckbox is licensed under the terms of
10
+ * the Open Source LGPL 3.0 license. Commercial use is permitted to the extent
11
+ * that the code/component(s) do NOT become part of another Open Source or Commercially
12
+ * licensed development library or toolkit without explicit permission.
13
+ *
14
+ * License details: http://www.gnu.org/licenses/lgpl.html
15
+ */
16
+
17
+ /*global Ext */
18
+
19
+ /**
20
+ * @class Ext.ux.XCheckbox
21
+ * @extends Ext.form.Checkbox
22
+ */
23
+ Ext.ns('Ext.ux.form');
24
+ Ext.ux.form.XCheckbox = Ext.extend(Ext.form.Checkbox, {
25
+ submitOffValue:'false'
26
+ ,submitOnValue:'true'
27
+
28
+ ,onRender:function() {
29
+
30
+ this.inputValue = this.submitOnValue;
31
+
32
+ // call parent
33
+ Ext.ux.form.XCheckbox.superclass.onRender.apply(this, arguments);
34
+
35
+ // create hidden field that is submitted if checkbox is not checked
36
+ this.hiddenField = this.wrap.insertFirst({tag:'input', type:'hidden'});
37
+
38
+ // support tooltip
39
+ if(this.tooltip) {
40
+ this.imageEl.set({qtip:this.tooltip});
41
+ }
42
+
43
+ // update value of hidden field
44
+ this.updateHidden();
45
+
46
+ } // eo function onRender
47
+
48
+ /**
49
+ * Calls parent and updates hiddenField
50
+ * @private
51
+ */
52
+ ,setValue:function(v) {
53
+ v = this.convertValue(v);
54
+ this.updateHidden(v);
55
+ Ext.ux.form.XCheckbox.superclass.setValue.apply(this, arguments);
56
+ } // eo function setValue
57
+
58
+ /**
59
+ * Updates hiddenField
60
+ * @private
61
+ */
62
+ ,updateHidden:function(v) {
63
+ v = undefined !== v ? v : this.checked;
64
+ v = this.convertValue(v);
65
+ if(this.hiddenField) {
66
+ this.hiddenField.dom.value = v ? this.submitOnValue : this.submitOffValue;
67
+ this.hiddenField.dom.name = v ? '' : this.el.dom.name;
68
+ }
69
+ } // eo function updateHidden
70
+
71
+ /**
72
+ * Converts value to boolean
73
+ * @private
74
+ */
75
+ ,convertValue:function(v) {
76
+ return (v === true || v === 'true' || v == 1 || v === this.submitOnValue || String(v).toLowerCase() === 'on');
77
+ } // eo function convertValue
78
+
79
+ }); // eo extend
80
+
81
+ // register xtype
82
+ Ext.reg('xcheckbox', Ext.ux.form.XCheckbox);
@@ -37,7 +37,7 @@ Ext.ux.form.DateTime = Ext.extend(Ext.form.Field, {
37
37
  /**
38
38
  * @cfg {Number} timeWidth Width of time field in pixels (defaults to 100)
39
39
  */
40
- ,timeWidth:100
40
+ ,timeWidth:80
41
41
  /**
42
42
  * @cfg {String} dtSeparator Date - Time separator. Used to split date and time (defaults to ' ' (space))
43
43
  */
@@ -20,7 +20,7 @@ module Netzke
20
20
  name:field.name,
21
21
  mapping:index++
22
22
  });
23
- field.hideLabel = field.hidden; // completely hide the field marked "hidden"
23
+ field.hideLabel = field.hidden; // completely hide fields marked "hidden"
24
24
  var extConfig;
25
25
  try{
26
26
  extConfig = Ext.decode(field.extConfig)
@@ -52,12 +52,13 @@ module Netzke
52
52
  }
53
53
  },
54
54
  :defaults => {
55
- :anchor => '-20', # to leave some space for the scrollbar
56
- :listeners => {
55
+ # :anchor => '-20', # to leave some space for the scrollbar
56
+ :width => 180,
57
+ :listeners => {
57
58
  :specialkey => {
58
59
  :fn => <<-JS.l,
59
60
  function(field, event){
60
- if (event.getKey() == 13) this.submit();
61
+ if (event.getKey() == 13) this.apply();
61
62
  }
62
63
  JS
63
64
  :scope => this
@@ -88,10 +89,9 @@ module Netzke
88
89
  }
89
90
  }
90
91
  JS
91
- :refresh_click => <<-JS.l,
92
+ :refresh=> <<-JS.l,
92
93
  function() {
93
94
  this.feedback('Implement me!');
94
- // this.loadRecord(3)
95
95
  }
96
96
  JS
97
97
  :previous => <<-JS.l,
@@ -106,7 +106,7 @@ module Netzke
106
106
  this.loadRecord(currentId, 'next');
107
107
  }
108
108
  JS
109
- :submit => <<-JS.l,
109
+ :apply => <<-JS.l,
110
110
  function() {
111
111
  this.form.submit({
112
112
  url:this.initialConfig.interface.submit,
@@ -1,5 +1,9 @@
1
1
  require 'searchlogic'
2
+ require "app/models/netzke_grid_panel_column"
3
+
2
4
  module Netzke
5
+ #
6
+ # GridPanel
3
7
  #
4
8
  # Functionality:
5
9
  # * data operations - get, post, delete, create
@@ -12,66 +16,58 @@ module Netzke
12
16
  # * properties and column configuration
13
17
  #
14
18
  class GridPanel < Base
15
- # so that some inherited methods would know our real location
16
- self.widget_file = __FILE__
17
-
18
- # include javascripts from Ext examples
19
- ext_js_include "examples/grid-filtering/menu/EditableItem.js",
20
- "examples/grid-filtering/menu/RangeMenu.js",
21
- "examples/grid-filtering/grid/GridFilters.js"
22
-
23
- %w{Boolean Date List Numeric String}.unshift("").each do |f|
24
- ext_js_include "examples/grid-filtering/grid/filter/#{f}Filter.js"
19
+ # Class-level configuration with defaults
20
+ def self.config
21
+ set_default_config({
22
+ :column_manager => "NetzkeGridPanelColumn",
23
+ :enable_filters => false
24
+ })
25
25
  end
26
26
 
27
- # include ruby code in grid_panel_extras
28
- include_extras
27
+ include Netzke::GridPanelExtras::JsBuilder
28
+ include Netzke::GridPanelExtras::Interface
29
+ include Netzke::DbFields # database field operations
30
+
31
+ # javascripts for grid-filtering (from Ext examples)
32
+ if Netzke::GridPanel.config[:enable_filters]
33
+ js_include :ext_examples => %w{grid-filtering/menu/EditableItem.js grid-filtering/menu/RangeMenu.js grid-filtering/grid/GridFilters.js}
34
+
35
+ js_include :ext_examples => %w{Boolean Date List Numeric String}.unshift("").map{|f| "grid-filtering/grid/filter/#{f}Filter.js" }
36
+
37
+ js_include "#{File.dirname(__FILE__)}/grid_panel_extras/javascripts/filters.js"
38
+ end
39
+
40
+ # extra javascripts
41
+ js_include "#{File.dirname(__FILE__)}/grid_panel_extras/javascripts/check-column.js"
29
42
 
30
43
  # define connection points between client side and server side of GridPanel.
31
44
  # See implementation of equally named methods in the GridPanelExtras::Interface module.
32
45
  interface :get_data, :post_data, :delete_data, :resize_column, :move_column, :get_cb_choices
33
46
 
34
- # database field operations
35
- include Netzke::DbFields
36
-
37
- module ClassMethods
38
- def widget_type
39
- :grid
40
- end
41
-
42
- # Global GridPanel configuration
43
- def config
44
- set_default_config({
45
- :column_manager => "NetzkeGridPanelColumn"
46
- })
47
- end
48
-
49
- def column_manager_class
50
- config[:column_manager].constantize
51
- rescue
52
- nil
53
- end
54
-
47
+ # widget type for DbFields
48
+ # TODO: ugly, rethink
49
+ def self.widget_type
50
+ :grid
55
51
  end
56
- extend ClassMethods
57
52
 
58
- def layout_manager_class
59
- self.class.layout_manager_class
53
+ def self.column_manager_class
54
+ config[:column_manager].constantize
55
+ rescue
56
+ nil
60
57
  end
61
58
 
62
59
  def column_manager_class
63
60
  self.class.column_manager_class
64
61
  end
65
62
 
66
- # default grid configuration
63
+ # default instance-level configuration
67
64
  def initial_config
68
65
  {
69
66
  :ext_config => {
70
- :config_tool => false,
71
- :enable_column_filters => Netzke::Base.config[:grid_panel][:filters],
67
+ :config_tool => true,
68
+ :enable_column_filters => Netzke::GridPanel.config[:enable_filters],
72
69
  :enable_column_move => true,
73
- :enable_column_resize => true,
74
- :load_mask => true
70
+ :enable_column_resize => true
75
71
  },
76
72
  :persistent_layout => true,
77
73
  :persistent_config => true
@@ -82,7 +78,7 @@ module Netzke
82
78
  ["FieldsConfigurator"] # TODO: make this happen automatically
83
79
  end
84
80
 
85
- def property_widgets
81
+ def configuration_widgets
86
82
  res = []
87
83
  res << {
88
84
  :name => 'columns',
@@ -94,28 +90,14 @@ module Netzke
94
90
 
95
91
  res << {
96
92
  :name => 'general',
97
- :widget_class_name => "PreferenceGrid",
98
- :host_widget_name => id_name,
99
- :default_properties => available_permissions.map{ |k| {:name => "permissions.#{k}", :value => @permissions[k.to_sym]}},
93
+ :widget_class_name => "PropertyEditor",
94
+ :widget_name => id_name,
100
95
  :ext_config => {:title => false}
101
96
  }
102
97
 
103
98
  res
104
99
  end
105
100
 
106
- def properties__general__load_source(params = {})
107
- w = aggregatee_instance(:properties__general)
108
- w.interface_load_source(params)
109
- end
110
-
111
- protected
112
-
113
- def available_permissions
114
- %w(read update create delete)
115
- end
116
-
117
- public
118
-
119
101
  # get columns from layout manager
120
102
  def get_columns
121
103
  @columns ||=
@@ -129,28 +111,28 @@ module Netzke
129
111
  end
130
112
 
131
113
  def tools
132
- [{:id => 'refresh', :on => {:click => 'refreshClick'}, :qtip => 'Refresh'}]
114
+ %w{ refresh }
133
115
  end
134
116
 
135
117
  def actions
136
- [{
137
- :text => 'Add', :handler_name => 'add', :disabled => !@permissions[:create], :id => 'add'
138
- },{
139
- :text => 'Edit', :handler_name => 'edit', :disabled => !@permissions[:update], :id => 'edit'
140
- },{
141
- :text => 'Delete', :handler_name => 'delete', :disabled => !@permissions[:delete], :id => 'delete'
142
- },{
143
- :text => 'Apply', :handler_name => 'submit', :disabled => !@permissions[:update] && !@permissions[:create], :id => 'apply'
144
- }]
118
+ { :add => {:text => 'Add', :disabled => !@permissions[:create]},
119
+ :edit => {:text => 'Edit', :disabled => !@permissions[:update]},
120
+ :delete => {:text => 'Delete', :disabled => !@permissions[:delete]},
121
+ :apply => {:text => 'Apply', :disabled => !@permissions[:update] && !@permissions[:create]}
122
+ }
145
123
  end
146
124
 
125
+ def bbar
126
+ persistent_config[:bottom_bar] ||= config[:bbar] == false ? nil : config[:bbar] || %w{ add edit apply delete }
127
+ end
147
128
 
148
-
149
- # Uncomment to enable a menu duplicating the actions
150
- # def js_menus
151
- # [{:text => "config.dataClassName".l, :menu => "config.actions".l}]
152
- # end
129
+ include ConfigurationTool # it will load aggregation with name :properties into a modal window
130
+
131
+ protected
132
+
133
+ def available_permissions
134
+ %w(read update create delete)
135
+ end
153
136
 
154
- include PropertiesTool # it will load aggregation with name :properties into a modal window
155
137
  end
156
138
  end
@@ -140,6 +140,7 @@ module Netzke
140
140
  output_array
141
141
  end
142
142
 
143
+ # TODO: document me!
143
144
  def convert_filters(column_filter)
144
145
  res = {}
145
146
  column_filter.each_pair do |k,v|
@@ -10,7 +10,7 @@ Ext.grid.CheckColumn = function(config){
10
10
  Ext.grid.CheckColumn.prototype ={
11
11
  init : function(grid){
12
12
  this.grid = grid;
13
- if (this.disabled) return; // SK
13
+ if (this.disabled) {return;} // SK
14
14
  this.grid.on('render', function(){
15
15
  var view = this.grid.getView();
16
16
  view.mainBody.on('mousedown', this.onMouseDown, this);
@@ -18,23 +18,13 @@ module Netzke
18
18
  :rows_per_page => persistent_config["rows_per_page"] ||= config[:ext_config][:rows_per_page]
19
19
  })
20
20
  end
21
-
21
+
22
22
  module ClassMethods
23
23
 
24
24
  def js_base_class
25
25
  'Ext.grid.EditorGridPanel'
26
26
  end
27
27
 
28
- def js_bbar
29
- <<-JS.l
30
- (config.rowsPerPage) ? new Ext.PagingToolbar({
31
- pageSize:config.rowsPerPage,
32
- items:config.actions,
33
- store:ds,
34
- emptyMsg:'Empty'}) : config.actions
35
- JS
36
- end
37
-
38
28
  def js_default_config
39
29
  super.merge({
40
30
  :store => "ds".l,
@@ -43,9 +33,8 @@ module Netzke
43
33
  :auto_scroll => true,
44
34
  :click_to_edit => 2,
45
35
  :track_mouse_over => true,
46
- # :bbar => "config.actions".l,
47
- :bbar => js_bbar,
48
36
  :plugins => "plugins".l,
37
+ :load_mask => true,
49
38
 
50
39
  #custom configs
51
40
  :auto_load_data => true
@@ -55,9 +44,9 @@ module Netzke
55
44
  def js_before_constructor
56
45
  <<-JS
57
46
  var plugins = [];
58
- if (!config.columns) this.feedback('No columns defined for grid '+config.id);
47
+ if (!config.columns) {this.feedback('No columns defined for grid '+config.id);}
59
48
  this.recordConfig = [];
60
- Ext.each(config.columns, function(column){this.recordConfig.push({name:column.name})}, this);
49
+ Ext.each(config.columns, function(column){this.recordConfig.push({name:column.name});}, this);
61
50
  this.Row = Ext.data.Record.create(this.recordConfig);
62
51
 
63
52
  var ds = new Ext.data.Store({
@@ -77,7 +66,7 @@ module Netzke
77
66
  extConfig = Ext.decode(c.extConfig);
78
67
  }
79
68
  catch(err){
80
- extConfig = {}
69
+ extConfig = {};
81
70
  }
82
71
  delete(c.extConfig);
83
72
 
@@ -105,24 +94,30 @@ module Netzke
105
94
  editor : editor,
106
95
  renderer : renderer,
107
96
  sortable : true
108
- }, extConfig))
97
+ }, extConfig));
109
98
  }
110
99
 
111
100
  }, this);
112
101
 
113
102
  var cm = new Ext.grid.ColumnModel(this.cmConfig);
114
103
 
115
- this.addEvents("refresh");
104
+ // this.addEvents("refresh");
116
105
 
117
106
  // Filters
118
107
  if (config.enableColumnFilters) {
119
- var filters = []
108
+ var filters = [];
120
109
  Ext.each(config.columns, function(c){
121
- filters.push({type:Ext.netzke.filterMap[c.editor], dataIndex:c.name})
122
- })
110
+ filters.push({type:Ext.netzke.filterMap[c.editor], dataIndex:c.name});
111
+ });
123
112
  var gridFilters = new Ext.grid.GridFilters({filters:filters});
124
113
  plugins.push(gridFilters);
125
114
  }
115
+
116
+ config.bbar = (config.rowsPerPage) ? new Ext.PagingToolbar({
117
+ pageSize:config.rowsPerPage,
118
+ items:["-", config.bbar],
119
+ store:ds,
120
+ emptyMsg:'Empty'}) : config.bbar
126
121
 
127
122
  JS
128
123
  end
@@ -140,8 +135,8 @@ module Netzke
140
135
  function(){
141
136
  // auto-load
142
137
  if (this.initialConfig.autoLoadData) {
143
- // if we have a paging toolbar, load the first page, otherwise
144
- if (this.getBottomToolbar().changePage) this.getBottomToolbar().changePage(0); else this.store.load();
138
+ // if we have a paging toolbar, load the first page
139
+ if (this.getBottomToolbar().changePage) {this.getBottomToolbar().changePage(0);} else {this.store.load();}
145
140
  }
146
141
  }
147
142
  JS
@@ -149,12 +144,12 @@ module Netzke
149
144
  :load_exception_handler => <<-JS.l,
150
145
  function(proxy, options, response, error){
151
146
  if (response.status == 200 && (responseObject = Ext.decode(response.responseText)) && responseObject.flash){
152
- this.feedback(responseObject.flash)
147
+ this.feedback(responseObject.flash);
153
148
  } else {
154
149
  if (error){
155
150
  this.feedback(error.message);
156
151
  } else {
157
- this.feedback(response.statusText)
152
+ this.feedback(response.statusText);
158
153
  }
159
154
  }
160
155
  }
@@ -182,7 +177,7 @@ module Netzke
182
177
  function(){
183
178
  var row = this.getSelectionModel().getSelected();
184
179
  if (row){
185
- this.tryStartEditing(this.store.indexOf(row))
180
+ this.tryStartEditing(this.store.indexOf(row));
186
181
  }
187
182
  }
188
183
  JS
@@ -190,7 +185,7 @@ module Netzke
190
185
  # try editing the first editable (not hidden, not read-only) sell
191
186
  :try_start_editing => <<-JS.l,
192
187
  function(row){
193
- if (row == null) return;
188
+ if (row === null) {return;}
194
189
  var editableColumns = this.getColumnModel().getColumnsBy(function(columnConfig, index){
195
190
  return !columnConfig.hidden && !!columnConfig.editor;
196
191
  });
@@ -207,7 +202,7 @@ module Netzke
207
202
  if (this.getSelectionModel().hasSelection()){
208
203
  Ext.Msg.confirm('Confirm', 'Are you sure?', function(btn){
209
204
  if (btn == 'yes') {
210
- var records = []
205
+ var records = [];
211
206
  this.getSelectionModel().each(function(r){
212
207
  records.push(r.get('id'));
213
208
  }, this);
@@ -226,7 +221,7 @@ module Netzke
226
221
  }
227
222
  }
228
223
  JS
229
- :submit => <<-JS.l,
224
+ :apply => <<-JS.l,
230
225
  function(){
231
226
 
232
227
  var newRecords = [];
@@ -261,15 +256,15 @@ module Netzke
261
256
  var m = Ext.decode(response.responseText);
262
257
  if (m.success) {
263
258
  // commit those rows that have successfully been updated/created
264
- var modRecords = [].concat(this.store.getModifiedRecords()) // there must be a better way to clone an array...
259
+ var modRecords = [].concat(this.store.getModifiedRecords()); // there must be a better way to clone an array...
265
260
  Ext.each(modRecords, function(r){
266
- var idsToSearch = r.is_new ? m.modRecordIds.create : m.modRecordIds.update
267
- if (idsToSearch.indexOf(r.id) >= 0) r.commit();
268
- })
261
+ var idsToSearch = r.is_new ? m.modRecordIds.create : m.modRecordIds.update;
262
+ if (idsToSearch.indexOf(r.id) >= 0) {r.commit();}
263
+ });
269
264
 
270
265
  // reload the grid only when there were no errors
271
266
  // (we need to reload because of filtering, sorting, etc)
272
- if (this.store.getModifiedRecords().length == 0){
267
+ if (this.store.getModifiedRecords().length === 0){
273
268
  this.store.reload();
274
269
  }
275
270
 
@@ -288,9 +283,9 @@ module Netzke
288
283
  }
289
284
  JS
290
285
 
291
- :refresh_click => <<-JS.l,
286
+ :refresh => <<-JS.l,
292
287
  function() {
293
- if (this.fireEvent('refresh', this) !== false) this.store.reload();
288
+ if (this.fireEvent('refresh', this) !== false) {this.store.reload();}
294
289
  }
295
290
  JS
296
291
 
@@ -302,7 +297,7 @@ module Netzke
302
297
  index:index,
303
298
  size:size
304
299
  }
305
- })
300
+ });
306
301
  }
307
302
  JS
308
303
 
@@ -314,7 +309,7 @@ module Netzke
314
309
  old_index:oldIndex,
315
310
  new_index:newIndex
316
311
  }
317
- })
312
+ });
318
313
  }
319
314
  JS
320
315