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.
- data/.gitignore +3 -2
- data/CHANGELOG.rdoc +15 -0
- data/README.rdoc +45 -50
- data/Rakefile +8 -8
- data/TODO.rdoc +1 -6
- data/app/components/netzke/basepack/accordion_panel.rb +37 -0
- data/app/components/netzke/basepack/basic_app.rb +267 -0
- data/{lib/netzke → app/components/netzke/basepack}/basic_app/statusbar_ext.js +0 -0
- data/app/components/netzke/basepack/border_layout_panel.rb +39 -0
- data/app/components/netzke/basepack/form_panel.rb +102 -0
- data/app/components/netzke/basepack/form_panel/fields.rb +206 -0
- data/{lib/netzke → app/components/netzke/basepack}/form_panel/javascripts/netzkefileupload.js +0 -0
- data/app/components/netzke/basepack/form_panel/javascripts/pre.js +76 -0
- data/{lib/netzke → app/components/netzke/basepack}/form_panel/javascripts/xcheckbox.js +0 -0
- data/app/components/netzke/basepack/form_panel/services.rb +99 -0
- data/app/components/netzke/basepack/grid_panel.rb +374 -0
- data/app/components/netzke/basepack/grid_panel/columns.rb +233 -0
- data/app/components/netzke/basepack/grid_panel/javascript.rb +69 -0
- data/app/components/netzke/basepack/grid_panel/javascripts/advanced_search.js +96 -0
- data/{lib/netzke → app/components/netzke/basepack}/grid_panel/javascripts/edit_in_form.js +5 -4
- data/{lib/netzke/grid_panel/javascripts/grid_panel_pre.js → app/components/netzke/basepack/grid_panel/javascripts/pre.js} +17 -37
- data/{lib/netzke → app/components/netzke/basepack}/grid_panel/javascripts/rows-dd.js +0 -0
- data/app/components/netzke/basepack/grid_panel/multi_edit_form.rb +16 -0
- data/app/components/netzke/basepack/grid_panel/record_form_window.rb +36 -0
- data/app/components/netzke/basepack/grid_panel/search_window.rb +56 -0
- data/app/components/netzke/basepack/grid_panel/services.rb +356 -0
- data/app/components/netzke/basepack/panel.rb +11 -0
- data/app/components/netzke/basepack/search_panel.rb +59 -0
- data/app/components/netzke/basepack/tab_panel.rb +32 -0
- data/app/components/netzke/basepack/window.rb +73 -0
- data/app/components/netzke/basepack/wrapper.rb +28 -0
- data/{lib/app → app}/models/netzke_field_list.rb +1 -1
- data/{lib/app → app}/models/netzke_model_attr_list.rb +0 -0
- data/{lib/app → app}/models/netzke_persistent_array_auto_model.rb +0 -0
- data/config/database.yml +35 -0
- data/features/accordion_panel.feature +15 -0
- data/features/basic_app.feature +12 -0
- data/features/form_panel.feature +40 -0
- data/features/grid_panel.feature +62 -0
- data/features/search_in_grid.feature +35 -0
- data/features/simple_panel.feature +15 -0
- data/features/step_definitions/accordion_steps.rb +9 -0
- data/features/step_definitions/generic_steps.rb +15 -0
- data/features/step_definitions/grid_panel_steps.rb +26 -0
- data/features/step_definitions/pickle_steps.rb +100 -0
- data/features/step_definitions/web_steps.rb +219 -0
- data/features/support/env.rb +66 -0
- data/features/support/paths.rb +59 -0
- data/features/support/pickle.rb +25 -0
- data/features/tab_panel.feature +15 -0
- data/features/window.feature +11 -0
- data/from_05_to_06.rdoc +2 -0
- data/javascripts/basepack.js +54 -2
- data/lib/netzke-basepack.rb +38 -25
- data/lib/netzke/active_record.rb +12 -4
- data/lib/netzke/active_record/attributes.rb +60 -5
- data/lib/netzke/active_record/combobox_options.rb +3 -2
- data/lib/netzke/active_record/relation_extensions.rb +35 -0
- data/lib/netzke/basepack.rb +27 -0
- data/lib/netzke/basepack/version.rb +11 -0
- data/lib/netzke/basepack/wrap_lazy_loaded.rb +26 -0
- data/lib/netzke/data_accessor.rb +60 -32
- data/lib/netzke/fields_configurator.rb +5 -9
- data/lib/netzke/masquerade_selector.rb +1 -1
- data/locale/en.yml +16 -0
- data/netzke-basepack.gemspec +298 -0
- data/spec/active_record/attributes_spec.rb +14 -0
- data/spec/active_record/relation_extensions_spec.rb +44 -0
- data/spec/components/form_panel_spec.rb +70 -0
- data/spec/components/grid_panel_spec.rb +10 -0
- data/spec/factories.rb +9 -0
- data/spec/spec_helper.rb +35 -0
- data/test/rails_app/.gitignore +4 -0
- data/test/rails_app/Gemfile +32 -0
- data/test/rails_app/Gemfile.lock +171 -0
- data/test/rails_app/README +256 -0
- data/test/rails_app/Rakefile +7 -0
- data/test/rails_app/app/components/generic_user_form.rb +12 -0
- data/test/rails_app/app/components/simple_accordion.rb +11 -0
- data/test/rails_app/app/components/simple_basic_app.rb +32 -0
- data/test/rails_app/app/components/simple_panel.rb +17 -0
- data/test/rails_app/app/components/simple_tab_panel.rb +11 -0
- data/test/rails_app/app/components/simple_wrapper.rb +7 -0
- data/test/rails_app/app/components/some_border_layout.rb +24 -0
- data/test/rails_app/app/components/some_search_panel.rb +34 -0
- data/test/rails_app/app/components/some_tab_panel.rb +15 -0
- data/test/rails_app/app/components/user_form.rb +21 -0
- data/test/rails_app/app/components/user_form_with_default_fields.rb +8 -0
- data/test/rails_app/app/components/user_grid.rb +4 -0
- data/test/rails_app/app/components/window_component_loader.rb +17 -0
- data/test/{app_root/app/controllers/application.rb → rails_app/app/controllers/application_controller.rb} +1 -0
- data/test/rails_app/app/controllers/components_controller.rb +6 -0
- data/test/rails_app/app/controllers/welcome_controller.rb +5 -0
- data/test/rails_app/app/helpers/application_helper.rb +2 -0
- data/test/{app_root → rails_app}/app/models/role.rb +0 -0
- data/test/rails_app/app/models/user.rb +6 -0
- data/test/rails_app/app/presenters/forms/generic_user.rb +6 -0
- data/test/rails_app/app/views/layouts/application.html.erb +13 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/config/application.rb +45 -0
- data/test/rails_app/config/boot.rb +13 -0
- data/test/rails_app/config/database.yml +35 -0
- data/test/rails_app/config/environment.rb +6 -0
- data/test/rails_app/config/environments/development.rb +22 -0
- data/test/rails_app/config/environments/production.rb +49 -0
- data/test/rails_app/config/environments/test.rb +35 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +8 -0
- data/test/rails_app/config/initializers/inflections.rb +10 -0
- data/test/rails_app/config/initializers/mime_types.rb +5 -0
- data/test/rails_app/config/initializers/netzke.rb +7 -0
- data/test/rails_app/config/initializers/secret_token.rb +7 -0
- data/test/rails_app/config/initializers/session_store.rb +8 -0
- data/test/rails_app/config/locales/es.yml +12 -0
- data/test/rails_app/config/routes.rb +65 -0
- data/test/rails_app/db/development_structure.sql +39 -0
- data/test/{app_root/db/migrate/20081222035855_create_netzke_preferences.rb → rails_app/db/migrate/20100905214933_create_netzke_preferences.rb} +2 -4
- data/test/{app_root/db/migrate/20090423222114_create_users.rb → rails_app/db/migrate/20100914104207_create_users.rb} +4 -1
- data/test/{app_root/db/migrate/20090423214303_create_roles.rb → rails_app/db/migrate/20100914104236_create_roles.rb} +2 -0
- data/test/rails_app/db/schema.rb +38 -0
- data/test/rails_app/db/seeds.rb +20 -0
- data/test/rails_app/features/support/paths.rb +47 -0
- data/test/{app_root/config/environments/in_memory.rb → rails_app/lib/tasks/.gitkeep} +0 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/{app_root/config/environments/mysql.rb → rails_app/public/favicon.ico} +0 -0
- data/test/rails_app/public/images/header-deco.gif +0 -0
- data/test/rails_app/public/images/rails.png +0 -0
- data/test/rails_app/public/javascripts/application.js +2 -0
- data/test/rails_app/public/javascripts/controls.js +965 -0
- data/test/rails_app/public/javascripts/dragdrop.js +974 -0
- data/test/rails_app/public/javascripts/effects.js +1123 -0
- data/test/rails_app/public/javascripts/prototype.js +6001 -0
- data/test/rails_app/public/javascripts/rails.js +175 -0
- data/test/rails_app/public/robots.txt +5 -0
- data/test/{app_root/config/environments/postgresql.rb → rails_app/public/stylesheets/.gitkeep} +0 -0
- data/test/rails_app/script/rails +6 -0
- data/test/rails_app/spec/models/role_spec.rb +5 -0
- data/test/rails_app/spec/models/user_spec.rb +5 -0
- data/test/rails_app/test/performance/browsing_test.rb +9 -0
- data/test/rails_app/test/test_helper.rb +13 -0
- data/test/{app_root/config/environments/sqlite.rb → rails_app/vendor/plugins/.gitkeep} +0 -0
- data/test/unit/accordion_panel_test.rb +3 -3
- data/test/unit/active_record_basepack_test.rb +4 -4
- data/test/unit/tab_panel_test.rb +4 -4
- metadata +199 -119
- data/lib/netzke/accordion_panel.rb +0 -115
- data/lib/netzke/active_record/data_accessor.rb +0 -25
- data/lib/netzke/attributes_configurator.rb +0 -195
- data/lib/netzke/basic_app.rb +0 -368
- data/lib/netzke/border_layout_panel.rb +0 -130
- data/lib/netzke/configuration_panel.rb +0 -24
- data/lib/netzke/form_panel.rb +0 -138
- data/lib/netzke/form_panel/form_panel_api.rb +0 -81
- data/lib/netzke/form_panel/form_panel_fields.rb +0 -149
- data/lib/netzke/form_panel/form_panel_js.rb +0 -163
- data/lib/netzke/grid_panel.rb +0 -367
- data/lib/netzke/grid_panel/grid_panel_api.rb +0 -364
- data/lib/netzke/grid_panel/grid_panel_columns.rb +0 -232
- data/lib/netzke/grid_panel/grid_panel_js.rb +0 -73
- data/lib/netzke/grid_panel/javascripts/advanced_search.js +0 -65
- data/lib/netzke/grid_panel/multi_edit_form.rb +0 -14
- data/lib/netzke/grid_panel/record_form_window.rb +0 -50
- data/lib/netzke/panel.rb +0 -11
- data/lib/netzke/plugins/configuration_tool.rb +0 -121
- data/lib/netzke/property_editor.rb +0 -111
- data/lib/netzke/property_editor/helper_model.rb +0 -122
- data/lib/netzke/search_panel.rb +0 -199
- data/lib/netzke/tab_panel.rb +0 -174
- data/lib/netzke/table_editor.rb +0 -118
- data/lib/netzke/tree_panel.rb +0 -25
- data/lib/netzke/window.rb +0 -82
- data/lib/netzke/wrapper.rb +0 -42
- data/test/app_root/app/models/book.rb +0 -9
- data/test/app_root/app/models/category.rb +0 -2
- data/test/app_root/app/models/city.rb +0 -3
- data/test/app_root/app/models/continent.rb +0 -2
- data/test/app_root/app/models/country.rb +0 -3
- data/test/app_root/app/models/genre.rb +0 -3
- data/test/app_root/app/models/user.rb +0 -3
- data/test/app_root/config/boot.rb +0 -114
- data/test/app_root/config/database.yml +0 -21
- data/test/app_root/config/environment.rb +0 -14
- data/test/app_root/config/environments/sqlite3.rb +0 -0
- data/test/app_root/config/routes.rb +0 -4
- data/test/app_root/db/migrate/20081222033343_create_books.rb +0 -15
- data/test/app_root/db/migrate/20081222033440_create_genres.rb +0 -15
- data/test/app_root/db/migrate/20081223024935_create_categories.rb +0 -13
- data/test/app_root/db/migrate/20081223025635_create_countries.rb +0 -14
- data/test/app_root/db/migrate/20081223025653_create_continents.rb +0 -13
- data/test/app_root/db/migrate/20081223025732_create_cities.rb +0 -15
- data/test/app_root/db/migrate/20090102223630_create_netzke_field_lists.rb +0 -18
- data/test/app_root/script/console +0 -7
- data/test/app_root/vendor/plugins/acts_as_list/README +0 -23
- data/test/app_root/vendor/plugins/acts_as_list/init.rb +0 -3
- data/test/app_root/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +0 -256
@@ -1,130 +0,0 @@
|
|
1
|
-
module Netzke
|
2
|
-
# Represents the Ext.Panel with layout 'border'. May serve as parent class for compound widgets.
|
3
|
-
#
|
4
|
-
# == Features:
|
5
|
-
# * Responds to region resizing, storing the sizes in persistent config
|
6
|
-
#
|
7
|
-
# == Future features:
|
8
|
-
# * Stores expand/collapse state in the persistent config
|
9
|
-
#
|
10
|
-
# == Non-functional features:
|
11
|
-
# * (JavaScript) Creates convinient methods to access aggregatees inside the regions, like
|
12
|
-
# <tt>getCenterWidget()</tt>, <tt>getWestWidget()</tt>, etc
|
13
|
-
#
|
14
|
-
# == Configuration:
|
15
|
-
# <tt>:regions</tt> - a hash in form:
|
16
|
-
#
|
17
|
-
# {:center => {<netzke widget config>}, :east => {<another netzke widget config>}, ...}
|
18
|
-
#
|
19
|
-
# <tt>:regions => :center/:west/:etc => :region_config</tt> - configuration options for
|
20
|
-
# Ext.layout.BorderLayout.SplitRegion.
|
21
|
-
#
|
22
|
-
# == Example configuration:
|
23
|
-
#
|
24
|
-
# :regions => {
|
25
|
-
# :center => {:class_name => "Panel", :ext_config => {:html => "A panel"}},
|
26
|
-
# :west => {
|
27
|
-
# :class_name => "GridPanel",
|
28
|
-
# :model => "User",
|
29
|
-
# :region_config => {
|
30
|
-
# :width => 100,
|
31
|
-
# :split => true
|
32
|
-
# }
|
33
|
-
# }
|
34
|
-
# }
|
35
|
-
class BorderLayoutPanel < Base
|
36
|
-
REGIONS = %w(center west east south north).map(&:to_sym)
|
37
|
-
|
38
|
-
# JavaScript part
|
39
|
-
def self.js_extend_properties
|
40
|
-
{
|
41
|
-
:layout => 'border',
|
42
|
-
|
43
|
-
:init_component => <<-END_OF_JAVASCRIPT.l,
|
44
|
-
function(){
|
45
|
-
this.items = [];
|
46
|
-
Ext.each(['center', 'west', 'east', 'south', 'north'], function(r){
|
47
|
-
var configName = r+'Config';
|
48
|
-
if (this[configName]){
|
49
|
-
var regionConfig = this.regions[r] || {};
|
50
|
-
regionConfig.layout = 'fit';
|
51
|
-
regionConfig.region = r;
|
52
|
-
var klass = this.classifyScopedName(this[configName].scopedClassName);
|
53
|
-
regionConfig.items = [new klass(this[configName])]
|
54
|
-
this.items.push(regionConfig);
|
55
|
-
|
56
|
-
// A function to access a region widget (even if the widget gets reloaded, the function will work).
|
57
|
-
// E.g.: getEastWidget()
|
58
|
-
this['get'+r.capitalize()+'Widget'] = function(){
|
59
|
-
return this.find('region', r)[0].getWidget()
|
60
|
-
}.createDelegate(this);
|
61
|
-
};
|
62
|
-
}, this);
|
63
|
-
|
64
|
-
// Now let Ext.Panel do the rest
|
65
|
-
#{js_full_class_name}.superclass.initComponent.call(this);
|
66
|
-
|
67
|
-
// First time on "afterlayout", set resize events
|
68
|
-
if (this.persistentConfig) {this.on('afterlayout', this.setResizeEvents, this, {single: true});}
|
69
|
-
}
|
70
|
-
END_OF_JAVASCRIPT
|
71
|
-
|
72
|
-
:get_region_widget => <<-END_OF_JAVASCRIPT.l,
|
73
|
-
function(region){
|
74
|
-
return this.find('region', region)[0].getWidget();
|
75
|
-
}
|
76
|
-
END_OF_JAVASCRIPT
|
77
|
-
|
78
|
-
:set_resize_events => <<-END_OF_JAVASCRIPT.l,
|
79
|
-
function(){
|
80
|
-
this.items.each(function(item, index, length){
|
81
|
-
if (!item.oldSize) item.oldSize = item.getSize();
|
82
|
-
if (item.region == 'east' || item.region == 'west') item.on('resize', function(panel, w, h){
|
83
|
-
if (panel.oldSize.width != w) {
|
84
|
-
this.resizeRegion({region_name: panel.region, new_width:w});
|
85
|
-
panel.oldSize.width = w;
|
86
|
-
}
|
87
|
-
return true;
|
88
|
-
}, this);
|
89
|
-
else if (item.region == 'south' || item.region == 'north') item.on('resize', function(panel, w, h){
|
90
|
-
if (panel.oldSize.height != h) {
|
91
|
-
this.resizeRegion({region_name: panel.region, new_height:h});
|
92
|
-
panel.oldSize.height = h;
|
93
|
-
}
|
94
|
-
return true;
|
95
|
-
}, this);
|
96
|
-
}, this);
|
97
|
-
}
|
98
|
-
END_OF_JAVASCRIPT
|
99
|
-
}
|
100
|
-
end
|
101
|
-
|
102
|
-
def initial_aggregatees
|
103
|
-
config[:regions] || {}
|
104
|
-
end
|
105
|
-
|
106
|
-
def region_aggregatees
|
107
|
-
aggregatees.reject{ |k,v| !REGIONS.include?(k) }
|
108
|
-
end
|
109
|
-
|
110
|
-
def js_config
|
111
|
-
regions = {}
|
112
|
-
REGIONS.each do |r|
|
113
|
-
if region_aggr = aggregatees[r]
|
114
|
-
regions.merge!(r => region_aggr[:region_config] || {})
|
115
|
-
end
|
116
|
-
end
|
117
|
-
super.merge(:regions => regions)
|
118
|
-
end
|
119
|
-
|
120
|
-
# API
|
121
|
-
api :resize_region # handles regions resize
|
122
|
-
def resize_region(params)
|
123
|
-
# Write to persistent_config such way that these settings are automatically picked up by region widgets
|
124
|
-
persistent_config["regions__#{params["region_name"]}__region_config__width"] = params["new_width"].to_i if params["new_width"]
|
125
|
-
persistent_config["regions__#{params["region_name"]}__region_config__height"] = params["new_height"].to_i if params["new_height"]
|
126
|
-
{}
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|
130
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Netzke
|
2
|
-
# TabPanel-based widget that wraps-up "configuration widgets" that each widget can define
|
3
|
-
# (along) with including the Plugins::ConfigurationTool tool.
|
4
|
-
class ConfigurationPanel < TabPanel
|
5
|
-
api :commit
|
6
|
-
def commit(params)
|
7
|
-
commit_data = ActiveSupport::JSON.decode params[:commit_data]
|
8
|
-
commit_data.each_pair do |k,v|
|
9
|
-
aggregatee_instance(k).commit(v) if aggregatee_instance(k).respond_to?(:commit)
|
10
|
-
end
|
11
|
-
{:reload_parent => true, :feedback => (@flash.empty? ? nil : @flash)}
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.js_extend_properties
|
15
|
-
{
|
16
|
-
:reload_parent => <<-END_OF_JAVASCRIPT.l,
|
17
|
-
function(){
|
18
|
-
this.getParent().reload();
|
19
|
-
}
|
20
|
-
END_OF_JAVASCRIPT
|
21
|
-
}
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/netzke/form_panel.rb
DELETED
@@ -1,138 +0,0 @@
|
|
1
|
-
require "netzke/form_panel/form_panel_js"
|
2
|
-
require "netzke/form_panel/form_panel_api"
|
3
|
-
require "netzke/form_panel/form_panel_fields"
|
4
|
-
require "netzke/plugins/configuration_tool"
|
5
|
-
require "netzke/data_accessor"
|
6
|
-
|
7
|
-
module Netzke
|
8
|
-
# = FormPanel
|
9
|
-
#
|
10
|
-
# Represents Ext.form.FormPanel
|
11
|
-
#
|
12
|
-
# == Configuration
|
13
|
-
# * <tt>:model</tt> - name of the ActiveRecord model that provides data to this GridPanel.
|
14
|
-
# * <tt>:record</tt> - record to be displayd in the form. Takes precedence over <tt>:record_id</tt>
|
15
|
-
# * <tt>:record_id</tt> - id of the record to be displayd in the form. Also see <tt>:record</tt>
|
16
|
-
#
|
17
|
-
# In the <tt>:ext_config</tt> hash (see Netzke::Base) the following FormPanel specific options are available:
|
18
|
-
#
|
19
|
-
# * <tt>:mode</tt> - when set to <tt>:config</tt>, FormPanel loads in configuration mode
|
20
|
-
class FormPanel < Base
|
21
|
-
include FormPanelJs # javascript (client-side)
|
22
|
-
include FormPanelApi # API (server-side)
|
23
|
-
include FormPanelFields # fields
|
24
|
-
include Netzke::DataAccessor # some code shared between GridPanel, FormPanel, and other widgets that use database attributes
|
25
|
-
|
26
|
-
# Class-level configuration with defaults
|
27
|
-
def self.config
|
28
|
-
set_default_config({
|
29
|
-
:config_tool_available => true,
|
30
|
-
|
31
|
-
:default_config => {
|
32
|
-
:persistent_config => true,
|
33
|
-
:ext_config => {
|
34
|
-
:tools => []
|
35
|
-
},
|
36
|
-
}
|
37
|
-
})
|
38
|
-
end
|
39
|
-
|
40
|
-
def initial_config
|
41
|
-
res = super
|
42
|
-
res[:ext_config][:bbar] = default_bbar if res[:ext_config][:bbar].nil?
|
43
|
-
res
|
44
|
-
end
|
45
|
-
|
46
|
-
def default_bbar
|
47
|
-
%w{ apply }
|
48
|
-
end
|
49
|
-
|
50
|
-
# Extra javascripts
|
51
|
-
def self.include_js
|
52
|
-
[
|
53
|
-
"#{File.dirname(__FILE__)}/form_panel/javascripts/xcheckbox.js",
|
54
|
-
Netzke::Base.config[:ext_location] + "/examples/ux/fileuploadfield/FileUploadField.js",
|
55
|
-
"#{File.dirname(__FILE__)}/form_panel/javascripts/netzkefileupload.js"
|
56
|
-
]
|
57
|
-
end
|
58
|
-
|
59
|
-
api :netzke_submit, :netzke_load, :get_combobox_options
|
60
|
-
|
61
|
-
attr_accessor :record
|
62
|
-
|
63
|
-
def initialize(*args)
|
64
|
-
super
|
65
|
-
apply_helpers
|
66
|
-
end
|
67
|
-
|
68
|
-
# Model class
|
69
|
-
# (We can't memoize this method because at some point we extend it, e.g. in Netzke::DataAccessor)
|
70
|
-
def data_class
|
71
|
-
@data_class ||= begin
|
72
|
-
klass = "Netzke::ModelExtensions::#{config[:model]}For#{short_widget_class_name}".constantize rescue nil
|
73
|
-
klass || original_data_class
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# Model class before model extensions are taken into account
|
78
|
-
def original_data_class
|
79
|
-
@original_data_class ||= begin
|
80
|
-
::ActiveSupport::Deprecation.warn("data_class_name option is deprecated. Use model instead", caller) if config[:data_class_name]
|
81
|
-
model_name = config[:model] || config[:data_class_name]
|
82
|
-
model_name && model_name.constantize
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def record
|
87
|
-
@record ||= config[:record] || config[:record_id] && data_class && data_class.find(:first, :conditions => {data_class.primary_key => config[:record_id]})
|
88
|
-
end
|
89
|
-
|
90
|
-
def configuration_widgets
|
91
|
-
res = []
|
92
|
-
|
93
|
-
res << {
|
94
|
-
:name => 'fields',
|
95
|
-
:class_name => "FieldsConfigurator",
|
96
|
-
:active => true,
|
97
|
-
:owner => self,
|
98
|
-
:persistent_config => true
|
99
|
-
}
|
100
|
-
|
101
|
-
res << {
|
102
|
-
:name => 'general',
|
103
|
-
:class_name => "PropertyEditor",
|
104
|
-
:widget => self,
|
105
|
-
:ext_config => {:title => false}
|
106
|
-
}
|
107
|
-
|
108
|
-
res
|
109
|
-
end
|
110
|
-
|
111
|
-
def actions
|
112
|
-
actions = {
|
113
|
-
:apply => {:text => 'Apply'}
|
114
|
-
}
|
115
|
-
|
116
|
-
if Netzke::Base.config[:with_icons]
|
117
|
-
icons_uri = Netzke::Base.config[:icons_uri]
|
118
|
-
actions.deep_merge!(
|
119
|
-
:apply => {:icon => icons_uri + "tick.png"}
|
120
|
-
)
|
121
|
-
end
|
122
|
-
|
123
|
-
actions
|
124
|
-
end
|
125
|
-
|
126
|
-
def self.property_fields
|
127
|
-
res = [
|
128
|
-
{:name => "ext_config__title", :attr_type => :string},
|
129
|
-
{:name => "ext_config__header", :attr_type => :boolean, :default => true},
|
130
|
-
# {:name => "ext_config__bbar", :attr_type => :json}
|
131
|
-
]
|
132
|
-
|
133
|
-
res
|
134
|
-
end
|
135
|
-
|
136
|
-
include Plugins::ConfigurationTool if config[:config_tool_available] # it will load ConfigurationPanel into a modal window
|
137
|
-
end
|
138
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
module Netzke
|
2
|
-
class FormPanel < Base
|
3
|
-
module FormPanelApi
|
4
|
-
# API handling form submission
|
5
|
-
def netzke_submit(params)
|
6
|
-
success = create_or_update_record(params)
|
7
|
-
|
8
|
-
if success
|
9
|
-
{:set_form_values => array_of_values, :set_result => "ok"}
|
10
|
-
else
|
11
|
-
# flash eventual errors
|
12
|
-
@record.errors.each_full do |msg|
|
13
|
-
flash :error => msg
|
14
|
-
end
|
15
|
-
{:feedback => @flash}
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# Creates/updates a record from hash
|
20
|
-
def create_or_update_record(params)
|
21
|
-
hsh = ActiveSupport::JSON.decode(params[:data])
|
22
|
-
hsh.merge!(config[:strong_default_attrs]) if config[:strong_default_attrs]
|
23
|
-
@record ||= data_class.find(:first, :conditions => {data_class.primary_key => hsh.delete(data_class.primary_key)}) # only pick up the record specified in the params if it was not provided in the configuration
|
24
|
-
success = true
|
25
|
-
|
26
|
-
@record = data_class.new if @record.nil?
|
27
|
-
|
28
|
-
hsh.each_pair do |k,v|
|
29
|
-
begin
|
30
|
-
@record.send("#{k}=",v)
|
31
|
-
rescue StandardError => exc
|
32
|
-
flash :error => exc.message
|
33
|
-
success = false
|
34
|
-
break
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# did we have complete success?
|
39
|
-
success && @record.save
|
40
|
-
end
|
41
|
-
|
42
|
-
# API handling form load
|
43
|
-
# def load(params)
|
44
|
-
# klass = config[:model].constantize
|
45
|
-
# case params[:neighbour]
|
46
|
-
# when "previous" then @record = klass.previous(params[:id])
|
47
|
-
# when "next" then @record = klass.next(params[:id])
|
48
|
-
# else @record = klass.find(params[:id])
|
49
|
-
# end
|
50
|
-
# {:data => [array_of_values]}
|
51
|
-
# end
|
52
|
-
|
53
|
-
def netzke_load(params)
|
54
|
-
@record = data_class && data_class.find_by_id(params[:id])
|
55
|
-
{:set_form_values => array_of_values}
|
56
|
-
end
|
57
|
-
|
58
|
-
# API that returns options for a combobox
|
59
|
-
def get_combobox_options(params)
|
60
|
-
column = params[:column]
|
61
|
-
query = params[:query]
|
62
|
-
|
63
|
-
column = fields.detect{ |c| c[:name] == params[:column] }.try(:to_options!)
|
64
|
-
scopes = column.to_options[:scopes]
|
65
|
-
query = params[:query]
|
66
|
-
|
67
|
-
{:data => combobox_options_for_column(column, :query => query, :scopes => scopes)}
|
68
|
-
end
|
69
|
-
|
70
|
-
def configuration_panel__fields__get_combobox_options(params)
|
71
|
-
query = params[:query]
|
72
|
-
{:data => (default_columns.map{ |c| c[:name].to_s }).grep(/^#{query}/).map{ |n| [n] }}.to_nifty_json
|
73
|
-
end
|
74
|
-
|
75
|
-
# Returns array of form values according to the configured columns
|
76
|
-
def array_of_values
|
77
|
-
@record && @record.to_array(fields, self)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,149 +0,0 @@
|
|
1
|
-
module Netzke
|
2
|
-
class FormPanel < Base
|
3
|
-
module FormPanelFields
|
4
|
-
module ClassMethods
|
5
|
-
# Columns to be displayed by the FieldConfigurator, "meta-columns". Each corresponds to a configuration
|
6
|
-
# option for each field in the form.
|
7
|
-
def meta_columns
|
8
|
-
[
|
9
|
-
{:name => "included", :attr_type => :boolean, :width => 40, :header => "Incl", :default_value => true},
|
10
|
-
{:name => "name", :attr_type => :string, :editor => :combobox, :width => 200},
|
11
|
-
{:name => "label", :attr_type => :string, :header => "Label"},
|
12
|
-
{:name => "default_value", :attr_type => :string}
|
13
|
-
]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def fields
|
18
|
-
@fields ||= begin
|
19
|
-
flds = load_fields
|
20
|
-
reverse_merge_equally_named_fields(flds, initial_fields) if flds
|
21
|
-
flds ||= initial_fields
|
22
|
-
|
23
|
-
flds.map! do |c|
|
24
|
-
value = record.send(c[:name])
|
25
|
-
value.nil? ? c : c.merge(:value => value)
|
26
|
-
end if record
|
27
|
-
|
28
|
-
flds
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def default_fields
|
33
|
-
@default_fields ||= load_model_level_attrs || (data_class && data_class.netzke_attributes) || []
|
34
|
-
end
|
35
|
-
|
36
|
-
def initial_fields(only_included = true)
|
37
|
-
::ActiveSupport::Deprecation.warn("The :columns option for FormPanel is deprecated. Use :fields instead", caller) if config[:columns]
|
38
|
-
|
39
|
-
# Normalize here, as from the config we can get symbols (names) instead of hashes
|
40
|
-
fields_from_config = (config[:columns] || config[:fields]) && normalize_attr_config(config[:columns] || config[:fields])
|
41
|
-
|
42
|
-
if fields_from_config
|
43
|
-
# reverse-merge each column hash from config with each column hash from exposed_attributes (fields from config have higher priority)
|
44
|
-
for c in fields_from_config
|
45
|
-
corresponding_exposed_column = default_fields.find{ |k| k[:name] == c[:name] }
|
46
|
-
c.reverse_merge!(corresponding_exposed_column) if corresponding_exposed_column
|
47
|
-
end
|
48
|
-
fields_for_create = fields_from_config
|
49
|
-
elsif default_fields
|
50
|
-
# we didn't have fields configured in widget's config, so, use the fields from the data class
|
51
|
-
fields_for_create = default_fields
|
52
|
-
else
|
53
|
-
raise ArgumentError, "No fields specified for widget '#{global_id}'"
|
54
|
-
end
|
55
|
-
|
56
|
-
fields_for_create.reject!{ |c| c[:included] == false }
|
57
|
-
|
58
|
-
fields_for_create.map! do |c|
|
59
|
-
if data_class
|
60
|
-
|
61
|
-
detect_association_with_method(c)
|
62
|
-
|
63
|
-
# detect association column (e.g. :category_id)
|
64
|
-
if assoc = data_class.reflect_on_all_associations.detect{|a| a.primary_key_name == c[:name]}
|
65
|
-
c[:xtype] ||= xtype_for_association
|
66
|
-
assoc_method = %w{name title label id}.detect{|m| (assoc.klass.instance_methods + assoc.klass.column_names).include?(m) } || assoc.klass.primary_key
|
67
|
-
c[:name] = "#{assoc.name}__#{assoc_method}"
|
68
|
-
end
|
69
|
-
|
70
|
-
c[:hidden] = true if c[:name] == data_class.primary_key && c[:hidden].nil? # hide ID column by default
|
71
|
-
end
|
72
|
-
|
73
|
-
set_default_field_label(c)
|
74
|
-
|
75
|
-
c[:xtype] ||= xtype_for_attr_type(c[:attr_type]) # unless xtype_map[type].nil?
|
76
|
-
c
|
77
|
-
end
|
78
|
-
|
79
|
-
fields_for_create
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
private
|
84
|
-
# Stores modified fields in persistent storage (not used in forms, as we can't modify them on the fly, only via FieldsConfigurator)
|
85
|
-
# def save_fields!
|
86
|
-
# NetzkeFieldList.update_list_for_current_authority(global_id, fields, data_class.name)
|
87
|
-
# end
|
88
|
-
|
89
|
-
def load_fields
|
90
|
-
NetzkeFieldList.read_list(global_id) if persistent_config_enabled?
|
91
|
-
end
|
92
|
-
|
93
|
-
def load_model_level_attrs
|
94
|
-
NetzkeModelAttrList.read_list(data_class.name) if persistent_config_enabled? && data_class
|
95
|
-
end
|
96
|
-
|
97
|
-
def set_default_field_label(c)
|
98
|
-
c[:label] ||= c[:name].humanize
|
99
|
-
end
|
100
|
-
|
101
|
-
def attr_type_to_xtype_map
|
102
|
-
{
|
103
|
-
:integer => :numberfield,
|
104
|
-
:boolean => :xcheckbox,
|
105
|
-
:date => :datefield,
|
106
|
-
:datetime => :xdatetime,
|
107
|
-
:text => :textarea,
|
108
|
-
:json => :jsonfield
|
109
|
-
# :string => :textfield
|
110
|
-
}
|
111
|
-
end
|
112
|
-
|
113
|
-
def xtype_for_attr_type(type)
|
114
|
-
attr_type_to_xtype_map[type]
|
115
|
-
end
|
116
|
-
|
117
|
-
def xtype_for_association
|
118
|
-
:combobox
|
119
|
-
end
|
120
|
-
|
121
|
-
def detect_association_with_method(c)
|
122
|
-
if c[:name].to_s.index('__')
|
123
|
-
assoc_name, method = c[:name].split('__').map(&:to_sym)
|
124
|
-
if assoc = data_class.reflect_on_association(assoc_name)
|
125
|
-
assoc_column = assoc.klass.columns_hash[method.to_s]
|
126
|
-
assoc_method_type = assoc_column.try(:type)
|
127
|
-
if assoc_method_type
|
128
|
-
c[:xtype] ||= assoc_method_type == :boolean ? xtype_for_attr_type(assoc_method_type) : :combobox
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
# Receives 2 arrays of columns. Merges the missing config from the +source+ into +dest+, matching columns by name
|
135
|
-
def reverse_merge_equally_named_fields(dest, source)
|
136
|
-
dest.each{ |dc| dc.reverse_merge!(source.detect{ |sc| sc[:name] == dc[:name] } || {}) }
|
137
|
-
end
|
138
|
-
|
139
|
-
|
140
|
-
def self.included(receiver)
|
141
|
-
receiver.extend ClassMethods
|
142
|
-
|
143
|
-
receiver.class_eval do
|
144
|
-
alias :initial_columns :initial_fields
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|