Class: Admin::ActivitiesWithPricesController

Inherits:
ActivitiesController
  • Object
show all
Defined in:
app/controllers/admin/activities_with_prices_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.active_scaffold_pathsObject

TODO: Put in a plugin-helper? We need to be sure the view is looking in the right place, this little hack should do it:



31
32
33
34
35
# File 'app/controllers/admin/activities_with_prices_controller.rb', line 31

def self.active_scaffold_paths
  super_view_path = BRISKBILLS_ROOT+'/app/views/admin/activities'
  @active_scaffold_overrides << super_view_path unless @active_scaffold_overrides.include? super_view_path
  super
end

Instance Method Details

This adjusts the order of the link so that move appears to the left:



24
25
26
27
# File 'app/controllers/admin/activities_with_prices_controller.rb', line 24

def action_links_order
  links = active_scaffold_config.action_links
  links.sort_by{ |l| ( l.action == "move_to_invoice" ) ? -1 : 1 }
end

#move_to_invoiceObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/admin/activities_with_prices_controller.rb', line 41

def move_to_invoice
  @errors_during_move = []
  
  activity = Activity.find params[:id].to_i
  
  dest_conditions = ['invoices.is_published = ?',false]
  dest_conditions[0] += ' AND invoices.id != ?' and dest_conditions << activity.invoice_id if activity
  
  @dest_invoices = Invoice.find_with_totals(
    :all, 
    :conditions => dest_conditions, 
    :order => 'invoices.issued_on DESC, invoices.id DESC', 
    :include => [:client]
  )

  if params.has_key? :move_to_invoice_id
    begin
      invoice_dest = (params[:move_to_invoice_id].empty?) ? 
        nil :
        Invoice.find(params[:move_to_invoice_id].to_i)

      activity.move_to_invoice! invoice_dest

      do_list
      
      flash[:warning]  = (invoice_dest) ? 
        ('%s successfully moved to "%s"' % [activity.label,invoice_dest.long_name]) :
        ('The %s was removed from this invoice.' % activity.label)
    rescue
      @errors_during_move << $!
    end
    
    render :action => 'move_to_invoice.js'
  else
    render :action => 'move_to_invoice.html', :layout => false
  end
end