netzke-basepack 0.5.14 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -2
- data/CHANGELOG.rdoc +15 -0
- data/README.rdoc +45 -50
- data/Rakefile +8 -8
- data/TODO.rdoc +1 -6
- data/app/components/netzke/basepack/accordion_panel.rb +37 -0
- data/app/components/netzke/basepack/basic_app.rb +267 -0
- data/{lib/netzke → app/components/netzke/basepack}/basic_app/statusbar_ext.js +0 -0
- data/app/components/netzke/basepack/border_layout_panel.rb +39 -0
- data/app/components/netzke/basepack/form_panel.rb +102 -0
- data/app/components/netzke/basepack/form_panel/fields.rb +206 -0
- data/{lib/netzke → app/components/netzke/basepack}/form_panel/javascripts/netzkefileupload.js +0 -0
- data/app/components/netzke/basepack/form_panel/javascripts/pre.js +76 -0
- data/{lib/netzke → app/components/netzke/basepack}/form_panel/javascripts/xcheckbox.js +0 -0
- data/app/components/netzke/basepack/form_panel/services.rb +99 -0
- data/app/components/netzke/basepack/grid_panel.rb +374 -0
- data/app/components/netzke/basepack/grid_panel/columns.rb +233 -0
- data/app/components/netzke/basepack/grid_panel/javascript.rb +69 -0
- data/app/components/netzke/basepack/grid_panel/javascripts/advanced_search.js +96 -0
- data/{lib/netzke → app/components/netzke/basepack}/grid_panel/javascripts/edit_in_form.js +5 -4
- data/{lib/netzke/grid_panel/javascripts/grid_panel_pre.js → app/components/netzke/basepack/grid_panel/javascripts/pre.js} +17 -37
- data/{lib/netzke → app/components/netzke/basepack}/grid_panel/javascripts/rows-dd.js +0 -0
- data/app/components/netzke/basepack/grid_panel/multi_edit_form.rb +16 -0
- data/app/components/netzke/basepack/grid_panel/record_form_window.rb +36 -0
- data/app/components/netzke/basepack/grid_panel/search_window.rb +56 -0
- data/app/components/netzke/basepack/grid_panel/services.rb +356 -0
- data/app/components/netzke/basepack/panel.rb +11 -0
- data/app/components/netzke/basepack/search_panel.rb +59 -0
- data/app/components/netzke/basepack/tab_panel.rb +32 -0
- data/app/components/netzke/basepack/window.rb +73 -0
- data/app/components/netzke/basepack/wrapper.rb +28 -0
- data/{lib/app → app}/models/netzke_field_list.rb +1 -1
- data/{lib/app → app}/models/netzke_model_attr_list.rb +0 -0
- data/{lib/app → app}/models/netzke_persistent_array_auto_model.rb +0 -0
- data/config/database.yml +35 -0
- data/features/accordion_panel.feature +15 -0
- data/features/basic_app.feature +12 -0
- data/features/form_panel.feature +40 -0
- data/features/grid_panel.feature +62 -0
- data/features/search_in_grid.feature +35 -0
- data/features/simple_panel.feature +15 -0
- data/features/step_definitions/accordion_steps.rb +9 -0
- data/features/step_definitions/generic_steps.rb +15 -0
- data/features/step_definitions/grid_panel_steps.rb +26 -0
- data/features/step_definitions/pickle_steps.rb +100 -0
- data/features/step_definitions/web_steps.rb +219 -0
- data/features/support/env.rb +66 -0
- data/features/support/paths.rb +59 -0
- data/features/support/pickle.rb +25 -0
- data/features/tab_panel.feature +15 -0
- data/features/window.feature +11 -0
- data/from_05_to_06.rdoc +2 -0
- data/javascripts/basepack.js +54 -2
- data/lib/netzke-basepack.rb +38 -25
- data/lib/netzke/active_record.rb +12 -4
- data/lib/netzke/active_record/attributes.rb +60 -5
- data/lib/netzke/active_record/combobox_options.rb +3 -2
- data/lib/netzke/active_record/relation_extensions.rb +35 -0
- data/lib/netzke/basepack.rb +27 -0
- data/lib/netzke/basepack/version.rb +11 -0
- data/lib/netzke/basepack/wrap_lazy_loaded.rb +26 -0
- data/lib/netzke/data_accessor.rb +60 -32
- data/lib/netzke/fields_configurator.rb +5 -9
- data/lib/netzke/masquerade_selector.rb +1 -1
- data/locale/en.yml +16 -0
- data/netzke-basepack.gemspec +298 -0
- data/spec/active_record/attributes_spec.rb +14 -0
- data/spec/active_record/relation_extensions_spec.rb +44 -0
- data/spec/components/form_panel_spec.rb +70 -0
- data/spec/components/grid_panel_spec.rb +10 -0
- data/spec/factories.rb +9 -0
- data/spec/spec_helper.rb +35 -0
- data/test/rails_app/.gitignore +4 -0
- data/test/rails_app/Gemfile +32 -0
- data/test/rails_app/Gemfile.lock +171 -0
- data/test/rails_app/README +256 -0
- data/test/rails_app/Rakefile +7 -0
- data/test/rails_app/app/components/generic_user_form.rb +12 -0
- data/test/rails_app/app/components/simple_accordion.rb +11 -0
- data/test/rails_app/app/components/simple_basic_app.rb +32 -0
- data/test/rails_app/app/components/simple_panel.rb +17 -0
- data/test/rails_app/app/components/simple_tab_panel.rb +11 -0
- data/test/rails_app/app/components/simple_wrapper.rb +7 -0
- data/test/rails_app/app/components/some_border_layout.rb +24 -0
- data/test/rails_app/app/components/some_search_panel.rb +34 -0
- data/test/rails_app/app/components/some_tab_panel.rb +15 -0
- data/test/rails_app/app/components/user_form.rb +21 -0
- data/test/rails_app/app/components/user_form_with_default_fields.rb +8 -0
- data/test/rails_app/app/components/user_grid.rb +4 -0
- data/test/rails_app/app/components/window_component_loader.rb +17 -0
- data/test/{app_root/app/controllers/application.rb → rails_app/app/controllers/application_controller.rb} +1 -0
- data/test/rails_app/app/controllers/components_controller.rb +6 -0
- data/test/rails_app/app/controllers/welcome_controller.rb +5 -0
- data/test/rails_app/app/helpers/application_helper.rb +2 -0
- data/test/{app_root → rails_app}/app/models/role.rb +0 -0
- data/test/rails_app/app/models/user.rb +6 -0
- data/test/rails_app/app/presenters/forms/generic_user.rb +6 -0
- data/test/rails_app/app/views/layouts/application.html.erb +13 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/config/application.rb +45 -0
- data/test/rails_app/config/boot.rb +13 -0
- data/test/rails_app/config/database.yml +35 -0
- data/test/rails_app/config/environment.rb +6 -0
- data/test/rails_app/config/environments/development.rb +22 -0
- data/test/rails_app/config/environments/production.rb +49 -0
- data/test/rails_app/config/environments/test.rb +35 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +8 -0
- data/test/rails_app/config/initializers/inflections.rb +10 -0
- data/test/rails_app/config/initializers/mime_types.rb +5 -0
- data/test/rails_app/config/initializers/netzke.rb +7 -0
- data/test/rails_app/config/initializers/secret_token.rb +7 -0
- data/test/rails_app/config/initializers/session_store.rb +8 -0
- data/test/rails_app/config/locales/es.yml +12 -0
- data/test/rails_app/config/routes.rb +65 -0
- data/test/rails_app/db/development_structure.sql +39 -0
- data/test/{app_root/db/migrate/20081222035855_create_netzke_preferences.rb → rails_app/db/migrate/20100905214933_create_netzke_preferences.rb} +2 -4
- data/test/{app_root/db/migrate/20090423222114_create_users.rb → rails_app/db/migrate/20100914104207_create_users.rb} +4 -1
- data/test/{app_root/db/migrate/20090423214303_create_roles.rb → rails_app/db/migrate/20100914104236_create_roles.rb} +2 -0
- data/test/rails_app/db/schema.rb +38 -0
- data/test/rails_app/db/seeds.rb +20 -0
- data/test/rails_app/features/support/paths.rb +47 -0
- data/test/{app_root/config/environments/in_memory.rb → rails_app/lib/tasks/.gitkeep} +0 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/{app_root/config/environments/mysql.rb → rails_app/public/favicon.ico} +0 -0
- data/test/rails_app/public/images/header-deco.gif +0 -0
- data/test/rails_app/public/images/rails.png +0 -0
- data/test/rails_app/public/javascripts/application.js +2 -0
- data/test/rails_app/public/javascripts/controls.js +965 -0
- data/test/rails_app/public/javascripts/dragdrop.js +974 -0
- data/test/rails_app/public/javascripts/effects.js +1123 -0
- data/test/rails_app/public/javascripts/prototype.js +6001 -0
- data/test/rails_app/public/javascripts/rails.js +175 -0
- data/test/rails_app/public/robots.txt +5 -0
- data/test/{app_root/config/environments/postgresql.rb → rails_app/public/stylesheets/.gitkeep} +0 -0
- data/test/rails_app/script/rails +6 -0
- data/test/rails_app/spec/models/role_spec.rb +5 -0
- data/test/rails_app/spec/models/user_spec.rb +5 -0
- data/test/rails_app/test/performance/browsing_test.rb +9 -0
- data/test/rails_app/test/test_helper.rb +13 -0
- data/test/{app_root/config/environments/sqlite.rb → rails_app/vendor/plugins/.gitkeep} +0 -0
- data/test/unit/accordion_panel_test.rb +3 -3
- data/test/unit/active_record_basepack_test.rb +4 -4
- data/test/unit/tab_panel_test.rb +4 -4
- metadata +199 -119
- data/lib/netzke/accordion_panel.rb +0 -115
- data/lib/netzke/active_record/data_accessor.rb +0 -25
- data/lib/netzke/attributes_configurator.rb +0 -195
- data/lib/netzke/basic_app.rb +0 -368
- data/lib/netzke/border_layout_panel.rb +0 -130
- data/lib/netzke/configuration_panel.rb +0 -24
- data/lib/netzke/form_panel.rb +0 -138
- data/lib/netzke/form_panel/form_panel_api.rb +0 -81
- data/lib/netzke/form_panel/form_panel_fields.rb +0 -149
- data/lib/netzke/form_panel/form_panel_js.rb +0 -163
- data/lib/netzke/grid_panel.rb +0 -367
- data/lib/netzke/grid_panel/grid_panel_api.rb +0 -364
- data/lib/netzke/grid_panel/grid_panel_columns.rb +0 -232
- data/lib/netzke/grid_panel/grid_panel_js.rb +0 -73
- data/lib/netzke/grid_panel/javascripts/advanced_search.js +0 -65
- data/lib/netzke/grid_panel/multi_edit_form.rb +0 -14
- data/lib/netzke/grid_panel/record_form_window.rb +0 -50
- data/lib/netzke/panel.rb +0 -11
- data/lib/netzke/plugins/configuration_tool.rb +0 -121
- data/lib/netzke/property_editor.rb +0 -111
- data/lib/netzke/property_editor/helper_model.rb +0 -122
- data/lib/netzke/search_panel.rb +0 -199
- data/lib/netzke/tab_panel.rb +0 -174
- data/lib/netzke/table_editor.rb +0 -118
- data/lib/netzke/tree_panel.rb +0 -25
- data/lib/netzke/window.rb +0 -82
- data/lib/netzke/wrapper.rb +0 -42
- data/test/app_root/app/models/book.rb +0 -9
- data/test/app_root/app/models/category.rb +0 -2
- data/test/app_root/app/models/city.rb +0 -3
- data/test/app_root/app/models/continent.rb +0 -2
- data/test/app_root/app/models/country.rb +0 -3
- data/test/app_root/app/models/genre.rb +0 -3
- data/test/app_root/app/models/user.rb +0 -3
- data/test/app_root/config/boot.rb +0 -114
- data/test/app_root/config/database.yml +0 -21
- data/test/app_root/config/environment.rb +0 -14
- data/test/app_root/config/environments/sqlite3.rb +0 -0
- data/test/app_root/config/routes.rb +0 -4
- data/test/app_root/db/migrate/20081222033343_create_books.rb +0 -15
- data/test/app_root/db/migrate/20081222033440_create_genres.rb +0 -15
- data/test/app_root/db/migrate/20081223024935_create_categories.rb +0 -13
- data/test/app_root/db/migrate/20081223025635_create_countries.rb +0 -14
- data/test/app_root/db/migrate/20081223025653_create_continents.rb +0 -13
- data/test/app_root/db/migrate/20081223025732_create_cities.rb +0 -15
- data/test/app_root/db/migrate/20090102223630_create_netzke_field_lists.rb +0 -18
- data/test/app_root/script/console +0 -7
- data/test/app_root/vendor/plugins/acts_as_list/README +0 -23
- data/test/app_root/vendor/plugins/acts_as_list/init.rb +0 -3
- data/test/app_root/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +0 -256
data/lib/netzke-basepack.rb
CHANGED
@@ -1,44 +1,57 @@
|
|
1
1
|
# External dependencies
|
2
|
-
require 'active_support'
|
3
2
|
require 'netzke-core'
|
3
|
+
require 'active_support/dependencies'
|
4
|
+
|
5
|
+
# path = File.dirname(__FILE__)
|
6
|
+
# $LOAD_PATH << path
|
7
|
+
|
8
|
+
# Make components auto-loadable
|
9
|
+
ActiveSupport::Dependencies.autoload_paths << File.dirname(__FILE__)
|
10
|
+
|
11
|
+
require 'netzke/basepack'
|
12
|
+
|
13
|
+
module Netzke
|
14
|
+
autoload :Ext, 'ext'
|
15
|
+
|
16
|
+
module Basepack
|
17
|
+
class Engine < Rails::Engine
|
18
|
+
config.after_initialize do
|
19
|
+
I18n.load_path << File.dirname(__FILE__) + '/../locale/en.yml'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
4
25
|
|
5
|
-
|
6
|
-
require 'netzke/ext'
|
7
|
-
require 'netzke/active_record'
|
26
|
+
Netzke::Basepack.init
|
8
27
|
|
9
|
-
#
|
10
|
-
|
11
|
-
ActiveSupport::Dependencies.load_paths << path
|
28
|
+
# Netzke::Core.javascripts << "#{File.dirname(__FILE__)}/../../javascripts/basepack.js"
|
29
|
+
# Netzke::Core.stylesheets << "#{File.dirname(__FILE__)}/../../stylesheets/basepack.css"
|
12
30
|
|
13
31
|
# Make this plugin auto-reloadable for easier development
|
14
|
-
ActiveSupport::Dependencies.
|
32
|
+
# ActiveSupport::Dependencies.autoload_once_paths.delete(path)
|
15
33
|
|
16
34
|
# Make gem's models auto-loadable
|
17
|
-
%w{ models }.each do |dir|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
# Include javascript & styles required by all basepack
|
35
|
+
# %w{ models }.each do |dir|
|
36
|
+
# path = File.join(File.dirname(__FILE__), 'app', dir)
|
37
|
+
# $LOAD_PATH << path
|
38
|
+
# ActiveSupport::Dependencies.autoload_paths << path
|
39
|
+
# ActiveSupport::Dependencies.autoload_once_paths.delete(path)
|
40
|
+
# end
|
41
|
+
|
42
|
+
# Include javascript & styles required by all basepack components.
|
25
43
|
# These files will get loaded at the initial load of the framework (along with Ext and Netzke-core).
|
26
|
-
Netzke::Base.config[:javascripts] << "#{File.dirname(__FILE__)}/../javascripts/basepack.js"
|
27
|
-
Netzke::Base.config[:stylesheets] << "#{File.dirname(__FILE__)}/../stylesheets/basepack.css"
|
28
44
|
|
29
45
|
|
30
|
-
# FIXME: The following stylesheet inclusion doesn't *really* belong here, being
|
46
|
+
# FIXME: The following stylesheet inclusion doesn't *really* belong here, being component-specific,
|
31
47
|
# but I don't see any other solution for now. The problem is that these stylesheets come straight from
|
32
48
|
# Ext JS, having *relative* URLs to the images, which doesn't allow us to include them all together as those stylesheets
|
33
49
|
# from Netzke.
|
34
50
|
|
35
51
|
# Used by FormPanel (file upload field)
|
36
|
-
Netzke::Base.config[:external_css] << "/extjs/examples/ux/fileuploadfield/css/fileuploadfield"
|
52
|
+
# Netzke::Base.config[:external_css] << "/extjs/examples/ux/fileuploadfield/css/fileuploadfield"
|
37
53
|
|
38
54
|
# Used by GridPanel
|
39
|
-
Netzke::Base.config[:external_css] << "/extjs/examples/ux/gridfilters/css/RangeMenu"
|
40
|
-
Netzke::Base.config[:external_css] << "/extjs/examples/ux/gridfilters/css/GridFilters"
|
55
|
+
# Netzke::Base.config[:external_css] << "/extjs/examples/ux/gridfilters/css/RangeMenu"
|
56
|
+
# Netzke::Base.config[:external_css] << "/extjs/examples/ux/gridfilters/css/GridFilters"
|
41
57
|
|
42
|
-
if Netzke::Base.config[:with_icons].nil? && defined?(RAILS_ROOT)
|
43
|
-
Netzke::Base.config[:with_icons] = File.exists?("#{RAILS_ROOT}/public#{Netzke::Base.config[:icons_uri]}")
|
44
|
-
end
|
data/lib/netzke/active_record.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
require 'netzke/active_record/association_attributes'
|
2
|
-
require 'netzke/active_record/attributes'
|
3
|
-
require 'netzke/active_record/combobox_options'
|
4
|
-
require 'netzke/active_record/data_accessor'
|
1
|
+
# require 'netzke/active_record/association_attributes'
|
2
|
+
# require 'netzke/active_record/attributes'
|
3
|
+
# require 'netzke/active_record/combobox_options'
|
4
|
+
# require 'netzke/active_record/data_accessor'
|
5
|
+
|
6
|
+
module Netzke::ActiveRecord
|
7
|
+
|
8
|
+
end
|
5
9
|
|
6
10
|
# Extend ActiveRecord
|
7
11
|
ActiveRecord::Base.class_eval do
|
@@ -9,3 +13,7 @@ ActiveRecord::Base.class_eval do
|
|
9
13
|
include ::Netzke::ActiveRecord::Attributes
|
10
14
|
include ::Netzke::ActiveRecord::ComboboxOptions
|
11
15
|
end
|
16
|
+
|
17
|
+
ActiveRecord::Relation.class_eval do
|
18
|
+
include ::Netzke::ActiveRecord::RelationExtensions
|
19
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Netzke::ActiveRecord::Attributes
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
2
4
|
module ClassMethods
|
3
|
-
|
4
5
|
# Define or configure an attribute.
|
5
6
|
# Example:
|
6
7
|
# netzke_attribute :recent, :type => :boolean, :read_only => true
|
@@ -13,7 +14,13 @@ module Netzke::ActiveRecord::Attributes
|
|
13
14
|
if existing
|
14
15
|
existing.merge!(options)
|
15
16
|
else
|
16
|
-
|
17
|
+
attr_config = {:name => name}.merge(options)
|
18
|
+
# if primary_key, insert in front, otherwise append
|
19
|
+
if name == self.primary_key
|
20
|
+
declared_attrs.insert(0, attr_config)
|
21
|
+
else
|
22
|
+
declared_attrs << {:name => name}.merge(options)
|
23
|
+
end
|
17
24
|
end
|
18
25
|
write_inheritable_attribute(:netzke_declared_attributes, declared_attrs)
|
19
26
|
end
|
@@ -37,10 +44,20 @@ module Netzke::ActiveRecord::Attributes
|
|
37
44
|
|
38
45
|
# Returns the attributes that will be picked up by grids and forms.
|
39
46
|
def netzke_attributes
|
40
|
-
exposed =
|
47
|
+
exposed = netzke_exposed_attributes
|
41
48
|
exposed ? netzke_attrs_in_forced_order(exposed) : netzke_attrs_in_natural_order
|
42
49
|
end
|
43
50
|
|
51
|
+
def netzke_exposed_attributes
|
52
|
+
exposed = read_inheritable_attribute(:netzke_exposed_attributes)
|
53
|
+
if exposed && !exposed.include?(self.primary_key)
|
54
|
+
# automatically declare primary key as a netzke attribute
|
55
|
+
netzke_attribute(self.primary_key)
|
56
|
+
exposed.insert(0, self.primary_key)
|
57
|
+
end
|
58
|
+
exposed
|
59
|
+
end
|
60
|
+
|
44
61
|
private
|
45
62
|
def netzke_declared_attributes
|
46
63
|
read_inheritable_attribute(:netzke_declared_attributes) || []
|
@@ -76,6 +93,7 @@ module Netzke::ActiveRecord::Attributes
|
|
76
93
|
def netzke_attrs_in_natural_order
|
77
94
|
(
|
78
95
|
declared_attrs = netzke_declared_attributes
|
96
|
+
|
79
97
|
column_names.map do |name|
|
80
98
|
c = {:name => name, :attr_type => columns_hash[name].type}
|
81
99
|
|
@@ -108,7 +126,44 @@ module Netzke::ActiveRecord::Attributes
|
|
108
126
|
|
109
127
|
end
|
110
128
|
|
111
|
-
|
112
|
-
|
129
|
+
# Transforms a record to array of values according to the passed attributes
|
130
|
+
def to_array(attributes)
|
131
|
+
res = []
|
132
|
+
for a in attributes
|
133
|
+
begin
|
134
|
+
next if a[:included] == false
|
135
|
+
v = send(a[:name])
|
136
|
+
# a work-around for to_json not taking the current timezone into account when serializing ActiveSupport::TimeWithZone
|
137
|
+
v = v.to_datetime.to_s(:db) if v.is_a?(ActiveSupport::TimeWithZone)
|
138
|
+
res << v
|
139
|
+
rescue NoMethodError
|
140
|
+
# So that we don't crash at a badly configured column
|
141
|
+
res << "UNDEF"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
res
|
145
|
+
end
|
146
|
+
|
147
|
+
# Accepts both hash and array of attributes
|
148
|
+
def to_hash(attributes)
|
149
|
+
res = {}
|
150
|
+
for a in (attributes.is_a?(Hash) ? attributes.values : attributes)
|
151
|
+
next if a[:included] == false
|
152
|
+
res[a[:name].to_sym] = self.value_for_attribute(a)
|
153
|
+
end
|
154
|
+
res
|
113
155
|
end
|
156
|
+
|
157
|
+
def value_for_attribute(a)
|
158
|
+
begin
|
159
|
+
v = send(a[:name])
|
160
|
+
# a work-around for to_json not taking the current timezone into account when serializing ActiveSupport::TimeWithZone
|
161
|
+
v = v.to_datetime.to_s(:db) if v.is_a?(ActiveSupport::TimeWithZone)
|
162
|
+
v
|
163
|
+
rescue NoMethodError
|
164
|
+
# So that we don't crash at a badly configured column
|
165
|
+
"UNDEF"
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
114
169
|
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module Netzke::ActiveRecord::ComboboxOptions
|
2
2
|
module ClassMethods
|
3
|
-
|
4
|
-
def
|
3
|
+
|
4
|
+
def netzke_combo_options_for(column, query = "")
|
5
5
|
records = query.empty? ? find_by_sql("select distinct #{column} from #{table_name}") : find_by_sql("select distinct #{column} from #{table_name} where #{column} like '#{query}%'")
|
6
6
|
records.map{|r| r.send(column)}
|
7
7
|
end
|
8
|
+
|
8
9
|
end
|
9
10
|
|
10
11
|
def self.included(receiver)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Netzke
|
2
|
+
module ActiveRecord
|
3
|
+
module RelationExtensions
|
4
|
+
|
5
|
+
def extend_with(*params)
|
6
|
+
scope = params.shift
|
7
|
+
case scope.class.name
|
8
|
+
when "Symbol" # model's scope
|
9
|
+
self.send(scope, *params)
|
10
|
+
when "String" # SQL query or SQL query with params (e.g. ["created_at < ?", 1.day.ago])
|
11
|
+
params.empty? ? self.where(scope) : self.where([scope, *params])
|
12
|
+
when "Array"
|
13
|
+
self.extend_with(*scope)
|
14
|
+
when "Hash" # conditions hash
|
15
|
+
self.where(scope)
|
16
|
+
when "Proc" # receives a relation, must return a relation
|
17
|
+
scope.call(self)
|
18
|
+
else
|
19
|
+
raise ArgumentError, "Wrong parameter type for ActiveRecord::Relation#extend_with"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Non-destructively extends itself whith a hash of double-underscore'd conditions,
|
24
|
+
# where the last part "__" is MetaWhere operator (which is required), e.g.:
|
25
|
+
# {:role__name__like => "%admin"}
|
26
|
+
def extend_with_netzke_conditions(cond)
|
27
|
+
cond.each_pair.inject(self) do |r, (k,v)|
|
28
|
+
assoc, method, *operator = k.to_s.split("__")
|
29
|
+
operator.empty? ? r.where(assoc.to_sym.send(method) => v) : r.where(assoc.to_sym => {method.to_sym.send(operator.last) => v}).joins(assoc.to_sym)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'netzke/basepack/version'
|
2
|
+
require 'netzke/active_record'
|
3
|
+
|
4
|
+
module Netzke
|
5
|
+
module Basepack
|
6
|
+
mattr_accessor :with_icons
|
7
|
+
|
8
|
+
mattr_accessor :icons_uri
|
9
|
+
|
10
|
+
class << self
|
11
|
+
# Called from netzke-basepack.rb
|
12
|
+
def init
|
13
|
+
Netzke::Core.javascripts << "#{File.dirname(__FILE__)}/../../javascripts/basepack.js"
|
14
|
+
Netzke::Core.stylesheets << "#{File.dirname(__FILE__)}/../../stylesheets/basepack.css"
|
15
|
+
end
|
16
|
+
|
17
|
+
# Use it to confirure Basepack in the initializers, e.g.:
|
18
|
+
#
|
19
|
+
# Netzke::Basepack.setup do |config|
|
20
|
+
# config.icons_uri = "/images/famfamfam/icons"
|
21
|
+
# end
|
22
|
+
def setup
|
23
|
+
yield self
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Netzke
|
2
|
+
module Basepack
|
3
|
+
# Include this module into your component component class when you want lazy-loaded component in config to be auto-replaced with
|
4
|
+
# a panel with the 'fit' layout, and a property wrappedComponent set to the name of the original component.
|
5
|
+
# Used, for instance, in TabPanel and AccordionPanel to dynamically load components on expanding a panel or clicking
|
6
|
+
# a tab.
|
7
|
+
module WrapLazyLoaded
|
8
|
+
def items
|
9
|
+
orig = super.dup
|
10
|
+
orig.each do |item|
|
11
|
+
wrapped_component = components[item[:component]]
|
12
|
+
# When a nested component with lazy loading is detected, it gets replaced with a 'fit' panel,
|
13
|
+
# into which later the component itself is dynamically loaded on request.
|
14
|
+
if wrapped_component && wrapped_component[:lazy_loading]
|
15
|
+
item.replace({
|
16
|
+
:layout => 'fit',
|
17
|
+
:wrapped_component => wrapped_component[:name],
|
18
|
+
:title => wrapped_component[:title] || wrapped_component[:name]
|
19
|
+
})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
orig
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/netzke/data_accessor.rb
CHANGED
@@ -1,62 +1,67 @@
|
|
1
|
-
require
|
2
|
-
require "searchlogic"
|
1
|
+
require 'netzke/active_record'
|
3
2
|
|
4
3
|
module Netzke
|
5
|
-
# This module is included into such data-driven
|
4
|
+
# This module is included into such data-driven components as GridPanel, FormPanel, etc.
|
6
5
|
module DataAccessor
|
7
|
-
# This method should be called from the constructor of the widget.
|
8
|
-
def apply_helpers
|
9
|
-
# Generic extensions to the data model
|
10
|
-
if data_class # because some widgets, like FormPanel, may have it optional
|
11
|
-
data_class.send(:include, Netzke::ActiveRecord::DataAccessor) if !data_class.include?(Netzke::ActiveRecord::DataAccessor)
|
12
|
-
end
|
13
|
-
end
|
14
6
|
|
15
7
|
# Returns options for comboboxes in grids/forms
|
16
8
|
def combobox_options_for_column(column, method_options = {})
|
9
|
+
query = method_options[:query]
|
10
|
+
|
17
11
|
# First, check if we have options for this column defined in persistent storage
|
18
12
|
options = column[:combobox_options] && column[:combobox_options].split("\n")
|
19
13
|
if options
|
20
|
-
|
14
|
+
query ? options.select{ |o| o.index(/^#{query}/) }.map{ |el| [el] } : options
|
21
15
|
else
|
22
16
|
assoc, assoc_method = assoc_and_assoc_method_for_column(column)
|
23
17
|
|
24
18
|
if assoc
|
25
19
|
# Options for an asssociation attribute
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
method_options[:scopes] && method_options[:scopes].each do |s|
|
31
|
-
if s.is_a?(Array)
|
32
|
-
scope_name, *args = s
|
33
|
-
search.send(scope_name, *args)
|
34
|
-
else
|
35
|
-
search.send(s, true)
|
36
|
-
end
|
37
|
-
end
|
20
|
+
|
21
|
+
relation = assoc.klass.where({})
|
22
|
+
|
23
|
+
relation = relation.extend_with(method_options[:scope]) if method_options[:scope]
|
38
24
|
|
39
25
|
if assoc.klass.column_names.include?(assoc_method)
|
40
26
|
# apply query
|
41
|
-
|
42
|
-
|
27
|
+
relation = relation.where(:"#{assoc_method}".like => "#{query}%") if query.present?
|
28
|
+
relation.all.map{ |r| [r.send(assoc_method)] }
|
43
29
|
else
|
44
|
-
|
30
|
+
relation.all.map{ |r| r.send(assoc_method) }.select{ |value| value =~ /^#{query}/ }.map{ |v| [v] }
|
45
31
|
end
|
46
32
|
|
47
33
|
else
|
48
34
|
# Options for a non-association attribute
|
49
|
-
data_class.
|
35
|
+
res=data_class.netzke_combo_options_for(column[:name], method_options)
|
36
|
+
|
37
|
+
# ensure it is an array-in-array, as Ext will fail otherwise
|
38
|
+
raise RuntimeError, "netzke_combo_options_for should return an Array" unless res.kind_of? Array
|
39
|
+
return [[]] if res.empty?
|
40
|
+
|
41
|
+
unless res.first.kind_of? Array
|
42
|
+
res=res.map do |v|
|
43
|
+
[v]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
return res
|
47
|
+
|
48
|
+
|
50
49
|
end
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
53
|
+
# Normalize array of attributes
|
54
54
|
# [:col1, "col2", {:name => :col3}] =>
|
55
55
|
# [{:name => "col1"}, {:name => "col2"}, {:name => "col3"}]
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
def normalize_attrs(attrs)
|
57
|
+
attrs.map{ |a| normalize_attr(a) }
|
58
|
+
end
|
59
|
+
|
60
|
+
# Normalize an attribute, e.g.:
|
61
|
+
# :first_name =>
|
62
|
+
# {:name => "first_name"}
|
63
|
+
def normalize_attr(a)
|
64
|
+
a.is_a?(Symbol) || a.is_a?(String) ? {:name => a.to_s} : a.merge(:name => a[:name].to_s)
|
60
65
|
end
|
61
66
|
|
62
67
|
# Returns association and association method for a column
|
@@ -69,6 +74,29 @@ module Netzke
|
|
69
74
|
def association_attr?(name)
|
70
75
|
!!name.to_s.index("__")
|
71
76
|
end
|
72
|
-
|
77
|
+
|
78
|
+
# Model class
|
79
|
+
# (We can't memoize this method because at some point we extend it, e.g. in Netzke::DataAccessor)
|
80
|
+
def data_class
|
81
|
+
@data_class ||= begin
|
82
|
+
klass = "Netzke::ModelExtensions::#{config[:model]}For#{short_component_class_name}".constantize rescue nil
|
83
|
+
klass || original_data_class
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Model class before model extensions are taken into account
|
88
|
+
def original_data_class
|
89
|
+
@original_data_class ||= begin
|
90
|
+
::ActiveSupport::Deprecation.warn("data_class_name option is deprecated. Use model instead", caller) if config[:data_class_name]
|
91
|
+
model_name = config[:model] || config[:data_class_name]
|
92
|
+
model_name.nil? ? raise(ArgumentError, "No model specified for component #{global_id}") : model_name.constantize
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# whether a column is bound to the primary_key
|
97
|
+
def primary_key_attr?(a)
|
98
|
+
data_class && a[:name].to_s == data_class.primary_key
|
99
|
+
end
|
100
|
+
|
73
101
|
end
|
74
102
|
end
|