Added init admin interface for translations.
This commit is contained in:
parent
c4c12e34e2
commit
ec12481273
6 changed files with 192 additions and 13 deletions
86
app/assets/javascripts/app/controllers/translation.js.coffee
Normal file
86
app/assets/javascripts/app/controllers/translation.js.coffee
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
class Index extends App.ControllerContent
|
||||||
|
events:
|
||||||
|
'blur input': 'update'
|
||||||
|
'click .js-Reset': 'reset'
|
||||||
|
|
||||||
|
constructor: ->
|
||||||
|
super
|
||||||
|
|
||||||
|
# check authentication
|
||||||
|
return if !@authenticate()
|
||||||
|
|
||||||
|
@title 'Translations'
|
||||||
|
|
||||||
|
@render()
|
||||||
|
@load()
|
||||||
|
|
||||||
|
load: =>
|
||||||
|
@ajax(
|
||||||
|
id: 'translations_admin'
|
||||||
|
type: 'GET'
|
||||||
|
url: @apiPath + '/translations/admin/lang/de'
|
||||||
|
processData: true
|
||||||
|
success: (data, status, xhr) =>
|
||||||
|
@render(data)
|
||||||
|
)
|
||||||
|
|
||||||
|
render: (data = {}) =>
|
||||||
|
@html App.view('translation')(
|
||||||
|
list: data.list
|
||||||
|
timestampFormat: data.timestampFormat
|
||||||
|
dateFormat: data.dateFormat
|
||||||
|
)
|
||||||
|
ui = @
|
||||||
|
@$('.js-Item').each( (e) ->
|
||||||
|
id = $(this).data('id')
|
||||||
|
ui.updateRow(id)
|
||||||
|
)
|
||||||
|
|
||||||
|
reset: (e) ->
|
||||||
|
e.preventDefault()
|
||||||
|
field = $(e.target).closest('tr').find('.js-Item')
|
||||||
|
id = field.data('id')
|
||||||
|
initial = field.data('initial')
|
||||||
|
field.val( initial )
|
||||||
|
@updateRow(id)
|
||||||
|
params =
|
||||||
|
id: id
|
||||||
|
target: initial
|
||||||
|
|
||||||
|
@ajax(
|
||||||
|
id: 'translations'
|
||||||
|
type: 'PUT'
|
||||||
|
url: @apiPath + '/translations/' + id
|
||||||
|
data: JSON.stringify(params)
|
||||||
|
processData: false
|
||||||
|
)
|
||||||
|
|
||||||
|
update: (e) ->
|
||||||
|
e.preventDefault()
|
||||||
|
id = $( e.target ).data('id')
|
||||||
|
target = $( e.target ).val()
|
||||||
|
@updateRow(id)
|
||||||
|
params =
|
||||||
|
id: id
|
||||||
|
target: target
|
||||||
|
|
||||||
|
@ajax(
|
||||||
|
id: 'translations'
|
||||||
|
type: 'PUT'
|
||||||
|
url: @apiPath + '/translations/' + id
|
||||||
|
data: JSON.stringify(params)
|
||||||
|
processData: false
|
||||||
|
)
|
||||||
|
|
||||||
|
updateRow: (id) =>
|
||||||
|
field = @$("[data-id=#{id}]")
|
||||||
|
current = field.val()
|
||||||
|
initial = field.data('initial')
|
||||||
|
reset = field.closest('tr').find('.js-Reset')
|
||||||
|
if current isnt initial
|
||||||
|
reset.show()
|
||||||
|
else
|
||||||
|
reset.hide()
|
||||||
|
|
||||||
|
|
||||||
|
App.Config.set( 'Translation', { prio: 1800, parent: '#system', name: 'Translations', target: '#system/translation', controller: Index, role: ['Admin'] }, 'NavBarAdmin' )
|
52
app/assets/javascripts/app/views/translation.jst.eco
Normal file
52
app/assets/javascripts/app/views/translation.jst.eco
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
<div class="page-header-title">
|
||||||
|
<h1><%- @T('Translations') %><small></small></h1>
|
||||||
|
</div>
|
||||||
|
<h2><%- @T('Date & Datetime') %></h2>
|
||||||
|
<table class="translationOverview table table-striped table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="translationOverview-source"><%- @T('Type') %></th>
|
||||||
|
<th class="translationOverview-target"><%- @T('Target') %></th>
|
||||||
|
<th class="translationOverview-initial"><%- @T('Original') %></th>
|
||||||
|
<th class="translationOverview-action"><%- @T('Action') %></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td><%- @T('Datetime') %></td>
|
||||||
|
<td><input class="translationOverview-item" value="<%= @timestampFormat %>"></td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><%- @T('Date') %></td>
|
||||||
|
<td><input class="translationOverview-item" value="<%= @dateFormat %>"></td>
|
||||||
|
<td></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h2><%- @T('Words') %></h2>
|
||||||
|
<table class="translationOverview table table-striped table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="translationOverview-source"><%- @T('Source') %></th>
|
||||||
|
<th class="translationOverview-target"><%- @T('Target') %></th>
|
||||||
|
<th class="translationOverview-initial"><%- @T('Original') %></th>
|
||||||
|
<th class="translationOverview-action"><%- @T('Action') %></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% if @list: %>
|
||||||
|
<% for item in @list: %>
|
||||||
|
<tr>
|
||||||
|
<td><%= item[1] %></td>
|
||||||
|
<td><input class="js-Item translationOverview-item" value="<%= item[2] %>" data-initial="<%= item[3] %>" data-id="<%= item[0] %>"></td>
|
||||||
|
<td><%= item[3]%></td>
|
||||||
|
<td><a href="#" class="js-Reset"><%- @T('Reset') %></a></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
|
@ -5266,6 +5266,23 @@ label + .wizard-buttonList {
|
||||||
.highlight-Purple { background: #eac5ee; }
|
.highlight-Purple { background: #eac5ee; }
|
||||||
|
|
||||||
|
|
||||||
|
.translationOverview {
|
||||||
|
.translationOverview-source {
|
||||||
|
width: 25%;
|
||||||
|
}
|
||||||
|
.translationOverview-target {
|
||||||
|
width: 35%;
|
||||||
|
}
|
||||||
|
.translationOverview-initial {
|
||||||
|
width: 25%;
|
||||||
|
}
|
||||||
|
.translationOverview-action {
|
||||||
|
width: 15%;
|
||||||
|
}
|
||||||
|
.translationOverview-item {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.overview-navigator {
|
.overview-navigator {
|
||||||
display: inherit;
|
display: inherit;
|
||||||
|
|
|
@ -3,11 +3,17 @@
|
||||||
class TranslationsController < ApplicationController
|
class TranslationsController < ApplicationController
|
||||||
before_filter :authentication_check, :except => [:load]
|
before_filter :authentication_check, :except => [:load]
|
||||||
|
|
||||||
# GET /translations/:lang
|
# GET /translations/lang/:locale
|
||||||
def load
|
def load
|
||||||
render :json => Translation.list( params[:locale] )
|
render :json => Translation.list( params[:locale] )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# GET /translations/admin/lang/:locale
|
||||||
|
def admin
|
||||||
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
||||||
|
render :json => Translation.list( params[:locale], true )
|
||||||
|
end
|
||||||
|
|
||||||
# GET /translations
|
# GET /translations
|
||||||
def index
|
def index
|
||||||
model_index_render(Translation, params)
|
model_index_render(Translation, params)
|
||||||
|
@ -20,16 +26,19 @@ class TranslationsController < ApplicationController
|
||||||
|
|
||||||
# POST /translations
|
# POST /translations
|
||||||
def create
|
def create
|
||||||
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
||||||
model_create_render(Translation, params)
|
model_create_render(Translation, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
# PUT /translations/1
|
# PUT /translations/1
|
||||||
def update
|
def update
|
||||||
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
||||||
model_update_render(Translation, params)
|
model_update_render(Translation, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
# DELETE /translations/1
|
# DELETE /translations/1
|
||||||
def destroy
|
def destroy
|
||||||
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
||||||
model_destory_render(Translation, params)
|
model_destory_render(Translation, params)
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -6,25 +6,39 @@ class Translation < ApplicationModel
|
||||||
after_update :cache_clear
|
after_update :cache_clear
|
||||||
after_destroy :cache_clear
|
after_destroy :cache_clear
|
||||||
|
|
||||||
def self.list(locale)
|
def self.list(locale, admin = false)
|
||||||
|
|
||||||
# check cache
|
# check cache
|
||||||
|
if !admin
|
||||||
list = cache_get( locale )
|
list = cache_get( locale )
|
||||||
|
end
|
||||||
if !list
|
if !list
|
||||||
list = []
|
list = []
|
||||||
translations = Translation.where( :locale => locale.downcase )
|
translations = Translation.where( :locale => locale.downcase ).order( :source )
|
||||||
translations.each { |item|
|
translations.each { |item|
|
||||||
|
if admin
|
||||||
|
data = [
|
||||||
|
item.id,
|
||||||
|
item.source,
|
||||||
|
item.target,
|
||||||
|
item.target_initial,
|
||||||
|
]
|
||||||
|
list.push data
|
||||||
|
else
|
||||||
data = [
|
data = [
|
||||||
item.id,
|
item.id,
|
||||||
item.source,
|
item.source,
|
||||||
item.target,
|
item.target,
|
||||||
]
|
]
|
||||||
list.push data
|
list.push data
|
||||||
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
# set cache
|
# set cache
|
||||||
|
if !admin
|
||||||
cache_set( locale, list )
|
cache_set( locale, list )
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
timestamp_map_default = 'yyyy-mm-dd HH:MM'
|
timestamp_map_default = 'yyyy-mm-dd HH:MM'
|
||||||
timestamp_map = {
|
timestamp_map = {
|
||||||
|
|
|
@ -8,4 +8,5 @@ Zammad::Application.routes.draw do
|
||||||
match api_path + '/translations/:id', :to => 'translations#destroy', :via => :delete
|
match api_path + '/translations/:id', :to => 'translations#destroy', :via => :delete
|
||||||
|
|
||||||
match api_path + '/translations/lang/:locale', :to => 'translations#load', :via => :get
|
match api_path + '/translations/lang/:locale', :to => 'translations#load', :via => :get
|
||||||
|
match api_path + '/translations/admin/lang/:locale', :to => 'translations#admin', :via => :get
|
||||||
end
|
end
|
Loading…
Reference in a new issue