term_edit_dlg.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 = "",channel="",lang="") {
  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 = lang;
  34. newWord.channel = channel;
  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. let currChannel=null;
  114. if(typeof word.channel == "undefined" && typeof word.channal != "undefined"){
  115. word.channel = word.channal;
  116. }
  117. for (const iterator of _my_channal) {
  118. if(iterator.id==word.channel){
  119. currChannel = iterator;
  120. }
  121. }
  122. output += "<select id='term_edit_form_channal' name='channal'>";
  123. if(currChannel !== null){
  124. if(currChannel.owner == getCookie("user_uid")){
  125. //是自己的
  126. output += "<option value=''>通用于所有版本</option>";
  127. }
  128. output += "<option value='"+currChannel.id+"'>仅用于"+currChannel.name+"</option>";
  129. }else{
  130. output += "<option value=''>通用于所有版本</option>";
  131. }
  132. /*
  133. for (const iterator of _my_channal) {
  134. if(word.channel=="" || (word.channel!="" && iterator.id==word.channel)){
  135. output += "<option value='"+iterator.id+"'>仅用于"+iterator.name+"</option>";
  136. }
  137. }
  138. */
  139. output += "</select>";
  140. output += "</fieldset>";
  141. output += "<fieldset>";
  142. output += "<legend>" + gLocal.gui.encyclopedia + "</legend>";
  143. output += "<textarea id='term_edit_form_note' name='note' placeholder=" + gLocal.gui.optional + ">";
  144. output += word.note ;
  145. output += "</textarea>";
  146. output += "</fieldset>";
  147. output += "</form>";
  148. return output;
  149. }
  150. function term_edit_dlg_save() {
  151. $.ajax({
  152. type: "POST", //方法类型
  153. dataType: "json", //预期服务器返回的数据类型
  154. url: "../term/term_post.php", //url
  155. data: $("#form_term").serialize(),
  156. success: function (result) {
  157. console.log(result); //打印服务端返回的数据(调试用)
  158. if (result.status == 0) {
  159. alert(result.message + gLocal.gui.saved + gLocal.gui.successful);
  160. for (let index = 0; index < arrMyTerm.length; index++) {
  161. const element = arrMyTerm[index];
  162. if(element.guid==result.data.guid){
  163. arrMyTerm.splice(index,1);
  164. break;
  165. }
  166. }
  167. arrMyTerm.push(result.data);
  168. term_updata_translation();
  169. } else {
  170. alert("error:" + result.message);
  171. }
  172. },
  173. error: function (data, status) {
  174. alert("异常!" + data.responseText);
  175. switch (status) {
  176. case "timeout":
  177. break;
  178. case "error":
  179. break;
  180. case "notmodified":
  181. break;
  182. case "parsererror":
  183. break;
  184. default:
  185. break;
  186. }
  187. },
  188. });
  189. }