Lines 18-37
Link Here
|
18 |
</head> |
18 |
</head> |
19 |
|
19 |
|
20 |
<body id="admin_localization" class="admin"> |
20 |
<body id="admin_localization" class="admin"> |
21 |
<div class="main container-fluid"> |
21 |
<div class="container-fluid"> |
22 |
<div class="row"> |
22 |
<div class="row"> |
23 |
<div class="col-sm-12"> |
23 |
<div class="col-sm-12"> |
24 |
<h1>Localization</h1> |
24 |
<h1>Localization</h1> |
25 |
<form id="add_translation" method="get"> |
25 |
<form id="add_translation" method="get"> |
26 |
[% INCLUDE 'csrf-token.inc' %] |
26 |
[% INCLUDE 'csrf-token.inc' %] |
27 |
<input type="hidden" name="entity" value="[% entity | html %]" /> |
27 |
<input type="hidden" name="source" value="[% source | html %]" /> |
28 |
<input type="hidden" name="code" value="[% code | html %]" /> |
28 |
<input type="hidden" name="object_id" value="[% object_id | html %]" /> |
29 |
<input type="hidden" name="interface" value="[% interface_side | html %]" /> |
29 |
<input type="hidden" name="property" value="[% property | html %]" /> |
30 |
<fieldset class="rows clearfix"> |
30 |
<fieldset class="rows clearfix"> |
31 |
<ol> |
31 |
<ol> |
32 |
<li> |
32 |
<li> |
33 |
<span class="label">Authorized value:</span> |
33 |
<span class="label">Authorized value:</span> |
34 |
[% code | html %] |
34 |
[% object_id | html %] |
35 |
</li> |
35 |
</li> |
36 |
<li> |
36 |
<li> |
37 |
<label for="lang">Language:</label> |
37 |
<label for="lang">Language:</label> |
Lines 76-84
Link Here
|
76 |
<table id="localization"> |
76 |
<table id="localization"> |
77 |
<thead> |
77 |
<thead> |
78 |
<tr> |
78 |
<tr> |
79 |
<th>Id</th> |
|
|
80 |
<th>Entity</th> |
81 |
<th>Code</th> |
82 |
<th>Language</th> |
79 |
<th>Language</th> |
83 |
<th>Translation</th> |
80 |
<th>Translation</th> |
84 |
<th class="NoSort"> </th> |
81 |
<th class="NoSort"> </th> |
Lines 86-95
Link Here
|
86 |
</thead> |
83 |
</thead> |
87 |
<tbody> |
84 |
<tbody> |
88 |
[% FOR t IN translations %] |
85 |
[% FOR t IN translations %] |
89 |
<tr id="row_id_[% t.id | html %]" data-id="[% t.id | html %]"> |
86 |
<tr id="row_id_[% t.localization_id | html %]" data-id="[% t.localization_id | html %]"> |
90 |
<td>[% t.id | html %]</td> |
|
|
91 |
<td>[% t.entity | html %]</td> |
92 |
<td>[% t.code | html %]</td> |
93 |
<td class="lang">[% t.lang | html %]</td> |
87 |
<td class="lang">[% t.lang | html %]</td> |
94 |
<td class="translation" contenteditable="true">[% t.translation | html %]</td> |
88 |
<td class="translation" contenteditable="true">[% t.translation | html %]</td> |
95 |
<td class="actions" |
89 |
<td class="actions" |
Lines 104-110
Link Here
|
104 |
</div> |
98 |
</div> |
105 |
<!-- /.row --> |
99 |
<!-- /.row --> |
106 |
</div> |
100 |
</div> |
107 |
<!-- /.main.container-fluid --> |
101 |
<!-- /.container-fluid --> |
108 |
|
102 |
|
109 |
[% MACRO jsinclude BLOCK %] |
103 |
[% MACRO jsinclude BLOCK %] |
110 |
[% INCLUDE 'datatables.inc' %] |
104 |
[% INCLUDE 'datatables.inc' %] |
Lines 116-122
Link Here
|
116 |
var message; |
110 |
var message; |
117 |
if ( type == 'success_on_update' ) { |
111 |
if ( type == 'success_on_update' ) { |
118 |
message = $('<div class="alert alert-info"></div>'); |
112 |
message = $('<div class="alert alert-info"></div>'); |
119 |
message.text(_("Entity %s (code %s) for lang %s has correctly been updated with '%s'").format(data.entity, data.code, data.lang, data.translation)); |
113 |
message.text(_("Translation for lang %s has correctly been updated with '%s'").format(data.lang, data.translation)); |
120 |
} else if ( type == 'error_on_update' ) { |
114 |
} else if ( type == 'error_on_update' ) { |
121 |
message = $('<div class="alert alert-warning"></div>'); |
115 |
message = $('<div class="alert alert-warning"></div>'); |
122 |
if ( data.error_code == 'already_exists' ) { |
116 |
if ( data.error_code == 'already_exists' ) { |
Lines 126-138
Link Here
|
126 |
} |
120 |
} |
127 |
} else if ( type == 'success_on_delete' ) { |
121 |
} else if ( type == 'success_on_delete' ) { |
128 |
message = $('<div class="alert alert-info"></div>'); |
122 |
message = $('<div class="alert alert-info"></div>'); |
129 |
message.text(_("The translation (id %s) has been removed successfully").format(data.id)); |
123 |
message.text(_("The translation has been removed successfully")); |
130 |
} else if ( type == 'error_on_delete' ) { |
124 |
} else if ( type == 'error_on_delete' ) { |
131 |
message = $('<div class="alert alert-warning"></div>'); |
125 |
message = $('<div class="alert alert-warning"></div>'); |
132 |
message.text(_("An error occurred when deleting this translation")); |
126 |
message.text(_("An error occurred when deleting this translation")); |
133 |
} else if ( type == 'success_on_insert' ) { |
127 |
} else if ( type == 'success_on_insert' ) { |
134 |
message = $('<div class="alert alert-info"></div>'); |
128 |
message = $('<div class="alert alert-info"></div>'); |
135 |
message.text(_("Translation (id %s) has been added successfully").format(data.id)); |
129 |
message.text(_("Translation has been added successfully")); |
136 |
} else if ( type == 'error_on_insert' ) { |
130 |
} else if ( type == 'error_on_insert' ) { |
137 |
message = $('<div class="alert alert-warning"></div>'); |
131 |
message = $('<div class="alert alert-warning"></div>'); |
138 |
if ( data.error_code == 'already_exists' ) { |
132 |
if ( data.error_code == 'already_exists' ) { |
Lines 149-162
Link Here
|
149 |
}, 3000); |
143 |
}, 3000); |
150 |
} |
144 |
} |
151 |
|
145 |
|
152 |
function send_update_request( data, cell ) { |
146 |
function send_update_request( _data, cell ) { |
|
|
147 |
const form = document.forms.add_translation; |
148 |
const source = form.elements.source.value; |
149 |
const object_id = form.elements.object_id.value; |
150 |
const data = Object.assign({}, _data, { source, object_id }); |
153 |
const client = APIClient.localization; |
151 |
const client = APIClient.localization; |
154 |
client.localizations.update(data).then( |
152 |
client.localizations.update(data).then( |
155 |
success => { |
153 |
success => { |
156 |
if ( success.error ) { |
154 |
if ( success.error ) { |
157 |
$(cell).css('background-color', '#FF0000'); |
155 |
$(cell).css('background-color', '#FF0000'); |
158 |
show_message({ type: 'error_on_update', data: success }); |
156 |
show_message({ type: 'error_on_update', data: success }); |
159 |
} else if ( success.is_changed == 1 ) { |
157 |
} else { |
160 |
$(cell).css('background-color', '#00FF00'); |
158 |
$(cell).css('background-color', '#00FF00'); |
161 |
show_message({ type: 'success_on_update', data: success }); |
159 |
show_message({ type: 'success_on_update', data: success }); |
162 |
} |
160 |
} |
Lines 180-191
Link Here
|
180 |
); |
178 |
); |
181 |
} |
179 |
} |
182 |
|
180 |
|
183 |
function send_delete_request( id, cell ) { |
181 |
function send_delete_request( localization_id, cell ) { |
|
|
182 |
const form = document.forms.add_translation; |
183 |
const source = form.elements.source.value; |
184 |
const object_id = form.elements.object_id.value; |
185 |
const property = form.elements.property.value; |
186 |
const data = { source, object_id, property, localization_id }; |
187 |
|
184 |
const client = APIClient.localization; |
188 |
const client = APIClient.localization; |
185 |
client.localizations.delete(id).then( |
189 |
client.localizations.delete(data).then( |
186 |
success => { |
190 |
success => { |
187 |
$("#localization").DataTable().row( '#row_id_' + id ).remove().draw(); |
191 |
$("#localization").DataTable().row( '#row_id_' + localization_id ).remove().draw(); |
188 |
show_message({ type: 'success_on_delete', data: {id} }); |
192 |
show_message({ type: 'success_on_delete', data: {localization_id} }); |
189 |
}, |
193 |
}, |
190 |
error => { |
194 |
error => { |
191 |
$(cell).css('background-color', '#FF9090'); |
195 |
$(cell).css('background-color', '#FF9090'); |
Lines 224-229
Link Here
|
224 |
}); |
228 |
}); |
225 |
$("td.lang").on('click', function(){ |
229 |
$("td.lang").on('click', function(){ |
226 |
var td = this; |
230 |
var td = this; |
|
|
231 |
if (td.childElementCount > 0) { |
232 |
// do nothing if there is already something there (like a select for instance) |
233 |
return; |
234 |
} |
235 |
|
227 |
var lang = $(td).text(); |
236 |
var lang = $(td).text(); |
228 |
$(td).css('background-color', ''); |
237 |
$(td).css('background-color', ''); |
229 |
var my_select = $(languages_select).clone(); |
238 |
var my_select = $(languages_select).clone(); |
Lines 233-242
Link Here
|
233 |
}); |
242 |
}); |
234 |
$(my_select).on('change', function(){ |
243 |
$(my_select).on('change', function(){ |
235 |
var tr = $(this).parent().parent(); |
244 |
var tr = $(this).parent().parent(); |
236 |
var id = $(tr).data('id'); |
245 |
var localization_id = $(tr).data('id'); |
237 |
var lang = $(this).find('option:selected').val(); |
246 |
var lang = $(this).find('option:selected').val(); |
238 |
var translation = $(this).text(); |
247 |
send_update_request( {localization_id, lang}, td ); |
239 |
send_update_request( {id, lang, translation}, td ); |
|
|
240 |
}); |
248 |
}); |
241 |
$(my_select).on('blur', function(){ |
249 |
$(my_select).on('blur', function(){ |
242 |
$(td).html(lang); |
250 |
$(td).html(lang); |
Lines 246-255
Link Here
|
246 |
|
254 |
|
247 |
$("td.translation").on('blur', function(){ |
255 |
$("td.translation").on('blur', function(){ |
248 |
var tr = $(this).parent(); |
256 |
var tr = $(this).parent(); |
249 |
var id = $(tr).data('id'); |
257 |
var localization_id = $(tr).data('id'); |
250 |
var lang = $(tr).find('td.lang').text(); |
|
|
251 |
var translation = $(this).text(); |
258 |
var translation = $(this).text(); |
252 |
send_update_request( {id, lang, translation}, this ); |
259 |
send_update_request( {localization_id, translation}, this ); |
253 |
}); |
260 |
}); |
254 |
|
261 |
|
255 |
$("body").on("click", "a.delete", function(e){ |
262 |
$("body").on("click", "a.delete", function(e){ |
Lines 264-283
Link Here
|
264 |
|
271 |
|
265 |
$("#add_translation").on('submit', function(e){ |
272 |
$("#add_translation").on('submit', function(e){ |
266 |
e.preventDefault(); |
273 |
e.preventDefault(); |
267 |
let localization = { |
274 |
|
268 |
entity: $(this).find('input[name="entity"]').val(), |
275 |
const form = this; |
269 |
code: $(this).find('input[name="code"]').val(), |
276 |
const source = form.elements.source.value; |
270 |
lang: $(this).find('select[name="lang"] option:selected').val(), |
277 |
const object_id = form.elements.object_id.value; |
271 |
translation: $(this).find('input[name="translation"]').val(), |
278 |
const property = form.elements.property.value; |
272 |
}; |
279 |
const lang = form.elements.lang.value |
|
|
280 |
const translation = form.elements.translation.value |
281 |
|
282 |
let localization = { source, object_id, property, lang, translation }; |
273 |
const client = APIClient.localization; |
283 |
const client = APIClient.localization; |
274 |
client.localizations.create(localization).then( |
284 |
client.localizations.create(localization).then( |
275 |
success => { |
285 |
success => { |
276 |
if ( success.error ) { |
286 |
if ( success.error ) { |
277 |
show_message({ type: 'error_on_insert', data: success }); |
287 |
show_message({ type: 'error_on_insert', data: success }); |
278 |
} else { |
288 |
} else { |
279 |
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(); |
289 |
let delete_str = _("Delete"); |
280 |
$( new_row ).attr("id", "row_id_" + success.id ).data("id", success.id ); |
290 |
var new_row = table.api().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(); |
|
|
291 |
$( new_row ).attr("id", "row_id_" + success.localization_id ).data("id", success.localization_id ); |
281 |
show_message({ type: 'success_on_insert', data: success }); |
292 |
show_message({ type: 'success_on_insert', data: success }); |
282 |
} |
293 |
} |
283 |
}, |
294 |
}, |