better broadcasting for user

This commit is contained in:
2012-12-01 16:12:04 +01:00
parent a14687d568
commit 926be8ec48
7 changed files with 50 additions and 17 deletions
@@ -30,6 +30,15 @@ root.Qsupplier=
$('#order-in-process-button-'+e.data.id).hide() $('#order-in-process-button-'+e.data.id).hide()
else if e.event == 'order_being_delivered' else if e.event == 'order_being_delivered'
$('#order-row-'+e.data.id).remove() $('#order-row-'+e.data.id).remove()
else if e.event == 'list_changed_table'
list_row = $('#list-row-'+e.data.list_id)
list_row.find('.table_number').text(e.data.table.number).addClass('changed')
list_row.find('.section_title').text(e.data.section_title)
order_rows = $('.of-list-'+e.data.list_id)
order_rows.find('.table_number').text(e.data.table.number).addClass('changed')
order_rows.find('.section_title').text(e.data.section_title)
console.log(e) console.log(e)
false false
move_table_to_active_section: (table_id)-> move_table_to_active_section: (table_id)->
@@ -52,7 +52,7 @@ var $translations = {
content: 'Request a waiter to your table' content: 'Request a waiter to your table'
}, },
list_needs_payment: { list_needs_payment: {
payment_already_requested: 'You already asked for the check', payment_already_requested: 'You already asked for the bill',
title: 'Ask for the check', title: 'Ask for the check',
content: 'Do you want to pay?' content: 'Do you want to pay?'
}, },
@@ -22,6 +22,16 @@ class Quser
$('#order-row-'+e.data.id).addClass('active') $('#order-row-'+e.data.id).addClass('active')
if(e.event == 'order_being_delivered') if(e.event == 'order_being_delivered')
$('#order-row-'+e.data.id).addClass('delivered') $('#order-row-'+e.data.id).addClass('delivered')
if(e.event == 'list_changed_table')
$('.table-number').text(e.data.table.number)
if(e.event == 'list_needs_help')
window.active_list.needs_help = true
@list_needs_help_default_action()
if(e.event == 'list_needs_payment')
window.active_list.needs_payment = true
@list_needs_payment_default_action()
console.log(e)
false false
home_loader: -> home_loader: ->
$.getJSON(data_host + '/user/list_info.json?' + authentication_string, (res) => @handle_active_list_default_actions(res)) $.getJSON(data_host + '/user/list_info.json?' + authentication_string, (res) => @handle_active_list_default_actions(res))
+2 -4
View File
@@ -213,9 +213,7 @@ class UserController < ApplicationController
respond_to do |format| respond_to do |format|
format.json do format.json do
render json: {list_active: false} and return unless list.present? render json: {list_active: false} and return unless list.present?
list.needs_help = true list.needs_help!
list.save
broadcast_supplier(list.supplier_id, 'list_needs_help', id: list.id)
render json: list.as_json.merge(list_active: list.active?) render json: list.as_json.merge(list_active: list.active?)
end end
end end
@@ -299,7 +297,7 @@ class UserController < ApplicationController
if @table.occupied? if @table.occupied?
render json: {occupied: true} render json: {occupied: true}
else else
list.move_to_table @table list.move_to_table! @table
render json: {occupied: false} render json: {occupied: false}
end end
end end
+23 -7
View File
@@ -126,6 +126,29 @@ class List
end end
end end
def move_to_table! to_table
UserTableMove.create list: self, from_table_id: table_id, to_table: to_table
self.table = to_table
self.section_id = to_table.section_id
if save
for user_id in user_ids
broadcast_user user_id, 'list_changed_table', list_id: id, table: to_table, section_title: to_table.section.try(:title)
end
broadcast_supplier supplier_id, 'list_changed_table', list_id: id, table: to_table, section_title: to_table.section.try(:title)
end
end
def needs_help!
self.needs_help = true
if save
for user_id in user_ids
broadcast_user user_id, 'list_needs_help', id: id
end
broadcast_supplier(supplier_id, 'list_needs_help', id: id)
end
end
def set_price def set_price
list_total = 0.0 list_total = 0.0
for order in orders for order in orders
@@ -162,13 +185,6 @@ class List
order order
end end
def move_to_table to_table
UserTableMove.create list: self, from_table_id: table_id, to_table: to_table
self.table = to_table
self.section_id = to_table.section_id
save
end
def as_json(*args) def as_json(*args)
super.merge(table_number: table_number) super.merge(table_number: table_number)
end end
+3 -3
View File
@@ -3,9 +3,9 @@
<span id="list-needs-help-indicator-{{id}}" class="list-needs-help-indicator {{^needs_help}}hide{{/needs_help}}">?</span> <span id="list-needs-help-indicator-{{id}}" class="list-needs-help-indicator {{^needs_help}}hide{{/needs_help}}">?</span>
<span id="list-needs-payment-indicator-{{id}}" class="list-needs-payment-indicator {{^needs_payment}}hide{{/needs_payment}}">&euro;</span> <span id="list-needs-payment-indicator-{{id}}" class="list-needs-payment-indicator {{^needs_payment}}hide{{/needs_payment}}">&euro;</span>
</td> </td>
<td class="numeric"><a href="/supplier/lists/{{id}}">{{table_number}}</a></td> <td class="numeric table_number">{{table_number}}</td>
<td>{{section_title}}</td> <td class="section_title">{{section_title}}</td>
<td class="currency">{{#currency}}{{total_amount}}{{/currency}}</td> <td class="currency total_list_amount">{{#currency}}{{total_amount}}{{/currency}}</td>
<td class="actions"> <td class="actions">
<button id="list-is-helped-button-{{id}}" class="btn btn-info {{^needs_help}}hide{{/needs_help}}" onclick="Qsupplier.mark_list_as_helped('{{id}}')">Question answered!</button> <button id="list-is-helped-button-{{id}}" class="btn btn-info {{^needs_help}}hide{{/needs_help}}" onclick="Qsupplier.mark_list_as_helped('{{id}}')">Question answered!</button>
<button class="btn btn-warning" onclick="Qsupplier.close_list('{{id}}')">Close!</button> <button class="btn btn-warning" onclick="Qsupplier.close_list('{{id}}')">Close!</button>
@@ -1,7 +1,7 @@
<tr id="order-row-{{id}}" class="of-list-{{list_id}}"> <tr id="order-row-{{id}}" class="of-list-{{list_id}}">
<td>{{display}}</td> <td>{{display}}</td>
<td class="numeric">{{table_number}}</td> <td class="numeric table_number">{{table_number}}</td>
<td>{{section_title}}</td> <td class="section_title">{{section_title}}</td>
<td class="currency">{{#currency}}{{total_amount}}{{/currency}}</td> <td class="currency">{{#currency}}{{total_amount}}{{/currency}}</td>
<td class="actions"> <td class="actions">
<button id="order-in-process-button-{{id}}" class="btn btn-success {{^can_process}}hide{{/can_process}}" onclick="Qsupplier.mark_order_in_process('{{id}}')">In process!</button> <button id="order-in-process-button-{{id}}" class="btn btn-success {{^can_process}}hide{{/can_process}}" onclick="Qsupplier.mark_order_in_process('{{id}}')">In process!</button>