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
File without changes
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Netzke
|
2
|
+
module Basepack
|
3
|
+
# Panel with border layout
|
4
|
+
# == Example configuration:
|
5
|
+
#
|
6
|
+
# :items => [
|
7
|
+
# {:title => "Item One", :class_name => "Basepack::Panel", :region => :center},
|
8
|
+
# {:title => "Item Two", :class_name => "Basepack::Panel", :region => :west, :width => 300, :split => true}
|
9
|
+
# ]
|
10
|
+
class BorderLayoutPanel < Netzke::Base
|
11
|
+
|
12
|
+
def self.js_properties
|
13
|
+
{
|
14
|
+
:layout => 'border',
|
15
|
+
:init_component => <<-END_OF_JAVASCRIPT.l,
|
16
|
+
function(){
|
17
|
+
Ext.each(['center', 'west', 'east', 'south', 'north'], function(r){
|
18
|
+
// A function to access a region component (even if the component gets reloaded, the function will work).
|
19
|
+
// E.g.: getEastComponent()
|
20
|
+
var methodName = 'get'+r.capitalize()+'Component';
|
21
|
+
this[methodName] = function(){
|
22
|
+
Netzke.deprecationWarning("Instead of '" + methodName + "' use getChildComponent('<name of your component>').");
|
23
|
+
return this.find('region', r)[0];
|
24
|
+
}.createDelegate(this);
|
25
|
+
}, this);
|
26
|
+
|
27
|
+
// Now let Ext.Panel do the rest
|
28
|
+
#{js_full_class_name}.superclass.initComponent.call(this);
|
29
|
+
|
30
|
+
// First time on "afterlayout", set resize events
|
31
|
+
if (this.persistentConfig) {this.on('afterlayout', this.setResizeEvents, this, {single: true});}
|
32
|
+
}
|
33
|
+
END_OF_JAVASCRIPT
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require "netzke/basepack/form_panel/fields"
|
2
|
+
require "netzke/basepack/form_panel/services"
|
3
|
+
# require "netzke/plugins/configuration_tool"
|
4
|
+
# require "netzke/data_accessor"
|
5
|
+
|
6
|
+
module Netzke
|
7
|
+
module Basepack
|
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
|
+
class FormPanel < Netzke::Base
|
17
|
+
# Class-level configuration
|
18
|
+
class_attribute :config_tool_available
|
19
|
+
self.config_tool_available = true
|
20
|
+
|
21
|
+
class_attribute :default_config
|
22
|
+
self.default_config = {} # To be filled in
|
23
|
+
|
24
|
+
include self::Services
|
25
|
+
include self::Fields
|
26
|
+
|
27
|
+
include Netzke::DataAccessor
|
28
|
+
|
29
|
+
js_base_class "Netzke.pre.FormPanel"
|
30
|
+
|
31
|
+
js_property :bbar, [:apply.action]
|
32
|
+
|
33
|
+
# def initial_config
|
34
|
+
# res = super
|
35
|
+
# res[:bbar] = default_bbar if res[:bbar].nil?
|
36
|
+
# res
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# def default_bbar
|
40
|
+
# [:apply.action]
|
41
|
+
# end
|
42
|
+
|
43
|
+
# Extra javascripts
|
44
|
+
js_include "#{File.dirname(__FILE__)}/form_panel/javascripts/pre.js",
|
45
|
+
"#{File.dirname(__FILE__)}/form_panel/javascripts/xcheckbox.js"
|
46
|
+
# Netzke::Base.config[:ext_location] + "/examples/ux/fileuploadfield/FileUploadField.js",
|
47
|
+
# "#{File.dirname(__FILE__)}/form_panel/javascripts/netzkefileupload.js"
|
48
|
+
|
49
|
+
def js_config
|
50
|
+
super.merge(
|
51
|
+
# :fields => fields,
|
52
|
+
:pri => data_class && data_class.primary_key
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
def record
|
57
|
+
@record ||= config[:record] || config[:record_id] && data_class && data_class.where(data_class.primary_key => config[:record_id]).first
|
58
|
+
end
|
59
|
+
|
60
|
+
def configuration_components
|
61
|
+
res = []
|
62
|
+
|
63
|
+
res << {
|
64
|
+
:name => 'fields',
|
65
|
+
:class_name => "FieldsConfigurator",
|
66
|
+
:active => true,
|
67
|
+
:owner => self,
|
68
|
+
:persistent_config => true
|
69
|
+
}
|
70
|
+
|
71
|
+
res << {
|
72
|
+
:name => 'general',
|
73
|
+
:class_name => "PropertyEditor",
|
74
|
+
:component => self,
|
75
|
+
:title => false
|
76
|
+
}
|
77
|
+
|
78
|
+
res
|
79
|
+
end
|
80
|
+
|
81
|
+
action :apply, :text => 'Apply', :icon => :tick
|
82
|
+
|
83
|
+
def self.property_fields
|
84
|
+
res = [
|
85
|
+
# {:name => "ext_config__title", :attr_type => :string},
|
86
|
+
# {:name => "ext_config__header", :attr_type => :boolean, :default => true},
|
87
|
+
# {:name => "ext_config__bbar", :attr_type => :json}
|
88
|
+
]
|
89
|
+
|
90
|
+
res
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def self.server_side_config_options
|
96
|
+
super + [:record]
|
97
|
+
end
|
98
|
+
|
99
|
+
# include ::Netzke::Plugins::ConfigurationTool if config_tool_available # it will load ConfigurationPanel into a modal window
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,206 @@
|
|
1
|
+
module Netzke
|
2
|
+
module Basepack
|
3
|
+
class FormPanel < Netzke::Base
|
4
|
+
# Because FormPanel allows for arbitrary layout of fields, we need to have all fields configured in one place (the +fields+ method), and then have references to those fields from +items+.
|
5
|
+
module Fields
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
# Items with normalized fields (i.e. containing all the necessary attributes needed by Ext.form.FormPanel to render
|
9
|
+
# a field)
|
10
|
+
def items
|
11
|
+
@form_panel_items ||= begin
|
12
|
+
res = normalize_fields(super || data_class && data_class.netzke_attributes || []) # take netzke_attributes as default items
|
13
|
+
|
14
|
+
# if primary key isn't there, insert it as first
|
15
|
+
if data_class && res.first && res.first[:name] != [data_class.primary_key]
|
16
|
+
primary_key_item = normalize_field(data_class.primary_key.to_sym)
|
17
|
+
@fields_from_config[data_class.primary_key.to_sym] = primary_key_item
|
18
|
+
res.insert(0, primary_key_item)
|
19
|
+
end
|
20
|
+
|
21
|
+
res
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Hash of fully configured fields, that are referenced in the items. E.g.:
|
26
|
+
# {
|
27
|
+
# :role__name => {:xtype => 'combobox', :disabled => true, :value => "admin"},
|
28
|
+
# :created_at => {:xtype => 'datetime', :disabled => true, :value => "2010-10-10 10:10"}
|
29
|
+
# }
|
30
|
+
def fields
|
31
|
+
@fields ||= begin
|
32
|
+
if static_layout?
|
33
|
+
# extract incomplete field configs from +config+
|
34
|
+
flds = fields_from_config
|
35
|
+
# and merged them with fields from the model
|
36
|
+
deep_merge_existing_fields(flds, fields_from_model)
|
37
|
+
else
|
38
|
+
# extract flds configs from the model
|
39
|
+
flds = fields_from_model
|
40
|
+
end
|
41
|
+
flds
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# The array of fields as specified on the model level (using +netzke_attribute+ and alike)
|
46
|
+
def fields_array_from_model
|
47
|
+
data_class && data_class.netzke_attributes
|
48
|
+
end
|
49
|
+
|
50
|
+
# Hash of fields as specified on the model level
|
51
|
+
def fields_from_model
|
52
|
+
@fields_from_model ||= fields_array_from_model && fields_array_from_model.inject({}){ |hsh, f| hsh.merge(f[:name].to_sym => f) }
|
53
|
+
end
|
54
|
+
|
55
|
+
# Hash of normalized field configs extracted from :items, e.g.:
|
56
|
+
#
|
57
|
+
# {:role__name => {:xtype => "combobox"}, :password => {:xtype => "passwordfield"}}
|
58
|
+
def fields_from_config
|
59
|
+
items if @fields_from_config.nil? # by calling +items+ we initiate building of @fields_from_config
|
60
|
+
@fields_from_config ||= {}
|
61
|
+
end
|
62
|
+
|
63
|
+
module ClassMethods
|
64
|
+
# Columns to be displayed by the FieldConfigurator, "meta-columns". Each corresponds to a configuration
|
65
|
+
# option for each field in the form.
|
66
|
+
def meta_columns
|
67
|
+
[
|
68
|
+
{:name => "included", :attr_type => :boolean, :width => 40, :header => "Incl", :default_value => true},
|
69
|
+
{:name => "name", :attr_type => :string, :editor => :combobox, :width => 200},
|
70
|
+
{:name => "label", :attr_type => :string, :header => "Label"},
|
71
|
+
{:name => "default_value", :attr_type => :string}
|
72
|
+
]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
def load_persistent_fields
|
78
|
+
# NetzkeFieldList.read_list(global_id) if persistent_config_enabled?
|
79
|
+
end
|
80
|
+
|
81
|
+
def load_model_level_attrs
|
82
|
+
# NetzkeModelAttrList.read_list(data_class.name) if persistent_config_enabled? && data_class
|
83
|
+
end
|
84
|
+
|
85
|
+
# This is where we expand our basic field config with all the default and eventual value
|
86
|
+
def normalize_field(field)
|
87
|
+
# field can only be a string, a symbol, or a hash
|
88
|
+
if field.is_a?(Hash)
|
89
|
+
field = field.dup # we don't want to modify original hash
|
90
|
+
field[:name] = field[:name].to_s if field[:name] # all names should be strings
|
91
|
+
else
|
92
|
+
field = {:name => field.to_s}
|
93
|
+
end
|
94
|
+
|
95
|
+
field.merge!(fields_from_model[field[:name].to_sym]) unless fields_from_model[field[:name].to_sym].nil?
|
96
|
+
|
97
|
+
detect_association_with_method(field) # xtype for an association field
|
98
|
+
|
99
|
+
set_default_field_label(field)
|
100
|
+
|
101
|
+
set_default_field_xtype(field) if field[:xtype].nil?
|
102
|
+
|
103
|
+
set_default_field_value(field) if self.record
|
104
|
+
|
105
|
+
# provide our special combobox with our id
|
106
|
+
field[:parent_id] = self.global_id if field[:xtype] == :combobox
|
107
|
+
|
108
|
+
field[:hidden] = field[:hide_label] = true if field[:hidden].nil? && primary_key_attr?(field)
|
109
|
+
|
110
|
+
field[:checked] = field[:value] if field[:attr_type] == "boolean"
|
111
|
+
|
112
|
+
field
|
113
|
+
end
|
114
|
+
|
115
|
+
# Sets the proper xtype of an asociation field
|
116
|
+
def detect_association_with_method(c)
|
117
|
+
if c[:name].to_s.index('__')
|
118
|
+
assoc_name, method = c[:name].split('__').map(&:to_sym)
|
119
|
+
if assoc = data_class.reflect_on_association(assoc_name)
|
120
|
+
assoc_column = assoc.klass.columns_hash[method.to_s]
|
121
|
+
assoc_method_type = assoc_column.try(:type)
|
122
|
+
if assoc_method_type
|
123
|
+
c[:xtype] ||= assoc_method_type == :boolean ? xtype_for_attr_type(assoc_method_type) : xtype_for_association
|
124
|
+
end
|
125
|
+
end
|
126
|
+
else
|
127
|
+
# are we reflecting some association's foreign key (e.g. :category_id)?
|
128
|
+
if assoc = data_class.reflect_on_all_associations.detect{|a| a.primary_key_name == c[:name]}
|
129
|
+
c[:xtype] ||= xtype_for_association
|
130
|
+
assoc_method = (%w{name title label} << assoc.primary_key_name).detect{|m| (assoc.klass.instance_methods + assoc.klass.column_names).include?(m) } || assoc.klass.primary_key
|
131
|
+
c[:name] = "#{assoc.name}__#{assoc_method}"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# RECURSIVELY extracts fields configuration from :items
|
137
|
+
def normalize_fields(items)
|
138
|
+
@fields_from_config ||= {}
|
139
|
+
items.map do |item|
|
140
|
+
# at this moment, item is a hash or a symbol
|
141
|
+
if is_field_config?(item)
|
142
|
+
item = normalize_field(item)
|
143
|
+
@fields_from_config[item[:name].to_sym] = item
|
144
|
+
item #.reject{ |k,v| k == :name } # do we really need to remove the :name key?
|
145
|
+
elsif item.is_a?(Hash)
|
146
|
+
item = item.dup # we don't want to modify original hash
|
147
|
+
item[:items].is_a?(Array) ? item.merge(:items => normalize_fields(item[:items])) : item
|
148
|
+
else
|
149
|
+
item
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def is_field_config?(item)
|
155
|
+
item.is_a?(String) || item.is_a?(Symbol) || item[:name] # && !is_component_config?(item)
|
156
|
+
end
|
157
|
+
|
158
|
+
def set_default_field_label(c)
|
159
|
+
c[:field_label] ||= c[:name].humanize.sub(/\s+/, " ") # multiple spaces get replaced with one
|
160
|
+
end
|
161
|
+
|
162
|
+
def set_default_field_value(field)
|
163
|
+
value = record.value_for_attribute(field)
|
164
|
+
field[:value] ||= value unless value.nil?
|
165
|
+
end
|
166
|
+
|
167
|
+
# Deeply merges only those key/values at the top level that are already there
|
168
|
+
def deep_merge_existing_fields(dest, src)
|
169
|
+
dest.each_pair do |k,v|
|
170
|
+
v.deep_merge!(src[k] || {})
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def set_default_field_xtype(field)
|
175
|
+
field[:xtype] = xtype_for_attr_type(field[:attr_type]) unless xtype_for_attr_type(field[:attr_type]).nil?
|
176
|
+
end
|
177
|
+
|
178
|
+
def attr_type_to_xtype_map
|
179
|
+
{
|
180
|
+
:integer => :numberfield,
|
181
|
+
:boolean => :xcheckbox,
|
182
|
+
:date => :datefield,
|
183
|
+
:datetime => :xdatetime,
|
184
|
+
:text => :textarea,
|
185
|
+
:json => :jsonfield,
|
186
|
+
:string => :textfield
|
187
|
+
}
|
188
|
+
end
|
189
|
+
|
190
|
+
def xtype_for_attr_type(type)
|
191
|
+
attr_type_to_xtype_map[type]
|
192
|
+
end
|
193
|
+
|
194
|
+
def xtype_for_association
|
195
|
+
:combobox
|
196
|
+
end
|
197
|
+
|
198
|
+
# Are we provided with a static field layout?
|
199
|
+
def static_layout?
|
200
|
+
!!config[:items]
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
data/{lib/netzke → app/components/netzke/basepack}/form_panel/javascripts/netzkefileupload.js
RENAMED
File without changes
|
@@ -0,0 +1,76 @@
|
|
1
|
+
/*
|
2
|
+
Static part of FormPanel's JavaScript class.
|
3
|
+
*/
|
4
|
+
Netzke.pre.FormPanel = Ext.extend(Ext.form.FormPanel, {
|
5
|
+
bodyStyle : 'padding:5px 5px 0',
|
6
|
+
autoScroll : true,
|
7
|
+
labelWidth : 150,
|
8
|
+
|
9
|
+
defaults : {
|
10
|
+
anchor : '-20', // to leave some space for the scrollbar
|
11
|
+
listeners : {
|
12
|
+
// On "return" key, submit the form
|
13
|
+
specialkey : {
|
14
|
+
fn : function(field, event){
|
15
|
+
if (event.getKey() == 13) this.ownerCt.onApply();
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
19
|
+
},
|
20
|
+
|
21
|
+
initComponent : function(){
|
22
|
+
this.recordFields = []; // Record
|
23
|
+
this.recordIndex = 0;
|
24
|
+
|
25
|
+
var Record = Ext.data.Record.create(this.recordFields);
|
26
|
+
this.reader = new Ext.data.RecordArrayReader({root:"data"}, Record);
|
27
|
+
|
28
|
+
// Now let Ext.form.FormPanel do the rest
|
29
|
+
Netzke.pre.FormPanel.superclass.initComponent.call(this);
|
30
|
+
|
31
|
+
// Apply event
|
32
|
+
this.addEvents('apply');
|
33
|
+
},
|
34
|
+
|
35
|
+
onApply : function() {
|
36
|
+
if (this.fireEvent('apply', this)) {
|
37
|
+
var values = this.getForm().getValues();
|
38
|
+
|
39
|
+
// do not send values from disabled fields and empty values
|
40
|
+
for (var fieldName in values) {
|
41
|
+
var field = this.getForm().findField(fieldName);
|
42
|
+
if (!field || field.disabled) delete values[fieldName];
|
43
|
+
}
|
44
|
+
|
45
|
+
if (this.fileUpload) {
|
46
|
+
// Not a Netzke's standard endpoint call, because the form is multipart
|
47
|
+
this.getForm().submit({
|
48
|
+
url: this.endpointUrl("netzke_submit"),
|
49
|
+
params: {
|
50
|
+
data: Ext.encode(values)
|
51
|
+
},
|
52
|
+
failure: function(form, action){
|
53
|
+
// It will always be failure, as we don't play along with the Ext success indication (not returning {success: true})
|
54
|
+
this.bulkExecute(Ext.decode(action.response.responseText));
|
55
|
+
this.fireEvent('submitsuccess');
|
56
|
+
},
|
57
|
+
scope: this
|
58
|
+
});
|
59
|
+
} else {
|
60
|
+
// Submit the data and process the result
|
61
|
+
this.netzkeSubmit(Ext.apply((this.baseParams || {}), {data:Ext.encode(values)}), function(result){
|
62
|
+
if (result === "ok") {this.fireEvent("submitsuccess")};
|
63
|
+
}, this);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
},
|
67
|
+
|
68
|
+
setFormValues : function(values){
|
69
|
+
var normValues = {};
|
70
|
+
for (var key in values) {
|
71
|
+
normValues[key.underscore()] = values[key];
|
72
|
+
}
|
73
|
+
this.getForm().setValues(normValues);
|
74
|
+
}
|
75
|
+
|
76
|
+
});
|
File without changes
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module Netzke
|
2
|
+
module Basepack
|
3
|
+
class FormPanel < Netzke::Base
|
4
|
+
module Services
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
|
9
|
+
#
|
10
|
+
# Endpoints
|
11
|
+
#
|
12
|
+
endpoint :netzke_submit do |params|
|
13
|
+
data = ActiveSupport::JSON.decode(params[:data])
|
14
|
+
success = create_or_update_record(data)
|
15
|
+
|
16
|
+
if success
|
17
|
+
{:set_form_values => values, :set_result => "ok"}
|
18
|
+
else
|
19
|
+
# flash eventual errors
|
20
|
+
@record.errors.to_a.each do |msg|
|
21
|
+
flash :error => msg
|
22
|
+
end
|
23
|
+
{:feedback => @flash}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
endpoint :netzke_load do |params|
|
28
|
+
@record = data_class && data_class.find_by_id(params[:id])
|
29
|
+
{:set_form_values => @record.to_hash(fields)}
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns options for a combobox
|
33
|
+
endpoint :get_combobox_options do |params|
|
34
|
+
query = params[:query]
|
35
|
+
|
36
|
+
field = fields[params[:column].to_sym]
|
37
|
+
scope = field.to_options[:scope]
|
38
|
+
query = params[:query]
|
39
|
+
|
40
|
+
{:data => combobox_options_for_column(field, :query => query, :scope => scope, :record_id => params[:id])}
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
# Overriding configuration_panel's get_combobox_options endpoint call
|
46
|
+
def configuration_panel__fields__get_combobox_options(params)
|
47
|
+
query = params[:query]
|
48
|
+
{:data => (default_columns.map{ |c| c[:name].to_s }).grep(/^#{query}/).map{ |n| [n] }}.to_nifty_json
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns array of form values according to the configured columns
|
52
|
+
# def array_of_values
|
53
|
+
# @record && @record.to_array(fields)
|
54
|
+
# end
|
55
|
+
|
56
|
+
def values
|
57
|
+
record && record.to_hash(fields)
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
# Creates/updates a record from hash
|
63
|
+
def create_or_update_record(hsh)
|
64
|
+
|
65
|
+
hsh.merge!(config[:strong_default_attrs]) if config[:strong_default_attrs]
|
66
|
+
@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
|
67
|
+
success = true
|
68
|
+
|
69
|
+
@record = data_class.new if @record.nil?
|
70
|
+
|
71
|
+
hsh.each_pair do |k,v|
|
72
|
+
begin
|
73
|
+
@record.send("#{k}=",v)
|
74
|
+
rescue StandardError => exc
|
75
|
+
flash :error => exc.message
|
76
|
+
success = false
|
77
|
+
break
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# did we have complete success?
|
82
|
+
success && @record.save
|
83
|
+
end
|
84
|
+
|
85
|
+
# API handling form load
|
86
|
+
# def load(params)
|
87
|
+
# klass = config[:model].constantize
|
88
|
+
# case params[:neighbour]
|
89
|
+
# when "previous" then @record = klass.previous(params[:id])
|
90
|
+
# when "next" then @record = klass.next(params[:id])
|
91
|
+
# else @record = klass.find(params[:id])
|
92
|
+
# end
|
93
|
+
# {:data => [array_of_values]}
|
94
|
+
# end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|