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: { selected_products: {
order: 'Order', order: 'Order',
clear: 'Clear' clear: 'Clear'
},
join_request: {
title: 'Join request',
body: '%{email} wants to join the table',
reject: 'Reject',
approve: 'Approve'
} }
} }
function redirect_to(mapping, variables){ function redirect_to(mapping, variables){
@@ -61,7 +67,7 @@ function redirect_to(mapping, variables){
for(var name in variables){ for(var name in variables){
vars.push(name + '=' +variables[name]) vars.push(name + '=' +variables[name])
} }
window.location = path_mapping[mapping] + '?' + vars.join('&') window.location = path_mapping[mapping] + '.html?' + vars.join('&')
} }
function currency(num) { function currency(num) {
return Qwaiter.currency(num); return Qwaiter.currency(num);
@@ -69,8 +75,9 @@ function currency(num) {
String.prototype.capitalize = function() { String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1); return this.charAt(0).toUpperCase() + this.slice(1);
} }
function t(path){ function t(path, vars){
var parts = path.split('.') vars || (vars = {});
var parts = path.split('.');
var accessor = 'translations["' + parts.join('"]["')+ '"]'; var accessor = 'translations["' + parts.join('"]["')+ '"]';
var result; var result;
try{ try{
@@ -78,5 +85,6 @@ function t(path){
} catch(err){ } catch(err){
result = parts[parts.length - 1].capitalize(); result = parts[parts.length - 1].capitalize();
} }
$.each(vars, function(v, value){ result = result.replace('%{'+v+'}', value)});
return result; return result;
} }
+48 -8
View File
@@ -3,7 +3,7 @@ window.Quser=
handle_active_list: (callback) -> handle_active_list: (callback) ->
$.get(data_host + '/user/list_info.json', (res) -> $.get(data_host + '/user/list_info.json', (res) ->
if !res.list_active if !res.list_active
window.location = '/user?list_closed=true' redirect_to 'user_root', {list_closed: 'true'}
return return
window.active_list = res window.active_list = res
callback.call() if callback callback.call() if callback
@@ -33,16 +33,17 @@ window.Quser=
)(join_request) )(join_request)
header = $('<div class="modal-header"></div>') header = $('<div class="modal-header"></div>')
.append('<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>') .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 = $('<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) body.appendTo(wrapper)
footer = $('<div class="modal-footer"></div>') footer = $('<div class="modal-footer"></div>')
.append($('<a href="#" class="btn">Reject</a>').click(reject_callback)) .append($('<a href="#" class="btn"></a>').text(t('join_request.reject')).click(reject_callback))
.append($('<a href="#" class="btn btn-primary">Approve</a>').click(join_callback)) .append($('<a href="#" class="btn btn-primary"></a>').text(t('join_request.approve')).click(join_callback))
.appendTo(wrapper) .appendTo(wrapper)
wrapper.modal() wrapper.modal()
@@ -100,7 +101,7 @@ window.Quser=
$.get(data_host + '/user/active_list.json', (res) -> $.get(data_host + '/user/active_list.json', (res) ->
window.active_list = res window.active_list = res
unless res.list_active 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 return
Quser.handle_active_list_default_actions(res) Quser.handle_active_list_default_actions(res)
body = $('#active-list-table tbody') body = $('#active-list-table tbody')
@@ -118,6 +119,42 @@ window.Quser=
foot = $('#history-list-table tfoot') foot = $('#history-list-table tfoot')
Quser.build_list_table(body, foot, res) 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) -> build_list_table: (body, foot, res) ->
body.find('tr').remove() body.find('tr').remove()
foot.find('tr').remove() foot.find('tr').remove()
@@ -152,8 +189,11 @@ window.Quser=
else else
eval(res) eval(res)
return 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: -> build_product_list: ->
table = $('#active-order-table') table = $('#active-order-table')
tbody = table.find('tbody') tbody = table.find('tbody')
+6
View File
@@ -201,6 +201,12 @@ class UserController < ApplicationController
def list_history def list_history
@lists = List.for_user(current_user, page: params[:page], per_page: params[:per_page].presence || 14) @lists = List.for_user(current_user, page: params[:page], per_page: params[:per_page].presence || 14)
@lists.include_relation(:supplier) @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 end
## ##
+7 -4
View File
@@ -1,5 +1,8 @@
.page-header= title 'User list history' .page-header= title 'User list history'
= paginate @lists nav.pagination
ul ul#list-history-container
- for list in @lists - content_for :footer do
li= link_to "#{l(list.created_at, format: :short)} - #{list.supplier.name}", user_history_list_path(list_id: list.id) javascript:
$(function(){
Quser.load_list_history();
});
+1
View File
@@ -73,6 +73,7 @@ module Qrammer
# Enable the asset pipeline # Enable the asset pipeline
config.assets.enabled = true config.assets.enabled = true
config.assets.precompile += ['supplier/application.css', 'user/application.css', 'qr_sheet/application.css'] config.assets.precompile += ['supplier/application.css', 'user/application.css', 'qr_sheet/application.css']
config.default_url_options = {format: 'html'}
# Version of your assets, change this if you want to expire all your assets # Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0' config.assets.version = '1.0'
+1
View File
@@ -37,6 +37,7 @@ Qrammer::Application.routes.draw do
match '/supplier/settings' => 'supplier#update', as: :supplier_update_settings, via: [:put, :post] match '/supplier/settings' => 'supplier#update', as: :supplier_update_settings, via: [:put, :post]
# USER # USER
default_url_options format: 'html'
match '/user' => 'user#home', as: :user_root match '/user' => 'user#home', as: :user_root
get '/user/active_list(.:format)' => 'user#active_list', as: :user_active_list get '/user/active_list(.:format)' => 'user#active_list', as: :user_active_list
get '/user/list_info' => 'user#list_info', as: :user_list_info get '/user/list_info' => 'user#list_info', as: :user_list_info
+1
View File
@@ -0,0 +1 @@