netzke-basepack 0.5.14 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. data/.gitignore +3 -2
  2. data/CHANGELOG.rdoc +15 -0
  3. data/README.rdoc +45 -50
  4. data/Rakefile +8 -8
  5. data/TODO.rdoc +1 -6
  6. data/app/components/netzke/basepack/accordion_panel.rb +37 -0
  7. data/app/components/netzke/basepack/basic_app.rb +267 -0
  8. data/{lib/netzke → app/components/netzke/basepack}/basic_app/statusbar_ext.js +0 -0
  9. data/app/components/netzke/basepack/border_layout_panel.rb +39 -0
  10. data/app/components/netzke/basepack/form_panel.rb +102 -0
  11. data/app/components/netzke/basepack/form_panel/fields.rb +206 -0
  12. data/{lib/netzke → app/components/netzke/basepack}/form_panel/javascripts/netzkefileupload.js +0 -0
  13. data/app/components/netzke/basepack/form_panel/javascripts/pre.js +76 -0
  14. data/{lib/netzke → app/components/netzke/basepack}/form_panel/javascripts/xcheckbox.js +0 -0
  15. data/app/components/netzke/basepack/form_panel/services.rb +99 -0
  16. data/app/components/netzke/basepack/grid_panel.rb +374 -0
  17. data/app/components/netzke/basepack/grid_panel/columns.rb +233 -0
  18. data/app/components/netzke/basepack/grid_panel/javascript.rb +69 -0
  19. data/app/components/netzke/basepack/grid_panel/javascripts/advanced_search.js +96 -0
  20. data/{lib/netzke → app/components/netzke/basepack}/grid_panel/javascripts/edit_in_form.js +5 -4
  21. data/{lib/netzke/grid_panel/javascripts/grid_panel_pre.js → app/components/netzke/basepack/grid_panel/javascripts/pre.js} +17 -37
  22. data/{lib/netzke → app/components/netzke/basepack}/grid_panel/javascripts/rows-dd.js +0 -0
  23. data/app/components/netzke/basepack/grid_panel/multi_edit_form.rb +16 -0
  24. data/app/components/netzke/basepack/grid_panel/record_form_window.rb +36 -0
  25. data/app/components/netzke/basepack/grid_panel/search_window.rb +56 -0
  26. data/app/components/netzke/basepack/grid_panel/services.rb +356 -0
  27. data/app/components/netzke/basepack/panel.rb +11 -0
  28. data/app/components/netzke/basepack/search_panel.rb +59 -0
  29. data/app/components/netzke/basepack/tab_panel.rb +32 -0
  30. data/app/components/netzke/basepack/window.rb +73 -0
  31. data/app/components/netzke/basepack/wrapper.rb +28 -0
  32. data/{lib/app → app}/models/netzke_field_list.rb +1 -1
  33. data/{lib/app → app}/models/netzke_model_attr_list.rb +0 -0
  34. data/{lib/app → app}/models/netzke_persistent_array_auto_model.rb +0 -0
  35. data/config/database.yml +35 -0
  36. data/features/accordion_panel.feature +15 -0
  37. data/features/basic_app.feature +12 -0
  38. data/features/form_panel.feature +40 -0
  39. data/features/grid_panel.feature +62 -0
  40. data/features/search_in_grid.feature +35 -0
  41. data/features/simple_panel.feature +15 -0
  42. data/features/step_definitions/accordion_steps.rb +9 -0
  43. data/features/step_definitions/generic_steps.rb +15 -0
  44. data/features/step_definitions/grid_panel_steps.rb +26 -0
  45. data/features/step_definitions/pickle_steps.rb +100 -0
  46. data/features/step_definitions/web_steps.rb +219 -0
  47. data/features/support/env.rb +66 -0
  48. data/features/support/paths.rb +59 -0
  49. data/features/support/pickle.rb +25 -0
  50. data/features/tab_panel.feature +15 -0
  51. data/features/window.feature +11 -0
  52. data/from_05_to_06.rdoc +2 -0
  53. data/javascripts/basepack.js +54 -2
  54. data/lib/netzke-basepack.rb +38 -25
  55. data/lib/netzke/active_record.rb +12 -4
  56. data/lib/netzke/active_record/attributes.rb +60 -5
  57. data/lib/netzke/active_record/combobox_options.rb +3 -2
  58. data/lib/netzke/active_record/relation_extensions.rb +35 -0
  59. data/lib/netzke/basepack.rb +27 -0
  60. data/lib/netzke/basepack/version.rb +11 -0
  61. data/lib/netzke/basepack/wrap_lazy_loaded.rb +26 -0
  62. data/lib/netzke/data_accessor.rb +60 -32
  63. data/lib/netzke/fields_configurator.rb +5 -9
  64. data/lib/netzke/masquerade_selector.rb +1 -1
  65. data/locale/en.yml +16 -0
  66. data/netzke-basepack.gemspec +298 -0
  67. data/spec/active_record/attributes_spec.rb +14 -0
  68. data/spec/active_record/relation_extensions_spec.rb +44 -0
  69. data/spec/components/form_panel_spec.rb +70 -0
  70. data/spec/components/grid_panel_spec.rb +10 -0
  71. data/spec/factories.rb +9 -0
  72. data/spec/spec_helper.rb +35 -0
  73. data/test/rails_app/.gitignore +4 -0
  74. data/test/rails_app/Gemfile +32 -0
  75. data/test/rails_app/Gemfile.lock +171 -0
  76. data/test/rails_app/README +256 -0
  77. data/test/rails_app/Rakefile +7 -0
  78. data/test/rails_app/app/components/generic_user_form.rb +12 -0
  79. data/test/rails_app/app/components/simple_accordion.rb +11 -0
  80. data/test/rails_app/app/components/simple_basic_app.rb +32 -0
  81. data/test/rails_app/app/components/simple_panel.rb +17 -0
  82. data/test/rails_app/app/components/simple_tab_panel.rb +11 -0
  83. data/test/rails_app/app/components/simple_wrapper.rb +7 -0
  84. data/test/rails_app/app/components/some_border_layout.rb +24 -0
  85. data/test/rails_app/app/components/some_search_panel.rb +34 -0
  86. data/test/rails_app/app/components/some_tab_panel.rb +15 -0
  87. data/test/rails_app/app/components/user_form.rb +21 -0
  88. data/test/rails_app/app/components/user_form_with_default_fields.rb +8 -0
  89. data/test/rails_app/app/components/user_grid.rb +4 -0
  90. data/test/rails_app/app/components/window_component_loader.rb +17 -0
  91. data/test/{app_root/app/controllers/application.rb → rails_app/app/controllers/application_controller.rb} +1 -0
  92. data/test/rails_app/app/controllers/components_controller.rb +6 -0
  93. data/test/rails_app/app/controllers/welcome_controller.rb +5 -0
  94. data/test/rails_app/app/helpers/application_helper.rb +2 -0
  95. data/test/{app_root → rails_app}/app/models/role.rb +0 -0
  96. data/test/rails_app/app/models/user.rb +6 -0
  97. data/test/rails_app/app/presenters/forms/generic_user.rb +6 -0
  98. data/test/rails_app/app/views/layouts/application.html.erb +13 -0
  99. data/test/rails_app/config.ru +4 -0
  100. data/test/rails_app/config/application.rb +45 -0
  101. data/test/rails_app/config/boot.rb +13 -0
  102. data/test/rails_app/config/database.yml +35 -0
  103. data/test/rails_app/config/environment.rb +6 -0
  104. data/test/rails_app/config/environments/development.rb +22 -0
  105. data/test/rails_app/config/environments/production.rb +49 -0
  106. data/test/rails_app/config/environments/test.rb +35 -0
  107. data/test/rails_app/config/initializers/backtrace_silencers.rb +8 -0
  108. data/test/rails_app/config/initializers/inflections.rb +10 -0
  109. data/test/rails_app/config/initializers/mime_types.rb +5 -0
  110. data/test/rails_app/config/initializers/netzke.rb +7 -0
  111. data/test/rails_app/config/initializers/secret_token.rb +7 -0
  112. data/test/rails_app/config/initializers/session_store.rb +8 -0
  113. data/test/rails_app/config/locales/es.yml +12 -0
  114. data/test/rails_app/config/routes.rb +65 -0
  115. data/test/rails_app/db/development_structure.sql +39 -0
  116. data/test/{app_root/db/migrate/20081222035855_create_netzke_preferences.rb → rails_app/db/migrate/20100905214933_create_netzke_preferences.rb} +2 -4
  117. data/test/{app_root/db/migrate/20090423222114_create_users.rb → rails_app/db/migrate/20100914104207_create_users.rb} +4 -1
  118. data/test/{app_root/db/migrate/20090423214303_create_roles.rb → rails_app/db/migrate/20100914104236_create_roles.rb} +2 -0
  119. data/test/rails_app/db/schema.rb +38 -0
  120. data/test/rails_app/db/seeds.rb +20 -0
  121. data/test/rails_app/features/support/paths.rb +47 -0
  122. data/test/{app_root/config/environments/in_memory.rb → rails_app/lib/tasks/.gitkeep} +0 -0
  123. data/test/rails_app/public/404.html +26 -0
  124. data/test/rails_app/public/422.html +26 -0
  125. data/test/rails_app/public/500.html +26 -0
  126. data/test/{app_root/config/environments/mysql.rb → rails_app/public/favicon.ico} +0 -0
  127. data/test/rails_app/public/images/header-deco.gif +0 -0
  128. data/test/rails_app/public/images/rails.png +0 -0
  129. data/test/rails_app/public/javascripts/application.js +2 -0
  130. data/test/rails_app/public/javascripts/controls.js +965 -0
  131. data/test/rails_app/public/javascripts/dragdrop.js +974 -0
  132. data/test/rails_app/public/javascripts/effects.js +1123 -0
  133. data/test/rails_app/public/javascripts/prototype.js +6001 -0
  134. data/test/rails_app/public/javascripts/rails.js +175 -0
  135. data/test/rails_app/public/robots.txt +5 -0
  136. data/test/{app_root/config/environments/postgresql.rb → rails_app/public/stylesheets/.gitkeep} +0 -0
  137. data/test/rails_app/script/rails +6 -0
  138. data/test/rails_app/spec/models/role_spec.rb +5 -0
  139. data/test/rails_app/spec/models/user_spec.rb +5 -0
  140. data/test/rails_app/test/performance/browsing_test.rb +9 -0
  141. data/test/rails_app/test/test_helper.rb +13 -0
  142. data/test/{app_root/config/environments/sqlite.rb → rails_app/vendor/plugins/.gitkeep} +0 -0
  143. data/test/unit/accordion_panel_test.rb +3 -3
  144. data/test/unit/active_record_basepack_test.rb +4 -4
  145. data/test/unit/tab_panel_test.rb +4 -4
  146. metadata +199 -119
  147. data/lib/netzke/accordion_panel.rb +0 -115
  148. data/lib/netzke/active_record/data_accessor.rb +0 -25
  149. data/lib/netzke/attributes_configurator.rb +0 -195
  150. data/lib/netzke/basic_app.rb +0 -368
  151. data/lib/netzke/border_layout_panel.rb +0 -130
  152. data/lib/netzke/configuration_panel.rb +0 -24
  153. data/lib/netzke/form_panel.rb +0 -138
  154. data/lib/netzke/form_panel/form_panel_api.rb +0 -81
  155. data/lib/netzke/form_panel/form_panel_fields.rb +0 -149
  156. data/lib/netzke/form_panel/form_panel_js.rb +0 -163
  157. data/lib/netzke/grid_panel.rb +0 -367
  158. data/lib/netzke/grid_panel/grid_panel_api.rb +0 -364
  159. data/lib/netzke/grid_panel/grid_panel_columns.rb +0 -232
  160. data/lib/netzke/grid_panel/grid_panel_js.rb +0 -73
  161. data/lib/netzke/grid_panel/javascripts/advanced_search.js +0 -65
  162. data/lib/netzke/grid_panel/multi_edit_form.rb +0 -14
  163. data/lib/netzke/grid_panel/record_form_window.rb +0 -50
  164. data/lib/netzke/panel.rb +0 -11
  165. data/lib/netzke/plugins/configuration_tool.rb +0 -121
  166. data/lib/netzke/property_editor.rb +0 -111
  167. data/lib/netzke/property_editor/helper_model.rb +0 -122
  168. data/lib/netzke/search_panel.rb +0 -199
  169. data/lib/netzke/tab_panel.rb +0 -174
  170. data/lib/netzke/table_editor.rb +0 -118
  171. data/lib/netzke/tree_panel.rb +0 -25
  172. data/lib/netzke/window.rb +0 -82
  173. data/lib/netzke/wrapper.rb +0 -42
  174. data/test/app_root/app/models/book.rb +0 -9
  175. data/test/app_root/app/models/category.rb +0 -2
  176. data/test/app_root/app/models/city.rb +0 -3
  177. data/test/app_root/app/models/continent.rb +0 -2
  178. data/test/app_root/app/models/country.rb +0 -3
  179. data/test/app_root/app/models/genre.rb +0 -3
  180. data/test/app_root/app/models/user.rb +0 -3
  181. data/test/app_root/config/boot.rb +0 -114
  182. data/test/app_root/config/database.yml +0 -21
  183. data/test/app_root/config/environment.rb +0 -14
  184. data/test/app_root/config/environments/sqlite3.rb +0 -0
  185. data/test/app_root/config/routes.rb +0 -4
  186. data/test/app_root/db/migrate/20081222033343_create_books.rb +0 -15
  187. data/test/app_root/db/migrate/20081222033440_create_genres.rb +0 -15
  188. data/test/app_root/db/migrate/20081223024935_create_categories.rb +0 -13
  189. data/test/app_root/db/migrate/20081223025635_create_countries.rb +0 -14
  190. data/test/app_root/db/migrate/20081223025653_create_continents.rb +0 -13
  191. data/test/app_root/db/migrate/20081223025732_create_cities.rb +0 -15
  192. data/test/app_root/db/migrate/20090102223630_create_netzke_field_lists.rb +0 -18
  193. data/test/app_root/script/console +0 -7
  194. data/test/app_root/vendor/plugins/acts_as_list/README +0 -23
  195. data/test/app_root/vendor/plugins/acts_as_list/init.rb +0 -3
  196. data/test/app_root/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +0 -256
@@ -1,73 +0,0 @@
1
- module Netzke
2
- class GridPanel < Base
3
- # (Dynamic) JavaScript for GridPanel
4
- module GridPanelJs
5
-
6
- # The result of this method (a hash) is converted to a JSON object and passed as the configuration parameter
7
- # to the constructor of our JavaScript class. Override it when you want to pass any extra configuration
8
- # to the JavaScript side.
9
- def js_config
10
- super.merge(
11
- :bbar => ext_config.has_key?(:bbar) ? ext_config[:bbar] : default_bbar,
12
- :context_menu => ext_config.has_key?(:context_menu) ? ext_config[:context_menu] : default_context_menu,
13
- :clmns => columns, # columns
14
- :model => config[:model], # the model name
15
- :inline_data => (get_data if ext_config[:load_inline_data]), # inline data (loaded along with the grid panel)
16
- :pri => data_class.primary_key # table primary key name
17
- )
18
- end
19
-
20
- module ClassMethods
21
-
22
- def js_base_class
23
- 'Netzke.pre.GridPanel' # see grid_panel_pre.js
24
- end
25
-
26
- # Ext.Component#initComponent, built up from pices (dependent on class-level configuration)
27
- def js_init_component
28
-
29
- # Optional "edit in form"-related events
30
- edit_in_form_events = <<-END_OF_JAVASCRIPT if config[:edit_in_form_available]
31
- if (this.enableEditInForm) {
32
- this.getSelectionModel().on('selectionchange', function(selModel){
33
- var disabled;
34
- if (!selModel.hasSelection()) {
35
- disabled = true;
36
- } else {
37
- // Disable "edit in form" button if new record is present in selection
38
- disabled = !selModel.each(function(r){
39
- if (r.isNew) { return false; }
40
- });
41
- };
42
- this.actions.editInForm.setDisabled(disabled);
43
- }, this);
44
- }
45
- END_OF_JAVASCRIPT
46
-
47
- # Result
48
- <<-END_OF_JAVASCRIPT
49
- function(){
50
- // Original initComponent
51
- #{js_full_class_name}.superclass.initComponent.call(this);
52
- #{edit_in_form_events}
53
- }
54
-
55
- END_OF_JAVASCRIPT
56
-
57
- end
58
-
59
- # All the rest that makes our JavaScript class
60
- def js_extend_properties
61
- {
62
- :init_component => js_init_component.l
63
- }
64
- end
65
- end
66
-
67
- def self.included(base)
68
- base.extend ClassMethods
69
- end
70
-
71
- end
72
- end
73
- end
@@ -1,65 +0,0 @@
1
- Ext.override(Netzke.pre.GridPanel, {
2
- onSearch: function(){
3
- delete this.searchWindow;
4
- this.searchWindow = new Ext.Window({
5
- title:'Advanced search',
6
- layout:'fit',
7
- modal: true,
8
- width: 400,
9
- height: Ext.lib.Dom.getViewHeight() *0.9,
10
- closeAction:'close',
11
- buttons:[{
12
- text: 'OK',
13
- handler: function(){
14
- this.ownerCt.ownerCt.closePositively();
15
- }
16
- },{
17
- text:'Cancel',
18
- handler:function(){
19
- this.ownerCt.ownerCt.closeNegatively();
20
- }
21
- }],
22
- closePositively : function(){
23
- this.conditions = this.getWidget().getForm().getValues();
24
- this.closeRes = 'OK';
25
- this.close();
26
- },
27
- closeNegatively: function(){
28
- this.closeRes = 'cancel';
29
- this.close();
30
- }
31
- });
32
-
33
- this.searchWindow.on('close', function(){
34
- if (this.searchWindow.closeRes == 'OK'){
35
- var searchConditions = this.searchWindow.conditions;
36
- var filtered = false;
37
- // check if there's any search condition set
38
- for (var k in searchConditions) {
39
- if (searchConditions[k].length > 0) {
40
- filtered = true;
41
- break;
42
- }
43
- }
44
- this.actions.search.setText(filtered ? "Search *" : "Search");
45
- this.getStore().baseParams = {extra_conditions: Ext.encode(this.searchWindow.conditions)};
46
- this.getStore().load();
47
- }
48
- }, this);
49
-
50
- this.searchWindow.on('add', function(container, searchPanel){
51
- searchPanel.on('apply', function(widget){
52
- this.searchWindow.closePositively();
53
- return false; // stop the event
54
- }, this);
55
- }, this);
56
-
57
- this.searchWindow.show(null, function(){
58
- this.searchWindow.closeRes = 'cancel';
59
- if (!this.searchWindow.getWidget()){
60
- this.loadAggregatee({id:"searchPanel", container:this.searchWindow.id});
61
- }
62
- }, this);
63
-
64
- }
65
- });
@@ -1,14 +0,0 @@
1
- module Netzke
2
- class GridPanel < Base
3
- class MultiEditForm < FormPanel
4
-
5
- # Replace checkbox for boolean fields with tristate checkbox
6
- def attr_type_to_xtype_map
7
- super.merge({
8
- :boolean => :tricheckbox
9
- })
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,50 +0,0 @@
1
- module Netzke
2
- class GridPanel < Base
3
- class RecordFormWindow < Window
4
- def initial_config
5
- super.deep_merge({
6
- :ext_config => {
7
- :modal => true,
8
- :width => "60%",
9
- :height => "90%",
10
- :fbar => [:ok, :cancel]
11
- }
12
- })
13
- end
14
-
15
- def self.js_extend_properties
16
- {
17
- :button_align => "right",
18
-
19
- :init_component => <<-END_OF_JAVASCRIPT.l,
20
- function(){
21
- #{js_full_class_name}.superclass.initComponent.call(this);
22
- this.getWidget().on("submitsuccess", function(){this.closeRes = "ok"; this.close();}, this);
23
- }
24
- END_OF_JAVASCRIPT
25
-
26
- :on_ok => <<-END_OF_JAVASCRIPT.l,
27
- function(){
28
- this.getWidget().onApply();
29
- // this.closeRes = "ok",
30
- // this.close();
31
- }
32
- END_OF_JAVASCRIPT
33
-
34
- :on_cancel => <<-END_OF_JAVASCRIPT.l,
35
- function(){
36
- this.close();
37
- }
38
- END_OF_JAVASCRIPT
39
-
40
- :on_test => <<-END_OF_JAVASCRIPT.l,
41
- function(){
42
- console.info("this.parent: ", this.getParent());
43
- }
44
- END_OF_JAVASCRIPT
45
-
46
- }
47
- end
48
- end
49
- end
50
- end
data/lib/netzke/panel.rb DELETED
@@ -1,11 +0,0 @@
1
- class Netzke::Panel < Netzke::Base
2
- def self.js_extend_properties
3
- {
4
- :update_body_html => <<-END_OF_JAVASCRIPT.l,
5
- function(html){
6
- this.body.update(html);
7
- }
8
- END_OF_JAVASCRIPT
9
- }
10
- end
11
- end
@@ -1,121 +0,0 @@
1
- module Netzke::Plugins
2
- # Include this module into any widget where you want a "gear" tool button in the top toolbar
3
- # which will triggger a modal window, which will load the ConfigurationPanel TabPanel-based
4
- # widget, which in its turn will contain all the aggregatees specified in widget's "configuration_widgets"
5
- # method (which *must* be defined)
6
- module ConfigurationTool
7
- def self.included(base)
8
- base.extend ClassMethods
9
-
10
- base.class_eval do
11
- # replacing instance methods
12
- [:config, :initial_aggregatees, :js_config].each{ |m| alias_method_chain m, :config_tool }
13
-
14
- # replacing class methods
15
- class << self
16
- alias_method_chain :js_extend_properties, :config_tool
17
- end
18
-
19
- # API to commit the changes
20
- api :commit
21
- end
22
-
23
- # if you include ConfigurationTool, you are supposed to provide configuration_widgets method which will returns an array of arrgeratees
24
- # that will be included in the property window (each in its own tab or accordion pane)
25
- raise "configuration_widgets method undefined" unless base.instance_methods.map(&:to_sym).include?(:configuration_widgets)
26
- end
27
-
28
- module ClassMethods
29
- def js_extend_properties_with_config_tool
30
- js_extend_properties_without_config_tool.merge({
31
- :on_gear => <<-END_OF_JAVASCRIPT.l
32
- function(){
33
- var w = new Ext.Window({
34
- title:'Config - '+ this.model,
35
- layout:'fit',
36
- modal:true,
37
- width: Ext.lib.Dom.getViewWidth() *0.9,
38
- height: Ext.lib.Dom.getViewHeight() *0.9,
39
- closeAction:'destroy',
40
- buttons:[{
41
- text:'OK',
42
- disabled: !this.configurable,
43
- tooltip: this.configurable ? null : "No dynamic configuration for this component",
44
- handler:function(){
45
- w.closeRes = 'OK';
46
- w.close();
47
- }
48
- },{
49
- text:'Cancel',
50
- handler:function(){
51
- w.closeRes = 'cancel';
52
- w.close();
53
- }
54
- }]
55
-
56
- });
57
-
58
- w.show(null, function(){
59
- this.loadAggregatee({id:"configuration_panel", container:w.id});
60
- }, this);
61
-
62
- w.on('close', function(){
63
- if (w.closeRes == 'OK'){
64
- var configurationPanel = this.getChildWidget('configuration_panel');
65
- var panels = configurationPanel.getLoadedChildren();
66
- var commitData = {};
67
- Ext.each(panels, function(p){
68
- if (p.getCommitData) {commitData[p.localId(configurationPanel)] = p.getCommitData();}
69
- }, this);
70
- configurationPanel.commit({commit_data:Ext.encode(commitData)});
71
- }
72
- }, this);
73
- }
74
- END_OF_JAVASCRIPT
75
- })
76
- end
77
- end
78
-
79
- def config_with_config_tool
80
- orig_config = config_without_config_tool
81
- return orig_config unless config_tool_needed?
82
- orig_config.deep_merge({
83
- :ext_config => {
84
- :tools => orig_config[:ext_config][:tools].clone << "gear",
85
- :header => true
86
- }
87
- })
88
- end
89
-
90
- def initial_aggregatees_with_config_tool
91
- res = initial_aggregatees_without_config_tool
92
-
93
- # Add the ConfigurationPanel as aggregatee, which in its turn aggregates widgets from the
94
- # configuration_widgets method
95
- res.merge!(:configuration_panel => {
96
- :class_name => 'ConfigurationPanel',
97
- :items => configuration_widgets,
98
- :late_aggregation => true
99
- }) if config_tool_needed?
100
-
101
- res
102
- end
103
-
104
- def tools_with_config_tool
105
- tools = tools_without_config_tool
106
- # Add the toolbutton
107
- tools << 'gear' if config_tool_needed?
108
- tools
109
- end
110
-
111
- def js_config_with_config_tool
112
- orig_config = js_config_without_config_tool
113
- orig_config.merge(:configurable => persistent_config_enabled?)
114
- end
115
-
116
- def config_tool_needed?
117
- config_without_config_tool[:ext_config][:config_tool] || config_without_config_tool[:ext_config][:mode] == :config
118
- end
119
-
120
- end
121
- end
@@ -1,111 +0,0 @@
1
- require "netzke/property_editor/helper_model"
2
-
3
- module Netzke
4
- class PropertyEditor < FormPanel
5
-
6
- def initialize(*args)
7
- super
8
- @widget = @passed_config[:widget]
9
- end
10
-
11
- def default_bbar
12
- %w{ restore_defaults }
13
- end
14
-
15
- def actions
16
- {:restore_defaults => {:text => "Restore defaults"}}
17
- end
18
-
19
- def fields
20
- fields = @widget.class.property_fields
21
-
22
- for f in fields
23
- f[:value] = @widget.flat_config(f[:name]).nil? ? f[:default] : @widget.flat_config(f[:name])
24
- f[:xtype] = xtype_for_attr_type(f[:type])
25
- f[:field_label] = f[:name].to_s.gsub("__", "/").humanize
26
- end
27
-
28
- fields
29
- end
30
-
31
- def self.js_extend_properties
32
- {
33
- :label_width => 200,
34
-
35
- # Disable the 'gear' tool for now
36
- :on_gear => <<-END_OF_JAVASCRIPT.l,
37
- function(){
38
- this.feedback("You can't configure property editor (yet)");
39
- }
40
- END_OF_JAVASCRIPT
41
-
42
- :on_restore_defaults => <<-END_OF_JAVASCRIPT.l,
43
- function(){
44
- this.restoreDefaults();
45
- }
46
- END_OF_JAVASCRIPT
47
-
48
- :get_commit_data => <<-END_OF_JAVASCRIPT.l
49
- function(){
50
- if (!this.getForm().isValid()) {this.getForm().reset()}; // if some fields are invalid, don't send anything
51
- var values = this.getForm().getValues();
52
- for (var k in values) {
53
- if (values[k] == "") {values[k] = null}
54
- }
55
- return values;
56
- }
57
- END_OF_JAVASCRIPT
58
- }
59
- end
60
-
61
- api :restore_defaults
62
- def restore_defaults(params)
63
- values = []
64
- columns.each do |c|
65
- init_config = @widget.flat_initial_config.detect{ |ic| ic[:name] == c[:name] }
66
-
67
- if init_config.nil?
68
- property_fields ||= @widget.class.property_fields
69
- values << property_fields.detect{ |f| f[:name] == c[:name] }[:default]
70
- else
71
- values << init_config[:value]
72
- end
73
-
74
- end
75
- {:set_form_values => values}
76
- end
77
-
78
- def commit(data)
79
- fields = @widget.class.property_fields
80
- data.each_pair do |property, value|
81
- field = fields.detect{ |f| f[:name] == property.to_sym }
82
- default = @widget.flat_initial_config(property).nil? ? field[:default] : @widget.flat_initial_config(property)
83
-
84
- new_value = normalize_form_value(value, field)
85
-
86
- # Only store the value in persistent config when it's different from the default one
87
- if field[:type] == :boolean
88
- # handle boolean type separately
89
- @widget.persistent_config[property] = new_value ^ default ? new_value : nil
90
- else
91
- @widget.persistent_config[property] = default == new_value ? nil : new_value
92
- end
93
- end
94
- {}
95
- end
96
-
97
- def normalize_form_value(value, field)
98
- case field[:attr_type]
99
- when :boolean
100
- value.to_b
101
- when :json
102
- ActiveSupport::JSON.decode(value) # no need to check for exceptions, as the value has been validated in browser
103
- when :integer
104
- value.to_i
105
- else
106
- value # TODO: support other types like :date and :datetime
107
- end
108
- end
109
-
110
- end
111
- end