module FabButtonHelper # FAB # Fixed Action Button def build_fab_button options={} list = <insert_chart
  • format_quote
  • publish
  • attach_file
  • LISTEND button = ' mode_edit ' menu = '
    %s
    ' options[:button] ||= button options[:list] ||= list options[:menu] ||= menu (options[:menu] % [ options[:button], options[:list]]).html_safe end def fab_button_options @fab_button_options ||= {} #raise "fab_button_options nil - not what you intended, I guess?!" end # 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: publish # def build_fab_options resource, options={} lst = [] # if items are empty - dream them up options[:items] ||= {} options[:items].merge!( list: { ajax: 'get', icon: 'list', class: 'blue', url: resources_url(resources, controller: params[:controller]), oxremote: 'false' }){ |key, v1, v2| v1 } case options[:action] when 'new','create' options[:items].merge!( reset: { action: 'reset', icon: 'undo', class: 'orange darken-2' }){ |key, v1, v2| v1 } options[:items].merge!( publish: { ajax: 'post', icon: 'publish', class: 'green', url: resources_url(resources, controller: params[:controller]), oxremote: 'false' }){ |key, v1, v2| v1 } options[:button] ||= "publish " when 'show' options[:items].merge!( add: { ajax: 'get', icon: 'add', class: 'green lighten-1', url: new_resource_url, oxremote: 'false' }){ |key, v1, v2| v1 } options[:items].merge!( edit: { ajax: 'get', icon: 'edit', class: 'yellow darken-2', url: edit_resource_url(resource), oxremote: 'false' }){ |key, v1, v2| v1 } options[:items].merge!( delete: { ajax: 'delete', icon: 'delete', class: 'red darken-1', url: resources_url, id: resource.id, oxremote: 'false' }){ |key, v1, v2| v1 } options[:button] ||= "edit " when 'edit', 'update' options[:items].merge!( add: { ajax: 'get', icon: 'add', class: 'green lighten-1', url: new_resource_url , oxremote: 'false'}){ |key, v1, v2| v1 } options[:items].merge!( publish: { ajax: 'post', icon: 'publish', class: 'green', url: resource_url, oxremote: 'false' }){ |key, v1, v2| v1 } options[:items].merge!( delete: { ajax: 'delete', icon: 'delete', class: 'red darken-1', url: resources_url, id: resource.id, oxremote: 'false' }){ |key, v1, v2| v1 } options[:button] ||= "publish " when 'index' options[:items].merge!( add: { ajax: 'get', icon: 'add', class: 'green lighten-1', url: new_resource_url(controller: params[:controller]), oxremote: 'false' }){ |key, v1, v2| v1 } options[:button] ||= "mode_edit " end if !options[:items].nil? options[: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 << "
  • %s
  • " % [ item[:class], str.join, item[:icon] ] end end options[:list] ||= lst.join options end end