Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add messaging to order (closes #327) #350

Merged
merged 1 commit into from Apr 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/views/orders/_show_js.html.haml
@@ -0,0 +1,20 @@
-# this needs to be in a separate file from show.html.erb to allow deface overrides
- content_for :javascript do
:javascript
function activate_search(view, placeholder) {
new List(document.body, {
valueNames: ['name'],
engine: 'unlist',
plugins: [
['reset', {highlightClass: 'btn-primary'}],
['delay', {delayedSearchTime: 500}],
],
// make large pages work too (as we don't have paging)
page: 10000,
indexAsync: true
});
$('#query').attr('placeholder', placeholder);
}
$(function() {
activate_search('#{j @view}', '#{j t(".search_placeholder.#{@view}")}');
});
22 changes: 1 addition & 21 deletions app/views/orders/show.html.haml
Expand Up @@ -79,25 +79,5 @@
#new_comment= render partial: 'order_comments/form', locals: { order_comment: @order.comments.build(user: current_user)}
= link_to_top


- content_for :javascript do
:javascript
function activate_search(view, placeholder) {
new List(document.body, {
valueNames: ['name'],
engine: 'unlist',
plugins: [
['reset', {highlightClass: 'btn-primary'}],
['delay', {delayedSearchTime: 500}],
],
// make large pages work too (as we don't have paging)
page: 10000,
indexAsync: true
});
$('#query').attr('placeholder', placeholder);
}
$(function() {
activate_search('#{j @view}', '#{j t(".search_placeholder.#{@view}")}');
});

= render 'show_js'
= render 'shared/articles_by/common', order: @order
7 changes: 7 additions & 0 deletions plugins/messages/app/models/message.rb
Expand Up @@ -40,6 +40,13 @@ def group_id=(group_id)
add_recipients Group.find(group_id).users unless group_id.blank?
end

def order_id=(order_id)
@order_id = order_id
for ordergroup in Order.find(order_id).ordergroups
add_recipients ordergroup.users
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be shorter and more performant

add_recipients Order.find(order_id).ordergroups unless order_id.blank?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silly me, that wouldn't work at all. Perhaps another has_many :through in Order would work, but let's leave it this way :o

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I couldn't resist. If you like:

# in app/models/order.rb
has_many :ordergroups, :through => :group_orders
has_many :users_ordered, :through => :ordergroups, :source => :users
# in plugins/messages/app/models/message.rb#order_id=
add_recipients Order.find(order_id).users_ordered if order_id

end

def recipient_tokens=(ids)
@recipient_tokens = ids
add_recipients ids.split(",").collect { |id| User.find(id) }
Expand Down
@@ -0,0 +1,4 @@
/ insert_after 'erb:contains("title t(\'.title\'")'
- content_for :actionbar do
- if FoodsoftMessages.enabled?
= link_to_new_message message_params: {order_id: @order.id}