netzke-basepack 0.3.10 → 0.4.0
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/CHANGELOG +10 -0
- data/Manifest +12 -16
- data/Rakefile +1 -1
- data/TODO +3 -1
- data/autotest/discover.rb +3 -0
- data/javascripts/basepack.js +680 -52
- data/lib/app/models/netzke_hash_record.rb +180 -0
- data/lib/app/models/netzke_layout_item.rb +11 -0
- data/lib/netzke/ar_ext.rb +57 -34
- data/lib/netzke/border_layout_panel.rb +0 -1
- data/lib/netzke/db_fields.rb +4 -0
- data/lib/netzke/field_model.rb +131 -0
- data/lib/netzke/fields_configurator.rb +13 -5
- data/lib/netzke/fields_configurator_old.rb +62 -0
- data/lib/netzke/form_panel.rb +18 -24
- data/lib/netzke/form_panel_extras/interface.rb +20 -13
- data/lib/netzke/form_panel_extras/js_builder.rb +4 -1
- data/lib/netzke/grid_panel.rb +37 -40
- data/lib/netzke/grid_panel_extras/interface.rb +22 -18
- data/lib/netzke/grid_panel_extras/js_builder.rb +42 -13
- data/lib/netzke/property_editor_extras/helper_model.rb +2 -1
- data/lib/netzke/tab_panel.rb +15 -11
- data/netzke-basepack.gemspec +10 -10
- data/test/{accordion_panel_test.rb → unit/accordion_panel_test.rb} +0 -0
- data/test/{ar_ext_test.rb → unit/ar_ext_test.rb} +3 -9
- data/test/{grid_panel_test.rb → unit/grid_panel_test.rb} +0 -5
- data/test/{netzke_basepack_test.rb → unit/netzke_basepack_test.rb} +0 -0
- data/test/unit/netzke_hash_record_test.rb +52 -0
- data/test/unit/netzke_layout_item_test.rb +28 -0
- data/test/{tab_panel_test.rb → unit/tab_panel_test.rb} +0 -0
- metadata +30 -30
- data/generators/netzke_basepack/USAGE +0 -8
- data/generators/netzke_basepack/netzke_basepack_generator.rb +0 -8
- data/generators/netzke_form_panel/netzke_form_panel_generator.rb +0 -7
- data/generators/netzke_form_panel/templates/create_netzke_form_panel_fields.rb +0 -21
- data/generators/netzke_grid_panel/netzke_grid_panel_generator.rb +0 -7
- data/generators/netzke_grid_panel/templates/create_netzke_grid_panel_columns.rb +0 -24
- data/lib/app/models/netzke_form_panel_field.rb +0 -51
- data/lib/app/models/netzke_grid_panel_column.rb +0 -56
- data/lib/netzke/form_panel_extras/javascripts/xdatetime.js +0 -634
- data/test/app_root/db/migrate/20090102223811_create_netzke_grid_panel_columns.rb +0 -23
- data/test/border_layout_panel_test.rb +0 -25
@@ -9,9 +9,8 @@ module Netzke
|
|
9
9
|
def initialize(*args)
|
10
10
|
super
|
11
11
|
|
12
|
-
|
13
|
-
config[:data_class_name]
|
14
|
-
# config[:persistent_layout] = false
|
12
|
+
NetzkeLayoutItem.widget = config[:widget].id_name
|
13
|
+
config[:data_class_name] = "NetzkeLayoutItem"
|
15
14
|
end
|
16
15
|
|
17
16
|
def initial_config
|
@@ -53,10 +52,19 @@ module Netzke
|
|
53
52
|
end
|
54
53
|
|
55
54
|
def load_defaults(params)
|
56
|
-
|
57
|
-
config[:
|
55
|
+
persistent_config.for_widget(config[:widget].id_name){ |p| p[:layout__columns] = config[:widget].default_db_fields }
|
56
|
+
# NetzkeLayoutItem.data = config[:widget].default_db_fields
|
58
57
|
{}
|
59
58
|
end
|
60
59
|
|
60
|
+
def default_db_fields_with_widget_change
|
61
|
+
NetzkeLayoutItem.widget = config[:widget].id_name
|
62
|
+
res = default_db_fields_without_widget_change
|
63
|
+
NetzkeLayoutItem.widget = id_name
|
64
|
+
res
|
65
|
+
end
|
66
|
+
|
67
|
+
alias_method_chain :default_db_fields, :widget_change
|
68
|
+
|
61
69
|
end
|
62
70
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Netzke
|
2
|
+
class FieldsConfigurator < GridPanel
|
3
|
+
interface :load_defaults
|
4
|
+
|
5
|
+
def self.js_base_class
|
6
|
+
GridPanel
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
|
12
|
+
config[:conditions] = {:layout_id => config[:layout].id}
|
13
|
+
config[:data_class_name] = config[:layout].items_class
|
14
|
+
# config[:persistent_layout] = false
|
15
|
+
end
|
16
|
+
|
17
|
+
def initial_config
|
18
|
+
super.recursive_merge({
|
19
|
+
:name => 'columns',
|
20
|
+
:widget_class_name => "GridPanel",
|
21
|
+
:ext_config => {:title => false}
|
22
|
+
})
|
23
|
+
end
|
24
|
+
|
25
|
+
def actions
|
26
|
+
super.merge(
|
27
|
+
:defaults => {:text => 'Restore defaults'}
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def bbar
|
32
|
+
super << "-" << "defaults"
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.js_extend_properties
|
36
|
+
super.merge({
|
37
|
+
:defaults => <<-JS.l,
|
38
|
+
function(){
|
39
|
+
Ext.Msg.confirm('Confirm', 'Are you sure?', function(btn){
|
40
|
+
if (btn == 'yes') {
|
41
|
+
Ext.Ajax.request({
|
42
|
+
url:this.initialConfig.interface.loadDefaults,
|
43
|
+
callback:function(){
|
44
|
+
this.store.reload();
|
45
|
+
},
|
46
|
+
scope:this
|
47
|
+
})
|
48
|
+
}
|
49
|
+
}, this);
|
50
|
+
}
|
51
|
+
JS
|
52
|
+
})
|
53
|
+
end
|
54
|
+
|
55
|
+
def load_defaults(params)
|
56
|
+
NetzkeLayout.destroy(config[:layout].id)
|
57
|
+
config[:data_class_name].constantize.create_layout_for_widget(parent.parent)
|
58
|
+
{}
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
data/lib/netzke/form_panel.rb
CHANGED
@@ -3,7 +3,6 @@ module Netzke
|
|
3
3
|
# Class-level configuration with defaults
|
4
4
|
def self.config
|
5
5
|
set_default_config({
|
6
|
-
:field_manager => "NetzkeFormPanelField",
|
7
6
|
})
|
8
7
|
end
|
9
8
|
|
@@ -12,9 +11,9 @@ module Netzke
|
|
12
11
|
include Netzke::DbFields # database field operations
|
13
12
|
|
14
13
|
# extra javascripts
|
15
|
-
js_include %w{ xcheckbox
|
14
|
+
js_include %w{ xcheckbox }.map{|js| "#{File.dirname(__FILE__)}/form_panel_extras/javascripts/#{js}.js"}
|
16
15
|
|
17
|
-
interface :submit, :load
|
16
|
+
interface :submit, :load, :get_cb_choices
|
18
17
|
|
19
18
|
def self.widget_type
|
20
19
|
:form
|
@@ -34,19 +33,18 @@ module Netzke
|
|
34
33
|
|
35
34
|
def configuration_widgets
|
36
35
|
res = []
|
36
|
+
|
37
37
|
res << {
|
38
38
|
:name => 'fields',
|
39
39
|
:widget_class_name => "FieldsConfigurator",
|
40
|
-
:ext_config => {:title => false},
|
41
40
|
:active => true,
|
42
|
-
:
|
43
|
-
:fields_for => :form
|
41
|
+
:widget => self
|
44
42
|
} if config[:persistent_layout]
|
45
43
|
|
46
44
|
res << {
|
47
45
|
:name => 'general',
|
48
46
|
:widget_class_name => "PropertyEditor",
|
49
|
-
:widget_name
|
47
|
+
:widget_name => id_name,
|
50
48
|
:ext_config => {:title => false}
|
51
49
|
}
|
52
50
|
|
@@ -67,35 +65,31 @@ module Netzke
|
|
67
65
|
persistent_config[:bottom_bar] ||= config[:bbar] == false ? nil : config[:bbar] || %w{ apply }
|
68
66
|
end
|
69
67
|
|
70
|
-
|
71
|
-
|
72
|
-
@fields ||=
|
73
|
-
if config[:persistent_layout] && layout_manager_class && field_manager_class
|
74
|
-
layout = layout_manager_class.by_widget(id_name)
|
75
|
-
layout ||= field_manager_class.create_layout_for_widget(self)
|
76
|
-
layout.items_arry_without_hidden
|
77
|
-
else
|
78
|
-
default_db_fields
|
79
|
-
end
|
68
|
+
def fields
|
69
|
+
@@fields ||= get_fields
|
80
70
|
end
|
81
71
|
|
82
72
|
# parameters used to instantiate the JS object
|
83
73
|
def js_config
|
84
74
|
res = super
|
85
|
-
|
86
|
-
res.merge!(:fields => get_fields || config[:fields]) # first try to get columns from DB, then from config
|
75
|
+
res.merge!(:fields => fields)
|
87
76
|
res.merge!(:data_class_name => config[:data_class_name])
|
88
|
-
res.merge!(:record_data => config[:record].to_array(
|
77
|
+
res.merge!(:record_data => config[:record].to_array(fields)) if config[:record]
|
89
78
|
res
|
90
79
|
end
|
91
80
|
|
92
81
|
protected
|
93
82
|
|
94
|
-
def
|
95
|
-
|
96
|
-
|
97
|
-
|
83
|
+
def get_fields
|
84
|
+
if config[:persistent_layout]
|
85
|
+
NetzkeLayoutItem.widget = id_name
|
86
|
+
NetzkeLayoutItem.data = default_db_fields if NetzkeLayoutItem.all.empty?
|
87
|
+
NetzkeLayoutItem.all
|
88
|
+
else
|
89
|
+
default_db_fields
|
90
|
+
end.map{ |r| r.reject{ |k,v| k == :id } }
|
98
91
|
end
|
92
|
+
|
99
93
|
|
100
94
|
# def available_permissions
|
101
95
|
# %w{ read update }
|
@@ -10,22 +10,20 @@ module Netzke
|
|
10
10
|
record = klass.find_by_id(params[:id])
|
11
11
|
success = true
|
12
12
|
|
13
|
-
if record.nil?
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
break
|
23
|
-
end
|
13
|
+
record = klass.new if record.nil?
|
14
|
+
|
15
|
+
params.each_pair do |k,v|
|
16
|
+
begin
|
17
|
+
record.send("#{k}=",v)
|
18
|
+
rescue StandardError => exc
|
19
|
+
flash :error => exc.message
|
20
|
+
success = false
|
21
|
+
break
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
27
25
|
if success && record.save
|
28
|
-
{:data => [record.to_array(
|
26
|
+
{:data => [record.to_array(fields)], :success => true}
|
29
27
|
else
|
30
28
|
# flash eventual errors
|
31
29
|
record.errors.each_full do |msg|
|
@@ -42,8 +40,17 @@ module Netzke
|
|
42
40
|
when "next" then record = klass.next(params[:id])
|
43
41
|
else record = klass.find(params[:id])
|
44
42
|
end
|
45
|
-
{:data => [record && record.to_array(
|
43
|
+
{:data => [record && record.to_array(fields)]}
|
44
|
+
end
|
45
|
+
|
46
|
+
# Return the choices for the column
|
47
|
+
def get_cb_choices(params)
|
48
|
+
column = params[:column]
|
49
|
+
query = params[:query]
|
50
|
+
|
51
|
+
{:data => config[:data_class_name].constantize.choices_for(column, query).map{|s| [s]}}
|
46
52
|
end
|
53
|
+
|
47
54
|
end
|
48
55
|
end
|
49
56
|
end
|
@@ -30,7 +30,10 @@ module Netzke
|
|
30
30
|
}
|
31
31
|
delete(field.extConfig);
|
32
32
|
Ext.apply(field, extConfig);
|
33
|
-
|
33
|
+
|
34
|
+
field.parentConfig = config;
|
35
|
+
field.fieldConfig = field;
|
36
|
+
}, this);
|
34
37
|
var Record = Ext.data.Record.create(recordFields);
|
35
38
|
this.reader = new Ext.data.RecordArrayReader({root:"data"}, Record);
|
36
39
|
JS
|
data/lib/netzke/grid_panel.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'searchlogic'
|
2
|
-
require "app/models/netzke_grid_panel_column"
|
3
2
|
|
4
3
|
module Netzke
|
5
4
|
#
|
@@ -16,11 +15,16 @@ module Netzke
|
|
16
15
|
# * properties and column configuration
|
17
16
|
#
|
18
17
|
class GridPanel < Base
|
19
|
-
# Class-level configuration
|
18
|
+
# Class-level configuration and its defaults
|
20
19
|
def self.config
|
21
20
|
set_default_config({
|
22
|
-
:
|
23
|
-
:
|
21
|
+
:enable_filters => true,
|
22
|
+
:config_tool_enabled_by_default => false,
|
23
|
+
:column_move_enabled_by_default => true,
|
24
|
+
:column_hide_enabled_by_default => true,
|
25
|
+
:column_resize_enabled_by_default => true,
|
26
|
+
:persistent_layout_enabled_by_default => true,
|
27
|
+
:persistent_config_enabled_by_default => true
|
24
28
|
})
|
25
29
|
end
|
26
30
|
|
@@ -42,7 +46,7 @@ module Netzke
|
|
42
46
|
|
43
47
|
# define connection points between client side and server side of GridPanel.
|
44
48
|
# See implementation of equally named methods in the GridPanelExtras::Interface module.
|
45
|
-
interface :get_data, :post_data, :delete_data, :resize_column, :move_column, :get_cb_choices
|
49
|
+
interface :get_data, :post_data, :delete_data, :resize_column, :move_column, :hide_column, :get_cb_choices
|
46
50
|
|
47
51
|
# widget type for DbFields
|
48
52
|
# TODO: ugly, rethink
|
@@ -50,27 +54,18 @@ module Netzke
|
|
50
54
|
:grid
|
51
55
|
end
|
52
56
|
|
53
|
-
def self.column_manager_class
|
54
|
-
config[:column_manager].constantize
|
55
|
-
rescue
|
56
|
-
nil
|
57
|
-
end
|
58
|
-
|
59
|
-
def column_manager_class
|
60
|
-
self.class.column_manager_class
|
61
|
-
end
|
62
|
-
|
63
57
|
# default instance-level configuration
|
64
58
|
def initial_config
|
65
59
|
{
|
66
60
|
:ext_config => {
|
67
|
-
:config_tool =>
|
68
|
-
:enable_column_filters =>
|
69
|
-
:enable_column_move =>
|
70
|
-
:
|
61
|
+
:config_tool => self.class.config[:config_tool_enabled_by_default],
|
62
|
+
:enable_column_filters => self.class.config[:enable_filters],
|
63
|
+
:enable_column_move => self.class.config[:column_move_enabled_by_default],
|
64
|
+
:enable_column_hide => self.class.config[:column_hide_enabled_by_default],
|
65
|
+
:enable_column_resize => self.class.config[:column_resize_enabled_by_default]
|
71
66
|
},
|
72
|
-
:persistent_layout =>
|
73
|
-
:persistent_config =>
|
67
|
+
:persistent_layout => self.class.config[:persistent_layout_enabled_by_default],
|
68
|
+
:persistent_config => self.class.config[:persistent_config_enabled_by_default]
|
74
69
|
}
|
75
70
|
end
|
76
71
|
|
@@ -83,48 +78,40 @@ module Netzke
|
|
83
78
|
res << {
|
84
79
|
:name => 'columns',
|
85
80
|
:widget_class_name => "FieldsConfigurator",
|
86
|
-
:ext_config => {:title => false},
|
87
81
|
:active => true,
|
88
|
-
:
|
82
|
+
:widget => self,
|
83
|
+
:persistent_layout => true
|
89
84
|
} if config[:persistent_layout]
|
90
85
|
|
91
86
|
res << {
|
92
87
|
:name => 'general',
|
93
88
|
:widget_class_name => "PropertyEditor",
|
94
|
-
:widget_name
|
89
|
+
:widget_name => id_name,
|
95
90
|
:ext_config => {:title => false}
|
96
91
|
}
|
97
92
|
|
98
93
|
res
|
99
94
|
end
|
100
95
|
|
101
|
-
# get columns from layout manager
|
102
|
-
def get_columns
|
103
|
-
@columns ||=
|
104
|
-
if config[:persistent_layout] && layout_manager_class && column_manager_class
|
105
|
-
layout = layout_manager_class.by_widget(id_name)
|
106
|
-
layout ||= column_manager_class.create_layout_for_widget(self)
|
107
|
-
layout.items_arry
|
108
|
-
else
|
109
|
-
default_db_fields
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
96
|
def tools
|
114
97
|
%w{ refresh }
|
115
98
|
end
|
116
99
|
|
117
100
|
def actions
|
118
|
-
{ :add => {:text => 'Add',
|
119
|
-
:edit => {:text => 'Edit',
|
120
|
-
:delete => {:text => 'Delete',
|
121
|
-
:apply => {:text => 'Apply',
|
101
|
+
{ :add => {:text => 'Add', :disabled => !@permissions[:create]},
|
102
|
+
:edit => {:text => 'Edit', :disabled => !@permissions[:update]},
|
103
|
+
:delete => {:text => 'Delete', :disabled => !@permissions[:delete]},
|
104
|
+
:apply => {:text => 'Apply', :disabled => !@permissions[:update] && !@permissions[:create]}
|
122
105
|
}
|
123
106
|
end
|
124
107
|
|
125
108
|
def bbar
|
126
109
|
persistent_config[:bottom_bar] ||= config[:bbar] == false ? nil : config[:bbar] || %w{ add edit apply delete }
|
127
110
|
end
|
111
|
+
|
112
|
+
def columns
|
113
|
+
@columns ||= get_columns
|
114
|
+
end
|
128
115
|
|
129
116
|
include ConfigurationTool # it will load aggregation with name :properties into a modal window
|
130
117
|
|
@@ -133,6 +120,16 @@ module Netzke
|
|
133
120
|
def available_permissions
|
134
121
|
%w(read update create delete)
|
135
122
|
end
|
123
|
+
|
124
|
+
def get_columns
|
125
|
+
if config[:persistent_layout]
|
126
|
+
NetzkeLayoutItem.widget = id_name
|
127
|
+
NetzkeLayoutItem.data = default_db_fields if NetzkeLayoutItem.all.empty?
|
128
|
+
NetzkeLayoutItem.all
|
129
|
+
else
|
130
|
+
default_db_fields
|
131
|
+
end
|
132
|
+
end
|
136
133
|
|
137
134
|
end
|
138
135
|
end
|
@@ -40,20 +40,35 @@ module Netzke
|
|
40
40
|
|
41
41
|
def resize_column(params)
|
42
42
|
raise "Called interface_resize_column while not configured to do so" unless config[:ext_config][:enable_column_resize]
|
43
|
-
if config[:persistent_layout]
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
if config[:persistent_layout]
|
44
|
+
NetzkeLayoutItem.widget = id_name
|
45
|
+
column = NetzkeLayoutItem.find(params[:index].to_i + 1)
|
46
|
+
column.width = params[:size].to_i
|
47
|
+
column.save
|
48
|
+
end
|
49
|
+
{}
|
50
|
+
end
|
51
|
+
|
52
|
+
def hide_column(params)
|
53
|
+
raise "Called interface_hide_column while not configured to do so" unless config[:ext_config][:enable_column_hide]
|
54
|
+
if config[:persistent_layout]
|
55
|
+
NetzkeLayoutItem.widget = id_name
|
56
|
+
column = NetzkeLayoutItem.find(params[:index].to_i + 1)
|
57
|
+
column.hidden = params[:hidden].to_b
|
58
|
+
column.save
|
47
59
|
end
|
48
60
|
{}
|
49
61
|
end
|
50
62
|
|
51
63
|
def move_column(params)
|
52
64
|
raise "Called interface_move_column while not configured to do so" unless config[:ext_config][:enable_column_move]
|
53
|
-
if config[:persistent_layout]
|
54
|
-
|
65
|
+
if config[:persistent_layout]
|
66
|
+
NetzkeLayoutItem.widget = id_name
|
67
|
+
NetzkeLayoutItem.move_item(params[:old_index].to_i, params[:new_index].to_i)
|
55
68
|
end
|
56
|
-
|
69
|
+
|
70
|
+
# provide the client side with the new columns order
|
71
|
+
{:columns => columns.map(&:name)}
|
57
72
|
end
|
58
73
|
|
59
74
|
# Return the choices for the column
|
@@ -117,19 +132,8 @@ module Netzke
|
|
117
132
|
|
118
133
|
raise ArgumentError, "No data_class_name specified for widget '#{config[:name]}'" if !config[:data_class_name]
|
119
134
|
records = config[:data_class_name].constantize.all(search_params.clone) # clone needed as searchlogic removes :conditions key from the hash
|
120
|
-
# output_array = []
|
121
|
-
columns = get_columns
|
122
135
|
output_array = records.map{|r| r.to_array(columns)}
|
123
136
|
|
124
|
-
# records.each do |r|
|
125
|
-
# r_array = []
|
126
|
-
# self.get_columns.each do |column|
|
127
|
-
# r_array << r.send(column[:name])
|
128
|
-
# end
|
129
|
-
# output_array << r_array
|
130
|
-
# output_array << r.to_array(columns)
|
131
|
-
# end
|
132
|
-
|
133
137
|
# add total_entries accessor to the result
|
134
138
|
class << output_array
|
135
139
|
attr :total_records, true
|