netzke-core 0.8.3 → 0.8.4
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile +1 -0
- data/README.md +9 -3
- data/javascripts/base.js +15 -8
- data/javascripts/ext.js +145 -70
- data/lib/netzke/base.rb +33 -10
- data/lib/netzke/core.rb +1 -0
- data/lib/netzke/core/action_config.rb +3 -3
- data/lib/netzke/core/actions.rb +34 -2
- data/lib/netzke/core/component_config.rb +3 -2
- data/lib/netzke/core/composition.rb +19 -36
- data/lib/netzke/core/configuration.rb +1 -3
- data/lib/netzke/core/dsl_config_base.rb +9 -0
- data/lib/netzke/core/dsl_support.rb +6 -6
- data/lib/netzke/core/javascript.rb +11 -5
- data/lib/netzke/core/railz/controller_extensions.rb +56 -28
- data/lib/netzke/core/services.rb +20 -6
- data/lib/netzke/core/version.rb +1 -1
- data/test/core_test_app/app/components/actions.rb +2 -0
- data/test/core_test_app/app/components/composition.rb +1 -0
- data/test/core_test_app/app/components/dynamic_loading.rb +7 -11
- data/test/core_test_app/app/components/dynamic_loading/javascripts/dynamic_loading.js +1 -1
- data/test/core_test_app/app/components/endpoints.rb +15 -1
- data/test/core_test_app/app/components/endpoints/javascripts/endpoints.js +6 -2
- data/test/core_test_app/app/components/hello_user.rb +12 -0
- data/test/core_test_app/app/components/hello_world/javascripts/hello_world.js +1 -1
- data/test/core_test_app/app/components/multi_instance_loading.rb +18 -0
- data/test/core_test_app/app/components/multi_instance_loading/javascripts/multi_instance_loading.js +18 -0
- data/test/core_test_app/app/components/persistence.rb +1 -1
- data/test/core_test_app/app/components/session_expiration.rb +21 -0
- data/test/core_test_app/app/components/simple_component.rb +1 -1
- data/test/core_test_app/config/initializers/javascripts/session_expiration.js +6 -0
- data/test/core_test_app/config/initializers/netzke.rb +3 -1
- data/test/core_test_app/log/development.log +46574 -0
- data/test/core_test_app/log/test.log +67624 -0
- data/test/core_test_app/tmp/cache/assets/C92/5A0/sprockets%2F39e75754782ee12179bf35c9a0971d80 +0 -0
- data/test/core_test_app/tmp/cache/assets/C9F/750/sprockets%2F20ce3d64040a5d3a0a8883bd60754356 +0 -0
- data/test/core_test_app/tmp/cache/assets/CC4/C00/sprockets%2Fc615df52887d8c2e67e8413576a419c5 +0 -0
- data/test/core_test_app/tmp/cache/assets/D0E/870/sprockets%2Fa593bf4fac106add88c9434141a49663 +0 -0
- data/test/core_test_app/tmp/cache/assets/D14/8E0/sprockets%2F20748e8d1d7d090d122904a9fe6f18fc +0 -0
- data/test/core_test_app/tmp/cache/assets/D3E/DA0/sprockets%2Fa175f1ac5996544b908ba3ba3f64c4f3 +0 -0
- data/test/core_test_app/tmp/cache/assets/D43/C00/sprockets%2F7bc60c758776356d615ab5edff201ee2 +0 -0
- data/test/core_test_app/tmp/cache/assets/D98/9C0/sprockets%2F18b80e8fe200aebc522e561a867ea6fb +0 -0
- data/test/core_test_app/tmp/cache/assets/DB0/6E0/sprockets%2F03e33f5a4779eeb48bcfc86ee717fb55 +0 -0
- metadata +13 -2
data/lib/netzke/base.rb
CHANGED
@@ -58,7 +58,7 @@ module Netzke
|
|
58
58
|
include Core::Actions
|
59
59
|
include Core::Html if const_defined? :Haml
|
60
60
|
|
61
|
-
#
|
61
|
+
# TODO: get rid of it
|
62
62
|
class_attribute :default_instance_config
|
63
63
|
self.default_instance_config = {}
|
64
64
|
|
@@ -70,12 +70,18 @@ module Netzke
|
|
70
70
|
# Parent component
|
71
71
|
attr_reader :parent
|
72
72
|
|
73
|
-
# Name that the parent can reference us by
|
73
|
+
# Name that the parent can reference us by
|
74
74
|
attr_reader :name
|
75
75
|
|
76
|
-
# Global id in the
|
76
|
+
# Global id in the component tree, following the double-underscore notation, e.g. +books__config_panel__form+
|
77
77
|
attr_reader :js_id
|
78
78
|
|
79
|
+
# JS id in the context of the parent
|
80
|
+
attr_reader :item_id
|
81
|
+
|
82
|
+
# Component's path in the component tree
|
83
|
+
attr_reader :path
|
84
|
+
|
79
85
|
class << self
|
80
86
|
# Instance of component by config
|
81
87
|
def instance_by_config(config)
|
@@ -109,11 +115,29 @@ module Netzke
|
|
109
115
|
|
110
116
|
# Instantiates a component instance. A parent can optionally be provided.
|
111
117
|
def initialize(conf = {}, parent = nil)
|
112
|
-
@passed_config = conf
|
113
|
-
|
114
|
-
|
115
|
-
@
|
116
|
-
|
118
|
+
@passed_config = conf
|
119
|
+
|
120
|
+
# parent component
|
121
|
+
@parent = parent
|
122
|
+
|
123
|
+
# name fo the component used in the +component+ DSL block, and is a part of component's +@path+
|
124
|
+
@name = conf[:name] || self.class.name.underscore
|
125
|
+
|
126
|
+
# path down the composition hierarchy (composed of names)
|
127
|
+
@path = parent.nil? ? @name : "#{parent.path}__#{@name}"
|
128
|
+
|
129
|
+
# JS id in the scope of the parent component. Auto-generated when using multiple instance loading.
|
130
|
+
# Full JS id will be built using these along the +@path+
|
131
|
+
@item_id = conf[:item_id] || @name
|
132
|
+
|
133
|
+
# JS full ID. Similar to +path+, but composed of item_id's. Differs from @path when multiple instances are being loaded.
|
134
|
+
@js_id = parent.nil? ? @item_id : [parent.js_id, @item_id].join("__")
|
135
|
+
|
136
|
+
# TODO: get rid of this in 0.9
|
137
|
+
@flash = []
|
138
|
+
|
139
|
+
# Make +client_config+ accessible in +configure+ before calling +super+
|
140
|
+
config.client_config = conf.delete(:client_config) || {}
|
117
141
|
|
118
142
|
# Build complete component configuration
|
119
143
|
configure(config)
|
@@ -125,8 +149,7 @@ module Netzke
|
|
125
149
|
|
126
150
|
private
|
127
151
|
|
128
|
-
# TODO:
|
129
|
-
# TODO: rename to smth more appropriate
|
152
|
+
# TODO: get rid of this in 0.9
|
130
153
|
def flash(flash_hash)
|
131
154
|
level = flash_hash.keys.first
|
132
155
|
raise "Unknown message level for flash" unless %(notice warning error).include?(level.to_s)
|
data/lib/netzke/core.rb
CHANGED
@@ -15,6 +15,7 @@ module Netzke
|
|
15
15
|
# * ext_path - absolute path to your Ext code root
|
16
16
|
# * icons_uri - relative URI to the icons
|
17
17
|
module Core
|
18
|
+
autoload :DslConfigBase, 'netzke/core/dsl_config_base'
|
18
19
|
autoload :ComponentConfig, 'netzke/core/component_config'
|
19
20
|
autoload :ActionConfig, 'netzke/core/action_config'
|
20
21
|
autoload :Panel, 'netzke/core/panel'
|
@@ -8,10 +8,10 @@ module Netzke::Core
|
|
8
8
|
# c.icon = :tick
|
9
9
|
# end
|
10
10
|
# end
|
11
|
-
class ActionConfig <
|
11
|
+
class ActionConfig < DslConfigBase
|
12
12
|
def initialize(name, component)
|
13
|
-
|
14
|
-
|
13
|
+
super
|
14
|
+
|
15
15
|
@text = @tooltip = @icon = ""
|
16
16
|
|
17
17
|
build_localized_attributes
|
data/lib/netzke/core/actions.rb
CHANGED
@@ -14,11 +14,18 @@ module Netzke::Core
|
|
14
14
|
#
|
15
15
|
# All config settings for an action are optional. When omitted, the locale files will be consulted first (see "I18n of actions"), falling back to the defaults.
|
16
16
|
#
|
17
|
+
# [+text+]
|
18
|
+
# The text of the action (defaults to humanized action name)
|
17
19
|
# [+icon+]
|
18
20
|
# Can be set to either a String (which will be interpreted as a full URI to the icon file), or as a Symbol, which will be expanded to +Netzke::Core.icons_uri+ + "/(icon).png". Defaults to nil (no icon)
|
21
|
+
# [+tooltip+]
|
22
|
+
# The tooltip of the action (defaults to humanized action name)
|
23
|
+
# [+disabled+]
|
24
|
+
# When set to +true+, renders this action as disabled
|
19
25
|
# [+handler+]
|
20
26
|
# A symbol that represents the JavaScript public method (snake-case), which will be called in the scope of the component instance. Defaults to +on_(action_name)+, which on JavaScript side will result in a call to +on(CamelCaseActionName)+
|
21
|
-
# +
|
27
|
+
# [+excluded+]
|
28
|
+
# When set to true, gets the action excluded from menus and toolbars
|
22
29
|
#
|
23
30
|
# When no block is given, the defaults will be used:
|
24
31
|
#
|
@@ -64,12 +71,37 @@ module Netzke::Core
|
|
64
71
|
# and for its icon in:
|
65
72
|
#
|
66
73
|
# I18n.t('my_components.cool_component.actions.some_action.icon')
|
74
|
+
#
|
75
|
+
# == Using actions
|
76
|
+
#
|
77
|
+
# Actions can be refferred to in the component configuration as symbols. The most common use cases are configuring toolbars.
|
78
|
+
# For example, to configure a bottom toolbar to show a button reflecting the +:do_something+ action:
|
79
|
+
#
|
80
|
+
# def configure(c)
|
81
|
+
# super
|
82
|
+
# c.bbar = [:do_something]
|
83
|
+
# end
|
84
|
+
#
|
85
|
+
# Using the +docked_items+ property is also possible:
|
86
|
+
#
|
87
|
+
# def configure(c)
|
88
|
+
# super
|
89
|
+
# c.docked_items = [{
|
90
|
+
# xtype: :toolbar,
|
91
|
+
# dock: :left,
|
92
|
+
# items: [:do_something]
|
93
|
+
# }]
|
94
|
+
# end
|
95
|
+
#
|
96
|
+
# == Interfering with action events in client class
|
97
|
+
#
|
98
|
+
# For each action Netzke creates an event on the level of the parent component following the convention '<action_name>click'. The handler receives the component itself as a parameter. If the handler returns +false+, the action event is not further propagated.
|
67
99
|
module Actions
|
68
100
|
extend ActiveSupport::Concern
|
69
101
|
|
70
102
|
included do
|
71
103
|
# Declares Base.action, for declaring actions, and Base#actions, which returns a [Hash] of all action configs by name
|
72
|
-
declare_dsl_for :actions
|
104
|
+
declare_dsl_for :actions, config_class: Netzke::Core::ActionConfig
|
73
105
|
end
|
74
106
|
|
75
107
|
module ClassMethods
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module Netzke::Core
|
2
|
-
class ComponentConfig <
|
3
|
-
def initialize(name,
|
2
|
+
class ComponentConfig < DslConfigBase
|
3
|
+
def initialize(name, component)
|
4
4
|
self.name = name.to_s
|
5
5
|
end
|
6
6
|
|
7
7
|
def set_defaults!
|
8
8
|
self.item_id ||= name # default item_id
|
9
|
+
self.client_config ||= {}
|
9
10
|
self.klass ||= name.camelize.constantize # default klass
|
10
11
|
end
|
11
12
|
end
|
@@ -81,26 +81,31 @@ module Netzke::Core
|
|
81
81
|
|
82
82
|
included do
|
83
83
|
# Declares Base.component, for declaring child componets, and Base#components, which returns a [Hash] of all component configs by name
|
84
|
-
declare_dsl_for :components
|
84
|
+
declare_dsl_for :components, config_class: Netzke::Core::ComponentConfig
|
85
85
|
|
86
86
|
# Loads a component on browser's request. Every Netzke component gets this endpoint.
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
87
|
+
# +params+ should contain:
|
88
|
+
# [cache] an array of component classes cached at the browser
|
89
|
+
# [name] name of the child component to be loaded
|
90
|
+
# [index] clone index of the loaded component
|
91
91
|
endpoint :deliver_component do |params, this|
|
92
92
|
cache = params[:cache].split(",") # array of cached xtypes
|
93
93
|
component_name = params[:name].underscore.to_sym
|
94
|
-
component = components[component_name] && !components[component_name][:excluded] && component_instance(component_name)
|
95
94
|
|
96
|
-
|
97
|
-
|
95
|
+
item_id = "#{component_name}#{params[:index]}"
|
96
|
+
|
97
|
+
cmp_instance = components[component_name] &&
|
98
|
+
!components[component_name][:excluded] &&
|
99
|
+
component_instance(component_name, {item_id: item_id, client_config: params[:client_config]})
|
100
|
+
|
101
|
+
if cmp_instance
|
102
|
+
js, css = cmp_instance.js_missing_code(cache), cmp_instance.css_missing_code(cache)
|
98
103
|
this.netzke_eval_js(js) if js.present?
|
99
104
|
this.netzke_eval_css(css) if css.present?
|
100
105
|
|
101
|
-
this.netzke_component_delivered(
|
106
|
+
this.netzke_component_delivered(cmp_instance.js_config);
|
102
107
|
else
|
103
|
-
this.netzke_component_delivery_failed(
|
108
|
+
this.netzke_component_delivery_failed(item_id: item_id, msg: "Couldn't load component '#{item_id}'")
|
104
109
|
end
|
105
110
|
end
|
106
111
|
|
@@ -116,20 +121,14 @@ module Netzke::Core
|
|
116
121
|
@components_in_config || (normalize_config || true) && @components_in_config
|
117
122
|
end
|
118
123
|
|
119
|
-
# Called when the method_missing tries to processes a non-existing component. Override when needed.
|
120
|
-
def component_missing(aggr)
|
121
|
-
flash :error => "Unknown component #{aggr} for #{name}"
|
122
|
-
{:feedback => @flash}.netzke_jsonify.to_json
|
123
|
-
end
|
124
|
-
|
125
124
|
# Recursively instantiates a child component based on its "path": e.g. if we have component :component1 which in its turn has component :component2, the path to the latter would be "component1__component2"
|
126
125
|
# @param name [Symbol] component name
|
127
|
-
def component_instance(name)
|
128
|
-
|
129
|
-
@_component_instance[name] ||= name.to_s.split('__').inject(self) do |out, cmp_name|
|
126
|
+
def component_instance(name, strong_config = {})
|
127
|
+
name.to_s.split('__').inject(self) do |out, cmp_name|
|
130
128
|
cmp_config = out.components[cmp_name.to_sym]
|
131
|
-
raise ArgumentError, "No component '#{cmp_name}' defined for '#{out.
|
129
|
+
raise ArgumentError, "No component '#{cmp_name}' defined for '#{out.path}'" if cmp_config.nil? || cmp_config[:excluded]
|
132
130
|
cmp_config[:name] = cmp_name
|
131
|
+
cmp_config.merge!(strong_config)
|
133
132
|
cmp_config[:klass].new(cmp_config, out)
|
134
133
|
end
|
135
134
|
end
|
@@ -146,22 +145,6 @@ module Netzke::Core
|
|
146
145
|
res.uniq
|
147
146
|
end
|
148
147
|
|
149
|
-
# JS id of a component in the hierarchy, based on passed reference that follows the double-underscore notation. Referring to "parent" is allowed. If going to far up the hierarchy will result in <tt>nil</tt>, while referring to a non-existent component will simply provide an erroneous ID.
|
150
|
-
# For example:
|
151
|
-
# <tt>parent__parent__child__subchild</tt> will traverse the hierarchy 2 levels up, then going down to "child", and further to "subchild". If such a component exists in the hierarchy, its global id will be returned, otherwise <tt>nil</tt> will be returned.
|
152
|
-
# @param ref [Symbol] reference to a child component
|
153
|
-
# @return [String] JS id
|
154
|
-
def js_id_by_reference(ref)
|
155
|
-
ref = ref.to_s
|
156
|
-
return parent && parent.js_id if ref == "parent"
|
157
|
-
substr = ref.sub(/^parent__/, "")
|
158
|
-
if substr == ref # there's no "parent__" in the beginning
|
159
|
-
return js_id + "__" + ref
|
160
|
-
else
|
161
|
-
return parent.js_id_by_reference(substr)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
148
|
def extend_item(item)
|
166
149
|
item = detect_and_normalize(:component, item)
|
167
150
|
@components_in_config << item[:netzke_component] if include_component?(item)
|
@@ -47,11 +47,10 @@ module Netzke::Core
|
|
47
47
|
# end
|
48
48
|
# end
|
49
49
|
def configure(c)
|
50
|
-
# passed config
|
51
50
|
c.merge!(@passed_config)
|
52
51
|
end
|
53
52
|
|
54
|
-
# Complete server class
|
53
|
+
# Complete configuration for server class instance. Can be accessed from within endpoint, component, and action blocks, as well as any other instance method, for example:
|
55
54
|
#
|
56
55
|
# action :do_something do |c|
|
57
56
|
# c.title = "Do it for #{config.title}"
|
@@ -60,7 +59,6 @@ module Netzke::Core
|
|
60
59
|
@config ||= ActiveSupport::OrderedOptions.new
|
61
60
|
end
|
62
61
|
|
63
|
-
|
64
62
|
protected
|
65
63
|
|
66
64
|
# During the normalization of config object, +extend_item+ is being called with each item found (recursively) in there.
|
@@ -25,19 +25,19 @@ module Netzke
|
|
25
25
|
# 2) Instance method `components` that returns a hash of all components configs. This hash is built by passing a new instance of `Netzke::Core::ComponentConfig` to each of the methods described in 1). Presence of `Netzke::Core::ComponentConfig` is assumed.
|
26
26
|
#
|
27
27
|
# Besides components, this method is being used in Core for DSL for actions.
|
28
|
-
def declare_dsl_for(things)
|
28
|
+
def declare_dsl_for(things, options = {})
|
29
29
|
things = things.to_s
|
30
30
|
storage_attribute = :"_declared_#{things}"
|
31
31
|
|
32
32
|
class_attribute storage_attribute
|
33
33
|
send("#{storage_attribute}=", [])
|
34
34
|
|
35
|
-
define_dsl_method(things, storage_attribute)
|
36
|
-
define_collector_method(things, storage_attribute)
|
35
|
+
define_dsl_method(things, storage_attribute, options)
|
36
|
+
define_collector_method(things, storage_attribute, options)
|
37
37
|
end
|
38
38
|
|
39
39
|
|
40
|
-
def define_dsl_method(things, storage_attribute)
|
40
|
+
def define_dsl_method(things, storage_attribute, options)
|
41
41
|
thing = things.singularize
|
42
42
|
|
43
43
|
define_singleton_method thing do |name, &block|
|
@@ -47,9 +47,9 @@ module Netzke
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
def define_collector_method(things, storage_attribute)
|
50
|
+
def define_collector_method(things, storage_attribute, options)
|
51
51
|
thing = things.singularize
|
52
|
-
config_class =
|
52
|
+
config_class = options[:config_class] || Netzke::Core::DslConfigBase
|
53
53
|
|
54
54
|
define_method things do
|
55
55
|
# memoization
|
@@ -43,11 +43,8 @@ module Netzke::Core
|
|
43
43
|
def js_configure(c)
|
44
44
|
c.merge!(normalized_config)
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
%w[id netzke_components endpoints xtype alias i18n netzke_plugins flash].each do |thing|
|
50
|
-
js_thing = send "js_#{thing}"
|
46
|
+
%w[id item_id path netzke_components endpoints xtype alias i18n netzke_plugins flash].each do |thing|
|
47
|
+
js_thing = send(:"js_#{thing}")
|
51
48
|
c[thing] = js_thing if js_thing.present?
|
52
49
|
end
|
53
50
|
|
@@ -56,10 +53,18 @@ module Netzke::Core
|
|
56
53
|
component_session.clear
|
57
54
|
end
|
58
55
|
|
56
|
+
def js_path
|
57
|
+
@path
|
58
|
+
end
|
59
|
+
|
59
60
|
def js_xtype
|
60
61
|
self.class.js_config.xtype
|
61
62
|
end
|
62
63
|
|
64
|
+
def js_item_id
|
65
|
+
@item_id
|
66
|
+
end
|
67
|
+
|
63
68
|
# Ext.createByAlias may be used to instantiate the component.
|
64
69
|
def js_alias
|
65
70
|
self.class.js_config.class_alias
|
@@ -74,6 +79,7 @@ module Netzke::Core
|
|
74
79
|
plugins.map{ |p| p.to_s.camelcase(:lower) }
|
75
80
|
end
|
76
81
|
|
82
|
+
# TODO: get rid of this in 0.9
|
77
83
|
def js_flash
|
78
84
|
session && session[:flash]
|
79
85
|
end
|
@@ -2,6 +2,42 @@ module Netzke
|
|
2
2
|
module Railz
|
3
3
|
# Before each request, Netzke::Base.controller and Netzke::Base.session are set, to be accessible from components.
|
4
4
|
module ControllerExtensions
|
5
|
+
class DirectRequest
|
6
|
+
def initialize(params)
|
7
|
+
@params = params
|
8
|
+
end
|
9
|
+
|
10
|
+
def cmp_path
|
11
|
+
@params[:path]
|
12
|
+
end
|
13
|
+
|
14
|
+
def endpoint
|
15
|
+
@params[:endpoint].underscore
|
16
|
+
end
|
17
|
+
|
18
|
+
def args
|
19
|
+
# for backward compatibility, fall back to old data structure (with the endpoint params being in the root of
|
20
|
+
# 'data')
|
21
|
+
remoting_args["configs"] ? remoting_args["args"] : remoting_args
|
22
|
+
end
|
23
|
+
|
24
|
+
def client_configs
|
25
|
+
# if no configs are provided, the behavior is the old one, and thus all instances the same child component
|
26
|
+
# will be treated as one
|
27
|
+
remoting_args["configs"] || []
|
28
|
+
end
|
29
|
+
|
30
|
+
def tid
|
31
|
+
@params[:tid]
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def remoting_args
|
37
|
+
@_remoting_args ||= @params[:data].first
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
5
41
|
extend ActiveSupport::Concern
|
6
42
|
|
7
43
|
included do
|
@@ -20,11 +56,12 @@ module Netzke
|
|
20
56
|
if params['_json'] # this is a batched request
|
21
57
|
response = []
|
22
58
|
params['_json'].each do |batch|
|
23
|
-
|
24
|
-
response << direct_response(
|
59
|
+
direct_request = DirectRequest.new(batch)
|
60
|
+
response << direct_response(direct_request, invoke_endpoint(direct_request))
|
25
61
|
end
|
26
62
|
else # this is a single request
|
27
|
-
|
63
|
+
direct_request = DirectRequest.new(params)
|
64
|
+
response = direct_response(direct_request, invoke_endpoint(direct_request))
|
28
65
|
end
|
29
66
|
|
30
67
|
render text: response.to_json, layout: false
|
@@ -50,44 +87,34 @@ module Netzke
|
|
50
87
|
|
51
88
|
protected
|
52
89
|
|
53
|
-
def direct_response(
|
54
|
-
|
55
|
-
component_name, *sub_components = path.split('__')
|
90
|
+
def direct_response(request, endpoint_response)
|
91
|
+
component_name, *sub_components = request.cmp_path.split('__')
|
56
92
|
|
57
93
|
# We render text/plain, so that the browser never modifies our response
|
58
94
|
response.headers["Content-Type"] = "text/plain; charset=utf-8"
|
59
95
|
|
60
|
-
{ :
|
61
|
-
:
|
62
|
-
:
|
63
|
-
:
|
64
|
-
:
|
96
|
+
{ type: :rpc,
|
97
|
+
tid: request.tid,
|
98
|
+
action: component_name,
|
99
|
+
method: request.endpoint,
|
100
|
+
result: ActiveSupport::JSON::Variable.new(endpoint_response.netzke_jsonify.to_json)
|
65
101
|
}
|
66
102
|
end
|
67
103
|
|
68
|
-
def invoke_endpoint(
|
69
|
-
|
70
|
-
|
71
|
-
component_name, *sub_components = path.split('__')
|
104
|
+
def invoke_endpoint(request)
|
105
|
+
component_name, *sub_components = request.cmp_path.split('__')
|
72
106
|
components_in_session = session[:netzke_components]
|
73
107
|
|
74
108
|
if components_in_session
|
75
|
-
|
76
|
-
|
109
|
+
cmp_config = components_in_session[component_name.to_sym]
|
110
|
+
cmp_config[:client_config] = request.client_configs.shift || {}
|
111
|
+
component_instance = Netzke::Base.instance_by_config(cmp_config)
|
112
|
+
component_instance.invoke_endpoint((sub_components + [request.endpoint]).join("__"), request.args, request.client_configs)
|
77
113
|
else
|
78
|
-
{:
|
114
|
+
{netzke_session_expired: []}
|
79
115
|
end
|
80
116
|
end
|
81
117
|
|
82
|
-
def parse_request_params(params)
|
83
|
-
path = params[:act]
|
84
|
-
action = params[:method].underscore
|
85
|
-
ep_params = params[:data].try(:first) # Rails >= 3.2.11 returns nil in request_params[:data]
|
86
|
-
tid = params[:tid]
|
87
|
-
|
88
|
-
[path, action, ep_params, tid]
|
89
|
-
end
|
90
|
-
|
91
118
|
# The dispatcher for the old-style requests (used for multi-part form submission). The URL contains the name of the component,
|
92
119
|
# as well as the method of this component to be called, according to the double underscore notation.
|
93
120
|
# E.g.: some_grid__post_grid_data.
|
@@ -95,7 +122,8 @@ module Netzke
|
|
95
122
|
component_name, *sub_components = endpoint_path.split('__')
|
96
123
|
component_instance = Netzke::Base.instance_by_config(session[:netzke_components][component_name.to_sym])
|
97
124
|
|
98
|
-
# We can't do this here; this method is only used for classic form submission, and the response from the server
|
125
|
+
# We can't do this here; this method is only used for classic form submission, and the response from the server
|
126
|
+
# should be the (default) "text/html"
|
99
127
|
# response.headers["Content-Type"] = "text/plain; charset=utf-8"
|
100
128
|
|
101
129
|
render :text => component_instance.invoke_endpoint(sub_components.join("__"), params).netzke_jsonify.to_json, :layout => false
|