Module: Admin::BaseHelper

Defined in:
app/helpers/admin/base_helper.rb

Instance Method Summary collapse

Instance Method Details

#dataSlides_tag(options = {}) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'app/helpers/admin/base_helper.rb', line 74

def dataSlides_tag(options = {})
  id = options[:id].nil? ? 'table' : options[:id]
  columns = options[:columns]

  # data source
  data_source = ''
  unless options[:url].nil? or options[:url].blank?
    data_source += "'bServerSide': true,"
    data_source += "'sAjaxSource': '#{options[:url]}',"
    data_source += "'fnDrawCallback': DataTablesDrawCallBack,"
    data_source += "'fnRowCallback': DataTablesRowCallBack,"
  end

  dataTables_init_function = "initDataSlides_on_#{id.gsub('-','_')}"

  javascript_tag "
    function #{dataTables_init_function}(){
      var target = jQuery('##{id}');
      if (typeof(target.dataTableInstance) != 'undefined' && typeof(target.dataTableInstance()) != 'undefined') {
        oTable.fnDraw();
      } else {
        var table = target.dataSlide({
          'sPaginationType': 'full_numbers',
          'sDom': \"<'top'if>t<'bottom'p<'clear'>\",
          'aoColumns': [ #{columns.join(',')} ],
          'sProcessing': true,
          'bStateSave': false,
          'bLengthChange': true,
          'iDisplayLength': 12,
          'iDisplayEnd': 12,
          #{data_source}
          'oLanguage': {
            'sProcessing' : '#{t('jquery.dataTables.oLanguage.sProcessing')}',
            'sLengthMenu':'#{t('jquery.dataTables.oLanguage.sLengthMenu')}',
            'sZeroRecords':'#{t('jquery.dataTables.oLanguage.sZeroRecords')}',
            'sInfo':'#{t('jquery.dataTables.oLanguage.sInfo')}',
            'sInfoEmpty':'#{t('jquery.dataTables.oLanguage.sInfoEmpty')}',
            'sSearch': '#{t('jquery.dataTables.oLanguage.sSearch')}',
            'oPaginate': {
              'sFirst': '#{t('jquery.dataTables.oLanguage.sFirst')}',
              'sPrevious': '#{t('jquery.dataTables.oLanguage.sPrevious')}',
              'sNext': '#{t('jquery.dataTables.oLanguage.sNext')}',
              'sLast': '#{t('jquery.dataTables.oLanguage.sLast')}'
            }
          }
        });
        oTables.push(table);
        oTable = table;
      }
    }

    jQuery(document).ready(function(){
      if(typeof(oTables) == 'undefined') {
        oTables = new Array();
      }
      jQuery('##{id}').data('dataTables_init_function','#{dataTables_init_function}');
      #{"eval(jQuery('##{id}').data('dataTables_init_function')+'()');" if options[:autostart] != false}
    });
  "
end

#dataTables_tag(options = {}) ⇒ Object



3
4
5
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
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
# File 'app/helpers/admin/base_helper.rb', line 3

def dataTables_tag(options = {})
  id = options[:id].nil? ? 'table' : options[:id]
  columns = options[:columns]
  options[:sort_col].nil? ? sort_col = 1 : sort_col = options[:sort_col]
  options[:sort_order].nil? ? sort_order = 'asc' : sort_order = options[:sort_order]

  save_state = options[:save_state] || false
  per_page = options[:per_page] || 50

  # data source
  data_source = ''
  unless options[:url].nil? or options[:url].blank?
    data_source += "'bServerSide': true,"
    data_source += "'sAjaxSource': '#{options[:url]}',"
    data_source += "'fnDrawCallback': DataTablesDrawCallBack,"
    data_source += "'fnRowCallback': DataTablesRowCallBack,"
  end

  unless options[:callback].nil? or options[:callback].blank?
    data_source += "'fnDrawCallback': #{options[:callback]},"
  end

  dataTables_init_function = "initDataTables_on_#{id.gsub('-','_')}"

  javascript_tag "
    function #{dataTables_init_function}(){
      var target = jQuery('##{id}');
      if (typeof(target.dataTableInstance) != 'undefined' && typeof(target.dataTableInstance()) != 'undefined') {
        oTable.fnDraw();
      } else {
        var table = target.dataTable({
          'sPaginationType': 'full_numbers',
          'sDom': \"<'top'f>tpl<'clear'>i\",
          'aoColumns': [ #{columns.join(',')} ],
          'sProcessing': true,
          'iDisplayLength': #{per_page},
          'bLengthChange': true,
          'aaSorting': [[#{sort_col},'#{sort_order}']],
          'bStateSave': #{save_state},
          'bAutoWidth': false,
          #{data_source}
          'oLanguage': {
            'sProcessing' : '#{t('jquery.dataTables.oLanguage.sProcessing')}',
            'sLengthMenu':'#{t('jquery.dataTables.oLanguage.sLengthMenu')}',
            'sZeroRecords': '#{t('jquery.dataTables.oLanguage.sZeroRecords')}',
            'sInfo': '#{t('jquery.dataTables.oLanguage.sInfo')}',
            'sInfoEmpty': '#{t('jquery.dataTables.oLanguage.sInfoEmpty')}',
            'sSearch': '#{t('jquery.dataTables.oLanguage.sSearch')}',
            'oPaginate': {
              'sFirst': '#{t('jquery.dataTables.oLanguage.sFirst')}',
              'sPrevious': '#{t('jquery.dataTables.oLanguage.sPrevious')}',
              'sNext': '#{t('jquery.dataTables.oLanguage.sNext')}',
              'sLast': '#{t('jquery.dataTables.oLanguage.sLast')}'
            }
          }
        });
        oTables.push(table);
        oTable = table;
      }
    }

    jQuery(document).ready(function(){
      if(typeof(oTables) == 'undefined') {
        oTables = new Array();
      }
      jQuery('##{id}').data('dataTables_init_function','#{dataTables_init_function}');
      #{"eval(jQuery('##{id}').data('dataTables_init_function')+'()');" if options[:autostart] != false}
    });
  "
end

#fg_searchObject



135
136
137
138
# File 'app/helpers/admin/base_helper.rb', line 135

def fg_search
  label = (:span, t('search').capitalize, :class => 'small-icons search-span')
  link_to(label, '#', :class => 'small-icons left search-link')
end

#fg_submit_tag(label) ⇒ Object



140
141
142
# File 'app/helpers/admin/base_helper.rb', line 140

def fg_submit_tag(label)
  submit_tag(t(label).capitalize, :class => 'backgrounds interact-button')
end

#Forgeos_save_buttons(back_path = [forgeos_core, :admin, :root], label = 'save') ⇒ Object



144
145
146
147
148
# File 'app/helpers/admin/base_helper.rb', line 144

def Forgeos_save_buttons(back_path= [forgeos_core, :admin, :root], label= 'save')
  (:div, :class => 'interact-links') do
    fg_submit_tag(label) + t('or') + link_to(t('cancel').capitalize, back_path, :class => 'back-link')
  end
end