add javascript translations, darken background and other confirm

This commit is contained in:
2012-09-07 11:35:33 +02:00
parent 19232be356
commit 3adf392e54
7 changed files with 60 additions and 20 deletions
@@ -1,19 +1,24 @@
root = exports ? this
root.Qrammer =
root.Qwaiter=
alert: (msg) ->
alert(msg)
confirm: (callback, content) ->
content ||= 'Are you sure?'
confirm: (options) ->
options ||= {}
content = options.content || 'Are you sure?'
title = options.title || 'Confirm'
wrapper = $('<div class="modal"></div>')
callback_wrapper = ->
wrapper.modal('hide')
callback()
options.ok()
callback_cancel_wrapper = ->
wrapper.modal('hide')
options.cancel() if options.cancel
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)
.append('<h3>'+title+'</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">Close</a>').click(callback_cancel_wrapper))
.append($('<a href="#" class="btn btn-primary">Yes</a>').click(callback_wrapper))
.appendTo(wrapper)
wrapper.modal()
+22 -4
View File
@@ -26,6 +26,7 @@
// require twitter/bootstrap/bootstrap-carousel
//= require twitter/bootstrap/bootstrap-typeahead
//= require twitter/bootstrap/bootstrap-affix
//= require qwaiter
//= require_directory .
//= require_self
var path_mapping = {
@@ -34,6 +35,12 @@ var path_mapping = {
list_products_for_table: '/user/list_products_for_table',
list_products: '/user/list_products'
}
var translations = {
confirmations: {
move_to_another_table_title: 'Move to another table?',
move_to_another_table: 'Are you sure you want to move to another table?'
}
}
function redirect_to(mapping, variables){
variables || (variables = {});
var vars = []
@@ -43,8 +50,19 @@ function redirect_to(mapping, variables){
window.location = path_mapping[mapping] + '?' + vars.join('&')
}
function currency(num) {
if (isNaN(num) || num === '' || num === null) {
num = 0.0;
}
return '&euro;&nbsp;' + parseFloat(num).toFixed(2);
return Qwaiter.currency(num);
}
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
function t(path){
var parts = path.split('.')
var accessor = 'translations["' + parts.join('"]["')+ '"]';
var result;
try{
result = eval(accessor);
} catch(err){
result = parts[parts.length - 1].capitalize();
}
return result;
}
+14 -7
View File
@@ -185,10 +185,10 @@ window.Quser=
$.get('/user/table_info.json?table_id='+table.table_id, (res)->
if res.current_table_id
if res.other_supplier
#TODO cannot do something with other supplier when list is active
redirect_to 'user_root', {message: 'table_is_from_other_supplier'}
else if res.current_table_id == table.table_id
#nothing has changed, show product list
window.location = '/user/list_products'
redirect_to 'list_products'
else if res.current_table_id != table.table_id
if res.occupied
redirect_to 'user_root', {message: 'table_is_occupied'}
@@ -200,11 +200,18 @@ window.Quser=
redirect_to 'user_root', {message: 'supplier_is_closed'}
else
#TODO Offer to move table
$.post('/user/move_table', {table_id: table.table_id}, (res2)->
if res2.occupied
alert('Cannot move to occupied table')
else
window.location = '/user/list_products'
Qwaiter.confirm(
ok: ->
$.post('/user/move_table', {table_id: table.table_id}, (res2)->
if res2.occupied
alert('Cannot move to occupied table')
else
redirect_to 'list_products', {message: 'moved_to_another_table'}
)
cancel: ->
redirect_to 'list_products'
title: t('confirmations.move_to_another_table_title')
content: t('confirmations.move_to_another_table')
)
else
if res.occupied