term_edit_dlg.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 = "", word = "") {
  24. if (id == "") {
  25. let newWord = new Object();
  26. newWord.guid = "";
  27. newWord.word = word;
  28. newWord.meaning = "";
  29. newWord.other_meaning = "";
  30. newWord.tag = "";
  31. newWord.note = "";
  32. newWord.language = "zh";
  33. newWord.channal = "";
  34. let html = term_edit_dlg_render(newWord);
  35. $("#term_edit_dlg_content").html(html);
  36. $("#term_edit_dlg").dialog("open");
  37. } else {
  38. $.post(
  39. "../term/term_get_id.php",
  40. {
  41. id: id,
  42. },
  43. function (data) {
  44. let word = JSON.parse(data);
  45. let html = term_edit_dlg_render(word);
  46. $("#term_edit_dlg_content").html(html);
  47. $("#term_edit_dlg").dialog("open");
  48. }
  49. );
  50. }
  51. }
  52. function term_edit_dlg_render(word = "") {
  53. if (word == "") {
  54. word = new Object();
  55. word.guid = "";
  56. word.word = pali;
  57. word.meaning = "";
  58. word.other_meaning = "";
  59. word.tag = "";
  60. word.note = "";
  61. }
  62. let output = "";
  63. output += "<form action='##' id='form_term'>";
  64. output += "<input type='hidden' id='term_edit_form_id' name='id' value='" + word.guid + "'>";
  65. output += "<fieldset>";
  66. output += "<legend>" + gLocal.gui.spell + "</legend>";
  67. output +=
  68. "<input type='input' id='term_edit_form_word' name='word' value='" +
  69. word.word +
  70. "'placeholder=" +
  71. gLocal.gui.required +
  72. ">";
  73. output += "</fieldset>";
  74. output += "<fieldset>";
  75. output += "<legend>" + gLocal.gui.first_choice_word + "</legend>";
  76. output +=
  77. "<input type='input' id='term_edit_form_meaning' name='mean' value='" +
  78. word.meaning +
  79. "' placeholder=" +
  80. gLocal.gui.required +
  81. ">";
  82. output += "</fieldset>";
  83. output += "<fieldset>";
  84. output += "<legend>" + gLocal.gui.other_meaning + "</legend>";
  85. output +=
  86. "<input type='input' id='term_edit_form_othermeaning' name='mean2' value='" +
  87. word.other_meaning +
  88. "' placeholder=" +
  89. gLocal.gui.optional +
  90. ">";
  91. output += "</fieldset>";
  92. output += "<fieldset>";
  93. output += "<legend>" + gLocal.gui.tag + "</legend>";
  94. output +=
  95. "<input type='input' id='term_edit_form_tag name='tag' name='tag' value='" +
  96. word.tag +
  97. "' placeholder=" +
  98. gLocal.gui.optional +
  99. " >";
  100. output += "</fieldset>";
  101. output += "<fieldset>";
  102. output += "<legend>" + gLocal.gui.language + "</legend>";
  103. output +=
  104. "<input type='input' id='term_edit_form_language' name='language' value='" +
  105. word.language +
  106. "' placeholder=" +
  107. gLocal.gui.required +
  108. " >";
  109. output += "</fieldset>";
  110. output += "<fieldset>";
  111. output += "<legend>" + gLocal.gui.channel + "</legend>";
  112. output +=
  113. "<input type='input' id='term_edit_form_channal' name='channal' value='" +
  114. word.channal +
  115. "' placeholder=" +
  116. gLocal.gui.optional +
  117. ">";
  118. output += "</fieldset>";
  119. output += "<fieldset>";
  120. output += "<legend>" + gLocal.gui.encyclopedia + "</legend>";
  121. output +=
  122. "<textarea id='term_edit_form_note' name='note' placeholder=" +
  123. gLocal.gui.optional +
  124. ">" +
  125. word.note +
  126. "</textarea>";
  127. output += "</fieldset>";
  128. output += "</form>";
  129. return output;
  130. }
  131. function term_edit_dlg_save() {
  132. $.ajax({
  133. type: "POST", //方法类型
  134. dataType: "json", //预期服务器返回的数据类型
  135. url: "../term/term_post.php", //url
  136. data: $("#form_term").serialize(),
  137. success: function (result) {
  138. console.log(result); //打印服务端返回的数据(调试用)
  139. if (result.status == 0) {
  140. alert(result.message + gLocal.gui.saved + gLocal.gui.successful);
  141. } else {
  142. alert("error:" + result.message);
  143. }
  144. },
  145. error: function (data, status) {
  146. alert("异常!" + data.responseText);
  147. switch (status) {
  148. case "timeout":
  149. break;
  150. case "error":
  151. break;
  152. case "notmodified":
  153. break;
  154. case "parsererror":
  155. break;
  156. default:
  157. break;
  158. }
  159. },
  160. });
  161. }