Skip to content

Commit 958142a

Browse files
committed
Uses REST for do_ajax_edit_impr_text.
Code is still dirty though.
1 parent f5dd1bb commit 958142a

2 files changed

Lines changed: 152 additions & 9 deletions

File tree

‎js/pgm.js‎

Lines changed: 38 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/js/jq_pgm.js‎

Lines changed: 114 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,25 +1486,131 @@ function word_count_click () {
14861486
});
14871487
}
14881488

1489-
function do_ajax_edit_impr_text (pagepos, word) {
1489+
1490+
function make_trans(i, wid, trans, word, lang, transarr)
1491+
{
1492+
trans = trans.trim();
1493+
const widset = Number.isInteger(wid);
1494+
let r = "";
1495+
let set = false;
1496+
if (widset) {
1497+
transarr.forEach(function (val) {
1498+
const tt = val.trim();
1499+
if (tt == '*' || tt == '') {
1500+
return;
1501+
}
1502+
set = tt == trans;
1503+
r += `<span class="nowrap">
1504+
<input class="impr-ann-radio" ` +
1505+
(set ? '' : 'checked="checked" ') + 'type="radio" name="rg' +
1506+
i + `" value="` + escape_html_chars(tt) + `" />
1507+
&nbsp; ` + escape_html_chars(tt) + `
1508+
</span>
1509+
<br />`;
1510+
1511+
});
1512+
r += `<span class="nowrap">
1513+
<input class="impr-ann-radio" type="radio" name="rg` + i + `" ` +
1514+
(set ? `` : `checked="checked" `) + `value="" />
1515+
&nbsp;
1516+
<input class="impr-ann-text" type="text" name="tx` + i +
1517+
`" id="tx` + i + `" value="` + (set ? '' : escape_html_chars(trans)) +
1518+
`" maxlength="50" size="40" />`;
1519+
} else {
1520+
r =
1521+
`<span class="nowrap">
1522+
<input checked="checked" type="radio" name="rg` + i + `" value="" />
1523+
&nbsp;
1524+
<input class="impr-ann-text" type="text" name="tx` + i +
1525+
`" id="tx` + i + `" value="` + escape_html_chars(trans) +
1526+
`" maxlength="50" size="40" />`;
1527+
}
1528+
r +=
1529+
` &nbsp;
1530+
<img class="click" src="icn/eraser.png" title="Erase Text Field"
1531+
alt="Erase Text Field"
1532+
onclick="$('#tx` + i + `').val('').trigger('change');" />
1533+
&nbsp;
1534+
<img class="click" src="icn/star.png" title="* (Set to Term)"
1535+
alt="* (Set to Term)"
1536+
onclick="$('#tx` + i + `').val('*').trigger('change');" />
1537+
&nbsp;`;
1538+
if (widset) {
1539+
r +=
1540+
`<img class="click" src="icn/plus-button.png"
1541+
title="Save another translation to existent term"
1542+
alt="Save another translation to existent term"
1543+
onclick="addTermTranslation(` + wid + `, '#tx` + i + `','',` + lang + `);" />`;
1544+
} else {
1545+
r +=
1546+
`<img class="click" src="icn/plus-button.png"
1547+
title="Save translation to new term"
1548+
alt="Save translation to new term"
1549+
onclick="addTermTranslation(0, '#tx` + i + `',` + word + `,` + lang + `);" />`;
1550+
}
1551+
r += `&nbsp;&nbsp;
1552+
<span id="wait` + i + `">
1553+
<img src="icn/empty.gif" />
1554+
</span>
1555+
</span>`;
1556+
return r;
1557+
}
1558+
1559+
function edit_term_ann_translations(trans_data)
1560+
{
1561+
let plus;
1562+
if (trans_data["wid"] !== null) {
1563+
plus = `<a name="rec' + trans_data["ann_index"] + '"></a>
1564+
<span class="click" onclick="oewin('edit_word.php?fromAnn=' + $(document).scrollTop() + '&amp;wid='` +
1565+
trans_data["wid"] + `');">
1566+
<img src="icn/sticky-note--pencil.png" title="Edit Term" alt="Edit Term" />
1567+
</span>`;
1568+
} else {
1569+
plus = '&nbsp;';
1570+
}
1571+
$('#editlink' + trans_data["ann_index"]).html(plus);
1572+
trans_data.translations.forEach(
1573+
function (candidate_trans) {
1574+
plus = make_trans(
1575+
trans_data["ann_index"], trans_data["wid"], candidate_trans,
1576+
trans_data["term_lc"], trans_data["lang_id"], trans_data.translations
1577+
);
1578+
$('#transsel' + trans_data["ann_index"]).html(plus);
1579+
}
1580+
);
1581+
}
1582+
1583+
/**
1584+
* Load the possible translations for a word.
1585+
*
1586+
* @param {int} pagepos Position to scroll to
1587+
* @param {string} word Word to get annotations
1588+
* @returns
1589+
*/
1590+
function do_ajax_edit_impr_text(pagepos, word) {
1591+
// Special case, on empty word reload the main annotations form
14901592
if (word == '') {
14911593
$('#editimprtextdata').html('<img src="icn/waiting2.gif" />');
14921594
location.reload();
14931595
return;
14941596
}
1597+
// Load the possible translations for a word
14951598
const textid = $('#editimprtextdata').attr('data_id');
1496-
$.post(
1497-
'inc/ajax_edit_impr_text.php',
1498-
{
1499-
id: textid,
1500-
word: word
1599+
$.get(
1600+
'inc/ajax.php',
1601+
{
1602+
action: "query",
1603+
action_type: "term_translations",
1604+
text_id: textid,
1605+
term_lc: word
15011606
},
15021607
function (data) {
1503-
eval(data);
1608+
edit_term_ann_translations(data);
15041609
$.scrollTo(pagepos);
15051610
$('input.impr-ann-text').on('change', changeImprAnnText);
15061611
$('input.impr-ann-radio').on('change', changeImprAnnRadio);
1507-
}
1612+
},
1613+
"json"
15081614
);
15091615
}
15101616

0 commit comments

Comments
 (0)