netzke-basepack 0.12.8 → 0.12.9

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.12.9 - 2015-12-06
2
+ * Grid: warn the user at an attempt to change the page when there are unapplied changes;
3
+ disable the warning by setting `disable_dirty_page_warning` to `true`.
4
+ * Implement `scope` option for `Tree`
5
+
1
6
  # 0.12.8 - 2015-09-11
2
7
  * Fix regression in Tree that would (again) prevent snake_cased columns from being displayed
3
8
 
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source 'http://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rails', '4.2.0'
5
+ gem 'rails', '~>4.2.0'
6
6
  gem 'sqlite3'
7
7
  gem 'yard'
8
8
  gem 'rake'
@@ -15,8 +15,10 @@ module Netzke
15
15
  self.where(scope)
16
16
  when Proc # receives a relation, must return a relation
17
17
  scope.call(self)
18
+ when nil
19
+ self
18
20
  else
19
- raise ArgumentError, "Wrong parameter type for ActiveRecord::Relation#extend_with"
21
+ raise ArgumentError, "Wrong parameter type for ActiveRecord::Relation#extend_with (#{scope.class.name})"
20
22
  end
21
23
  end
22
24
  end
@@ -225,17 +225,19 @@ module Netzke::Basepack::DataAdapters
225
225
  name.to_s.humanize
226
226
  end
227
227
 
228
- # Return root record for tree-like data
228
+ # Returns root record for tree-like data
229
229
  def root
230
230
  model_class.root
231
231
  end
232
232
 
233
- def find_record_children(r)
234
- r.children
233
+ # Children records for given record in the tree; extra scope (lambda/proc) is optional
234
+ def find_record_children(r, scope = nil)
235
+ r.children.extend_with(scope)
235
236
  end
236
237
 
237
- def find_root_records
238
- model_class.where(parent_id: nil)
238
+ # All root records in the tree
239
+ def find_root_records(scope)
240
+ model_class.where(parent_id: nil).extend_with(scope)
239
241
  end
240
242
 
241
243
  # Does record respond to given method?
@@ -29,7 +29,8 @@ module Netzke
29
29
  #
30
30
  # [scope]
31
31
  #
32
- # Specifies how the data should be filtered.
32
+ # Specifies how the records should be scoped.
33
+ #
33
34
  # When it's a symbol, it's used as a scope name.
34
35
  # When it's a string, it's a SQL statement (passed directly to +where+).
35
36
  # When it's a hash, it's a conditions hash (passed directly to +where+).
@@ -37,6 +38,11 @@ module Netzke
37
38
  #
38
39
  # scope: ["id > ?", 100])
39
40
  #
41
+ # When it's a Proc, it gets the current relation passed as the only parameter and is expected to return a
42
+ # relation, e.g.:
43
+ #
44
+ # scope: ->(relation) { relation.where(user_id: 100) }
45
+ #
40
46
  # [role]
41
47
  #
42
48
  # Role for ActiveModel mass-assignment security
@@ -73,6 +79,10 @@ module Netzke
73
79
  #
74
80
  # (defaults to 30) number of rows per page (ignored when +enable_pagination+ is set to +false+)
75
81
  #
82
+ # [disable_dirty_page_warning]
83
+ #
84
+ # (defaults to false) do not warn the user about dirty records on the page when changing the page
85
+ #
76
86
  # [data_store]
77
87
  #
78
88
  # (defaults to empty Hash) extra configuration for the JS class's internal store (see
@@ -367,7 +377,7 @@ module Netzke
367
377
  c.mixins << "Netzke.mixins.Basepack.Columns"
368
378
  c.mixins << "Netzke.mixins.Basepack.GridEventHandlers"
369
379
 
370
- c.translate *%w[are_you_sure confirmation]
380
+ c.translate *%w[are_you_sure confirmation proceed_with_unapplied_changes]
371
381
 
372
382
  # JavaScript includes
373
383
  ex = Netzke::Core.ext_path.join("examples")
@@ -51,6 +51,9 @@
51
51
  this.dockedItems.push({
52
52
  xtype: 'pagingtoolbar',
53
53
  dock: 'bottom',
54
+ listeners: {
55
+ 'beforechange': this.disableDirtyPageWarning ? {} : {fn: this.netzkeBeforePageChange, scope: this}
56
+ },
54
57
  store: this.store,
55
58
  items: this.bbar && ["-"].concat(this.bbar) // append the passed bbar
56
59
  });
@@ -171,5 +174,12 @@
171
174
 
172
175
  netzkeBuildReader: function() {
173
176
  return Ext.create('Netzke.classes.Basepack.Grid.ArrayReader');
177
+ },
178
+
179
+ netzkeBeforePageChange: function(){
180
+ var store = this.getStore();
181
+ if (store.getNewRecords().length > 0 || store.getModifiedRecords().length > 0) {
182
+ return confirm(this.i18n.proceedWithUnappliedChanges);
183
+ }
174
184
  }
175
185
  }
@@ -52,6 +52,22 @@ module Netzke
52
52
  # Note, that the root record can be hidden from the tree by specifying the `Ext.tree.Panel`'s `root_visible`
53
53
  # config option set to `false`, which is probably what you want when you have multiple root records.
54
54
  #
55
+ # [scope]
56
+ #
57
+ # Specifies how the records should be scoped.
58
+ #
59
+ # When it's a symbol, it's used as a scope name.
60
+ # When it's a string, it's a SQL statement (passed directly to +where+).
61
+ # When it's a hash, it's a conditions hash (passed directly to +where+).
62
+ # When it's an array, it's expanded into an SQL statement with arguments (passed directly to +where+), e.g.:
63
+ #
64
+ # scope: ["id > ?", 100])
65
+ #
66
+ # When it's a Proc, it gets the current relation passed as the only parameter and is expected to return a
67
+ # relation, e.g.:
68
+ #
69
+ # scope: ->(relation) { relation.where(user_id: 100) }
70
+ #
55
71
  # == Persisting nodes' expand/collapse state
56
72
  #
57
73
  # If the model includes the `expanded` DB field, the expand/collapse state will get stored in the DB.
@@ -90,9 +106,9 @@ module Netzke
90
106
 
91
107
  def get_records(params)
92
108
  if params[:id] == 'root'
93
- data_adapter.find_root_records
109
+ data_adapter.find_root_records(config[:scope])
94
110
  else
95
- data_adapter.find_record_children(data_adapter.find_record(params[:id]))
111
+ data_adapter.find_record_children(data_adapter.find_record(params[:id]), config[:scope])
96
112
  end
97
113
  end
98
114
 
@@ -108,7 +124,7 @@ module Netzke
108
124
  def node_to_hash(record, columns)
109
125
  data_adapter.record_to_hash(record, columns).tap do |hash|
110
126
  if is_node_expanded?(record)
111
- hash["children"] = record.children.map {|child| node_to_hash(child, columns).netzke_literalize_keys}
127
+ hash["children"] = record.children.extend_with(config.scope).map {|child| node_to_hash(child, columns).netzke_literalize_keys}
112
128
  end
113
129
  end
114
130
  end
@@ -243,6 +259,11 @@ module Netzke
243
259
  c.rows_per_page = 30 if c.rows_per_page.nil?
244
260
  c.tools = %w{ refresh } if c.tools.nil?
245
261
  end
262
+
263
+ def self.server_side_config_options
264
+ super + [:scope]
265
+ end
266
+
246
267
  end
247
268
  end
248
269
  end
@@ -1,5 +1,5 @@
1
1
  module Netzke
2
2
  module Basepack
3
- VERSION = "0.12.8"
3
+ VERSION = "0.12.9"
4
4
  end
5
5
  end
data/locales/en.yml CHANGED
@@ -47,6 +47,7 @@ en:
47
47
 
48
48
  confirmation: Confirmation
49
49
  are_you_sure: Are you sure?
50
+ proceed_with_unapplied_changes: You will lose uncommitted changes - do you want to proceed?
50
51
 
51
52
  record_form_window:
52
53
  actions:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netzke-basepack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.8
4
+ version: 0.12.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-11 00:00:00.000000000 Z
12
+ date: 2015-12-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: netzke-core