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.
- data/.gitignore +2 -1
- data/CHANGELOG.rdoc +13 -0
- data/README.rdoc +18 -9
- data/Rakefile +6 -7
- data/TODO.rdoc +4 -2
- data/javascripts/basepack.js +32 -1
- data/lib/app/models/netzke_auto_column.rb +2 -2
- data/lib/netzke-basepack.rb +2 -1
- data/lib/netzke/accordion_panel.rb +6 -4
- data/lib/netzke/basic_app.rb +222 -231
- data/lib/netzke/border_layout_panel.rb +4 -2
- data/lib/netzke/fields_configurator.rb +2 -2
- data/lib/netzke/form_panel.rb +6 -4
- data/lib/netzke/form_panel_api.rb +20 -16
- data/lib/netzke/form_panel_extras/javascripts/netzkefileupload.js +5 -0
- data/lib/netzke/form_panel_js.rb +26 -7
- data/lib/netzke/grid_panel.rb +31 -10
- data/lib/netzke/grid_panel_api.rb +46 -40
- data/lib/netzke/grid_panel_extras/record_form_window.rb +46 -0
- data/lib/netzke/grid_panel_js.rb +9 -32
- data/lib/netzke/property_editor.rb +1 -1
- data/lib/netzke/property_editor_extras/helper_model.rb +2 -6
- data/lib/netzke/tab_panel.rb +5 -4
- data/lib/netzke/table_editor.rb +1 -1
- data/lib/netzke/tree_panel.rb +1 -1
- data/lib/netzke/window.rb +77 -0
- data/lib/netzke/wrapper.rb +1 -1
- data/test/unit/accordion_panel_test.rb +1 -1
- data/test/unit/grid_panel_test.rb +11 -2
- data/test/unit/tab_panel_test.rb +1 -1
- metadata +8 -6
- data/VERSION +0 -1
@@ -49,7 +49,8 @@ module Netzke
|
|
49
49
|
var regionConfig = this.regions[r] || {};
|
50
50
|
regionConfig.layout = 'fit';
|
51
51
|
regionConfig.region = r;
|
52
|
-
|
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
|
-
|
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
|
-
:
|
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
|
73
|
+
{:load_store_data => get_data}
|
74
74
|
end
|
75
75
|
|
76
76
|
def commit(params)
|
data/lib/netzke/form_panel.rb
CHANGED
@@ -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 :
|
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.
|
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 '#{
|
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
|
5
|
-
|
6
|
-
|
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(
|
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
|
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
|
-
|
29
|
-
|
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
|
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
|
data/lib/netzke/form_panel_js.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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.
|
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.
|
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.
|
109
|
+
var values = this.getForm().getValues();
|
110
110
|
for (var k in values) {
|
111
111
|
if (values[k] == "") {delete values[k]}
|
112
112
|
}
|
113
|
-
|
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
|
data/lib/netzke/grid_panel.rb
CHANGED
@@ -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]
|
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 #{
|
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,
|
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
|
205
|
+
def default_config
|
206
206
|
res = super
|
207
207
|
|
208
|
-
res[:ext_config][:bbar] = default_bbar
|
209
|
-
res[:ext_config][: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
|
-
|
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] &&
|
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
|
-
|
59
|
-
|
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
|
-
#
|
243
|
-
#
|
244
|
-
#
|
245
|
-
#
|
246
|
-
#
|
247
|
-
#
|
248
|
-
#
|
249
|
-
#
|
250
|
-
#
|
251
|
-
#
|
252
|
-
#
|
253
|
-
#
|
254
|
-
#
|
255
|
-
#
|
256
|
-
#
|
257
|
-
#
|
258
|
-
#
|
259
|
-
#
|
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.
|
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
|
296
|
-
|
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
|
324
|
-
|
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
|
333
|
-
|
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
|
-
|
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
|
|