term_edit_dlg.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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' name='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' name='mean' 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 name='mean2' 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' 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' name='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' name='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 +=
  106. "<textarea id='term_edit_form_note' name='note' placeholder=" +
  107. gLocal.gui.optional +
  108. ">" +
  109. word.note +
  110. "</textarea>";
  111. output += "</fieldset>";
  112. output += "</form>";
  113. return output;
  114. }
  115. function term_edit_dlg_save() {
  116. $.ajax({
  117. type: "POST", //方法类型
  118. dataType: "json", //预期服务器返回的数据类型
  119. url: "../term/term_post.php", //url
  120. data: $("#form_term").serialize(),
  121. success: function (result) {
  122. console.log(result); //打印服务端返回的数据(调试用)
  123. if (result.status == 0) {
  124. alert(result.message + gLocal.gui.saved + gLocal.gui.successful);
  125. } else {
  126. alert("error:" + result.message);
  127. }
  128. },
  129. error: function (data, status) {
  130. alert("异常!" + data.responseText);
  131. switch (status) {
  132. case "timeout":
  133. break;
  134. case "error":
  135. break;
  136. case "notmodified":
  137. break;
  138. case "parsererror":
  139. break;
  140. default:
  141. break;
  142. }
  143. },
  144. });
  145. }