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