javascript translations and default format html

This commit is contained in:
2012-09-17 18:35:16 +02:00
parent 29848bb3cf
commit 2b2b81c23b
7 changed files with 75 additions and 15 deletions
+11 -3
View File
@@ -53,6 +53,12 @@ var translations = {
selected_products: {
order: 'Order',
clear: 'Clear'
},
join_request: {
title: 'Join request',
body: '%{email} wants to join the table',
reject: 'Reject',
approve: 'Approve'
}
}
function redirect_to(mapping, variables){
@@ -61,7 +67,7 @@ function redirect_to(mapping, variables){
for(var name in variables){
vars.push(name + '=' +variables[name])
}
window.location = path_mapping[mapping] + '?' + vars.join('&')
window.location = path_mapping[mapping] + '.html?' + vars.join('&')
}
function currency(num) {
return Qwaiter.currency(num);
@@ -69,8 +75,9 @@ function currency(num) {
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
function t(path){
var parts = path.split('.')
function t(path, vars){
vars || (vars = {});
var parts = path.split('.');
var accessor = 'translations["' + parts.join('"]["')+ '"]';
var result;
try{
@@ -78,5 +85,6 @@ function t(path){
} catch(err){
result = parts[parts.length - 1].capitalize();
}
$.each(vars, function(v, value){ result = result.replace('%{'+v+'}', value)});
return result;
}
+48 -8
View File
@@ -3,7 +3,7 @@ window.Quser=
handle_active_list: (callback) ->
$.get(data_host + '/user/list_info.json', (res) ->
if !res.list_active
window.location = '/user?list_closed=true'
redirect_to 'user_root', {list_closed: 'true'}
return
window.active_list = res
callback.call() if callback
@@ -33,16 +33,17 @@ window.Quser=
)(join_request)
header = $('<div class="modal-header"></div>')
.append('<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>')
.append('<h3>Join request</h3>').appendTo(wrapper)
.append($('<h3></h3>').text(t('join_request.title'))).appendTo(wrapper)
body = $('<div class="modal-body"></div>')
body.append(join_request.user_email + ' wants to join the table')
#body.append(join_request.user_email + ' wants to join the table')
body.text(t('join_request.body', {email: join_request.user_email}))
body.appendTo(wrapper)
footer = $('<div class="modal-footer"></div>')
.append($('<a href="#" class="btn">Reject</a>').click(reject_callback))
.append($('<a href="#" class="btn btn-primary">Approve</a>').click(join_callback))
.append($('<a href="#" class="btn"></a>').text(t('join_request.reject')).click(reject_callback))
.append($('<a href="#" class="btn btn-primary"></a>').text(t('join_request.approve')).click(join_callback))
.appendTo(wrapper)
wrapper.modal()
@@ -100,7 +101,7 @@ window.Quser=
$.get(data_host + '/user/active_list.json', (res) ->
window.active_list = res
unless res.list_active
window.location = '/user/list_history/'+res._id + '?list_closed=true'
window.location = '/user/list_history/'+res._id + '.html?list_closed=true'
return
Quser.handle_active_list_default_actions(res)
body = $('#active-list-table tbody')
@@ -118,6 +119,42 @@ window.Quser=
foot = $('#history-list-table tfoot')
Quser.build_list_table(body, foot, res)
)
load_list_history: ->
match = window.document.URL.toString().match('page=([0-9]+)')
if match
page = match[1]
else
page = 1
$.get(data_host + '/user/list_history.json?page='+page, (res) ->
Quser.paginate(res, '/user/list_history.html')
container = $('#list-history-container')
for list in res.lists
li = $('<li></li>').appendTo(container)
link = $('<a></a>').appendTo(li)
link.attr('href', '/user/list_history/'+list._id + '.html')
txt = list.supplier_name
txt += ' - '
txt += list.created_at.substr(0,10)
txt += ' '
txt += list.created_at.substr(11, 5)
link.text(txt)
)
paginate: (wrapper, src) ->
container = $('nav.pagination')
container.html('')
list = $('<ul></ul>').appendTo(container)
if wrapper.num_pages && wrapper.num_pages > 1
for i in [1..wrapper.num_pages]
li = $('<li class="page"></li>')
link = $('<a></a>')
link.text(i)
if wrapper.current_page && wrapper.current_page == i
li.addClass('active')
link.attr('href', 'javascript:void(0)')
else
link.attr('href', src + '?page='+i)
li.append(link)
list.append(li)
build_list_table: (body, foot, res) ->
body.find('tr').remove()
foot.find('tr').remove()
@@ -152,8 +189,11 @@ window.Quser=
else
eval(res)
return
window.location = '/user' if res['message'] && !res['ok']
window.location = res.location || '/user/list_products' if res['ok']
if res['message'] && !res['ok']
redirect_to 'user_root', {message: res['message']}
else
redirect_to 'list_products' if res['ok']
build_product_list: ->
table = $('#active-order-table')
tbody = table.find('tbody')