netzke-basepack 0.5.4 → 0.5.5

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.
@@ -49,7 +49,8 @@ module Netzke
49
49
  var regionConfig = this.regions[r] || {};
50
50
  regionConfig.layout = 'fit';
51
51
  regionConfig.region = r;
52
- regionConfig.items = [new Ext.netzke.cache[this[configName].widgetClassName](this[configName])]
52
+ var klass = this.classifyScopedName(this[configName].scopedClassName);
53
+ regionConfig.items = [new klass(this[configName])]
53
54
  this.items.push(regionConfig);
54
55
 
55
56
  // A function to access a region widget (even if the widget gets reloaded, the function will work).
@@ -61,7 +62,7 @@ module Netzke
61
62
  }, this);
62
63
 
63
64
  // Now let Ext.Panel do the rest
64
- Ext.netzke.cache.BorderLayoutPanel.superclass.initComponent.call(this);
65
+ #{js_full_class_name}.superclass.initComponent.call(this);
65
66
 
66
67
  // First time on "afterlayout", set resize events
67
68
  if (this.persistentConfig) {this.on('afterlayout', this.setResizeEvents, this, {single: true});}
@@ -119,6 +120,7 @@ module Netzke
119
120
  # API
120
121
  api :resize_region # handles regions resize
121
122
  def resize_region(params)
123
+ # Write to persistent_config such way that these settings are automatically picked up by region widgets
122
124
  persistent_config["regions__#{params["region_name"]}__region_config__width"] = params["new_width"].to_i if params["new_width"]
123
125
  persistent_config["regions__#{params["region_name"]}__region_config__height"] = params["new_height"].to_i if params["new_height"]
124
126
  {}
@@ -55,7 +55,7 @@ module Netzke
55
55
  }
56
56
  END_OF_JAVASCRIPT
57
57
 
58
- :defaults => <<-END_OF_JAVASCRIPT.l,
58
+ :on_defaults => <<-END_OF_JAVASCRIPT.l,
59
59
  function(){
60
60
  Ext.Msg.confirm('Confirm', 'Are you sure?', function(btn){
61
61
  if (btn == 'yes') {
@@ -70,7 +70,7 @@ module Netzke
70
70
  def load_defaults(params)
71
71
  config[:widget].persistent_config[:layout__columns] = config[:widget].default_columns
72
72
  NetzkeAutoColumn.rebuild_table
73
- {:load_store_data => get_data, :reconfigure => js_config}
73
+ {:load_store_data => get_data}
74
74
  end
75
75
 
76
76
  def commit(params)
@@ -43,11 +43,13 @@ module Netzke
43
43
  # Extra javascripts
44
44
  def self.include_js
45
45
  [
46
- "#{File.dirname(__FILE__)}/form_panel_extras/javascripts/xcheckbox.js"
46
+ "#{File.dirname(__FILE__)}/form_panel_extras/javascripts/xcheckbox.js",
47
+ Netzke::Base.config[:ext_location] + "/examples/ux/FileUploadField.js",
48
+ "#{File.dirname(__FILE__)}/form_panel_extras/javascripts/netzkefileupload.js"
47
49
  ]
48
50
  end
49
51
 
50
- api :submit, :load, :get_combobox_options
52
+ api :netzke_submit, :netzke_load, :get_combobox_options
51
53
 
52
54
  attr_accessor :record
53
55
 
@@ -89,7 +91,7 @@ module Netzke
89
91
  end
90
92
 
91
93
  def columns
92
- @columns ||= get_columns.convert_keys{|k| k.to_sym}
94
+ @columns ||= get_columns.deep_convert_keys{|k| k.to_sym}
93
95
  end
94
96
 
95
97
  # parameters used to instantiate the JS object
@@ -171,7 +173,7 @@ module Netzke
171
173
  # we didn't have columns configured in widget's config, so, use the columns from the data class
172
174
  columns_for_create = predefined_columns
173
175
  else
174
- raise ArgumentError, "No columns specified for widget '#{id_name}'"
176
+ raise ArgumentError, "No columns specified for widget '#{global_id}'"
175
177
  end
176
178
 
177
179
  columns_for_create.map! do |c|
@@ -1,15 +1,26 @@
1
1
  module Netzke
2
2
  module FormPanelApi
3
3
  # API handling form submission
4
- def submit(params)
5
- data_hsh = ActiveSupport::JSON.decode(params[:data])
6
- create_or_update_record(data_hsh)
4
+ def netzke_submit(params)
5
+ success = create_or_update_record(params)
6
+
7
+ if success
8
+ {:set_form_values => array_of_values, :set_result => "ok"}
9
+ else
10
+ # flash eventual errors
11
+ @record.errors.each_full do |msg|
12
+ flash :error => msg
13
+ end
14
+ {:feedback => @flash}
15
+ end
7
16
  end
8
17
 
9
18
  # Creates/updates a record from hash
10
- def create_or_update_record(hsh)
19
+ def create_or_update_record(params)
20
+ hsh = ActiveSupport::JSON.decode(params[:data])
21
+ hsh.merge!(config[:strong_default_attrs]) if config[:strong_default_attrs]
11
22
  klass = config[:data_class_name].constantize
12
- @record = klass.find_by_id(hsh.delete("id"))
23
+ @record ||= klass.find_by_id(hsh.delete("id")) # only pick up the record specified in the params if it was not provided in the configuration
13
24
  success = true
14
25
 
15
26
  @record = klass.new if @record.nil?
@@ -24,16 +35,9 @@ module Netzke
24
35
  break
25
36
  end
26
37
  end
27
-
28
- if success && @record.save
29
- {:set_form_values => array_of_values}
30
- else
31
- # flash eventual errors
32
- @record.errors.each_full do |msg|
33
- flash :error => msg
34
- end
35
- {:feedback => @flash}
36
- end
38
+
39
+ # did we have complete success?
40
+ success && @record.save
37
41
  end
38
42
 
39
43
  # API handling form load
@@ -47,7 +51,7 @@ module Netzke
47
51
  # {:data => [array_of_values]}
48
52
  # end
49
53
 
50
- def load(params)
54
+ def netzke_load(params)
51
55
  @record = data_class && data_class.find_by_id(params[:id])
52
56
  {:set_form_values => array_of_values}
53
57
  end
@@ -0,0 +1,5 @@
1
+ Ext.netzke.FileUploadField = Ext.extend(Ext.ux.form.FileUploadField, {
2
+ buttonText: "..."
3
+ });
4
+
5
+ Ext.reg('netzkefileuploadfield', Ext.netzke.FileUploadField);
@@ -50,7 +50,7 @@ module Netzke
50
50
  delete this.clmns; // we don't need them anymore
51
51
 
52
52
  // Now let Ext.form.FormPanel do the rest
53
- Ext.netzke.cache.FormPanel.superclass.initComponent.call(this);
53
+ #{js_full_class_name}.superclass.initComponent.call(this);
54
54
 
55
55
  // Apply event
56
56
  this.addEvents('apply');
@@ -59,14 +59,14 @@ module Netzke
59
59
 
60
60
  # Defaults for each field
61
61
  :defaults => {
62
- # :anchor => '-20', # to leave some space for the scrollbar
63
- :width => 180,
62
+ :anchor => '-20', # to leave some space for the scrollbar
63
+ # :width => 180, # we do NOT want fixed size because it doesn't look nice when resizing
64
64
  :listeners => {
65
65
  # On "return" key, submit the form
66
66
  :specialkey => {
67
67
  :fn => <<-END_OF_JAVASCRIPT.l
68
68
  function(field, event){
69
- if (event.getKey() == 13) this.ownerCt.apply();
69
+ if (event.getKey() == 13) this.ownerCt.onApply();
70
70
  }
71
71
  END_OF_JAVASCRIPT
72
72
  }
@@ -85,7 +85,7 @@ module Netzke
85
85
 
86
86
  :load_record => <<-END_OF_JAVASCRIPT.l,
87
87
  function(id, neighbour){
88
- this.load({id:id});
88
+ this.netzkeLoad({id:id});
89
89
  }
90
90
  END_OF_JAVASCRIPT
91
91
 
@@ -106,11 +106,30 @@ module Netzke
106
106
  :on_apply => <<-END_OF_JAVASCRIPT.l
107
107
  function() {
108
108
  if (this.fireEvent('apply', this)) {
109
- var values = this.form.getValues();
109
+ var values = this.getForm().getValues();
110
110
  for (var k in values) {
111
111
  if (values[k] == "") {delete values[k]}
112
112
  }
113
- this.submit(Ext.apply((this.baseParams || {}), {data:Ext.encode(values)}));
113
+ if (this.fileUpload) {
114
+ // Not a Netzke's standard API call, because the form is multipart
115
+ this.getForm().submit({
116
+ url: this.id + '__netzke_submit',
117
+ params: {
118
+ data: Ext.encode(values)
119
+ },
120
+ failure: function(form, action){
121
+ // It will always be failure, as we don't play along with the Ext success indication (not returning {success: true})
122
+ this.bulkExecute(Ext.decode(action.response.responseText));
123
+ this.fireEvent('submitsuccess');
124
+ },
125
+ scope: this
126
+ });
127
+ } else {
128
+ // Submit the data and process the result
129
+ this.netzkeSubmit(Ext.apply((this.baseParams || {}), {data:Ext.encode(values)}), function(result){
130
+ if (result === "ok") {this.fireEvent("submitsuccess")};
131
+ }, this);
132
+ }
114
133
  }
115
134
  }
116
135
  END_OF_JAVASCRIPT
@@ -64,7 +64,7 @@ module Netzke
64
64
  include Netzke::DataAccessor
65
65
 
66
66
  def self.enforce_config_consistency
67
- config[:default_config][:ext_config][:enable_edit_in_form] &&= config[:edit_in_form_available]
67
+ config[:default_config][:ext_config][:enable_edit_in_form] &&= config[:edit_in_form_available]
68
68
  config[:default_config][:ext_config][:enable_extended_search] &&= config[:extended_search_available]
69
69
  config[:default_config][:ext_config][:enable_rows_reordering] &&= config[:rows_reordering_available]
70
70
  end
@@ -143,7 +143,7 @@ module Netzke
143
143
  api :create_new_record if config[:edit_in_form_available]
144
144
 
145
145
  def data_class
146
- @data_class ||= config[:data_class_name].nil? ? raise(ArgumentError, "No data_class_name specified for widget #{id_name}") : config[:data_class_name].constantize
146
+ @data_class ||= config[:data_class_name].nil? ? raise(ArgumentError, "No data_class_name specified for widget #{global_id}") : config[:data_class_name].constantize
147
147
  end
148
148
 
149
149
 
@@ -188,7 +188,7 @@ module Netzke
188
188
  {:name => :ext_config__context_menu, :type => :json},
189
189
  {:name => :ext_config__enable_pagination, :type => :boolean, :default => true},
190
190
  {:name => :ext_config__rows_per_page, :type => :integer},
191
- {:name => :ext_config__bbar, :type => :json},
191
+ {:name => :ext_config__bbar, :type => :json},
192
192
  {:name => :ext_config__prohibit_create, :type => :boolean},
193
193
  {:name => :ext_config__prohibit_update, :type => :boolean},
194
194
  {:name => :ext_config__prohibit_delete, :type => :boolean},
@@ -202,11 +202,11 @@ module Netzke
202
202
 
203
203
  end
204
204
 
205
- def initial_config
205
+ def default_config
206
206
  res = super
207
207
 
208
- res[:ext_config][:bbar] = default_bbar if res[:ext_config][:bbar].nil?
209
- res[:ext_config][:context_menu] ||= default_context_menu
208
+ res[:ext_config][:bbar] = default_bbar
209
+ res[:ext_config][:context_menu] = default_context_menu
210
210
 
211
211
  res
212
212
  end
@@ -244,17 +244,16 @@ module Netzke
244
244
 
245
245
  def actions
246
246
  # Defaults
247
- res = {
247
+ {
248
248
  :add => {:text => 'Add', :disabled => ext_config[:prohibit_create]},
249
249
  :edit => {:text => 'Edit', :disabled => true},
250
250
  :del => {:text => 'Delete', :disabled => true},
251
- :apply => {:text => 'Apply', :disabled => ext_config[:prohibit_update] && ext_config[:prohibit_create]},
251
+ :apply => {:text => 'Apply', :disabled => ext_config[:prohibit_update] &&
252
+ ext_config[:prohibit_create]},
252
253
  :add_in_form => {:text => 'Add in form', :disabled => !ext_config[:enable_edit_in_form]},
253
254
  :edit_in_form => {:text => 'Edit in form', :disabled => true},
254
255
  :search => {:text => 'Search', :disabled => !ext_config[:enable_extended_search]}
255
256
  }
256
-
257
- res
258
257
  end
259
258
 
260
259
  def initial_late_aggregatees
@@ -262,6 +261,27 @@ module Netzke
262
261
 
263
262
  # Edit in form
264
263
  res.merge!({
264
+ :add_form => {
265
+ :widget_class_name => "GridPanelExtras::RecordFormWindow",
266
+ :ext_config => {
267
+ :title => "Add #{config[:data_class_name].humanize}",
268
+ :button_align => "right"
269
+ },
270
+ :item => {
271
+ :widget_class_name => "FormPanel",
272
+ :data_class_name => config[:data_class_name],
273
+ :persistent_config => config[:persistent_config],
274
+ :strong_default_attrs => config[:strong_default_attrs],
275
+ :ext_config => {
276
+ :border => true,
277
+ :bbar => false,
278
+ :header => false,
279
+ :mode => ext_config[:mode]
280
+ },
281
+ :record => config[:data_class_name].constantize.new
282
+ }
283
+ },
284
+
265
285
  :edit_form => {
266
286
  :widget_class_name => "FormPanel",
267
287
  :data_class_name => config[:data_class_name],
@@ -288,6 +308,7 @@ module Netzke
288
308
  :widget_class_name => "FormPanel",
289
309
  :data_class_name => config[:data_class_name],
290
310
  :persistent_config => config[:persistent_config],
311
+ :strong_default_attrs => config[:strong_default_attrs],
291
312
  :ext_config => {
292
313
  :bbar => false,
293
314
  :header => false,
@@ -28,7 +28,7 @@ module Netzke
28
28
  end
29
29
  end
30
30
 
31
- def delete_data(params = {})
31
+ def delete_data(params)
32
32
  if !ext_config[:prohibit_delete]
33
33
  record_ids = ActiveSupport::JSON.decode(params[:records])
34
34
  klass = config[:data_class_name].constantize
@@ -39,24 +39,38 @@ module Netzke
39
39
  end
40
40
  end
41
41
 
42
+ # Given an index of a column among enabled (non-excluded) columns, provides the index (position) in the table
43
+ def normalize_index(index)
44
+ norm_index = 0
45
+ index.times do
46
+ while true do
47
+ norm_index += 1
48
+ break unless normalized_columns[norm_index][:excluded]
49
+ end
50
+ end
51
+ norm_index
52
+ end
53
+
42
54
  def resize_column(params)
43
55
  raise "Called api_resize_column while not configured to do so" if ext_config[:enable_column_resize] == false
44
- column_at(params[:index].to_i)[:width] = params[:size].to_i
56
+ column_at(normalize_index(params[:index].to_i))[:width] = params[:size].to_i
45
57
  save_columns!
46
58
  {}
47
59
  end
48
60
 
49
61
  def hide_column(params)
50
62
  raise "Called api_hide_column while not configured to do so" if ext_config[:enable_column_hide] == false
51
- column_at(params[:index].to_i)[:hidden] = params[:hidden].to_b
63
+ column_at(normalize_index(params[:index].to_i))[:hidden] = params[:hidden].to_b
52
64
  save_columns!
53
65
  {}
54
66
  end
55
67
 
56
68
  def move_column(params)
57
69
  raise "Called api_move_column while not configured to do so" if ext_config[:enable_column_move] == false
58
- column_to_move = columns.delete_at(params[:old_index].to_i)
59
- columns.insert(params[:new_index].to_i, column_to_move)
70
+ remove_from = normalize_index(params[:old_index].to_i)
71
+ insert_to = normalize_index(params[:new_index].to_i)
72
+ column_to_move = columns.delete_at(remove_from)
73
+ columns.insert(insert_to, column_to_move)
60
74
  save_columns!
61
75
 
62
76
  # reorder the columns on the client side (still not sure if it's not an overkill)
@@ -239,24 +253,24 @@ module Netzke
239
253
  end
240
254
 
241
255
  # Converts Ext.grid.GridFilters filters to searchlogic conditions, e.g.
242
- # {"0" => {
243
- # "data" => {
244
- # "type" => "numeric",
245
- # "comparison" => "gt",
246
- # "value" => 10 },
247
- # "field" => "id"
248
- # },
249
- # "1" => {
250
- # "data" => {
251
- # "type" => "string",
252
- # "value" => "pizza"
253
- # },
254
- # "field" => "food_name"
255
- # }}
256
- #
257
- # =>
258
- #
259
- # {"id_gt" => 100, "food_name_contains" => "pizza"}
256
+ # {"0" => {
257
+ # "data" => {
258
+ # "type" => "numeric",
259
+ # "comparison" => "gt",
260
+ # "value" => 10 },
261
+ # "field" => "id"
262
+ # },
263
+ # "1" => {
264
+ # "data" => {
265
+ # "type" => "string",
266
+ # "value" => "pizza"
267
+ # },
268
+ # "field" => "food_name"
269
+ # }}
270
+ #
271
+ # =>
272
+ #
273
+ # {"id_gt" => 100, "food_name_contains" => "pizza"}
260
274
  def convert_filters(column_filter)
261
275
  res = {}
262
276
  column_filter.each_pair do |k,v|
@@ -274,7 +288,7 @@ module Netzke
274
288
  end
275
289
 
276
290
  def normalize_extra_conditions(conditions)
277
- conditions.convert_keys{|k| k.to_s.gsub("__", "_").to_sym}
291
+ conditions.deep_convert_keys{|k| k.to_s.gsub("__", "_").to_sym}
278
292
  end
279
293
 
280
294
  # make params understandable to searchlogic
@@ -292,13 +306,8 @@ module Netzke
292
306
  end
293
307
 
294
308
  ## Edit in form specific API
295
- def new_record_form__submit(params)
296
- form_data = ActiveSupport::JSON.decode(params[:data])
297
-
298
- # merge with strong default attirbutes
299
- form_data.merge!(config[:strong_default_attrs]) if config[:strong_default_attrs]
300
-
301
- res = aggregatee_instance(:new_record_form).create_or_update_record(form_data)
309
+ def new_record_form__netzke_submit(params)
310
+ res = aggregatee_instance(:new_record_form).netzke_submit(params)
302
311
 
303
312
  if res[:set_form_values]
304
313
  # successful creation
@@ -320,24 +329,21 @@ module Netzke
320
329
  end
321
330
  end
322
331
 
323
- def edit_form__submit(params)
324
- form_data = ActiveSupport::JSON.decode(params[:data])
325
- res = aggregatee_instance(:new_record_form).create_or_update_record(form_data)
332
+ def edit_form__netzke_submit(params)
333
+ res = aggregatee_instance(:edit_form).netzke_submit(params)
326
334
 
327
335
  check_for_positive_result(res)
328
336
 
329
337
  res.to_nifty_json
330
338
  end
331
339
 
332
- def multi_edit_form__submit(params)
333
- form_data = ActiveSupport::JSON.decode(params[:data])
334
- form_instance = aggregatee_instance(:new_record_form)
335
-
336
- ids = ActiveSupport::JSON.decode(params[:ids])
340
+ def multi_edit_form__netzke_submit(params)
341
+ ids = ActiveSupport::JSON.decode(params.delete(:ids))
337
342
 
338
343
  res = {}
339
344
  ids.each do |id|
340
- res = form_instance.create_or_update_record(form_data.merge("id" => id))
345
+ form_instance = aggregatee_instance(:edit_form, :record => data_class.find(id))
346
+ res = form_instance.netzke_submit(params)
341
347
  break if !res[:set_form_values]
342
348
  end
343
349