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,281 @@
|
|
1
|
+
Ext.namespace('Ext.ux.dd');
|
2
|
+
|
3
|
+
Ext.ux.dd.GridDragDropRowOrder = Ext.extend(Ext.util.Observable,
|
4
|
+
{
|
5
|
+
copy: false,
|
6
|
+
|
7
|
+
scrollable: false,
|
8
|
+
|
9
|
+
constructor : function(config)
|
10
|
+
{
|
11
|
+
Ext.ux.dd.GridDragDropRowOrder.superclass.constructor.call(this);
|
12
|
+
if (config)
|
13
|
+
Ext.apply(this, config);
|
14
|
+
|
15
|
+
this.addEvents(
|
16
|
+
{
|
17
|
+
beforerowmove: true,
|
18
|
+
afterrowmove: true,
|
19
|
+
beforerowcopy: true,
|
20
|
+
afterrowcopy: true
|
21
|
+
});
|
22
|
+
},
|
23
|
+
|
24
|
+
init : function (grid)
|
25
|
+
{
|
26
|
+
this.grid = grid;
|
27
|
+
grid.enableDragDrop = true;
|
28
|
+
|
29
|
+
grid.on({
|
30
|
+
render: { fn: this.onGridRender, scope: this, single: true }
|
31
|
+
});
|
32
|
+
},
|
33
|
+
|
34
|
+
onGridRender : function (grid)
|
35
|
+
{
|
36
|
+
var self = this;
|
37
|
+
|
38
|
+
this.target = new Ext.dd.DropTarget(grid.getEl(),
|
39
|
+
{
|
40
|
+
ddGroup: grid.ddGroup || 'GridDD',
|
41
|
+
grid: grid,
|
42
|
+
gridDropTarget: this,
|
43
|
+
|
44
|
+
notifyDrop: function(dd, e, data)
|
45
|
+
{
|
46
|
+
// Remove drag lines. The 'if' condition prevents null error when drop occurs without dragging out of the selection area
|
47
|
+
if (this.currentRowEl)
|
48
|
+
{
|
49
|
+
this.currentRowEl.removeClass('grid-row-insert-below');
|
50
|
+
this.currentRowEl.removeClass('grid-row-insert-above');
|
51
|
+
}
|
52
|
+
|
53
|
+
// determine the row
|
54
|
+
var t = Ext.lib.Event.getTarget(e);
|
55
|
+
var rindex = this.grid.getView().findRowIndex(t);
|
56
|
+
if (rindex === false || rindex == data.rowIndex)
|
57
|
+
{
|
58
|
+
return false;
|
59
|
+
}
|
60
|
+
// fire the before move/copy event
|
61
|
+
if (this.gridDropTarget.fireEvent(self.copy ? 'beforerowcopy' : 'beforerowmove', this.gridDropTarget, data.rowIndex, rindex, data.selections, 123) === false)
|
62
|
+
{
|
63
|
+
return false;
|
64
|
+
}
|
65
|
+
|
66
|
+
// update the store
|
67
|
+
var ds = this.grid.getStore();
|
68
|
+
|
69
|
+
// Changes for multiselction by Spirit
|
70
|
+
var selections = new Array();
|
71
|
+
var keys = ds.data.keys;
|
72
|
+
for (var key in keys)
|
73
|
+
{
|
74
|
+
for (var i = 0; i < data.selections.length; i++)
|
75
|
+
{
|
76
|
+
if (keys[key] == data.selections[i].id)
|
77
|
+
{
|
78
|
+
// Exit to prevent drop of selected records on itself.
|
79
|
+
if (rindex == key)
|
80
|
+
{
|
81
|
+
return false;
|
82
|
+
}
|
83
|
+
selections.push(data.selections[i]);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
// fix rowindex based on before/after move
|
89
|
+
if (rindex > data.rowIndex && this.rowPosition < 0)
|
90
|
+
{
|
91
|
+
rindex--;
|
92
|
+
}
|
93
|
+
if (rindex < data.rowIndex && this.rowPosition > 0)
|
94
|
+
{
|
95
|
+
rindex++;
|
96
|
+
}
|
97
|
+
|
98
|
+
// fix rowindex for multiselection
|
99
|
+
if (rindex > data.rowIndex && data.selections.length > 1)
|
100
|
+
{
|
101
|
+
rindex = rindex - (data.selections.length - 1);
|
102
|
+
}
|
103
|
+
|
104
|
+
// we tried to move this node before the next sibling, we stay in place
|
105
|
+
if (rindex == data.rowIndex)
|
106
|
+
{
|
107
|
+
return false;
|
108
|
+
}
|
109
|
+
|
110
|
+
// fire the before move/copy event
|
111
|
+
/* dupe - does it belong here or above???
|
112
|
+
if (this.gridDropTarget.fireEvent(self.copy ? 'beforerowcopy' : 'beforerowmove', this.gridDropTarget, data.rowIndex, rindex, data.selections, 123) === false)
|
113
|
+
{
|
114
|
+
return false;
|
115
|
+
}
|
116
|
+
*/
|
117
|
+
|
118
|
+
if (!self.copy)
|
119
|
+
{
|
120
|
+
for (var i = 0; i < data.selections.length; i++)
|
121
|
+
{
|
122
|
+
ds.remove(ds.getById(data.selections[i].id));
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
for (var i = selections.length - 1; i >= 0; i--)
|
127
|
+
{
|
128
|
+
var insertIndex = rindex;
|
129
|
+
ds.insert(insertIndex, selections[i]);
|
130
|
+
}
|
131
|
+
|
132
|
+
// re-select the row(s)
|
133
|
+
var sm = this.grid.getSelectionModel();
|
134
|
+
if (sm)
|
135
|
+
{
|
136
|
+
sm.selectRecords(data.selections);
|
137
|
+
}
|
138
|
+
|
139
|
+
// console.info(this.gridDropTarget);
|
140
|
+
|
141
|
+
// fire the after move/copy event
|
142
|
+
this.gridDropTarget.fireEvent(self.copy ? 'afterrowcopy' : 'afterrowmove', this.gridDropTarget, data.rowIndex, rindex, data.selections);
|
143
|
+
return true;
|
144
|
+
},
|
145
|
+
|
146
|
+
notifyOver: function(dd, e, data)
|
147
|
+
{
|
148
|
+
// WIP: todo - rewrite Ext.lib call to Ext 4
|
149
|
+
var t = Ext.lib.Event.getTarget(e);
|
150
|
+
var rindex = this.grid.getView().findRowIndex(t);
|
151
|
+
|
152
|
+
// Similar to the code in notifyDrop. Filters for selected rows and quits function if any one row matches the current selected row.
|
153
|
+
var ds = this.grid.getStore();
|
154
|
+
var keys = ds.data.keys;
|
155
|
+
for (var key in keys)
|
156
|
+
{
|
157
|
+
for (var i = 0; i < data.selections.length; i++)
|
158
|
+
{
|
159
|
+
if (keys[key] == data.selections[i].id)
|
160
|
+
{
|
161
|
+
if (rindex == key)
|
162
|
+
{
|
163
|
+
if (this.currentRowEl)
|
164
|
+
{
|
165
|
+
this.currentRowEl.removeClass('grid-row-insert-below');
|
166
|
+
this.currentRowEl.removeClass('grid-row-insert-above');
|
167
|
+
}
|
168
|
+
return this.dropNotAllowed;
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
}
|
173
|
+
|
174
|
+
// If on first row, remove upper line. Prevents negative index error as a result of rindex going negative.
|
175
|
+
if (rindex < 0 || rindex === false)
|
176
|
+
{
|
177
|
+
this.currentRowEl.removeClass('grid-row-insert-above');
|
178
|
+
return this.dropNotAllowed;
|
179
|
+
}
|
180
|
+
|
181
|
+
try
|
182
|
+
{
|
183
|
+
var currentRow = this.grid.getView().getRow(rindex);
|
184
|
+
// Find position of row relative to page (adjusting for grid's scroll position)
|
185
|
+
var resolvedRow = new Ext.Element(currentRow).getY() - this.grid.getView().scroller.dom.scrollTop;
|
186
|
+
var rowHeight = currentRow.offsetHeight;
|
187
|
+
|
188
|
+
// Cursor relative to a row. -ve value implies cursor is above the row's middle and +ve value implues cursor is below the row's middle.
|
189
|
+
this.rowPosition = e.getPageY() - resolvedRow - (rowHeight/2);
|
190
|
+
|
191
|
+
// Clear drag line.
|
192
|
+
if (this.currentRowEl)
|
193
|
+
{
|
194
|
+
this.currentRowEl.removeClass('grid-row-insert-below');
|
195
|
+
this.currentRowEl.removeClass('grid-row-insert-above');
|
196
|
+
}
|
197
|
+
|
198
|
+
if (this.rowPosition > 0)
|
199
|
+
{
|
200
|
+
// If the pointer is on the bottom half of the row.
|
201
|
+
this.currentRowEl = new Ext.Element(currentRow);
|
202
|
+
this.currentRowEl.addClass('grid-row-insert-below');
|
203
|
+
}
|
204
|
+
else
|
205
|
+
{
|
206
|
+
// If the pointer is on the top half of the row.
|
207
|
+
if (rindex - 1 >= 0)
|
208
|
+
{
|
209
|
+
var previousRow = this.grid.getView().getRow(rindex - 1);
|
210
|
+
this.currentRowEl = new Ext.Element(previousRow);
|
211
|
+
this.currentRowEl.addClass('grid-row-insert-below');
|
212
|
+
}
|
213
|
+
else
|
214
|
+
{
|
215
|
+
// If the pointer is on the top half of the first row.
|
216
|
+
this.currentRowEl.addClass('grid-row-insert-above');
|
217
|
+
}
|
218
|
+
}
|
219
|
+
}
|
220
|
+
catch (err)
|
221
|
+
{
|
222
|
+
console.warn(err);
|
223
|
+
rindex = false;
|
224
|
+
}
|
225
|
+
return (rindex === false)? this.dropNotAllowed : this.dropAllowed;
|
226
|
+
},
|
227
|
+
|
228
|
+
notifyOut: function(dd, e, data)
|
229
|
+
{
|
230
|
+
// Remove drag lines when pointer leaves the gridView.
|
231
|
+
if (this.currentRowEl)
|
232
|
+
{
|
233
|
+
this.currentRowEl.removeClass('grid-row-insert-above');
|
234
|
+
this.currentRowEl.removeClass('grid-row-insert-below');
|
235
|
+
}
|
236
|
+
}
|
237
|
+
});
|
238
|
+
|
239
|
+
if (this.targetCfg)
|
240
|
+
{
|
241
|
+
Ext.apply(this.target, this.targetCfg);
|
242
|
+
}
|
243
|
+
|
244
|
+
if (this.scrollable)
|
245
|
+
{
|
246
|
+
Ext.dd.ScrollManager.register(grid.getView().getEditorParent());
|
247
|
+
grid.on({
|
248
|
+
beforedestroy: this.onBeforeDestroy,
|
249
|
+
scope: this,
|
250
|
+
single: true
|
251
|
+
});
|
252
|
+
}
|
253
|
+
},
|
254
|
+
|
255
|
+
getTarget: function()
|
256
|
+
{
|
257
|
+
return this.target;
|
258
|
+
},
|
259
|
+
|
260
|
+
getGrid: function()
|
261
|
+
{
|
262
|
+
return this.grid;
|
263
|
+
},
|
264
|
+
|
265
|
+
getCopy: function()
|
266
|
+
{
|
267
|
+
return this.copy ? true : false;
|
268
|
+
},
|
269
|
+
|
270
|
+
setCopy: function(b)
|
271
|
+
{
|
272
|
+
this.copy = b ? true : false;
|
273
|
+
},
|
274
|
+
|
275
|
+
onBeforeDestroy : function (grid)
|
276
|
+
{
|
277
|
+
// if we previously registered with the scroll manager, unregister
|
278
|
+
// it (if we don't it will lead to problems in IE)
|
279
|
+
Ext.dd.ScrollManager.unregister(grid.getView().getEditorParent());
|
280
|
+
}
|
281
|
+
});
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Netzke
|
2
|
+
module Basepack
|
3
|
+
class GridPanel < Netzke::Base
|
4
|
+
class RecordFormWindow < Window
|
5
|
+
|
6
|
+
js_properties :button_align => :right,
|
7
|
+
:width => 400,
|
8
|
+
:auto_height => true,
|
9
|
+
:modal => true,
|
10
|
+
:fbar => [:ok.action, :cancel.action]
|
11
|
+
|
12
|
+
action :ok do
|
13
|
+
{ :text => I18n.t('netzke.basepack.grid_panel.record_form_window.actions.ok')}
|
14
|
+
end
|
15
|
+
|
16
|
+
action :cancel do
|
17
|
+
{ :text => I18n.t('netzke.basepack.grid_panel.record_form_window.actions.cancel')}
|
18
|
+
end
|
19
|
+
|
20
|
+
js_method :init_component, <<-JS
|
21
|
+
function(params){
|
22
|
+
this.callParent();
|
23
|
+
this.items.first().on("submitsuccess", function(){ this.closeRes = "ok"; this.close(); }, this);
|
24
|
+
}
|
25
|
+
JS
|
26
|
+
|
27
|
+
js_method :on_ok, <<-JS
|
28
|
+
function(params){
|
29
|
+
this.items.first().onApply();
|
30
|
+
}
|
31
|
+
JS
|
32
|
+
|
33
|
+
js_method :on_cancel, <<-JS
|
34
|
+
function(params){
|
35
|
+
this.close();
|
36
|
+
}
|
37
|
+
JS
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,235 @@
|
|
1
|
+
module Netzke
|
2
|
+
module Basepack
|
3
|
+
class GridPanel < Netzke::Base
|
4
|
+
module Services
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
|
9
|
+
endpoint :get_data do |params|
|
10
|
+
get_data(params)
|
11
|
+
end
|
12
|
+
|
13
|
+
endpoint :post_data do |params|
|
14
|
+
mod_records = {}
|
15
|
+
[:create, :update].each do |operation|
|
16
|
+
data = ActiveSupport::JSON.decode(params["#{operation}d_records"]) if params["#{operation}d_records"]
|
17
|
+
if !data.nil? && !data.empty? # data may be nil for one of the operations
|
18
|
+
mod_records[operation] = process_data(data, operation)
|
19
|
+
mod_records[operation] = nil if mod_records[operation].empty?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
on_data_changed
|
24
|
+
|
25
|
+
{
|
26
|
+
:update_new_records => mod_records[:create],
|
27
|
+
:update_mod_records => mod_records[:update] || {},
|
28
|
+
:netzke_feedback => @flash
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
endpoint :delete_data do |params|
|
33
|
+
if !config[:prohibit_delete]
|
34
|
+
record_ids = ActiveSupport::JSON.decode(params[:records])
|
35
|
+
data_adapter.destroy(record_ids)
|
36
|
+
on_data_changed
|
37
|
+
{:netzke_feedback => I18n.t('netzke.basepack.grid_panel.deleted_n_records', :n => record_ids.size), :load_store_data => get_data}
|
38
|
+
else
|
39
|
+
{:netzke_feedback => I18n.t('netzke.basepack.grid_panel.cannot_delete')}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
endpoint :resize_column do |params|
|
44
|
+
raise "Called resize_column endpoint while not configured to do so" if !config[:persistence]
|
45
|
+
current_columns_order = state[:columns_order] || initial_columns_order
|
46
|
+
current_columns_order[normalize_index(params[:index].to_i)][:width] = params[:size].to_i
|
47
|
+
update_state(:columns_order, current_columns_order)
|
48
|
+
{}
|
49
|
+
end
|
50
|
+
|
51
|
+
endpoint :move_column do |params|
|
52
|
+
raise "Called move_column endpoint while not configured to do so" if !config[:persistence]
|
53
|
+
remove_from = normalize_index(params[:old_index].to_i)
|
54
|
+
insert_to = normalize_index(params[:new_index].to_i)
|
55
|
+
|
56
|
+
current_columns_order = state[:columns_order] || initial_columns_order
|
57
|
+
|
58
|
+
column_to_move = current_columns_order.delete_at(remove_from)
|
59
|
+
current_columns_order.insert(insert_to, column_to_move)
|
60
|
+
|
61
|
+
update_state(:columns_order, current_columns_order)
|
62
|
+
|
63
|
+
{}
|
64
|
+
end
|
65
|
+
|
66
|
+
endpoint :hide_column do |params|
|
67
|
+
raise "Called hide_column endpoint while not configured to do so" if !config[:persistence]
|
68
|
+
current_columns_order = state[:columns_order] || initial_columns_order
|
69
|
+
current_columns_order[normalize_index(params[:index].to_i)][:hidden] = params[:hidden]
|
70
|
+
update_state(:columns_order, current_columns_order)
|
71
|
+
{}
|
72
|
+
end
|
73
|
+
|
74
|
+
# Returns choices for a column
|
75
|
+
endpoint :get_combobox_options do |params|
|
76
|
+
query = params[:query]
|
77
|
+
|
78
|
+
column = columns.detect{ |c| c[:name] == params[:column] }
|
79
|
+
scope = column.to_options[:scope] || column.to_options[:editor].try(:fetch, :scope, nil)
|
80
|
+
query = params[:query]
|
81
|
+
|
82
|
+
{:data => combobox_options_for_column(column, :query => query, :scope => scope, :record_id => params[:id])}
|
83
|
+
end
|
84
|
+
|
85
|
+
endpoint :move_rows do |params|
|
86
|
+
data_adapter.move_records(params)
|
87
|
+
{}
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
#
|
92
|
+
# Some components' overridden endpoints
|
93
|
+
#
|
94
|
+
|
95
|
+
## Edit in form specific endpoint
|
96
|
+
def add_form__form_panel0__netzke_submit_endpoint(params)
|
97
|
+
res = component_instance(:add_form__form_panel0).netzke_submit(params)
|
98
|
+
|
99
|
+
if res[:set_form_values]
|
100
|
+
# successful creation
|
101
|
+
on_data_changed
|
102
|
+
res[:set_form_values] = nil
|
103
|
+
end
|
104
|
+
res.to_nifty_json
|
105
|
+
end
|
106
|
+
|
107
|
+
def edit_form__form_panel0__netzke_submit_endpoint(params)
|
108
|
+
res = component_instance(:edit_form__form_panel0).netzke_submit(params)
|
109
|
+
|
110
|
+
if res[:set_form_values]
|
111
|
+
on_data_changed
|
112
|
+
res[:set_form_values] = nil
|
113
|
+
end
|
114
|
+
|
115
|
+
res.to_nifty_json
|
116
|
+
end
|
117
|
+
|
118
|
+
def multi_edit_form__multi_edit_form0__netzke_submit_endpoint(params)
|
119
|
+
ids = ActiveSupport::JSON.decode(params.delete(:ids))
|
120
|
+
data = ids.collect{ |id| ActiveSupport::JSON.decode(params[:data]).merge("id" => id) }
|
121
|
+
|
122
|
+
data.map!{|el| el.delete_if{ |k,v| v.is_a?(String) && v.blank? }} # only interested in set values
|
123
|
+
|
124
|
+
mod_records_count = process_data(data, :update).count
|
125
|
+
|
126
|
+
# remove duplicated flash messages
|
127
|
+
@flash = @flash.inject([]){ |r,hsh| r.include?(hsh) ? r : r.push(hsh) }
|
128
|
+
|
129
|
+
if mod_records_count > 0
|
130
|
+
on_data_changed
|
131
|
+
{:set_result => "ok", :netzke_feedback => @flash}.to_nifty_json
|
132
|
+
else
|
133
|
+
{:netzke_feedback => @flash}.to_nifty_json
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# When providing the edit_form component, fill in the form with the requested record
|
138
|
+
def deliver_component_endpoint(params)
|
139
|
+
components[:edit_form][:items].first.merge!(:record_id => params[:record_id].to_i) if params[:name] == 'edit_form'
|
140
|
+
super
|
141
|
+
end
|
142
|
+
|
143
|
+
# Implementation for the "get_data" endpoint
|
144
|
+
def get_data(*args)
|
145
|
+
params = args.first || {} # params are optional!
|
146
|
+
if !config[:prohibit_read]
|
147
|
+
{}.tap do |res|
|
148
|
+
records = get_records(params)
|
149
|
+
res[:data] = records.map{|r| r.netzke_array(columns(:with_meta => true))}
|
150
|
+
res[:total] = count_records(params) if config[:enable_pagination]
|
151
|
+
end
|
152
|
+
else
|
153
|
+
flash :error => "You don't have permissions to read data"
|
154
|
+
{ :netzke_feedback => @flash }
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
protected
|
159
|
+
|
160
|
+
# Returns an array of records.
|
161
|
+
def get_records(params)
|
162
|
+
params[:limit] = config[:rows_per_page] if config[:enable_pagination]
|
163
|
+
params[:scope] = config[:scope] # note, params[:scope] becomes ActiveSupport::HashWithIndifferentAccess
|
164
|
+
|
165
|
+
data_adapter.get_records(params, columns)
|
166
|
+
end
|
167
|
+
|
168
|
+
def count_records(params)
|
169
|
+
params[:scope] = config[:scope] # note, params[:scope] becomes ActiveSupport::HashWithIndifferentAccess
|
170
|
+
|
171
|
+
data_adapter.count_records(params, columns)
|
172
|
+
end
|
173
|
+
|
174
|
+
# Override this method to react on each operation that caused changing of data
|
175
|
+
def on_data_changed; end
|
176
|
+
|
177
|
+
# Given an index of a column among enabled (non-excluded) columns, provides the index (position) in the table
|
178
|
+
def normalize_index(index)
|
179
|
+
norm_index = 0
|
180
|
+
index.times do
|
181
|
+
while true do
|
182
|
+
norm_index += 1
|
183
|
+
break unless columns[norm_index][:included] == false
|
184
|
+
end
|
185
|
+
end
|
186
|
+
norm_index
|
187
|
+
end
|
188
|
+
|
189
|
+
# Params:
|
190
|
+
# <tt>:operation</tt>: :update or :create
|
191
|
+
def process_data(data, operation)
|
192
|
+
success = true
|
193
|
+
mod_records = {}
|
194
|
+
if !config[:"prohibit_#{operation}"]
|
195
|
+
modified_records = 0
|
196
|
+
data.each do |record_hash|
|
197
|
+
id = record_hash.delete('id')
|
198
|
+
record = operation == :create ? data_adapter.new_record : data_adapter.find_record(id)
|
199
|
+
success = true
|
200
|
+
|
201
|
+
# merge with strong default attirbutes
|
202
|
+
record_hash.merge!(config[:strong_default_attrs]) if config[:strong_default_attrs]
|
203
|
+
|
204
|
+
record_hash.each_pair do |k,v|
|
205
|
+
record.set_value_for_attribute(columns_hash[k.to_sym].nil? ? {:name => k} : columns_hash[k.to_sym], v)
|
206
|
+
end
|
207
|
+
|
208
|
+
# try to save
|
209
|
+
mod_records[id] = record.netzke_array(columns(:with_meta => true)) if success && record.save
|
210
|
+
|
211
|
+
# flash eventual errors
|
212
|
+
if !record.errors.empty?
|
213
|
+
success = false
|
214
|
+
record.errors.to_a.each do |msg|
|
215
|
+
flash :error => msg
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
else
|
220
|
+
success = false
|
221
|
+
flash :error => "You don't have permissions to #{operation} data"
|
222
|
+
end
|
223
|
+
mod_records
|
224
|
+
end
|
225
|
+
|
226
|
+
def normalize_extra_conditions(conditions)
|
227
|
+
conditions.each_pair do |k,v|
|
228
|
+
conditions[k] = "%#{v}%" if ["like", "matches"].include?(k.to_s.split("__").last)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|