javascript translations and default format html
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -201,6 +201,12 @@ class UserController < ApplicationController
|
||||
def list_history
|
||||
@lists = List.for_user(current_user, page: params[:page], per_page: params[:per_page].presence || 14)
|
||||
@lists.include_relation(:supplier)
|
||||
respond_to do |format|
|
||||
format.html {}
|
||||
format.json do
|
||||
render json: @lists.inject(lists: [], current_page: @lists.current_page, num_pages: @lists.num_pages, total_count: @lists.total_count){|h, l| h[:lists] << l.as_json.merge(supplier_name: l.supplier.name); h}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
.page-header= title 'User list history'
|
||||
= paginate @lists
|
||||
ul
|
||||
- for list in @lists
|
||||
li= link_to "#{l(list.created_at, format: :short)} - #{list.supplier.name}", user_history_list_path(list_id: list.id)
|
||||
nav.pagination
|
||||
ul#list-history-container
|
||||
- content_for :footer do
|
||||
javascript:
|
||||
$(function(){
|
||||
Quser.load_list_history();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user