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,51 @@
1
+ Ext.ns("Ext.netzke.form");
2
+
3
+ /*
4
+ A very simple CheckboxGroup extension, which serializes its checkboxes' "boxLabel" attributes into a string.
5
+ Config options:
6
+ * separator - separator of values in the string (defaults to ",")
7
+ * options - all checkboxes, by boxLabel, e.g.: ["Cool", "To read", "Important"]
8
+ */
9
+ Ext.define('Ext.netzke.form.CommaListCbg', {
10
+ extend: 'Ext.form.CheckboxGroup',
11
+ alias: 'widget.commalistcbg',
12
+ separator: ",",
13
+
14
+ initComponent: function(){
15
+ this.items = [];
16
+ Ext.each(this.options, function(o){
17
+ this.items.push({ boxLabel: o, displayOnly:true });
18
+ }, this);
19
+
20
+ this.callParent();
21
+ },
22
+
23
+ getSubmitData: function(){
24
+ var res = [];
25
+ Ext.each(this.getChecked(), function( item ){ res.push( item.boxLabel ) });
26
+ res = res.join(this.separator);
27
+ var o = {};
28
+ o[this.name]=res;
29
+ return o;
30
+ },
31
+
32
+ setValue: function(v){
33
+ if (Ext.isString(v)) {
34
+ var passedValues = v.split(this.separator);
35
+ this.items.each(function(i){
36
+ i.setValue( passedValues.indexOf(i.boxLabel) >= 0 );
37
+ });
38
+ // we can alse set values the Ext way
39
+ } else {
40
+ this.callParent(arguments);
41
+ }
42
+ },
43
+
44
+ setReadonlyMode: function(onOff) {
45
+ this.items.each(function(i){
46
+ i.setReadonlyMode(onOff);
47
+ });
48
+ }
49
+
50
+ });
51
+
@@ -0,0 +1,225 @@
1
+ {
2
+ bodyStyle : 'padding:5px 5px 0',
3
+ autoScroll : true,
4
+ fieldDefaults : { labelWidth : 150 },
5
+ applyMask : { msg: "Updating..." },
6
+
7
+ defaults : {
8
+ anchor : '-20', // to leave some space for the scrollbar
9
+ listeners : {
10
+ // On "return" key, submit the form
11
+ specialkey : {
12
+ fn : function(field, event){
13
+ if (event.getKey() == 13) this.ownerCt.onApply();
14
+ }
15
+ }
16
+ }
17
+ },
18
+
19
+ initComponent: function(){
20
+ // passing config options to BasicForm is possible via initialConfig only
21
+ // see Ext.form.Panel documentation
22
+ this.initialConfig = {
23
+ // form tracks it's default field values so they can be reset()
24
+ trackResetOnLoad: true,
25
+ }
26
+
27
+ if (!this.bbar && !this.readOnly) this.bbar = {xtype: 'toolbar'}; // an empty bbar by default, so that we can dynamically add buttons
28
+
29
+ // Custom error reader. We don't use it to process form values, but rather to normalize the response from the server in case of "real" (iframe) form submit.
30
+ ErrorReader = function(){};
31
+
32
+ ErrorReader.prototype.read = function(xhr) {
33
+ var unescapeHTML = function(str) {
34
+ return str.replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&amp;/g,'&');
35
+ }
36
+ xhr.responseText = unescapeHTML(xhr.responseText.replace(/<pre.*?>/, "").replace("</pre>", ""));
37
+ return {records: [], success: true};
38
+ };
39
+
40
+ this.initialConfig.errorReader = new ErrorReader();
41
+
42
+ // Now let Ext.form.FormPanel do the rest
43
+ this.callParent(arguments);
44
+
45
+ // To inform the parent about the apply event
46
+ this.addEvents('apply', 'cancel');
47
+ },
48
+
49
+ afterRender: function(){
50
+ this.callParent();
51
+
52
+ // have a record to be displayed?
53
+ if (this.record) { this.setFormValues(this.record); }
54
+
55
+ // render in display mode?
56
+ if (this.locked || this.readOnly) this.setReadonlyMode(true);
57
+ },
58
+
59
+ onEdit: function(){
60
+ this.setReadonlyMode(false);
61
+ },
62
+
63
+ onCancel: function(){
64
+ this.getForm().reset();
65
+ this.setReadonlyMode(true, true);
66
+ },
67
+
68
+ updateToolbar: function(){
69
+ var tbar = this.child('toolbar');
70
+
71
+ if ( this.inReadonlyMode ) {
72
+ // if the form in readonly mode, remove "Apply" and "Cancel"
73
+ // buttons from toolbar and add "Edit" button
74
+ var buttonToRemove = tbar.child("button[name='apply']");
75
+ if ( buttonToRemove ) {
76
+ tbar.remove( buttonToRemove );
77
+ }
78
+
79
+ var buttonToRemove = tbar.child("button[name='cancel']");
80
+ if ( buttonToRemove ) {
81
+ tbar.remove( buttonToRemove );
82
+ }
83
+
84
+ tbar.add( this.actions.edit );
85
+
86
+ } else {
87
+ // if the form editable, remove "edit" button and
88
+ // insert "apply" and "cancel" instead
89
+
90
+ var buttonIndex = tbar.items.findIndex("name", "edit");
91
+ var buttonToRemove = tbar.items.getAt(buttonIndex);
92
+ if (buttonToRemove) {
93
+ tbar.remove(buttonToRemove);
94
+ }
95
+ tbar.insert( buttonIndex, this.actions.cancel );
96
+ tbar.insert( buttonIndex, this.actions.apply );
97
+ }
98
+
99
+ tbar.doLayout();
100
+ },
101
+
102
+ onApply: function() {
103
+ if (this.fireEvent('apply', this)) {
104
+ var values = this.getForm().getValues();
105
+ for (var fieldName in values) {
106
+ var field = this.getForm().findField(fieldName);
107
+
108
+ // TODO: move the following checks to the server side (through the :display_only option)
109
+
110
+ // do not submit values from disabled fields
111
+ if (!field || field.disabled) {
112
+ delete values[fieldName];
113
+ }
114
+
115
+ // do not submit values from read-only association fields
116
+ if (field
117
+ && field.name.indexOf("__") !== -1
118
+ && (field.readOnly || !field.isXType('combobox'))
119
+ && (!field.nestedAttribute) // except for "nested attributes"
120
+ ) {
121
+ delete values[fieldName];
122
+ }
123
+
124
+ // do not submit values from displayfields
125
+ if (field.isXType('displayfield')) {
126
+ delete values[fieldName];
127
+ }
128
+
129
+ // do not submit displayOnly fields
130
+ if (field.displayOnly) {
131
+ delete values[fieldName];
132
+ }
133
+ }
134
+ // WIP: commented out on 2011-05-11 because of fatal errors
135
+ // apply mask
136
+ // if (!this.applyMaskCmp) this.applyMaskCmp = new Ext.LoadMask(this.bwrap, this.applyMask);
137
+ // this.applyMaskCmp.show();
138
+
139
+ // We must use a different approach when the form is multipart, as we can't use the endpoint
140
+ if (this.fileUpload) {
141
+ this.getForm().submit({ // normal submit
142
+ url: this.endpointUrl("netzke_submit"),
143
+ params: {
144
+ data: Ext.encode(values) // here are the correct values that may be different from display values
145
+ },
146
+ failure: function(form, action){
147
+ if (this.applyMaskCmp) this.applyMaskCmp.hide();
148
+ },
149
+ success: function(form, action) {
150
+ try {
151
+ var respObj = Ext.decode(action.response.responseText);
152
+ delete respObj.success;
153
+ this.bulkExecute(respObj);
154
+ this.fireEvent('submitsuccess');
155
+ }
156
+ catch(e) {
157
+ Ext.Msg.alert('File upload error', action.response.responseText);
158
+ }
159
+ if (this.applyMaskCmp) this.applyMaskCmp.hide();
160
+ },
161
+ scope: this
162
+ });
163
+ } else {
164
+ this.netzkeSubmit(Ext.apply((this.baseParams || {}), {data:Ext.encode(values)}), function(success){
165
+ if (success) {
166
+ this.fireEvent("submitsuccess");
167
+ if (this.mode == "lockable") this.setReadonlyMode(true);
168
+ };
169
+ if (this.applyMaskCmp) this.applyMaskCmp.hide();
170
+ }, this);
171
+ }
172
+ }
173
+ this.fireEvent('afterApply', this);
174
+ },
175
+
176
+ setFormValues: function(values){
177
+ var assocValues = values._meta.associationValues || {};
178
+ for (var assocFieldName in assocValues) {
179
+
180
+ var assocField = this.getForm().getFields().filter('name', assocFieldName).first();
181
+ if (assocField.isXType('combobox')) {
182
+ assocField.emptyText = assocField.emptyText || "---";
183
+ // HACK: using private property 'store' here!
184
+ assocField.store.loadData([[values[assocFieldName], assocValues[assocFieldName]]]);
185
+ delete assocField.lastQuery; // force loading the store next time user clicks the trigger
186
+ } else {
187
+ assocField.setValue(assocValues[assocFieldName]);
188
+ delete values[assocFieldName]; // we don't want this to be set once more below with setValues()
189
+ }
190
+ }
191
+
192
+ this.getForm().setValues(values);
193
+ },
194
+
195
+ setReadonlyMode: function(onOff, cancel){
196
+ if (this.inReadonlyMode == onOff) return;
197
+ this.getForm().getFields().each(function(i){
198
+ if (i.setReadonlyMode) i.setReadonlyMode(onOff);
199
+ });
200
+
201
+ // this.getForm().cleanDestroyed(); // because fields inside of composite fields are not auto-cleaned!
202
+ this.doLayout();
203
+ this.inReadonlyMode = onOff;
204
+ if (this.mode == "lockable") this.updateToolbar();
205
+ },
206
+
207
+ // recursively extract field names
208
+ extractFields: function(items){
209
+ Ext.each(items, function(i){
210
+ if (i.items) {this.extractFields(i.items);}
211
+ else if (i.name) {this.fieldNames.push(i.name);}
212
+ }, this);
213
+ },
214
+
215
+ applyFormErrors: function(errors) {
216
+ var field;
217
+ Ext.iterate(errors, function(fieldName, message){
218
+ fieldName = fieldName.underscore();
219
+ if ( field = this.getForm().findField(fieldName) || this.getForm().findField(fieldName.replace(/([a-z]+)([0-9])/g, '$1_$2'))) {
220
+ field.markInvalid(message.join('<br/>'));
221
+ }
222
+ }, this);
223
+ }
224
+
225
+ }
@@ -0,0 +1,4 @@
1
+ Ext.override(Ext.ux.form.FileUploadField, {
2
+ // FormPanel won't submit this by default
3
+ displayOnly: true
4
+ });
@@ -0,0 +1,43 @@
1
+ Ext.ns("Ext.netzke.form");
2
+ /*
3
+ A very simple RadioGroup extension.
4
+ Config options:
5
+ * options:
6
+ 1) all radio buttons, by boxLabel, e.g.: ["Cool", "To read", "Important"]
7
+ 2) array of arrays in format [value, label], e.g.: [[1, "Good"], [2, "Average"], [3, "Poor"]]
8
+ */
9
+ Ext.define('Ext.netzke.form.NRadioGroup', {
10
+ extend: 'Ext.form.RadioGroup',
11
+ alias: 'widget.nradiogroup',
12
+ initComponent: function(){
13
+ this.callParent();
14
+
15
+ this.items = [];
16
+
17
+ Ext.each(this.options, function(o){
18
+ if (Ext.isArray(o)){
19
+ this.items.push({boxLabel: o[1], name: this.name, inputValue: o[0]});
20
+ } else {
21
+ this.items.push({boxLabel: o, name: this.name, inputValue: o});
22
+ }
23
+ }, this);
24
+
25
+ // delete this.name;
26
+ },
27
+
28
+ getValue: function() {
29
+ var value;
30
+ this.items.each(function(i) {
31
+ value = i.inputValue;
32
+ return !i.getValue();
33
+ });
34
+ return value;
35
+ },
36
+
37
+ setReadonlyMode: function(onOff) {
38
+ this.items.each(function(i){
39
+ i.setReadonlyMode(onOff);
40
+ });
41
+ }
42
+ });
43
+
@@ -0,0 +1,35 @@
1
+ // Overrides that implement setReadonlyMode for form fields.
2
+ //
3
+
4
+ Ext.form.field.Base.override({
5
+ setReadonlyMode: function(onOff){
6
+ if (this.hidden) return;
7
+
8
+ if (!this.initialConfig.readOnly) {
9
+ this.setReadOnly(onOff);
10
+ }
11
+
12
+ if (onOff) {
13
+ this.addCls("readonly");
14
+ if (this.label) this.label.addCls("readonly");
15
+ } else {
16
+ this.removeCls("readonly");
17
+ if (this.label) this.label.removeCls("readonly");
18
+ }
19
+ }
20
+ });
21
+
22
+ // Also the FieldContainer
23
+ Ext.form.FieldContainer.override({
24
+ setReadonlyMode: function(onOff){
25
+ this.items.each(function(i){
26
+ i.setReadonlyMode(onOff);
27
+ });
28
+ }
29
+ });
30
+
31
+ Ext.form.field.Checkbox.override({
32
+ setReadonlyMode: function(onOff){
33
+ this.setDisabled(onOff);
34
+ }
35
+ });
@@ -0,0 +1,142 @@
1
+ module Netzke
2
+ module Basepack
3
+ class FormPanel < Netzke::Base
4
+ module Services
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+
9
+ #
10
+ # Endpoints
11
+
12
+ # Called when the form gets submitted (e.g. by pressing the Apply button)
13
+ endpoint :netzke_submit, :pre => true do |params|
14
+ netzke_submit(params)
15
+ end
16
+
17
+ # Can be called when the form needs to load a record with given ID. E.g.:
18
+ #
19
+ # someForm.netzkeLoad({id: 100});
20
+ endpoint :netzke_load do |params|
21
+ @record = data_class && data_adapter.find_record(params[:id])
22
+ {:set_form_values => js_record_data}
23
+ end
24
+
25
+ # Returns options for a combobox
26
+ endpoint :get_combobox_options do |params|
27
+ query = params[:query]
28
+
29
+ field = fields[params[:column].to_sym]
30
+ scope = field.to_options[:scope]
31
+ query = params[:query]
32
+ {:data => combobox_options_for_column(field, :query => query, :scope => scope, :record_id => params[:id])}
33
+ end
34
+
35
+ end
36
+
37
+ # Overriding configuration_panel's get_combobox_options endpoint call
38
+ def configuration_panel__fields__get_combobox_options(params)
39
+ query = params[:query]
40
+ {:data => (default_columns.map{ |c| c[:name].to_s }).grep(/^#{query}/).map{ |n| [n] }}.to_nifty_json
41
+ end
42
+
43
+ # Returns array of form values according to the configured columns
44
+ # def array_of_values
45
+ # @record && @record.netzke_array(fields)
46
+ # end
47
+
48
+ def values
49
+ record && record.netzke_hash(fields)
50
+ end
51
+
52
+ # Implementation for the "netzke_submit" endpoint (for backward compatibility)
53
+ def netzke_submit(params)
54
+ data = ActiveSupport::JSON.decode(params[:data])
55
+ data.each_pair do |k,v|
56
+ data[k]=nil if v.blank? || v == "null" # Ext JS returns "null" on empty date fields, or "" for not filled optional integer fields, which gives errors when passed to model (at least in DataMapper)
57
+ end
58
+
59
+ # File uploads are in raw params instead of "data" hash, so, mix them in into "data"
60
+ if config[:file_upload]
61
+ Netzke::Core.controller.params.each_pair do |k,v|
62
+ data[k] = v if v.is_a?(ActionDispatch::Http::UploadedFile)
63
+ end
64
+ end
65
+
66
+ success = create_or_update_record(data)
67
+
68
+ if success
69
+ {:set_form_values => js_record_data, :set_result => true}
70
+ else
71
+ # flash eventual errors
72
+ data_adapter.errors_array(@record).each do |error|
73
+ flash :error => error
74
+ end
75
+ {:netzke_feedback => @flash, :apply_form_errors => build_form_errors(record)}
76
+ end
77
+ end
78
+
79
+ private
80
+
81
+ # Builds the form errors
82
+ def build_form_errors(record)
83
+ form_errors = {}
84
+ foreign_keys = data_adapter.hash_fk_model
85
+ record.errors.to_hash.map{|field, error|
86
+ # some ORM return an array for error
87
+ error = error.join ', ' if error.kind_of? Array
88
+ # Get the correct field name for the errors on foreign keys
89
+ if foreign_keys.has_key?(field)
90
+ fields.each do |k, v|
91
+ # Hack to stop to_nifty_json from camalizing model__field
92
+ field = k.to_s.gsub('__', '____') if k.to_s.split('__').first == foreign_keys[field].to_s
93
+ end
94
+ end
95
+ form_errors[field] ||= []
96
+ form_errors[field] << error
97
+ }
98
+ form_errors
99
+ end
100
+
101
+ # Creates/updates a record from hash
102
+ def create_or_update_record(hsh)
103
+ hsh.merge!(config[:strong_default_attrs]) if config[:strong_default_attrs]
104
+ @record ||= data_adapter.find_record hsh.delete(data_class.primary_key.to_s) # only pick up the record specified in the params if it was not provided in the configuration
105
+ #data_class.find(:first, :conditions => {data_class.primary_key => hsh.delete(data_class.primary_key)})
106
+ success = true
107
+
108
+ @record = data_class.new if @record.nil?
109
+
110
+ hsh.each_pair do |k,v|
111
+ @record.set_value_for_attribute(fields[k.to_sym].nil? ? {:name => k} : fields[k.to_sym], v)
112
+ end
113
+
114
+ #hsh.each_pair do |k,v|
115
+ #begin
116
+ #@record.send("#{k}=",v)
117
+ #rescue StandardError => exc
118
+ #flash :error => exc.message
119
+ #success = false
120
+ #break
121
+ #end
122
+ #end
123
+
124
+ # did we have complete success?
125
+ success && data_adapter.save_record(@record)
126
+ end
127
+
128
+ # API handling form load
129
+ # def load(params)
130
+ # klass = config[:model].constantize
131
+ # case params[:neighbour]
132
+ # when "previous" then @record = klass.previous(params[:id])
133
+ # when "next" then @record = klass.next(params[:id])
134
+ # else @record = klass.find(params[:id])
135
+ # end
136
+ # {:data => [array_of_values]}
137
+ # end
138
+
139
+ end
140
+ end
141
+ end
142
+ end