Files
mozo-backend/app/assets/javascripts/qrammer.js.coffee
T

54 lines
2.2 KiB
CoffeeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
root = exports ? this
root.Qrammer =
alert: (msg) ->
alert(msg)
confirm: (callback, content) ->
content ||= 'Are you sure?'
wrapper = $('<div class="modal"></div>')
callback_wrapper = ->
wrapper.modal('hide')
callback()
header = $('<div class="modal-header"></div>')
.append('<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>')
.append('<h3>Confirm</h3>').appendTo(wrapper)
body = $('<div class="modal-body"></div>').append('<p>'+content+'</p>').appendTo(wrapper)
footer = $('<div class="modal-footer"></div>')
.append($('<a href="#" class="btn">Close</a>').click(-> wrapper.modal('hide')))
.append($('<a href="#" class="btn btn-primary">Yes</a>').click(callback_wrapper))
.appendTo(wrapper)
wrapper.modal()
currency: (num) ->
num = 0.0 if isNaN(num) || num == '' || num == null
'&euro; ' + 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
Qrammer.build_product_list()
build_product_list: ->
wrapper = $('<div class="modal"></div>')
callback_wrapper = ->
wrapper.modal('hide')
callback()
header = $('<div class="modal-header"></div>')
.append('<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>')
.append('<h3>Product list</h3>').appendTo(wrapper)
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
row = $('<tr></tr>').appendTo(tbody)
row.append('<td>'+info.product.name+'</td>')
row.append('<td>'+info.number+'</td>')
row.append('<td>'+Qrammer.currency(info.product.price * info.number)+'</td>')
body.appendTo(wrapper)
footer = $('<div class="modal-footer"></div>')
.append($('<a href="#" class="btn">Close</a>').click(-> wrapper.modal('hide')))
.append($('<a href="#" class="btn btn-primary">Yes</a>').click(callback_wrapper))
.appendTo(wrapper)
wrapper.modal()