Module: ReportsHelper

Defined in:
app/helpers/reports_helper.rb

Instance Method Summary collapse

Instance Method Details

#default_comparison_analytical_ids(analytical_type) ⇒ Object



6
7
8
# File 'app/helpers/reports_helper.rb', line 6

def default_comparison_analytical_ids(analytical_type)
  analytical_type.classify.constantize.order('id DESC').limit(1).map(&:id)
end

#default_recent_analytical_ids(analytical_type, start_date, end_date) ⇒ Object



2
3
4
# File 'app/helpers/reports_helper.rb', line 2

def default_recent_analytical_ids(analytical_type,start_date,end_date)
  analytical_type.classify.constantize.limit(params[:analytical_limit]||6).where(:created_at => start_date.beginning_of_day.to_date..(end_date+1.day).beginning_of_day.to_date).map(&:id)
end

#how_are_we_doing_chart(form_id, graph_container_id, graph_type, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
# File 'app/helpers/reports_helper.rb', line 10

def how_are_we_doing_chart(form_id,graph_container_id,graph_type,options={})
  script = <<-END.gsub(/^ {6}/, '')
    <script>
      $("##{form_id} #analyticals").live('click',function(){
        $(this).attr('size',10);
      });
    
      $('##{form_id} #analyticals').live('change',function(){
        $(this).parents('form').find('#analytical_ids').val($(this).val());
        $(this).parents('form').trigger('submit');
      });
    
    
      $('##{form_id} input:checkbox').live('change',function(){
        $(this).parents('form').find('#'+$(this).attr('id').replace('include_','exclude_')).val($(this).attr("checked") ? "" : true);
        $(this).parents('form').trigger('submit');
      });
    
      $('##{form_id}').live('submit',function(){
        var data = {};
        var allowable_params = {
          exclude_totals:1,
          exclude_prints:1,
          exclude_shares:1,
          exclude_views:1,
          start_date:1,
          end_date:1,
          start_date:1,
          parent_type: 1,
          parent_id: 1,
          analytical_ids: 1,
          analytical_type:1
        };

        $(this).find('input,select').each(function(i,element){
          if(element.name && allowable_params[element.name] && $(element).val()) {
            data[element.name] = $(element).val();
          }
        });

      
        $.ajax({
          url: $(this).attr('action')+".json",
          method: 'get',
          data: $.param(data),
          dataType: 'json',
          success: function(data) {
            #{graph_type}_graph_it(data,'#{graph_container_id}');
          }
        });
        return false;
      });
    
      $(function(){
        $('##{form_id}').trigger('submit');
        $(".date-selector").datepicker();
      });
    </script>
  END
  content_for :javascripts do
    script.html_safe
  end
  render :partial => "reports/#{graph_type}_graph", :locals => {:form_id => form_id, :graph_container_id => graph_container_id, :analytical_ids => options[:analytical_ids], :include_comparison => options[:include_comparison]}
end