netzke-basepack-zh 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- 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,10 @@
|
|
1
|
+
module Netzke
|
2
|
+
class BasepackGenerator < ::Rails::Generators::Base
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
|
5
|
+
desc 'Copies necessary assets to public/netzke/basepack'
|
6
|
+
def execute
|
7
|
+
copy_file 'assets/ts-checkbox.gif', "public/netzke/basepack/ts-checkbox.gif"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
Binary file
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateNetzkeFieldLists < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :netzke_field_lists do |t|
|
4
|
+
t.string :name
|
5
|
+
t.text :value
|
6
|
+
t.string :model_name
|
7
|
+
t.integer :user_id
|
8
|
+
t.integer :role_id
|
9
|
+
t.string :type
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
drop_table :netzke_field_lists
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# External dependencies
|
2
|
+
require 'netzke-core'
|
3
|
+
require 'active_support/dependencies'
|
4
|
+
|
5
|
+
# Make components auto-loadable
|
6
|
+
ActiveSupport::Dependencies.autoload_paths << File.dirname(__FILE__)
|
7
|
+
|
8
|
+
require 'netzke/basepack'
|
9
|
+
|
10
|
+
module Netzke
|
11
|
+
module Basepack
|
12
|
+
class Engine < Rails::Engine
|
13
|
+
|
14
|
+
I18n.load_path << File.dirname(__FILE__) + '/../locales/en.yml'
|
15
|
+
I18n.load_path << File.dirname(__FILE__) + '/../locales/de.yml'
|
16
|
+
|
17
|
+
config.after_initialize do
|
18
|
+
Netzke::Core.external_ext_css << "#{Netzke::Core.ext_uri}/examples/ux/grid/css/RangeMenu"
|
19
|
+
Netzke::Core.external_ext_css << "#{Netzke::Core.ext_uri}/examples/ux/grid/css/GridFilters"
|
20
|
+
Netzke::Core.external_ext_css << "#{Netzke::Core.ext_uri}/examples/ux/css/CheckHeader"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Netzke::Basepack.init
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'netzke/active_record/attributes'
|
2
|
+
require 'netzke/active_record/combobox_options'
|
3
|
+
require 'netzke/active_record/relation_extensions'
|
4
|
+
|
5
|
+
module Netzke
|
6
|
+
module ActiveRecord
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
if defined? ActiveRecord
|
11
|
+
# Extend ActiveRecord
|
12
|
+
ActiveRecord::Base.class_eval do
|
13
|
+
include ::Netzke::ActiveRecord::Attributes
|
14
|
+
include ::Netzke::ActiveRecord::ComboboxOptions
|
15
|
+
end
|
16
|
+
|
17
|
+
ActiveRecord::Relation.class_eval do
|
18
|
+
include ::Netzke::ActiveRecord::RelationExtensions
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,256 @@
|
|
1
|
+
module Netzke
|
2
|
+
module ActiveRecord
|
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
|
+
@data_adapter = 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
|
+
private
|
82
|
+
|
83
|
+
def netzke_attrs_in_forced_order(attrs)
|
84
|
+
attrs.collect do |attr_name|
|
85
|
+
declared = self.netzke_declared_attr.detect { |va| va[:name] == attr_name } || {}
|
86
|
+
in_columns_hash = columns_hash[attr_name] && {:name => attr_name, :attr_type => columns_hash[attr_name].type, :default_value => columns_hash[attr_name].default} || {} # {:virtual => true} # if nothing found in columns, mark it as "virtual" or not?
|
87
|
+
if in_columns_hash.empty?
|
88
|
+
# If not among the model columns, it's either virtual, or an association
|
89
|
+
merged = association_attr?(attr_name) ? declared.merge!(:name => attr_name) : declared.merge(:virtual => true)
|
90
|
+
else
|
91
|
+
# .. otherwise merge with what's declared
|
92
|
+
merged = in_columns_hash.merge(declared)
|
93
|
+
end
|
94
|
+
|
95
|
+
# We didn't find it among declared, nor among the model columns, nor does it seem association attribute
|
96
|
+
merged[:name].nil? && raise(ArgumentError, "Unknown attribute '#{attr_name}' for model #{self.name}", caller)
|
97
|
+
|
98
|
+
merged
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Returns netzke attributes in the order of columns in the table, followed by extra declared attributes
|
103
|
+
# Detects one-to-many association columns and replaces the name of the column with association column name (Netzke style), e.g.:
|
104
|
+
#
|
105
|
+
# role_id => role__name
|
106
|
+
def netzke_attrs_in_natural_order
|
107
|
+
(
|
108
|
+
declared_attrs = self.netzke_declared_attr
|
109
|
+
|
110
|
+
column_names.map do |name|
|
111
|
+
c = {:name => name, :attr_type => columns_hash[name].type}
|
112
|
+
|
113
|
+
# If it's named as foreign key of some association, then it's an association column
|
114
|
+
assoc = reflect_on_all_associations.detect { |a| foreign_key_for_assoc(a) == c[:name] }
|
115
|
+
|
116
|
+
if assoc && !assoc.options[:polymorphic]
|
117
|
+
candidates = %w{name title label} << foreign_key_for_assoc(assoc)
|
118
|
+
assoc_method = candidates.detect{|m| (assoc.klass.instance_methods.map(&:to_s) + assoc.klass.column_names).include?(m) }
|
119
|
+
c[:name] = "#{assoc.name}__#{assoc_method}"
|
120
|
+
c[:attr_type] = :integer # when it's an instance method rather than a column, fall back to :string
|
121
|
+
end
|
122
|
+
|
123
|
+
# auto set up the default value from the column settings
|
124
|
+
c.merge!(:default_value => columns_hash[name].default) if columns_hash[name].default
|
125
|
+
|
126
|
+
# if there's a declared attr with the same name, simply merge it with what's taken from the model's columns
|
127
|
+
if declared = declared_attrs.detect{ |va| va[:name] == c[:name] }
|
128
|
+
c.merge!(declared)
|
129
|
+
declared_attrs.delete(declared)
|
130
|
+
end
|
131
|
+
c
|
132
|
+
end +
|
133
|
+
declared_attrs
|
134
|
+
).reject { |attr| self.netzke_excluded_attr.include?(attr[:name]) }
|
135
|
+
end
|
136
|
+
|
137
|
+
# Returns foreign key for given association (Rails >= 3.0)
|
138
|
+
def foreign_key_for_assoc(assoc)
|
139
|
+
assoc.respond_to?(:foreign_key) ? assoc.foreign_key : assoc.primary_key_name
|
140
|
+
end
|
141
|
+
|
142
|
+
def association_attr?(attr_name)
|
143
|
+
!!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
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
# Transforms a record to array of values according to the passed attributes
|
149
|
+
def netzke_array(attributes = self.class.netzke_attributes)
|
150
|
+
res = []
|
151
|
+
for a in attributes
|
152
|
+
next if a[:included] == false
|
153
|
+
res << value_for_attribute(a, a[:nested_attribute])
|
154
|
+
end
|
155
|
+
res
|
156
|
+
end
|
157
|
+
|
158
|
+
def netzke_json
|
159
|
+
netzke_hash.to_nifty_json
|
160
|
+
end
|
161
|
+
|
162
|
+
# Accepts both hash and array of attributes
|
163
|
+
def netzke_hash(attributes = self.class.netzke_attributes)
|
164
|
+
res = {}
|
165
|
+
for a in (attributes.is_a?(Hash) ? attributes.values : attributes)
|
166
|
+
next if a[:included] == false
|
167
|
+
res[a[:name].to_sym] = self.value_for_attribute(a, a[:nested_attribute])
|
168
|
+
end
|
169
|
+
res
|
170
|
+
end
|
171
|
+
|
172
|
+
# Fetches the value specified by an (association) attribute
|
173
|
+
# If +through_association+ is true, get the value of the association by provided method, *not* the associated record's id
|
174
|
+
# 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
|
175
|
+
def value_for_attribute(a, through_association = false)
|
176
|
+
v = if a[:getter]
|
177
|
+
a[:getter].call(self)
|
178
|
+
elsif respond_to?("#{a[:name]}")
|
179
|
+
send("#{a[:name]}")
|
180
|
+
elsif is_association_attr?(a)
|
181
|
+
split = a[:name].to_s.split(/\.|__/)
|
182
|
+
assoc = self.class.reflect_on_association(split.first.to_sym)
|
183
|
+
if through_association
|
184
|
+
split.inject(self) do |r,m| # TODO: do we really need to descend deeper than 1 level?
|
185
|
+
if r.respond_to?(m)
|
186
|
+
r.send(m)
|
187
|
+
else
|
188
|
+
logger.debug "Netzke::Basepack: Wrong attribute name: #{a[:name]}" unless r.nil?
|
189
|
+
nil
|
190
|
+
end
|
191
|
+
end
|
192
|
+
else
|
193
|
+
self.send("#{assoc.options[:foreign_key] || assoc.name.to_s.foreign_key}")
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
# a work-around for to_json not taking the current timezone into account when serializing ActiveSupport::TimeWithZone
|
198
|
+
v = v.to_datetime.to_s(:db) if [ActiveSupport::TimeWithZone].include?(v.class)
|
199
|
+
|
200
|
+
v
|
201
|
+
end
|
202
|
+
|
203
|
+
# Assigns new value to an (association) attribute
|
204
|
+
def set_value_for_attribute(a, v)
|
205
|
+
v = v.to_time_in_current_zone if v.is_a?(Date) # convert Date to Time
|
206
|
+
|
207
|
+
if a[:setter]
|
208
|
+
a[:setter].call(self, v)
|
209
|
+
elsif respond_to?("#{a[:name]}=")
|
210
|
+
send("#{a[:name]}=", v)
|
211
|
+
elsif is_association_attr?(a)
|
212
|
+
split = a[:name].to_s.split(/\.|__/)
|
213
|
+
if a[:nested_attribute]
|
214
|
+
# We want:
|
215
|
+
# set_value_for_attribute({:name => :assoc_1__assoc_2__method, :nested_attribute => true}, 100)
|
216
|
+
# =>
|
217
|
+
# self.assoc_1.assoc_2.method = 100
|
218
|
+
split.inject(self) { |r,m| m == split.last ? (r && r.send("#{m}=", v) && r.save) : r.send(m) }
|
219
|
+
else
|
220
|
+
if split.size == 2
|
221
|
+
# search for association and assign it to self
|
222
|
+
assoc = self.class.reflect_on_association(split.first.to_sym)
|
223
|
+
assoc_method = split.last
|
224
|
+
if assoc
|
225
|
+
if assoc.macro == :has_one
|
226
|
+
assoc_instance = self.send(assoc.name)
|
227
|
+
if assoc_instance
|
228
|
+
assoc_instance.send("#{assoc_method}=", v)
|
229
|
+
assoc_instance.save # what should we do when this fails?..
|
230
|
+
else
|
231
|
+
# what should we do in this case?
|
232
|
+
end
|
233
|
+
else
|
234
|
+
self.send("#{assoc.options[:foreign_key] || assoc.name.to_s.foreign_key}=", v)
|
235
|
+
end
|
236
|
+
else
|
237
|
+
logger.debug "Netzke::Basepack: Association #{assoc} is not known for class #{self.class.name}"
|
238
|
+
end
|
239
|
+
else
|
240
|
+
logger.debug "Netzke::Basepack: Wrong attribute name: #{a[:name]}"
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
protected
|
247
|
+
|
248
|
+
# Returns true if passed attribute is an "association attribute"
|
249
|
+
def is_association_attr?(a)
|
250
|
+
# maybe the check is too simplistic, but will do for now
|
251
|
+
!!a[:name].to_s.index("__")
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Netzke
|
2
|
+
module ActiveRecord
|
3
|
+
module ComboboxOptions
|
4
|
+
module ClassMethods
|
5
|
+
def netzke_combo_options_for(column, query = "")
|
6
|
+
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}%'")
|
7
|
+
records.map{|r| r.send(column)}
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.included(receiver)
|
12
|
+
receiver.extend ClassMethods
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,37 @@
|
|
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 "ActiveSupport::HashWithIndifferentAccess" # conditions hash
|
17
|
+
self.where(scope)
|
18
|
+
when "Proc" # receives a relation, must return a relation
|
19
|
+
scope.call(self)
|
20
|
+
else
|
21
|
+
raise ArgumentError, "Wrong parameter type for ActiveRecord::Relation#extend_with"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Non-destructively extends itself whith a hash of double-underscore'd conditions,
|
26
|
+
# where the last part "__" is MetaWhere operator (which is required), e.g.:
|
27
|
+
# {:role__name__like => "%admin"}
|
28
|
+
def extend_with_netzke_conditions(cond)
|
29
|
+
cond.each_pair.inject(self) do |r, (k,v)|
|
30
|
+
assoc, method, *operator = k.to_s.split("__")
|
31
|
+
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)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'netzke/basepack/version'
|
2
|
+
|
3
|
+
if defined? ActiveRecord
|
4
|
+
require 'netzke/active_record'
|
5
|
+
end
|
6
|
+
if defined? DataMapper
|
7
|
+
require 'netzke/data_mapper'
|
8
|
+
end
|
9
|
+
if defined? Sequel
|
10
|
+
require 'netzke/sequel'
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'netzke/basepack/data_adapters/abstract_adapter'
|
14
|
+
require 'netzke/basepack/data_adapters/active_record_adapter' if defined? ActiveRecord
|
15
|
+
require 'netzke/basepack/data_adapters/data_mapper_adapter' if defined? DataMapper
|
16
|
+
require 'netzke/basepack/data_adapters/sequel_adapter' if defined? Sequel
|
17
|
+
|
18
|
+
module Netzke
|
19
|
+
module Basepack
|
20
|
+
mattr_accessor :with_icons
|
21
|
+
|
22
|
+
mattr_accessor :icons_uri
|
23
|
+
|
24
|
+
class << self
|
25
|
+
|
26
|
+
# Called from netzke-basepack.rb
|
27
|
+
def init
|
28
|
+
Netzke::Core.ext_javascripts << "#{File.dirname(__FILE__)}/../../javascripts/xdatetime.js"
|
29
|
+
Netzke::Core.ext_javascripts << "#{File.dirname(__FILE__)}/../../javascripts/basepack.js"
|
30
|
+
|
31
|
+
Netzke::Core.ext_stylesheets << "#{File.dirname(__FILE__)}/../../stylesheets/basepack.css"
|
32
|
+
end
|
33
|
+
|
34
|
+
# Use it to confirure Basepack in the initializers, e.g.:
|
35
|
+
#
|
36
|
+
# Netzke::Basepack.setup do |config|
|
37
|
+
# config.icons_uri = "/images/famfamfam/icons"
|
38
|
+
# end
|
39
|
+
def setup
|
40
|
+
yield self
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Netzke
|
2
|
+
module Basepack
|
3
|
+
# = AccordionPanel
|
4
|
+
#
|
5
|
+
# A panel with the 'accordion' layout. Can lazily load its nested components. For example:
|
6
|
+
#
|
7
|
+
# netzke :my_accordion, :items => [{
|
8
|
+
# :html => "I'm a simple Ext.Panel",
|
9
|
+
# :title => "Panel One"
|
10
|
+
# },{
|
11
|
+
# :class_name => "SimplePanel",
|
12
|
+
# :update_text => "Update for Panel Two",
|
13
|
+
# :title => "Panel Two",
|
14
|
+
# :lazy_loading => true
|
15
|
+
# }]
|
16
|
+
class AccordionPanel < Netzke::Base
|
17
|
+
|
18
|
+
include WrapLazyLoaded
|
19
|
+
|
20
|
+
js_property :layout, 'accordion'
|
21
|
+
js_property :component_load_mask, {:msg => null} # due to a probable bug in Ext's Accordion Layout (mask message is mis-layed-out), disabling mask message
|
22
|
+
|
23
|
+
js_method :init_component, <<-JS
|
24
|
+
function(params){
|
25
|
+
#{js_full_class_name}.superclass.initComponent.call(this);
|
26
|
+
this.items.each(function(item){
|
27
|
+
item.on('expand', function(i){
|
28
|
+
if (i && i.wrappedComponent && !i.items.first() && !i.beingLoaded) {
|
29
|
+
i.beingLoaded = true; // prevent more than one request per panel in case of fast clicking
|
30
|
+
this.loadNetzkeComponent({name: i.wrappedComponent, container: i.id}, function(){i.beingLoaded = false});
|
31
|
+
}
|
32
|
+
}, this);
|
33
|
+
}, this);
|
34
|
+
}
|
35
|
+
JS
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|