netzke-basepack-zh 0.7.6
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/.autotest +1 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.rdoc +445 -0
- data/LICENSE +1 -0
- data/README.md +94 -0
- data/Rakefile +44 -0
- data/TODO.rdoc +8 -0
- data/config/ci/before-travis.sh +28 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/javascripts/basepack.js +139 -0
- data/javascripts/xdatetime.js +196 -0
- data/lib/generators/netzke/basepack_generator.rb +10 -0
- data/lib/generators/netzke/templates/assets/ts-checkbox.gif +0 -0
- data/lib/generators/netzke/templates/create_netzke_field_lists.rb +18 -0
- data/lib/netzke-basepack.rb +26 -0
- data/lib/netzke/active_record.rb +20 -0
- data/lib/netzke/active_record/attributes.rb +256 -0
- data/lib/netzke/active_record/combobox_options.rb +16 -0
- data/lib/netzke/active_record/relation_extensions.rb +37 -0
- data/lib/netzke/basepack.rb +45 -0
- data/lib/netzke/basepack/accordion_panel.rb +39 -0
- data/lib/netzke/basepack/action_column.rb +68 -0
- data/lib/netzke/basepack/action_column/javascripts/action_column.js +61 -0
- data/lib/netzke/basepack/auth_app.rb +159 -0
- data/lib/netzke/basepack/basic_app.rb +7 -0
- data/lib/netzke/basepack/border_layout_panel.rb +53 -0
- data/lib/netzke/basepack/border_layout_panel/javascripts/border_layout_panel.js +40 -0
- data/lib/netzke/basepack/data_accessor.rb +53 -0
- data/lib/netzke/basepack/data_adapters/abstract_adapter.rb +164 -0
- data/lib/netzke/basepack/data_adapters/active_record_adapter.rb +279 -0
- data/lib/netzke/basepack/data_adapters/data_mapper_adapter.rb +264 -0
- data/lib/netzke/basepack/data_adapters/sequel_adapter.rb +260 -0
- data/lib/netzke/basepack/form_panel.rb +144 -0
- data/lib/netzke/basepack/form_panel/fields.rb +208 -0
- data/lib/netzke/basepack/form_panel/javascripts/comma_list_cbg.js +51 -0
- data/lib/netzke/basepack/form_panel/javascripts/form_panel.js +225 -0
- data/lib/netzke/basepack/form_panel/javascripts/misc.js +4 -0
- data/lib/netzke/basepack/form_panel/javascripts/n_radio_group.js +43 -0
- data/lib/netzke/basepack/form_panel/javascripts/readonly_mode.js +35 -0
- data/lib/netzke/basepack/form_panel/services.rb +142 -0
- data/lib/netzke/basepack/form_panel/stylesheets/readonly_mode.css +14 -0
- data/lib/netzke/basepack/grid_panel.rb +440 -0
- data/lib/netzke/basepack/grid_panel/columns.rb +394 -0
- data/lib/netzke/basepack/grid_panel/javascripts/advanced_search.js +27 -0
- data/lib/netzke/basepack/grid_panel/javascripts/check_column_fix.js +6 -0
- data/lib/netzke/basepack/grid_panel/javascripts/edit_in_form.js +51 -0
- data/lib/netzke/basepack/grid_panel/javascripts/event_handling.js +179 -0
- data/lib/netzke/basepack/grid_panel/javascripts/grid_panel.js +438 -0
- data/lib/netzke/basepack/grid_panel/javascripts/misc.js +4 -0
- data/lib/netzke/basepack/grid_panel/javascripts/rows-dd.js +281 -0
- data/lib/netzke/basepack/grid_panel/record_form_window.rb +41 -0
- data/lib/netzke/basepack/grid_panel/services.rb +235 -0
- data/lib/netzke/basepack/paging_form_panel.rb +72 -0
- data/lib/netzke/basepack/paging_form_panel/javascripts/paging_form_panel.js +76 -0
- data/lib/netzke/basepack/panel.rb +11 -0
- data/lib/netzke/basepack/query_builder.rb +107 -0
- data/lib/netzke/basepack/query_builder/javascripts/query_builder.js +153 -0
- data/lib/netzke/basepack/search_panel.rb +79 -0
- data/lib/netzke/basepack/search_panel/javascripts/condition_field.js +160 -0
- data/lib/netzke/basepack/search_panel/javascripts/search_panel.js +65 -0
- data/lib/netzke/basepack/search_window.rb +66 -0
- data/lib/netzke/basepack/simple_app.rb +104 -0
- data/lib/netzke/basepack/simple_app/javascripts/simple_app.js +64 -0
- data/lib/netzke/basepack/simple_app/javascripts/statusbar_ext.js +8 -0
- data/lib/netzke/basepack/tab_panel.rb +21 -0
- data/lib/netzke/basepack/tab_panel/javascripts/tab_panel.js +11 -0
- data/lib/netzke/basepack/version.rb +11 -0
- data/lib/netzke/basepack/window.rb +29 -0
- data/lib/netzke/basepack/window/javascripts/window.js +20 -0
- data/lib/netzke/basepack/wrap_lazy_loaded.rb +28 -0
- data/lib/netzke/basepack/wrapper.rb +28 -0
- data/lib/netzke/data_mapper.rb +18 -0
- data/lib/netzke/data_mapper/attributes.rb +273 -0
- data/lib/netzke/data_mapper/combobox_options.rb +11 -0
- data/lib/netzke/data_mapper/relation_extensions.rb +38 -0
- data/lib/netzke/sequel.rb +18 -0
- data/lib/netzke/sequel/attributes.rb +274 -0
- data/lib/netzke/sequel/combobox_options.rb +10 -0
- data/lib/netzke/sequel/relation_extensions.rb +40 -0
- data/lib/tasks/netzke_basepack_tasks.rake +4 -0
- data/locales/de.yml +79 -0
- data/locales/en.yml +79 -0
- data/netzke-basepack.gemspec +306 -0
- data/stylesheets/basepack.css +72 -0
- data/stylesheets/datetimefield.css +54 -0
- data/test/basepack_test_app/.gitignore +6 -0
- data/test/basepack_test_app/.rvmrc +1 -0
- data/test/basepack_test_app/Gemfile +59 -0
- data/test/basepack_test_app/Gemfile.lock +196 -0
- data/test/basepack_test_app/Guardfile +46 -0
- data/test/basepack_test_app/README +1 -0
- data/test/basepack_test_app/Rakefile +7 -0
- data/test/basepack_test_app/app/components/author_form.rb +32 -0
- data/test/basepack_test_app/app/components/author_grid.rb +3 -0
- data/test/basepack_test_app/app/components/book_form.rb +38 -0
- data/test/basepack_test_app/app/components/book_form_with_custom_fields.rb +21 -0
- data/test/basepack_test_app/app/components/book_form_with_defaults.rb +8 -0
- data/test/basepack_test_app/app/components/book_form_with_nested_attributes.rb +18 -0
- data/test/basepack_test_app/app/components/book_grid.rb +12 -0
- data/test/basepack_test_app/app/components/book_grid_filtering.rb +10 -0
- data/test/basepack_test_app/app/components/book_grid_loader.rb +24 -0
- data/test/basepack_test_app/app/components/book_grid_with_column_actions.rb +15 -0
- data/test/basepack_test_app/app/components/book_grid_with_custom_columns.rb +27 -0
- data/test/basepack_test_app/app/components/book_grid_with_default_values.rb +9 -0
- data/test/basepack_test_app/app/components/book_grid_with_extra_feedback.rb +8 -0
- data/test/basepack_test_app/app/components/book_grid_with_extra_filters.rb +14 -0
- data/test/basepack_test_app/app/components/book_grid_with_nested_attributes.rb +13 -0
- data/test/basepack_test_app/app/components/book_grid_with_overridden_columns.rb +15 -0
- data/test/basepack_test_app/app/components/book_grid_with_paging.rb +10 -0
- data/test/basepack_test_app/app/components/book_grid_with_persistence.rb +8 -0
- data/test/basepack_test_app/app/components/book_grid_with_scoped_authors.rb +8 -0
- data/test/basepack_test_app/app/components/book_grid_with_virtual_attributes.rb +21 -0
- data/test/basepack_test_app/app/components/book_paging_form_panel.rb +22 -0
- data/test/basepack_test_app/app/components/book_query_builder.rb +8 -0
- data/test/basepack_test_app/app/components/book_search_panel.rb +5 -0
- data/test/basepack_test_app/app/components/book_search_panel/javascripts/i18n_de.js +6 -0
- data/test/basepack_test_app/app/components/book_with_custom_primary_key_grid.rb +10 -0
- data/test/basepack_test_app/app/components/books_bound_to_author.rb +10 -0
- data/test/basepack_test_app/app/components/double_book_grid.rb +18 -0
- data/test/basepack_test_app/app/components/extras/book_presentation.rb +27 -0
- data/test/basepack_test_app/app/components/form_without_model.rb +21 -0
- data/test/basepack_test_app/app/components/generic_user_form.rb +12 -0
- data/test/basepack_test_app/app/components/lockable_book_form.rb +17 -0
- data/test/basepack_test_app/app/components/lockable_user_form.rb +7 -0
- data/test/basepack_test_app/app/components/paging_form_with_search.rb +40 -0
- data/test/basepack_test_app/app/components/simple_accordion.rb +11 -0
- data/test/basepack_test_app/app/components/simple_panel.rb +17 -0
- data/test/basepack_test_app/app/components/simple_tab_panel.rb +11 -0
- data/test/basepack_test_app/app/components/simple_window.rb +10 -0
- data/test/basepack_test_app/app/components/simple_wrapper.rb +7 -0
- data/test/basepack_test_app/app/components/some_accordion_panel.rb +22 -0
- data/test/basepack_test_app/app/components/some_auth_app.rb +32 -0
- data/test/basepack_test_app/app/components/some_border_layout.rb +28 -0
- data/test/basepack_test_app/app/components/some_simple_app.rb +35 -0
- data/test/basepack_test_app/app/components/some_tab_panel.rb +20 -0
- data/test/basepack_test_app/app/components/user_form.rb +25 -0
- data/test/basepack_test_app/app/components/user_form_with_default_fields.rb +8 -0
- data/test/basepack_test_app/app/components/user_grid.rb +8 -0
- data/test/basepack_test_app/app/components/user_grid_with_customized_form_fields.rb +18 -0
- data/test/basepack_test_app/app/components/window_component_loader.rb +27 -0
- data/test/basepack_test_app/app/controllers/application_controller.rb +9 -0
- data/test/basepack_test_app/app/controllers/components_controller.rb +10 -0
- data/test/basepack_test_app/app/controllers/welcome_controller.rb +9 -0
- data/test/basepack_test_app/app/helpers/application_helper.rb +8 -0
- data/test/basepack_test_app/app/helpers/embedded_components_helper.rb +2 -0
- data/test/basepack_test_app/app/models/address.rb +29 -0
- data/test/basepack_test_app/app/models/author.rb +38 -0
- data/test/basepack_test_app/app/models/book.rb +49 -0
- data/test/basepack_test_app/app/models/book_with_custom_primary_key.rb +26 -0
- data/test/basepack_test_app/app/models/role.rb +24 -0
- data/test/basepack_test_app/app/models/user.rb +29 -0
- data/test/basepack_test_app/app/presenters/forms/generic_user.rb +6 -0
- data/test/basepack_test_app/app/views/components/loadable_window.html.erb +9 -0
- data/test/basepack_test_app/app/views/components/simple_panel.html.erb +1 -0
- data/test/basepack_test_app/app/views/layouts/application.html.erb +12 -0
- data/test/basepack_test_app/app/views/layouts/components.html.erb +13 -0
- data/test/basepack_test_app/app/views/layouts/nested.html.erb +5 -0
- data/test/basepack_test_app/app/views/welcome/index.html.erb +10 -0
- data/test/basepack_test_app/config.ru +4 -0
- data/test/basepack_test_app/config/application.rb +57 -0
- data/test/basepack_test_app/config/boot.rb +13 -0
- data/test/basepack_test_app/config/cucumber.yml +8 -0
- data/test/basepack_test_app/config/database.yml.sample +41 -0
- data/test/basepack_test_app/config/database.yml.travis +15 -0
- data/test/basepack_test_app/config/environment.rb +6 -0
- data/test/basepack_test_app/config/environments/development.rb +22 -0
- data/test/basepack_test_app/config/environments/production.rb +49 -0
- data/test/basepack_test_app/config/environments/test.rb +35 -0
- data/test/basepack_test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/basepack_test_app/config/initializers/data_mapper_logging.rb +3 -0
- data/test/basepack_test_app/config/initializers/inflections.rb +10 -0
- data/test/basepack_test_app/config/initializers/mime_types.rb +5 -0
- data/test/basepack_test_app/config/initializers/netzke.rb +9 -0
- data/test/basepack_test_app/config/initializers/secret_token.rb +7 -0
- data/test/basepack_test_app/config/initializers/sequel.rb +26 -0
- data/test/basepack_test_app/config/initializers/session_store.rb +8 -0
- data/test/basepack_test_app/config/locales/de.yml +35 -0
- data/test/basepack_test_app/config/locales/es.yml +96 -0
- data/test/basepack_test_app/config/routes.rb +68 -0
- data/test/basepack_test_app/db/development_structure.sql +88 -0
- data/test/basepack_test_app/db/migrate/20100914104207_create_users.rb +15 -0
- data/test/basepack_test_app/db/migrate/20100914104236_create_roles.rb +13 -0
- data/test/basepack_test_app/db/migrate/20101026185816_create_authors.rb +14 -0
- data/test/basepack_test_app/db/migrate/20101026190021_create_books.rb +19 -0
- data/test/basepack_test_app/db/migrate/20110101143818_create_addresses.rb +17 -0
- data/test/basepack_test_app/db/migrate/20110213213050_create_netzke_component_states.rb +20 -0
- data/test/basepack_test_app/db/migrate/20110701070052_create_book_with_custom_primary_keys.rb +15 -0
- data/test/basepack_test_app/db/migrate/20110901114016_add_last_read_at_to_books.rb +9 -0
- data/test/basepack_test_app/db/migrate/20110909071740_add_published_on_to_books.rb +5 -0
- data/test/basepack_test_app/db/schema.rb +81 -0
- data/test/basepack_test_app/db/seeds.rb +44 -0
- data/test/basepack_test_app/features/accordion_panel.feature +12 -0
- data/test/basepack_test_app/features/components_in_view.feature +11 -0
- data/test/basepack_test_app/features/form_panel.feature +142 -0
- data/test/basepack_test_app/features/grid_panel.feature +277 -0
- data/test/basepack_test_app/features/grid_panel_filters.feature +73 -0
- data/test/basepack_test_app/features/grid_panel_with_custom_primary_key.feature +15 -0
- data/test/basepack_test_app/features/grid_sorting.feature +47 -0
- data/test/basepack_test_app/features/i18n.feature +18 -0
- data/test/basepack_test_app/features/nested_attributes.feature +26 -0
- data/test/basepack_test_app/features/paging_form_panel.feature +43 -0
- data/test/basepack_test_app/features/search_in_grid.feature +49 -0
- data/test/basepack_test_app/features/simple_app.feature +15 -0
- data/test/basepack_test_app/features/simple_panel.feature +11 -0
- data/test/basepack_test_app/features/step_definitions/accordion_steps.rb +5 -0
- data/test/basepack_test_app/features/step_definitions/ext_steps.rb +16 -0
- data/test/basepack_test_app/features/step_definitions/form_panel_steps.rb +46 -0
- data/test/basepack_test_app/features/step_definitions/generic_steps.rb +44 -0
- data/test/basepack_test_app/features/step_definitions/grid_panel_steps.rb +186 -0
- data/test/basepack_test_app/features/step_definitions/pickle_steps.rb +100 -0
- data/test/basepack_test_app/features/step_definitions/web_steps.rb +219 -0
- data/test/basepack_test_app/features/support/env.rb +81 -0
- data/test/basepack_test_app/features/support/paths.rb +65 -0
- data/test/basepack_test_app/features/support/pickle.rb +24 -0
- data/test/basepack_test_app/features/support/selectors.rb +39 -0
- data/test/basepack_test_app/features/tab_panel.feature +12 -0
- data/test/basepack_test_app/features/validations_in_grid.feature +13 -0
- data/test/basepack_test_app/features/virtual_attributes.feature +16 -0
- data/test/basepack_test_app/features/window.feature +11 -0
- data/test/basepack_test_app/lib/tasks/.gitkeep +0 -0
- data/test/basepack_test_app/lib/tasks/cucumber.rake +71 -0
- data/test/basepack_test_app/lib/tasks/travis.rake +7 -0
- data/test/basepack_test_app/public/404.html +26 -0
- data/test/basepack_test_app/public/422.html +26 -0
- data/test/basepack_test_app/public/500.html +26 -0
- data/test/basepack_test_app/public/favicon.ico +0 -0
- data/test/basepack_test_app/public/images/header-deco.gif +0 -0
- data/test/basepack_test_app/public/images/rails.png +0 -0
- data/test/basepack_test_app/public/javascripts/application.js +2 -0
- data/test/basepack_test_app/public/javascripts/controls.js +965 -0
- data/test/basepack_test_app/public/javascripts/dragdrop.js +974 -0
- data/test/basepack_test_app/public/javascripts/effects.js +1123 -0
- data/test/basepack_test_app/public/javascripts/prototype.js +6001 -0
- data/test/basepack_test_app/public/javascripts/rails.js +175 -0
- data/test/basepack_test_app/public/robots.txt +5 -0
- data/test/basepack_test_app/public/stylesheets/.gitkeep +0 -0
- data/test/basepack_test_app/script/cucumber +10 -0
- data/test/basepack_test_app/script/rails +6 -0
- data/test/basepack_test_app/spec/components/form_panel_spec.rb +53 -0
- data/test/basepack_test_app/spec/components/grid_panel_spec.rb +10 -0
- data/test/basepack_test_app/spec/data_adapter/adapter_spec.rb +68 -0
- data/test/basepack_test_app/spec/data_adapter/attributes_spec.rb +56 -0
- data/test/basepack_test_app/spec/data_adapter/relation_extensions_spec.rb +125 -0
- data/test/basepack_test_app/spec/factories.rb +28 -0
- data/test/basepack_test_app/spec/spec_helper.rb +39 -0
- data/test/basepack_test_app/test/performance/browsing_test.rb +9 -0
- data/test/basepack_test_app/test/test_helper.rb +13 -0
- data/test/basepack_test_app/vendor/plugins/.gitkeep +0 -0
- data/test/console_with_fixtures.rb +4 -0
- data/test/fixtures/books.yml +11 -0
- data/test/fixtures/categories.yml +7 -0
- data/test/fixtures/cities.yml +21 -0
- data/test/fixtures/continents.yml +7 -0
- data/test/fixtures/countries.yml +9 -0
- data/test/fixtures/genres.yml +9 -0
- data/test/fixtures/roles.yml +8 -0
- data/test/fixtures/users.yml +11 -0
- data/test/schema.rb +10 -0
- data/test/test_helper.rb +21 -0
- data/test/unit/accordion_panel_test.rb +20 -0
- data/test/unit/active_record_basepack_test.rb +54 -0
- data/test/unit/fields_configuration_test.rb +18 -0
- data/test/unit/grid_panel_test.rb +52 -0
- data/test/unit/netzke_basepack_test.rb +4 -0
- data/test/unit/tab_panel_test.rb +21 -0
- data/uninstall.rb +1 -0
- metadata +332 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
module Netzke
|
|
2
|
+
module Basepack
|
|
3
|
+
class GridPanel < Netzke::Base
|
|
4
|
+
module Columns
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
extend ActiveSupport::Memoizable
|
|
7
|
+
|
|
8
|
+
# module ClassMethods
|
|
9
|
+
# # Columns to be displayed by the FieldConfigurator, "meta-columns". Each corresponds to a configuration
|
|
10
|
+
# # option for each column in the grid.
|
|
11
|
+
# def meta_columns
|
|
12
|
+
# [
|
|
13
|
+
# # Whether the column will be present in the grid, also in :hidden or :meta state. The value for this column will
|
|
14
|
+
# # always be sent to/from the JS grid to the server
|
|
15
|
+
# {:name => "included", :attr_type => :boolean, :width => 40, :header => "Incl", :default_value => true},
|
|
16
|
+
#
|
|
17
|
+
# # The name of the column. May be any accessible method or attribute of the data_class.
|
|
18
|
+
# {:name => "name", :attr_type => :string, :width => 200},
|
|
19
|
+
#
|
|
20
|
+
# # The header for the column.
|
|
21
|
+
# {:name => "label", :attr_type => :string, :width => 200, :header => "Header"},
|
|
22
|
+
#
|
|
23
|
+
# # The default value of this column. Is used when a new row in the grid gets created.
|
|
24
|
+
# {:name => "default_value", :attr_type => :string, :width => 200},
|
|
25
|
+
#
|
|
26
|
+
# # Options for drop-downs
|
|
27
|
+
# {:name => "combobox_options", :attr_type => :string, :editor => :textarea, :width => 200},
|
|
28
|
+
#
|
|
29
|
+
# # Whether the column is editable in the grid.
|
|
30
|
+
# {:name => "read_only", :attr_type => :boolean, :header => "R/O", :tooltip => "Read-only"},
|
|
31
|
+
#
|
|
32
|
+
# # Whether the column will be in the hidden state (hide/show columns from the column menu, if it's enabled).
|
|
33
|
+
# {:name => "hidden", :attr_type => :boolean},
|
|
34
|
+
#
|
|
35
|
+
# # Whether the column should have "grid filters" enabled
|
|
36
|
+
# # (see here: http://www.extjs.com/deploy/dev/examples/grid-filtering/grid-filter-local.html)
|
|
37
|
+
# {:name => "with_filters", :attr_type => :boolean, :default_value => true, :header => "Filters"},
|
|
38
|
+
#
|
|
39
|
+
# #
|
|
40
|
+
# # Below some rarely used parameters, hidden by default (you can always un-hide them from the column menu).
|
|
41
|
+
# #
|
|
42
|
+
#
|
|
43
|
+
# # The column's width
|
|
44
|
+
# {:name => "width", :attr_type => :integer, :hidden => true},
|
|
45
|
+
#
|
|
46
|
+
# # Whether the column should be hideable
|
|
47
|
+
# {:name => "hideable", :attr_type => :boolean, :default_value => true, :hidden => true},
|
|
48
|
+
#
|
|
49
|
+
# # Whether the column should be sortable (why change it? normally it's hardcoded)
|
|
50
|
+
# {:name => "sortable", :attr_type => :boolean, :default_value => true, :hidden => true},
|
|
51
|
+
# ]
|
|
52
|
+
# end
|
|
53
|
+
#
|
|
54
|
+
# end
|
|
55
|
+
|
|
56
|
+
# Normalized columns for the grid, e.g.:
|
|
57
|
+
# [{:name => :id, :hidden => true, ...}, {:name => :name, :editable => false, ...}, ...]
|
|
58
|
+
# Possible options:
|
|
59
|
+
# * +with_excluded+ - when set to true, also excluded columns will be returned (handy for dynamic column configuration)
|
|
60
|
+
# * +with_meta+ - when set to true, the meta column will be included as the last column
|
|
61
|
+
def columns(options = {})
|
|
62
|
+
[].tap do |cols|
|
|
63
|
+
if loaded_columns = load_columns
|
|
64
|
+
filter_out_excluded_columns(loaded_columns) unless options[:with_excluded]
|
|
65
|
+
cols.concat(reverse_merge_equally_named_columns(loaded_columns, initial_columns(options[:with_excluded])))
|
|
66
|
+
else
|
|
67
|
+
cols.concat(initial_columns(options[:with_excluded]))
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
append_meta_column(cols) if options[:with_meta]
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
memoize :columns
|
|
75
|
+
|
|
76
|
+
def append_meta_column(cols)
|
|
77
|
+
cols << {}.tap do |c|
|
|
78
|
+
c.merge!(
|
|
79
|
+
:name => "_meta",
|
|
80
|
+
:meta => true,
|
|
81
|
+
:getter => lambda do |r|
|
|
82
|
+
meta_data(r)
|
|
83
|
+
end
|
|
84
|
+
)
|
|
85
|
+
c[:default_value] = meta_default_data if meta_default_data.present?
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# default_value for the meta column; used when a new record is being created in the grid
|
|
90
|
+
def meta_default_data
|
|
91
|
+
get_default_association_values.present? ? { :association_values => get_default_association_values.literalize_keys } : {}
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Override it when you need extra meta data to be passed through the meta column
|
|
95
|
+
def meta_data(r)
|
|
96
|
+
{ :association_values => get_association_values(r).literalize_keys }
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Columns as a hash, for easier access to a specific column
|
|
100
|
+
def columns_hash
|
|
101
|
+
@columns_hash ||= columns.inject({}){|r,c| r.merge(c[:name].to_sym => c)}
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Columns that we fall back to when neither persistent columns, nor configured columns are present.
|
|
105
|
+
# If there's a model-level field configuration, it's being used.
|
|
106
|
+
# Otherwise the defaults straight from the ActiveRecord model ("netzke_attributes").
|
|
107
|
+
# Override this method if you want to provide a fix set of columns in your subclass.
|
|
108
|
+
def default_columns
|
|
109
|
+
@default_columns ||= load_model_level_attrs || data_class.netzke_attributes
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Columns that were overridden with :override_columns config option.
|
|
113
|
+
def overridden_default_columns
|
|
114
|
+
if config[:override_columns].present?
|
|
115
|
+
result = []
|
|
116
|
+
default_columns.each do |col|
|
|
117
|
+
result << col.merge(config[:override_columns][col[:name].to_sym] || {})
|
|
118
|
+
end
|
|
119
|
+
result
|
|
120
|
+
else
|
|
121
|
+
default_columns
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Columns that represent a smart merge of default_columns and columns passed during the configuration.
|
|
126
|
+
def initial_columns(with_excluded = false)
|
|
127
|
+
# Normalize here, as from the config we can get symbols (names) instead of hashes
|
|
128
|
+
columns_from_config = config[:columns] && normalize_attrs(config[:columns])
|
|
129
|
+
|
|
130
|
+
if columns_from_config
|
|
131
|
+
# automatically add a column that reflects the primary key (unless specified in the config)
|
|
132
|
+
columns_from_config.insert(0, {:name => data_class.primary_key.to_s}) unless columns_from_config.any?{ |c| c[:name] == data_class.primary_key }
|
|
133
|
+
|
|
134
|
+
# reverse-merge each column hash from config with each column hash from exposed_attributes
|
|
135
|
+
# (columns from config have higher priority)
|
|
136
|
+
for c in columns_from_config
|
|
137
|
+
corresponding_default_column = overridden_default_columns.find{ |k| k[:name] == c[:name] }
|
|
138
|
+
c.reverse_merge!(corresponding_default_column) if corresponding_default_column
|
|
139
|
+
end
|
|
140
|
+
columns_for_create = columns_from_config
|
|
141
|
+
else
|
|
142
|
+
# we didn't have columns configured in component's config, so, use the columns from the data class
|
|
143
|
+
columns_for_create = overridden_default_columns
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
filter_out_excluded_columns(columns_for_create) unless with_excluded
|
|
147
|
+
|
|
148
|
+
# Make the column config complete with the defaults.
|
|
149
|
+
# Note: dup is needed to avoid modifying original hashes.
|
|
150
|
+
columns_for_create.map { |c| c.dup.tap { |c| augment_column_config c } }
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
memoize :initial_columns
|
|
154
|
+
|
|
155
|
+
private
|
|
156
|
+
|
|
157
|
+
# Based on initial column config, e.g.:
|
|
158
|
+
#
|
|
159
|
+
# {:name=>"author__name", :attr_type=>:string}
|
|
160
|
+
#
|
|
161
|
+
# augment it with additional configuration params, e.g.:
|
|
162
|
+
#
|
|
163
|
+
# {:name=>"author__name", :attr_type=>:string, :editor=>{:xtype=>:netzkeremotecombo}, :assoc=>true, :virtual=>true, :header=>"Author name", :editable=>true, :sortable=>false, :filterable=>false}
|
|
164
|
+
#
|
|
165
|
+
# It may be handy to override it.
|
|
166
|
+
def augment_column_config(c)
|
|
167
|
+
# note: the order of these calls is important, as consequent calls may depend on the result of previous ones
|
|
168
|
+
set_default_xtype(c)
|
|
169
|
+
set_default_virtual(c)
|
|
170
|
+
set_default_text(c)
|
|
171
|
+
set_default_editable(c)
|
|
172
|
+
set_default_editor(c)
|
|
173
|
+
set_default_width(c)
|
|
174
|
+
set_default_hidden(c)
|
|
175
|
+
set_default_sortable(c)
|
|
176
|
+
set_default_filterable(c)
|
|
177
|
+
c[:assoc] = association_attr?(c)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def set_default_xtype(c)
|
|
181
|
+
return if c[:renderer] || c[:editor] # if user set those manually, we don't mess with column xtype
|
|
182
|
+
c[:xtype] ||= attr_type_to_xtype_map[c[:attr_type]]
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def set_default_text(c)
|
|
186
|
+
c[:text] ||= c[:label] || data_class.human_attribute_name(c[:name])
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def set_default_editor(c)
|
|
190
|
+
# if shouldn't be editable, don't set any default editor; also, specifying xtype takes care of the editor
|
|
191
|
+
return if c[:read_only] || c[:editable] == false
|
|
192
|
+
|
|
193
|
+
if association_attr?(c)
|
|
194
|
+
set_default_association_editor(c)
|
|
195
|
+
else
|
|
196
|
+
c[:editor] ||= editor_for_attr_type(c[:attr_type])
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def set_default_width(c)
|
|
202
|
+
c[:width] ||= 50 if c[:attr_type] == :boolean
|
|
203
|
+
c[:width] ||= 150 if c[:attr_type] == :datetime
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def set_default_hidden(c)
|
|
207
|
+
c[:hidden] = true if primary_key_attr?(c) && c[:hidden].nil?
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def set_default_editable(c)
|
|
211
|
+
if c[:editable].nil?
|
|
212
|
+
c[:editable] = is_editable_column?(c)
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def set_default_sortable(c)
|
|
217
|
+
# this *has* to be set to false if we don't want the column to be sortable (it's sortable by default in Ext)
|
|
218
|
+
c[:sortable] = !(c[:virtual] && !c[:sorting_scope]) if c[:sortable].nil?
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def set_default_filterable(c)
|
|
222
|
+
c[:filterable] = !c[:virtual] if c[:filterable].nil?
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
# Detects an association column and sets up the proper editor.
|
|
227
|
+
def set_default_association_editor(c)
|
|
228
|
+
assoc, assoc_method = c[:name].split('__')
|
|
229
|
+
return unless assoc
|
|
230
|
+
|
|
231
|
+
assoc_method_type = data_adapter.get_assoc_property_type assoc, assoc_method
|
|
232
|
+
|
|
233
|
+
# if association column is boolean, display a checkbox (or alike), otherwise - a combobox (or alike)
|
|
234
|
+
if c[:nested_attribute]
|
|
235
|
+
c[:editor] ||= editor_for_attr_type(assoc_method_type)
|
|
236
|
+
else
|
|
237
|
+
c[:editor] ||= assoc_method_type == :boolean ? editor_for_attr_type(:boolean) : editor_for_association
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
# If the column should be editable
|
|
242
|
+
def is_editable_column?(c)
|
|
243
|
+
not_editable_if = primary_key_attr?(c)
|
|
244
|
+
not_editable_if ||= c[:virtual] && !association_attr?(c[:name])
|
|
245
|
+
not_editable_if ||= c[:read_only]
|
|
246
|
+
|
|
247
|
+
editable_if = data_class.column_names.include?(c[:name])
|
|
248
|
+
editable_if ||= data_class.instance_methods.map(&:to_s).include?("#{c[:name]}=")
|
|
249
|
+
editable_if ||= association_attr?(c[:name])
|
|
250
|
+
|
|
251
|
+
editable_if && !not_editable_if
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def initial_columns_order
|
|
255
|
+
columns.map do |c|
|
|
256
|
+
{
|
|
257
|
+
:name => c[:name],
|
|
258
|
+
:width => c[:width],
|
|
259
|
+
:hidden => c[:hidden]
|
|
260
|
+
}
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
def columns_order
|
|
265
|
+
if config[:persistence]
|
|
266
|
+
update_state(:columns_order, initial_columns_order) if columns_have_changed?
|
|
267
|
+
state[:columns_order] || initial_columns_order
|
|
268
|
+
else
|
|
269
|
+
initial_columns_order
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
def columns_have_changed?
|
|
274
|
+
init_column_names = initial_columns_order.map{ |c| c[:name].to_s }.sort
|
|
275
|
+
stored_column_names = (state[:columns_order] || initial_columns_order).map{ |c| c[:name].to_s }.sort
|
|
276
|
+
init_column_names != stored_column_names
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def filter_out_excluded_columns(cols)
|
|
280
|
+
cols.reject!{ |c| c[:included] == false }
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
# Stores modified columns in persistent storage
|
|
284
|
+
def save_columns!
|
|
285
|
+
# NetzkeFieldList.update_list_for_current_authority(global_id, columns(false), original_data_class.name) if persistent_config_enabled?
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
def load_columns
|
|
289
|
+
# NetzkeFieldList.read_list(global_id) if persistent_config_enabled?
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
def load_model_level_attrs
|
|
293
|
+
# NetzkeModelAttrList.read_list(data_class.name) if persistent_config_enabled?
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
# Column editor config for attribute type.
|
|
297
|
+
def editor_for_attr_type(type)
|
|
298
|
+
{:xtype => attr_type_to_editor_xtype_map[type] || :textfield}
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
# Column editor config for one-to-many association
|
|
302
|
+
def editor_for_association
|
|
303
|
+
{:xtype => :netzkeremotecombo}
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
# Hash that maps a column type to the editor xtype. Override if you want different editors.
|
|
307
|
+
def attr_type_to_editor_xtype_map
|
|
308
|
+
{
|
|
309
|
+
:integer => :numberfield,
|
|
310
|
+
:boolean => :checkbox,
|
|
311
|
+
:date => :datefield,
|
|
312
|
+
:datetime => :xdatetime,
|
|
313
|
+
:text => :textarea,
|
|
314
|
+
:string => :textfield
|
|
315
|
+
}
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
def attr_type_to_xtype_map
|
|
319
|
+
{
|
|
320
|
+
# :integer => :numbercolumn, # don't like the default formatter
|
|
321
|
+
:boolean => :checkcolumn,
|
|
322
|
+
:date => :datecolumn,
|
|
323
|
+
#:datetime => :datecolumn # TODO: replace with datetimepicker
|
|
324
|
+
}
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
# Default fields that will be displayed in the Add/Edit/Search forms
|
|
328
|
+
# When overriding this method, keep in mind that the fields inside the layout must be expanded (each field represented by a hash, not just a symbol)
|
|
329
|
+
def default_fields_for_forms
|
|
330
|
+
selected_columns = columns.select do |c|
|
|
331
|
+
data_class.column_names.include?(c[:name]) ||
|
|
332
|
+
data_class.instance_methods.include?("#{c[:name]}=") ||
|
|
333
|
+
association_attr?(c[:name])
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
selected_columns.map do |c|
|
|
337
|
+
field_config = {
|
|
338
|
+
:name => c[:name],
|
|
339
|
+
:field_label => c[:text] || c[:header]
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
# scopes for combobox options
|
|
343
|
+
field_config[:scopes] = c[:editor][:scopes] if c[:editor].is_a?(Hash)
|
|
344
|
+
|
|
345
|
+
field_config.merge!(c[:editor] || {})
|
|
346
|
+
|
|
347
|
+
field_config
|
|
348
|
+
end
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
# default_fields_for_forms extended with default values (for new-record form)
|
|
352
|
+
# def default_fields_for_forms_with_default_values
|
|
353
|
+
# res = default_fields_for_forms.dup
|
|
354
|
+
# each_attr_in(res) do |a|
|
|
355
|
+
# attr_name = a[:name].to_sym
|
|
356
|
+
# a[:value] = a[:default_value] || columns_hash[attr_name].try(:fetch, :default_value, nil) || data_class.netzke_attribute_hash[attr_name].try(:fetch, :default_value, nil)
|
|
357
|
+
# end
|
|
358
|
+
# res
|
|
359
|
+
# end
|
|
360
|
+
|
|
361
|
+
def columns_default_values
|
|
362
|
+
columns.inject({}) do |r,c|
|
|
363
|
+
assoc_name, assoc_method = c[:name].split '__'
|
|
364
|
+
if c[:default_value].nil?
|
|
365
|
+
r
|
|
366
|
+
else
|
|
367
|
+
if assoc_method
|
|
368
|
+
r.merge(data_adapter.foreign_key_for(assoc_name) || data_adapter.foreign_key_for(assoc_name) => c[:default_value])
|
|
369
|
+
else
|
|
370
|
+
r.merge(c[:name] => c[:default_value])
|
|
371
|
+
end
|
|
372
|
+
end
|
|
373
|
+
end
|
|
374
|
+
end
|
|
375
|
+
|
|
376
|
+
# Recursively traversess items (an array) and yields each found field (a hash with :name set)
|
|
377
|
+
def each_attr_in(items)
|
|
378
|
+
items.each do |item|
|
|
379
|
+
if item.is_a?(Hash)
|
|
380
|
+
each_attr_in(item[:items]) if item[:items].is_a?(Array)
|
|
381
|
+
yield(item) if item[:name]
|
|
382
|
+
end
|
|
383
|
+
end
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
# Receives 2 arrays of columns. Merges the missing config from the +source+ into +dest+, matching columns by name
|
|
387
|
+
def reverse_merge_equally_named_columns(dest, source)
|
|
388
|
+
dest.each{ |dc| dc.reverse_merge!(source.detect{ |sc| sc[:name] == dc[:name] } || {}) }
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
end
|
|
392
|
+
end
|
|
393
|
+
end
|
|
394
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
onSearch: function(el){
|
|
3
|
+
if (this.searchWindow) {
|
|
4
|
+
this.searchWindow.show();
|
|
5
|
+
} else {
|
|
6
|
+
this.loadNetzkeComponent({name: 'search_form', callback: function(win){
|
|
7
|
+
this.searchWindow = win;
|
|
8
|
+
win.show();
|
|
9
|
+
|
|
10
|
+
win.items.first().on('apply', function(){
|
|
11
|
+
win.onSearch();
|
|
12
|
+
return false; // do not propagate the 'apply' event
|
|
13
|
+
}, this);
|
|
14
|
+
|
|
15
|
+
win.on('hide', function(){
|
|
16
|
+
var query = win.getQuery();
|
|
17
|
+
if (win.closeRes == 'search'){
|
|
18
|
+
var store = this.getStore(), proxy = store.getProxy();
|
|
19
|
+
proxy.extraParams.query = Ext.encode(query);
|
|
20
|
+
store.load();
|
|
21
|
+
}
|
|
22
|
+
el.toggle(query.length > 0); // toggle based on the state
|
|
23
|
+
}, this);
|
|
24
|
+
}, scope: this});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
onEditInForm: function(){
|
|
3
|
+
var selModel = this.getSelectionModel();
|
|
4
|
+
if (selModel.getCount() > 1) {
|
|
5
|
+
var recordId = selModel.selected.first().getId();
|
|
6
|
+
this.loadNetzkeComponent({name: "multi_edit_form",
|
|
7
|
+
params: {record_id: recordId},
|
|
8
|
+
callback: function(w){
|
|
9
|
+
w.show();
|
|
10
|
+
var form = w.items.first();
|
|
11
|
+
form.on('apply', function(){
|
|
12
|
+
var ids = [];
|
|
13
|
+
selModel.selected.each(function(r){
|
|
14
|
+
ids.push(r.getId());
|
|
15
|
+
});
|
|
16
|
+
if (!form.baseParams) form.baseParams = {};
|
|
17
|
+
form.baseParams.ids = Ext.encode(ids);
|
|
18
|
+
}, this);
|
|
19
|
+
|
|
20
|
+
w.on('close', function(){
|
|
21
|
+
if (w.closeRes === "ok") {
|
|
22
|
+
this.store.load();
|
|
23
|
+
}
|
|
24
|
+
}, this);
|
|
25
|
+
}, scope: this});
|
|
26
|
+
} else {
|
|
27
|
+
var recordId = selModel.selected.first().getId();
|
|
28
|
+
this.loadNetzkeComponent({name: "edit_form",
|
|
29
|
+
params: {record_id: recordId},
|
|
30
|
+
callback: function(w){
|
|
31
|
+
w.show();
|
|
32
|
+
w.on('close', function(){
|
|
33
|
+
if (w.closeRes === "ok") {
|
|
34
|
+
this.store.load();
|
|
35
|
+
}
|
|
36
|
+
}, this);
|
|
37
|
+
}, scope: this});
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
onAddInForm: function(){
|
|
42
|
+
this.loadNetzkeComponent({name: "add_form", callback: function(w){
|
|
43
|
+
w.show();
|
|
44
|
+
w.on('close', function(){
|
|
45
|
+
if (w.closeRes === "ok") {
|
|
46
|
+
this.store.load();
|
|
47
|
+
}
|
|
48
|
+
}, this);
|
|
49
|
+
}, scope: this});
|
|
50
|
+
}
|
|
51
|
+
}
|