selecting the group from the ask followers modal works now.

This commit is contained in:
nilsding 2015-01-13 15:45:32 +01:00
parent 9b0b2df18e
commit a05d763b75
4 changed files with 25 additions and 4 deletions

View File

@ -3,11 +3,18 @@ $(document).on "click", "button[name=qb-all-ask]", ->
btn.button "loading"
$("textarea[name=qb-all-question]").attr "readonly", "readonly"
rcptSelect = ($ 'select[name=qb-all-rcpt]')
rcpt = if rcptSelect.length > 0
rcptSelect.first().val()
else
'followers'
$.ajax
url: '/ajax/ask'
type: 'POST'
data:
rcpt: "followers"
rcpt: rcpt
question: $("textarea[name=qb-all-question]").val()
anonymousQuestion: false
success: (data, status, jqxhr) ->

View File

@ -25,6 +25,19 @@ class Ajax::QuestionController < ApplicationController
Inbox.create!(user_id: f.id, question_id: question.id, new: true)
end
end
elsif params[:rcpt].start_with? 'grp:'
unless current_user.nil?
begin
current_user.groups.find_by_name!(params[:rcpt].sub 'grp:', '').members.each do |m|
Inbox.create!(user_id: m.user.id, question_id: question.id, new: true)
end
rescue ActiveRecord::RecordNotFound
@status = :not_found
@message = "Group not found"
@success = false
return
end
end
else
Inbox.create!(user_id: params[:rcpt], question_id: question.id, new: true)
end

View File

@ -4,6 +4,7 @@ class Group < ActiveRecord::Base
before_validation do
self.name = self.display_name.downcase.sub(/\s+/, '-')
self.name = 'group-followers' if self.name == 'followers'
end
alias members group_members

View File

@ -12,10 +12,10 @@
- if current_user.groups.count > 0
%label
Choose group:
%select{name: 'qb-all-target', class: 'form-control', autocomplete: 'off'}
%option{value: '_followers', selected: true} Followers
%select{name: 'qb-all-rcpt', class: 'form-control', autocomplete: 'off'}
%option{value: 'followers', selected: true} Followers
%optgroup{label: 'Groups'}
- current_user.groups.each do |group|
%option{value: group.name}= group.display_name
%option{value: "grp:#{group.name}"}= group.display_name
%button.btn.btn-default{"data-dismiss" => "modal", :type => "button"} Cancel
%button.btn.btn-primary{name: 'qb-all-ask', :type => "button", data: {loading_text: 'Asking...' }} Ask