lib/engine2/action.rb in engine2-1.0.6 vs lib/engine2/action.rb in engine2-1.0.7
- old
+ new
@@ -16,14 +16,17 @@
def inherited cls
cls.http_method http_method
end
- def inherit
- Class.new self do
+ def inherit &blk
+ cls = Class.new self do
action_type superclass.action_type
end
+
+ cls.instance_eval &blk if block_given?
+ cls
end
end
http_method :get
@@ -44,13 +47,23 @@
def check_static_action
raise E2Error.new("Static action required") if dynamic?
end
+ def check_anonymous_action_class name
+ raise E2Error.new("Defining method '#{name}'' for named class '#{self.class}', consider using #inherit") if self.class.name
+ end
+
+ def define_method name, &blk
+ check_anonymous_action_class name
+ self.class.class_eval{define_method name, &blk}
+ end
+
def define_invoke &blk
check_static_action
- self.class.class_eval{define_method :invoke, &blk}
+ define_method :invoke, &blk
+ # self.class.class_eval{define_method :invoke, &blk}
end
def invoke! handler
if rmp = @request_action_proc
action = self.class.new(node, assets, self)
@@ -152,10 +165,14 @@
end
def split_keys id
Sequel::split_keys(id)
end
+
+ def join_keys id
+ Sequel::join_keys(id)
+ end
end
module ActionWebSocketSupport
WS_METHODS ||= Faye::WebSocket::API::TYPES.keys.map(&:to_sym)
WS_METHODS.each do |method|
@@ -899,11 +916,11 @@
def validate_and_approve_association handler, record, assoc_name, node_name, hash
records = hash[node_name].to_a
unless records.empty?
action = node.parent[:"#{assoc_name}!"][node_name].approve.*
- parent_id = Sequel::join_keys(record.primary_key_values)
+ parent_id = join_keys(record.primary_key_values)
records.each do |arec|
rec = action.allocate_record(handler, arec)
action.validate_and_approve(handler, rec, parent_id, false)
rec.errors.each do |k, v|
(record.errors[assoc_name] ||= []).concat(v)
@@ -1097,10 +1114,10 @@
super
panel_template 'scaffold/view'
panel_title "#{LOCS[:view_title]} - #{LOCS[assets[:model].table_name]}"
panel[:backdrop] = true
- menu(:panel_menu).option :cancel, icon: "remove"
+ menu(:panel_menu).option :close, icon: "remove"
node.parent.*.menu(:item_menu).option node.name, icon: "file", button_loc: false
end
def field_tabs hash
super