Class: Backend::ListingNodesController

Inherits:
BaseController show all
Defined in:
app/controllers/backend/listing_nodes_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_theme

Instance Method Summary collapse

Methods inherited from BaseController

account_lettering_states_crit, accounts_range_crit, amount_range_crit, crit_params, journal_entries_states_crit, journal_letter_crit, journal_period_crit, journals_crit, search_conditions

Methods inherited from ApplicationController

#after_sign_in_path_for, #authorized?, human_action_name, #human_action_name, #session_controller?

Instance Method Details

#createObject


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/backend/listing_nodes_controller.rb', line 46

def create
  return unless @listing_node = find_and_check(id: params[:parent_id])
  render text: '[UnfoundListingNode]' unless @listing_node
  desc = params[:nature].split('-')
  # raise StandardError.new desc.inspect
  if desc[0] == 'special'
    case desc[1]
    when 'all_columns'
      model = @listing_node.model
      for column in model.content_columns.sort { |a, b| model.human_attribute_name(a.name.to_s) <=> model.human_attribute_name(b.name.to_s) }
        ln = @listing_node.children.new(nature: 'column', attribute_name: column.name, label: @listing_node.model.human_attribute_name(column.name))
        ln.save!
      end
    when 'custom'
      ln = @listing_node.children.new(nature: 'custom', attribute_name: desc[2], label: @listing_node.model.human_attribute_name(desc[2]))
      ln.save!
    end
  else
    ln = @listing_node.children.new(nature: desc[0], attribute_name: desc[1], label: @listing_node.model.human_attribute_name(desc[1]))
    ln.save!
  end

  render(partial: 'backend/listings/reflection', object: @listing_node)
end

#destroyObject


119
120
121
122
123
124
125
126
127
128
# File 'app/controllers/backend/listing_nodes_controller.rb', line 119

def destroy
  return unless @listing_node = find_and_check
  parent = @listing_node.parent
  @listing_node.reload.destroy
  if request.xhr?
    render(partial: 'backend/listings/reflection', object: parent)
  else
    redirect_to controller: :listings, action: :edit, id: @listing_node.listing_id
  end
end

#editObject


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/backend/listing_nodes_controller.rb', line 71

def edit
  return unless @listing_node = find_and_check
  if request.xhr?
    if params[:type] == 'hide' || params[:type] == 'show'
      @listing_node.exportable = !@listing_node.exportable
      render text: ''
    elsif params[:type] == 'column_label'
      @listing_node.label = params[:label]
      render(partial: 'backend/listing_nodes/column_label', object: @listing_node)
    elsif params[:type] == 'comparison'
      @listing_node.condition_operator = params[:comparator]
      @listing_node.condition_value = params[:comparison_value]
      render(partial: 'backend/listing_nodes/comparison', object: @listing_node)
    elsif params[:type] == 'position'
      @listing_node.position = params[:position]
      render(partial: 'backend/listing_nodes/position', object: @listing_node)
    else
      render(text: '[ERROR] Unknown update type')
    end
    @listing_node.save
  else
    redirect_to backend_listings_path
  end
end

#newObject


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/backend/listing_nodes_controller.rb', line 21

def new
  return unless @listing_node = find_and_check(id: params[:parent_id])
  if params[:nature]
    desc = params[:nature].split('-')
    # raise StandardError.new desc.inspect
    if desc[0] == 'special'
      if desc[1] == 'all_columns'
        model = @listing_node.model
        for column in model.content_columns.sort { |a, b| model.human_attribute_name(a.name.to_s) <=> model.human_attribute_name(b.name.to_s) }
          ln = @listing_node.children.new(nature: 'column', attribute_name: column.name, label: @listing_node.model.human_attribute_name(column.name))
          ln.save!
        end
      end
    else
      ln = @listing_node.children.new(nature: desc[0], attribute_name: desc[1], label: @listing_node.model.human_attribute_name(desc[1]))
      ln.save!
    end
  end
  if request.xhr?
    render(partial: 'backend/listings/reflection', object: @listing_node)
  else
    redirect_to backend_listing_path(@listing_node.listing)
  end
end

#updateObject


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'app/controllers/backend/listing_nodes_controller.rb', line 96

def update
  return unless @listing_node = find_and_check
  if request.xhr?
    if params[:type] == 'exportable' # "hide" or params[:type] == "show"
      @listing_node.exportable = !@listing_node.exportable
      render text: ''
    elsif params[:type] == 'column_label'
      @listing_node.label = params[:label]
      render(partial: 'backend/listing_nodes/column_label', object: @listing_node)
    elsif params[:type] == 'comparison'
      @listing_node.condition_operator = params[:comparator]
      @listing_node.condition_value = params[:comparison_value]
      render(partial: 'backend/listing_nodes/comparison', object: @listing_node)
    elsif params[:type] == 'position'
      @listing_node.position = params[:position]
      render(partial: 'backend/listing_nodes/position', object: @listing_node)
    end
    @listing_node.save
  else
    redirect_to backend_listings_path
  end
end