term_edit_dlg.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. function term_edit_dlg_init(title = gLocal.gui.dict_terms) {
  2. $("body").append('<div id="term_edit_dlg" title="' + title + '"><div id="term_edit_dlg_content"></div></div>');
  3. $("#term_edit_dlg").dialog({
  4. autoOpen: false,
  5. width: 550,
  6. buttons: [
  7. {
  8. text: gLocal.gui.save,
  9. click: function () {
  10. term_edit_dlg_save();
  11. $(this).dialog("close");
  12. },
  13. },
  14. {
  15. text: gLocal.gui.cancel,
  16. click: function () {
  17. $(this).dialog("close");
  18. },
  19. },
  20. ],
  21. });
  22. }
  23. function term_edit_dlg_open(id = "") {
  24. if (id == "") {
  25. $("#term_edit_dlg").dialog("open");
  26. } else {
  27. $.post(
  28. "../term/term_get_id.php",
  29. {
  30. id: id,
  31. },
  32. function (data) {
  33. let word = JSON.parse(data);
  34. let html = term_edit_dlg_render(word);
  35. $("#term_edit_dlg_content").html(html);
  36. $("#term_edit_dlg").dialog("open");
  37. }
  38. );
  39. }
  40. }
  41. function term_edit_dlg_render(word = "") {
  42. if (word == "") {
  43. word = new Object();
  44. word.pali = "";
  45. }
  46. let output = "";
  47. output += "<form action='##' id='form_term'>";
  48. output += "<input type='hidden' id='term_edit_form_id' name='id' value='" + word.guid + "'>";
  49. output += "<fieldset>";
  50. output += "<legend>" + gLocal.gui.spell + "</legend>";
  51. output +=
  52. "<input type='input' id='term_edit_form_word' value='" +
  53. word.word +
  54. "'placeholder=" +
  55. gLocal.gui.required +
  56. ">";
  57. output += "</fieldset>";
  58. output += "<fieldset>";
  59. output += "<legend>" + gLocal.gui.first_choice_word + "</legend>";
  60. output +=
  61. "<input type='input' id='term_edit_form_meaning' value='" +
  62. word.meaning +
  63. "' placeholder=" +
  64. gLocal.gui.required +
  65. ">";
  66. output += "</fieldset>";
  67. output += "<fieldset>";
  68. output += "<legend>" + gLocal.gui.other_meaning + "</legend>";
  69. output +=
  70. "<input type='input' id='term_edit_form_othermeaning value='" +
  71. word.other_meaning +
  72. "' placeholder=" +
  73. gLocal.gui.optional +
  74. ">";
  75. output += "</fieldset>";
  76. output += "<fieldset>";
  77. output += "<legend>" + gLocal.gui.tag + "</legend>";
  78. output +=
  79. "<input type='input' id='term_edit_form_tag name='tag' value='" +
  80. word.tag +
  81. "' placeholder=" +
  82. gLocal.gui.optional +
  83. " >";
  84. output += "</fieldset>";
  85. output += "<fieldset>";
  86. output += "<legend>" + gLocal.gui.language + "</legend>";
  87. output +=
  88. "<input type='input' id='term_edit_form_language' value='" +
  89. word.language +
  90. "' placeholder=" +
  91. gLocal.gui.required +
  92. " >";
  93. output += "</fieldset>";
  94. output += "<fieldset>";
  95. output += "<legend>" + gLocal.gui.channel + "</legend>";
  96. output +=
  97. "<input type='input' id='term_edit_form_channal' value='" +
  98. word.channal +
  99. "' placeholder=" +
  100. gLocal.gui.optional +
  101. ">";
  102. output += "</fieldset>";
  103. output += "<fieldset>";
  104. output += "<legend>" + gLocal.gui.encyclopedia + "</legend>";
  105. output += "<textarea id='term_edit_form_note' placeholder=" + gLocal.gui.optional + ">" + word.note + "</textarea>";
  106. output += "</fieldset>";
  107. output += "</form>";
  108. return output;
  109. }
  110. function term_edit_dlg_save() {
  111. $.ajax({
  112. type: "POST", //方法类型
  113. dataType: "json", //预期服务器返回的数据类型
  114. url: "../term/term_post.php", //url
  115. data: $("#form_term").serialize(),
  116. success: function (result) {
  117. console.log(result); //打印服务端返回的数据(调试用)
  118. if (result.status == 0) {
  119. alert(result.message + gLocal.gui.saved + gLocal.gui.successful);
  120. } else {
  121. alert("error:" + result.message);
  122. }
  123. },
  124. error: function (data, status) {
  125. alert("异常!" + data.responseText);
  126. switch (status) {
  127. case "timeout":
  128. break;
  129. case "error":
  130. break;
  131. case "notmodified":
  132. break;
  133. case "parsererror":
  134. break;
  135. default:
  136. break;
  137. }
  138. },
  139. });
  140. }