Lines 18-31
Link Here
|
18 |
<h1>Localization</h1> |
18 |
<h1>Localization</h1> |
19 |
<form id="add_translation" method="get"> |
19 |
<form id="add_translation" method="get"> |
20 |
[% INCLUDE 'csrf-token.inc' %] |
20 |
[% INCLUDE 'csrf-token.inc' %] |
21 |
<input type="hidden" name="entity" value="[% entity | html %]" /> |
21 |
<input type="hidden" name="source" value="[% source | html %]" /> |
22 |
<input type="hidden" name="code" value="[% code | html %]" /> |
22 |
<input type="hidden" name="object_id" value="[% object_id | html %]" /> |
23 |
<input type="hidden" name="interface" value="[% interface_side | html %]" /> |
23 |
<input type="hidden" name="property" value="[% property | html %]" /> |
24 |
<fieldset class="rows clearfix"> |
24 |
<fieldset class="rows clearfix"> |
25 |
<ol> |
25 |
<ol> |
26 |
<li> |
26 |
<li> |
27 |
<span class="label">Authorized value:</span> |
27 |
<span class="label">Authorized value:</span> |
28 |
[% code | html %] |
28 |
[% object_id | html %] |
29 |
</li> |
29 |
</li> |
30 |
<li> |
30 |
<li> |
31 |
<label for="lang">Language:</label> |
31 |
<label for="lang">Language:</label> |
Lines 66-74
Link Here
|
66 |
<table id="localization"> |
66 |
<table id="localization"> |
67 |
<thead> |
67 |
<thead> |
68 |
<tr> |
68 |
<tr> |
69 |
<th>Id</th> |
|
|
70 |
<th>Entity</th> |
71 |
<th>Code</th> |
72 |
<th>Language</th> |
69 |
<th>Language</th> |
73 |
<th>Translation</th> |
70 |
<th>Translation</th> |
74 |
<th class="NoSort"> </th> |
71 |
<th class="NoSort"> </th> |
Lines 76-85
Link Here
|
76 |
</thead> |
73 |
</thead> |
77 |
<tbody> |
74 |
<tbody> |
78 |
[% FOR t IN translations %] |
75 |
[% FOR t IN translations %] |
79 |
<tr id="row_id_[% t.id | html %]" data-id="[% t.id | html %]"> |
76 |
<tr id="row_id_[% t.localization_id | html %]" data-id="[% t.localization_id | html %]"> |
80 |
<td>[% t.id | html %]</td> |
|
|
81 |
<td>[% t.entity | html %]</td> |
82 |
<td>[% t.code | html %]</td> |
83 |
<td class="lang">[% t.lang | html %]</td> |
77 |
<td class="lang">[% t.lang | html %]</td> |
84 |
<td class="translation" contenteditable="true">[% t.translation | html %]</td> |
78 |
<td class="translation" contenteditable="true">[% t.translation | html %]</td> |
85 |
<td class="actions"><a href="#" class="delete"><i class="fa fa-trash-can"></i> Delete</a></td> |
79 |
<td class="actions"><a href="#" class="delete"><i class="fa fa-trash-can"></i> Delete</a></td> |
Lines 102-108
Link Here
|
102 |
var message; |
96 |
var message; |
103 |
if ( type == 'success_on_update' ) { |
97 |
if ( type == 'success_on_update' ) { |
104 |
message = $('<div class="alert alert-info"></div>'); |
98 |
message = $('<div class="alert alert-info"></div>'); |
105 |
message.text(_("Entity %s (code %s) for lang %s has correctly been updated with '%s'").format(data.entity, data.code, data.lang, data.translation)); |
99 |
message.text(_("Translation for lang %s has correctly been updated with '%s'").format(data.lang, data.translation)); |
106 |
} else if ( type == 'error_on_update' ) { |
100 |
} else if ( type == 'error_on_update' ) { |
107 |
message = $('<div class="alert alert-warning"></div>'); |
101 |
message = $('<div class="alert alert-warning"></div>'); |
108 |
if ( data.error_code == 'already_exists' ) { |
102 |
if ( data.error_code == 'already_exists' ) { |
Lines 112-124
Link Here
|
112 |
} |
106 |
} |
113 |
} else if ( type == 'success_on_delete' ) { |
107 |
} else if ( type == 'success_on_delete' ) { |
114 |
message = $('<div class="alert alert-info"></div>'); |
108 |
message = $('<div class="alert alert-info"></div>'); |
115 |
message.text(_("The translation (id %s) has been removed successfully").format(data.id)); |
109 |
message.text(_("The translation has been removed successfully")); |
116 |
} else if ( type == 'error_on_delete' ) { |
110 |
} else if ( type == 'error_on_delete' ) { |
117 |
message = $('<div class="alert alert-warning"></div>'); |
111 |
message = $('<div class="alert alert-warning"></div>'); |
118 |
message.text(_("An error occurred when deleting this translation")); |
112 |
message.text(_("An error occurred when deleting this translation")); |
119 |
} else if ( type == 'success_on_insert' ) { |
113 |
} else if ( type == 'success_on_insert' ) { |
120 |
message = $('<div class="alert alert-info"></div>'); |
114 |
message = $('<div class="alert alert-info"></div>'); |
121 |
message.text(_("Translation (id %s) has been added successfully").format(data.id)); |
115 |
message.text(_("Translation has been added successfully")); |
122 |
} else if ( type == 'error_on_insert' ) { |
116 |
} else if ( type == 'error_on_insert' ) { |
123 |
message = $('<div class="alert alert-warning"></div>'); |
117 |
message = $('<div class="alert alert-warning"></div>'); |
124 |
if ( data.error_code == 'already_exists' ) { |
118 |
if ( data.error_code == 'already_exists' ) { |
Lines 135-148
Link Here
|
135 |
}, 3000); |
129 |
}, 3000); |
136 |
} |
130 |
} |
137 |
|
131 |
|
138 |
function send_update_request( data, cell ) { |
132 |
function send_update_request( _data, cell ) { |
|
|
133 |
const form = document.forms.add_translation; |
134 |
const source = form.elements.source.value; |
135 |
const object_id = form.elements.object_id.value; |
136 |
const data = Object.assign({}, _data, { source, object_id }); |
139 |
const client = APIClient.localization; |
137 |
const client = APIClient.localization; |
140 |
client.localizations.update(data).then( |
138 |
client.localizations.update(data).then( |
141 |
success => { |
139 |
success => { |
142 |
if ( success.error ) { |
140 |
if ( success.error ) { |
143 |
$(cell).css('background-color', '#FF0000'); |
141 |
$(cell).css('background-color', '#FF0000'); |
144 |
show_message({ type: 'error_on_update', data: success }); |
142 |
show_message({ type: 'error_on_update', data: success }); |
145 |
} else if ( success.is_changed == 1 ) { |
143 |
} else { |
146 |
$(cell).css('background-color', '#00FF00'); |
144 |
$(cell).css('background-color', '#00FF00'); |
147 |
show_message({ type: 'success_on_update', data: success }); |
145 |
show_message({ type: 'success_on_update', data: success }); |
148 |
} |
146 |
} |
Lines 166-177
Link Here
|
166 |
); |
164 |
); |
167 |
} |
165 |
} |
168 |
|
166 |
|
169 |
function send_delete_request( id, cell ) { |
167 |
function send_delete_request( localization_id, cell ) { |
|
|
168 |
const form = document.forms.add_translation; |
169 |
const source = form.elements.source.value; |
170 |
const object_id = form.elements.object_id.value; |
171 |
const property = form.elements.property.value; |
172 |
const data = { source, object_id, property, localization_id }; |
173 |
|
170 |
const client = APIClient.localization; |
174 |
const client = APIClient.localization; |
171 |
client.localizations.delete(id).then( |
175 |
client.localizations.delete(data).then( |
172 |
success => { |
176 |
success => { |
173 |
$("#localization").DataTable().row( '#row_id_' + id ).remove().draw(); |
177 |
$("#localization").DataTable().row( '#row_id_' + localization_id ).remove().draw(); |
174 |
show_message({ type: 'success_on_delete', data: {id} }); |
178 |
show_message({ type: 'success_on_delete', data: {localization_id} }); |
175 |
}, |
179 |
}, |
176 |
error => { |
180 |
error => { |
177 |
$(cell).css('background-color', '#FF9090'); |
181 |
$(cell).css('background-color', '#FF9090'); |
Lines 212-217
Link Here
|
212 |
}); |
216 |
}); |
213 |
$("td.lang").on('click', function(){ |
217 |
$("td.lang").on('click', function(){ |
214 |
var td = this; |
218 |
var td = this; |
|
|
219 |
if (td.childElementCount > 0) { |
220 |
// do nothing if there is already something there (like a select for instance) |
221 |
return; |
222 |
} |
223 |
|
215 |
var lang = $(td).text(); |
224 |
var lang = $(td).text(); |
216 |
$(td).css('background-color', ''); |
225 |
$(td).css('background-color', ''); |
217 |
var my_select = $(languages_select).clone(); |
226 |
var my_select = $(languages_select).clone(); |
Lines 221-230
Link Here
|
221 |
}); |
230 |
}); |
222 |
$(my_select).on('change', function(){ |
231 |
$(my_select).on('change', function(){ |
223 |
var tr = $(this).parent().parent(); |
232 |
var tr = $(this).parent().parent(); |
224 |
var id = $(tr).data('id'); |
233 |
var localization_id = $(tr).data('id'); |
225 |
var lang = $(this).find('option:selected').val(); |
234 |
var lang = $(this).find('option:selected').val(); |
226 |
var translation = $(this).text(); |
235 |
send_update_request( {localization_id, lang}, td ); |
227 |
send_update_request( {id, lang, translation}, td ); |
|
|
228 |
}); |
236 |
}); |
229 |
$(my_select).on('blur', function(){ |
237 |
$(my_select).on('blur', function(){ |
230 |
$(td).html(lang); |
238 |
$(td).html(lang); |
Lines 234-243
Link Here
|
234 |
|
242 |
|
235 |
$("td.translation").on('blur', function(){ |
243 |
$("td.translation").on('blur', function(){ |
236 |
var tr = $(this).parent(); |
244 |
var tr = $(this).parent(); |
237 |
var id = $(tr).data('id'); |
245 |
var localization_id = $(tr).data('id'); |
238 |
var lang = $(tr).find('td.lang').text(); |
|
|
239 |
var translation = $(this).text(); |
246 |
var translation = $(this).text(); |
240 |
send_update_request( {id, lang, translation}, this ); |
247 |
send_update_request( {localization_id, translation}, this ); |
241 |
}); |
248 |
}); |
242 |
|
249 |
|
243 |
$("body").on("click", "a.delete", function(e){ |
250 |
$("body").on("click", "a.delete", function(e){ |
Lines 252-271
Link Here
|
252 |
|
259 |
|
253 |
$("#add_translation").on('submit', function(e){ |
260 |
$("#add_translation").on('submit', function(e){ |
254 |
e.preventDefault(); |
261 |
e.preventDefault(); |
255 |
let localization = { |
262 |
|
256 |
entity: $(this).find('input[name="entity"]').val(), |
263 |
const form = this; |
257 |
code: $(this).find('input[name="code"]').val(), |
264 |
const source = form.elements.source.value; |
258 |
lang: $(this).find('select[name="lang"] option:selected').val(), |
265 |
const object_id = form.elements.object_id.value; |
259 |
translation: $(this).find('input[name="translation"]').val(), |
266 |
const property = form.elements.property.value; |
260 |
}; |
267 |
const lang = form.elements.lang.value |
|
|
268 |
const translation = form.elements.translation.value |
269 |
|
270 |
let localization = { source, object_id, property, lang, translation }; |
261 |
const client = APIClient.localization; |
271 |
const client = APIClient.localization; |
262 |
client.localizations.create(localization).then( |
272 |
client.localizations.create(localization).then( |
263 |
success => { |
273 |
success => { |
264 |
if ( success.error ) { |
274 |
if ( success.error ) { |
265 |
show_message({ type: 'error_on_insert', data: success }); |
275 |
show_message({ type: 'error_on_insert', data: success }); |
266 |
} else { |
276 |
} else { |
267 |
var new_row = table.row.add( [ success.id, success.entity, success.code, success.lang, success.translation, "<a href=\"#\" class=\"delete\"><i class=\"fa fa-trash-can\"></i> Delete</a>" ] ).draw().node(); |
277 |
let delete_str = _("Delete"); |
268 |
$( new_row ).attr("id", "row_id_" + success.id ).data("id", success.id ); |
278 |
var new_row = table.row.add( [ success.lang, success.translation, "<a href=\"#\" class=\"delete\"><i class=\"fa fa-trash-can\"></i> %s</a>".format(escape_str(delete_str)) ] ).draw().node(); |
|
|
279 |
$( new_row ).attr("id", "row_id_" + success.localization_id ).data("id", success.localization_id ); |
269 |
show_message({ type: 'success_on_insert', data: success }); |
280 |
show_message({ type: 'success_on_insert', data: success }); |
270 |
} |
281 |
} |
271 |
}, |
282 |
}, |