Skip to content

Commit

Permalink
Suggestions in columns
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmike committed Jun 1, 2014
1 parent 979479e commit 2736ea7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
2 changes: 2 additions & 0 deletions app/assets/stylesheets/distribution.css.sass
@@ -0,0 +1,2 @@
.add-recipient-button
margin: 6px 0
55 changes: 29 additions & 26 deletions app/views/distributions/recipient_suggestions.html.haml
@@ -1,27 +1,30 @@
= bootstrap_form_for Distribution.new do |f|
%ul.list-unstyled
- User.where('nickname LIKE ?', "%#{params[:text]}%").each do |user|
%li
- recipients = capture_haml do
= f.fields_for :tips, Tip.new(user_id: user.id), child_index: rand(1<<160) do |fields|
%tr
%td
= fields.hidden_field :user_id
= "#{user.nickname} (GitHub user)"
%td= fields.text_field :coin_amount, hide_label: true
%a.btn.btn-default.add-recipient-button{href: "#", data: {recipients: recipients}}= "#{user.nickname} (GitHub user)"
- if params[:text] =~ Devise::email_regexp
- user = User.where(email: params[:text]).first_or_initialize
%li
- recipients = capture_haml do
= f.fields_for :tips, Tip.new(user: user), child_index: rand(1<<160) do |fields|
%tr
%td
- if user.new_record?
= fields.fields_for :user do |user_fields|
= user_fields.hidden_field :email
- else
= fields.hidden_field :user_id
= user.recipient_label
%td= fields.text_field :coin_amount, hide_label: true
%a.btn.btn-default.add-recipient-button{href: "#", data: {recipients: recipients}}= user.recipient_label
- suggestions = []
- if params[:text] =~ Devise::email_regexp
- user = User.where(email: params[:text]).first_or_initialize
- recipients = capture_haml do
= f.fields_for :tips, Tip.new(user: user), child_index: rand(1<<160) do |fields|
%tr
%td
- if user.new_record?
= fields.fields_for :user do |user_fields|
= user_fields.hidden_field :email
- else
= fields.hidden_field :user_id
= user.recipient_label
%td= fields.text_field :coin_amount, hide_label: true
- suggestions << [user.recipient_label, recipients]
- User.where('nickname LIKE ?', "%#{params[:text]}%").each do |user|
- recipients = capture_haml do
= f.fields_for :tips, Tip.new(user_id: user.id), child_index: rand(1<<160) do |fields|
%tr
%td
= fields.hidden_field :user_id
= "#{user.nickname} (GitHub user)"
%td= fields.text_field :coin_amount, hide_label: true
- suggestions << [user.recipient_label, recipients]
- suggestions.each_slice(4) do |slice|
.row
- slice.each do |label, recipients|
.col-md-3
%a.btn.btn-block.btn-default.add-recipient-button{href: "#", data: {recipients: recipients}}= label

0 comments on commit 2736ea7

Please sign in to comment.