Class: Backend::MapBackgroundsController

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

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_theme

Instance Method Summary collapse

Methods inherited from BaseController

accounts_range_crit, crit_params, journal_entries_states_crit, journal_period_crit, journals_crit, search_conditions

Methods inherited from ApplicationController

#after_sign_in_path_for, #authorized?, human_action_name, #human_action_name

Instance Method Details

#destroyObject


50
51
52
53
54
# File 'app/controllers/backend/map_backgrounds_controller.rb', line 50

def destroy
  return unless m = MapBackground.find_by_id(params[:id])
  m.destroy
  head :no_content
end

#indexObject


7
8
9
# File 'app/controllers/backend/map_backgrounds_controller.rb', line 7

def index
  @map_backgrounds = MapBackground.order('by_default DESC, enabled DESC, name')
end

#loadObject


11
12
13
14
# File 'app/controllers/backend/map_backgrounds_controller.rb', line 11

def load
  MapBackground.load_defaults
  redirect_to params[:redirect] || { action: :index }
end

#starObject


44
45
46
47
48
# File 'app/controllers/backend/map_backgrounds_controller.rb', line 44

def star
  return unless m = MapBackground.find_by_id(params[:id])
  m.update(by_default: !m.by_default)
  head :no_content
end

#toggleObject


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/backend/map_backgrounds_controller.rb', line 16

def toggle
  if m = MapBackground.find_by_id(params[:id])

    if !!m.enabled && MapBackground.availables.length == 1
      return head :forbidden
    end
    toggle = !m.enabled
    m.update(enabled: toggle)

    id = nil

    # if map background is disabling but is by default
    if !toggle && m.by_default
      mb = MapBackground.availables.first
      unless mb.nil?
        mb.update(by_default: true)
        id = mb.id
      end
    end

    respond_to do |format|
      format.json { render json: { new_default: id } }
    end
  else
    head :forbidden
  end
end