netzke-basepack 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +27 -2
- data/TODO.rdoc +1 -5
- data/app/models/netzke_persistent_array_auto_model.rb +0 -1
- data/features/components_in_view.feature +11 -0
- data/features/form_panel.feature +49 -0
- data/features/grid_panel.feature +32 -1
- data/features/i18n.feature +18 -0
- data/features/nested_attributes.feature +23 -0
- data/features/search_in_grid.feature +9 -9
- data/features/simple_app.feature +10 -0
- data/features/step_definitions/grid_panel_steps.rb +23 -0
- data/features/support/paths.rb +6 -0
- data/features/support/pickle.rb +0 -1
- data/features/virtual_attributes.feature +20 -0
- data/javascripts/basepack.js +166 -243
- data/lib/netzke-basepack.rb +3 -3
- data/lib/netzke/active_record.rb +6 -7
- data/lib/netzke/active_record/attributes.rb +214 -143
- data/lib/netzke/active_record/combobox_options.rb +12 -10
- data/lib/netzke/basepack.rb +6 -3
- data/lib/netzke/basepack/accordion_panel.rb +4 -2
- data/lib/netzke/basepack/auth_app.rb +152 -0
- data/lib/netzke/basepack/basic_app.rb +2 -262
- data/lib/netzke/basepack/form_panel.rb +35 -27
- data/lib/netzke/basepack/form_panel/fields.rb +35 -17
- data/lib/netzke/basepack/form_panel/javascripts/comma_list_cbg.js +59 -0
- data/lib/netzke/basepack/form_panel/javascripts/display_mode.js +62 -0
- data/lib/netzke/basepack/form_panel/javascripts/main.js +138 -0
- data/lib/netzke/basepack/form_panel/javascripts/n_radio_group.js +25 -0
- data/lib/netzke/basepack/form_panel/services.rb +12 -9
- data/lib/netzke/basepack/grid_panel.rb +87 -53
- data/lib/netzke/basepack/grid_panel/columns.rb +60 -15
- data/lib/netzke/basepack/grid_panel/javascripts/advanced_search.js +2 -64
- data/lib/netzke/basepack/grid_panel/javascripts/edit_in_form.js +2 -2
- data/lib/netzke/basepack/grid_panel/javascripts/{pre.js → main.js} +35 -17
- data/lib/netzke/basepack/grid_panel/javascripts/misc.js +4 -0
- data/lib/netzke/basepack/grid_panel/services.rb +17 -14
- data/lib/netzke/basepack/paging_form_panel.rb +92 -0
- data/lib/netzke/basepack/simple_app.rb +71 -0
- data/lib/netzke/basepack/simple_app/javascripts/main.js +53 -0
- data/lib/netzke/basepack/{basic_app → simple_app/javascripts}/statusbar_ext.js +0 -0
- data/lib/netzke/basepack/tab_panel.rb +2 -12
- data/lib/netzke/basepack/tab_panel/javascripts/main.js +11 -0
- data/lib/netzke/basepack/version.rb +2 -2
- data/lib/netzke/basepack/window.rb +6 -7
- data/lib/netzke/basepack/wrap_lazy_loaded.rb +3 -1
- data/lib/netzke/data_accessor.rb +25 -14
- data/lib/netzke/ext.rb +1 -1
- data/locales/en.yml +22 -0
- data/netzke-basepack.gemspec +66 -12
- data/spec/active_record/attributes_spec.rb +31 -2
- data/spec/factories.rb +16 -1
- data/test/rails_app/Gemfile +2 -2
- data/test/rails_app/Gemfile.lock +76 -77
- data/test/rails_app/app/components/author_grid.rb +7 -0
- data/test/rails_app/app/components/book_form.rb +24 -0
- data/test/rails_app/app/components/book_grid.rb +6 -1
- data/test/rails_app/app/components/book_grid_with_default_values.rb +11 -0
- data/test/rails_app/app/components/book_grid_with_nested_attributes.rb +13 -0
- data/test/rails_app/app/components/book_grid_with_virtual_attributes.rb +22 -0
- data/test/rails_app/app/components/book_paging_form_panel.rb +20 -0
- data/test/rails_app/app/components/book_presentation.rb +18 -0
- data/test/rails_app/app/components/books_bound_to_author.rb +10 -0
- data/test/rails_app/app/components/form_without_model.rb +19 -0
- data/test/rails_app/app/components/lockable_book_form.rb +17 -0
- data/test/rails_app/app/components/lockable_user_form.rb +7 -0
- data/test/rails_app/app/components/simple_window.rb +10 -0
- data/test/rails_app/app/components/some_accordion_panel.rb +22 -0
- data/test/rails_app/app/components/{simple_basic_app.rb → some_auth_app.rb} +3 -3
- data/test/rails_app/app/components/some_border_layout.rb +10 -7
- data/test/rails_app/app/components/some_simple_app.rb +34 -0
- data/test/rails_app/app/components/some_tab_panel.rb +16 -11
- data/test/rails_app/app/components/user_form.rb +11 -4
- data/test/rails_app/app/components/user_grid.rb +7 -1
- data/test/rails_app/app/components/window_component_loader.rb +1 -0
- data/test/rails_app/app/controllers/application_controller.rb +6 -0
- data/test/rails_app/app/controllers/components_controller.rb +3 -3
- data/test/rails_app/app/controllers/welcome_controller.rb +2 -2
- data/test/rails_app/app/helpers/embedded_components_helper.rb +2 -0
- data/test/rails_app/app/models/address.rb +3 -0
- data/test/rails_app/app/models/author.rb +2 -0
- data/test/rails_app/app/models/book.rb +1 -0
- data/test/rails_app/app/models/user.rb +1 -2
- data/test/rails_app/app/views/components/simple_panel.html.erb +1 -0
- data/test/rails_app/app/views/layouts/nested.html.erb +5 -0
- data/test/rails_app/config/application.rb +1 -1
- data/test/rails_app/config/initializers/netzke.rb +0 -4
- data/test/rails_app/config/locales/es.yml +16 -0
- data/test/rails_app/config/routes.rb +4 -1
- data/test/rails_app/db/development_structure.sql +33 -4
- data/test/rails_app/db/migrate/20101026190021_create_books.rb +2 -0
- data/test/rails_app/db/migrate/20110101143818_create_addresses.rb +17 -0
- data/test/rails_app/db/schema.rb +33 -1
- data/test/rails_app/spec/controllers/embedded_components_controller_spec.rb +12 -0
- data/test/rails_app/spec/helpers/embedded_components_helper_spec.rb +15 -0
- data/test/rails_app/spec/models/address_spec.rb +5 -0
- data/test/rails_app/spec/views/embedded_components/index.html.erb_spec.rb +5 -0
- metadata +67 -13
- data/features/basic_app.feature +0 -12
- data/lib/netzke/active_record/association_attributes.rb +0 -102
- data/lib/netzke/basepack/form_panel/javascripts/pre.js +0 -76
- data/lib/netzke/basepack/form_panel/javascripts/xcheckbox.js +0 -82
- data/lib/netzke/basepack/grid_panel/javascript.rb +0 -69
- data/locale/en.yml +0 -16
@@ -5,14 +5,12 @@ module Netzke
|
|
5
5
|
module Fields
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
|
-
# Items with normalized fields (i.e. containing all the necessary attributes needed by Ext.form.FormPanel to render
|
9
|
-
# a field)
|
8
|
+
# Items with normalized fields (i.e. containing all the necessary attributes needed by Ext.form.FormPanel to render a field)
|
10
9
|
def items
|
11
10
|
@form_panel_items ||= begin
|
12
|
-
res = normalize_fields(super || data_class && data_class.netzke_attributes || []) #
|
13
|
-
|
11
|
+
res = normalize_fields(super || data_class && data_class.netzke_attributes || []) # netzke_attributes as default items
|
14
12
|
# if primary key isn't there, insert it as first
|
15
|
-
if data_class && res.
|
13
|
+
if data_class && !res.detect{ |f| f[:name] == data_class.primary_key}
|
16
14
|
primary_key_item = normalize_field(data_class.primary_key.to_sym)
|
17
15
|
@fields_from_config[data_class.primary_key.to_sym] = primary_key_item
|
18
16
|
res.insert(0, primary_key_item)
|
@@ -33,7 +31,7 @@ module Netzke
|
|
33
31
|
# extract incomplete field configs from +config+
|
34
32
|
flds = fields_from_config
|
35
33
|
# and merged them with fields from the model
|
36
|
-
deep_merge_existing_fields(flds, fields_from_model)
|
34
|
+
deep_merge_existing_fields(flds, fields_from_model) if data_class
|
37
35
|
else
|
38
36
|
# extract flds configs from the model
|
39
37
|
flds = fields_from_model
|
@@ -82,32 +80,37 @@ module Netzke
|
|
82
80
|
# NetzkeModelAttrList.read_list(data_class.name) if persistent_config_enabled? && data_class
|
83
81
|
end
|
84
82
|
|
85
|
-
# This is where we expand our basic field config with all the
|
83
|
+
# This is where we expand our basic field config with all the defaults
|
86
84
|
def normalize_field(field)
|
87
85
|
# field can only be a string, a symbol, or a hash
|
88
86
|
if field.is_a?(Hash)
|
89
87
|
field = field.dup # we don't want to modify original hash
|
88
|
+
return field if field[:no_binding] # stop here if no normalization is needed
|
90
89
|
field[:name] = field[:name].to_s if field[:name] # all names should be strings
|
91
90
|
else
|
92
91
|
field = {:name => field.to_s}
|
93
92
|
end
|
94
93
|
|
95
|
-
|
94
|
+
field_from_model = fields_from_model && fields_from_model[field[:name].to_sym]
|
96
95
|
|
97
|
-
|
96
|
+
field_from_model && field.merge!(field_from_model)
|
98
97
|
|
98
|
+
detect_association_with_method(field) # xtype for an association field
|
99
99
|
set_default_field_label(field)
|
100
|
-
|
101
100
|
set_default_field_xtype(field) if field[:xtype].nil?
|
102
|
-
|
103
101
|
set_default_field_value(field) if self.record
|
102
|
+
set_default_read_only(field)
|
103
|
+
|
104
|
+
field[:display_mode] = config[:display_mode] if config[:display_mode]
|
104
105
|
|
105
106
|
# provide our special combobox with our id
|
106
107
|
field[:parent_id] = self.global_id if field[:xtype] == :combobox
|
107
108
|
|
108
109
|
field[:hidden] = field[:hide_label] = true if field[:hidden].nil? && primary_key_attr?(field)
|
109
110
|
|
110
|
-
|
111
|
+
# checkbox setup
|
112
|
+
field[:checked] = field[:value] if field[:attr_type] == :boolean
|
113
|
+
field[:input_value] = true if field[:attr_type] == :boolean
|
111
114
|
|
112
115
|
field
|
113
116
|
end
|
@@ -120,7 +123,11 @@ module Netzke
|
|
120
123
|
assoc_column = assoc.klass.columns_hash[method.to_s]
|
121
124
|
assoc_method_type = assoc_column.try(:type)
|
122
125
|
if assoc_method_type
|
123
|
-
c[:
|
126
|
+
if c[:nested_attribute]
|
127
|
+
c[:xtype] ||= xtype_for_attr_type(assoc_method_type)
|
128
|
+
else
|
129
|
+
c[:xtype] ||= assoc_method_type == :boolean ? xtype_for_attr_type(assoc_method_type) : xtype_for_association
|
130
|
+
end
|
124
131
|
end
|
125
132
|
end
|
126
133
|
end
|
@@ -149,7 +156,9 @@ module Netzke
|
|
149
156
|
end
|
150
157
|
|
151
158
|
def set_default_field_label(c)
|
152
|
-
|
159
|
+
# multiple spaces (in case of association attrs) get replaced with one
|
160
|
+
c[:field_label] ||= data_class ? data_class.human_attribute_name(c[:name]) : c[:name].humanize
|
161
|
+
c[:field_label].gsub!(/\s+/, " ")
|
153
162
|
end
|
154
163
|
|
155
164
|
def set_default_field_value(field)
|
@@ -168,10 +177,19 @@ module Netzke
|
|
168
177
|
field[:xtype] = xtype_for_attr_type(field[:attr_type]) unless xtype_for_attr_type(field[:attr_type]).nil?
|
169
178
|
end
|
170
179
|
|
180
|
+
def set_default_read_only(field)
|
181
|
+
enabled_if = !data_class || data_class.column_names.include?(field[:name])
|
182
|
+
enabled_if ||= data_class.instance_methods.map(&:to_s).include?("#{field[:name]}=")
|
183
|
+
enabled_if ||= record && record.respond_to?("#{field[:name]}=")
|
184
|
+
enabled_if ||= association_attr?(field[:name])
|
185
|
+
|
186
|
+
field[:read_only] = !enabled_if if field[:read_only].nil?
|
187
|
+
end
|
188
|
+
|
171
189
|
def attr_type_to_xtype_map
|
172
190
|
{
|
173
191
|
:integer => :numberfield,
|
174
|
-
:boolean => :
|
192
|
+
:boolean => :checkbox,
|
175
193
|
:date => :datefield,
|
176
194
|
:datetime => :xdatetime,
|
177
195
|
:text => :textarea,
|
@@ -181,7 +199,7 @@ module Netzke
|
|
181
199
|
end
|
182
200
|
|
183
201
|
def xtype_for_attr_type(type)
|
184
|
-
attr_type_to_xtype_map[type]
|
202
|
+
attr_type_to_xtype_map[type] || :textfield
|
185
203
|
end
|
186
204
|
|
187
205
|
def xtype_for_association
|
@@ -196,4 +214,4 @@ module Netzke
|
|
196
214
|
end
|
197
215
|
end
|
198
216
|
end
|
199
|
-
end
|
217
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
Ext.ns("Ext.netzke.form");
|
2
|
+
|
3
|
+
/*
|
4
|
+
A very simple CheckboxGroup extension, which serializes its checkboxes' "boxLabel" attributes into a string.
|
5
|
+
Config options:
|
6
|
+
* separator - separator of values in the string (defaults to ",")
|
7
|
+
* options - all checkboxes, by boxLabel, e.g.: ["Cool", "To read", "Important"]
|
8
|
+
*/
|
9
|
+
Ext.netzke.form.CommaListCbg = Ext.extend(Ext.form.CheckboxGroup, {
|
10
|
+
separator: ",",
|
11
|
+
|
12
|
+
initComponent: function(){
|
13
|
+
Ext.netzke.form.CommaListCbg.superclass.initComponent.call(this);
|
14
|
+
|
15
|
+
this.items = [];
|
16
|
+
Ext.each(this.options, function(o){
|
17
|
+
this.items.push({boxLabel: o});
|
18
|
+
}, this);
|
19
|
+
|
20
|
+
this.on('change', function(el){
|
21
|
+
this.hiddenEl.dom.value = this.getValue();
|
22
|
+
}, this);
|
23
|
+
},
|
24
|
+
|
25
|
+
onRender: function(ct, position){
|
26
|
+
Ext.netzke.form.CommaListCbg.superclass.onRender.call(this, ct, position)
|
27
|
+
this.hiddenEl = Ext.DomHelper.append(ct, {tag:'input', type: 'hidden', name: this.name}, true);
|
28
|
+
|
29
|
+
// Don't submit individual checkboxes
|
30
|
+
this.items.each(function(i){
|
31
|
+
i.el.dom.removeAttribute("name");
|
32
|
+
});
|
33
|
+
},
|
34
|
+
|
35
|
+
getValue: function(){
|
36
|
+
var checkedBoxes = Ext.netzke.form.CommaListCbg.superclass.getValue.call(this);
|
37
|
+
var res = [];
|
38
|
+
Ext.each(checkedBoxes, function(cb){
|
39
|
+
res.push(cb.boxLabel);
|
40
|
+
});
|
41
|
+
res = res.join(this.separator);
|
42
|
+
return res;
|
43
|
+
},
|
44
|
+
|
45
|
+
setValue: function(v){
|
46
|
+
if (Ext.isString(v)) {
|
47
|
+
var passedValues = v.split(this.separator);
|
48
|
+
var values = [];
|
49
|
+
this.items.each(function(i){
|
50
|
+
values.push(passedValues.indexOf(i.boxLabel) >= 0);
|
51
|
+
});
|
52
|
+
Ext.netzke.form.CommaListCbg.superclass.setValue.call(this, values);
|
53
|
+
} else {
|
54
|
+
Ext.netzke.form.CommaListCbg.superclass.setValue.call(this, arguments);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
});
|
58
|
+
|
59
|
+
Ext.reg('commalistcbg', Ext.netzke.form.CommaListCbg);
|
@@ -0,0 +1,62 @@
|
|
1
|
+
Ext.override(Ext.form.Field, {
|
2
|
+
|
3
|
+
// By calling this, the field is instructed to replace itself with another instance, configured with displayModeConfig
|
4
|
+
setDisplayMode: function(onOff){
|
5
|
+
if (this.hidden) return;
|
6
|
+
|
7
|
+
var owner = this.ownerCt;
|
8
|
+
var newConfig = this.displayModeConfig(onOff);
|
9
|
+
|
10
|
+
var idx = this.removeSelf();
|
11
|
+
owner.insert(idx, newConfig);
|
12
|
+
|
13
|
+
this.destroy();
|
14
|
+
},
|
15
|
+
|
16
|
+
// Remove self from the container
|
17
|
+
removeSelf: function(){
|
18
|
+
var idx = this.ownerCt.items.indexOf(this);
|
19
|
+
this.ownerCt.remove(this);
|
20
|
+
return idx;
|
21
|
+
},
|
22
|
+
|
23
|
+
// Config for creating an instance in "displayMode" (if onOff is true), or normal mode (if onOff is false)
|
24
|
+
displayModeConfig: function(onOff){
|
25
|
+
return Ext.apply(this.initialConfig, onOff ? {xtype: 'displayfield', origXtype: this.xtype, value: this.getValue()} : {xtype: this.origXtype, value: this.getValue()});
|
26
|
+
}
|
27
|
+
|
28
|
+
});
|
29
|
+
|
30
|
+
Ext.override(Ext.netzke.form.NRadioGroup, {
|
31
|
+
setDisplayMode: function(onOff){
|
32
|
+
this.items.each(function(i){
|
33
|
+
i.setDisabled(onOff);
|
34
|
+
});
|
35
|
+
}
|
36
|
+
});
|
37
|
+
|
38
|
+
Ext.override(Ext.netzke.form.CommaListCbg, {
|
39
|
+
setDisplayMode: function(onOff){
|
40
|
+
this.items.each(function(i){
|
41
|
+
i.setDisabled(onOff);
|
42
|
+
});
|
43
|
+
}
|
44
|
+
});
|
45
|
+
|
46
|
+
Ext.override(Ext.form.Checkbox, {
|
47
|
+
setDisplayMode: function(onOff){
|
48
|
+
this.setDisabled(onOff);
|
49
|
+
}
|
50
|
+
});
|
51
|
+
|
52
|
+
// Composite field has to take care of its children, by setting them into the "display mode"
|
53
|
+
Ext.override(Ext.form.CompositeField, {
|
54
|
+
displayModeConfig: function(onOff){
|
55
|
+
var newItems = [];
|
56
|
+
this.items.each(function(i){
|
57
|
+
newItems.push(Ext.apply(i.displayModeConfig(onOff)));
|
58
|
+
i.destroy();
|
59
|
+
});
|
60
|
+
return Ext.apply(this.initialConfig, {items: newItems, name: this.name});
|
61
|
+
}
|
62
|
+
});
|
@@ -0,0 +1,138 @@
|
|
1
|
+
{
|
2
|
+
bodyStyle : 'padding:5px 5px 0',
|
3
|
+
autoScroll : true,
|
4
|
+
labelWidth : 150,
|
5
|
+
applyMask : {msg: "Updating..."},
|
6
|
+
|
7
|
+
defaults : {
|
8
|
+
anchor : '-20', // to leave some space for the scrollbar
|
9
|
+
listeners : {
|
10
|
+
// On "return" key, submit the form
|
11
|
+
specialkey : {
|
12
|
+
fn : function(field, event){
|
13
|
+
if (event.getKey() == 13) this.ownerCt.onApply();
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
17
|
+
},
|
18
|
+
|
19
|
+
initComponent: function(){
|
20
|
+
if (!this.bbar) this.bbar = {xtype: 'toolbar'}; // an empty bbar by default, so that we can dynamically add buttons
|
21
|
+
|
22
|
+
// Now let Ext.form.FormPanel do the rest
|
23
|
+
Netzke.classes.Basepack.FormPanel.superclass.initComponent.call(this);
|
24
|
+
|
25
|
+
// Apply event
|
26
|
+
this.addEvents('apply');
|
27
|
+
},
|
28
|
+
|
29
|
+
afterRender: function(){
|
30
|
+
Netzke.classes.Basepack.FormPanel.superclass.afterRender.call(this);
|
31
|
+
|
32
|
+
// render in display mode?
|
33
|
+
if (this.locked) this.setDisplayMode(true);
|
34
|
+
},
|
35
|
+
|
36
|
+
onEdit: function(){
|
37
|
+
this.setDisplayMode(false);
|
38
|
+
},
|
39
|
+
|
40
|
+
onCancel: function(){
|
41
|
+
this.setDisplayMode(true, true);
|
42
|
+
},
|
43
|
+
|
44
|
+
updateToolbar: function(){
|
45
|
+
var tbar = this.getBottomToolbar();
|
46
|
+
|
47
|
+
if (this.inDisplayMode) {
|
48
|
+
var buttonIndex = tbar.items.findIndex("name", "apply");
|
49
|
+
var buttonToRemove = tbar.items.itemAt(buttonIndex);
|
50
|
+
if (buttonToRemove) {
|
51
|
+
tbar.remove(buttonToRemove);
|
52
|
+
}
|
53
|
+
|
54
|
+
var buttonIndex = tbar.items.findIndex("name", "cancel");
|
55
|
+
var buttonToRemove = tbar.items.itemAt(buttonIndex);
|
56
|
+
if (buttonToRemove) {
|
57
|
+
tbar.remove(buttonToRemove);
|
58
|
+
}
|
59
|
+
tbar.add(this.actions.edit);
|
60
|
+
} else {
|
61
|
+
var buttonIndex = tbar.items.findIndex("name", "edit");
|
62
|
+
var buttonToRemove = tbar.items.itemAt(buttonIndex);
|
63
|
+
if (buttonToRemove) {
|
64
|
+
tbar.remove(buttonToRemove);
|
65
|
+
}
|
66
|
+
tbar.insertButton(buttonIndex, this.actions.apply);
|
67
|
+
tbar.insertButton(buttonIndex, this.actions.cancel);
|
68
|
+
}
|
69
|
+
|
70
|
+
tbar.doLayout();
|
71
|
+
},
|
72
|
+
|
73
|
+
|
74
|
+
onApply: function() {
|
75
|
+
if (this.fireEvent('apply', this)) {
|
76
|
+
var values = this.getForm().getValues();
|
77
|
+
|
78
|
+
// do not send values from disabled fields and empty values
|
79
|
+
for (var fieldName in values) {
|
80
|
+
var field = this.getForm().findField(fieldName);
|
81
|
+
if (!field || field.disabled) delete values[fieldName];
|
82
|
+
}
|
83
|
+
|
84
|
+
if (!this.applyMaskCmp) this.applyMaskCmp = new Ext.LoadMask(this.bwrap, this.applyMask);
|
85
|
+
|
86
|
+
this.applyMaskCmp.show();
|
87
|
+
|
88
|
+
if (this.fileUpload) {
|
89
|
+
// Not a Netzke's standard endpoint call, because the form is multipart
|
90
|
+
this.getForm().submit({
|
91
|
+
url: this.endpointUrl("netzke_submit"),
|
92
|
+
params: {
|
93
|
+
data: Ext.encode(values)
|
94
|
+
},
|
95
|
+
failure: function(form, action){
|
96
|
+
// It will always be failure, as we don't play along with the Ext success indication (not returning {success: true})
|
97
|
+
this.bulkExecute(Ext.decode(action.response.responseText));
|
98
|
+
this.fireEvent('submitsuccess');
|
99
|
+
if (this.applyMaskCmp) this.applyMaskCmp.hide();
|
100
|
+
},
|
101
|
+
scope: this
|
102
|
+
});
|
103
|
+
} else {
|
104
|
+
// Submit the data and process the result
|
105
|
+
this.netzkeSubmit(Ext.apply((this.baseParams || {}), {data:Ext.encode(values)}), function(result){
|
106
|
+
if (result === "ok") {
|
107
|
+
this.fireEvent("submitsuccess");
|
108
|
+
if (this.mode == "lockable") this.setDisplayMode(true);
|
109
|
+
};
|
110
|
+
if (this.applyMaskCmp) this.applyMaskCmp.hide();
|
111
|
+
}, this);
|
112
|
+
}
|
113
|
+
}
|
114
|
+
},
|
115
|
+
|
116
|
+
setFormValues: function(values){
|
117
|
+
this.getForm().setValues(values);
|
118
|
+
},
|
119
|
+
|
120
|
+
setDisplayMode: function(onOff, cancel){
|
121
|
+
if (this.inDisplayMode == onOff) return;
|
122
|
+
this.getForm().items.each(function(i){i.setDisplayMode(onOff);});
|
123
|
+
this.getForm().cleanDestroyed(); // because fields inside of composite fields are not auto-cleaned!
|
124
|
+
this.doLayout();
|
125
|
+
this.inDisplayMode = onOff;
|
126
|
+
this.updateToolbar();
|
127
|
+
},
|
128
|
+
|
129
|
+
// recursively extract field names
|
130
|
+
extractFields: function(items){
|
131
|
+
Ext.each(items, function(i){
|
132
|
+
if (i.items) {this.extractFields(i.items);}
|
133
|
+
else if (i.name) {this.fieldNames.push(i.name);}
|
134
|
+
}, this);
|
135
|
+
|
136
|
+
}
|
137
|
+
|
138
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Ext.ns("Ext.netzke.form");
|
2
|
+
|
3
|
+
/*
|
4
|
+
A very simple RadioGroup extension.
|
5
|
+
Config options:
|
6
|
+
* options - all radio buttons, by boxLabel, e.g.: ["Cool", "To read", "Important"]
|
7
|
+
*/
|
8
|
+
Ext.netzke.form.NRadioGroup = Ext.extend(Ext.form.RadioGroup, {
|
9
|
+
// defaultType: 'radio',
|
10
|
+
// groupCls : 'x-form-radio-group',
|
11
|
+
|
12
|
+
initComponent: function(){
|
13
|
+
Ext.netzke.form.NRadioGroup.superclass.initComponent.call(this);
|
14
|
+
|
15
|
+
this.items = [];
|
16
|
+
|
17
|
+
Ext.each(this.options, function(o){
|
18
|
+
this.items.push({boxLabel: o, name: this.name, inputValue: o});
|
19
|
+
}, this);
|
20
|
+
|
21
|
+
delete this.name;
|
22
|
+
}
|
23
|
+
});
|
24
|
+
|
25
|
+
Ext.reg('nradiogroup', Ext.netzke.form.NRadioGroup);
|
@@ -25,7 +25,6 @@ module Netzke
|
|
25
25
|
field = fields[params[:column].to_sym]
|
26
26
|
scope = field.to_options[:scope]
|
27
27
|
query = params[:query]
|
28
|
-
|
29
28
|
{:data => combobox_options_for_column(field, :query => query, :scope => scope, :record_id => params[:id])}
|
30
29
|
end
|
31
30
|
|
@@ -52,7 +51,7 @@ module Netzke
|
|
52
51
|
success = create_or_update_record(data)
|
53
52
|
|
54
53
|
if success
|
55
|
-
{:set_form_values => values, :set_result => "ok"}
|
54
|
+
{:set_form_values => values.each_pair.inject({}){ |r,(k,v)| r.merge(k.l => v) }, :set_result => "ok"}
|
56
55
|
else
|
57
56
|
# flash eventual errors
|
58
57
|
@record.errors.to_a.each do |msg|
|
@@ -74,15 +73,19 @@ module Netzke
|
|
74
73
|
@record = data_class.new if @record.nil?
|
75
74
|
|
76
75
|
hsh.each_pair do |k,v|
|
77
|
-
|
78
|
-
@record.send("#{k}=",v)
|
79
|
-
rescue StandardError => exc
|
80
|
-
flash :error => exc.message
|
81
|
-
success = false
|
82
|
-
break
|
83
|
-
end
|
76
|
+
@record.set_value_for_attribute(fields[k.to_sym].nil? ? {:name => k} : fields[k.to_sym], v)
|
84
77
|
end
|
85
78
|
|
79
|
+
#hsh.each_pair do |k,v|
|
80
|
+
#begin
|
81
|
+
#@record.send("#{k}=",v)
|
82
|
+
#rescue StandardError => exc
|
83
|
+
#flash :error => exc.message
|
84
|
+
#success = false
|
85
|
+
#break
|
86
|
+
#end
|
87
|
+
#end
|
88
|
+
|
86
89
|
# did we have complete success?
|
87
90
|
success && @record.save
|
88
91
|
end
|