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,21 @@
|
|
|
1
|
+
module Netzke
|
|
2
|
+
module Basepack
|
|
3
|
+
# = TabPanel
|
|
4
|
+
#
|
|
5
|
+
# Features:
|
|
6
|
+
# * Dynamically loads components for the tabs that get activated for the first time
|
|
7
|
+
# * (TODO) Provides the method markTabsOutdated to mark all inactive tabs as 'outdated', and calls "update" method on components in tabs when they get activated
|
|
8
|
+
# * (TODO) Stores the last active tab in persistent_config
|
|
9
|
+
#
|
|
10
|
+
# ToDo:
|
|
11
|
+
# * Introduce a second or two delay before informing the server about a tab switched
|
|
12
|
+
class TabPanel < Netzke::Base
|
|
13
|
+
|
|
14
|
+
include WrapLazyLoaded
|
|
15
|
+
|
|
16
|
+
js_base_class "Ext.TabPanel"
|
|
17
|
+
|
|
18
|
+
js_mixin :tab_panel
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
initComponent: function(params){
|
|
3
|
+
Netzke.classes.Basepack.TabPanel.superclass.initComponent.call(this);
|
|
4
|
+
this.on('tabchange', function(self, i){
|
|
5
|
+
if (i && i.wrappedComponent && !i.items.first() && !i.beingLoaded) {
|
|
6
|
+
i.beingLoaded = true; // prevent more than one request per tab in case of fast clicking
|
|
7
|
+
this.loadNetzkeComponent({name: i.wrappedComponent, container: i.id}, function(){i.beingLoaded = false});
|
|
8
|
+
}
|
|
9
|
+
}, this);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Netzke
|
|
2
|
+
module Basepack
|
|
3
|
+
# == Window
|
|
4
|
+
# Ext.Window-based component able to nest other Netzke components
|
|
5
|
+
#
|
|
6
|
+
# == Features
|
|
7
|
+
# * Persistent position and dimensions
|
|
8
|
+
#
|
|
9
|
+
# == Instance configuration
|
|
10
|
+
# <tt>:item</tt> - nested Netzke component, e.g.:
|
|
11
|
+
#
|
|
12
|
+
# netzke :window, :item => {:class_name => "GridPanel", :model => "User"}
|
|
13
|
+
class Window < Netzke::Base
|
|
14
|
+
js_base_class "Ext.window.Window"
|
|
15
|
+
|
|
16
|
+
js_mixin
|
|
17
|
+
|
|
18
|
+
endpoint :set_size_and_position do |params|
|
|
19
|
+
update_persistent_options(
|
|
20
|
+
:x => params[:x].to_i,
|
|
21
|
+
:y => params[:y].to_i,
|
|
22
|
+
:width => params[:w].to_i,
|
|
23
|
+
:height => params[:h].to_i
|
|
24
|
+
)
|
|
25
|
+
{}
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
layout: 'fit',
|
|
3
|
+
|
|
4
|
+
initComponent: function(){
|
|
5
|
+
this.callParent();
|
|
6
|
+
|
|
7
|
+
// set the move and resize events after window is shown, so that they don't fire at initial rendering
|
|
8
|
+
if (this.persistence) {
|
|
9
|
+
this.on("show", function(){
|
|
10
|
+
this.on("move", this.onMoveResize, this);
|
|
11
|
+
this.on("resize", this.onMoveResize, this);
|
|
12
|
+
}, this);
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
onMoveResize: function(){
|
|
17
|
+
var x = this.getPosition()[0], y = this.getPosition()[1], w = this.getSize().width, h = this.getSize().height;
|
|
18
|
+
this.setSizeAndPosition({x:x, y:y, w:w, h:h}); // API call
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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[:netzke_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
|
+
:icon_cls => wrapped_component[:icon_cls],
|
|
20
|
+
:disabled => wrapped_component[:disabled]
|
|
21
|
+
})
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
orig
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Netzke
|
|
2
|
+
module Basepack
|
|
3
|
+
# = Wrapper
|
|
4
|
+
#
|
|
5
|
+
# Simple Ext.Panel with layout 'fit' that wraps up another Netzke component. Can be useful in HTML pages where
|
|
6
|
+
# a component should be dynamically configured, to not reload the entire page after configuration (Wrapper
|
|
7
|
+
# will reload the component automatically).
|
|
8
|
+
#
|
|
9
|
+
# == Configuration
|
|
10
|
+
# * <tt>:item</tt> - configuration hash for wrapped component
|
|
11
|
+
#
|
|
12
|
+
# Example:
|
|
13
|
+
#
|
|
14
|
+
# netzke :wrapper, :item => {
|
|
15
|
+
# :class_name => "FormPanel",
|
|
16
|
+
# :model => "User"
|
|
17
|
+
# }
|
|
18
|
+
class Wrapper < Netzke::Base
|
|
19
|
+
js_properties(
|
|
20
|
+
:layout => 'fit',
|
|
21
|
+
|
|
22
|
+
# invisible
|
|
23
|
+
:header => false,
|
|
24
|
+
:border => false
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'netzke/data_mapper/attributes'
|
|
2
|
+
require 'netzke/data_mapper/combobox_options'
|
|
3
|
+
require 'netzke/data_mapper/relation_extensions'
|
|
4
|
+
|
|
5
|
+
module Netzke
|
|
6
|
+
module DataMapper
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
if defined? DataMapper
|
|
11
|
+
# Extend DataMapper
|
|
12
|
+
|
|
13
|
+
DataMapper::Model.append_extensions(Netzke::DataMapper::Attributes::ClassMethods)
|
|
14
|
+
DataMapper::Model.append_inclusions(Netzke::DataMapper::Attributes)
|
|
15
|
+
DataMapper::Model.append_extensions(Netzke::DataMapper::ComboboxOptions)
|
|
16
|
+
DataMapper::Model.append_extensions(Netzke::DataMapper::RelationExtensions)
|
|
17
|
+
end
|
|
18
|
+
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
module Netzke
|
|
2
|
+
module DataMapper
|
|
3
|
+
module Attributes
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
included do
|
|
7
|
+
class_attribute :netzke_declared_attr
|
|
8
|
+
self.netzke_declared_attr = []
|
|
9
|
+
|
|
10
|
+
class_attribute :netzke_excluded_attr
|
|
11
|
+
self.netzke_excluded_attr = []
|
|
12
|
+
|
|
13
|
+
class_attribute :netzke_exposed_attr
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
module ClassMethods
|
|
17
|
+
def data_adapter
|
|
18
|
+
Netzke::Basepack::DataAdapters::AbstractAdapter.adapter_class(self).new(self)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Define or configure an attribute.
|
|
22
|
+
# Example:
|
|
23
|
+
# netzke_attribute :recent, :type => :boolean, :read_only => true
|
|
24
|
+
def netzke_attribute(name, options = {})
|
|
25
|
+
name = name.to_s
|
|
26
|
+
options[:attr_type] = options.delete(:type) || options.delete(:attr_type) || :string
|
|
27
|
+
declared_attrs = self.netzke_declared_attr.dup
|
|
28
|
+
# if the attr was declared already, simply merge it with the new options
|
|
29
|
+
existing = declared_attrs.detect{ |va| va[:name] == name }
|
|
30
|
+
if existing
|
|
31
|
+
existing.merge!(options)
|
|
32
|
+
else
|
|
33
|
+
attr_config = {:name => name}.merge(options)
|
|
34
|
+
# if primary_key, insert in front, otherwise append
|
|
35
|
+
if name == self.primary_key
|
|
36
|
+
declared_attrs.insert(0, attr_config)
|
|
37
|
+
else
|
|
38
|
+
declared_attrs << {:name => name}.merge(options)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
self.netzke_declared_attr = declared_attrs
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Exclude attributes from being picked up by grids and forms.
|
|
45
|
+
# Accepts an array of attribute names (as symbols).
|
|
46
|
+
# Example:
|
|
47
|
+
# netzke_expose_attributes :created_at, :updated_at, :crypted_password
|
|
48
|
+
def netzke_exclude_attributes(*args)
|
|
49
|
+
self.netzke_excluded_attr = args.map(&:to_s)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Explicitly expose attributes that should be picked up by grids and forms.
|
|
53
|
+
# Accepts an array of attribute names (as symbols).
|
|
54
|
+
# Takes precedence over <tt>netzke_exclude_attributes</tt>.
|
|
55
|
+
# Example:
|
|
56
|
+
# netzke_expose_attributes :name, :role__name
|
|
57
|
+
def netzke_expose_attributes(*args)
|
|
58
|
+
self.netzke_exposed_attr = args.map(&:to_s)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Returns the attributes that will be picked up by grids and forms.
|
|
62
|
+
def netzke_attributes
|
|
63
|
+
exposed = netzke_exposed_attributes
|
|
64
|
+
exposed ? netzke_attrs_in_forced_order(exposed) : netzke_attrs_in_natural_order
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def netzke_attribute_hash
|
|
68
|
+
netzke_attributes.inject({}){ |r,a| r.merge(a[:name].to_sym => a) }
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def netzke_exposed_attributes
|
|
72
|
+
exposed = self.netzke_exposed_attr
|
|
73
|
+
if exposed && !exposed.include?(self.primary_key)
|
|
74
|
+
# automatically declare primary key as a netzke attribute
|
|
75
|
+
netzke_attribute(self.primary_key)
|
|
76
|
+
exposed.insert(0, self.primary_key)
|
|
77
|
+
end
|
|
78
|
+
exposed
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def primary_key
|
|
82
|
+
key.first.name.to_s
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def column_names
|
|
86
|
+
properties.map(&:name).map(&:to_s)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def columns
|
|
90
|
+
properties
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def columns_hash
|
|
94
|
+
properties.inject({}) { |hsh, prop|
|
|
95
|
+
hsh[prop.name.to_s] = prop
|
|
96
|
+
hsh
|
|
97
|
+
}
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def property_with(name)
|
|
101
|
+
properties.find{|p| p.name == name.to_sym}
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
private
|
|
105
|
+
def netzke_attrs_in_forced_order(attrs)
|
|
106
|
+
attrs.collect do |attr_name|
|
|
107
|
+
declared = self.netzke_declared_attr.detect { |va| va[:name] == attr_name } || {}
|
|
108
|
+
in_columns_hash = columns_hash[attr_name] && {:name => attr_name, :attr_type => data_adapter.map_type(columns_hash[attr_name].class), :default_value => columns_hash[attr_name].default} || {} # {:virtual => true} # if nothing found in columns, mark it as "virtual" or not?
|
|
109
|
+
if in_columns_hash.empty?
|
|
110
|
+
# If not among the model columns, it's either virtual, or an association
|
|
111
|
+
merged = association_attr?(attr_name) ? declared.merge!(:name => attr_name) : declared.merge(:virtual => true)
|
|
112
|
+
else
|
|
113
|
+
# .. otherwise merge with what's declared
|
|
114
|
+
merged = in_columns_hash.merge(declared)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# We didn't find it among declared, nor among the model columns, nor does it seem association attribute
|
|
118
|
+
merged[:name].nil? && raise(ArgumentError, "Unknown attribute '#{attr_name}' for model #{self.name}", caller)
|
|
119
|
+
|
|
120
|
+
merged
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Returns netzke attributes in the order of columns in the table, followed by extra declared attributes
|
|
125
|
+
# Detects one-to-many association columns and replaces the name of the column with association column name (Netzke style), e.g.:
|
|
126
|
+
#
|
|
127
|
+
# role_id => role__name
|
|
128
|
+
def netzke_attrs_in_natural_order
|
|
129
|
+
(
|
|
130
|
+
declared_attrs = self.netzke_declared_attr
|
|
131
|
+
|
|
132
|
+
column_names.map do |name|
|
|
133
|
+
c = {:name => name, :attr_type => data_adapter.map_type(property_with(name).class)}
|
|
134
|
+
|
|
135
|
+
# If it's named as foreign key of some association, then it's an association column
|
|
136
|
+
# assoc = reflect_on_all_associations.detect { |a| foreign_key_for_assoc(a) == c[:name] }
|
|
137
|
+
assoc = relationships.detect { |r| r.child_key.first.name.to_s == c[:name] }
|
|
138
|
+
if assoc
|
|
139
|
+
assoc_class = assoc.parent_model
|
|
140
|
+
candidates = %w{name title label} << c[:name]
|
|
141
|
+
assoc_method = candidates.detect{|m| (assoc_class.instance_methods.map(&:to_s) + assoc_class.column_names).include?(m) }
|
|
142
|
+
c[:name] = "#{assoc.name}__#{assoc_method}"
|
|
143
|
+
c[:attr_type] = data_adapter.map_type(columns_hash[assoc_method]).try(:class) || :string # when it's an instance method rather than a column, fall back to :string
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# auto set up the default value from the column settings
|
|
147
|
+
c.merge!(:default_value => property_with(name).default) if property_with(name).default
|
|
148
|
+
|
|
149
|
+
# if there's a declared attr with the same name, simply merge it with what's taken from the model's columns
|
|
150
|
+
if declared = declared_attrs.detect{ |va| va[:name] == c[:name] }
|
|
151
|
+
c.merge!(declared)
|
|
152
|
+
declared_attrs.delete(declared)
|
|
153
|
+
end
|
|
154
|
+
c
|
|
155
|
+
end +
|
|
156
|
+
declared_attrs
|
|
157
|
+
).reject { |attr| self.netzke_excluded_attr.include?(attr[:name]) }
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def association_attr?(attr_name)
|
|
161
|
+
!!attr_name.index("__") # probably we can't do much better than this, as we don't know at this moment if the associated model has a specific attribute, and we don't really want to find it out
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# Transforms a record to array of values according to the passed attributes
|
|
166
|
+
def netzke_array(attributes = self.class.netzke_attributes)
|
|
167
|
+
res = []
|
|
168
|
+
for a in attributes
|
|
169
|
+
next if a[:included] == false
|
|
170
|
+
res << value_for_attribute(a, a[:nested_attribute])
|
|
171
|
+
end
|
|
172
|
+
res
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def netzke_json
|
|
176
|
+
netzke_hash.to_nifty_json
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
# Accepts both hash and array of attributes
|
|
180
|
+
def netzke_hash(attributes = self.class.netzke_attributes)
|
|
181
|
+
res = {}
|
|
182
|
+
for a in (attributes.is_a?(Hash) ? attributes.values : attributes)
|
|
183
|
+
next if a[:included] == false
|
|
184
|
+
res[a[:name].to_sym] = self.value_for_attribute(a, a[:nested_attribute])
|
|
185
|
+
end
|
|
186
|
+
res
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
# Fetches the value specified by an (association) attribute
|
|
190
|
+
# If +through_association+ is true, get the value of the association by provided method, *not* the associated record's id
|
|
191
|
+
# E.g., author__name with through_association set to true may return "Vladimir Nabokov", while with through_association set to false, it'll return author_id for the current record
|
|
192
|
+
def value_for_attribute(a, through_association = false)
|
|
193
|
+
v = if a[:getter]
|
|
194
|
+
a[:getter].call(self)
|
|
195
|
+
elsif respond_to?("#{a[:name]}")
|
|
196
|
+
send("#{a[:name]}")
|
|
197
|
+
elsif is_association_attr?(a)
|
|
198
|
+
split = a[:name].to_s.split(/\.|__/)
|
|
199
|
+
assoc = self.class.relationships[split.first.to_sym]
|
|
200
|
+
|
|
201
|
+
if through_association
|
|
202
|
+
split.inject(self) do |r,m| # TODO: do we really need to descend deeper than 1 level?
|
|
203
|
+
if r.respond_to?(m)
|
|
204
|
+
r.send(m)
|
|
205
|
+
else
|
|
206
|
+
::Rails.logger.debug "Netzke::Basepack: Wrong attribute name: #{a[:name]}" unless r.nil?
|
|
207
|
+
nil
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
else
|
|
211
|
+
self.send assoc.child_key.first.name
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
# a work-around for to_json not taking the current timezone into account when serializing ActiveSupport::TimeWithZone
|
|
216
|
+
v = v.to_datetime.to_s(:db) if [ActiveSupport::TimeWithZone].include?(v.class)
|
|
217
|
+
v = v.to_s(:db) if [DateTime, Date].include?(v.class)
|
|
218
|
+
v
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
# Assigns new value to an (association) attribute
|
|
222
|
+
def set_value_for_attribute(a, v)
|
|
223
|
+
v = v.to_time_in_current_zone if v.is_a?(Date) # convert Date to Time
|
|
224
|
+
|
|
225
|
+
if a[:setter]
|
|
226
|
+
a[:setter].call(self, v)
|
|
227
|
+
elsif respond_to?("#{a[:name]}=")
|
|
228
|
+
send("#{a[:name]}=", v)
|
|
229
|
+
elsif is_association_attr?(a)
|
|
230
|
+
split = a[:name].to_s.split(/\.|__/)
|
|
231
|
+
if a[:nested_attribute]
|
|
232
|
+
# We want:
|
|
233
|
+
# set_value_for_attribute({:name => :assoc_1__assoc_2__method, :nested_attribute => true}, 100)
|
|
234
|
+
# =>
|
|
235
|
+
# self.assoc_1.assoc_2.method = 100
|
|
236
|
+
split.inject(self) { |r,m| m == split.last ? (r && r.send("#{m}=", v) && r.save) : r.send(m) }
|
|
237
|
+
else
|
|
238
|
+
if split.size == 2
|
|
239
|
+
# search for association and assign it to self
|
|
240
|
+
assoc_name, assoc_method = split
|
|
241
|
+
relationship=self.class.relationships[assoc_name]
|
|
242
|
+
|
|
243
|
+
if relationship
|
|
244
|
+
if relationship.kind_of? ::DataMapper::Associations::OneToOne::Relationship
|
|
245
|
+
assoc_instance=self.send(assoc_name)
|
|
246
|
+
if assoc_instance
|
|
247
|
+
assoc_instance.send("#{assoc_method}=", v)
|
|
248
|
+
assoc_instance.save # what should we do when this fails?..
|
|
249
|
+
else
|
|
250
|
+
# what should we do in this case?
|
|
251
|
+
end
|
|
252
|
+
else
|
|
253
|
+
self.send("#{self.class.data_adapter.foreign_key_for assoc_name}=", v)
|
|
254
|
+
end
|
|
255
|
+
else
|
|
256
|
+
::Rails.logger.debug "Netzke::Basepack: Association #{assoc} is not known for class #{self.class.name}"
|
|
257
|
+
end
|
|
258
|
+
else
|
|
259
|
+
::Rails.logger.debug "Netzke::Basepack: Wrong attribute name: #{a[:name]}"
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
protected
|
|
266
|
+
# Returns true if passed attribute is an "association attribute"
|
|
267
|
+
def is_association_attr?(a)
|
|
268
|
+
# maybe the check is too simplistic, but will do for now
|
|
269
|
+
!!a[:name].to_s.index("__")
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
end
|