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,163 +0,0 @@
1
- module Netzke
2
- class FormPanel < Base
3
- module FormPanelJs
4
- # parameters used to instantiate the JS object
5
- def js_config
6
- res = super
7
- res.merge!(:fields => fields)
8
- res.merge!(:model => data_class.name) if data_class
9
- res.merge!(:pri => data_class.primary_key) if data_class
10
- res
11
- end
12
-
13
- module ClassMethods
14
- def js_base_class
15
- "Ext.FormPanel"
16
- end
17
-
18
- def js_extend_properties
19
- {
20
- :body_style => 'padding:5px 5px 0',
21
- :auto_scroll => true,
22
- :label_width => 150,
23
- :default_type => 'textfield',
24
-
25
- :init_component => <<-END_OF_JAVASCRIPT.l,
26
- function(){
27
- var recordFields = []; // Record
28
- this.items = [];
29
- var index = 0;
30
-
31
- // Process columns
32
- Ext.each(this.fields, function(field){
33
- if (!field.hidden || field.name == this.pri) {
34
- recordFields.push({name:field.name, mapping:index++});
35
-
36
- var defaultColumnConfig = Ext.apply({}, this.defaultColumnConfig);
37
- var columnConfig = Ext.apply(defaultColumnConfig, field);
38
-
39
- // apply dynamically defined properties
40
- Ext.applyIf(columnConfig, {
41
- xtype : this.attrTypeEditorMap[columnConfig.attrType],
42
- fieldLabel: columnConfig.fieldLabel || columnConfig.label || columnConfig.name.humanize(),
43
- hideLabel : columnConfig.hidden, // completely hide fields marked "hidden"
44
- parentId : this.id,
45
- name : columnConfig.name,
46
- value : columnConfig.value || columnConfig.defaultValue,
47
- checked : columnConfig.attrType == "boolean" ? columnConfig.value : null // checkbox state
48
- });
49
-
50
- this.items.push(columnConfig);
51
- }
52
- }, this);
53
-
54
- var Record = Ext.data.Record.create(recordFields);
55
- this.reader = new Ext.data.RecordArrayReader({root:"data"}, Record);
56
-
57
- delete this.fields; // we don't need them anymore
58
-
59
- // Now let Ext.form.FormPanel do the rest
60
- #{js_full_class_name}.superclass.initComponent.call(this);
61
-
62
- // Apply event
63
- this.addEvents('apply');
64
- }
65
- END_OF_JAVASCRIPT
66
-
67
- :attr_type_editor_map => {
68
- :integer => "numberfield",
69
- :boolean => "checkbox",
70
- :decimal => "numberfield",
71
- :datetime => "xdatetime",
72
- :date => "datefield",
73
- :string => "textfield"
74
- },
75
-
76
- # Defaults for each field
77
- :defaults => {
78
- :anchor => '-20', # to leave some space for the scrollbar
79
- # :width => 180, # we do NOT want fixed size because it doesn't look nice when resizing
80
- :listeners => {
81
- # On "return" key, submit the form
82
- :specialkey => {
83
- :fn => <<-END_OF_JAVASCRIPT.l
84
- function(field, event){
85
- if (event.getKey() == 13) this.ownerCt.onApply();
86
- }
87
- END_OF_JAVASCRIPT
88
- }
89
- }
90
- },
91
-
92
- # :default_column_config => meta_columns.inject({}){ |r, c| r.merge!({
93
- # c[:name] => c[:default_value]
94
- # })},
95
-
96
- :set_form_values => <<-END_OF_JAVASCRIPT.l,
97
- function(values){
98
- this.form.loadRecord(this.reader.readRecords({data:[values]}).records[0]);
99
- }
100
- END_OF_JAVASCRIPT
101
-
102
- :load_record => <<-END_OF_JAVASCRIPT.l,
103
- function(id, neighbour){
104
- this.netzkeLoad({id:id});
105
- }
106
- END_OF_JAVASCRIPT
107
-
108
- # :previous => <<-END_OF_JAVASCRIPT.l,
109
- # function() {
110
- # var currentId = this.form.getValues().id;
111
- # this.loadRecord(currentId, 'previous');
112
- # }
113
- # END_OF_JAVASCRIPT
114
- #
115
- # :next => <<-END_OF_JAVASCRIPT.l,
116
- # function() {
117
- # var currentId = this.form.getValues().id;
118
- # this.loadRecord(currentId, 'next');
119
- # }
120
- # END_OF_JAVASCRIPT
121
-
122
- :on_apply => <<-END_OF_JAVASCRIPT.l
123
- function() {
124
- if (this.fireEvent('apply', this)) {
125
- var values = this.getForm().getValues();
126
- for (var k in values) {
127
- if (values[k] == "") {delete values[k]}
128
- }
129
- if (this.fileUpload) {
130
- // Not a Netzke's standard API call, because the form is multipart
131
- this.getForm().submit({
132
- url: this.buildApiUrl("netzke_submit"),
133
- params: {
134
- data: Ext.encode(values)
135
- },
136
- failure: function(form, action){
137
- // It will always be failure, as we don't play along with the Ext success indication (not returning {success: true})
138
- this.bulkExecute(Ext.decode(action.response.responseText));
139
- this.fireEvent('submitsuccess');
140
- },
141
- scope: this
142
- });
143
- } else {
144
- // Submit the data and process the result
145
- this.netzkeSubmit(Ext.apply((this.baseParams || {}), {data:Ext.encode(values)}), function(result){
146
- if (result === "ok") {this.fireEvent("submitsuccess")};
147
- }, this);
148
- }
149
- }
150
- }
151
- END_OF_JAVASCRIPT
152
- }
153
- end
154
-
155
- end
156
-
157
- def self.included(base)
158
- base.extend ClassMethods
159
- end
160
-
161
- end
162
- end
163
- end
@@ -1,367 +0,0 @@
1
- require "netzke/grid_panel/grid_panel_js"
2
- require "netzke/grid_panel/grid_panel_api"
3
- require "netzke/grid_panel/grid_panel_columns"
4
- require "netzke/plugins/configuration_tool"
5
- require "netzke/data_accessor"
6
-
7
- module Netzke
8
- # == GridPanel
9
- # Ext.grid.EditorGridPanel + server-side code
10
- #
11
- # == Features:
12
- # * multi-line CRUD operations - get, post, delete, create
13
- # * (multe-record) editing and adding records through a form
14
- # * column resize, move and hide
15
- # * permissions
16
- # * sorting
17
- # * pagination
18
- # * filtering
19
- # * extended configurable search
20
- # * rows reordering (drag-n-drop)
21
- # * dynamic configuration of properties and columns
22
- #
23
- # == Class configuration
24
- # Configuration on this level is effective during the life-time of the application. They can be put into a .rb file
25
- # inside of config/initializers like this:
26
- #
27
- # Netzke::GridPanel.configure :column_filters_available, false
28
- # Netzke::GridPanel.configure :default_config => {:ext_config => {:enable_config_tool => false}}
29
- #
30
- # Most of these options directly influence the amount of JavaScript code that is generated for this widget's class.
31
- # The less functionality is enabled, the less code is generated.
32
- #
33
- # The following configuration options are available:
34
- # * <tt>:column_filters_available</tt> - (default is true) include code for the filters in the column's context menu
35
- # * <tt>:config_tool_available</tt> - (default is true) include code for the configuration tool that launches the configuration panel
36
- # * <tt>:edit_in_form_available</tt> - (defaults to true) include code for (multi-record) editing and adding records through a form
37
- # * <tt>:extended_search_available</tt> - (defaults to true) include code for extended configurable search
38
- # * <tt>:default_config</tt> - a hash of default configuration options for each instance of the GridPanel widget.
39
- # See the "Instance configuration" section below.
40
- #
41
- # == Instance configuration
42
- # The following config options are available:
43
- # * <tt>:model</tt> - name of the ActiveRecord model that provides data to this GridPanel.
44
- # * <tt>:strong_default_attrs</tt> - a hash of attributes to be merged atop of every created/updated record.
45
- # * <tt>:scopes</tt> - an array of named scopes to filter grid data, e.g.:
46
- #
47
- # [["user_id_not", 100], ["name_like", "Peter"], :recent]
48
- #
49
- # In the <tt>:ext_config</tt> hash (see Netzke::Base) the following GridPanel specific options are available:
50
- #
51
- # * <tt>:enable_column_filters</tt> - enable filters in column's context menu
52
- # * <tt>:enable_edit_in_form</tt> - provide buttons into the toolbar that activate editing/adding records via a form
53
- # * <tt>:enable_extended_search</tt> - provide a button into the toolbar that shows configurable search form
54
- # * <tt>:enable_context_menu</tt> - enable rows context menu
55
- # * <tt>:enable_rows_reordering</tt> - enable reordering of rows with drag-n-drop; underlying model (specified in <tt>:model</tt>) must implement "acts_as_list"-compatible functionality; defaults to <tt>false</tt>
56
- # * <tt>:enable_pagination</tt> - enable pagination; defaults to <tt>true</tt>
57
- # * <tt>:rows_per_page</tt> - number of rows per page (ignored when <tt>:enable_pagination</tt> is set to <tt>false</tt>)
58
- # * <tt>:load_inline_data</tt> - load initial data into the grid right after its instantiation (saves a request to server); defaults to <tt>true</tt>
59
- # * <tt>:mode</tt> - when set to <tt>:config</tt>, GridPanel loads in configuration mode
60
- # * <tt>:add/edit/multi_edit/search_form_config</tt> - additional configuration for add/edit/multi_edit/search form panel
61
- # * <tt>:add/edit/multi_edit_form_window_config</tt> - additional configuration for the window that wrapps up add/edit/multi_edit form panel
62
- #
63
- # Additionally supports Netzke::Base config options.
64
- #
65
- # == Columns
66
- # Here's how the GridPanel decides which columns in which sequence and with which configuration to display.
67
- # First, the column configs are aquired from this GridPanel's persistent storage, as an array of hashes, each
68
- # representing a column configuration, such as:
69
- #
70
- # {:name => :created_at, :header => "Created", :tooltip => "When the record was created"}
71
- #
72
- # This hash *overrides* (deep_merge) the hard-coded configuration, an example of which can be specifying
73
- # columns for a GridPanel instance, e.g.:
74
- #
75
- # :columns => [{:name => :created_at, :sortable => false}]
76
- #
77
- # ... which in its turn overrides the defaults provided by persistent storage managed by the AttributesConfigurator
78
- # that provides *model-level* (as opposed to a widget-level) configuration of a database model
79
- # (which is used by both grids and forms in Netzke).
80
- # And lastly, the defaults for AttributesConfigurator are calculated from the database model itself (extended by Netzke).
81
- # For example, in the model you can specify virtual attributes and their types that will be picked up by Netzke, the default
82
- # order of columns, or excluded columns. For details see <tt>Netzke::ActiveRecord::Attributes</tt>.
83
- #
84
- # The columns are displayed in the order specified by what's found first in the following sequence:
85
- # GridPanel instance's persistent storage
86
- # hardcoded config
87
- # AttributesConfigurator persistent storage
88
- # netzke_expose_attributes in the database model
89
- # database columns + (eventually) virtual attributes specified with netzke_attribute
90
- class GridPanel < Base
91
- # javascript (client-side)
92
- include GridPanelJs
93
-
94
- # API (server-side)
95
- include GridPanelApi
96
-
97
- # Columns
98
- include GridPanelColumns
99
-
100
- # Code shared between GridPanel, FormPanel, and other widgets that serve as interface to database tables
101
- include Netzke::DataAccessor
102
-
103
- def self.enforce_config_consistency
104
- config[:default_config][:ext_config][:enable_edit_in_form] &&= config[:edit_in_form_available]
105
- config[:default_config][:ext_config][:enable_extended_search] &&= config[:extended_search_available]
106
- config[:default_config][:ext_config][:enable_rows_reordering] &&= config[:rows_reordering_available]
107
- end
108
-
109
- # Class-level configuration. This options directly influence the amount of generated
110
- # javascript code for this widget's class. For example, if you don't want filters for the grid,
111
- # set :column_filters_available to false, and the javascript for the filters won't be included at all.
112
- def self.config
113
- set_default_config({
114
-
115
- :column_filters_available => true,
116
- :config_tool_available => true,
117
- :edit_in_form_available => true,
118
- :extended_search_available => true,
119
- :rows_reordering_available => true,
120
-
121
- :default_config => {
122
- :ext_config => {
123
- :enable_edit_in_form => true,
124
- :enable_extended_search => true,
125
- :enable_column_filters => true,
126
- :load_inline_data => true,
127
- :enable_context_menu => true,
128
- :enable_rows_reordering => false, # column drag n drop
129
- :enable_pagination => true,
130
- :rows_per_page => 25,
131
- :tools => %w{ refresh },
132
-
133
- :mode => :normal # when set to :config, :configuration button is enabled
134
- },
135
- :persistent_config => true
136
-
137
- }
138
- })
139
- end
140
-
141
- # Include extra javascript that we depend on
142
- def self.include_js
143
- res = ["#{File.dirname(__FILE__)}/grid_panel/javascripts/grid_panel_pre.js"]
144
-
145
- # Optional edit in form functionality
146
- res << "#{File.dirname(__FILE__)}/grid_panel/javascripts/edit_in_form.js" if config[:edit_in_form_available]
147
-
148
- # Optional extended search functionality
149
- res << "#{File.dirname(__FILE__)}/grid_panel/javascripts/advanced_search.js" if config[:extended_search_available]
150
-
151
- # Checkcolumn
152
- ext_examples = Netzke::Base.config[:ext_location] + "/examples/"
153
- res << ext_examples + "ux/CheckColumn.js"
154
-
155
- # Filters
156
- if config[:column_filters_available]
157
- ext_examples = Netzke::Base.config[:ext_location] + "/examples/"
158
- res << ext_examples + "ux/gridfilters/menu/ListMenu.js"
159
- res << ext_examples + "ux/gridfilters/menu/RangeMenu.js"
160
- res << ext_examples + "ux/gridfilters/GridFilters.js"
161
-
162
- %w{Boolean Date List Numeric String}.unshift("").each do |f|
163
- res << ext_examples + "ux/gridfilters/filter/#{f}Filter.js"
164
- end
165
-
166
- end
167
-
168
- # DD
169
- if config[:rows_reordering_available]
170
- res << "#{File.dirname(__FILE__)}/grid_panel/javascripts/rows-dd.js"
171
- end
172
-
173
- res
174
- end
175
-
176
- # Define connection points between client side and server side of GridPanel.
177
- # See implementation of equally named methods in the GridPanelApi module.
178
- api :get_data, :post_data, :delete_data, :resize_column, :move_column, :hide_column, :get_combobox_options, :move_rows
179
-
180
- # Edit in form
181
- api :create_new_record if config[:edit_in_form_available]
182
-
183
- # Model class
184
- # (We can't memoize this method because at some point we extend it, e.g. in Netzke::DataAccessor)
185
- def data_class
186
- @data_class ||= begin
187
- klass = "Netzke::ModelExtensions::#{config[:model]}For#{short_widget_class_name}".constantize rescue nil
188
- klass || original_data_class
189
- end
190
- end
191
-
192
- # Model class before model extensions are taken into account
193
- def original_data_class
194
- @original_data_class ||= begin
195
- ::ActiveSupport::Deprecation.warn("data_class_name option is deprecated. Use model instead", caller) if config[:data_class_name]
196
- model_name = config[:model] || config[:data_class_name]
197
- model_name.nil? ? raise(ArgumentError, "No model specified for widget #{global_id}") : model_name.constantize
198
- end
199
- end
200
-
201
- def initialize(config = {}, parent = nil)
202
- super
203
- apply_helpers
204
- end
205
-
206
- # Fields to be displayed in the "General" tab of the configuration panel
207
- def self.property_fields
208
- [
209
- {:name => :ext_config__title, :attr_type => :string},
210
- {:name => :ext_config__header, :attr_type => :boolean, :default => true},
211
- {:name => :ext_config__enable_context_menu, :attr_type => :boolean, :default => true},
212
- {:name => :ext_config__enable_pagination, :attr_type => :boolean, :default => true},
213
- {:name => :ext_config__rows_per_page, :attr_type => :integer},
214
- {:name => :ext_config__prohibit_create, :attr_type => :boolean},
215
- {:name => :ext_config__prohibit_update, :attr_type => :boolean},
216
- {:name => :ext_config__prohibit_delete, :attr_type => :boolean},
217
- {:name => :ext_config__prohibit_read, :attr_type => :boolean}
218
- ]
219
- end
220
-
221
- def default_bbar
222
- res = %w{ add edit apply del }
223
- res << "-" << "add_in_form" << "edit_in_form" if ext_config[:enable_edit_in_form]
224
- res << "-" << "search" if ext_config[:enable_extended_search]
225
- res
226
- end
227
-
228
- def default_context_menu
229
- res = %w{ edit del }
230
- res << "-" << "edit_in_form" if ext_config[:enable_edit_in_form]
231
- res
232
- end
233
-
234
- def configuration_widgets
235
- res = []
236
- res << {
237
- :persistent_config => true,
238
- :name => 'columns',
239
- :class_name => "FieldsConfigurator",
240
- :active => true,
241
- :owner => self
242
- }
243
- res << {
244
- :name => 'general',
245
- :class_name => "PropertyEditor",
246
- :widget => self,
247
- :ext_config => {:title => false}
248
- }
249
- res
250
- end
251
-
252
- def actions
253
- # Defaults
254
- actions = {
255
- :add => {:text => 'Add', :disabled => ext_config[:prohibit_create]},
256
- :edit => {:text => 'Edit', :disabled => true},
257
- :del => {:text => 'Delete', :disabled => true},
258
- :apply => {:text => 'Apply', :disabled => ext_config[:prohibit_update] && ext_config[:prohibit_create]},
259
- :add_in_form => {:text => 'Add in form', :disabled => !ext_config[:enable_edit_in_form]},
260
- :edit_in_form => {:text => 'Edit in form', :disabled => true},
261
- :search => {:text => 'Search', :disabled => !ext_config[:enable_extended_search], :checked => true}
262
- }
263
-
264
- if Netzke::Base.config[:with_icons]
265
- icons_uri = Netzke::Base.config[:icons_uri]
266
- actions.deep_merge!(
267
- :add => {:icon => icons_uri + "add.png"},
268
- :edit => {:icon => icons_uri + "table_edit.png"},
269
- :del => {:icon => icons_uri + "table_row_delete.png"},
270
- :apply => {:icon => icons_uri + "tick.png"},
271
- :add_in_form => {:icon => icons_uri + "application_form_add.png"},
272
- :edit_in_form => {:icon => icons_uri + "application_form_edit.png"},
273
- :search => {:icon => icons_uri + "find.png"}
274
- )
275
- end
276
-
277
- actions
278
- end
279
-
280
- def initial_late_aggregatees
281
- res = {}
282
-
283
- # Edit in form
284
- res.merge!({
285
- :add_form => {
286
- :class_name => "GridPanel::RecordFormWindow",
287
- :ext_config => {
288
- :title => "Add #{data_class.table_name.singularize.humanize}",
289
- :button_align => "right"
290
- },
291
- :item => {
292
- :class_name => "FormPanel",
293
- :model => config[:model],
294
- :fields => default_fields_for_forms,
295
- :persistent_config => config[:persistent_config],
296
- :strong_default_attrs => config[:strong_default_attrs],
297
- :ext_config => {
298
- :border => true,
299
- :bbar => false,
300
- :header => false,
301
- :mode => ext_config[:mode]
302
- },
303
- :record => data_class.new
304
- }.deep_merge(config[:add_form_config] || {})
305
- }.deep_merge(config[:add_form_window_config] || {}),
306
-
307
- :edit_form => {
308
- :class_name => "GridPanel::RecordFormWindow",
309
- :ext_config => {
310
- :title => "Edit #{data_class.table_name.singularize.humanize}",
311
- :button_align => "right"
312
- },
313
- :item => {
314
- :class_name => "FormPanel",
315
- :model => config[:model],
316
- :fields => default_fields_for_forms,
317
- :persistent_config => config[:persistent_config],
318
- :ext_config => {
319
- :bbar => false,
320
- :header => false,
321
- :mode => ext_config[:mode]
322
- }
323
- }.deep_merge(config[:edit_form_config] || {})
324
- }.deep_merge(config[:edit_form_window_config] || {}),
325
-
326
- :multi_edit_form => {
327
- :class_name => "GridPanel::RecordFormWindow",
328
- :ext_config => {
329
- :title => "Edit #{data_class.table_name.humanize}",
330
- :button_align => "right"
331
- },
332
- :item => {
333
- :class_name => "GridPanel::MultiEditForm",
334
- :model => config[:model],
335
- :fields => default_fields_for_forms,
336
- :persistent_config => config[:persistent_config],
337
- :ext_config => {
338
- :bbar => false,
339
- :header => false,
340
- :mode => ext_config[:mode]
341
- }
342
- }.deep_merge(config[:multi_edit_form_config] || {})
343
- }.deep_merge(config[:multi_edit_form_window_config] || {})
344
- }) if ext_config[:enable_edit_in_form]
345
-
346
- # Extended search
347
- res.merge!({
348
- :search_panel => {
349
- :class_name => "SearchPanel",
350
- :fields => default_fields_for_forms,
351
- :search_class_name => config[:model],
352
- :persistent_config => config[:persistent_config],
353
- :ext_config => {
354
- :header => false,
355
- :bbar => false,
356
- :mode => ext_config[:mode]
357
- },
358
- }.deep_merge(config[:search_form_config] || {})
359
- }) if ext_config[:enable_extended_search]
360
-
361
- res
362
- end
363
-
364
- include Plugins::ConfigurationTool if config[:config_tool_available] # it will load ConfigurationPanel into a modal window
365
-
366
- end
367
- end