netzke-core 0.6.7 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +36 -1
- data/{README.markdown → README.md} +17 -15
- data/Rakefile +1 -1
- data/TODO +4 -4
- data/app/controllers/netzke_controller.rb +8 -3
- data/javascripts/base.js +71 -68
- data/javascripts/ext.js +182 -111
- data/lib/netzke/actions.rb +2 -1
- data/lib/netzke/base.rb +5 -1
- data/lib/netzke/composition.rb +2 -2
- data/lib/netzke/configuration.rb +1 -1
- data/lib/netzke/core/dynamic_assets.rb +7 -7
- data/lib/netzke/core/session.rb +4 -0
- data/lib/netzke/core/version.rb +2 -2
- data/lib/netzke/core.rb +23 -30
- data/lib/netzke/core_ext/symbol.rb +1 -1
- data/lib/netzke/embedding.rb +1 -1
- data/lib/netzke/ext_component.rb +2 -2
- data/lib/netzke/javascript.rb +70 -39
- data/lib/netzke/plugin.rb +15 -0
- data/lib/netzke/plugins.rb +29 -0
- data/lib/netzke/railz/action_view_ext/ext.rb +13 -16
- data/lib/netzke/railz/action_view_ext/touch.rb +3 -3
- data/lib/netzke/railz/action_view_ext.rb +0 -3
- data/lib/netzke/railz/engine.rb +34 -29
- data/lib/netzke/services.rb +1 -1
- data/lib/netzke/state.rb +2 -2
- data/lib/netzke-core.rb +1 -0
- data/netzke-core.gemspec +108 -9
- data/stylesheets/core.css +25 -5
- data/test/rails_app/Gemfile +1 -1
- data/test/rails_app/Gemfile.lock +37 -36
- data/test/rails_app/app/components/component_loader.rb +36 -24
- data/test/rails_app/app/components/component_with_js_mixin/javascripts/component_with_js_mixin.js +5 -0
- data/test/rails_app/app/components/component_with_js_mixin.rb +3 -1
- data/test/rails_app/app/components/component_with_nested_through.rb +28 -0
- data/test/rails_app/app/components/component_with_session_persistence.rb +7 -5
- data/test/rails_app/app/components/dynamic_tab_panel/javascripts/dynamic_tab_panel.js +9 -0
- data/test/rails_app/app/components/dynamic_tab_panel.rb +19 -0
- data/test/rails_app/app/components/extended_server_caller.rb +6 -5
- data/test/rails_app/app/components/loader_of_component_with_custom_css.rb +7 -8
- data/test/rails_app/app/components/localized_panel.rb +10 -1
- data/test/rails_app/app/components/nested_component.rb +18 -0
- data/test/rails_app/app/components/panel_with_plugin.rb +4 -0
- data/test/rails_app/app/components/panel_with_tools.rb +19 -0
- data/test/rails_app/app/components/plugin_with_components.rb +14 -0
- data/test/rails_app/app/components/server_caller.rb +1 -1
- data/test/rails_app/app/components/server_counter.rb +1 -1
- data/test/rails_app/app/components/simple_component.rb +2 -0
- data/test/rails_app/app/components/simple_tab_panel.rb +21 -21
- data/test/rails_app/app/components/simple_window.rb +1 -1
- data/test/rails_app/app/components/some_composite.rb +3 -2
- data/test/rails_app/app/components/some_plugin.rb +39 -0
- data/test/rails_app/app/controllers/application_controller.rb +1 -1
- data/test/rails_app/app/controllers/components_controller.rb +1 -1
- data/test/rails_app/app/views/layouts/touch.html.erb +1 -1
- data/test/rails_app/config/application.rb +0 -2
- data/test/rails_app/config/initializers/netzke.rb +2 -1
- data/test/rails_app/config/locales/es.yml +1 -0
- data/test/rails_app/features/{actions.feature → actions_and_tools.feature} +8 -0
- data/test/rails_app/features/client-server.feature +0 -1
- data/test/rails_app/features/complex_component.feature +1 -1
- data/test/rails_app/features/component_loader.feature +7 -0
- data/test/rails_app/features/composition.feature +2 -2
- data/test/rails_app/features/custom_css.feature +1 -1
- data/test/rails_app/features/i18n.feature +3 -0
- data/test/rails_app/features/js_include.feature +2 -0
- data/test/rails_app/features/nested_views.feature +5 -4
- data/test/rails_app/features/plugin.feature +16 -0
- data/test/rails_app/features/step_definitions/generic_steps.rb +21 -2
- data/test/rails_app/features/touch.feature +10 -10
- data/test/rails_app/spec/component/component_spec.rb +20 -0
- metadata +106 -10
- data/app/models/netzke_preference.rb +0 -170
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: netzke-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.7.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Sergei Kozlov
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-08-
|
13
|
+
date: 2011-08-09 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -19,9 +19,9 @@ dependencies:
|
|
19
19
|
requirement: &id001 !ruby/object:Gem::Requirement
|
20
20
|
none: false
|
21
21
|
requirements:
|
22
|
-
- -
|
22
|
+
- - ~>
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: 3.0.
|
24
|
+
version: 3.0.0
|
25
25
|
type: :runtime
|
26
26
|
version_requirements: *id001
|
27
27
|
description: Allows building ExtJS/Rails reusable code in a DRY way
|
@@ -32,18 +32,17 @@ extensions: []
|
|
32
32
|
|
33
33
|
extra_rdoc_files:
|
34
34
|
- LICENSE
|
35
|
-
- README.
|
35
|
+
- README.md
|
36
36
|
- TODO
|
37
37
|
files:
|
38
38
|
- .autotest
|
39
39
|
- CHANGELOG.rdoc
|
40
40
|
- LICENSE
|
41
41
|
- Manifest
|
42
|
-
- README.
|
42
|
+
- README.md
|
43
43
|
- Rakefile
|
44
44
|
- TODO
|
45
45
|
- app/controllers/netzke_controller.rb
|
46
|
-
- app/models/netzke_preference.rb
|
47
46
|
- config/database.yml
|
48
47
|
- init.rb
|
49
48
|
- install.rb
|
@@ -73,6 +72,8 @@ files:
|
|
73
72
|
- lib/netzke/inheritance.rb
|
74
73
|
- lib/netzke/javascript.rb
|
75
74
|
- lib/netzke/javascript/scopes.rb
|
75
|
+
- lib/netzke/plugin.rb
|
76
|
+
- lib/netzke/plugins.rb
|
76
77
|
- lib/netzke/railz.rb
|
77
78
|
- lib/netzke/railz/action_view_ext.rb
|
78
79
|
- lib/netzke/railz/action_view_ext/ext.rb
|
@@ -101,12 +102,16 @@ files:
|
|
101
102
|
- test/rails_app/app/components/component_with_custom_css/stylesheets/custom.css
|
102
103
|
- test/rails_app/app/components/component_with_included_js.rb
|
103
104
|
- test/rails_app/app/components/component_with_js_mixin.rb
|
105
|
+
- test/rails_app/app/components/component_with_js_mixin/javascripts/component_with_js_mixin.js
|
104
106
|
- test/rails_app/app/components/component_with_js_mixin/javascripts/extra_one.js
|
105
107
|
- test/rails_app/app/components/component_with_js_mixin/javascripts/extra_two.js
|
106
108
|
- test/rails_app/app/components/component_with_js_mixin/javascripts/method_set_one.js
|
107
109
|
- test/rails_app/app/components/component_with_js_mixin/javascripts/method_set_two.js
|
110
|
+
- test/rails_app/app/components/component_with_nested_through.rb
|
108
111
|
- test/rails_app/app/components/component_with_session_persistence.rb
|
109
112
|
- test/rails_app/app/components/deprecated/server_caller.rb
|
113
|
+
- test/rails_app/app/components/dynamic_tab_panel.rb
|
114
|
+
- test/rails_app/app/components/dynamic_tab_panel/javascripts/dynamic_tab_panel.js
|
110
115
|
- test/rails_app/app/components/ext_direct/composite.rb
|
111
116
|
- test/rails_app/app/components/ext_direct/details.rb
|
112
117
|
- test/rails_app/app/components/ext_direct/selector.rb
|
@@ -123,6 +128,10 @@ files:
|
|
123
128
|
- test/rails_app/app/components/kinda_complex_component/extra_stuff.rb
|
124
129
|
- test/rails_app/app/components/loader_of_component_with_custom_css.rb
|
125
130
|
- test/rails_app/app/components/localized_panel.rb
|
131
|
+
- test/rails_app/app/components/nested_component.rb
|
132
|
+
- test/rails_app/app/components/panel_with_plugin.rb
|
133
|
+
- test/rails_app/app/components/panel_with_tools.rb
|
134
|
+
- test/rails_app/app/components/plugin_with_components.rb
|
126
135
|
- test/rails_app/app/components/scoped_components/deep_scoped_components/some_deep_scoped_component.rb
|
127
136
|
- test/rails_app/app/components/scoped_components/extended_scoped_component.rb
|
128
137
|
- test/rails_app/app/components/scoped_components/some_scoped_component.rb
|
@@ -134,6 +143,7 @@ files:
|
|
134
143
|
- test/rails_app/app/components/simple_window.rb
|
135
144
|
- test/rails_app/app/components/some_composite.rb
|
136
145
|
- test/rails_app/app/components/some_ext_component.rb
|
146
|
+
- test/rails_app/app/components/some_plugin.rb
|
137
147
|
- test/rails_app/app/components/touch/hello_world_component.rb
|
138
148
|
- test/rails_app/app/components/touch/server_caller.rb
|
139
149
|
- test/rails_app/app/components/touch/simple_carousel.rb
|
@@ -171,7 +181,7 @@ files:
|
|
171
181
|
- test/rails_app/db/migrate/20110110132720_create_netzke_component_states.rb
|
172
182
|
- test/rails_app/db/schema.rb
|
173
183
|
- test/rails_app/db/seeds.rb
|
174
|
-
- test/rails_app/features/
|
184
|
+
- test/rails_app/features/actions_and_tools.feature
|
175
185
|
- test/rails_app/features/basic.feature
|
176
186
|
- test/rails_app/features/client-server.feature
|
177
187
|
- test/rails_app/features/complex_component.feature
|
@@ -186,6 +196,7 @@ files:
|
|
186
196
|
- test/rails_app/features/js_include.feature
|
187
197
|
- test/rails_app/features/nested_views.feature
|
188
198
|
- test/rails_app/features/persistence.feature
|
199
|
+
- test/rails_app/features/plugin.feature
|
189
200
|
- test/rails_app/features/scopes.feature
|
190
201
|
- test/rails_app/features/step_definitions/custom_css_steps.rb
|
191
202
|
- test/rails_app/features/step_definitions/generic_steps.rb
|
@@ -204,6 +215,7 @@ files:
|
|
204
215
|
- test/rails_app/script/rails
|
205
216
|
- test/rails_app/spec/component/actions_spec.rb
|
206
217
|
- test/rails_app/spec/component/base_spec.rb
|
218
|
+
- test/rails_app/spec/component/component_spec.rb
|
207
219
|
- test/rails_app/spec/component/composition_spec.rb
|
208
220
|
- test/rails_app/spec/component/configuration_spec.rb
|
209
221
|
- test/rails_app/spec/component/javascript_spec.rb
|
@@ -247,5 +259,89 @@ rubygems_version: 1.6.2
|
|
247
259
|
signing_key:
|
248
260
|
specification_version: 3
|
249
261
|
summary: Build ExtJS/Rails components with minimum effort
|
250
|
-
test_files:
|
251
|
-
|
262
|
+
test_files:
|
263
|
+
- test/rails_app/app/components/border_layout_panel.rb
|
264
|
+
- test/rails_app/app/components/component_loader.rb
|
265
|
+
- test/rails_app/app/components/component_with_actions.rb
|
266
|
+
- test/rails_app/app/components/component_with_custom_css.rb
|
267
|
+
- test/rails_app/app/components/component_with_included_js.rb
|
268
|
+
- test/rails_app/app/components/component_with_js_mixin.rb
|
269
|
+
- test/rails_app/app/components/component_with_nested_through.rb
|
270
|
+
- test/rails_app/app/components/component_with_session_persistence.rb
|
271
|
+
- test/rails_app/app/components/deprecated/server_caller.rb
|
272
|
+
- test/rails_app/app/components/dynamic_tab_panel.rb
|
273
|
+
- test/rails_app/app/components/ext_direct/composite.rb
|
274
|
+
- test/rails_app/app/components/ext_direct/details.rb
|
275
|
+
- test/rails_app/app/components/ext_direct/selector.rb
|
276
|
+
- test/rails_app/app/components/ext_direct/statistics.rb
|
277
|
+
- test/rails_app/app/components/extended_component_with_actions.rb
|
278
|
+
- test/rails_app/app/components/extended_component_with_js_mixin.rb
|
279
|
+
- test/rails_app/app/components/extended_localized_panel.rb
|
280
|
+
- test/rails_app/app/components/extended_server_caller.rb
|
281
|
+
- test/rails_app/app/components/hello_world_component.rb
|
282
|
+
- test/rails_app/app/components/kinda_complex_component.rb
|
283
|
+
- test/rails_app/app/components/kinda_complex_component/basic_stuff.rb
|
284
|
+
- test/rails_app/app/components/kinda_complex_component/extra_stuff.rb
|
285
|
+
- test/rails_app/app/components/loader_of_component_with_custom_css.rb
|
286
|
+
- test/rails_app/app/components/localized_panel.rb
|
287
|
+
- test/rails_app/app/components/nested_component.rb
|
288
|
+
- test/rails_app/app/components/panel_with_plugin.rb
|
289
|
+
- test/rails_app/app/components/panel_with_tools.rb
|
290
|
+
- test/rails_app/app/components/plugin_with_components.rb
|
291
|
+
- test/rails_app/app/components/scoped_components/deep_scoped_components/some_deep_scoped_component.rb
|
292
|
+
- test/rails_app/app/components/scoped_components/extended_scoped_component.rb
|
293
|
+
- test/rails_app/app/components/scoped_components/some_scoped_component.rb
|
294
|
+
- test/rails_app/app/components/server_caller.rb
|
295
|
+
- test/rails_app/app/components/server_counter.rb
|
296
|
+
- test/rails_app/app/components/simple_component.rb
|
297
|
+
- test/rails_app/app/components/simple_panel.rb
|
298
|
+
- test/rails_app/app/components/simple_tab_panel.rb
|
299
|
+
- test/rails_app/app/components/simple_window.rb
|
300
|
+
- test/rails_app/app/components/some_composite.rb
|
301
|
+
- test/rails_app/app/components/some_ext_component.rb
|
302
|
+
- test/rails_app/app/components/some_plugin.rb
|
303
|
+
- test/rails_app/app/components/touch/hello_world_component.rb
|
304
|
+
- test/rails_app/app/components/touch/server_caller.rb
|
305
|
+
- test/rails_app/app/components/touch/simple_carousel.rb
|
306
|
+
- test/rails_app/app/controllers/application_controller.rb
|
307
|
+
- test/rails_app/app/controllers/components_controller.rb
|
308
|
+
- test/rails_app/app/controllers/multiple_components_controller.rb
|
309
|
+
- test/rails_app/app/controllers/touch_controller.rb
|
310
|
+
- test/rails_app/app/controllers/welcome_controller.rb
|
311
|
+
- test/rails_app/app/helpers/application_helper.rb
|
312
|
+
- test/rails_app/app/helpers/touch_helper.rb
|
313
|
+
- test/rails_app/config/application.rb
|
314
|
+
- test/rails_app/config/boot.rb
|
315
|
+
- test/rails_app/config/environment.rb
|
316
|
+
- test/rails_app/config/environments/development.rb
|
317
|
+
- test/rails_app/config/environments/production.rb
|
318
|
+
- test/rails_app/config/environments/test.rb
|
319
|
+
- test/rails_app/config/initializers/backtrace_silencers.rb
|
320
|
+
- test/rails_app/config/initializers/inflections.rb
|
321
|
+
- test/rails_app/config/initializers/mime_types.rb
|
322
|
+
- test/rails_app/config/initializers/netzke.rb
|
323
|
+
- test/rails_app/config/initializers/secret_token.rb
|
324
|
+
- test/rails_app/config/initializers/session_store.rb
|
325
|
+
- test/rails_app/config/routes.rb
|
326
|
+
- test/rails_app/db/migrate/20110110132720_create_netzke_component_states.rb
|
327
|
+
- test/rails_app/db/schema.rb
|
328
|
+
- test/rails_app/db/seeds.rb
|
329
|
+
- test/rails_app/features/step_definitions/custom_css_steps.rb
|
330
|
+
- test/rails_app/features/step_definitions/generic_steps.rb
|
331
|
+
- test/rails_app/features/step_definitions/touch_steps.rb
|
332
|
+
- test/rails_app/features/step_definitions/web_steps.rb
|
333
|
+
- test/rails_app/features/support/env.rb
|
334
|
+
- test/rails_app/features/support/paths.rb
|
335
|
+
- test/rails_app/spec/component/actions_spec.rb
|
336
|
+
- test/rails_app/spec/component/base_spec.rb
|
337
|
+
- test/rails_app/spec/component/component_spec.rb
|
338
|
+
- test/rails_app/spec/component/composition_spec.rb
|
339
|
+
- test/rails_app/spec/component/configuration_spec.rb
|
340
|
+
- test/rails_app/spec/component/javascript_spec.rb
|
341
|
+
- test/rails_app/spec/component/state_spec.rb
|
342
|
+
- test/rails_app/spec/core_ext_spec.rb
|
343
|
+
- test/rails_app/spec/spec_helper.rb
|
344
|
+
- test/test_helper.rb
|
345
|
+
- test/unit/core_ext_test.rb
|
346
|
+
- test/unit/netzke_core_test.rb
|
347
|
+
- test/unit/netzke_preference_test.rb
|
@@ -1,170 +0,0 @@
|
|
1
|
-
class NetzkePreference < ActiveRecord::Base
|
2
|
-
serialize :value
|
3
|
-
|
4
|
-
# belongs_to :user
|
5
|
-
# belongs_to :role
|
6
|
-
|
7
|
-
# ELEMENTARY_CONVERTION_METHODS= {'Fixnum' => 'to_i', 'String' => 'to_s', 'Float' => 'to_f', 'Symbol' => 'to_sym'}
|
8
|
-
|
9
|
-
# def self.component_name=(value)
|
10
|
-
# @@component_name = value
|
11
|
-
# end
|
12
|
-
#
|
13
|
-
# def self.component_name
|
14
|
-
# @@component_name ||= nil
|
15
|
-
# end
|
16
|
-
|
17
|
-
# def normalized_value
|
18
|
-
# klass = read_attribute(:pref_type)
|
19
|
-
# norm_value = read_attribute(:value)
|
20
|
-
#
|
21
|
-
# case klass
|
22
|
-
# when nil then r = norm_value # do not cast
|
23
|
-
# when 'Boolean' then r = norm_value == 'false' ? false : (norm_value == 'true' || norm_value)
|
24
|
-
# when 'NilClass' then r = nil
|
25
|
-
# when 'Array', 'Hash' then r = ActiveSupport::JSON.decode(norm_value)
|
26
|
-
# else
|
27
|
-
# r = norm_value.send(ELEMENTARY_CONVERTION_METHODS[klass])
|
28
|
-
# end
|
29
|
-
# r
|
30
|
-
# end
|
31
|
-
#
|
32
|
-
# def normalized_value=(new_value)
|
33
|
-
# case new_value.class.name
|
34
|
-
# when "Array" then write_attribute(:value, new_value.to_json)
|
35
|
-
# when "Hash" then write_attribute(:value, new_value.to_json)
|
36
|
-
# else write_attribute(:value, new_value.to_s)
|
37
|
-
# end
|
38
|
-
# write_attribute(:pref_type, [TrueClass, FalseClass].include?(new_value.class) ? 'Boolean' : new_value.class.to_s)
|
39
|
-
# end
|
40
|
-
#
|
41
|
-
# def self.[](pref_name)
|
42
|
-
# pref_name = normalize_preference_name(pref_name)
|
43
|
-
# pref = self.pref_to_read(pref_name)
|
44
|
-
# pref && pref.normalized_value
|
45
|
-
# end
|
46
|
-
#
|
47
|
-
# def self.[]=(pref_name, new_value)
|
48
|
-
# pref_name = normalize_preference_name(pref_name)
|
49
|
-
# pref = self.pref_to_write(pref_name)
|
50
|
-
#
|
51
|
-
# # if assigning nil, simply delete the eventually found preference
|
52
|
-
# if new_value.nil?
|
53
|
-
# pref && pref.destroy
|
54
|
-
# else
|
55
|
-
# # pref ||= self.new(conditions(pref_name))
|
56
|
-
# pref.normalized_value = new_value
|
57
|
-
# pref.save!
|
58
|
-
# end
|
59
|
-
# end
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
# Overwrite pref_to_read, pref_to_write methods, and find_all_for_component if you want a different way of
|
64
|
-
# identifying the proper preference based on your own authorization strategy.
|
65
|
-
#
|
66
|
-
# The default strategy is:
|
67
|
-
# 1) if no masq_user or masq_role defined
|
68
|
-
# pref_to_read will search for the preference for user first, then for user's role
|
69
|
-
# pref_to_write will always find or create a preference for the current user (never for its role)
|
70
|
-
# 2) if masq_user or masq_role is defined
|
71
|
-
# pref_to_read and pref_to_write will always take the masquerade into account, e.g. reads/writes will go to
|
72
|
-
# the user/role specified
|
73
|
-
#
|
74
|
-
def self.pref_to_read(name)
|
75
|
-
name = name.to_s
|
76
|
-
session = Netzke::Core.session
|
77
|
-
cond = {:key => name}
|
78
|
-
|
79
|
-
if session[:masq_user]
|
80
|
-
# first, get the prefs for this user it they exist
|
81
|
-
res = self.where(cond.merge({:user_id => session[:masq_user]})).first
|
82
|
-
|
83
|
-
# if it doesn't exist, get them for the user's role
|
84
|
-
user = User.where(session[:masq_user])
|
85
|
-
res ||= self.where(cond.merge({:role_id => user.role.id})).first
|
86
|
-
|
87
|
-
# if it doesn't exist either, get them for the World (role_id = 0)
|
88
|
-
res ||= self.where(cond.merge({:role_id => 0})).first
|
89
|
-
elsif session[:masq_role]
|
90
|
-
# first, get the prefs for this role
|
91
|
-
res = self.where(cond.merge({:role_id => session[:masq_role]})).first
|
92
|
-
# if it doesn't exist, get them for the World (role_id = 0)
|
93
|
-
res ||= self.where(cond.merge({:role_id => 0})).first
|
94
|
-
elsif session[:netzke_user_id]
|
95
|
-
user = User.where(session[:netzke_user_id])
|
96
|
-
# first, get the prefs for this user
|
97
|
-
res = self.where(cond.merge({:user_id => user.id})).first
|
98
|
-
# if it doesn't exist, get them for the user's role
|
99
|
-
res ||= self.where(cond.merge({:role_id => user.role.id})).first
|
100
|
-
# if it doesn't exist either, get them for the World (role_id = 0)
|
101
|
-
res ||= self.where(cond.merge({:role_id => 0})).first
|
102
|
-
else
|
103
|
-
res = self.where(cond).first
|
104
|
-
end
|
105
|
-
|
106
|
-
res
|
107
|
-
end
|
108
|
-
|
109
|
-
def self.pref_to_write(name)
|
110
|
-
name = name.to_s
|
111
|
-
session = Netzke::Core.session
|
112
|
-
cond = {:key => name}
|
113
|
-
|
114
|
-
if session[:masq_user]
|
115
|
-
cond.merge!({:user_id => session[:masq_user]})
|
116
|
-
# first, try to find the preference for masq_user
|
117
|
-
res = self.where(cond).first
|
118
|
-
# if it doesn't exist, create it
|
119
|
-
res ||= self.new(cond)
|
120
|
-
elsif session[:masq_role]
|
121
|
-
# first, delete all the corresponding preferences for the users that have this role
|
122
|
-
Role.where(session[:masq_role]).users.each do |u|
|
123
|
-
self.delete_all(cond.merge({:user_id => u.id}))
|
124
|
-
end
|
125
|
-
cond.merge!({:role_id => session[:masq_role]})
|
126
|
-
res = self.where(cond).first
|
127
|
-
res ||= self.new(cond)
|
128
|
-
elsif session[:masq_world]
|
129
|
-
# first, delete all the corresponding preferences for all users and roles
|
130
|
-
self.delete_all(cond)
|
131
|
-
# then, create the new preference for the World (role_id = 0)
|
132
|
-
res = self.new(cond.merge(:role_id => 0))
|
133
|
-
elsif session[:netzke_user_id]
|
134
|
-
res = self.where(cond.merge({:user_id => session[:netzke_user_id]})).first
|
135
|
-
res ||= self.new(cond.merge({:user_id => session[:netzke_user_id]}))
|
136
|
-
else
|
137
|
-
res = self.where(cond).first
|
138
|
-
res ||= self.new(cond)
|
139
|
-
end
|
140
|
-
res
|
141
|
-
end
|
142
|
-
|
143
|
-
# def self.find_all_for_component(name)
|
144
|
-
# session = Netzke::Core.session
|
145
|
-
# cond = {:component_name => name}
|
146
|
-
#
|
147
|
-
# if session[:masq_user] || session[:masq_role]
|
148
|
-
# cond.merge!({:user_id => session[:masq_user], :role_id => session[:masq_role]})
|
149
|
-
# res = self.where(cond).all
|
150
|
-
# elsif session[:netzke_user_id]
|
151
|
-
# user = User.where(session[:netzke_user_id])
|
152
|
-
# res = self.where(cond.merge({:user_id => session[:netzke_user_id]})).all
|
153
|
-
# res += self.where(cond.merge({:role_id => user.role.try(:id)})).all
|
154
|
-
# else
|
155
|
-
# res = self.where(cond).all
|
156
|
-
# end
|
157
|
-
#
|
158
|
-
# res
|
159
|
-
# end
|
160
|
-
|
161
|
-
# def self.delete_all_for_component(name)
|
162
|
-
# self.destroy(find_all_for_component(name))
|
163
|
-
# end
|
164
|
-
#
|
165
|
-
# private
|
166
|
-
# def self.normalize_preference_name(name)
|
167
|
-
# name.to_s.gsub(".", "__").gsub("/", "__")
|
168
|
-
# end
|
169
|
-
|
170
|
-
end
|