|
Lines 18-26
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> |
|
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 221-230
Link Here
|
| 221 |
}); |
225 |
}); |
| 222 |
$(my_select).on('change', function(){ |
226 |
$(my_select).on('change', function(){ |
| 223 |
var tr = $(this).parent().parent(); |
227 |
var tr = $(this).parent().parent(); |
| 224 |
var id = $(tr).data('id'); |
228 |
var localization_id = $(tr).data('id'); |
| 225 |
var lang = $(this).find('option:selected').val(); |
229 |
var lang = $(this).find('option:selected').val(); |
| 226 |
var translation = $(this).text(); |
230 |
send_update_request( {localization_id, lang}, td ); |
| 227 |
send_update_request( {id, lang, translation}, td ); |
|
|
| 228 |
}); |
231 |
}); |
| 229 |
$(my_select).on('blur', function(){ |
232 |
$(my_select).on('blur', function(){ |
| 230 |
$(td).html(lang); |
233 |
$(td).html(lang); |
|
Lines 234-243
Link Here
|
| 234 |
|
237 |
|
| 235 |
$("td.translation").on('blur', function(){ |
238 |
$("td.translation").on('blur', function(){ |
| 236 |
var tr = $(this).parent(); |
239 |
var tr = $(this).parent(); |
| 237 |
var id = $(tr).data('id'); |
240 |
var localization_id = $(tr).data('id'); |
| 238 |
var lang = $(tr).find('td.lang').text(); |
|
|
| 239 |
var translation = $(this).text(); |
241 |
var translation = $(this).text(); |
| 240 |
send_update_request( {id, lang, translation}, this ); |
242 |
send_update_request( {localization_id, translation}, this ); |
| 241 |
}); |
243 |
}); |
| 242 |
|
244 |
|
| 243 |
$("body").on("click", "a.delete", function(e){ |
245 |
$("body").on("click", "a.delete", function(e){ |
|
Lines 252-271
Link Here
|
| 252 |
|
254 |
|
| 253 |
$("#add_translation").on('submit', function(e){ |
255 |
$("#add_translation").on('submit', function(e){ |
| 254 |
e.preventDefault(); |
256 |
e.preventDefault(); |
| 255 |
let localization = { |
257 |
|
| 256 |
entity: $(this).find('input[name="entity"]').val(), |
258 |
const form = this; |
| 257 |
code: $(this).find('input[name="code"]').val(), |
259 |
const source = form.elements.source.value; |
| 258 |
lang: $(this).find('select[name="lang"] option:selected').val(), |
260 |
const object_id = form.elements.object_id.value; |
| 259 |
translation: $(this).find('input[name="translation"]').val(), |
261 |
const property = form.elements.property.value; |
| 260 |
}; |
262 |
const lang = form.elements.lang.value |
|
|
263 |
const translation = form.elements.translation.value |
| 264 |
|
| 265 |
let localization = { source, object_id, property, lang, translation }; |
| 261 |
const client = APIClient.localization; |
266 |
const client = APIClient.localization; |
| 262 |
client.localizations.create(localization).then( |
267 |
client.localizations.create(localization).then( |
| 263 |
success => { |
268 |
success => { |
| 264 |
if ( success.error ) { |
269 |
if ( success.error ) { |
| 265 |
show_message({ type: 'error_on_insert', data: success }); |
270 |
show_message({ type: 'error_on_insert', data: success }); |
| 266 |
} else { |
271 |
} 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(); |
272 |
var new_row = table.row.add( [ success.lang, success.translation, "<a href=\"#\" class=\"delete\"><i class=\"fa fa-trash-can\"></i> Delete</a>" ] ).draw().node(); |
| 268 |
$( new_row ).attr("id", "row_id_" + success.id ).data("id", success.id ); |
273 |
$( new_row ).attr("id", "row_id_" + success.localization_id ).data("id", success.localization_id ); |
| 269 |
show_message({ type: 'success_on_insert', data: success }); |
274 |
show_message({ type: 'success_on_insert', data: success }); |
| 270 |
} |
275 |
} |
| 271 |
}, |
276 |
}, |