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,122 +0,0 @@
1
- module Netzke
2
- class PropertyEditor < FormPanel
3
- class HelperModel
4
- def self.widget=(w)
5
- @@widget = w
6
- end
7
-
8
- def self.widget
9
- @@widget ||= raise RuntimeError, "No widget specified for PropertyEditor::HelperModel"
10
- end
11
-
12
- def self.reflect_on_all_associations
13
- []
14
- end
15
-
16
- def self.primary_key
17
- "id"
18
- end
19
-
20
- def self.netzke_exposed_attributes
21
- preferences = self.widget.flat_default_config
22
- # preferences = NetzkePreference.find_all_for_widget(widget.name)
23
- preferences.each { |p| p.reject!{ |k,v| k == :value}.merge!(:field_label => p[:name].to_s.gsub('__', "/").humanize) }
24
- preferences
25
- end
26
-
27
- DEFAULTS_FOR_FIELD = {
28
- :Fixnum => {
29
- :xtype => :numberfield
30
- },
31
- :Boolean => {
32
- :xtype => :xcheckbox,
33
- :checked => true
34
- },
35
- :String => {
36
- :xtype => :textfield
37
- }
38
- }
39
-
40
- # DRY out!
41
- def self.default_field_config(config)
42
- type = config.delete(:type)
43
-
44
- common = {
45
- :field_label => config[:name].to_s.gsub('__', '_').humanize,
46
- :hidden => config[:name] == :id
47
- }
48
-
49
- default = DEFAULTS_FOR_FIELD[type] || DEFAULTS_FOR_FIELD[:String] # fallback to plain textfield
50
-
51
- res = default.merge(common).merge(config)
52
- end
53
-
54
- def self.find_by_id(*args)
55
- self.new
56
- end
57
-
58
- def save
59
- end
60
-
61
- def errors
62
- a = Array.new
63
- def a.each_full
64
- []
65
- end
66
- a
67
- end
68
-
69
- def to_array(columns, widget = nil)
70
- res = []
71
- for c in columns
72
- method = c.is_a?(Symbol) ? c : c[:name]
73
- value = send(method)
74
- res << (value.is_a?(Array) || value.is_a?(Hash) ? value.to_json : value)
75
- end
76
- res
77
- end
78
-
79
- # somewhat sofisticated code to convert all NetzkePreferences for current widget into a hash ("un-flatten")
80
- def attributes
81
- prefs = NetzkePreference.find_all_for_widget(self.class.widget.global_id)
82
- res = {}
83
- prefs.each do |p|
84
- tmp_res = {}
85
- hsh_levels = p.name.split("__").map(&:to_sym)
86
- hsh_levels.each do |level_prefix|
87
- tmp_res[level_prefix] ||= level_prefix == hsh_levels.last ? p.normalized_value : {}
88
- res[level_prefix] = tmp_res[level_prefix] if level_prefix == hsh_levels.first
89
- tmp_res = tmp_res[level_prefix]
90
- end
91
- end
92
- res
93
- end
94
-
95
- def method_missing(method_name, *args)
96
- method_name = method_name.to_s
97
- method_name_without_equal_sign = method_name.sub(/=$/, '')
98
- NetzkePreference.widget_name = self.class.widget.global_id
99
-
100
- if method_name =~ /=$/
101
- current_value = self.class.widget.flat_independent_config(method_name_without_equal_sign)
102
-
103
- begin
104
- new_value = ActiveSupport::JSON.decode(args.first) # TODO: provide feedback about this error
105
- rescue ActiveSupport::JSON::ParseError
106
- new_value = current_value
107
- end
108
-
109
- initial_value = self.class.widget.flat_initial_config(method_name_without_equal_sign)
110
-
111
- new_value = nil if new_value == initial_value
112
- NetzkePreference[method_name_without_equal_sign] = new_value
113
- else
114
- res = self.class.widget.flat_independent_config(method_name_without_equal_sign)
115
- res = ActiveSupport::JSON.encode(res) if res.is_a?(Array) || res.is_a?(Hash)
116
- res
117
- end
118
- end
119
-
120
- end
121
- end
122
- end
@@ -1,199 +0,0 @@
1
- module Netzke
2
- # SearchPanel
3
- #
4
- # FormPanel-based widget that allows create configurable searchlogic-compatible searches.
5
- # Pretty much work in progress.
6
- class SearchPanel < FormPanel
7
-
8
- # Something like [:equals, :greater_than_or_equal_to, :does_not_equal, :less_than, :less_than_or_equal_to, :greater_than, :ends_with, :like, :begins_with, :empty, :null]
9
- CONDITIONS = [:COMPARISON_CONDITIONS, :WILDCARD_CONDITIONS, :BOOLEAN_CONDITIONS].inject([]){|r, c| r + Searchlogic::NamedScopes::Conditions.const_get(c).keys}
10
-
11
- def default_config
12
- super.merge({
13
- :model => @passed_config[:search_class_name]
14
- })
15
- end
16
-
17
- def independent_config
18
- super.deep_merge(
19
- :ext_config => {
20
- :tbar => ["Presets:",
21
- {
22
- :xtype => "combo",
23
- :fieldLabel => "Presets",
24
- :triggerAction => "all",
25
- :store => (persistent_config[:saved_searches] || []).map{ |s| s["name"] },
26
- :id => "presets-combo",
27
- :listeners => {:before_select => {
28
- :fn => "function(combo, record){Ext.getCmp('#{global_id}').selectPreset(record.data.field1);}".l
29
- }}
30
- }, :save, :del]
31
- }
32
- )
33
- end
34
-
35
- def actions
36
- super.merge(
37
- :save => {:text => "Save", :icon => Netzke::Base.config[:with_icons] && (Netzke::Base.config[:icons_uri] + "disk.png")},
38
- :del => {:text => "Delete", :icon => Netzke::Base.config[:with_icons] && (Netzke::Base.config[:icons_uri] + "delete.png")}
39
- )
40
- end
41
-
42
- def self.js_extend_properties
43
- {
44
- :remove_search_from_list => <<-END_OF_JAVASCRIPT.l,
45
- function(name){
46
- var presetsCombo = Ext.getCmp("presets-combo");
47
- var presetsComboStore = presetsCombo.getStore();
48
- presetsComboStore.removeAt(presetsComboStore.find('field1', name));
49
- presetsCombo.reset();
50
- this.getForm().reset();
51
- }
52
- END_OF_JAVASCRIPT
53
-
54
- :set_values => <<-END_OF_JAVASCRIPT.l,
55
- function(values){
56
- this.getForm().setValues(Ext.decode(values));
57
- }
58
- END_OF_JAVASCRIPT
59
-
60
- :select_preset => <<-END_OF_JAVASCRIPT.l,
61
- function(name){
62
- this.getForm().reset();
63
- this.loadSearch({name: name});
64
- }
65
- END_OF_JAVASCRIPT
66
-
67
- :on_save => <<-END_OF_JAVASCRIPT.l,
68
- function(){
69
- var searchName = Ext.getCmp("presets-combo").getValue();
70
- if (searchName !== "") {
71
- var presetsComboStore = Ext.getCmp("presets-combo").getStore();
72
- if (presetsComboStore.find('field1', searchName) !== -1) {
73
- Ext.Msg.confirm("Overwriting preset '" + searchName + "'", "Are you sure you want to overwrite this preset?", function(btn, text){
74
- if (btn == 'yes') {
75
- this.doSavePreset(searchName);
76
- }
77
- }, this);
78
- } else {
79
- this.doSavePreset(searchName);
80
- presetsComboStore.add(new presetsComboStore.recordType({field1: searchName}));
81
- }
82
- }
83
- }
84
- END_OF_JAVASCRIPT
85
-
86
- :do_save_preset => <<-END_OF_JAVASCRIPT.l,
87
- function(name){
88
- var values = this.getForm().getValues();
89
- for (var k in values) {
90
- if (values[k] == "") {delete values[k]}
91
- }
92
-
93
- this.saveSearch({
94
- name: name,
95
- values: Ext.encode(values)
96
- });
97
- }
98
- END_OF_JAVASCRIPT
99
-
100
- :on_del => <<-END_OF_JAVASCRIPT.l,
101
- function(){
102
- var searchName = Ext.getCmp("presets-combo").getValue();
103
- if (searchName !== "") {
104
- Ext.Msg.confirm("Deleting preset '" + searchName + "'", "Are you sure you want to delete this preset?", function(btn, text){
105
- if (btn == 'yes') {
106
- this.deleteSearch({
107
- name: searchName
108
- });
109
- }
110
- }, this);
111
- }
112
- }
113
- END_OF_JAVASCRIPT
114
-
115
- }
116
- end
117
-
118
- api :save_search
119
- def save_search(params)
120
- saved_searches = persistent_config[:saved_searches] || []
121
- existing = saved_searches.detect{ |s| s["name"] == params[:name] }
122
- values = ActiveSupport::JSON.decode(params[:values])
123
- if existing
124
- existing["values"].replace(values)
125
- else
126
- saved_searches << {"name" => params[:name], "values" => values}
127
- end
128
- persistent_config[:saved_searches] = saved_searches
129
- {:feedback => "Preset successfully saved"}
130
- end
131
-
132
- api :delete_search
133
- def delete_search(params)
134
- saved_searches = persistent_config[:saved_searches]
135
- saved_searches.delete_if{ |s| s["name"] == params[:name] }
136
- {:feedback => "Preset successfully deleted", :remove_search_from_list => params[:name]}
137
- end
138
-
139
- api :load_search
140
- def load_search(params)
141
- saved_searches = persistent_config[:saved_searches]
142
- the_search = saved_searches.detect{ |s| s["name"] == params[:name] }
143
-
144
- {:set_values => the_search["values"].to_json}
145
- end
146
-
147
- def initial_fields(only_included = true)
148
- res = super
149
-
150
- res.reject!{ |f| f[:virtual] }
151
-
152
- res.each do |f|
153
- f.merge!(:condition => "like", :default_value => nil)
154
- f.merge!(:xtype => xtype_for_attr_type(:string), :attr_type => "string") if f[:name].to_s.index("__")
155
- f.merge!(:condition => "greater_than") if [:datetime, :integer, :date].include?(f[:attr_type])
156
- f.merge!(:condition => "equals") if f[:attr_type] == :boolean
157
- end
158
-
159
- res
160
- end
161
-
162
- # columns to be displayed by the FieldConfigurator (which is GridPanel-based)
163
- def self.meta_columns
164
- [
165
- {:name => "hidden", :attr_type => :boolean, :editor => :checkbox, :width => 50},
166
- {:name => "name", :attr_type => :string, :editor => :combobox},
167
- {:name => "condition", :attr_type => :string, :editor => {:xtype => :combo, :store => CONDITIONS}},
168
- {:name => "field_label", :attr_type => :string},
169
- {:name => "xtype", :attr_type => :string},
170
- {:name => "value", :attr_type => :string},
171
- ]
172
- end
173
-
174
- # tweaking the form fields at the last moment
175
- def js_config
176
- super.merge({
177
- :fields => fields.map{ |c| c.merge({
178
- :label => "#{c[:label] || c[:name]} #{c[:condition]}".humanize,
179
- :name => "#{c[:name]}_#{c[:condition]}"
180
- })}
181
- })
182
- end
183
-
184
- private
185
- # we need to correct the queries to cut off the condition suffixes, otherwise the FormPanel gets confused
186
- def get_combobox_options(params)
187
- column_name = params[:column]
188
- CONDITIONS.each { |c| column_name.sub!(/_#{c}$/, "") }
189
- super(:column => column_name)
190
- end
191
-
192
- def attr_type_to_xtype_map
193
- super.merge({
194
- :boolean => :tricheckbox
195
- })
196
- end
197
-
198
- end
199
- end
@@ -1,174 +0,0 @@
1
- module Netzke
2
- # TabPanel
3
- #
4
- # Features:
5
- # * Dynamically loads widgets for the tabs that get activated for the first time
6
- # * Is loaded along with the active widget - saves a request to the server
7
- # * Provides the method markTabsOutdated to mark all inactive tabs as 'outdated', and calls "update" method on widgets in tabs when they get activated
8
- #
9
- # TODO:
10
- # * Stores the last active tab in persistent_config
11
- # * Introduce a second or two delay before informing the server about a tab switched
12
- #
13
- class TabPanel < Base
14
- api :api_activate_tab
15
-
16
- def self.js_base_class
17
- "Ext.TabPanel"
18
- end
19
-
20
- def self.js_extend_properties
21
- {
22
- :id_delimiter => "___", # the default was "__", which conflicts with Netzke's double underscore notation
23
- :defaults => {:layout => 'fit'}, # all tabs will be Ext.Panel-s with layout 'fit' ("fit-panels")
24
-
25
- :render => <<-END_OF_JAVASCRIPT.l,
26
- function(el){
27
- #{js_full_class_name}.superclass.render.call(this, el);
28
-
29
- // We do this all in +render+ because only at this moment the activeTab is actually activated
30
- var activeTab = this.getActiveTab();
31
-
32
- // Insert (render) preloaded widgets into their respective tabs
33
- this.items.each(function(fitPanel){
34
- var preloadedItemConfig = this[fitPanel.widget.camelize(true)+"Config"];
35
- if (preloadedItemConfig){
36
- var klass = this.classifyScopedName(preloadedItemConfig.scopedClassName);
37
- fitPanel.add(new klass(preloadedItemConfig));
38
- fitPanel.doLayout();
39
- }
40
- }, this);
41
-
42
- // setting the tabchange event
43
- this.on('tabchange', this.onTabChange, this);
44
- }
45
- END_OF_JAVASCRIPT
46
-
47
- # loads widget from the server
48
- :load_widget_into => <<-END_OF_JAVASCRIPT.l,
49
- function(fitPanel){
50
- this.loadAggregatee({id:fitPanel.widget, container:fitPanel.id});
51
- }
52
- END_OF_JAVASCRIPT
53
-
54
- :mark_tabs_outdated => <<-END_OF_JAVASCRIPT.l,
55
- function(){
56
- this.items.each(function(i){
57
- if (this.getActiveTab() != i){
58
- i.outdated = true
59
- }
60
- }, this);
61
- }
62
- END_OF_JAVASCRIPT
63
-
64
- # bulkExecute in active tab
65
- :execute_in_active_tab => <<-END_OF_JAVASCRIPT.l,
66
- function(commands){
67
- this.getActiveTab().getWidget().bulkExecute(commands);
68
- }
69
- END_OF_JAVASCRIPT
70
-
71
- :get_loaded_children => <<-END_OF_JAVASCRIPT.l,
72
- function(){
73
- var res = [];
74
- this.items.each(function(tab){
75
- var kid = tab.getWidget();
76
- if (kid) { res.push(kid) }
77
- }, this);
78
- return res;
79
- }
80
- END_OF_JAVASCRIPT
81
-
82
- :on_tab_change => <<-END_OF_JAVASCRIPT.l
83
- function(self, tab) {
84
- // load widget into the panel from the server if it's not there yet
85
- if (!tab.getWidget()) {
86
- this.loadWidgetInto(tab);
87
- }
88
-
89
- // inform the server about active tab change
90
- this.apiActivateTab({tab:tab.widget});
91
-
92
- // call "update" on the widget
93
- if (tab.outdated) {
94
- tab.outdated = false;
95
- var widget = tab.getWidget();
96
- if (widget && widget.update) {widget.update.call(widget)};
97
- }
98
- }
99
- END_OF_JAVASCRIPT
100
- }
101
- end
102
-
103
- def items
104
- @items ||= config[:items]
105
- end
106
-
107
- def js_config
108
- super.merge({
109
- :items => fit_panels,
110
- :active_tab => global_id + '_active' # id of the fit panel that is active
111
- })
112
- end
113
-
114
- # some configuration normalization
115
- def initialize(*args)
116
- super
117
-
118
- # to remove duplicated active tabs
119
- first_active = nil
120
-
121
- items.each_with_index do |item, i|
122
- # if the item is provided without a name, give it a generated name
123
- item[:name] ||= "item#{i}"
124
-
125
- # remove duplicated "active" configuration
126
- if item[:active]
127
- if first_active.nil?
128
- first_active = item.name
129
- else
130
- item[:active] = nil
131
- end
132
- end
133
- end
134
-
135
- # the first tab is forced to become active, if none was configured as active
136
- items.first[:active] = true and first_active = items.first.name if first_active.nil?
137
-
138
- widget_session[:active_tab] = first_active
139
- end
140
-
141
- # the items are late aggregatees, besides the one that is configured active
142
- def initial_aggregatees
143
- res = {}
144
- items.each_with_index do |item, i|
145
- item[:late_aggregation] = !item[:active] && !item[:preloaded]
146
- res.merge!(item[:name].to_sym => item)
147
- end
148
- res
149
- end
150
-
151
- # "Fit panels" - Panels with layout 'fit' that serve as containers for (dynamically) loaded widgets
152
- def fit_panels
153
- res = []
154
- items.each_with_index do |item, i|
155
- item_config = {
156
- :id => item[:active] && global_id + '_active',
157
- :title => item[:title] || (item[:name] && item[:name].humanize),
158
- :widget => item[:name] # to know which fit-panel will load which widget
159
- }
160
- res << item_config
161
- end
162
- res
163
- end
164
-
165
- def api_activate_tab(params)
166
- widget_session[:active_tab] = params[:tab]
167
- {}
168
- end
169
-
170
- def get_active_tab
171
- aggregatee_instance(widget_session[:active_tab])
172
- end
173
- end
174
- end