function term_edit_dlg_init(title = gLocal.gui.dict_terms) {
$("body").append('
');
$("#term_edit_dlg").dialog({
autoOpen: false,
width: 550,
outerHeight: "80vh",
buttons: [
{
text: gLocal.gui.save,
click: function () {
term_edit_dlg_save();
$(this).dialog("close");
},
},
{
text: gLocal.gui.cancel,
click: function () {
$(this).dialog("close");
},
},
],
});
}
function term_edit_dlg_open(id = "", word = "",channel="",lang="") {
if (id == "") {
let newWord = new Object();
newWord.guid = "";
newWord.word = word;
newWord.meaning = "";
newWord.other_meaning = "";
newWord.tag = "";
newWord.note = "";
newWord.language = lang;
newWord.channel = channel;
let html = term_edit_dlg_render(newWord);
$("#term_edit_dlg_content").html(html);
$("#term_edit_dlg").dialog("open");
} else {
$.post(
"../term/term_get_id.php",
{
id: id,
},
function (data) {
let word = JSON.parse(data);
let html = term_edit_dlg_render(word);
$("#term_edit_dlg_content").html(html);
$("#term_edit_dlg").dialog("open");
}
);
}
}
function term_edit_dlg_render(word = "") {
if (word == "") {
word = new Object();
word.guid = "";
word.word = pali;
word.meaning = "";
word.other_meaning = "";
word.tag = "";
word.note = "";
}
let output = "";
output += "";
return output;
}
function term_edit_dlg_save() {
$.ajax({
type: "POST", //方法类型
dataType: "json", //预期服务器返回的数据类型
url: "../term/term_post.php", //url
data: $("#form_term").serialize(),
success: function (result) {
console.log(result); //打印服务端返回的数据(调试用)
if (result.status == 0) {
alert(result.message + gLocal.gui.saved + gLocal.gui.successful);
for (let index = 0; index < arrMyTerm.length; index++) {
const element = arrMyTerm[index];
if(element.guid==result.data.guid){
arrMyTerm.splice(index,1);
break;
}
}
arrMyTerm.push(result.data);
term_updata_translation();
} else {
alert("error:" + result.message);
}
},
error: function (data, status) {
alert("异常!" + data.responseText);
switch (status) {
case "timeout":
break;
case "error":
break;
case "notmodified":
break;
case "parsererror":
break;
default:
break;
}
},
});
}