Fix Date and Time display formats on JS side

This commit is contained in:
Matej Zrimšek 2019-01-08 08:07:24 +01:00
parent b64df7d8cc
commit 8070b7f8b5
3 changed files with 39 additions and 2 deletions

View file

@ -115,8 +115,29 @@ function importProtocolFromFile(
$("#protocol_authors").val($(this).children("authors").text());
$("#import_protocol_description").val($(this).children("description").text());
}
$("#protocol_created_at").val($(this).children("created_at").text());
$("#protocol_updated_at").val($(this).children("updated_at").text());
$.ajax({
url: "/helpers/to_user_date_format.json",
type: "GET",
data: { "timestamp": $(this).children("created_at").text(),
"ts_format": "full" },
dataType: "json",
async: false,
success: function (data) {
$("#protocol_created_at").val(data.ts);
}
});
$.ajax({
url: "/helpers/to_user_date_format.json",
type: "GET",
data: { "timestamp": $(this).children("updated_at").text(),
"ts_format": "full" },
dataType: "json",
async: false,
success: function (data) {
$("#protocol_updated_at").val(data.ts);
}
});
});
// PREVIEW

View file

@ -36,6 +36,16 @@ class ApplicationController < ActionController::Base
Team.find_by_id(current_user.current_team_id)
end
def to_user_date_format
ts = I18n.l(Time.parse(params[:timestamp]),
format: params[:ts_format].to_sym)
respond_to do |format|
format.json do
render json: { ts: ts }, status: :ok
end
end
end
protected
def render_403(style = 'danger')

View file

@ -53,6 +53,12 @@ Rails.application.routes.draw do
get 'forbidden', to: 'application#forbidden', as: 'forbidden'
get 'not_found', to: 'application#not_found', as: 'not_found'
# JS backend helpers
get 'helpers/to_user_date_format',
to: 'application#to_user_date_format',
as: 'to_user_date_format',
defaults: { format: 'json' }
# Settings
resources :users, only: :index # needed for testing signup
# needed for testing edit passowrd