Class: AppyantraAdmin::AdminSettingsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/appyantra_admin/admin_settings_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#add_breadcrumb, #asset_display_name, #current_breadcrumb, #get_object_name, #set_objects

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/appyantra_admin/admin_settings_controller.rb', line 21

def create
  type_object_name = get_object_name @type_class # e.g. Link -> link
  type_object = @type_class.new(params[type_object_name.to_sym])  
  # TODO set name as slug  
  AdminSetting.create({ name: @setting_name, display_name: @setting_name, entity_type: @entity_type, entity_id: type_object.id, group: @group }) if type_object.save #TODO error handling
  
  respond_to do |format|
    format.html do |format|
      flash[:notice] = "Setting was successfully added." 
      redirect_to main_app.settings_path
    end
  end
end

#destroyObject



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/appyantra_admin/admin_settings_controller.rb', line 50

def destroy
  setting = AdminSetting.find(params[:id])
  # TODO error handling
  setting.entity.destroy
  setting.destroy
  
  respond_to do |format|
    format.html do |format|
      flash[:notice] = "Setting was successfully removed." 
      redirect_to main_app.settings_path
    end
  end
end

#editObject



64
65
66
67
68
# File 'app/controllers/appyantra_admin/admin_settings_controller.rb', line 64

def edit
  @page_title = 'Edit'
  current_breadcrumb @page_title
  @setting = AdminSetting.find(params[:id])
end

#edit_mail_settingsObject



77
78
79
80
81
82
# File 'app/controllers/appyantra_admin/admin_settings_controller.rb', line 77

def edit_mail_settings
  @page_title = 'Mail Settings'
  current_breadcrumb @page_title
  @mail_settings = AdminSetting.group_settings 'Mail'
  render 'mail_settings'
end

#indexObject



10
11
12
13
# File 'app/controllers/appyantra_admin/admin_settings_controller.rb', line 10

def index
  @page_title = 'Settings'
  current_breadcrumb @page_title
end

#newObject



15
16
17
18
19
# File 'app/controllers/appyantra_admin/admin_settings_controller.rb', line 15

def new
  @page_title = 'New'
  current_breadcrumb @page_title
  @entity_object = @type_class.new
end

#new_mail_settingsObject



70
71
72
73
74
75
# File 'app/controllers/appyantra_admin/admin_settings_controller.rb', line 70

def new_mail_settings
  @page_title = 'Mail Settings'
  current_breadcrumb @page_title
  @mail_settings = AdminSetting.initialize_group 'Mail', AppyantraAdmin.mail_settings_fields
  render 'mail_settings'
end

#updateObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/appyantra_admin/admin_settings_controller.rb', line 35

def update
  setting = AdminSetting.find(params[:id])
  type_object_name = get_object_name setting.entity.class
  respond_to do |format|
    if setting.entity.update_attributes(params[type_object_name.to_sym])
      format.html do |format|
        flash[:notice] = "Setting was successfully updated." 
        redirect_to main_app.settings_path
      end
    else
      # TODO handle errors
    end
  end
end

#update_mail_settingsObject



84
85
86
87
88
89
# File 'app/controllers/appyantra_admin/admin_settings_controller.rb', line 84

def update_mail_settings
  mail_settings = params[:mail_settings]
  AdminSetting.update_group_settings 'Mail', mail_settings
  AppyantraAdmin.setup_mailer
  redirect_to main_app.settings_path
end