term_edit_dlg.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. function term_edit_dlg_init(title = "Trem") {
  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: "Save",
  9. click: function () {
  10. term_edit_dlg_save();
  11. $(this).dialog("close");
  12. },
  13. },
  14. {
  15. text: "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>Spell</legend>";
  51. output += "<input type='input' id='term_edit_form_word' name='word' value='" + word.word + "'>";
  52. output += "</fieldset>";
  53. output += "<fieldset>";
  54. output += "<legend>Meaning</legend>";
  55. output += "<input type='input' id='term_edit_form_meaning' name='mean' value='" + word.meaning + "'>";
  56. output += "</fieldset>";
  57. output += "<fieldset>";
  58. output += "<legend>Meaning</legend>";
  59. output += "<input type='input' id='term_edit_form_othermeaning name='mean2' value='" + word.other_meaning + "'>";
  60. output += "</fieldset>";
  61. output += "<fieldset>";
  62. output += "<legend>Tag</legend>";
  63. output += "<input type='input' id='term_edit_form_tag name='tag' value='" + word.tag + "'>";
  64. output += "</fieldset>";
  65. output += "<fieldset>";
  66. output += "<legend>Language</legend>";
  67. output += "<input type='input' id='term_edit_form_language' name='language' value='" + word.language + "'>";
  68. output += "</fieldset>";
  69. output += "<fieldset>";
  70. output += "<legend>Channal</legend>";
  71. output += "<input type='input' id='term_edit_form_channal' name='channal' value='" + word.channal + "'>";
  72. output += "</fieldset>";
  73. output += "<fieldset>";
  74. output += "<legend>Note</legend>";
  75. output += "<textarea id='term_edit_form_note' name='note'>" + word.note + "</textarea>";
  76. output += "</fieldset>";
  77. output += "</form>";
  78. return output;
  79. }
  80. function term_edit_dlg_save() {
  81. $.ajax({
  82. type: "POST", //方法类型
  83. dataType: "json", //预期服务器返回的数据类型
  84. url: "../term/term_post.php", //url
  85. data: $("#form_term").serialize(),
  86. success: function (result) {
  87. console.log(result); //打印服务端返回的数据(调试用)
  88. if (result.status == 0) {
  89. alert(result.message + gLocal.gui.saved + gLocal.gui.successful);
  90. } else {
  91. alert("error:" + result.message);
  92. }
  93. },
  94. error: function (data, status) {
  95. alert("异常!" + data.responseText);
  96. switch (status) {
  97. case "timeout":
  98. break;
  99. case "error":
  100. break;
  101. case "notmodified":
  102. break;
  103. case "parsererror":
  104. break;
  105. default:
  106. break;
  107. }
  108. },
  109. });
  110. }