Module: FabButtonHelper
- Defined in:
- app/helpers/fab_button_helper.rb
Instance Method Summary collapse
-
#build_fab_button(options = {}) ⇒ Object
FAB Fixed Action Button.
-
#build_fab_options(resource, options = {}) ⇒ Object
do a ‘before_action :set_fab_button_options (that returns a Hash with list elements like: { items: { print: { ajax: ’get’, icon: ‘list’, class: ‘blue lighten-2’, url: ‘/stock_items/print?print_list=true’ } } })‘, add a special build_fab_options on your project - or use this default one.
- #fab_button_options ⇒ Object
Instance Method Details
#build_fab_button(options = {}) ⇒ Object
FAB Fixed Action Button
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/helpers/fab_button_helper.rb', line 5 def ={} list = <<LISTEND <li><a class="btn-floating red"><i class="material-icons">insert_chart</i></i></a></li> <li><a class="btn-floating yellow darken-1"><i class="material-icons">format_quote</i></a></li> <li><a class="btn-floating green"><i class="material-icons">publish</i></a></li> <li><a class="btn-floating blue"><i class="material-icons">attach_file</i></a></li> LISTEND = '<a class="btn-floating btn-large blue"> <i class="large material-icons">mode_edit</i> </a>' = '<div class="fixed-action-btn" style="bottom: 45px; right: 24px;">%s <ul> %s </ul> </div>' [:button] ||= [:list] ||= list [:menu] ||= ([:menu] % [ [:button], [:list]]).html_safe end |
#build_fab_options(resource, options = {}) ⇒ Object
do a ‘before_action :set_fab_button_options (that returns a Hash with list elements like:
{ items: { print: { ajax: 'get', icon: 'list', class: 'blue lighten-2', url: '/stock_items/print?print_list=true' } } })',
add a special build_fab_options on your project - or use this default one
AJAX: <a data-ajax=“post” data-remote=“false” data-url=“%s” class=“btn-floating green”><i class=“material-icons”>publish</i></a>
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/helpers/fab_button_helper.rb', line 33 def resource, ={} lst = [] # if items are empty - dream them up [:items] ||= {} [:items].merge!( list: { ajax: 'get', icon: 'list', class: 'blue', url: resources_url(resources, controller: params[:controller]), oxremote: 'false' }){ |key, v1, v2| v1 } case [:action] when 'new','create' [:items].merge!( reset: { action: 'reset', icon: 'undo', class: 'orange darken-2' }){ |key, v1, v2| v1 } [:items].merge!( publish: { ajax: 'post', icon: 'publish', class: 'green', url: resources_url(resources, controller: params[:controller]), oxremote: 'false' }){ |key, v1, v2| v1 } [:button] ||= "<a class='btn-floating btn-large green'><i class='large material-icons'>publish</i> </a>" when 'show' [:items].merge!( add: { ajax: 'get', icon: 'add', class: 'green lighten-1', url: new_resource_url, oxremote: 'false' }){ |key, v1, v2| v1 } [:items].merge!( edit: { ajax: 'get', icon: 'edit', class: 'yellow darken-2', url: edit_resource_url(resource), oxremote: 'false' }){ |key, v1, v2| v1 } [:items].merge!( delete: { ajax: 'delete', icon: 'delete', class: 'red darken-1', url: resources_url, id: resource.id, oxremote: 'false' }){ |key, v1, v2| v1 } [:button] ||= "<a class='btn-floating btn-large blue'><i class='fab-button large material-icons'>edit</i> </a>" when 'edit', 'update' [:items].merge!( add: { ajax: 'get', icon: 'add', class: 'green lighten-1', url: new_resource_url , oxremote: 'false'}){ |key, v1, v2| v1 } [:items].merge!( publish: { ajax: 'post', icon: 'publish', class: 'green', url: resource_url, oxremote: 'false' }){ |key, v1, v2| v1 } [:items].merge!( delete: { ajax: 'delete', icon: 'delete', class: 'red darken-1', url: resources_url, id: resource.id, oxremote: 'false' }){ |key, v1, v2| v1 } [:button] ||= "<a class='btn-floating btn-large green'><i class='large material-icons'>publish</i> </a>" when 'index' [:items].merge!( add: { ajax: 'get', icon: 'add', class: 'green lighten-1', url: new_resource_url(controller: params[:controller]), oxremote: 'false' }){ |key, v1, v2| v1 } [:button] ||= "<a class='btn-floating btn-large blue'><i class='fab-button large material-icons'>mode_edit</i> </a>" end if ![:items].nil? [:items].each do |k,item| next if item.empty? item[:ajax] ||= 'get' item[:action] ||= item[:ajax] item[:oxremote] ||= 'false' item[:class] ||= '' item[:icon] ||= '' item[:url] ||= '' item[:browser] ||= '' item[:remote] ||= 'false' item[:method] ||= item[:ajax] str = [] (item.keys - [:class,:icon]).each do |key| str << " data-%s='%s' " % [ key,item[key] ] end lst << "<li><a class='fab-button btn-floating %s' %s><i class='material-icons'>%s</i></a></li>" % [ item[:class], str.join, item[:icon] ] end end [:list] ||= lst.join end |
#fab_button_options ⇒ Object
22 23 24 |
# File 'app/helpers/fab_button_helper.rb', line 22 def @fab_button_options ||= {} #raise "fab_button_options nil - not what you intended, I guess?!" end |