Module: AbstractResourcesHelper

Defined in:
app/helpers/abstract_resources_helper.rb

Instance Method Summary collapse

Instance Method Details

#activate_url(resource) ⇒ Object

activate and deactivate resources



168
169
170
# File 'app/helpers/abstract_resources_helper.rb', line 168

def activate_url resource
  '%s/activate' % url_for(resource)
end

#active_msg(active) ⇒ Object



392
393
394
# File 'app/helpers/abstract_resources_helper.rb', line 392

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



396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'app/helpers/abstract_resources_helper.rb', line 396

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(p, prefix = "") ⇒ Object



462
463
464
465
466
467
468
469
470
471
472
473
# File 'app/helpers/abstract_resources_helper.rb', line 462

def add_print_params p, prefix=""
  args = []
  p.each do |k,v|
    k = "#{prefix}[#{k}]" unless prefix.blank?
    if v.is_a? Hash
      args << add_print_params( v, 'print')
    else
      args << "#{k}=#{v}" unless %w{ ids action controller}.include? k
    end
  end
  args.join("&")
end

#attach_url(parent, resource) ⇒ Object

attach and detach resources



158
159
160
# File 'app/helpers/abstract_resources_helper.rb', line 158

def attach_url parent, resource
  '%s/%s/%s/attach' % [url_for( parent), resource.class.to_s.downcase.pluralize, resource.id]
end

set title of breadcrumb



505
506
507
508
509
# File 'app/helpers/abstract_resources_helper.rb', line 505

def breadcrumb_title( str )
  str.index( 'title="translation missing' ) ? str : str.mb_chars.upcase
rescue
  str
end

return a link - either to activate_resource_path or passify_resource_path used to turn on/off any resource



387
388
389
390
# File 'app/helpers/abstract_resources_helper.rb', line 387

def build_active_link resource
  lbl = resource.active ? ((:i, active_popover(true)) do end) : ((: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

return the url for the activate_link only



420
421
422
423
# File 'app/helpers/abstract_resources_helper.rb', line 420

def build_active_link_url resource
  r_url = url_for( resource)
  resource.active ? r_url + "/passify" : r_url + "/activate"
end

return a link to a new entity - possibly add route to parent



441
442
443
444
445
# File 'app/helpers/abstract_resources_helper.rb', line 441

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

return a link - either to attach_resource_path or detach_resource_path used to attach or detach a resource to its parent



427
428
429
430
431
# File 'app/helpers/abstract_resources_helper.rb', line 427

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

return the url for the attach_detach_link only



434
435
436
437
438
# File 'app/helpers/abstract_resources_helper.rb', line 434

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(button, options = {}) ⇒ Object

return button_tag 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



265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'app/helpers/abstract_resources_helper.rb', line 265

def build_button_tag button, options={}
  layout = options.delete(:link_layout) || {}
  text = layout.delete(:text) || ''
  title = layout.delete(:title) || ''
  icon = layout.delete(:icon) || ''
  (text << (:i,icon, class: button, title: title )).html_safe
  # if text
  #   content_tag( :span) do
  #     text[1]
  #   end << content_tag(:i,text[0], class: button )
  # else
  #   content_tag(:i,text[0], class: button )
  # end
end

#build_close_button(type) ⇒ Object



345
346
347
348
349
350
# File 'app/helpers/abstract_resources_helper.rb', line 345

def build_close_button(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


229
230
231
# File 'app/helpers/abstract_resources_helper.rb', line 229

def build_delete_link resource
  link_to((:i,'delete',class:'material-icons icon-trash'), resource, class: 'btn btn-mini delete_item', :"data-no-turbolink"=>true)
end

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



490
491
492
493
494
495
496
497
498
499
500
# File 'app/helpers/abstract_resources_helper.rb', line 490

def build_label_link resource, options={}

  list = options.delete(:list) || false
  button = options.delete(:button) || true
  url = options.delete(:url) || ( !list ? url_for( resource) + "/label" : url_for(resource_class.to_s.underscore.pluralize) + "/label?print_list=true&#{add_print_params}" )
  classes = options.delete(:classes) || ( button ? 'btn btn-mini' : '')

  return link_to((:i,nil,class:'icon-tag'), url, class: classes, target: '_new') if button
  link_to oxt(resource_class.to_s.underscore.pluralize.to_sym), url, options.merge( class: classes, target: '_new')

end

return a link - either to prefer_resource_path or defer_resource_path used to prefer or defer a resource by its parent



449
450
451
452
453
# File 'app/helpers/abstract_resources_helper.rb', line 449

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

return the url for the prefer_defer_link only



456
457
458
459
460
# File 'app/helpers/abstract_resources_helper.rb', line 456

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

return a link to print a row url: ” print: ‘what_list.html.haml’, layout: ‘list’|‘record’, range: ‘1,2,4-5’, medium: ‘printer’|‘display’|‘email’|‘download’, format: ‘html’|‘pdf’, printer: ‘name_of_printer’ data: { action: ”, method: ”, selector: ”, id: ”, osv. } button: ‘material-icons’|false either classes for a button or false => a link link_layout: { text: ”, title: ”, icon: ” } text for the link - or <a..>text<i title=“”>icon</i></a> 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



241
242
243
244
245
246
247
248
249
# File 'app/helpers/abstract_resources_helper.rb', line 241

def build_print_link resource, options={}
  url, list, options = build_resource_url(resource,options)
  button = options.delete(:button) || false
  options[:class] = options.delete(:classes) || ( button ? 'btn btn-mini' : '')
  options[:class] += ( list ? ' print_items' : ' print_item')
  return link_to( build_button_tag(button, options), url, options) if button
  text = options.delete(:text) || t(resource_class.to_s.underscore.pluralize.to_sym)
  link_to text, url, options
end

#build_resource_url(resource, options = {}) ⇒ Object

return an array url, list, options options{ url: ”, button: ”, classes: ”, text: ”}



253
254
255
256
257
258
259
260
# File 'app/helpers/abstract_resources_helper.rb', line 253

def build_resource_url resource, options={}
  print_options = options.delete(:print) || {}
  args = add_print_params params.merge( print: print_options)
  data_attribs = options.delete(:data) || {}
  list = print_options[:format]=='list' || false
  url = "%s/print?%s" % [ options.delete(:url) || ( !list ? url_for( resource) : url_for(resource_class.to_s.underscore.pluralize) ), args ]
  [ url, list, options.merge( data: data_attribs) ]
end

#build_toggle_white_collar_urlObject



475
476
477
478
479
480
481
# File 'app/helpers/abstract_resources_helper.rb', line 475

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

#column_header(field, options = {}) ⇒ Object

adding balloon helptext

column_header :some_field, balloon: true
( set the text to fixed with balloon: "FIXED TEXT - NOT TRANSLATED")
( set position with balloon_pos: "left")


565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# File 'app/helpers/abstract_resources_helper.rb', line 565

def column_header field, options={}
  options[:data] ||= {}
  # role = (options.delete :role) || ''
  # classes = (options.delete :class) || ''
  # id = (options.delete :id) || nil
  balloon = (options.delete :balloon) || false
  if balloon
    options[:data][:balloon] = (balloon.class==String) ? balloon : I18n.translate("tables.headers.#{field}.balloon")
    options[:data][:balloon_pos] = (options.delete :balloon_pos) || "up"
    options[:data][:balloon_length] = (options.delete :balloon_length) || "fit"
  end
  options[:data][:field] = (options.delete :field) || field
  options[:data][:direction] = (options.delete :direction) || @sorting_direction
  # txt = []
   :th, options do
    if options[:role] && options[:role]=="sort"
      mark_sorted options[:data][:field], I18n.translate( "tables.headers.#{field}.label")
    else
      I18n.translate( "tables.headers.#{field}.label")
    end
  end
end

#deactivate_url(resource) ⇒ Object



172
173
174
# File 'app/helpers/abstract_resources_helper.rb', line 172

def deactivate_url resource
  '%s/deactivate' % url_for( resource)
end

#defer_url(parent, resource) ⇒ Object



182
183
184
# File 'app/helpers/abstract_resources_helper.rb', line 182

def defer_url parent, resource
  '%s/%s/%s/defer' % [url_for( parent), resource.class.to_s.downcase.pluralize, resource.id]
end

#detach_url(parent, resource) ⇒ Object



162
163
164
# File 'app/helpers/abstract_resources_helper.rb', line 162

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



281
282
283
284
285
286
287
288
289
290
291
# File 'app/helpers/abstract_resources_helper.rb', line 281

def display_base_errors resource
  return '' if (resource.errors.empty?) or (resource.errors[:base].empty?)
  messages = resource.errors[:base].map { |msg| (:p, msg) }.join
  html = <<-HTML
  <div class="alert alert-error alert-block">
    <button type="button" class="close" data-dismiss="alert">&#215;</button>
    #{messages}
  </div>
  HTML
  html.html_safe
end

#divide_text(str, max_chars) ⇒ Object



317
318
319
320
321
322
323
324
# File 'app/helpers/abstract_resources_helper.rb', line 317

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



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'app/helpers/abstract_resources_helper.rb', line 108

def edit_resource_url(options={})
  opt = {}
  if options.class.ancestors.include? ActiveRecord::Base # edit_resource_url(@post)
    return '' if options.id.nil? # raise "'id' value nil - cannot build edit_resource_url"
    opt[:id] = options.id
  else
    opt.merge!(options) if options.class==Hash
  end
  opt[:action] = :edit
  resource_url opt
  # opt[:id] ||= @resource.id
  # opt[:controller] ||= @resource_class.table_name
  # url_for opt
end

#mark_sorted(col, label) ⇒ Object

mark_sorted will set a class depending on whether this column is sorted on



590
591
592
593
594
595
596
597
598
599
600
601
602
603
# File 'app/helpers/abstract_resources_helper.rb', line 590

def mark_sorted col, label
  if request.params[:s] == col
    (
      ( :span, label, class: "th-label-sort-by") +
      ( :i, class: "material-icons" do
        (request.params[:d]=='DESC' ? "arrow_drop_down" : "arrow_drop_up") rescue "arrow_drop_up"
      end)
    ).html_safe
  else
     :span, label, class: "th-label"
  end
rescue
   :span, label, class: "th-label"
end

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: {} }} }



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 365

def menu_item(items, level=0 )
  return "" if items.nil?
  str = []
  level+=1
  items.each do |k,item|
    options = 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]}", "#", options.merge(class: "dropdown-toggle", :"data-toggle"=>"dropdown")), menu_item(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, "#", options.merge(class: "dropdown-toggle", :"data-toggle"=>"dropdown")), menu_item(item[:url],level)]
      end
    else
      str << "<li>%s</li>" % link_to( item[:lbl], item[:url], options )
    end
  end
  str.join( "")
end

#new_resource_url(options = {}) ⇒ Object

new_resource_url returns a new entity



98
99
100
101
102
103
104
# File 'app/helpers/abstract_resources_helper.rb', line 98

def new_resource_url(options={})
  opt = {}
  opt.merge!(options) if options.class==Hash
  opt[:controller] ||= resource_class.table_name
  opt[:action] = :new
  url_for opt
end

#parentObject

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

Returns:

  • (Boolean)


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_classObject

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_nameObject

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_urlObject

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



178
179
180
# File 'app/helpers/abstract_resources_helper.rb', line 178

def prefer_url parent, resource
  '%s/%s/%s/prefer' % [url_for( parent), resource.class.to_s.downcase.pluralize, resource.id]
end

#resourceObject

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?

Returns:

  • (Boolean)


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_classObject

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_nameObject

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_options(options = {}) ⇒ Object



91
92
93
94
# File 'app/helpers/abstract_resources_helper.rb', line 91

def resource_options options={}
  options.merge! params.except( "id", "controller", "action", "utf8", "_method", "authenticity_token" )
  options.empty? ? "" : "?" + options.collect{ |k,v| "#{k}=#{v}" }.join("&")
end

#resource_url(options = {}) ⇒ Object

resource_url returns the current entity’s url



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/helpers/abstract_resources_helper.rb', line 72

def resource_url options={}
  r=request.path
  id=params[:id]
  options = case params[:action]
    when 'create','update','delete','destroy'; ""
    else resource_options(options)
  end
  return "%s%s" % [r,options] if r.match "\/#{resource.class.to_s.tableize}\/#{id}(|\/#{params[:action]})$"
  "%s%s" % [ r.split("/#{params[:action]}")[0], options]

  # opt = {}
  # opt[:id] = options.id if options.class.ancestors.include? ActiveRecord::Base # edit_resource_url(@post)
  # opt.merge!(options) if options.class==Hash
  # opt[:action] ||= 'show'
  # opt[:id] ||= resource.id
  # opt[:controller] ||= resource_class.table_name
  # url_for opt
end

#resourcesObject

returns the current collection of entities



128
129
130
# File 'app/helpers/abstract_resources_helper.rb', line 128

def resources
  @resources
end

#resources_nameObject

returns the resource_class pluralized - eg: stock_item => ‘stock_items’



134
135
136
# File 'app/helpers/abstract_resources_helper.rb', line 134

def resources_name
  resource_name.pluralize
end

#resources_url(resources = @resources, options = {}) ⇒ Object

resources_url returns the current collection of entities’ url



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'app/helpers/abstract_resources_helper.rb', line 140

def resources_url resources=@resources, options={}
  #
  # lnk = parent? ? (parent_url + "/#{resource_name}") : "/#{resource_name}"
  # lnk += options.empty? ? "" : "?" + options.collect{ |k,v| "#{k}=#{v}" }.join("&")
  options = resources if resources.class == Hash
  opt = {}
  opt.merge!(options) if options.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



188
189
190
191
192
193
# File 'app/helpers/abstract_resources_helper.rb', line 188

def set_attached_class children, child
  return "" unless parent?
  return "" if children.nil?
  return "detached" if children.empty?
  children.include?( child) ? "" : "detached"
end

#set_direction(dir) ⇒ Object

when sorting rows set_direction will flip ASC and DESC



541
542
543
544
# File 'app/helpers/abstract_resources_helper.rb', line 541

def set_direction dir
  return 'ASC' unless dir
  dir == 'ASC' ? 'DESC' : 'ASC'
end

#set_flashesObject

set_flashes will build the necessary flash

quite stolen from bootstrap_flash

  • but reengineered to avoid empty arrays



297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'app/helpers/abstract_resources_helper.rb', line 297

def set_flashes
  flash_messages = []
  flash.each do |type, message|
    next if message.blank?
    tp = 'danger'
    tp = 'success' if [ "notice", "info" ].include? type.to_s
    message = show_flash(flash, type) if flash.kind_of? Array
    unless message.blank?
      flash[type]=nil
      text = (:div, build_close_button(tp) + message.html_safe, class: "alert fade in alert-#{tp}")
      flash_messages << text
    end
  end
  flash.clear
  flash_messages.join("").html_safe
rescue => e
  Rails.logger.error "setting the flashes - set_flashes - failed with #{e.message}"
  ""
end

#set_toastsObject



326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'app/helpers/abstract_resources_helper.rb', line 326

def set_toasts
  toast_messages = []
  flash.each do |type, msg|
    message_arr = msg.size < 61 ? [msg] : divide_text( msg, [60,60,60,60] )
      message_arr.each do |message|
        case type
        when 'error','danger','alert'; toast_messages << "Materialize.toast('#{message}',8000, 'red darken-4');"
        when 'info'; toast_messages << "Materialize.toast('#{message}',2000, 'green lighten-3');"
        when 'success','notice'; toast_messages << "Materialize.toast('#{message}',2000, 'blue lighten-4');"
        end
      end
    end
  flash.clear
  toast_messages.join("").html_safe
rescue => e
  Rails.logger.error "setting the toasts - set_toasts - failed with #{e.message}"
  ""
end

#show_flash(flash, key) ⇒ Object

show_flash flash, key



355
356
357
358
359
# File 'app/helpers/abstract_resources_helper.rb', line 355

def show_flash flash, key
  msg = flash[key].kind_of?( Array) ? flash[key].flatten.compact : [ flash[key] ].compact
  msg.collect!{ |m| ((: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



523
524
525
# File 'app/helpers/abstract_resources_helper.rb', line 523

def show_lbl key
   :b, "#{key}: "
end

#show_page_titleObject

show_page_title does a resource_class and action based translation of title on a page



515
516
517
518
# File 'app/helpers/abstract_resources_helper.rb', line 515

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



529
530
531
532
533
534
535
536
# File 'app/helpers/abstract_resources_helper.rb', line 529

def  
  case 
  when /.jpg/, /.png/
    tag(:img, { class: "product_logo", src: "#{Rails.root}/app/assets/images/#{}" }, false)
  else
    
  end
end

#show_resource_active(item, linkable = true) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'app/helpers/abstract_resources_helper.rb', line 197

def show_resource_active item, linkable=true
  unless linkable
    if item.active
       :i, 'done', class: "material-icons small"
    else
       :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
         :i, 'done', class: 'material-icons'
      end
    else
      link_to activate_url(item), class: 'deactivated red-text', title: t("activate_#{item.resource_name}") do
         :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



219
220
221
222
223
224
225
226
# File 'app/helpers/abstract_resources_helper.rb', line 219

def show_resource_delete_icon item, url, lbl='name'
  link_to item, class: 'delete_link', data: { delete_title: t("delete_title"), delete_prompt: t("delete_prompt", item: t("delete_modal.#{item.class.to_s.underscore}")), delete_confirm: t("delete_confirm"), balloon: t("balloons.delete" ), balloon_pos: "left", url: url, name: "#{item.send lbl }", id: "#{item.id}", remove: "#tr-#{item.class.to_s}-#{item.id}" } do
     :i, 'delete', class: 'material-icons small'
  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