Module: RearActions
Constant Summary
RearConstants::ASSETS__PATH, RearConstants::ASSETS__SUFFIX, RearConstants::ASSETS__SUFFIX_REGEXP, RearConstants::ASSOCS__STRUCT, RearConstants::COLUMNS__BOOLEAN_MAP, RearConstants::COLUMNS__DEFAULT_TYPE, RearConstants::COLUMNS__HANDLED_TYPES, RearConstants::COLUMNS__PANE_MAX_LENGTH, RearConstants::FILTERS__DECORATIVE_CMP, RearConstants::FILTERS__DEFAULT_TYPE, RearConstants::FILTERS__HANDLED_TYPES, RearConstants::FILTERS__QUERY_MAP, RearConstants::FILTERS__STR_TO_BOOLEAN, RearConstants::PAGER__SIDE_PAGES, RearConstants::PATH__TEMPLATES
Instance Method Summary
collapse
-
#delete_delete_selected ⇒ Object
-
#delete_reverse_assoc(source_ctrl, assoc_type, assoc_name, item_id, attached = nil) ⇒ Object
-
#get_assets ⇒ Object
-
#get_bulk_edit ⇒ Object
-
#get_edit(id) ⇒ Object
-
#get_index ⇒ Object
-
#get_quickview ⇒ Object
-
#get_reverse_assoc(source_ctrl, assoc_type, assoc_name, item_id, attached = nil) ⇒ Object
-
#html_filters(partial = false) ⇒ Object
-
#post_bulk_edit ⇒ Object
-
#post_reverse_assoc(source_ctrl, assoc_type, assoc_name, item_id, attached = nil) ⇒ Object
Instance Method Details
#delete_delete_selected ⇒ Object
82
83
84
85
86
87
|
# File 'lib/rear/actions.rb', line 82
def delete_delete_selected
halt(400, '%s is in readonly mode' % model) if readonly?
if (ids = params[:items].to_s.split.map(&:to_i).select {|r| r > 0}).any?
orm.delete_multiple(*ids)
end
end
|
#delete_reverse_assoc(source_ctrl, assoc_type, assoc_name, item_id, attached = nil) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/rear/actions.rb', line 61
def delete_reverse_assoc source_ctrl, assoc_type, assoc_name, item_id, attached = nil
case @reverse_assoc.type
when :belongs_to, :has_one
@reverse_assoc.source_item.send '%s=' % @reverse_assoc.name, nil
when :has_many
if sequel?
(@reverse_assoc.source_item.send(@reverse_assoc.name)||[]).each do |ti|
next unless ti[pkey] == @reverse_assoc.target_item[pkey]
m = 'remove_' << orm.singularize(@reverse_assoc.name)
@reverse_assoc.source_item.send m, ti
end
else
target_items = Array.new(@reverse_assoc.source_item.send(@reverse_assoc.name)||[]).reject do |ti|
ti[pkey] == @reverse_assoc.target_item[pkey]
end
@reverse_assoc.source_item.send '%s=' % @reverse_assoc.name, target_items
end
end
@reverse_assoc.source_item.save
end
|
#get_assets ⇒ Object
93
94
95
96
97
|
# File 'lib/rear/actions.rb', line 93
def get_assets(*)
env['PATH_INFO'] = env['PATH_INFO'].to_s.sub(ASSETS__SUFFIX_REGEXP, '')
send_files @__rear__assets_fullpath ? @__rear__assets_fullpath :
(@__rear__assets_path ? File.join(app.root, @__rear__assets_path) : ASSETS__PATH)
end
|
#get_bulk_edit ⇒ Object
16
17
18
19
20
|
# File 'lib/rear/actions.rb', line 16
def get_bulk_edit
@items = params[:items].to_s.gsub(/[^\d|\s]/, '')
self.item, self.item_id = model.new, 0
reander_p 'editor/bulk_edit'
end
|
#get_edit(id) ⇒ Object
12
13
14
|
# File 'lib/rear/actions.rb', line 12
def get_edit id
reander_l(:layout) { reander_p 'editor/layout' }
end
|
#get_index ⇒ Object
4
5
6
|
# File 'lib/rear/actions.rb', line 4
def get_index
reander_l(:layout) { reander_p 'pane/layout' }
end
|
#get_quickview ⇒ Object
8
9
10
|
# File 'lib/rear/actions.rb', line 8
def get_quickview
reander_p 'pane/quickview'
end
|
#get_reverse_assoc(source_ctrl, assoc_type, assoc_name, item_id, attached = nil) ⇒ Object
39
40
41
|
# File 'lib/rear/actions.rb', line 39
def get_reverse_assoc source_ctrl, assoc_type, assoc_name, item_id, attached = nil
reander_p 'pane/assocs'
end
|
#html_filters(partial = false) ⇒ Object
89
90
91
|
# File 'lib/rear/actions.rb', line 89
def html_filters partial = false
partial ? render_filters : reander_p('filters/layout')
end
|
#post_bulk_edit ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/rear/actions.rb', line 22
def post_bulk_edit
data = Hash[params]
(columns = data.delete('rear-bulk_editor-crudifier_toggler')).is_a?(Array) ||
halt(400, 'Nothing to update. Please edit at least one column.')
items = data.delete('rear-bulk_editor-items').to_s.strip.split
items.empty? && halt(400, 'No items selected')
data.reject! {|k,v| !columns.include?(k)}
updated, failed = [], []
items.each do |id|
status, h, body = invoke_via_put(:crud, id, data)
status == 200 ? updated << id : failed << ['%s Failed' % id, *body]
end
failed.any? && styled_halt(500, failed)
"Successfully Updated Items:\n%s" % updated.join(', ')
end
|
#post_reverse_assoc(source_ctrl, assoc_type, assoc_name, item_id, attached = nil) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/rear/actions.rb', line 43
def post_reverse_assoc source_ctrl, assoc_type, assoc_name, item_id, attached = nil
case @reverse_assoc.type
when :belongs_to, :has_one
@reverse_assoc.source_item.send '%s=' % @reverse_assoc.name, @reverse_assoc.target_item
when :has_many
@reverse_assoc.source_item.send(@reverse_assoc.name).each do |ti|
ti[pkey] == @reverse_assoc.target_item[pkey] && halt(400, "Relation already exists")
end
if sequel?
m = 'add_' << orm.singularize(@reverse_assoc.name)
@reverse_assoc.source_item.send m, @reverse_assoc.target_item
else
@reverse_assoc.source_item.send(@reverse_assoc.name) << @reverse_assoc.target_item
end
end
@reverse_assoc.source_item.save
end
|