Class: Kaui::AccountTagsController

Inherits:
EngineController show all
Defined in:
app/controllers/kaui/account_tags_controller.rb

Instance Method Summary collapse

Methods inherited from EngineController

#current_ability, #current_user, #options_for_klient

Instance Method Details

#editObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/kaui/account_tags_controller.rb', line 15

def edit
   = params[:account_id]

  begin
    @account        = Kaui::Account::find_by_id_or_key(, false, false, options_for_klient)
    @tag_names      = (@account.tags(false, 'NONE', options_for_klient).map { |tag| tag.tag_definition_name }).sort
    @available_tags = Kaui::TagDefinition.(options_for_klient)
  rescue => e
    flash[:error] = "Error while editing tags: #{as_string(e)}"
    redirect_to kaui_engine.(:account_id => )
  end
end

#showObject



3
4
5
6
7
8
9
10
11
12
13
# File 'app/controllers/kaui/account_tags_controller.rb', line 3

def show
   = params[:account_id]

  begin
    @account = Kaui::Account::find_by_id_or_key(, false, false, options_for_klient)
    @tags    = @account.tags(true, 'FULL', options_for_klient).sort { |tag_a, tag_b| tag_a <=> tag_b }
  rescue => e
    flash[:error] = "Error while getting tags: #{as_string(e)}"
    redirect_to :back
  end
end

#updateObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/kaui/account_tags_controller.rb', line 28

def update
   = params[:account_id]

  tags = []
  params.each do |tag, tag_name|
    tag_info = tag.split('_')
    next if tag_info.size != 2 or tag_info[0] != 'tag'
    tags << tag_info[1]
  end

  begin
     = Kaui::Account.new(:account_id => )
    .set_tags(tags, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
    redirect_to kaui_engine.(:account_id => ), :notice => 'Account tags successfully set'
  rescue => e
    flash[:error] = "Error while updating tags: #{as_string(e)}"
    redirect_to kaui_engine.(:account_id => )
  end
end