backup push
This commit is contained in:
@@ -21,9 +21,9 @@ root.Qrammer =
|
||||
num = 0.0 if isNaN(num) || num == '' || num == null
|
||||
'€ ' + parseFloat(num).toFixed(2)
|
||||
add_product: (product) ->
|
||||
window.active_list = {} unless window.active_list
|
||||
window.active_list[product._id] = {product: product, number: 0} unless window.active_list[product._id]
|
||||
window.active_list[product._id].number += 1
|
||||
window.active_products_list = {} unless window.active_products_list
|
||||
window.active_products_list[product._id] = {product: product, number: 0} unless window.active_products_list[product._id]
|
||||
window.active_products_list[product._id].number += 1
|
||||
Qrammer.build_product_list()
|
||||
build_product_list: ->
|
||||
table = $('#active-order-table')
|
||||
@@ -31,22 +31,22 @@ root.Qrammer =
|
||||
tbody = $('<tbody></tbody>').appendTo(table) unless tbody.length
|
||||
tbody.find('tr').remove()
|
||||
total = 0.0
|
||||
for product_id, info of window.active_list
|
||||
for product_id, info of window.active_products_list
|
||||
total += info.product.price * info.number
|
||||
row = $('<tr></tr>').attr('id', 'active-order-row-'+product_id).appendTo(tbody)
|
||||
row.append('<td>'+info.product.name+'</td>')
|
||||
row.append('<td>'+info.number+'</td>')
|
||||
row.append('<td class="currency">'+Qrammer.currency(info.product.price * info.number)+'</td>')
|
||||
x_btn = $('<button class="btn btn-warning btn-mini">x</button>').click(-> delete(window.active_list[product_id]) && Qrammer.build_product_list() )
|
||||
x_btn = $('<button class="btn btn-warning btn-mini">x</button>').click(-> delete(window.active_products_list[product_id]) && Qrammer.build_product_list() )
|
||||
row.append($('<td></td>').append(x_btn))
|
||||
$('#active-order-total').html(Qrammer.currency(total))
|
||||
table.show()
|
||||
clear_active_list: ->
|
||||
window.active_list = {}
|
||||
window.active_products_list = {}
|
||||
$('#active-order-table').hide()
|
||||
order_active_list: (post_uri)->
|
||||
order_active_products_list: (post_uri)->
|
||||
h = {list_id: active_list_id}
|
||||
for product_id, info of window.active_list
|
||||
for product_id, info of window.active_products_list
|
||||
h['products['+product_id+']'] = info.number
|
||||
$.post(post_uri, h, ((res) -> Qrammer.handle_response(res)), 'json')
|
||||
handle_response: (res) ->
|
||||
@@ -96,6 +96,29 @@ root.Qrammer =
|
||||
row.append(td_buttons)
|
||||
#foot.append('<tr><td></td><td class="currency"><strong>'+Qrammer.currency(res.total_amount)+'</strong></td></tr>');
|
||||
)
|
||||
|
||||
handle_active_user_list: (callback) ->
|
||||
$.get('/user_list_info.json', (res) ->
|
||||
if !res.list_active
|
||||
window.location = '/phone_home?list_closed=true'
|
||||
return
|
||||
window.active_list = res
|
||||
callback.call() if callback
|
||||
Qrammer.handle_active_user_list_default_actions()
|
||||
)
|
||||
handle_active_user_list_default_actions: ->
|
||||
Qrammer.list_needs_help_default_action()
|
||||
list_needs_help_default_action: ->
|
||||
needs_help_container = $('#list-needs-help-button')
|
||||
if needs_help_container.length
|
||||
if window.active_list.needs_help
|
||||
needs_help_container.html('Help requested')
|
||||
else
|
||||
needs_help_container.html($('<button class="btn btn-info">I have a question</button>').click(Qrammer.list_needs_help)) #TODO TEXT
|
||||
list_needs_help: ->
|
||||
return unless window.active_list && !window.active_list.needs_help
|
||||
$.post('/active_user_list_needs_help.json', (res) -> window.active_list = res; Qrammer.list_needs_help_default_action())
|
||||
|
||||
load_active_lists: (supplier_id) ->
|
||||
$.get('/suppliers/'+supplier_id+'/active_lists.json', (res) ->
|
||||
body = $('#active-lists-table tbody')
|
||||
@@ -104,21 +127,31 @@ root.Qrammer =
|
||||
for list in res.lists
|
||||
order_txts = []
|
||||
row = $('<tr></tr>').appendTo(body)
|
||||
close_btn = $('<button class="btn btn-success">Close!</button>')
|
||||
close_btn = $('<button class="btn btn-warning">Close!</button>')
|
||||
close_callback = ( (lst, r) ->
|
||||
->
|
||||
my_btn = $(this)
|
||||
$.post('/lists/'+lst._id+'/is_closed', {}, (res)-> r.slideUp('slow'))
|
||||
)(list, row)
|
||||
close_btn.click(close_callback)
|
||||
|
||||
needs_help_btn = $('<button class="btn btn-info">Question answered!</button>')
|
||||
needs_help_callback = ( (lst, r) ->
|
||||
->
|
||||
my_btn = $(this)
|
||||
$.post('/lists/'+lst._id+'/is_helped', {}, (res)-> my_btn.remove() )
|
||||
)(list, row)
|
||||
needs_help_btn.click(needs_help_callback)
|
||||
|
||||
|
||||
icons_td = $('<td class="status-icons"></td>').appendTo(row)
|
||||
icons_td.append('<li class="icon-hand-up"></li>') if list.need_help # or icon-bell
|
||||
icons_td.append('<li class="icon-check"></li>') if list.needs_payment
|
||||
icons_td.append('<i class="icon-hand-up"></i>').append(' ') if list.needs_help # or icon-bell
|
||||
icons_td.append('<i class="icon-check"></i>') if list.needs_payment
|
||||
|
||||
row.append($('<td></td>').text(list.table_number))
|
||||
row.append($('<td class="currency"></td>').html(Qrammer.currency(list.total_amount)))
|
||||
td_buttons = $('<td class="actions"></td>')
|
||||
td_buttons.append(needs_help_btn).append(' ') if list.needs_help
|
||||
td_buttons.append(close_btn)
|
||||
row.append(td_buttons)
|
||||
#foot.append('<tr><td></td><td class="currency"><strong>'+Qrammer.currency(res.total_amount)+'</strong></td></tr>');
|
||||
@@ -158,7 +191,7 @@ root.Qrammer =
|
||||
body = $('<div class="modal-body"></div>')
|
||||
table = $('<table class="table"></table>').appendTo(body)
|
||||
tbody = $('<tbody></tbody>').appendTo(table)
|
||||
for product_id, info of window.active_list
|
||||
for product_id, info of window.active_products_list
|
||||
row = $('<tr></tr>').appendTo(tbody)
|
||||
row.append('<td>'+info.product.name+'</td>')
|
||||
row.append('<td>'+info.number+'</td>')
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
$side-spacing: 5px
|
||||
body
|
||||
padding-left: 0px
|
||||
padding-right: 0px
|
||||
padding-left: $side-spacing
|
||||
padding-right: $side-spacing
|
||||
//padding-top: 50px
|
||||
.navbar-fixed-top
|
||||
margin-left: 0px
|
||||
margin-right: 0px
|
||||
margin-left: -$side-spacing
|
||||
margin-right: -$side-spacing
|
||||
margin-bottom: 3px
|
||||
.page-header
|
||||
margin-top: 4px
|
||||
margin-bottom: 6px
|
||||
padding-bottom: 0
|
||||
|
||||
@@ -5,6 +5,7 @@ table
|
||||
text-align: right
|
||||
tbody
|
||||
td
|
||||
&.status-icons
|
||||
&.currency
|
||||
text-align: right
|
||||
&.numeric
|
||||
@@ -61,3 +62,10 @@ table
|
||||
top: 100px
|
||||
width: 880px
|
||||
height: 590px
|
||||
|
||||
#list-needs-help-button
|
||||
button
|
||||
margin-left: 5px
|
||||
#list-needs-payment-button
|
||||
button
|
||||
margin-left: 5px
|
||||
|
||||
@@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base
|
||||
if session[:active_list_id]
|
||||
unless active_list.active?
|
||||
session[:active_list_id] = nil
|
||||
redirect_to root_path, alert: t('messages.the_list_has_been_closed')
|
||||
redirect_to phone_root_path, alert: t('messages.the_list_has_been_closed', list: List.model_name.human)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ class DashboardController < ApplicationController
|
||||
|
||||
end
|
||||
def phone_home
|
||||
flash.now[:notice] = t('messages.the_list_has_been_closed', list: List.model_name.human) if params[:list_closed].present?
|
||||
render layout: 'phone'
|
||||
end
|
||||
|
||||
@@ -32,7 +33,7 @@ class DashboardController < ApplicationController
|
||||
render layout: 'phone'
|
||||
end
|
||||
|
||||
def order_active_list
|
||||
def order_active_products_list
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
redirect_to(root_path, alert: t('messages.cannot_order_without_list_id')) and return if params[:list_id].blank?
|
||||
@@ -62,7 +63,7 @@ class DashboardController < ApplicationController
|
||||
render layout: 'phone'
|
||||
end
|
||||
|
||||
def list_info
|
||||
def user_list_info
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {list_active: false} and return unless session[:active_list_id].present?
|
||||
@@ -78,4 +79,16 @@ class DashboardController < ApplicationController
|
||||
def supplier_lists
|
||||
redirect_to active_lists_supplier_path(Supplier.first)
|
||||
end
|
||||
|
||||
# POST /active_user_list_needs_help
|
||||
def active_user_list_needs_help
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {list_active: false} and return unless session[:active_list_id].present?
|
||||
active_list.needs_help = true
|
||||
active_list.save
|
||||
render json: active_list.as_json.merge(list_active: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -94,8 +94,8 @@ class ListsController < ApplicationController
|
||||
ho = {products: []}
|
||||
order_total = 0.0
|
||||
for product_order in order.product_orders
|
||||
order_total += (product_order.amount * product_order.product.price).round(2)
|
||||
ho[:products] << {name: product_order.product.name, id: product_order.product_id, number: product_order.amount, price: product_order.product.price}
|
||||
order_total += (product_order.amount * product_order.price).round(2)
|
||||
ho[:products] << {name: product_order.product.name, id: product_order.product_id, number: product_order.amount, price: product_order.price}
|
||||
end
|
||||
ho[:total_amount] = order_total.round(2)
|
||||
ho[:state] = order.state
|
||||
@@ -110,12 +110,20 @@ class ListsController < ApplicationController
|
||||
|
||||
end
|
||||
|
||||
# POST /orders/1/is_delivered
|
||||
# POST /orders/1/is_closed
|
||||
def is_closed
|
||||
@list = List.find(params[:id])
|
||||
@list.close!
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
# POST /orders/1/is_helped
|
||||
def is_helped
|
||||
@list = List.find(params[:id])
|
||||
@list.needs_help = false
|
||||
@list.save
|
||||
render nothing: true
|
||||
end
|
||||
private
|
||||
|
||||
def set_relation_options
|
||||
|
||||
@@ -113,8 +113,8 @@ class SuppliersController < ApplicationController
|
||||
ho = {products: []}
|
||||
order_total = 0.0
|
||||
for product_order in order.product_orders
|
||||
order_total += (product_order.amount * product_order.product.price).round(2)
|
||||
ho[:products] << {name: product_order.product.name, id: product_order.product_id, number: product_order.amount, price: product_order.product.price}
|
||||
order_total += (product_order.amount * product_order.price).round(2)
|
||||
ho[:products] << {name: product_order.product.name, id: product_order.product_id, number: product_order.amount, price: product_order.price}
|
||||
end
|
||||
ho[:total_amount] = order_total.round(2)
|
||||
ho[:state] = order.state
|
||||
@@ -141,7 +141,7 @@ class SuppliersController < ApplicationController
|
||||
grand_total = 0.0
|
||||
for list in @supplier.active_lists
|
||||
hl = list.as_json
|
||||
hl[:total_amount] = list.orders.inject(0.0){|sum, o| sum + o.product_orders.inject(0.0){|s, po| s + (po.amount * po.product.price).round(2)}}.round(2)
|
||||
hl[:total_amount] = list.orders.inject(0.0){|sum, o| sum + o.product_orders.inject(0.0){|s, po| s + (po.amount * po.price).round(2)}}.round(2)
|
||||
grand_total += hl[:total_amount]
|
||||
h[:lists] << hl
|
||||
end
|
||||
@@ -150,6 +150,7 @@ class SuppliersController < ApplicationController
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_relation_options
|
||||
|
||||
+4
-2
@@ -2,7 +2,7 @@ class List
|
||||
include SimplyStored::Couch
|
||||
|
||||
property :state, default: 'active' # active, #closed
|
||||
property :need_help, type: :boolean, default: false
|
||||
property :needs_help, type: :boolean, default: false
|
||||
property :needs_payment, type: :boolean, default: false
|
||||
property :closed_at, type: Time
|
||||
has_many :orders, dependent: :destroy
|
||||
@@ -34,9 +34,11 @@ class List
|
||||
return unless products.any?
|
||||
@order = Order.create list: self, supplier: supplier
|
||||
return unless @order.id
|
||||
loaded_products = self.class.database.load_document products.keys
|
||||
products.each do |product_id, number|
|
||||
number = number.to_i
|
||||
ProductOrder.create order: @order, product_id: product_id, amount: number if number > 0
|
||||
product = loaded_products.find{|p| p.id == product_id} # to get the price
|
||||
ProductOrder.create order: @order, product_id: product_id, amount: number, price: product.price if number > 0
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ class ProductOrder
|
||||
include SimplyStored::Couch
|
||||
|
||||
property :amount, type: Fixnum
|
||||
property :price, type: Float
|
||||
|
||||
belongs_to :product
|
||||
belongs_to :order
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
.page-header
|
||||
h4= t('user.show_products.title', products: Product.model_name.human_plural)
|
||||
= link_to t('helpers.links.show_active_list', list: List.model_name.human), user_active_list_path, class: ['btn btn']
|
||||
span#list-needs-help-button
|
||||
table#products-table.table.table-striped.table-hover
|
||||
tbody
|
||||
-# content_for :sidebar do
|
||||
@@ -12,7 +16,7 @@ table#active-order-table.table.table-striped.hide
|
||||
tfoot
|
||||
tr
|
||||
td colspan=2
|
||||
button class="btn btn-primary" onClick="Qrammer.order_active_list('/order_active_list')" Bestellen
|
||||
button class="btn btn-primary" onClick="Qrammer.handle_active_user_list(function(){Qrammer.order_active_products_list('/order_active_products_list')})" Bestellen
|
||||
|
|
||||
button class="btn btn btn-warning" onClick="Qrammer.clear_active_list()" Clear
|
||||
td.currency
|
||||
@@ -21,26 +25,29 @@ table#active-order-table.table.table-striped.hide
|
||||
- content_for :footer do
|
||||
javascript:
|
||||
jQuery(function(){
|
||||
$.get('#{product_list_supplier_path(@supplier, format: :json).html_safe}', function(res){
|
||||
window.products = res
|
||||
body = $('#products-table tbody')
|
||||
for(var category in window.products){
|
||||
body.append('<tr><td colspan="3"><h4>'+category+'<h4></td></tr>');
|
||||
var category_ref = window.products[category];
|
||||
for(var iproduct = 0; iproduct < window.products[category].length; iproduct++){
|
||||
var product_index = iproduct;
|
||||
row = $('<tr></tr>');
|
||||
button = $('<button class="btn btn-mini btn-primary">Add</button>');
|
||||
var callback = (function(ref){
|
||||
return function(){ Qrammer.add_product(ref[product_index]) }
|
||||
})(category_ref)
|
||||
button.click(callback);
|
||||
row.append('<td>'+window.products[category][iproduct].name+'</td>');
|
||||
row.append('<td>'+Qrammer.currency(window.products[category][iproduct].price)+'</td>');
|
||||
row.append($('<td></td>').append(button));
|
||||
body.append(row);
|
||||
Qrammer.handle_active_user_list(function(){
|
||||
$.get('#{product_list_supplier_path(@supplier, format: :json).html_safe}', function(res){
|
||||
window.products = res
|
||||
body = $('#products-table tbody')
|
||||
for(var category in window.products){
|
||||
body.append('<tr><td colspan="3"><h4>'+category+'<h4></td></tr>');
|
||||
var category_ref = window.products[category];
|
||||
for(var iproduct = 0; iproduct < window.products[category].length; iproduct++){
|
||||
var product_index = iproduct;
|
||||
row = $('<tr></tr>');
|
||||
button = $('<button class="btn btn-mini btn-primary">Add</button>');
|
||||
var callback = (function(ref){
|
||||
return function(){ Qrammer.add_product(ref[product_index]) }
|
||||
})(category_ref)
|
||||
button.click(callback);
|
||||
row.append('<td>'+window.products[category][iproduct].name+'</td>');
|
||||
row.append('<td>'+Qrammer.currency(window.products[category][iproduct].price)+'</td>');
|
||||
row.append($('<td></td>').append(button));
|
||||
body.append(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
setInterval('Qrammer.handle_active_user_list()', 7500);
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
.page-header
|
||||
h1 List overview
|
||||
table#active-list-table.table
|
||||
h4= t('user.active_list.title', list: List.model_name.human)
|
||||
= link_to t('helpers.links.place_order'), user_products_path, class: ['btn btn-primary']
|
||||
span#list-needs-payment-button
|
||||
span#list-needs-help-button
|
||||
table#active-list-table.table.table-striped
|
||||
thead
|
||||
tr
|
||||
th Order
|
||||
th.currency Price
|
||||
th= Order.model_name.human
|
||||
th.currency= Product.human_attribute_name(:price)
|
||||
tbody
|
||||
tfoot
|
||||
- content_for :footer do
|
||||
|
||||
@@ -4,6 +4,14 @@
|
||||
= f.label :state, class: 'control-label'
|
||||
.controls
|
||||
= f.text_field :state, class: 'text_field'
|
||||
.control-group class=(@list.errors[:need_help].any? ? 'error' : nil)
|
||||
= f.label :need_help, class: 'control-label'
|
||||
.controls
|
||||
= f.check_box :need_help, class: 'check_box'
|
||||
.control-group class=(@list.errors[:needs_payment].any? ? 'error' : nil)
|
||||
= f.label :needs_payment, class: 'control-label'
|
||||
.controls
|
||||
= f.check_box :needs_payment, class: 'check_box'
|
||||
.control-group class=(@list.errors[:closed_at].any? ? 'error' : nil)
|
||||
= f.label :closed_at, class: 'control-label'
|
||||
.controls
|
||||
|
||||
@@ -5,6 +5,8 @@ div.page-header= title :index, model_class
|
||||
thead
|
||||
tr
|
||||
th= model_class.human_attribute_name(:state)
|
||||
th= model_class.human_attribute_name(:need_help)
|
||||
th= model_class.human_attribute_name(:needs_payment)
|
||||
th= model_class.human_attribute_name(:closed_at)
|
||||
th= Table.model_name.human
|
||||
th= model_class.human_attribute_name(:created_at)
|
||||
@@ -13,8 +15,10 @@ div.page-header= title :index, model_class
|
||||
- @lists.each do |list|
|
||||
tr
|
||||
td= link_to list.state, list
|
||||
td= list.need_help
|
||||
td= list.needs_payment
|
||||
td= list.closed_at
|
||||
td= link_to list.table.number, list.table
|
||||
td= link_to_if list.table.present?, list.table.try(:number), list.table
|
||||
td=l list.created_at, format: :short
|
||||
td
|
||||
= link_to t('helpers.links.edit'), [:edit, list], class: 'btn btn-mini'
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
dl.dl-horizontal.show-list
|
||||
dt= model_class.human_attribute_name(:state)
|
||||
dd= @list.state
|
||||
dt= model_class.human_attribute_name(:need_help)
|
||||
dd= @list.need_help
|
||||
dt= model_class.human_attribute_name(:needs_payment)
|
||||
dd= @list.needs_payment
|
||||
dt= model_class.human_attribute_name(:closed_at)
|
||||
dd= @list.closed_at
|
||||
- if @list.table.present?
|
||||
|
||||
@@ -9,8 +9,9 @@ table#active-lists-table.table.table-striped
|
||||
tbody
|
||||
- content_for :footer do
|
||||
javascript:
|
||||
var active_lists_interval;
|
||||
jQuery(function(){
|
||||
Qrammer.load_active_lists('#{@supplier.id}')
|
||||
setInterval( "Qrammer.load_active_lists('#{@supplier.id}')", 7500);
|
||||
active_lists_interval = setInterval( "Qrammer.load_active_lists('#{@supplier.id}')", 7500);
|
||||
});
|
||||
|
||||
|
||||
+13
-1
@@ -5,6 +5,8 @@ en:
|
||||
helpers:
|
||||
links:
|
||||
are_you_sure: 'Are you sure?'
|
||||
place_order: Place order
|
||||
show_active_list: Show %{list}
|
||||
forms:
|
||||
errors:
|
||||
title: There are problems found during saving (%{count})
|
||||
@@ -12,7 +14,7 @@ en:
|
||||
cannot_order_without_list_id: You cannot place an order without specifying a list
|
||||
cannot_order_on_non_active_list: You cannot place an order on a closed list
|
||||
order_is_placed: Your order has been received in good order
|
||||
the_list_has_been_closed: The list has been closed
|
||||
the_list_has_been_closed: The %{list} has been closed
|
||||
action:
|
||||
index:
|
||||
label: Listing %{models}
|
||||
@@ -43,6 +45,16 @@ en:
|
||||
list: Lists
|
||||
product: Products
|
||||
product_category: Product categories
|
||||
attributes:
|
||||
product:
|
||||
price: Price
|
||||
supplier:
|
||||
menu:
|
||||
active_lists: Active %{lists}
|
||||
user:
|
||||
active_list:
|
||||
title: Active %{list}
|
||||
needs_payment: Check please!
|
||||
show_products:
|
||||
# The title gets products: Product.model_name.human_plural that can be used: e.g.: Showing %{products}
|
||||
title: Menu
|
||||
|
||||
+7
-2
@@ -22,18 +22,23 @@ Qrammer::Application.routes.draw do
|
||||
member do
|
||||
get :current
|
||||
post :is_closed
|
||||
post :is_helped
|
||||
end
|
||||
end
|
||||
resources :products
|
||||
resources :product_categories
|
||||
|
||||
match "/:action", controller: 'dashboard'
|
||||
match '/view_active_list' => 'dashboard#view_active_list', as: :view_active_list
|
||||
match '/view_active_list' => 'dashboard#view_active_list', as: :view_active_list # depricated
|
||||
match '/view_active_list' => 'dashboard#view_active_list', as: :user_active_list
|
||||
match '/phone_home' => 'dashboard#phone_home', as: :phone_root
|
||||
match '/supplier_home' => 'dashboard#supplier_home', as: :supplier_root
|
||||
match '/supplier_home' => 'dashboard#supplier_home', as: :supplier_orders
|
||||
match '/supplier_lists' => 'dashboard#supplier_lists', as: :supplier_lists
|
||||
match '/user_list_info' => 'dashboard#user_list_info', as: :user_list_info
|
||||
match '/user_history' => 'dashboard#user_history', as: :user_history
|
||||
match '/show_products' => 'dashboard#show_products', as: :user_products
|
||||
post '/active_user_list_needs_help' => 'dashboard#active_user_list_needs_help', as: :active_user_list_needs_help
|
||||
match "/:action", controller: 'dashboard'
|
||||
|
||||
# The priority is based upon order of creation:
|
||||
# first created -> highest priority.
|
||||
|
||||
Reference in New Issue
Block a user