Module: AbstractResourcesHelper
- Defined in:
- app/helpers/abstract_resources_helper.rb
Instance Method Summary collapse
-
#activate_url(resource) ⇒ Object
activate and deactivate resources.
- #active_msg(active) ⇒ Object
- #active_popover(active) ⇒ Object
-
#add_print_params ⇒ Object
def build_button_tag options={} text = options.include?(:text) ? options.delete(:text) : nil button = options.include?(:button) ? options.delete(:button) : false if text content_tag( :span) do text end << content_tag(:i,nil, class: button ) else content_tag(:i,nil, class: button ) end end.
-
#attach_url(parent, resource) ⇒ Object
attach and detach resources.
-
#breadcrumb_title(str) ⇒ Object
set title of breadcrumb.
-
#build_active_link(resource) ⇒ Object
return a link - either to activate_resource_path or passify_resource_path used to turn on/off any resource.
-
#build_active_link_url(resource) ⇒ Object
return the url for the activate_link only.
-
#build_add_link(lbl, cls) ⇒ Object
return a link to a new entity - possibly add route to parent.
-
#build_attach_link(children, child) ⇒ Object
return a link - either to attach_resource_path or detach_resource_path used to attach or detach a resource to its parent.
-
#build_attach_link_url(child, attached) ⇒ Object
return the url for the attach_detach_link only.
- #build_button_tag(options = {}) ⇒ Object
- #build_close_button(type) ⇒ Object
- #build_delete_link(resource) ⇒ Object
-
#build_label_link(resource, options = {}) ⇒ Object
return a link to print a label for a row url: ” list: true|false template: ‘what_list.html.haml’, button: true|false either a button or a link classes: ‘btn btn-mini print_item print_items …’ jquery hooks print_item will print a specific record, print_items will print a list of records.
-
#build_prefer_link(children, child) ⇒ Object
return a link - either to prefer_resource_path or defer_resource_path used to prefer or defer a resource by its parent.
-
#build_prefer_link_url(child, preferred) ⇒ Object
return the url for the prefer_defer_link only.
-
#build_print_link(resource, options = {}) ⇒ Object
return a link to print a row url: ” list: true|false template: ‘what_list.html.haml’, button: true|false either a button or a link text: ‘what to write on the link if at all’ classes: ‘btn btn-mini print_item print_items …’ jquery hooks print_item will print a specific record, print_items will print a list of records.
-
#build_toggle_white_collar_url ⇒ Object
def add_from_to_params return “” if params.blank? “&from=#:from&until=#:until” end.
- #deactivate_url(resource) ⇒ Object
- #defer_url(parent, resource) ⇒ Object
- #detach_url(parent, resource) ⇒ Object
- #display_base_errors(resource) ⇒ Object
- #divide_text(str, max_chars) ⇒ Object
-
#edit_resource_url(options = {}) ⇒ Object
edit_resource_url returns the current entity’s url for editing.
-
#menu_item(items, level = 0) ⇒ Object
return a HTML fragtment containing the menu_items referring to this one items is a Hash of three elements, lbl, url and possible any children { item: { lbl: ‘menu’, url: ‘menu’, options: {} } } { item: { lbl: ‘menu’, url: { item: {}, item: {} }} }.
-
#new_resource_url(options = {}) ⇒ Object
new_resource_url returns a new entity.
-
#parent ⇒ Object
parent returns the parent entity.
-
#parent? ⇒ Boolean
parent? will tell if a parent exists.
-
#parent_class ⇒ Object
parent_class returns the class of the parent.
-
#parent_name ⇒ Object
parent_name returns the name of the resource - that would be the empty string on nil’s.
-
#parent_url ⇒ Object
parent_url returns the parent url - /employees/1 in the /employees/1/events.
-
#prefer_url(parent, resource) ⇒ Object
prefer and defer resources - like printers.
-
#resource ⇒ Object
resource returns the current entity.
-
#resource? ⇒ Boolean
did we manage to set a resource at all?.
-
#resource_class ⇒ Object
resource_class is the class which the resource represent.
-
#resource_name ⇒ Object
return the name of the resource - that would be the empty string on nil’s.
-
#resource_url(options = {}) ⇒ Object
resource_url returns the current entity’s url.
-
#resources ⇒ Object
returns the current collection of entities.
-
#resources_name ⇒ Object
returns the resource_class pluralized - eg: stock_item => ‘stock_items’.
-
#resources_url(resources = @resources, options = {}) ⇒ Object
resources_url returns the current collection of entities’ url.
-
#set_attached_class(children, child) ⇒ Object
List Helpers.
-
#set_flashes ⇒ Object
set_flashes will build the necessary flash.
- #set_toasts ⇒ Object
-
#show_flash(flash, key) ⇒ Object
show_flash flash, key - flash=nil.
-
#show_lbl(key) ⇒ Object
show_lbl is used on every show.html.haml to build the label.
-
#show_page_title ⇒ Object
show_page_title does a resource_class and action based translation of title on a page.
-
#show_product_logo(product_logo) ⇒ Object
on imprint_certificate.html.haml.
- #show_resource_active(item, linkable = true) ⇒ Object
-
#show_resource_delete_icon(item, url, lbl = 'name') ⇒ Object
return a link to delete a row.
Instance Method Details
#activate_url(resource) ⇒ Object
activate and deactivate resources
149 150 151 |
# File 'app/helpers/abstract_resources_helper.rb', line 149 def activate_url resource '%s/activate' % url_for(resource) end |
#active_msg(active) ⇒ Object
358 359 360 |
# File 'app/helpers/abstract_resources_helper.rb', line 358 def active_msg active active ? "Er aktiv nu! Tryk på denne knap for at gøre denne post passiv!" : "Er passiv nu! Tryk på denne knap for at gøre denne post aktiv!" end |
#active_popover(active) ⇒ Object
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'app/helpers/abstract_resources_helper.rb', line 362 def active_popover active if active { class: "icon-minus", rel: "popover", :"data-html" => true, :"data-trigger" => "hover", :"data-title" => "Posten er aktiv!", :"data-content" => "Tryk på denne knap for at gøre denne post passiv!</br/>Når poster anvendes i andre sammenhænge vil oxenServer kun tage hensyn til aktive poster!", } else { class: "icon-plus", rel: "popover", :"data-html" => true, :"data-trigger" => "hover", :"data-title" => "Posten er passiv!", :"data-content" => "Tryk på denne knap for at gøre denne post aktiv!</br/>Når poster anvendes i andre sammenhænge vil oxenServer kun tage hensyn til aktive poster!", } end end |
#add_print_params ⇒ Object
def build_button_tag options={}
text = .include?(:text) ? .delete(:text) : nil
= .include?(:button) ? .delete(:button) : false
if text
content_tag( :span) do
text
end << content_tag(:i,nil, class: )
else
content_tag(:i,nil, class: )
end
end
461 462 463 464 465 466 467 |
# File 'app/helpers/abstract_resources_helper.rb', line 461 def add_print_params args = [] params.each do |k,v| args << "#{k}=#{v}" unless %w{ ids action controller}.include? k end args.join("&") end |
#attach_url(parent, resource) ⇒ Object
attach and detach resources
139 140 141 |
# File 'app/helpers/abstract_resources_helper.rb', line 139 def attach_url parent, resource '%s/%s/%s/attach' % [url_for( parent), resource.class.to_s.downcase.pluralize, resource.id] end |
#breadcrumb_title(str) ⇒ Object
set title of breadcrumb
504 505 506 507 508 |
# File 'app/helpers/abstract_resources_helper.rb', line 504 def ( str ) str.index( 'title="translation missing' ) ? str : str.mb_chars.upcase rescue str end |
#build_active_link(resource) ⇒ Object
return a link - either to activate_resource_path or passify_resource_path used to turn on/off any resource
353 354 355 356 |
# File 'app/helpers/abstract_resources_helper.rb', line 353 def build_active_link resource lbl = resource.active ? (content_tag(:i, active_popover(true)) do end) : (content_tag(:i, active_popover(false)) do end) link_to lbl, build_active_link_url(resource), class: "btn btn-mini active_button", remote: true, :"data-no-turbolink" => true, id: "%s_%i_actpas" % [resource.class.to_s, resource.id] end |
#build_active_link_url(resource) ⇒ Object
return the url for the activate_link only
386 387 388 389 |
# File 'app/helpers/abstract_resources_helper.rb', line 386 def build_active_link_url resource r_url = url_for( resource) resource.active ? r_url + "/passify" : r_url + "/activate" end |
#build_add_link(lbl, cls) ⇒ Object
return a link to a new entity - possibly add route to parent
407 408 409 410 411 |
# File 'app/helpers/abstract_resources_helper.rb', line 407 def build_add_link lbl, cls r_url = cls.to_s.singularize.underscore r_url = parent? ? parent.class.to_s.singularize.underscore + "_" + r_url : r_url link_to( lbl, eval("new_%s_path" % r_url), class: 'btn btn-success') end |
#build_attach_link(children, child) ⇒ Object
return a link - either to attach_resource_path or detach_resource_path used to attach or detach a resource to its parent
393 394 395 396 397 |
# File 'app/helpers/abstract_resources_helper.rb', line 393 def build_attach_link children, child attached = children.nil? ? false : children.include?( child) lbl = attached ? t(:detach) : t(:attach) link_to lbl, build_attach_link_url(child,attached), class: "btn btn-mini", remote: true, :"data-no-turbolink" => true, id: "%s_%i_attdet" % [child.class.to_s, child.id] end |
#build_attach_link_url(child, attached) ⇒ Object
return the url for the attach_detach_link only
400 401 402 403 404 |
# File 'app/helpers/abstract_resources_helper.rb', line 400 def build_attach_link_url child, attached path = request.path.match( /detach|attach/) ? request.path.split("/")[0..3].join("/") : request.path r_url = path + "/%i" % child.id attached ? r_url + "/detach" : r_url + "/attach" end |
#build_button_tag(options = {}) ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 |
# File 'app/helpers/abstract_resources_helper.rb', line 234 def ={} text = .include?(:text) ? .delete(:text) : nil = .include?(:button) ? .delete(:button) : false if text content_tag( :span) do text end << content_tag(:i,nil, class: ) else content_tag(:i,nil, class: ) end end |
#build_close_button(type) ⇒ Object
311 312 313 314 315 316 |
# File 'app/helpers/abstract_resources_helper.rb', line 311 def (type) "<a href='#!' class='#{type} close-notice btn-floating btn-small waves-effect waves-light' aria-hidden='true' type='button' data-dismiss='alert'><i class='material-icons'>close</i></a>".html_safe # link_to "#", type: "button", "aria-hidden" => "true", class: "#{type} close-notice btn-floating btn-small waves-effect waves-light", "data-dismiss" => "alert" do # "<i class='material-icons'>close</i>".html_safe # end end |
#build_delete_link(resource) ⇒ Object
209 210 211 |
# File 'app/helpers/abstract_resources_helper.rb', line 209 def build_delete_link resource link_to(content_tag(:i,'delete',class:'material-icons icon-trash'), resource, class: 'btn btn-mini delete_item', :"data-no-turbolink"=>true) end |
#build_label_link(resource, options = {}) ⇒ Object
return a link to print a label for a row url: ” list: true|false template: ‘what_list.html.haml’, button: true|false either a button or a link classes: ‘btn btn-mini print_item print_items …’ jquery hooks print_item will print a specific record, print_items will print a list of records
489 490 491 492 493 494 495 496 497 498 499 |
# File 'app/helpers/abstract_resources_helper.rb', line 489 def build_label_link resource, ={} list = .delete(:list) || false = .delete(:button) || true url = .delete(:url) || ( !list ? url_for( resource) + "/label" : url_for(resource_class.to_s.underscore.pluralize) + "/label?print_list=true&#{add_print_params}" ) classes = .delete(:classes) || ( ? 'btn btn-mini' : '') return link_to(content_tag(:i,nil,class:'icon-tag'), url, class: classes, target: '_new') if link_to oxt(resource_class.to_s.underscore.pluralize.to_sym), url, .merge( class: classes, target: '_new') end |
#build_prefer_link(children, child) ⇒ Object
return a link - either to prefer_resource_path or defer_resource_path used to prefer or defer a resource by its parent
415 416 417 418 419 |
# File 'app/helpers/abstract_resources_helper.rb', line 415 def build_prefer_link children, child preferred = (children.include?( child) && child.preferred?( parent)) return oxt(:preferred) if preferred link_to oxt(:prefer), build_prefer_link_url(child,preferred), class: "btn btn-mini", remote: true, :"data-no-turbolink" => true, id: "%s_%i_predet" % [child.class.to_s, child.id] end |
#build_prefer_link_url(child, preferred) ⇒ Object
return the url for the prefer_defer_link only
422 423 424 425 426 |
# File 'app/helpers/abstract_resources_helper.rb', line 422 def build_prefer_link_url child, preferred path = request.path.match( /defer|prefer/) ? request.path.split("/")[0..3].join("/") : request.path r_url = path + "/%i" % child.id preferred ? r_url + "/defer" : r_url + "/prefer" end |
#build_print_link(resource, options = {}) ⇒ Object
return a link to print a row url: ” list: true|false template: ‘what_list.html.haml’, button: true|false either a button or a link text: ‘what to write on the link if at all’ classes: ‘btn btn-mini print_item print_items …’ jquery hooks print_item will print a specific record, print_items will print a list of records
220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'app/helpers/abstract_resources_helper.rb', line 220 def build_print_link resource, ={} list = .include?(:list) ? .delete(:list) : true = .include?(:button) ? [:button] : false = .include?(:print_options) ? "?" + .delete(:print_options) : "" url = .include?(:url) ? .delete(:url) : ( !list ? url_for( resource) + "/print" + : url_for(resource_class.to_s.underscore.pluralize) + "/print?print_list=true&#{add_print_params}" ) classes = .include?(:classes) ? .delete(:classes) : ( ? 'btn btn-mini' : '') classes += ( list ? ' print_items' : ' print_item') return link_to( (), url, class: classes) if .include?(:button) link_to t(resource_class.to_s.underscore.pluralize.to_sym), url, .merge( classes: classes) end |
#build_toggle_white_collar_url ⇒ Object
def add_from_to_params
return "" if params[:from].blank?
"&from=#{params[:from]}&until=#{params[:until]}"
end
474 475 476 477 478 479 480 |
# File 'app/helpers/abstract_resources_helper.rb', line 474 def build_toggle_white_collar_url if params[:blue_collar].nil? link_to oxt(:kun_timelønnede), collection_url(blue_collar: true), class: "btn btn-info" else link_to oxt(:alle_medarbejdere), collection_url, class: "btn btn-info" end end |
#deactivate_url(resource) ⇒ Object
153 154 155 |
# File 'app/helpers/abstract_resources_helper.rb', line 153 def deactivate_url resource '%s/deactivate' % url_for( resource) end |
#defer_url(parent, resource) ⇒ Object
163 164 165 |
# File 'app/helpers/abstract_resources_helper.rb', line 163 def defer_url parent, resource '%s/%s/%s/defer' % [url_for( parent), resource.class.to_s.downcase.pluralize, "{{id}}"] end |
#detach_url(parent, resource) ⇒ Object
143 144 145 |
# File 'app/helpers/abstract_resources_helper.rb', line 143 def detach_url parent, resource '%s/%s/%s/detach' % [url_for( parent), resource.class.to_s.downcase.pluralize, resource.id] end |
#display_base_errors(resource) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 |
# File 'app/helpers/abstract_resources_helper.rb', line 247 def display_base_errors resource return '' if (resource.errors.empty?) or (resource.errors[:base].empty?) = resource.errors[:base].map { |msg| content_tag(:p, msg) }.join html = <<-HTML <div class="alert alert-error alert-block"> <button type="button" class="close" data-dismiss="alert">×</button> #{} </div> HTML html.html_safe end |
#divide_text(str, max_chars) ⇒ Object
283 284 285 286 287 288 289 290 |
# File 'app/helpers/abstract_resources_helper.rb', line 283 def divide_text(str, max_chars) max_chars.map do |n| str.lstrip! s = str[/^.{,#{n}}(?=\b)/] || '' str = str[s.size..-1] s end end |
#edit_resource_url(options = {}) ⇒ Object
edit_resource_url returns the current entity’s url for editing
94 95 96 97 98 99 100 101 102 103 |
# File 'app/helpers/abstract_resources_helper.rb', line 94 def edit_resource_url(={}) opt = {} opt[:id] = .id if .class.ancestors.include? ActiveRecord::Base opt.merge!() if .class==Hash opt[:action] = :edit resource_url opt # opt[:id] ||= @resource.id # opt[:controller] ||= @resource_class.table_name # url_for opt end |
#menu_item(items, level = 0) ⇒ Object
return a HTML fragtment containing the menu_items referring to this one items is a Hash of three elements, lbl, url and possible any children { item: { lbl: ‘menu’, url: ‘menu’, options: {} } } { item: { lbl: ‘menu’, url: { item: {}, item: {} }} }
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'app/helpers/abstract_resources_helper.rb', line 331 def (items, level=0 ) return "" if items.nil? str = [] level+=1 items.each do |k,item| = item[:options] || {} unless item[:url].class==String if level>1 str << "<li class='dropdown-submenu'>%s<ul class='dropdown-menu'>%s</ul></li>" % [ link_to( "#{item[:lbl]}", "#", .merge(class: "dropdown-toggle", :"data-toggle"=>"dropdown")), (item[:url],level)] else str << "<li class='dropdown'>%s<ul class='dropdown-menu'>%s</ul></li>" % [ link_to( "#{item[:lbl]}<b class='caret'></b>".html_safe, "#", .merge(class: "dropdown-toggle", :"data-toggle"=>"dropdown")), (item[:url],level)] end else str << "<li>%s</li>" % link_to( item[:lbl], item[:url], ) end end str.join( "") end |
#new_resource_url(options = {}) ⇒ Object
new_resource_url returns a new entity
84 85 86 87 88 89 90 |
# File 'app/helpers/abstract_resources_helper.rb', line 84 def new_resource_url(={}) opt = {} opt.merge!() if .class==Hash opt[:controller] ||= resource_class.table_name opt[:action] = :new url_for opt end |
#parent ⇒ Object
parent returns the parent entity
10 11 12 |
# File 'app/helpers/abstract_resources_helper.rb', line 10 def parent parent? ? @parent : raise("parent will return nil - which probably was not anticipated!") end |
#parent? ⇒ Boolean
parent? will tell if a parent exists
34 35 36 37 |
# File 'app/helpers/abstract_resources_helper.rb', line 34 def parent? return true if (params[:parent] && params[:parent_id] && @parent = params[:parent].classify.constantize.find(params[:parent_id])) !(%w{NilClass TrueClass FalseClass}.include? @parent.class.to_s) end |
#parent_class ⇒ Object
parent_class returns the class of the parent
16 17 18 |
# File 'app/helpers/abstract_resources_helper.rb', line 16 def parent_class parent? ? @parent.class : raise("parent_class will return Object - which probably was not anticipated!") end |
#parent_name ⇒ Object
parent_name returns the name of the resource - that would be the empty string on nil’s
22 23 24 |
# File 'app/helpers/abstract_resources_helper.rb', line 22 def parent_name parent? ? parent_class.to_s.pluralize.underscore : raise("parent_name will return '' - which probably was not anticipated!") end |
#parent_url ⇒ Object
parent_url returns the parent url - /employees/1 in the /employees/1/events
28 29 30 |
# File 'app/helpers/abstract_resources_helper.rb', line 28 def parent_url parent? ? ( "/" + parent_class.to_s.pluralize.underscore + "/%s" % @parent.id) : "no_route_to_parent" end |
#prefer_url(parent, resource) ⇒ Object
prefer and defer resources - like printers
159 160 161 |
# File 'app/helpers/abstract_resources_helper.rb', line 159 def prefer_url parent, resource '%s/%s/%s/prefer' % [url_for( parent), resource.class.to_s.downcase.pluralize, resource.id] end |
#resource ⇒ Object
resource returns the current entity
50 51 52 |
# File 'app/helpers/abstract_resources_helper.rb', line 50 def resource resource? ? @resource : nil end |
#resource? ⇒ Boolean
did we manage to set a resource at all?
44 45 46 |
# File 'app/helpers/abstract_resources_helper.rb', line 44 def resource? !(%w{NilClass TrueClass FalseClass}.include? @resource.class.to_s) end |
#resource_class ⇒ Object
resource_class is the class which the resource represent
63 64 65 66 67 68 |
# File 'app/helpers/abstract_resources_helper.rb', line 63 def resource_class return @resource_class if resource? @resource_class = params[:controller].singularize.classify.constantize rescue raise("resource_class will return Object - which probably was not anticipated!") end |
#resource_name ⇒ Object
return the name of the resource - that would be the empty string on nil’s
57 58 59 |
# File 'app/helpers/abstract_resources_helper.rb', line 57 def resource_name resource? ? resource.resource_name : resource_class.to_s.underscore.pluralize end |
#resource_url(options = {}) ⇒ Object
resource_url returns the current entity’s url
72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/abstract_resources_helper.rb', line 72 def resource_url ={} opt = {} opt[:id] = .id if .class.ancestors.include? ActiveRecord::Base opt.merge!() if .class==Hash opt[:action] ||= 'show' opt[:id] ||= resource.id opt[:controller] ||= resource_class.table_name url_for opt end |
#resources ⇒ Object
returns the current collection of entities
110 111 112 |
# File 'app/helpers/abstract_resources_helper.rb', line 110 def resources @resources end |
#resources_name ⇒ Object
returns the resource_class pluralized - eg: stock_item => ‘stock_items’
116 117 118 |
# File 'app/helpers/abstract_resources_helper.rb', line 116 def resources_name resource_name.pluralize end |
#resources_url(resources = @resources, options = {}) ⇒ Object
resources_url returns the current collection of entities’ url
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'app/helpers/abstract_resources_helper.rb', line 122 def resources_url resources=@resources, ={} # # lnk = parent? ? (parent_url + "/#{resource_name}") : "/#{resource_name}" # lnk += options.empty? ? "" : "?" + options.collect{ |k,v| "#{k}=#{v}" }.join("&") opt = {} opt.merge!() if .class==Hash opt[:controller] ||= resource_class.table_name opt[:action] ||= :index url_for opt rescue # # return the root_url if no route was found! root_url end |
#set_attached_class(children, child) ⇒ Object
List Helpers
171 172 173 174 175 176 |
# File 'app/helpers/abstract_resources_helper.rb', line 171 def set_attached_class children, child return "" unless parent? return "" if children.nil? return "detached" if children.empty? children.include?( child) ? "" : "detached" end |
#set_flashes ⇒ Object
set_flashes will build the necessary flash
quite stolen from bootstrap_flash
-
but reengineered to avoid empty arrays
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'app/helpers/abstract_resources_helper.rb', line 263 def set_flashes = [] flash.each do |type, | next if .blank? tp = 'danger' tp = 'success' if [ "notice", "info" ].include? type.to_s = show_flash(flash, type) if flash.kind_of? Array unless .blank? flash[type]=nil text = content_tag(:div, (tp) + .html_safe, class: "alert fade in alert-#{tp}") << text end end flash.clear .join("").html_safe rescue => e Rails.logger.error "setting the flashes - set_flashes - failed with #{e.}" "" end |
#set_toasts ⇒ Object
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'app/helpers/abstract_resources_helper.rb', line 292 def set_toasts = [] flash.each do |type, | = .size < 61 ? [] : divide_text( , [60,60,60,60] ) .each do || case type when 'error','danger','alert'; << "Materialize.toast('#{}',8000, 'red darken-4');" when 'info'; << "Materialize.toast('#{}',2000, 'green lighten-3');" when 'success','notice'; << "Materialize.toast('#{}',2000, 'blue lighten-4');" end end end flash.clear .join("").html_safe rescue => e Rails.logger.error "setting the toasts - set_toasts - failed with #{e.}" "" end |
#show_flash(flash, key) ⇒ Object
show_flash flash, key
-
flash=nil
321 322 323 324 325 |
# File 'app/helpers/abstract_resources_helper.rb', line 321 def show_flash flash, key msg = flash[key].kind_of?( Array) ? flash[key].flatten.compact : [ flash[key] ].compact msg.collect!{ |m| (content_tag(:div, id: key) do m end) unless m.blank? } raw(msg.join) end |
#show_lbl(key) ⇒ Object
show_lbl is used on every show.html.haml to build the label
522 523 524 |
# File 'app/helpers/abstract_resources_helper.rb', line 522 def show_lbl key content_tag :b, "#{key}: " end |
#show_page_title ⇒ Object
show_page_title does a resource_class and action based translation of title on a page
514 515 516 517 |
# File 'app/helpers/abstract_resources_helper.rb', line 514 def show_page_title # t '%s.%s.title' % [ resource_class.table_name, params[:action] ] t '%s.%s.title' % [ params[:controller], params[:action] ] end |
#show_product_logo(product_logo) ⇒ Object
on imprint_certificate.html.haml
528 529 530 531 532 533 534 535 |
# File 'app/helpers/abstract_resources_helper.rb', line 528 def show_product_logo product_logo case product_logo when /.jpg/, /.png/ tag(:img, { class: "product_logo", src: "#{Rails.root}/app/assets/images/#{product_logo}" }, false) else product_logo end end |
#show_resource_active(item, linkable = true) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'app/helpers/abstract_resources_helper.rb', line 179 def show_resource_active item, linkable=true unless linkable if item.active content_tag :i, 'done', class: "material-icons small" else content_tag :i, 'pause', class: "material-icons small" end else if item.active link_to deactivate_url(item), class: 'activated green-text', title: t("deactivate_#{item.resource_name}") do content_tag :i, 'done', class: 'material-icons' end else link_to activate_url(item), class: 'deactivated red-text', title: t("activate_#{item.resource_name}") do content_tag :i, 'pause', class: 'material-icons' end end end end |
#show_resource_delete_icon(item, url, lbl = 'name') ⇒ Object
return a link to delete a row
201 202 203 204 205 206 207 208 |
# File 'app/helpers/abstract_resources_helper.rb', line 201 def show_resource_delete_icon item, url, lbl='name' link_to item, class: 'delete_link', data: { url: url, name: "#{item.send lbl }", id: "#{item.id}", remove: "#tr-#{item.id}" } do content_tag :i, 'delete', class: 'material-icons small', title: "#{t('.delete')}" end # = link_to account, class: 'delete_link', data: { url: '/admin/accounts', name: "#{account.name}", id: "#{account.id}", remove: "#tr-#{account.id}" } do # %i.material-icons.small{ title: "#{t('.delete')}"} delete end |