Module: Gaku::GakuHelper
- Includes:
- FlashHelper, SortHelper, TranslationsHelper
- Defined in:
- app/helpers/gaku/gaku_helper.rb
Instance Method Summary collapse
- #ajax_link_to_recovery(resource, options = {}) ⇒ Object
- #broadcast(channel, &block) ⇒ Object
- #can_edit? ⇒ Boolean
- #cannot_edit? ⇒ Boolean
- #color_code(color) ⇒ Object
- #comma_separated_list(objects, &block) ⇒ Object
- #current_controller_action ⇒ Object
- #current_parent_controller ⇒ Object
- #datepicker_date_format(date) ⇒ Object
- #disabled?(object) ⇒ Boolean
- #drag_field ⇒ Object
- #exam_completion_info(exam) ⇒ Object
- #extract_grouped(grouped, resource) ⇒ Object
- #genders ⇒ Object
- #icon(name) ⇒ Object
- #icon_label(icon_name, label) ⇒ Object
- #link_to_download(resource, options = {}) ⇒ Object
- #nested_header(text) ⇒ Object
- #prepare_resource_name(nested_resources, resource) ⇒ Object
- #prepare_target(nested_resource, address) ⇒ Object
- #render_js_partial(partial, locals = {}) ⇒ Object
- #required_field ⇒ Object
- #state_load(object) ⇒ Object
- #style_semester(date) ⇒ Object
- #title(text) ⇒ Object
- #tr_for(resource, &block) ⇒ Object
Instance Method Details
#ajax_link_to_recovery(resource, options = {}) ⇒ Object
136 137 138 139 140 141 142 143 |
# File 'app/helpers/gaku/gaku_helper.rb', line 136 def ajax_link_to_recovery(resource, = {}) name = content_tag(:span, nil, class: 'glyphicon glyphicon-repeat') attributes = { remote: true, class: "btn btn-xs btn-success recovery-link" }.merge() link_to name, resource, attributes end |
#broadcast(channel, &block) ⇒ Object
8 9 10 11 12 |
# File 'app/helpers/gaku/gaku_helper.rb', line 8 def broadcast(channel, &block) = {:channel => channel, :data => capture(&block)} uri = URI.parse("http://localhost:9292/faye") Net::HTTP.post_form(uri, :message => .to_json) end |
#can_edit? ⇒ Boolean
35 36 37 38 39 40 41 |
# File 'app/helpers/gaku/gaku_helper.rb', line 35 def can_edit? if controller.action_name.include?('edit') true else false end end |
#cannot_edit? ⇒ Boolean
43 44 45 |
# File 'app/helpers/gaku/gaku_helper.rb', line 43 def cannot_edit? ! can_edit? end |
#color_code(color) ⇒ Object
73 74 75 |
# File 'app/helpers/gaku/gaku_helper.rb', line 73 def color_code(color) content_tag :div, nil, style: "width:100px;height:20px;background-color:#{color}" end |
#comma_separated_list(objects, &block) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'app/helpers/gaku/gaku_helper.rb', line 79 def comma_separated_list(objects, &block) if objects.any? objects.map do |object| block_given? ? block.call(object) : object end.join(', ').html_safe else t(:empty) end end |
#current_controller_action ⇒ Object
25 26 27 |
# File 'app/helpers/gaku/gaku_helper.rb', line 25 def current_controller_action controller.action_name end |
#current_parent_controller ⇒ Object
21 22 23 |
# File 'app/helpers/gaku/gaku_helper.rb', line 21 def current_parent_controller controller.controller_path.split('/').second end |
#datepicker_date_format(date) ⇒ Object
108 109 110 |
# File 'app/helpers/gaku/gaku_helper.rb', line 108 def datepicker_date_format(date) date ? date.strftime('%Y-%m-%d') : Time.now.strftime('%Y-%m-%d') end |
#disabled?(object) ⇒ Boolean
124 125 126 |
# File 'app/helpers/gaku/gaku_helper.rb', line 124 def disabled?(object) object.new_record? || object.country.states.blank? end |
#drag_field ⇒ Object
29 30 31 32 33 |
# File 'app/helpers/gaku/gaku_helper.rb', line 29 def drag_field content_tag :td, class: 'sort-handler' do content_tag :i, nil, class: 'icon-move' end end |
#exam_completion_info(exam) ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'app/helpers/gaku/gaku_helper.rb', line 98 def exam_completion_info(exam) @course_students ||= @course.students ungraded = exam.ungraded(@course_students) total = exam.total_records(@course_students) percentage = number_to_percentage exam.completion(@course_students), precision: 2 "#{t(:'exam.completion')}:#{percentage} #{t(:'exam.graded')}:#{total - ungraded} #{t(:'exam.ungraded')}:#{ungraded} #{t(:'exam.total')}:#{total}" end |
#extract_grouped(grouped, resource) ⇒ Object
112 113 114 |
# File 'app/helpers/gaku/gaku_helper.rb', line 112 def extract_grouped(grouped, resource) grouped.map(&resource.to_sym) end |
#genders ⇒ Object
47 48 49 |
# File 'app/helpers/gaku/gaku_helper.rb', line 47 def genders { t(:'gender.female') => false, t(:'gender.male') => true } end |
#icon(name) ⇒ Object
145 146 147 |
# File 'app/helpers/gaku/gaku_helper.rb', line 145 def icon(name) content_tag(:span, nil, class: "#{name}") end |
#icon_label(icon_name, label) ⇒ Object
149 150 151 |
# File 'app/helpers/gaku/gaku_helper.rb', line 149 def icon_label(icon_name, label) raw %{ #{icon(icon_name)} #{label} } end |
#link_to_download(resource, options = {}) ⇒ Object
128 129 130 131 132 133 134 |
# File 'app/helpers/gaku/gaku_helper.rb', line 128 def link_to_download(resource, = {}) name = content_tag(:span, nil, class: 'glyphicon glyphicon-download') attributes = { class: "btn btn-xs btn-success download-link" }.merge() link_to name, resource, attributes end |
#nested_header(text) ⇒ Object
116 117 118 |
# File 'app/helpers/gaku/gaku_helper.rb', line 116 def nested_header(text) content_tag :h4, text end |
#prepare_resource_name(nested_resources, resource) ⇒ Object
94 95 96 |
# File 'app/helpers/gaku/gaku_helper.rb', line 94 def prepare_resource_name(nested_resources, resource) @resource_name = [nested_resources.map {|r| r.is_a?(Symbol) ? r.to_s : get_class(r) }, resource.to_s].flatten.join '-' end |
#prepare_target(nested_resource, address) ⇒ Object
89 90 91 92 |
# File 'app/helpers/gaku/gaku_helper.rb', line 89 def prepare_target(nested_resource, address) return nil if nested_resource.blank? [nested_resource, address].flatten end |
#render_js_partial(partial, locals = {}) ⇒ Object
59 60 61 62 63 64 65 |
# File 'app/helpers/gaku/gaku_helper.rb', line 59 def render_js_partial(partial, locals = {}) unless locals == {} escape_javascript(render partial: partial, formats: [:html], handlers: [:erb, :slim], locals: locals) else escape_javascript(render partial: partial, formats: [:html], handlers: [:erb, :slim]) end end |
#required_field ⇒ Object
55 56 57 |
# File 'app/helpers/gaku/gaku_helper.rb', line 55 def required_field content_tag :span, t(:required), class: 'label label-important pull-right' end |
#state_load(object) ⇒ Object
120 121 122 |
# File 'app/helpers/gaku/gaku_helper.rb', line 120 def state_load(object) object.country.nil? ? Gaku::State.none : object.country.states end |
#style_semester(date) ⇒ Object
51 52 53 |
# File 'app/helpers/gaku/gaku_helper.rb', line 51 def style_semester(date) date.strftime('') end |
#title(text) ⇒ Object
67 68 69 70 71 |
# File 'app/helpers/gaku/gaku_helper.rb', line 67 def title(text) content_for(:title) do text end end |
#tr_for(resource, &block) ⇒ Object
15 16 17 18 19 |
# File 'app/helpers/gaku/gaku_helper.rb', line 15 def tr_for(resource, &block) content_tag :tr, id: "#{resource.class.to_s.demodulize.underscore.dasherize}-#{resource.id}" do block.call end end |