function term_edit_dlg_init(title = gLocal.gui.dict_terms) {
$("body").append('
');
$("#term_edit_dlg").dialog({
autoOpen: false,
width: 550,
outerHeight: "80vh",
buttons: [
{
id:"term_edit_dlg_save",
text: gLocal.gui.submit,
click: function () {
term_edit_dlg_save();
$(this).dialog("close");
},
},
{
text: gLocal.gui.cancel,
click: function () {
$(this).dialog("close");
},
},
],
});
}
/*
obj:调用此函数的按钮的handle
*/
function term_edit_dlg_open(id = "", word = "",channel="",lang="",obj=null) {
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,obj);
$("#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,obj);
$("#term_edit_dlg_content").html(html);
$("#term_edit_dlg").dialog("open");
}
);
}
}
function term_edit_dlg_render(word = null,obj=null) {
if (word == null) {
word = new Object();
word.guid = "";
word.word = "";
word.meaning = "";
word.other_meaning = "";
word.tag = "";
word.note = "";
}
let output = "";
output += "";
return output;
}
function set_term_dlg_channel_msg(msg){
$("#term_dlg_channel_msg").text(msg);
}
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;
}
},
});
}
function term_save_as(obj){
if(obj.checked){
$("#term_save_as_channel").show();
}else{
$("#term_save_as_channel").hide();
}
}