netzke-basepack-zh 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (268) hide show
  1. data/.autotest +1 -0
  2. data/.travis.yml +11 -0
  3. data/CHANGELOG.rdoc +445 -0
  4. data/LICENSE +1 -0
  5. data/README.md +94 -0
  6. data/Rakefile +44 -0
  7. data/TODO.rdoc +8 -0
  8. data/config/ci/before-travis.sh +28 -0
  9. data/init.rb +1 -0
  10. data/install.rb +1 -0
  11. data/javascripts/basepack.js +139 -0
  12. data/javascripts/xdatetime.js +196 -0
  13. data/lib/generators/netzke/basepack_generator.rb +10 -0
  14. data/lib/generators/netzke/templates/assets/ts-checkbox.gif +0 -0
  15. data/lib/generators/netzke/templates/create_netzke_field_lists.rb +18 -0
  16. data/lib/netzke-basepack.rb +26 -0
  17. data/lib/netzke/active_record.rb +20 -0
  18. data/lib/netzke/active_record/attributes.rb +256 -0
  19. data/lib/netzke/active_record/combobox_options.rb +16 -0
  20. data/lib/netzke/active_record/relation_extensions.rb +37 -0
  21. data/lib/netzke/basepack.rb +45 -0
  22. data/lib/netzke/basepack/accordion_panel.rb +39 -0
  23. data/lib/netzke/basepack/action_column.rb +68 -0
  24. data/lib/netzke/basepack/action_column/javascripts/action_column.js +61 -0
  25. data/lib/netzke/basepack/auth_app.rb +159 -0
  26. data/lib/netzke/basepack/basic_app.rb +7 -0
  27. data/lib/netzke/basepack/border_layout_panel.rb +53 -0
  28. data/lib/netzke/basepack/border_layout_panel/javascripts/border_layout_panel.js +40 -0
  29. data/lib/netzke/basepack/data_accessor.rb +53 -0
  30. data/lib/netzke/basepack/data_adapters/abstract_adapter.rb +164 -0
  31. data/lib/netzke/basepack/data_adapters/active_record_adapter.rb +279 -0
  32. data/lib/netzke/basepack/data_adapters/data_mapper_adapter.rb +264 -0
  33. data/lib/netzke/basepack/data_adapters/sequel_adapter.rb +260 -0
  34. data/lib/netzke/basepack/form_panel.rb +144 -0
  35. data/lib/netzke/basepack/form_panel/fields.rb +208 -0
  36. data/lib/netzke/basepack/form_panel/javascripts/comma_list_cbg.js +51 -0
  37. data/lib/netzke/basepack/form_panel/javascripts/form_panel.js +225 -0
  38. data/lib/netzke/basepack/form_panel/javascripts/misc.js +4 -0
  39. data/lib/netzke/basepack/form_panel/javascripts/n_radio_group.js +43 -0
  40. data/lib/netzke/basepack/form_panel/javascripts/readonly_mode.js +35 -0
  41. data/lib/netzke/basepack/form_panel/services.rb +142 -0
  42. data/lib/netzke/basepack/form_panel/stylesheets/readonly_mode.css +14 -0
  43. data/lib/netzke/basepack/grid_panel.rb +440 -0
  44. data/lib/netzke/basepack/grid_panel/columns.rb +394 -0
  45. data/lib/netzke/basepack/grid_panel/javascripts/advanced_search.js +27 -0
  46. data/lib/netzke/basepack/grid_panel/javascripts/check_column_fix.js +6 -0
  47. data/lib/netzke/basepack/grid_panel/javascripts/edit_in_form.js +51 -0
  48. data/lib/netzke/basepack/grid_panel/javascripts/event_handling.js +179 -0
  49. data/lib/netzke/basepack/grid_panel/javascripts/grid_panel.js +438 -0
  50. data/lib/netzke/basepack/grid_panel/javascripts/misc.js +4 -0
  51. data/lib/netzke/basepack/grid_panel/javascripts/rows-dd.js +281 -0
  52. data/lib/netzke/basepack/grid_panel/record_form_window.rb +41 -0
  53. data/lib/netzke/basepack/grid_panel/services.rb +235 -0
  54. data/lib/netzke/basepack/paging_form_panel.rb +72 -0
  55. data/lib/netzke/basepack/paging_form_panel/javascripts/paging_form_panel.js +76 -0
  56. data/lib/netzke/basepack/panel.rb +11 -0
  57. data/lib/netzke/basepack/query_builder.rb +107 -0
  58. data/lib/netzke/basepack/query_builder/javascripts/query_builder.js +153 -0
  59. data/lib/netzke/basepack/search_panel.rb +79 -0
  60. data/lib/netzke/basepack/search_panel/javascripts/condition_field.js +160 -0
  61. data/lib/netzke/basepack/search_panel/javascripts/search_panel.js +65 -0
  62. data/lib/netzke/basepack/search_window.rb +66 -0
  63. data/lib/netzke/basepack/simple_app.rb +104 -0
  64. data/lib/netzke/basepack/simple_app/javascripts/simple_app.js +64 -0
  65. data/lib/netzke/basepack/simple_app/javascripts/statusbar_ext.js +8 -0
  66. data/lib/netzke/basepack/tab_panel.rb +21 -0
  67. data/lib/netzke/basepack/tab_panel/javascripts/tab_panel.js +11 -0
  68. data/lib/netzke/basepack/version.rb +11 -0
  69. data/lib/netzke/basepack/window.rb +29 -0
  70. data/lib/netzke/basepack/window/javascripts/window.js +20 -0
  71. data/lib/netzke/basepack/wrap_lazy_loaded.rb +28 -0
  72. data/lib/netzke/basepack/wrapper.rb +28 -0
  73. data/lib/netzke/data_mapper.rb +18 -0
  74. data/lib/netzke/data_mapper/attributes.rb +273 -0
  75. data/lib/netzke/data_mapper/combobox_options.rb +11 -0
  76. data/lib/netzke/data_mapper/relation_extensions.rb +38 -0
  77. data/lib/netzke/sequel.rb +18 -0
  78. data/lib/netzke/sequel/attributes.rb +274 -0
  79. data/lib/netzke/sequel/combobox_options.rb +10 -0
  80. data/lib/netzke/sequel/relation_extensions.rb +40 -0
  81. data/lib/tasks/netzke_basepack_tasks.rake +4 -0
  82. data/locales/de.yml +79 -0
  83. data/locales/en.yml +79 -0
  84. data/netzke-basepack.gemspec +306 -0
  85. data/stylesheets/basepack.css +72 -0
  86. data/stylesheets/datetimefield.css +54 -0
  87. data/test/basepack_test_app/.gitignore +6 -0
  88. data/test/basepack_test_app/.rvmrc +1 -0
  89. data/test/basepack_test_app/Gemfile +59 -0
  90. data/test/basepack_test_app/Gemfile.lock +196 -0
  91. data/test/basepack_test_app/Guardfile +46 -0
  92. data/test/basepack_test_app/README +1 -0
  93. data/test/basepack_test_app/Rakefile +7 -0
  94. data/test/basepack_test_app/app/components/author_form.rb +32 -0
  95. data/test/basepack_test_app/app/components/author_grid.rb +3 -0
  96. data/test/basepack_test_app/app/components/book_form.rb +38 -0
  97. data/test/basepack_test_app/app/components/book_form_with_custom_fields.rb +21 -0
  98. data/test/basepack_test_app/app/components/book_form_with_defaults.rb +8 -0
  99. data/test/basepack_test_app/app/components/book_form_with_nested_attributes.rb +18 -0
  100. data/test/basepack_test_app/app/components/book_grid.rb +12 -0
  101. data/test/basepack_test_app/app/components/book_grid_filtering.rb +10 -0
  102. data/test/basepack_test_app/app/components/book_grid_loader.rb +24 -0
  103. data/test/basepack_test_app/app/components/book_grid_with_column_actions.rb +15 -0
  104. data/test/basepack_test_app/app/components/book_grid_with_custom_columns.rb +27 -0
  105. data/test/basepack_test_app/app/components/book_grid_with_default_values.rb +9 -0
  106. data/test/basepack_test_app/app/components/book_grid_with_extra_feedback.rb +8 -0
  107. data/test/basepack_test_app/app/components/book_grid_with_extra_filters.rb +14 -0
  108. data/test/basepack_test_app/app/components/book_grid_with_nested_attributes.rb +13 -0
  109. data/test/basepack_test_app/app/components/book_grid_with_overridden_columns.rb +15 -0
  110. data/test/basepack_test_app/app/components/book_grid_with_paging.rb +10 -0
  111. data/test/basepack_test_app/app/components/book_grid_with_persistence.rb +8 -0
  112. data/test/basepack_test_app/app/components/book_grid_with_scoped_authors.rb +8 -0
  113. data/test/basepack_test_app/app/components/book_grid_with_virtual_attributes.rb +21 -0
  114. data/test/basepack_test_app/app/components/book_paging_form_panel.rb +22 -0
  115. data/test/basepack_test_app/app/components/book_query_builder.rb +8 -0
  116. data/test/basepack_test_app/app/components/book_search_panel.rb +5 -0
  117. data/test/basepack_test_app/app/components/book_search_panel/javascripts/i18n_de.js +6 -0
  118. data/test/basepack_test_app/app/components/book_with_custom_primary_key_grid.rb +10 -0
  119. data/test/basepack_test_app/app/components/books_bound_to_author.rb +10 -0
  120. data/test/basepack_test_app/app/components/double_book_grid.rb +18 -0
  121. data/test/basepack_test_app/app/components/extras/book_presentation.rb +27 -0
  122. data/test/basepack_test_app/app/components/form_without_model.rb +21 -0
  123. data/test/basepack_test_app/app/components/generic_user_form.rb +12 -0
  124. data/test/basepack_test_app/app/components/lockable_book_form.rb +17 -0
  125. data/test/basepack_test_app/app/components/lockable_user_form.rb +7 -0
  126. data/test/basepack_test_app/app/components/paging_form_with_search.rb +40 -0
  127. data/test/basepack_test_app/app/components/simple_accordion.rb +11 -0
  128. data/test/basepack_test_app/app/components/simple_panel.rb +17 -0
  129. data/test/basepack_test_app/app/components/simple_tab_panel.rb +11 -0
  130. data/test/basepack_test_app/app/components/simple_window.rb +10 -0
  131. data/test/basepack_test_app/app/components/simple_wrapper.rb +7 -0
  132. data/test/basepack_test_app/app/components/some_accordion_panel.rb +22 -0
  133. data/test/basepack_test_app/app/components/some_auth_app.rb +32 -0
  134. data/test/basepack_test_app/app/components/some_border_layout.rb +28 -0
  135. data/test/basepack_test_app/app/components/some_simple_app.rb +35 -0
  136. data/test/basepack_test_app/app/components/some_tab_panel.rb +20 -0
  137. data/test/basepack_test_app/app/components/user_form.rb +25 -0
  138. data/test/basepack_test_app/app/components/user_form_with_default_fields.rb +8 -0
  139. data/test/basepack_test_app/app/components/user_grid.rb +8 -0
  140. data/test/basepack_test_app/app/components/user_grid_with_customized_form_fields.rb +18 -0
  141. data/test/basepack_test_app/app/components/window_component_loader.rb +27 -0
  142. data/test/basepack_test_app/app/controllers/application_controller.rb +9 -0
  143. data/test/basepack_test_app/app/controllers/components_controller.rb +10 -0
  144. data/test/basepack_test_app/app/controllers/welcome_controller.rb +9 -0
  145. data/test/basepack_test_app/app/helpers/application_helper.rb +8 -0
  146. data/test/basepack_test_app/app/helpers/embedded_components_helper.rb +2 -0
  147. data/test/basepack_test_app/app/models/address.rb +29 -0
  148. data/test/basepack_test_app/app/models/author.rb +38 -0
  149. data/test/basepack_test_app/app/models/book.rb +49 -0
  150. data/test/basepack_test_app/app/models/book_with_custom_primary_key.rb +26 -0
  151. data/test/basepack_test_app/app/models/role.rb +24 -0
  152. data/test/basepack_test_app/app/models/user.rb +29 -0
  153. data/test/basepack_test_app/app/presenters/forms/generic_user.rb +6 -0
  154. data/test/basepack_test_app/app/views/components/loadable_window.html.erb +9 -0
  155. data/test/basepack_test_app/app/views/components/simple_panel.html.erb +1 -0
  156. data/test/basepack_test_app/app/views/layouts/application.html.erb +12 -0
  157. data/test/basepack_test_app/app/views/layouts/components.html.erb +13 -0
  158. data/test/basepack_test_app/app/views/layouts/nested.html.erb +5 -0
  159. data/test/basepack_test_app/app/views/welcome/index.html.erb +10 -0
  160. data/test/basepack_test_app/config.ru +4 -0
  161. data/test/basepack_test_app/config/application.rb +57 -0
  162. data/test/basepack_test_app/config/boot.rb +13 -0
  163. data/test/basepack_test_app/config/cucumber.yml +8 -0
  164. data/test/basepack_test_app/config/database.yml.sample +41 -0
  165. data/test/basepack_test_app/config/database.yml.travis +15 -0
  166. data/test/basepack_test_app/config/environment.rb +6 -0
  167. data/test/basepack_test_app/config/environments/development.rb +22 -0
  168. data/test/basepack_test_app/config/environments/production.rb +49 -0
  169. data/test/basepack_test_app/config/environments/test.rb +35 -0
  170. data/test/basepack_test_app/config/initializers/backtrace_silencers.rb +7 -0
  171. data/test/basepack_test_app/config/initializers/data_mapper_logging.rb +3 -0
  172. data/test/basepack_test_app/config/initializers/inflections.rb +10 -0
  173. data/test/basepack_test_app/config/initializers/mime_types.rb +5 -0
  174. data/test/basepack_test_app/config/initializers/netzke.rb +9 -0
  175. data/test/basepack_test_app/config/initializers/secret_token.rb +7 -0
  176. data/test/basepack_test_app/config/initializers/sequel.rb +26 -0
  177. data/test/basepack_test_app/config/initializers/session_store.rb +8 -0
  178. data/test/basepack_test_app/config/locales/de.yml +35 -0
  179. data/test/basepack_test_app/config/locales/es.yml +96 -0
  180. data/test/basepack_test_app/config/routes.rb +68 -0
  181. data/test/basepack_test_app/db/development_structure.sql +88 -0
  182. data/test/basepack_test_app/db/migrate/20100914104207_create_users.rb +15 -0
  183. data/test/basepack_test_app/db/migrate/20100914104236_create_roles.rb +13 -0
  184. data/test/basepack_test_app/db/migrate/20101026185816_create_authors.rb +14 -0
  185. data/test/basepack_test_app/db/migrate/20101026190021_create_books.rb +19 -0
  186. data/test/basepack_test_app/db/migrate/20110101143818_create_addresses.rb +17 -0
  187. data/test/basepack_test_app/db/migrate/20110213213050_create_netzke_component_states.rb +20 -0
  188. data/test/basepack_test_app/db/migrate/20110701070052_create_book_with_custom_primary_keys.rb +15 -0
  189. data/test/basepack_test_app/db/migrate/20110901114016_add_last_read_at_to_books.rb +9 -0
  190. data/test/basepack_test_app/db/migrate/20110909071740_add_published_on_to_books.rb +5 -0
  191. data/test/basepack_test_app/db/schema.rb +81 -0
  192. data/test/basepack_test_app/db/seeds.rb +44 -0
  193. data/test/basepack_test_app/features/accordion_panel.feature +12 -0
  194. data/test/basepack_test_app/features/components_in_view.feature +11 -0
  195. data/test/basepack_test_app/features/form_panel.feature +142 -0
  196. data/test/basepack_test_app/features/grid_panel.feature +277 -0
  197. data/test/basepack_test_app/features/grid_panel_filters.feature +73 -0
  198. data/test/basepack_test_app/features/grid_panel_with_custom_primary_key.feature +15 -0
  199. data/test/basepack_test_app/features/grid_sorting.feature +47 -0
  200. data/test/basepack_test_app/features/i18n.feature +18 -0
  201. data/test/basepack_test_app/features/nested_attributes.feature +26 -0
  202. data/test/basepack_test_app/features/paging_form_panel.feature +43 -0
  203. data/test/basepack_test_app/features/search_in_grid.feature +49 -0
  204. data/test/basepack_test_app/features/simple_app.feature +15 -0
  205. data/test/basepack_test_app/features/simple_panel.feature +11 -0
  206. data/test/basepack_test_app/features/step_definitions/accordion_steps.rb +5 -0
  207. data/test/basepack_test_app/features/step_definitions/ext_steps.rb +16 -0
  208. data/test/basepack_test_app/features/step_definitions/form_panel_steps.rb +46 -0
  209. data/test/basepack_test_app/features/step_definitions/generic_steps.rb +44 -0
  210. data/test/basepack_test_app/features/step_definitions/grid_panel_steps.rb +186 -0
  211. data/test/basepack_test_app/features/step_definitions/pickle_steps.rb +100 -0
  212. data/test/basepack_test_app/features/step_definitions/web_steps.rb +219 -0
  213. data/test/basepack_test_app/features/support/env.rb +81 -0
  214. data/test/basepack_test_app/features/support/paths.rb +65 -0
  215. data/test/basepack_test_app/features/support/pickle.rb +24 -0
  216. data/test/basepack_test_app/features/support/selectors.rb +39 -0
  217. data/test/basepack_test_app/features/tab_panel.feature +12 -0
  218. data/test/basepack_test_app/features/validations_in_grid.feature +13 -0
  219. data/test/basepack_test_app/features/virtual_attributes.feature +16 -0
  220. data/test/basepack_test_app/features/window.feature +11 -0
  221. data/test/basepack_test_app/lib/tasks/.gitkeep +0 -0
  222. data/test/basepack_test_app/lib/tasks/cucumber.rake +71 -0
  223. data/test/basepack_test_app/lib/tasks/travis.rake +7 -0
  224. data/test/basepack_test_app/public/404.html +26 -0
  225. data/test/basepack_test_app/public/422.html +26 -0
  226. data/test/basepack_test_app/public/500.html +26 -0
  227. data/test/basepack_test_app/public/favicon.ico +0 -0
  228. data/test/basepack_test_app/public/images/header-deco.gif +0 -0
  229. data/test/basepack_test_app/public/images/rails.png +0 -0
  230. data/test/basepack_test_app/public/javascripts/application.js +2 -0
  231. data/test/basepack_test_app/public/javascripts/controls.js +965 -0
  232. data/test/basepack_test_app/public/javascripts/dragdrop.js +974 -0
  233. data/test/basepack_test_app/public/javascripts/effects.js +1123 -0
  234. data/test/basepack_test_app/public/javascripts/prototype.js +6001 -0
  235. data/test/basepack_test_app/public/javascripts/rails.js +175 -0
  236. data/test/basepack_test_app/public/robots.txt +5 -0
  237. data/test/basepack_test_app/public/stylesheets/.gitkeep +0 -0
  238. data/test/basepack_test_app/script/cucumber +10 -0
  239. data/test/basepack_test_app/script/rails +6 -0
  240. data/test/basepack_test_app/spec/components/form_panel_spec.rb +53 -0
  241. data/test/basepack_test_app/spec/components/grid_panel_spec.rb +10 -0
  242. data/test/basepack_test_app/spec/data_adapter/adapter_spec.rb +68 -0
  243. data/test/basepack_test_app/spec/data_adapter/attributes_spec.rb +56 -0
  244. data/test/basepack_test_app/spec/data_adapter/relation_extensions_spec.rb +125 -0
  245. data/test/basepack_test_app/spec/factories.rb +28 -0
  246. data/test/basepack_test_app/spec/spec_helper.rb +39 -0
  247. data/test/basepack_test_app/test/performance/browsing_test.rb +9 -0
  248. data/test/basepack_test_app/test/test_helper.rb +13 -0
  249. data/test/basepack_test_app/vendor/plugins/.gitkeep +0 -0
  250. data/test/console_with_fixtures.rb +4 -0
  251. data/test/fixtures/books.yml +11 -0
  252. data/test/fixtures/categories.yml +7 -0
  253. data/test/fixtures/cities.yml +21 -0
  254. data/test/fixtures/continents.yml +7 -0
  255. data/test/fixtures/countries.yml +9 -0
  256. data/test/fixtures/genres.yml +9 -0
  257. data/test/fixtures/roles.yml +8 -0
  258. data/test/fixtures/users.yml +11 -0
  259. data/test/schema.rb +10 -0
  260. data/test/test_helper.rb +21 -0
  261. data/test/unit/accordion_panel_test.rb +20 -0
  262. data/test/unit/active_record_basepack_test.rb +54 -0
  263. data/test/unit/fields_configuration_test.rb +18 -0
  264. data/test/unit/grid_panel_test.rb +52 -0
  265. data/test/unit/netzke_basepack_test.rb +4 -0
  266. data/test/unit/tab_panel_test.rb +21 -0
  267. data/uninstall.rb +1 -0
  268. metadata +332 -0
@@ -0,0 +1,11 @@
1
+ module Netzke
2
+ module DataMapper
3
+ module ComboboxOptions
4
+ def netzke_combo_options_for(column, query = "")
5
+ # NOTE: :order=>[column.to_sym.asc] is necessary as per http://datamapper.org/docs/find.html, Version 1.2.0
6
+ values=all(:fields=>[column], :unique=>true, :order=>[column.to_sym.asc])
7
+ (query.blank? ? values : values.all(column.to_sym.like => "#{query}%")).map &column.to_sym
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,38 @@
1
+ module Netzke
2
+ module DataMapper
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
+ # In DataMapper case this is just a method
10
+ self.send(scope, *params)
11
+ when "String" # SQL query or SQL query with params (e.g. ["created_at < ?", 1.day.ago])
12
+ raise NotImplementedError.new("This method is unsupported, as DM doen't allow to extend relations with SQL")
13
+ when "Array"
14
+ self.extend_with(*scope)
15
+ when "Hash" # conditions hash
16
+ self.all(scope)
17
+ when "ActiveSupport::HashWithIndifferentAccess" # conditions hash
18
+ self.all(scope)
19
+ when "Proc" # receives a relation, must return a relation
20
+ scope.call(self)
21
+ else
22
+ raise ArgumentError, "Wrong parameter type for ActiveRecord::Relation#extend_with"
23
+ end
24
+ end
25
+
26
+ # Non-destructively extends itself whith a hash of double-underscore'd conditions,
27
+ # where the last part "__" is MetaWhere operator (which is required), e.g.:
28
+ # {:role__name__like => "%admin"}
29
+ def extend_with_netzke_conditions(cond)
30
+ cond.each_pair.inject(self) do |r, (k,v)|
31
+ assoc, method, *operator = k.to_s.split("__")
32
+ 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)
33
+ end
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,18 @@
1
+ require 'netzke/sequel/attributes'
2
+ require 'netzke/sequel/combobox_options'
3
+ #require 'netzke/sequel/relation_extensions'
4
+
5
+ module Netzke
6
+ module Sequel
7
+ end
8
+ end
9
+
10
+ if defined? Sequel
11
+ # Extend Sequel
12
+ Sequel::Model.class_eval do
13
+ include ::Netzke::Sequel::Attributes
14
+ include ::Netzke::Sequel::ComboboxOptions
15
+ include ::Netzke::Sequel::RelationExtensions
16
+ end
17
+ end
18
+
@@ -0,0 +1,274 @@
1
+ module Netzke
2
+ module Sequel
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
+ self.netzke_exposed_attr = []
15
+ end
16
+
17
+ def self.included receiver
18
+ receiver.extend ClassMethods
19
+ end
20
+
21
+ module ClassMethods
22
+ def data_adapter
23
+ @data_adapter = Netzke::Basepack::DataAdapters::AbstractAdapter.adapter_class(self).new(self)
24
+ end
25
+
26
+ # mostly AR compatible for our purposes ;-)
27
+ def columns_hash
28
+ db_schema.inject({}){|memo,(k,v)| memo[k.to_s] = v; memo}
29
+ end
30
+
31
+ def column_names
32
+ columns.map &:to_s
33
+ end
34
+
35
+ # human attribute name
36
+ def human_attribute_name attr
37
+ I18n.translate(attr, :scope => [:activerecord, :attributes, model_name.downcase.to_sym], :default => attr.to_s.humanize)
38
+ end
39
+
40
+ # Example:
41
+ # netzke_attribute :recent, :type => :boolean, :read_only => true
42
+ def netzke_attribute(name, options = {})
43
+ name = name.to_s
44
+ options[:attr_type] = options.delete(:type) || options.delete(:attr_type) || :string
45
+ declared_attrs = self.netzke_declared_attr.dup
46
+ # if the attr was declared already, simply merge it with the new options
47
+ existing = declared_attrs.detect{ |va| va[:name] == name }
48
+ if existing
49
+ existing.merge!(options)
50
+ else
51
+ attr_config = {:name => name}.merge(options)
52
+ # if primary_key, insert in front, otherwise append
53
+ if name == self.primary_key.to_s
54
+ declared_attrs.insert(0, attr_config)
55
+ else
56
+ declared_attrs << {:name => name}.merge(options)
57
+ end
58
+ end
59
+ self.netzke_declared_attr = declared_attrs
60
+ end
61
+
62
+ # Exclude attributes from being picked up by grids and forms.
63
+ # Accepts an array of attribute names (as symbols).
64
+ # Example:
65
+ # netzke_expose_attributes :created_at, :updated_at, :crypted_password
66
+ def netzke_exclude_attributes(*args)
67
+ self.netzke_excluded_attr = args.map(&:to_s)
68
+ end
69
+
70
+ # Explicitly expose attributes that should be picked up by grids and forms.
71
+ # Accepts an array of attribute names (as symbols).
72
+ # Takes precedence over <tt>netzke_exclude_attributes</tt>.
73
+ # Example:
74
+ # netzke_expose_attributes :name, :role__name
75
+ def netzke_expose_attributes(*args)
76
+ self.netzke_exposed_attr = args.map(&:to_s)
77
+ end
78
+
79
+ # Returns the attributes that will be picked up by grids and forms.
80
+ def netzke_attributes
81
+ exposed = netzke_exposed_attributes
82
+ exposed ? netzke_attrs_in_forced_order(exposed) : netzke_attrs_in_natural_order
83
+ end
84
+
85
+ def netzke_attribute_hash
86
+ netzke_attributes.inject({}){ |r,a| r.merge(a[:name].to_sym => a) }
87
+ end
88
+
89
+ def netzke_exposed_attributes
90
+ exposed = self.netzke_exposed_attr
91
+ if exposed && !exposed.include?(self.primary_key.to_s)
92
+ # automatically declare primary key as a netzke attribute
93
+ netzke_attribute(self.primary_key.to_s)
94
+ exposed.insert(0, self.primary_key.to_s)
95
+ end
96
+ exposed
97
+ end
98
+
99
+ private
100
+ def netzke_attrs_in_forced_order(attrs)
101
+ attrs.collect do |attr_name|
102
+ declared = self.netzke_declared_attr.detect { |va| va[:name] == attr_name } || {}
103
+ 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?
104
+ if in_columns_hash.empty?
105
+ # If not among the model columns, it's either virtual, or an association
106
+ merged = association_attr?(attr_name) ? declared.merge!(:name => attr_name) : declared.merge(:virtual => true)
107
+ else
108
+ # .. otherwise merge with what's declared
109
+ merged = in_columns_hash.merge(declared)
110
+ end
111
+
112
+ # We didn't find it among declared, nor among the model columns, nor does it seem association attribute
113
+ merged[:name].nil? && raise(ArgumentError, "Unknown attribute '#{attr_name}' for model #{self.name}", caller)
114
+
115
+ merged
116
+ end
117
+ end
118
+
119
+ # Returns netzke attributes in the order of columns in the table, followed by extra declared attributes
120
+ # Detects many-to-one association columns and replaces the name of the column with association column name (Netzke style), e.g.:
121
+ #
122
+ # role_id => role__name
123
+ def netzke_attrs_in_natural_order
124
+ (
125
+ declared_attrs = self.netzke_declared_attr
126
+
127
+ column_names.map do |name|
128
+ c = {:name => name, :attr_type => columns_hash[name][:type]}
129
+
130
+ # If it's named as foreign key of some association, then it's an association column
131
+ assoc = all_association_reflections.detect { |a| a[:key].to_s == c[:name] && a[:type] == :many_to_one }
132
+ if assoc
133
+ candidates = %w{name title label} << assoc[:key].to_s
134
+ assoc_class = assoc[:class_name].constantize
135
+ assoc_method = candidates.detect{|m| ( assoc_class.instance_methods.map(&:to_s) + column_names).include?(m) }
136
+ c[:name] = "#{assoc[:name].to_s}__#{assoc_method}"
137
+ c[:attr_type] = assoc_class.columns_hash[assoc_method].try(:[], :type) || :string # when it's an instance method rather than a column, fall back to :string
138
+ end
139
+
140
+ # auto set up the default value from the column settings
141
+ c.merge!(:default_value => columns_hash[name][:default]) if columns_hash[name][:default]
142
+
143
+ # if there's a declared attr with the same name, simply merge it with what's taken from the model's columns
144
+ if declared = declared_attrs.detect{ |va| va[:name] == c[:name] }
145
+ c.merge!(declared)
146
+ declared_attrs.delete(declared)
147
+ end
148
+ c
149
+ end +
150
+ declared_attrs
151
+ ).reject { |attr| self.netzke_excluded_attr.include?(attr[:name]) }
152
+ end
153
+
154
+ def association_attr?(attr_name)
155
+ !!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
156
+ end
157
+
158
+ end
159
+
160
+ # AR compatibility
161
+ def attributes
162
+ values
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
+ # convenience method to convert all netzke attributes of a model to nifty json
176
+ def netzke_json
177
+ netzke_hash.to_nifty_json
178
+ end
179
+
180
+ # Accepts both hash and array of attributes
181
+ def netzke_hash(attributes = self.class.netzke_attributes)
182
+ res = {}
183
+ for a in (attributes.is_a?(Hash) ? attributes.values : attributes)
184
+ next if a[:included] == false
185
+ res[a[:name].to_sym] = self.value_for_attribute(a, a[:nested_attribute])
186
+ end
187
+ res
188
+ end
189
+
190
+ # Fetches the value specified by an (association) attribute
191
+ # If +through_association+ is true, get the value of the association by provided method, *not* the associated record's id
192
+ # 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
193
+ def value_for_attribute(a, through_association = false)
194
+ v = if a[:getter]
195
+ a[:getter].call(self)
196
+ elsif respond_to?("#{a[:name]}")
197
+ send("#{a[:name]}")
198
+ elsif is_association_attr?(a)
199
+ split = a[:name].to_s.split(/\.|__/)
200
+ assoc = self.class.association_reflection(split.first.to_sym)
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
+ logger.debug "Netzke::Basepack: Wrong attribute name: #{a[:name]}" unless r.nil?
207
+ nil
208
+ end
209
+ end
210
+ else
211
+ self.send("#{assoc[:key].to_s}")
212
+ end
213
+ end
214
+
215
+ # need to serialize Date and Time objects with to_s :db for compatibility with client side
216
+ # DATETIME fields in database are given as Time by Sequel
217
+ v = v.to_s(:db) if [Date, Time].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
+ unless primary_key.to_s == a[:name] && v.blank? # In contrast to ActiveRecord, Sequel doesn't allow setting nil/NULL primary keys
229
+ send("#{a[:name]}=", v)
230
+ end
231
+ elsif is_association_attr?(a)
232
+ split = a[:name].to_s.split(/\.|__/)
233
+ if a[:nested_attribute]
234
+ # We want:
235
+ # set_value_for_attribute({:name => :assoc_1__assoc_2__method, :nested_attribute => true}, 100)
236
+ # =>
237
+ # self.assoc_1.assoc_2.method = 100
238
+ split.inject(self) { |r,m| m == split.last ? (r && r.send("#{m}=", v) && r.save) : r.send(m) }
239
+ else
240
+ if split.size == 2
241
+ # search for association and assign it to self
242
+ assoc = self.class.association_reflection(split.first.to_sym)
243
+ assoc_method = split.last
244
+ if assoc
245
+ if assoc[:type] == :one_to_one
246
+ assoc_instance = self.send(assoc[:name])
247
+ if assoc_instance
248
+ assoc_instance.send("#{assoc_method}=", v)
249
+ assoc_instance.save # what should we do when this fails?..
250
+ else
251
+ # what should we do in this case?
252
+ end
253
+ else
254
+ self.send("#{assoc[:key]}=", v)
255
+ end
256
+ else
257
+ logger.debug "Netzke::Basepack: Association #{assoc} is not known for class #{self.class.name}"
258
+ end
259
+ else
260
+ logger.debug "Netzke::Basepack: Wrong attribute name: #{a[:name]}"
261
+ end
262
+ end
263
+ end
264
+ end
265
+
266
+ protected
267
+ # Returns true if passed attribute is an "association attribute"
268
+ def is_association_attr?(a)
269
+ # maybe the check is too simplistic, but will do for now
270
+ !!a[:name].to_s.index("__")
271
+ end
272
+ end
273
+ end
274
+ end
@@ -0,0 +1,10 @@
1
+ module Netzke
2
+ module Sequel
3
+ module ComboboxOptions
4
+ def netzke_combo_options_for(column, query = "")
5
+ ds = query.empty? ? self : filter(column.to_sym.ilike("#{query}%"))
6
+ ds.select(column.to_sym).distinct.all.map &column.to_sym
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,40 @@
1
+ module Netzke
2
+ module Sequel
3
+ module RelationExtensions
4
+ def self.included receiver
5
+ receiver.class_eval do
6
+ def_dataset_method :extend_with do |*params|
7
+ scope = params.shift
8
+ case scope.class.name
9
+ when "Symbol" # model's scope
10
+ self.send(scope, *params)
11
+ when "String" # SQL query or SQL query with params (e.g. ["created_at < ?", 1.day.ago])
12
+ params.empty? ? self.where(scope) : self.where([scope, *params])
13
+ when "Array"
14
+ self.extend_with(*scope)
15
+ when "Hash" # conditions hash
16
+ self.where(scope)
17
+ when "ActiveSupport::HashWithIndifferentAccess" # conditions hash
18
+ self.where(scope)
19
+ when "Proc" # receives a relation, must return a relation
20
+ scope.call(self)
21
+ else
22
+ raise ArgumentError, "Wrong parameter type for ActiveRecord::Relation#extend_with"
23
+ end
24
+ end
25
+
26
+ # Non-destructively extends itself whith a hash of double-underscore'd conditions,
27
+ # where the last part "__" is MetaWhere operator (which is required), e.g.:
28
+ # {:role__name__like => "%admin"}
29
+
30
+ def_dataset_method :extend_with_netzke_conditions do |cond|
31
+ cond.each_pair.inject(self) do |r, (k,v)|
32
+ assoc, method, *operator = k.to_s.split("__")
33
+ 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)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :netzke-basepack do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,79 @@
1
+ de:
2
+ netzke:
3
+ basepack:
4
+ grid_panel:
5
+ actions:
6
+ add: Hinzufügen
7
+ edit: Bearbeiten
8
+ del: Löschen
9
+ apply: Anwenden
10
+ add_in_form: extern Hinzufügen
11
+ edit_in_form: extern Bearbeiten
12
+ search: Suche
13
+
14
+ deleted_n_records: "Deleted %{n} record(s)"
15
+ cannot_delete: "Du hast keine Berechtigung die Daten zu löschen"
16
+ confirmation: Bestätigung
17
+ are_you_sure: Bist du sicher?
18
+
19
+ record_form_window:
20
+ actions:
21
+ ok: OK
22
+ cancel: Abbrechen
23
+
24
+ search_window:
25
+ title: erweiterte Suche
26
+ actions:
27
+ search: Suche
28
+ cancel: Abbrechen
29
+
30
+ form_panel:
31
+ actions:
32
+ edit: Bearbeiten
33
+ edit_tooltip: Bearbeiten
34
+ cancel: Abbrechen
35
+ cancel_tooltip: Bearbeiten abbrechen
36
+ apply: Anwenden
37
+ apply_tooltip: Änderungen speichern
38
+
39
+ search_panel:
40
+ presets: Vorlagen
41
+ equals: entspricht
42
+ greater_than: größer als
43
+ less_than: kleiner als
44
+ contains: enthält
45
+ matches: ist gleich
46
+ date_equals: "On"
47
+ before: vorher
48
+ after: nachher
49
+
50
+ paging_form_panel:
51
+ actions:
52
+ search: Suche
53
+ search_tooltip: Erweiterte Suche
54
+
55
+ query_builder:
56
+ presets: Vorlagen
57
+ preset_saved: Vorlage erfolgreich gespeichert
58
+ preset_deleted: Vorlage erfolgreich geglöscht
59
+ overwrite_confirm: "Soll das Vorlage wirklich überschrieben werden '{0}'?"
60
+ overwrite_confirm_title: "Überschreibe Vorlage"
61
+ delete_confirm: "Soll die Vorlage wirklich gelöscht werden '{0}'?"
62
+ delete_confirm_title: "Lösche Vorlage"
63
+ actions:
64
+ clear_all: leeren
65
+ clear_all_tooltip: Leere alle Bedingungen
66
+ reset: Reset
67
+ reset_tooltip: Setze alle Bedingungs-Werte zurück
68
+ save_preset: Speicher Vorlage
69
+ save_preset_tooltip: Speichere Vorlage
70
+ delete_preset: Lösche Vorlage
71
+ delete_preset_tooltip: Lösche Vorlage
72
+ apply: Anwenden
73
+ apply_tooltip: Wende neue Bedinungen an
74
+
75
+
76
+ formats:
77
+ date: d.m.Y
78
+ datetime: d.m.Y H:i:s
79
+ time: H:i:s