|
| 1 | +Admin.controllers :accounts do |
| 2 | + before do |
| 3 | + settings.breadcrumbs.reset |
| 4 | + settings.breadcrumbs.add :account, url(:accounts, :index), :account |
| 5 | + end |
| 6 | + |
| 7 | + get :index do |
| 8 | + @accounts = Account.all |
| 9 | + render 'accounts/index' |
| 10 | + end |
| 11 | + |
| 12 | + get :new do |
| 13 | + settings.breadcrumbs.add :account_new , url(:accounts, :new), :new |
| 14 | + @account = Account.new |
| 15 | + render 'accounts/new' |
| 16 | + end |
| 17 | + |
| 18 | + post :create do |
| 19 | + @account = Account.new(params[:account]) |
| 20 | + if @account.save |
| 21 | + flash[:notice] = 'Account was successfully created.' |
| 22 | + params[:save_and_continue] ? redirect(url(:accounts, :index)) : redirect(url(:accounts, :edit, :id => @account.id)) |
| 23 | + else |
| 24 | + render 'accounts/new' |
| 25 | + end |
| 26 | + end |
| 27 | + |
| 28 | + get :edit, :with => :id do |
| 29 | + settings.breadcrumbs.add :account_edit, params[:id], :edit |
| 30 | + @account = Account.find(params[:id]) |
| 31 | + if @account |
| 32 | + render 'accounts/edit' |
| 33 | + else |
| 34 | + halt 404 |
| 35 | + end |
| 36 | + end |
| 37 | + |
| 38 | + put :update, :with => :id do |
| 39 | + @account = Account.find(params[:id]) |
| 40 | + if @account |
| 41 | + if @account.update_attributes(params[:account]) |
| 42 | + flash[:notice] = 'Account was successfully updated.' |
| 43 | + params[:save_and_continue] ? redirect(url(:accounts, :index)) : redirect(url(:accounts, :edit, :id => @account.id)) |
| 44 | + else |
| 45 | + render 'accounts/edit' |
| 46 | + end |
| 47 | + else |
| 48 | + halt 404 |
| 49 | + end |
| 50 | + end |
| 51 | + |
| 52 | + delete :destroy, :with => :id do |
| 53 | + account = Account.find(params[:id]) |
| 54 | + if account |
| 55 | + if account != current_account && account.destroy |
| 56 | + flash[:notice] = 'Account was successfully destroyed.' |
| 57 | + else |
| 58 | + flash[:error] = 'Unable to destroy Account!' |
| 59 | + end |
| 60 | + redirect url(:accounts, :index) |
| 61 | + else |
| 62 | + halt 404 |
| 63 | + end |
| 64 | + end |
| 65 | + |
| 66 | + delete :delete_multiple do |
| 67 | + unless params[:account_ids] |
| 68 | + flash[:error] = 'You must select at least one account ' |
| 69 | + redirect(url(:accounts, :index)) |
| 70 | + end |
| 71 | + accounts = Account.find(params[:account_ids]) |
| 72 | + if Account.destroy accounts |
| 73 | + flash[:notice] = 'accounts have been successfully destroyed.' |
| 74 | + end |
| 75 | + redirect url(:accounts, :index) |
| 76 | + end |
| 77 | +end |
0 commit comments