Module: ComponentHelper
- Defined in:
- app/helpers/component_helper.rb
Instance Method Summary collapse
- #button_delete(obj, opts = {}) ⇒ Object
- #button_delete_with_cancan(obj, opts = {}) ⇒ Object
- #button_edit(obj, opts = {}) ⇒ Object
- #button_edit_delete(obj) ⇒ Object
- #button_edit_delete_with_cancan(obj, opts = {}) ⇒ Object
- #button_edit_with_cancan(obj, opts = {}) ⇒ Object
- #button_form_actions(fobj) ⇒ Object
- #code_with_name(code, name, row = 1) ⇒ Object
- #component_by_page(slug) ⇒ Object
- #error_message_list(errors) ⇒ Object
- #fake_pagination(rtc_controller_name) ⇒ Object
- #icon(ico, text = '', pos = 'left') ⇒ Object
- #lvr_row_class(item) ⇒ Object
- #lvr_row_id(item) ⇒ Object
-
#mapping_label(arr) ⇒ Object
Needed for constructing dot format in recapitulation matrix.
-
#part(opts = {}) ⇒ Object
Return part div.
- #render_recapitulation(options) ⇒ Object
- #render_rich_table_component(options) ⇒ Object
- #render_rtc(options) ⇒ Object
- #row_number(local_var_assignments) ⇒ Object
- #row_selection(local_var_assignments, options = {}) ⇒ Object
-
#sort_link(column = {}, options = {}) ⇒ Object
rendering link for sortable column that used by rich table component.
- #time_period(sdate, edate) ⇒ Object
- #uneditable_input_control(value, label = ' ') ⇒ Object
- #uneditable_textarea_control(value, label = ' ') ⇒ Object
- #with_html_title(text) ⇒ Object
Instance Method Details
#button_delete(obj, opts = {}) ⇒ Object
87 88 89 90 |
# File 'app/helpers/component_helper.rb', line 87 def (obj, opts = {}) opts[:scope_params] ||= {} ( link_to icon('trash'), {controller: obj.class.name.tableize, id: obj, action: :destroy}.merge(opts[:scope_params]), confirm: 'Apakah Anda yakin?', method: :delete, remote: true, title: 'Hapus data', rel: 'tooltip', class: 'btn btn-mini btn-danger delete' ).html_safe end |
#button_delete_with_cancan(obj, opts = {}) ⇒ Object
100 101 102 |
# File 'app/helpers/component_helper.rb', line 100 def (obj, opts = {}) can?(:destroy, obj) ? (obj, opts).html_safe : '' end |
#button_edit(obj, opts = {}) ⇒ Object
82 83 84 85 |
# File 'app/helpers/component_helper.rb', line 82 def (obj, opts = {}) opts[:scope_params] ||= {} ( link_to icon('pencil'), {controller: obj.class.name.tableize, id: obj, action: :edit}.merge(opts[:scope_params]), remote: true, title: 'Ubah data', rel: 'tooltip', class: 'btn btn-mini edit' ).html_safe end |
#button_edit_delete(obj) ⇒ Object
92 93 94 |
# File 'app/helpers/component_helper.rb', line 92 def (obj) [(obj), (obj)].join(' ').strip.html_safe end |
#button_edit_delete_with_cancan(obj, opts = {}) ⇒ Object
104 105 106 |
# File 'app/helpers/component_helper.rb', line 104 def (obj, opts = {}) [(obj, opts), (obj, opts)].join(' ').strip.html_safe end |
#button_edit_with_cancan(obj, opts = {}) ⇒ Object
96 97 98 |
# File 'app/helpers/component_helper.rb', line 96 def (obj, opts = {}) can?(:update, obj) ? (obj, opts).html_safe : '' end |
#button_form_actions(fobj) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'app/helpers/component_helper.rb', line 71 def (fobj) result = '' # result << (fobj.error :base).presence || '' result << '<div class="form-actions">' result << (fobj. :submit, 'Simpan', class: 'btn btn-large btn-primary btn_submit') result << '</div>' result.html_safe end |
#code_with_name(code, name, row = 1) ⇒ Object
108 109 110 111 112 113 114 |
# File 'app/helpers/component_helper.rb', line 108 def code_with_name(code, name, row = 1) if row == 2 "<strong>#{code}</strong><br/>#{name}".html_safe else "<strong>#{code}:</strong> #{name}".html_safe end end |
#component_by_page(slug) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'app/helpers/component_helper.rb', line 144 def component_by_page slug comp_page = Page.find_by_slug slug result = '' if comp_page result = "<div class='component'>" + " <div class='component_title'>" + " <h2> #{comp_page.name}" + " </h2>" + " </div>" + " <div class='component_content'>#{truncate_html(comp_page.description, 300)}" + " </div>" + "</div>" end result.html_safe end |
#error_message_list(errors) ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'app/helpers/component_helper.rb', line 240 def errors result = "" if errors.present? result += ' <div class="alert alert-error">' result += ' <ul>' errors.each do |k, v| result += ' <li>' result += t(k.to_s.split('.').join('_')) + ' ' + v result += ' </li>' end result += ' </ul>' result += ' </div>' end result.html_safe end |
#fake_pagination(rtc_controller_name) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'app/helpers/component_helper.rb', line 220 def fake_pagination(rtc_controller_name) = [5, 10, 20, 50, 100, 200] result = '<div class="pagination">' result += '<span class="first_page disabled"><<</span>' result += '<span class="previous_page disabled"><</span>' result += '<div class="current_page_part">Hal. 1 dari 1' result += '</div>' result += '<span class="previous_page disabled"><</span>' result += '<span class="last_page disabled">>></span>' result += '<div class="per_page_part">' result += (select_tag 'per_page', (.map{|m| "<option #{(m==params[:per_page].to_i ? 'selected=selected' : '')}>#{m}</option>"}.join.html_safe)) result += 'Per hal. </div>' result += '<div class="go_to_page_part">' result += '<input type="text" value="1" name="page">' result += (link_to "Go", {controller: rtc_controller_name}, remote: true, class: "gotopage btn-mini") result += '</div>' result += '</div>' result.html_safe end |
#icon(ico, text = '', pos = 'left') ⇒ Object
61 62 63 64 65 66 67 |
# File 'app/helpers/component_helper.rb', line 61 def icon(ico, text = '', pos = 'left') if pos.eql? 'right' sanitize text + ' <i class="icon-' + ico + '"></i>' else sanitize '<i class="icon-' + ico + '"></i> ' + text end end |
#lvr_row_class(item) ⇒ Object
140 141 142 |
# File 'app/helpers/component_helper.rb', line 140 def lvr_row_class(item) "#{controller_name}_#{item.class.name.tableize.singularize}_list_view_row" end |
#lvr_row_id(item) ⇒ Object
136 137 138 |
# File 'app/helpers/component_helper.rb', line 136 def lvr_row_id(item) "#{item.class.name.tableize.singularize}_list_view_row_#{item.id}" end |
#mapping_label(arr) ⇒ Object
Needed for constructing dot format in recapitulation matrix
172 173 174 |
# File 'app/helpers/component_helper.rb', line 172 def mapping_label(arr) [['mapping'] + arr].flatten.join('.') end |
#part(opts = {}) ⇒ Object
Return part div
48 49 50 51 52 53 54 55 56 57 |
# File 'app/helpers/component_helper.rb', line 48 def part(opts = {}) content_tag :div, class: "part #{opts[:class]}" do if opts[:label].present? content_tag(:span, opts[:label], class: "part_label") + content_tag(:span, opts[:value], class: "part_value", title: opts[:title], rel: 'tooltip') else content_tag(:span, opts[:value], class: "part_value", title: opts[:title], rel: 'tooltip') end end end |
#render_recapitulation(options) ⇒ Object
184 185 186 |
# File 'app/helpers/component_helper.rb', line 184 def render_recapitulation() render partial: 'rich_table_component/rtc/recapitulation_matrix', locals: end |
#render_rich_table_component(options) ⇒ Object
180 181 182 |
# File 'app/helpers/component_helper.rb', line 180 def render_rich_table_component() render partial: 'rich_table_component/rtc/component', locals: end |
#render_rtc(options) ⇒ Object
176 177 178 |
# File 'app/helpers/component_helper.rb', line 176 def render_rtc() render partial: 'rich_table_component/rtc/component', locals: end |
#row_number(local_var_assignments) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'app/helpers/component_helper.rb', line 200 def row_number local_var_assignments result = '<td class="numeric rtc_row_number">' if local_var_assignments[:rtc_partial].present? counter = local_var_assignments["#{local_var_assignments[:rtc_partial].split('/').last}_counter".to_sym].presence || 0 offset = local_var_assignments[:offset] if offset result << "#{counter + offset + 1}." else result << '(baru)' end else result << '(update)' end result << '</td>' result.html_safe end |
#row_selection(local_var_assignments, options = {}) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 |
# File 'app/helpers/component_helper.rb', line 188 def row_selection local_var_assignments, = {} obj = local_var_assignments["#{local_var_assignments[:rtc_partial]}".to_sym] [:visible] = true if [:visible].nil? result = '<td class="numeric rtc_row_select_cell">' if [:visible] result << (check_box_tag "#{obj.class.name.tableize}[]", obj.id, false, class: 'rtc_row_select', style: 'height: 0px; margin-top: 0px; margin-right: 7px;') end result << '</td>' result.html_safe end |
#sort_link(column = {}, options = {}) ⇒ Object
rendering link for sortable column that used by rich table component
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 |
# File 'app/helpers/component_helper.rb', line 5 def sort_link(column = {}, = {}) new_params = Hash.new new_params.merge! params case column when Hash new_params.merge!(column[:params]) if column[:params].present? [:title] ||= column[:title].to_s if column[:value].present? [:title] = column[:label] column = column[:value] else column = column[:column] end when Array [:title] = column[1].presence || column.first.to_s.split('.').last(2).join('_') column = column.first end [:title] = [:title].presence || column.to_s.split('.').last(2).join('_') [:controller] ||= controller_name [:params][:rtc_controller_name] = [:rtc_controller_name].presence || controller_name [:params][:rtc_partial] = [:rtc_partial] if [:rtc_partial].present? css_class = (column == sort_column) ? "current #{sort_direction}" : nil direction = (column == sort_column && sort_direction == "asc") ? "desc" : "asc" [:params].stringify_keys! new_params.merge!([:params]) if !action_name.eql? 'index' new_params.merge!({pgos: true}) end new_params.merge!({controller: [:controller], sort: column, direction: direction, page: params[:page]}.stringify_keys!) #new_params.merge!({controller: options[:controller], sort: column, direction: direction, page: params[:page]}) link_to t("#{[:title]}"), new_params, {class: css_class, remote: true, title: t("#{[:title]}")} end |
#time_period(sdate, edate) ⇒ Object
165 166 167 168 169 |
# File 'app/helpers/component_helper.rb', line 165 def time_period(sdate, edate) strsdate = sdate.present? ? (mdate sdate) : "..." stredate = edate.present? ? (mdate edate) : "..." "#{strsdate} - #{stredate}" end |
#uneditable_input_control(value, label = ' ') ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'app/helpers/component_helper.rb', line 116 def uneditable_input_control(value, label = ' ') content_tag :div, class: "control-group" do content_tag(:label, label, class: "control-label") + content_tag(:div, class: "controls") do content_tag(:div, value, class: "uneditable-input-plain") end end end |
#uneditable_textarea_control(value, label = ' ') ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'app/helpers/component_helper.rb', line 126 def uneditable_textarea_control(value, label = ' ') content_tag :div, class: "control-group" do content_tag(:label, label, class: "control-label") + content_tag(:div, class: "controls") do content_tag(:div, value, class: "uneditable-textarea-plain") end end end |
#with_html_title(text) ⇒ Object
161 162 163 |
# File 'app/helpers/component_helper.rb', line 161 def with_html_title text "<span title='#{text}'>#{text}</span>".html_safe if text.present? end |