netzke-basepack 1.0.0.1 → 1.0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -92
- data/javascripts/grid/columns.js +9 -1
- data/javascripts/grid/event_handlers.js +31 -4
- data/lib/netzke/basepack/attr_config.rb +1 -5
- data/lib/netzke/basepack/attributes.rb +38 -3
- data/lib/netzke/basepack/columns.rb +11 -19
- data/lib/netzke/basepack/data_adapters/abstract_adapter.rb +4 -4
- data/lib/netzke/basepack/fields.rb +1 -1
- data/lib/netzke/basepack/version.rb +1 -1
- data/lib/netzke/grid/actions.rb +27 -3
- data/lib/netzke/grid/base.rb +48 -18
- data/lib/netzke/grid/base/client/base.js +9 -6
- data/lib/netzke/grid/base/client/extensions.js +7 -4
- data/lib/netzke/grid/configuration.rb +16 -8
- data/lib/netzke/tree/base.rb +26 -3
- data/lib/netzke/tree/base/client/base.js +8 -0
- metadata +2 -3
- data/lib/netzke/basepack/attribute_config.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf5c58faf416227bdbc8e57fce202ba5bfe073fc
|
4
|
+
data.tar.gz: ab2ba7342fca7c413795685800526343e842b1ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53de795fda7f1aa8d96802d4ddfd71a418961acbd6433d0d8398355c5566496f1cf00548a49fbf4fea525278762f7b84fca726fd771ab0c50f18dc08505f96e6
|
7
|
+
data.tar.gz: a1519277e2ec6d997b644adece7268ab1b84db4a13d19f9faac72e516d55670afce629fb4220354a5f94ed532096b894eed79f853be470a3840f484e54e64ac1
|
data/CHANGELOG.md
CHANGED
@@ -1,105 +1,28 @@
|
|
1
|
-
# v1.0.0
|
2
|
-
|
3
|
-
* Grid: fix showing validation errors on inline update
|
4
|
-
|
5
|
-
*Mike (firemind)*
|
6
|
-
|
7
|
-
# v1.0.0.0 - 2016-01-04
|
8
|
-
|
9
|
-
## Components changed/renamed
|
10
|
-
|
11
|
-
* Base classes of main componens have been renamed from `Netzke::Basepack::{Grid|Form|Tree|Window|Viewport}` to `Netzke::{Grid|Form|Tree|Window|Viewport}::Base`.
|
12
|
-
|
13
|
-
* `Netzke::Basepack::TabPanel` and `Netzke::Basepack::Accordion` have been removed. The only purpose for them was dynamic loading of child components, which didn't prove that useful.
|
14
|
-
|
15
|
-
## Form, Grid, Tree
|
16
|
-
|
17
|
-
### Breaking changes
|
18
|
-
|
19
|
-
* `strong_default_attrs` config option has been renamed to `strong_values`.
|
20
|
-
|
21
|
-
* `attr_type` config option for columns/fields has been renamed to `type`.
|
22
|
-
|
23
|
-
* The new `attribute` DSL method and the accompanying `attribute_overrides` config option allow reconfiguring the way specific model attributes are presented by both the grid and the form. The `column` DSL method has been left for configuring what's specific for a column. For details, see [Netzke::Basepack::Attributes](http://www.rubydoc.info/github/netzke/netzke-basepack/Netzke/Basepack/Attributes).
|
24
|
-
|
25
|
-
* `data_adapter` method has been renamed to `model_adapter`
|
26
|
-
|
27
|
-
* `model_class` method in `AbstractAdapter` has been renamed to `model`
|
28
|
-
|
29
|
-
## Form
|
30
|
-
|
31
|
-
### Breaking changes
|
32
|
-
|
33
|
-
* The `netzkeSubmit` and `netzkeLoad` endpoints have been renamed to `submit` and `load` respectively; keep this in mind if you override them in your app.
|
34
|
-
|
35
|
-
## Grid
|
1
|
+
# v1.0.1.0 - 2016-05-01
|
36
2
|
|
37
3
|
### Breaking changes
|
38
4
|
|
39
|
-
*
|
40
|
-
`
|
41
|
-
|
42
|
-
* `preconfigure_record_window` has been renamed to `configure_form_window`
|
43
|
-
|
44
|
-
* The `default_fields_for_forms` method has been renamed to `default_form_items`.
|
45
|
-
|
46
|
-
* The `data_store` config option has been renamed to `store_config`.
|
47
|
-
|
48
|
-
* Permissions configuration got consolidated into single `permissions` config option. See [Netzke::Grid::Base](http://www.rubydoc.info/github/netzke/netzke-basepack/Netzke/Grid/Base)
|
49
|
-
|
50
|
-
* The `del` action has been renamed to `delete`.
|
51
|
-
|
52
|
-
* Columns configuration (by using the `Grid.column` DSL method, or the `columns` configuration option) no longer has effect on corresponding form fields. Use the new `attribute` DSL method or the `attribute_overrides` config option (see above) to set the common configuration option for both column and form field.
|
53
|
-
|
54
|
-
* Virtual columns declared with the `column` DSL method are no longer automatically appended to the end of the column
|
55
|
-
list; use the `columns` config option or override the `Grid#columns` method to explicitely list them.
|
56
|
-
|
57
|
-
* The endpoints dropped their prefix `server`; additionally, `serverDelete` has become `destroy`; keep this in mind if you override endpoints in your app.
|
58
|
-
|
59
|
-
* All scope-related configs (including those of the columns) now only accept a Proc or a Hash.
|
60
|
-
|
61
|
-
* Class-level component configuration is gone (its sole purpose was to allow reducing the amount of generated JS code - not worth it).
|
62
|
-
|
63
|
-
* `enable_edit_in_form`, `enable_edit_inline`, `enable_pagination` options are gone.
|
64
|
-
|
65
|
-
* `enable_extended_search` option is gone.
|
66
|
-
|
67
|
-
### I18n
|
68
|
-
|
69
|
-
* Before to localize association attribute it was needed to specify the attribute in the doubre-underscore notation,
|
70
|
-
for example:
|
71
|
-
|
72
|
-
|
73
|
-
es:
|
74
|
-
activerecord:
|
75
|
-
attributes:
|
76
|
-
book:
|
77
|
-
author__name: Autor
|
78
|
-
|
79
|
-
Now it should be cut down to the association name:
|
80
|
-
|
81
|
-
es:
|
82
|
-
activerecord:
|
83
|
-
attributes:
|
84
|
-
book:
|
85
|
-
author: Autor
|
5
|
+
* Grid, Tree: use the `attributes` config option if you need to configure what attributes are shown in both the grid
|
6
|
+
and its forms. The `columns` config option now only takes effect on grid, and it doesn't modify the layout of its
|
7
|
+
forms.
|
86
8
|
|
87
|
-
|
9
|
+
* `edit_inline` config option is gone (see the new `editing` option).
|
88
10
|
|
89
|
-
*
|
11
|
+
* Provide full association name using the double-underscore notation in locales (e.g. `author__name` instead of just
|
12
|
+
`author`). This reverts the change introduced in 1.0.0.0.
|
90
13
|
|
91
|
-
|
14
|
+
### New and mproved
|
92
15
|
|
93
|
-
*
|
16
|
+
* Grid: new `paging` and `editing` options allow for more flexible combinations of different editing and paging modes.
|
94
17
|
|
95
|
-
*
|
18
|
+
* Tree: fixed date and datetime columns in some browsers.
|
96
19
|
|
97
|
-
*
|
20
|
+
* Tree: implement `scope` config option for Tree.
|
98
21
|
|
99
|
-
*
|
22
|
+
* Fix bug that allowed editing grids in inline mode by dblclicking the rows.
|
100
23
|
|
101
|
-
*
|
24
|
+
* Fix bug that allowed toggling checkbox in grids with prohibited update.
|
102
25
|
|
103
|
-
*
|
26
|
+
* Explicitly speficying grid actions will no longer display the buttons, whose actions are not permitted.
|
104
27
|
|
105
|
-
Please check [0-
|
28
|
+
Please check [1-0-0](https://github.com/netzke/netzke-basepack/blob/1-0-0/CHANGELOG.md) for previous changes.
|
data/javascripts/grid/columns.js
CHANGED
@@ -174,7 +174,10 @@ Ext.define("Netzke.Grid.Columns", {
|
|
174
174
|
return !(c.hidden || c.readOnly || c.type == 'boolean')
|
175
175
|
});
|
176
176
|
|
177
|
-
if (column) {
|
177
|
+
if (column) {
|
178
|
+
this.getPlugin('celleditor').startEdit(r, column);
|
179
|
+
var a = this.getPlugin('celleditor').editing;
|
180
|
+
}
|
178
181
|
},
|
179
182
|
|
180
183
|
netzkeFilterTypeForAttrType: function(type){
|
@@ -203,5 +206,10 @@ Ext.define("Netzke.Grid.Columns", {
|
|
203
206
|
'boolean' : 'boolean'
|
204
207
|
};
|
205
208
|
return map[type] || 'string';
|
209
|
+
},
|
210
|
+
|
211
|
+
netzkePermits: function(operation) {
|
212
|
+
var permissions = this.permissions || {};
|
213
|
+
return permissions[operation] != false;
|
206
214
|
}
|
207
215
|
});
|
@@ -5,7 +5,7 @@
|
|
5
5
|
Ext.define("Netzke.Grid.EventHandlers", {
|
6
6
|
// Handler for the 'add' button
|
7
7
|
netzkeOnAdd: function(){
|
8
|
-
if (
|
8
|
+
if (this.editing == 'in_form') {
|
9
9
|
this.netzkeOnAddInForm();
|
10
10
|
} else {
|
11
11
|
// Note: default values are taken from the model's field's defaultValue property
|
@@ -92,6 +92,15 @@ Ext.define("Netzke.Grid.EventHandlers", {
|
|
92
92
|
}
|
93
93
|
},
|
94
94
|
|
95
|
+
netzkeOnEditInForm: function(){
|
96
|
+
var selection = this.getSelectionModel().getSelection();
|
97
|
+
if (selection.length == 1) {
|
98
|
+
this.doEditInForm(selection[0]);
|
99
|
+
} else {
|
100
|
+
this.doMultiEdit(selection);
|
101
|
+
}
|
102
|
+
},
|
103
|
+
|
95
104
|
netzkeOnAddInForm: function(){
|
96
105
|
this.netzkeLoadComponent("add_window", {
|
97
106
|
callback: function(w) {
|
@@ -105,9 +114,9 @@ Ext.define("Netzke.Grid.EventHandlers", {
|
|
105
114
|
});
|
106
115
|
},
|
107
116
|
|
108
|
-
// Edit single record
|
117
|
+
// Edit single record using default mode
|
109
118
|
doEdit: function(record){
|
110
|
-
if (this.
|
119
|
+
if (this.editsInline) {
|
111
120
|
this.doEditInline(record);
|
112
121
|
} else {
|
113
122
|
this.doEditInForm(record);
|
@@ -178,6 +187,7 @@ Ext.define("Netzke.Grid.EventHandlers", {
|
|
178
187
|
netzkeSetActionEvents: function(){
|
179
188
|
this.getSelectionModel().on('selectionchange', function(selModel, selected){
|
180
189
|
if (this.actions.delete) this.actions.delete.setDisabled(selected.length == 0);
|
190
|
+
|
181
191
|
if (this.actions.edit) {
|
182
192
|
var disabled = false;
|
183
193
|
Ext.each(selected, function(r){
|
@@ -185,6 +195,10 @@ Ext.define("Netzke.Grid.EventHandlers", {
|
|
185
195
|
});
|
186
196
|
this.actions.edit.setDisabled(selected.length == 0 || disabled);
|
187
197
|
}
|
198
|
+
|
199
|
+
if (this.actions.editInForm) {
|
200
|
+
this.actions.editInForm.setDisabled(selected.length == 0);
|
201
|
+
}
|
188
202
|
}, this);
|
189
203
|
},
|
190
204
|
|
@@ -193,7 +207,7 @@ Ext.define("Netzke.Grid.EventHandlers", {
|
|
193
207
|
* @method netzkeHandleItemdblclick
|
194
208
|
*/
|
195
209
|
netzkeHandleItemdblclick: function(view, record){
|
196
|
-
if (this.
|
210
|
+
if (this.editsInline) return; // inline editing is handled elsewhere
|
197
211
|
|
198
212
|
if ((this.permissions || {}).update !== false) {
|
199
213
|
this.doEditInForm(record);
|
@@ -209,4 +223,17 @@ Ext.define("Netzke.Grid.EventHandlers", {
|
|
209
223
|
Netzke.warning("Undefined handler '"+handlerName+"'");
|
210
224
|
}
|
211
225
|
},
|
226
|
+
|
227
|
+
netzkeHandleBeforeEdit: function(_, field){
|
228
|
+
return this.netzkePermitInlineEdit(field.record);
|
229
|
+
},
|
230
|
+
|
231
|
+
/**
|
232
|
+
* Whether given record can be edited
|
233
|
+
* @method netzkePermitInlineEdit
|
234
|
+
* @return {Boolean}
|
235
|
+
*/
|
236
|
+
netzkePermitInlineEdit: function(record) {
|
237
|
+
return this.editsInline && (this.netzkePermits('update') || !!record.isNew);
|
238
|
+
}
|
212
239
|
});
|
@@ -32,11 +32,7 @@ module Netzke
|
|
32
32
|
private
|
33
33
|
|
34
34
|
def default_label
|
35
|
-
|
36
|
-
@model_adapter.human_attribute_name(name.split("__").first)
|
37
|
-
else
|
38
|
-
@model_adapter.human_attribute_name(name)
|
39
|
-
end
|
35
|
+
@model_adapter.human_attribute_name(name)
|
40
36
|
end
|
41
37
|
|
42
38
|
def responded_to_by_model?
|
@@ -43,8 +43,28 @@ module Netzke
|
|
43
43
|
# component :roles
|
44
44
|
# end
|
45
45
|
#
|
46
|
+
# Another way to override attributes is by overriding the +augment_attribute_config+ method:
|
47
|
+
#
|
48
|
+
# class Users < Netzke::Grid::Base
|
49
|
+
# def configure(c)
|
50
|
+
# super
|
51
|
+
# c.model = User
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# def augment_attribute_config(c)
|
55
|
+
# super
|
56
|
+
# c.read_only = true if [:address, :salary].include?(c.name)
|
57
|
+
# end
|
58
|
+
# end
|
59
|
+
#
|
46
60
|
# The following attribute config options are available:
|
47
61
|
#
|
62
|
+
# [label]
|
63
|
+
#
|
64
|
+
# Field label and/or column title used for this attribute. Defaults to
|
65
|
+
# `ActiveRecord::Base.human_attribute_name(attribute)`, which means that this value will be localized according to
|
66
|
+
# Rails conventions.
|
67
|
+
#
|
48
68
|
# [read_only]
|
49
69
|
#
|
50
70
|
# A boolean that defines whether the attribute should be editable via grid/form.
|
@@ -156,11 +176,17 @@ module Netzke
|
|
156
176
|
end
|
157
177
|
end
|
158
178
|
|
179
|
+
# Returns the list of (non-normalized) attributes to be used.
|
180
|
+
# Can be overridden.
|
181
|
+
def attributes
|
182
|
+
config.attributes || model_adapter.model_attributes
|
183
|
+
end
|
184
|
+
|
159
185
|
def attribute_overrides
|
160
186
|
return @attribute_overrides if @attribute_overrides
|
161
187
|
|
162
|
-
declared = self.class.declared_attribute_names.reduce({}) do |res, name|
|
163
|
-
c =
|
188
|
+
declared = (attributes | self.class.declared_attribute_names).reduce({}) do |res, name|
|
189
|
+
c = Netzke::Basepack::AttrConfig.new(name, model_adapter)
|
164
190
|
augment_attribute_config(c)
|
165
191
|
res.merge!(name => c)
|
166
192
|
end
|
@@ -168,8 +194,17 @@ module Netzke
|
|
168
194
|
@attribute_overrides = (config.attribute_overrides || {}).deep_merge(declared)
|
169
195
|
end
|
170
196
|
|
197
|
+
# Extends passed column config with DSL declaration for this column
|
198
|
+
def apply_attribute_dsl(c)
|
199
|
+
method_name = ATTRIBUTE_METHOD_NAME % c.name
|
200
|
+
send(method_name, c) if respond_to?(method_name)
|
201
|
+
end
|
202
|
+
|
203
|
+
# Receives a +Netzke::Basepack::AttrConfig+ with minimum attribute configuration and extends it according to the
|
204
|
+
# attribute's type. May be overridden.
|
171
205
|
def augment_attribute_config(c)
|
172
|
-
|
206
|
+
apply_attribute_dsl(c)
|
207
|
+
c.set_defaults
|
173
208
|
end
|
174
209
|
|
175
210
|
def association_attr?(attr)
|
@@ -71,7 +71,7 @@ module Netzke
|
|
71
71
|
# Returns the list of (non-normalized) columns to be used. By default returns the list of model column names and declared columns.
|
72
72
|
# Can be overridden.
|
73
73
|
def columns
|
74
|
-
config.columns ||
|
74
|
+
config.columns || attributes
|
75
75
|
end
|
76
76
|
|
77
77
|
# An array of complete columns configs ready to be passed to the JS side.
|
@@ -79,8 +79,8 @@ module Netzke
|
|
79
79
|
@final_columns ||= [].tap do |cols|
|
80
80
|
has_primary_column = false
|
81
81
|
|
82
|
-
columns.each do |
|
83
|
-
c = build_column_config(
|
82
|
+
columns.each do |name|
|
83
|
+
c = build_column_config(name)
|
84
84
|
next if c.excluded
|
85
85
|
|
86
86
|
has_primary_column ||= c.primary?
|
@@ -92,8 +92,8 @@ module Netzke
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
def build_column_config(
|
96
|
-
Netzke::Basepack::ColumnConfig.new(
|
95
|
+
def build_column_config(name)
|
96
|
+
Netzke::Basepack::ColumnConfig.new(name, model_adapter).tap do |c|
|
97
97
|
attribute_config = attribute_overrides[c.name.to_sym]
|
98
98
|
c.merge_attribute(attribute_config) if attribute_config
|
99
99
|
augment_column_config(c)
|
@@ -112,11 +112,10 @@ module Netzke
|
|
112
112
|
|
113
113
|
# Columns that have to be used by the JS side of the grid
|
114
114
|
def js_columns
|
115
|
-
final_columns.
|
115
|
+
final_columns.each do |c|
|
116
116
|
# we are removing the editor on this last step, so that the editor config is still being passed from the
|
117
117
|
# column config to the form editor; refactor!
|
118
|
-
c.delete(:editor) unless config.
|
119
|
-
c
|
118
|
+
c.delete(:editor) unless config.edits_inline
|
120
119
|
end
|
121
120
|
end
|
122
121
|
|
@@ -142,7 +141,7 @@ module Netzke
|
|
142
141
|
|
143
142
|
# Default form items (non-normalized) that will be displayed in the Add/Edit forms
|
144
143
|
def default_form_items
|
145
|
-
|
144
|
+
attributes
|
146
145
|
end
|
147
146
|
|
148
147
|
# ATM the same attributes are used as in forms
|
@@ -156,7 +155,7 @@ module Netzke
|
|
156
155
|
end
|
157
156
|
end
|
158
157
|
|
159
|
-
# Form items that will be used by the Add/Edit forms. May be
|
158
|
+
# Form items that will be used by the Add/Edit forms. May be overridden.
|
160
159
|
def form_items
|
161
160
|
config.form_items || default_form_items
|
162
161
|
end
|
@@ -197,15 +196,8 @@ module Netzke
|
|
197
196
|
send(method_name, c) if respond_to?(method_name)
|
198
197
|
end
|
199
198
|
|
200
|
-
#
|
201
|
-
#
|
202
|
-
# {:name=>"author__name", :type=>:string}
|
203
|
-
#
|
204
|
-
# augment it with additional configuration params, e.g.:
|
205
|
-
#
|
206
|
-
# {:name=>"author__name", :type=>:string, :editor=>{:xtype=>:netzkeremotecombo}, :assoc=>true, :virtual=>true, :header=>"Author", :sortable=>false, :filterable=>false}
|
207
|
-
#
|
208
|
-
# It may be handy to override it.
|
199
|
+
# Receives a +Netzke::Basepack::ColumnConfig+ with minimum column configuration and extends it according to the
|
200
|
+
# attribute's type. May be overridden.
|
209
201
|
def augment_column_config(c)
|
210
202
|
apply_column_dsl(c)
|
211
203
|
c.set_defaults
|
@@ -230,12 +230,12 @@ module Netzke::Basepack::DataAdapters
|
|
230
230
|
model.root
|
231
231
|
end
|
232
232
|
|
233
|
-
def find_record_children(r)
|
234
|
-
r.children
|
233
|
+
def find_record_children(r, scope = nil)
|
234
|
+
extend_relation_with_scope(r.children, scope)
|
235
235
|
end
|
236
236
|
|
237
|
-
def find_root_records
|
238
|
-
model.where(parent_id: nil)
|
237
|
+
def find_root_records(scope = nil)
|
238
|
+
extend_relation_with_scope(model.where(parent_id: nil), scope)
|
239
239
|
end
|
240
240
|
|
241
241
|
# Does record respond to given method?
|
@@ -6,7 +6,7 @@ module Netzke
|
|
6
6
|
|
7
7
|
# Items with normalized fields (i.e. containing all the necessary attributes needed by Ext.form.Form to render a field)
|
8
8
|
def items
|
9
|
-
prepend_primary_key(config.items
|
9
|
+
prepend_primary_key(config.items || attributes)
|
10
10
|
end
|
11
11
|
|
12
12
|
# Hash of fully configured fields, that are referenced in the items. E.g.:
|
data/lib/netzke/grid/actions.rb
CHANGED
@@ -6,25 +6,41 @@ module Netzke
|
|
6
6
|
included do
|
7
7
|
action :add do |a|
|
8
8
|
a.icon = :add
|
9
|
+
a.excluded = !has_add_action?
|
10
|
+
end
|
11
|
+
|
12
|
+
action :add_in_form do |a|
|
13
|
+
a.icon = :application_form_add
|
14
|
+
a.excluded = !has_add_in_form_action?
|
9
15
|
end
|
10
16
|
|
11
17
|
action :edit do |a|
|
12
|
-
a.disabled = true #
|
18
|
+
a.disabled = true # initially
|
13
19
|
a.icon = :table_edit
|
20
|
+
a.excluded = !has_edit_action?
|
14
21
|
end
|
15
22
|
|
16
23
|
action :delete do |a|
|
17
|
-
a.disabled = true #
|
24
|
+
a.disabled = true # initially
|
18
25
|
a.icon = :table_row_delete
|
26
|
+
a.excluded = !has_delete_action?
|
19
27
|
end
|
20
28
|
|
21
29
|
action :apply do |a|
|
22
30
|
a.icon = :tick
|
31
|
+
a.excluded = !has_apply_action?
|
23
32
|
end
|
24
33
|
|
25
34
|
action :search do |a|
|
26
35
|
a.enable_toggle = true
|
27
36
|
a.icon = :magnifier
|
37
|
+
a.excluded = !has_search_action?
|
38
|
+
end
|
39
|
+
|
40
|
+
action :edit_in_form do |a|
|
41
|
+
a.disabled = true # initially
|
42
|
+
a.icon = :application_form_edit
|
43
|
+
a.excluded = !has_edit_in_form_action?
|
28
44
|
end
|
29
45
|
end
|
30
46
|
|
@@ -32,12 +48,20 @@ module Netzke
|
|
32
48
|
allowed_to?(:create)
|
33
49
|
end
|
34
50
|
|
51
|
+
def has_add_in_form_action?
|
52
|
+
allowed_to?(:create) && config.editing == :both
|
53
|
+
end
|
54
|
+
|
35
55
|
def has_edit_action?
|
36
56
|
allowed_to?(:update)
|
37
57
|
end
|
38
58
|
|
59
|
+
def has_edit_in_form_action?
|
60
|
+
allowed_to?(:update) && config.editing == :both
|
61
|
+
end
|
62
|
+
|
39
63
|
def has_apply_action?
|
40
|
-
config.
|
64
|
+
config.edits_inline && (allowed_to?(:create) || allowed_to?(:update))
|
41
65
|
end
|
42
66
|
|
43
67
|
def has_delete_action?
|
data/lib/netzke/grid/base.rb
CHANGED
@@ -24,35 +24,55 @@ module Netzke
|
|
24
24
|
# Name of the ActiveRecord model that provides data to this Grid (e.g. "User") or the model's class (e.g. User).
|
25
25
|
# Required.
|
26
26
|
#
|
27
|
-
# [
|
27
|
+
# [attributes]
|
28
28
|
#
|
29
|
-
# Explicit list of
|
30
|
-
# or a hash, which contains the +name+ key pointing to the attribute name and additional
|
31
|
-
# the "Configuring attributes" section below). For example:
|
29
|
+
# Explicit list of attributes to be displayed in the grid and its forms; each attribute may be represented by a
|
30
|
+
# symbol (attribute name), or a hash, which contains the +name+ key pointing to the attribute name and additional
|
31
|
+
# configuration keys (see the "Configuring attributes" section below). For example:
|
32
32
|
#
|
33
33
|
# class Users < Netzke::Grid::Base
|
34
34
|
# def configure(c)
|
35
35
|
# super
|
36
36
|
# c.model = User
|
37
|
-
# c.
|
37
|
+
# c.attributes = [
|
38
38
|
# :first_name,
|
39
39
|
# :last_name,
|
40
|
-
# { name: :salary,
|
40
|
+
# { name: :salary, read_only: true }
|
41
41
|
# ]
|
42
42
|
# end
|
43
43
|
# end
|
44
44
|
#
|
45
45
|
# Defaults to model attribute list.
|
46
46
|
#
|
47
|
+
# Note, that you can also individually override attribute configs, see +Basepack::Attributes+.
|
48
|
+
#
|
49
|
+
# [columns]
|
50
|
+
#
|
51
|
+
# Array of columns to be displayed in the grid. This overrides the +attributes+ config option. For example:
|
52
|
+
#
|
53
|
+
# class Users < Netzke::Grid::Base
|
54
|
+
# def configure(c)
|
55
|
+
# super
|
56
|
+
# c.model = User
|
57
|
+
# c.attributes = [
|
58
|
+
# :first_name,
|
59
|
+
# :last_name,
|
60
|
+
# { name: :salary, width: 50 }
|
61
|
+
# ]
|
62
|
+
# end
|
63
|
+
# end
|
64
|
+
#
|
47
65
|
# Note, that you can also individually override column configs (e.g. setting a column's width) by using the
|
48
|
-
# +column+ DSL method (see +Basepack::Columns+)
|
49
|
-
#
|
66
|
+
# +column+ DSL method (see +Basepack::Columns+).
|
67
|
+
#
|
68
|
+
# Defaults to attribute names listed with the +attributes+ config option.
|
50
69
|
#
|
51
70
|
# [form_items]
|
52
71
|
#
|
53
|
-
# Array of
|
54
|
-
#
|
55
|
-
# name, as well as additional
|
72
|
+
# Array of items to be displayed in the grid's forms. This overrides the +attributes+ config option and may define
|
73
|
+
# arbitrary form layout. An item that represents a specific attribute, should be specified as either a symbol
|
74
|
+
# (attribute name), or a hash containing the +name+ key pointing to the attribute name, as well as additional
|
75
|
+
# configuration keys.
|
56
76
|
#
|
57
77
|
# class Users < Netzke::Grid::Base
|
58
78
|
# def configure(c)
|
@@ -67,7 +87,7 @@ module Netzke
|
|
67
87
|
# end
|
68
88
|
# end
|
69
89
|
#
|
70
|
-
# Defaults to
|
90
|
+
# Defaults to attribute names listed with the +attributes+ config option.
|
71
91
|
#
|
72
92
|
# [attribute_overrides]
|
73
93
|
#
|
@@ -104,18 +124,28 @@ module Netzke
|
|
104
124
|
#
|
105
125
|
# A hash of attributes to be merged atop of every created/updated record, e.g. +role_id: 1+
|
106
126
|
#
|
107
|
-
# [edit_inline]
|
108
|
-
# Whether record editing should happen inline (as opposed to using a form). When set to +true+, automatically sets
|
109
|
-
# +paging+ to +true+. Defaults to +false+.
|
110
|
-
#
|
111
127
|
# [context_menu]
|
112
128
|
#
|
113
129
|
# An array of actions (e.g. [:edit, "-", :delete] - see the Actions section) or +false+ to disable the context menu.
|
114
130
|
#
|
115
131
|
# [paging]
|
116
132
|
#
|
117
|
-
#
|
118
|
-
#
|
133
|
+
# Type of pagination to use:
|
134
|
+
#
|
135
|
+
# * :buffered (default) - implements "infinite scrolling" with help of the Ext's buffered store
|
136
|
+
# * :pagination - uses the paging toolbar
|
137
|
+
# * :none - loads all data at once
|
138
|
+
#
|
139
|
+
# [editing]
|
140
|
+
#
|
141
|
+
# Grid editing mode:
|
142
|
+
#
|
143
|
+
# * :in_form (default) - all add/edit operations are performed via a form
|
144
|
+
# * :inline - all add/edit operations are performed inline, with exception of multi-line editing, which is done
|
145
|
+
# via a form. Note: 1) this option is not compatible with `paging` set to :buffered, 2) if no `paging` option is
|
146
|
+
# set, setting this option will automatically set that to :pagination.
|
147
|
+
# * :both - same as :inline, but there are 2 more actions added to the toolbar: "Add in form" and "Edit in form",
|
148
|
+
# which will use a form.
|
119
149
|
#
|
120
150
|
# [store_config]
|
121
151
|
#
|
@@ -38,13 +38,13 @@
|
|
38
38
|
this.store = this.netzkeBuildStore();
|
39
39
|
|
40
40
|
// Cell editing
|
41
|
-
if (
|
41
|
+
if (this.netzkePermits('update') || this.netzkePermits('create') && this.editsInline) {
|
42
42
|
this.plugins.push(Ext.create('Ext.grid.plugin.CellEditing', {pluginId: 'celleditor'}));
|
43
43
|
}
|
44
44
|
|
45
45
|
// Toolbar
|
46
46
|
this.dockedItems = this.dockedItems || [];
|
47
|
-
if (this.paging) {
|
47
|
+
if (this.paging == 'pagination') {
|
48
48
|
this.dockedItems.push({
|
49
49
|
xtype: 'pagingtoolbar',
|
50
50
|
dock: 'bottom',
|
@@ -75,7 +75,7 @@
|
|
75
75
|
|
76
76
|
// When starting editing as assocition column, pre-load the combobox store from the meta column, so that we don't see the real value of this cell (the id of the associated record), but rather the associated record by the configured method.
|
77
77
|
this.on('beforeedit', function(editor, e){
|
78
|
-
if (e.column.assoc && e.
|
78
|
+
if (e.column.assoc && e.column.getEditor()) {
|
79
79
|
var c = e.column,
|
80
80
|
combo = c.getEditor(),
|
81
81
|
store = combo.store,
|
@@ -83,7 +83,7 @@
|
|
83
83
|
|
84
84
|
// initial load of 1 single record for the combobox store, which contains the display text (stored in the meta field) for the current value
|
85
85
|
if (id && -1 == store.find('value', id)) {
|
86
|
-
store.loadData([[e.record.get(e.field), e.record.get('
|
86
|
+
store.loadData([[e.record.get(e.field), e.record.get('association_values')[e.field]]], true);
|
87
87
|
}
|
88
88
|
|
89
89
|
}
|
@@ -109,6 +109,7 @@
|
|
109
109
|
}
|
110
110
|
|
111
111
|
this.on('itemdblclick', this.netzkeHandleItemdblclick, this);
|
112
|
+
this.on('beforeedit', this.netzkeHandleBeforeEdit, this);
|
112
113
|
|
113
114
|
// Remember grid selection on reloads
|
114
115
|
if(this.netzkeRememberSelection && this.netzkeRestoreSelection){
|
@@ -144,10 +145,12 @@
|
|
144
145
|
pruneModifiedRecords: true,
|
145
146
|
remoteSort: true,
|
146
147
|
remoteFilter: true,
|
147
|
-
buffered:
|
148
|
+
buffered: this.paging == 'buffered'
|
148
149
|
};
|
149
150
|
|
150
|
-
if (
|
151
|
+
if (this.paging == 'buffered') defaults.pageSize = 300;
|
152
|
+
|
153
|
+
if (this.paging == 'none') defaults.pageSize = 0;
|
151
154
|
|
152
155
|
return Ext.apply({}, this.storeConfig, defaults);
|
153
156
|
},
|
@@ -149,9 +149,12 @@ Ext.define('Netzke.Grid.Proxy', {
|
|
149
149
|
|
150
150
|
// Fix for CheckColumn
|
151
151
|
Ext.override(Ext.ux.CheckColumn, {
|
152
|
-
processEvent: function(type) {
|
153
|
-
|
154
|
-
|
155
|
-
|
152
|
+
processEvent: function(type, view, _, _, _, _, record) {
|
153
|
+
if (type == 'mousedown' && this.readOnly || !view.grid.netzkePermitInlineEdit(record)) {
|
154
|
+
// by returning true, we'll allow event propagation, so it reacts similarly to other columns
|
155
|
+
return true;
|
156
|
+
} else {
|
157
|
+
return this.callOverridden(arguments);
|
158
|
+
}
|
156
159
|
}
|
157
160
|
});
|
@@ -20,13 +20,7 @@ module Netzke
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def default_bbar
|
23
|
-
[
|
24
|
-
bbar << :add if has_add_action?
|
25
|
-
bbar << :edit if has_edit_action?
|
26
|
-
bbar << :apply if has_apply_action?
|
27
|
-
bbar << :delete if has_delete_action?
|
28
|
-
bbar << :search if has_search_action?
|
29
|
-
end
|
23
|
+
[:add, :add_in_form, :edit, :edit_in_form, :apply, :delete, :search]
|
30
24
|
end
|
31
25
|
|
32
26
|
def context_menu
|
@@ -61,10 +55,24 @@ module Netzke
|
|
61
55
|
|
62
56
|
def validate_config(c)
|
63
57
|
raise ArgumentError, "Grid requires a model" if model.nil?
|
64
|
-
|
58
|
+
|
59
|
+
c.editing = :in_form if c.editing.nil?
|
60
|
+
|
61
|
+
c.edits_in_form = [:both, :in_form].include?(c.editing)
|
62
|
+
c.edits_inline = [:both, :inline].include?(c.editing)
|
63
|
+
|
64
|
+
if c.paging.nil?
|
65
|
+
c.paging = c.edits_inline ? :pagination : :buffered
|
66
|
+
end
|
67
|
+
|
68
|
+
if c.paging == :buffered && c.edits_inline
|
69
|
+
raise ArgumentError, "Buffered grid cannot have inline editing"
|
70
|
+
end
|
71
|
+
|
65
72
|
c.tools = tools
|
66
73
|
c.bbar = bbar
|
67
74
|
c.context_menu = context_menu
|
75
|
+
|
68
76
|
super
|
69
77
|
end
|
70
78
|
end
|
data/lib/netzke/tree/base.rb
CHANGED
@@ -54,6 +54,29 @@ module Netzke
|
|
54
54
|
# Note, that the root record can be hidden from the tree by specifying the `Ext.tree.Panel`'s `root_visible`
|
55
55
|
# config option set to `false`, which is probably what you want when you have multiple root records.
|
56
56
|
#
|
57
|
+
# [scope]
|
58
|
+
#
|
59
|
+
# A Proc or a Hash used to scope out grid data. The Proc will receive the current relation as a parameter and must
|
60
|
+
# return the modified relation. For example:
|
61
|
+
#
|
62
|
+
# class Books < Netzke::Grid::Base
|
63
|
+
# def configure(c)
|
64
|
+
# super
|
65
|
+
# c.model = Book
|
66
|
+
# c.scope = lambda {|r| r.where(author_id: 1) }
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# Hash is being accepted for conivience, it will be directly passed to `where`. So the above can be rewritten as:
|
71
|
+
#
|
72
|
+
# class Books < Netzke::Grid::Base
|
73
|
+
# def configure(c)
|
74
|
+
# super
|
75
|
+
# c.model = Book
|
76
|
+
# c.scope = {author_id: 1}
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
#
|
57
80
|
# [drag_drop]
|
58
81
|
#
|
59
82
|
# Enables drag and drop in the tree.
|
@@ -108,9 +131,9 @@ module Netzke
|
|
108
131
|
# Overrides Grid::Services#get_records
|
109
132
|
def get_records(params)
|
110
133
|
if params[:id] == 'root'
|
111
|
-
model_adapter.find_root_records
|
134
|
+
model_adapter.find_root_records(config[:scope])
|
112
135
|
else
|
113
|
-
model_adapter.find_record_children(model_adapter.find_record(params[:id]))
|
136
|
+
model_adapter.find_record_children(model_adapter.find_record(params[:id]), config[:scope])
|
114
137
|
end
|
115
138
|
end
|
116
139
|
|
@@ -126,7 +149,7 @@ module Netzke
|
|
126
149
|
def node_to_hash(record, columns)
|
127
150
|
model_adapter.record_to_hash(record, columns).tap do |hash|
|
128
151
|
if is_node_expanded?(record)
|
129
|
-
hash["children"] = record.
|
152
|
+
hash["children"] = model_adapter.find_record_children(record, config[:scope]).map {|child| node_to_hash(child, columns).netzke_literalize_keys}
|
130
153
|
end
|
131
154
|
end
|
132
155
|
end
|
@@ -32,6 +32,7 @@
|
|
32
32
|
}, this);
|
33
33
|
|
34
34
|
this.on('itemdblclick', this.netzkeHandleItemdblclick, this);
|
35
|
+
this.on('beforeedit', this.netzkeHandleBeforeEdit, this);
|
35
36
|
},
|
36
37
|
|
37
38
|
/**
|
@@ -45,6 +46,7 @@
|
|
45
46
|
netzkeBuildStore: function() {
|
46
47
|
var store = Ext.create('Ext.data.TreeStore', Ext.apply({
|
47
48
|
proxy: this.netzkeBuildProxy(),
|
49
|
+
fields: this.fields,
|
48
50
|
pruneModifiedRecords: true,
|
49
51
|
remoteSort: true,
|
50
52
|
remoteFilter: true,
|
@@ -148,5 +150,11 @@
|
|
148
150
|
store.sync();
|
149
151
|
}
|
150
152
|
}, this);
|
153
|
+
},
|
154
|
+
|
155
|
+
netzkeExtractFieldConfig: function(c){
|
156
|
+
var res = this.callParent([c]);
|
157
|
+
if (res.name == 'id') res.type = 'auto';
|
158
|
+
return res;
|
151
159
|
}
|
152
160
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netzke-basepack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Gorin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A set of feature-rich extendible Netzke components (such as Grid, Tree,
|
14
14
|
Form, Window) and component extensions which can be used as building blocks for
|
@@ -35,7 +35,6 @@ files:
|
|
35
35
|
- lib/netzke/basepack/action_column.rb
|
36
36
|
- lib/netzke/basepack/active_record.rb
|
37
37
|
- lib/netzke/basepack/attr_config.rb
|
38
|
-
- lib/netzke/basepack/attribute_config.rb
|
39
38
|
- lib/netzke/basepack/attributes.rb
|
40
39
|
- lib/netzke/basepack/column_config.rb
|
41
40
|
- lib/netzke/basepack/columns.rb
|