Class: Kaui::BundlesController

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

Instance Method Summary collapse

Methods inherited from EngineController

#current_ability, #current_user, #options_for_klient

Instance Method Details

#do_transferObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/kaui/bundles_controller.rb', line 55

def do_transfer
  key = params[:new_account_key]
  unless key.present?
    flash.now[:error] = 'No new account key given'
    render :action => :index and return
  end

  begin
    # Retrieve the new account to get the account id
     = Kaui::Account::find_by_id_or_key(params[:new_account_key], false, false, options_for_klient)
  rescue => e
    flash.now[:error] = "Error while retrieving new account: #{as_string(e)}"
    render :action => :index and return
  end

  begin
    billing_policy = params[:billing_policy]

    bundle = Kaui::Bundle::new(:bundle_id => params[:id], :account_id => .)
    bundle.transfer(nil, billing_policy, current_user.kb_username, params[:reason], params[:comment], options_for_klient)

    redirect_to (.), :notice => 'Bundle was successfully transferred'
  rescue => e
    flash.now[:error] = "Error while transferring bundle: #{as_string(e)}"
    render :action => :index
  end
end

#indexObject



3
4
# File 'app/controllers/kaui/bundles_controller.rb', line 3

def index
end

#paginationObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/kaui/bundles_controller.rb', line 6

def pagination
  search_key = params[:sSearch]
  offset     = params[:iDisplayStart] || 0
  limit      = params[:iDisplayLength] || 10

  bundles = Kaui::Bundle.list_or_search(search_key, offset, limit, options_for_klient)

  json = {
      :sEcho                => params[:sEcho],
      :iTotalRecords        => bundles.pagination_max_nb_records,
      :iTotalDisplayRecords => bundles.pagination_total_nb_records,
      :aaData               => []
  }

  bundles.each do |bundle|
    json[:aaData] << [
        view_context.link_to(view_context.truncate_uuid(bundle.bundle_id), view_context.url_for(:action => :show, :id => bundle.bundle_id)),
        view_context.link_to(view_context.truncate_uuid(bundle.), view_context.url_for(:controller => :accounts, :action => :show, :id => bundle.)),
        bundle.external_key,
        bundle.subscriptions.nil? ? '' : (bundle.subscriptions.map { |s| s.product_name }).join(', ')
    ]
  end

  respond_to do |format|
    format.json { render :json => json }
  end
end

#showObject



34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/kaui/bundles_controller.rb', line 34

def show
  begin
    @bundle  = Kaui::Bundle::find_by_id_or_key(params[:id], nil, options_for_klient)
    @account = Kaui::Account::find_by_id(@bundle., false, false, options_for_klient)
    @tags    = @bundle.tags(false, 'NONE', options_for_klient).sort { |tag_a, tag_b| tag_a <=> tag_b }
  rescue => e
    flash.now[:error] = "Error while retrieving bundle information: #{as_string(e)}"
    render :action => :index
  end
end

#transferObject



45
46
47
48
49
50
51
52
53
# File 'app/controllers/kaui/bundles_controller.rb', line 45

def transfer
  begin
    @bundle  = Kaui::Bundle::find_by_id_or_key(params[:id], nil, options_for_klient)
    @account = Kaui::Account::find_by_id(@bundle., false, false, options_for_klient)
  rescue => e
    flash.now[:error] = "Error while preparing to transfer bundle: #{as_string(e)}"
    render :action => :index
  end
end