|
Lines 5-16
Link Here
|
| 5 |
[% INCLUDE 'doc-head-open.inc' %] |
5 |
[% INCLUDE 'doc-head-open.inc' %] |
| 6 |
<title> |
6 |
<title> |
| 7 |
[% FILTER collapse %] |
7 |
[% FILTER collapse %] |
| 8 |
[% SWITCH entity %] |
8 |
[% SWITCH source %] |
| 9 |
[% CASE "itemtypes" %] |
9 |
[% CASE "Itemtype" %] |
| 10 |
[% tx("Add translations for item type '{code}'", { code = code }) | html %] |
10 |
[% tx("Add translations for item type '{code}'", { code = object_id }) | html %] |
| 11 |
› [% t("Item types") | html %] › [% t("Administration") | html %] |
11 |
› [% t("Item types") | html %] › [% t("Administration") | html %] |
| 12 |
[% CASE %] |
12 |
[% CASE %] |
| 13 |
[% tx("Add translations for '{code}'", { code = code }) | html %] |
13 |
[% tx("Add translations for '{code}'", { code = object_id }) | html %] |
| 14 |
[% END %] |
14 |
[% END %] |
| 15 |
› [% t("Koha") | html %] |
15 |
› [% t("Koha") | html %] |
| 16 |
[% END %] |
16 |
[% END %] |
|
Lines 29-36
Link Here
|
| 29 |
[% END %] |
29 |
[% END %] |
| 30 |
[% WRAPPER 'sub-header.inc' %] |
30 |
[% WRAPPER 'sub-header.inc' %] |
| 31 |
[% WRAPPER breadcrumbs %] |
31 |
[% WRAPPER breadcrumbs %] |
| 32 |
[% SWITCH entity %] |
32 |
[% SWITCH source %] |
| 33 |
[% CASE "itemtypes" %] |
33 |
[% CASE "Itemtype" %] |
| 34 |
[% WRAPPER breadcrumb_item %] |
34 |
[% WRAPPER breadcrumb_item %] |
| 35 |
<a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> |
35 |
<a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> |
| 36 |
[% END %] |
36 |
[% END %] |
|
Lines 38-74
Link Here
|
| 38 |
<a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a> |
38 |
<a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a> |
| 39 |
[% END %] |
39 |
[% END %] |
| 40 |
[% WRAPPER breadcrumb_item %] |
40 |
[% WRAPPER breadcrumb_item %] |
| 41 |
<a href="/cgi-bin/koha/admin/itemtypes.pl?op=add_form&itemtype=[% code | uri %]"> [% tx("Modify item type '{code}'", { code = code }) | html %] </a> |
41 |
<a href="/cgi-bin/koha/admin/itemtypes.pl?op=add_form&itemtype=[% object_id | uri %]"> [% tx("Modify item type '{code}'", { code = object_id }) | html %] </a> |
| 42 |
[% END %] |
42 |
[% END %] |
| 43 |
[% WRAPPER breadcrumb_item bc_active= 1 %] |
43 |
[% WRAPPER breadcrumb_item bc_active= 1 %] |
| 44 |
<span>Add translations</span> |
44 |
<span>Add translations</span> |
| 45 |
[% END %] |
45 |
[% END %] |
| 46 |
[% CASE %] |
46 |
[% CASE %] |
| 47 |
[% WRAPPER breadcrumb_item bc_active= 1 %] |
47 |
[% WRAPPER breadcrumb_item bc_active= 1 %] |
| 48 |
[% tx("Add translations for '{code}'", { code = code }) | html %] |
48 |
[% tx("Add translations for '{code}'", { code = object_id }) | html %] |
| 49 |
[% END %] |
49 |
[% END %] |
| 50 |
[% END %] |
50 |
[% END %] |
| 51 |
[% END #/ WRAPPER breadcrumbs %] |
51 |
[% END #/ WRAPPER breadcrumbs %] |
| 52 |
[% END #/ WRAPPER sub-header.inc %] |
52 |
[% END #/ WRAPPER sub-header.inc %] |
| 53 |
|
53 |
|
| 54 |
[% WRAPPER 'main-container.inc' %] |
54 |
[% WRAPPER 'main-container.inc' %] |
| 55 |
[% SWITCH entity %] |
55 |
[% SWITCH source %] |
| 56 |
[% CASE "itemtypes" %] |
56 |
[% CASE "Itemtype" %] |
| 57 |
<h1>[% tx("Add translations for item type '{code}'", { code = code }) | html %]</h1> |
57 |
<h1>[% tx("Add translations for item type '{code}'", { code = object_id }) | html %]</h1> |
| 58 |
[% CASE %] |
58 |
[% CASE %] |
| 59 |
<h1>[% tx("Add translations for '{code}'", { code = code }) | html %]</h1> |
59 |
<h1>[% tx("Add translations for '{code}'", { code = code }) | html %]</h1> |
| 60 |
[% END %] |
60 |
[% END %] |
| 61 |
|
61 |
|
| 62 |
<form id="add_translation" method="get"> |
62 |
<form id="add_translation" method="get"> |
| 63 |
[% INCLUDE 'csrf-token.inc' %] |
63 |
[% INCLUDE 'csrf-token.inc' %] |
| 64 |
<input type="hidden" name="entity" value="[% entity | html %]" /> |
64 |
<input type="hidden" name="source" value="[% source | html %]" /> |
| 65 |
<input type="hidden" name="code" value="[% code | html %]" /> |
65 |
<input type="hidden" name="object_id" value="[% object_id | html %]" /> |
| 66 |
<input type="hidden" name="interface" value="[% interface_side | html %]" /> |
66 |
<input type="hidden" name="property" value="[% property | html %]" /> |
| 67 |
<fieldset class="rows clearfix"> |
67 |
<fieldset class="rows clearfix"> |
| 68 |
<ol> |
68 |
<ol> |
| 69 |
<li> |
69 |
<li> |
| 70 |
<span class="label">Authorized value:</span> |
70 |
<span class="label">Code:</span> |
| 71 |
[% code | html %] |
71 |
[% object_id | html %] |
| 72 |
</li> |
72 |
</li> |
| 73 |
<li> |
73 |
<li> |
| 74 |
<label for="lang">Language:</label> |
74 |
<label for="lang">Language:</label> |
|
Lines 100-108
Link Here
|
| 100 |
<table id="localization"> |
100 |
<table id="localization"> |
| 101 |
<thead> |
101 |
<thead> |
| 102 |
<tr> |
102 |
<tr> |
| 103 |
<th>Id</th> |
|
|
| 104 |
<th>Entity</th> |
| 105 |
<th>Code</th> |
| 106 |
<th class="lang">Language</th> |
103 |
<th class="lang">Language</th> |
| 107 |
<th class="translation">Translation</th> |
104 |
<th class="translation">Translation</th> |
| 108 |
<th class="no-sort"> </th> |
105 |
<th class="no-sort"> </th> |
|
Lines 110-126
Link Here
|
| 110 |
</thead> |
107 |
</thead> |
| 111 |
<tbody> |
108 |
<tbody> |
| 112 |
[% FOR t IN translations %] |
109 |
[% FOR t IN translations %] |
| 113 |
<tr id="row_id_[% t.id | html %]" data-id="[% t.id | html %]"> |
110 |
<tr id="row_id_[% t.localization_id | html %]" data-id="[% t.localization_id | html %]"> |
| 114 |
<td>[% t.id | html %]</td> |
|
|
| 115 |
<td> |
| 116 |
[% SWITCH entity %] |
| 117 |
[% CASE "itemtypes" %] |
| 118 |
Item type |
| 119 |
[% CASE %] |
| 120 |
[% t.entity | html %] |
| 121 |
[% END %] |
| 122 |
</td> |
| 123 |
<td>[% t.code | html %]</td> |
| 124 |
<td class="lang">[% t.lang | html %]</td> |
111 |
<td class="lang">[% t.lang | html %]</td> |
| 125 |
<td class="translation" contenteditable="true">[% t.translation | html %]</td> |
112 |
<td class="translation" contenteditable="true">[% t.translation | html %]</td> |
| 126 |
<td class="actions" |
113 |
<td class="actions" |
|
Lines 149-155
Link Here
|
| 149 |
var message; |
136 |
var message; |
| 150 |
if ( type == 'success_on_update' ) { |
137 |
if ( type == 'success_on_update' ) { |
| 151 |
message = $('<div class="alert alert-info"></div>'); |
138 |
message = $('<div class="alert alert-info"></div>'); |
| 152 |
message.text(_("Entity %s (code %s) for lang %s has been updated with '%s'").format(data.entity, data.code, data.lang, data.translation)); |
139 |
message.text(_("Translation for lang %s has correctly been updated with '%s'").format(data.lang, data.translation)); |
| 153 |
} else if ( type == 'error_on_update' ) { |
140 |
} else if ( type == 'error_on_update' ) { |
| 154 |
message = $('<div class="alert alert-warning"></div>'); |
141 |
message = $('<div class="alert alert-warning"></div>'); |
| 155 |
if ( data.error_code == 'already_exists' ) { |
142 |
if ( data.error_code == 'already_exists' ) { |
|
Lines 159-171
Link Here
|
| 159 |
} |
146 |
} |
| 160 |
} else if ( type == 'success_on_delete' ) { |
147 |
} else if ( type == 'success_on_delete' ) { |
| 161 |
message = $('<div class="alert alert-info"></div>'); |
148 |
message = $('<div class="alert alert-info"></div>'); |
| 162 |
message.text(_("The translation (id %s) has been removed successfully").format(data.id)); |
149 |
message.text(_("The translation has been removed successfully")); |
| 163 |
} else if ( type == 'error_on_delete' ) { |
150 |
} else if ( type == 'error_on_delete' ) { |
| 164 |
message = $('<div class="alert alert-warning"></div>'); |
151 |
message = $('<div class="alert alert-warning"></div>'); |
| 165 |
message.text(_("An error occurred when deleting this translation")); |
152 |
message.text(_("An error occurred when deleting this translation")); |
| 166 |
} else if ( type == 'success_on_insert' ) { |
153 |
} else if ( type == 'success_on_insert' ) { |
| 167 |
message = $('<div class="alert alert-info"></div>'); |
154 |
message = $('<div class="alert alert-info"></div>'); |
| 168 |
message.text(_("Translation (id %s) has been added successfully").format(data.id)); |
155 |
message.text(_("Translation has been added successfully")); |
| 169 |
} else if ( type == 'error_on_insert' ) { |
156 |
} else if ( type == 'error_on_insert' ) { |
| 170 |
message = $('<div class="alert alert-warning"></div>'); |
157 |
message = $('<div class="alert alert-warning"></div>'); |
| 171 |
if ( data.error_code == 'already_exists' ) { |
158 |
if ( data.error_code == 'already_exists' ) { |
|
Lines 182-195
Link Here
|
| 182 |
}, 3000); |
169 |
}, 3000); |
| 183 |
} |
170 |
} |
| 184 |
|
171 |
|
| 185 |
function send_update_request( data, cell ) { |
172 |
function send_update_request( _data, cell ) { |
|
|
173 |
const form = document.forms.add_translation; |
| 174 |
const source = form.elements.source.value; |
| 175 |
const object_id = form.elements.object_id.value; |
| 176 |
const data = Object.assign({}, _data, { source, object_id }); |
| 186 |
const client = APIClient.localization; |
177 |
const client = APIClient.localization; |
| 187 |
client.localizations.update(data).then( |
178 |
client.localizations.update(data).then( |
| 188 |
success => { |
179 |
success => { |
| 189 |
if ( success.error ) { |
180 |
if ( success.error ) { |
| 190 |
$(cell).css('background-color', '#FF0000'); |
181 |
$(cell).css('background-color', '#FF0000'); |
| 191 |
show_message({ type: 'error_on_update', data: success }); |
182 |
show_message({ type: 'error_on_update', data: success }); |
| 192 |
} else if ( success.is_changed == 1 ) { |
183 |
} else { |
| 193 |
$(cell).css('background-color', '#00FF00'); |
184 |
$(cell).css('background-color', '#00FF00'); |
| 194 |
show_message({ type: 'success_on_update', data: success }); |
185 |
show_message({ type: 'success_on_update', data: success }); |
| 195 |
} |
186 |
} |
|
Lines 213-224
Link Here
|
| 213 |
); |
204 |
); |
| 214 |
} |
205 |
} |
| 215 |
|
206 |
|
| 216 |
function send_delete_request( id, cell ) { |
207 |
function send_delete_request( localization_id, cell ) { |
|
|
208 |
const form = document.forms.add_translation; |
| 209 |
const source = form.elements.source.value; |
| 210 |
const object_id = form.elements.object_id.value; |
| 211 |
const property = form.elements.property.value; |
| 212 |
const data = { source, object_id, property, localization_id }; |
| 213 |
|
| 217 |
const client = APIClient.localization; |
214 |
const client = APIClient.localization; |
| 218 |
client.localizations.delete(id).then( |
215 |
client.localizations.delete(data).then( |
| 219 |
success => { |
216 |
success => { |
| 220 |
$("#localization").DataTable().row( '#row_id_' + id ).remove().draw(); |
217 |
$("#localization").DataTable().row( '#row_id_' + localization_id ).remove().draw(); |
| 221 |
show_message({ type: 'success_on_delete', data: {id} }); |
218 |
show_message({ type: 'success_on_delete', data: {localization_id} }); |
| 222 |
}, |
219 |
}, |
| 223 |
error => { |
220 |
error => { |
| 224 |
$(cell).css('background-color', '#FF9090'); |
221 |
$(cell).css('background-color', '#FF9090'); |
|
Lines 257-262
Link Here
|
| 257 |
}); |
254 |
}); |
| 258 |
$("body").on('click', "td.lang", function(){ |
255 |
$("body").on('click', "td.lang", function(){ |
| 259 |
var td = $(this); |
256 |
var td = $(this); |
|
|
257 |
if (td[0].childElementCount > 0) { |
| 258 |
// do nothing if there is already something there (like a select for instance) |
| 259 |
return; |
| 260 |
} |
| 260 |
var tr = td.parent(); |
261 |
var tr = td.parent(); |
| 261 |
var id = tr.data('id'); |
262 |
var id = tr.data('id'); |
| 262 |
var lang = td.text(); |
263 |
var lang = td.text(); |
|
Lines 268-276
Link Here
|
| 268 |
}); |
269 |
}); |
| 269 |
var lang; |
270 |
var lang; |
| 270 |
my_select.on('change', function(){ |
271 |
my_select.on('change', function(){ |
|
|
272 |
var localization_id = $(tr).data('id'); |
| 271 |
lang = td.find('option:selected').val(); |
273 |
lang = td.find('option:selected').val(); |
| 272 |
var translation = tr.find("td.translation").text(); |
274 |
send_update_request( {localization_id, lang}, td[0] ); |
| 273 |
send_update_request( {id, lang, translation}, td[0] ); |
|
|
| 274 |
}); |
275 |
}); |
| 275 |
my_select.on('blur', function(){ |
276 |
my_select.on('blur', function(){ |
| 276 |
td.html(lang); |
277 |
td.html(lang); |
|
Lines 280-289
Link Here
|
| 280 |
|
281 |
|
| 281 |
$("body").on('blur', "td.translation", function(){ |
282 |
$("body").on('blur', "td.translation", function(){ |
| 282 |
var tr = $(this).parent(); |
283 |
var tr = $(this).parent(); |
| 283 |
var id = $(tr).data('id'); |
284 |
var localization_id = $(tr).data('id'); |
| 284 |
var lang = $(tr).find('td.lang').text(); |
|
|
| 285 |
var translation = $(this).text(); |
285 |
var translation = $(this).text(); |
| 286 |
send_update_request( {id, lang, translation}, this ); |
286 |
send_update_request( {localization_id, translation}, this ); |
| 287 |
}); |
287 |
}); |
| 288 |
|
288 |
|
| 289 |
$("body").on("click", "a.delete", function(e){ |
289 |
$("body").on("click", "a.delete", function(e){ |
|
Lines 301-320
Link Here
|
| 301 |
|
301 |
|
| 302 |
$("#add_translation").on('submit', function(e){ |
302 |
$("#add_translation").on('submit', function(e){ |
| 303 |
e.preventDefault(); |
303 |
e.preventDefault(); |
| 304 |
let localization = { |
304 |
|
| 305 |
entity: $(this).find('input[name="entity"]').val(), |
305 |
const form = this; |
| 306 |
code: $(this).find('input[name="code"]').val(), |
306 |
const source = form.elements.source.value; |
| 307 |
lang: $(this).find('select[name="lang"] option:selected').val(), |
307 |
const object_id = form.elements.object_id.value; |
| 308 |
translation: $(this).find('input[name="translation"]').val(), |
308 |
const property = form.elements.property.value; |
| 309 |
}; |
309 |
const lang = form.elements.lang.value |
|
|
310 |
const translation = form.elements.translation.value |
| 311 |
|
| 312 |
let localization = { source, object_id, property, lang, translation }; |
| 310 |
const client = APIClient.localization; |
313 |
const client = APIClient.localization; |
| 311 |
client.localizations.create(localization).then( |
314 |
client.localizations.create(localization).then( |
| 312 |
success => { |
315 |
success => { |
| 313 |
if ( success.error ) { |
316 |
if ( success.error ) { |
| 314 |
show_message({ type: 'error_on_insert', data: success }); |
317 |
show_message({ type: 'error_on_insert', data: success }); |
| 315 |
} else { |
318 |
} else { |
| 316 |
var new_row = table_dt.row.add( [ success.id, success.entity, success.code, success.lang, success.translation, "<a href=\"#\" class=\"btn btn-default btn-xs delete\"><i class=\"fa fa-trash-can\"></i> Delete</a>" ] ).draw().node(); |
319 |
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"))) ] ).draw().node(); |
| 317 |
$( new_row ).attr("id", "row_id_" + success.id ).data("id", success.id ); |
320 |
$( new_row ).attr("id", "row_id_" + success.localization_id ).data("id", success.localization_id ); |
| 318 |
$( new_row.children[th_lang_index] ).prop("contenteditable", true).addClass("lang") |
321 |
$( new_row.children[th_lang_index] ).prop("contenteditable", true).addClass("lang") |
| 319 |
$( new_row.children[th_translation_index] ).prop("contenteditable", true).addClass("translation") |
322 |
$( new_row.children[th_translation_index] ).prop("contenteditable", true).addClass("translation") |
| 320 |
show_message({ type: 'success_on_insert', data: success }); |
323 |
show_message({ type: 'success_on_insert', data: success }); |