channal.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. var _my_channal = null;
  2. var get_channel_list_callback = null;
  3. channal_list();
  4. function channal_list_init() {
  5. my_channal_list();
  6. channal_add_dlg_init("channal_add_div");
  7. }
  8. function channal_list() {
  9. $.post("../channal/get.php", {}, function (data) {
  10. try {
  11. _my_channal = JSON.parse(data);
  12. if (get_channel_list_callback) {
  13. get_channel_list_callback();
  14. }
  15. } catch (e) {
  16. console.error(e);
  17. }
  18. });
  19. }
  20. function channal_getById(id) {
  21. for (const iterator of _my_channal) {
  22. if (iterator.id == id) {
  23. return iterator;
  24. }
  25. }
  26. return false;
  27. }
  28. function my_channal_list() {
  29. $.get(
  30. "../channal/get.php",
  31. {
  32. setting: "",
  33. },
  34. function (data, status) {
  35. if (status == "success") {
  36. try {
  37. let html = "";
  38. let result = JSON.parse(data);
  39. let key = 1;
  40. for (const iterator of result) {
  41. html += '<div class="file_list_row" style="padding:5px;">';
  42. html += '<div style="max-width:2em;flex:1;"><input type="checkbox" /></div>';
  43. html += "<div style='flex:1;'>" + key++ + "</div>";
  44. html += "<div style='flex:2;'>" + iterator.name + "</div>";
  45. html += "<div style='flex:2;'>" + iterator.nickname + "</div>";
  46. html += "<div style='flex:2;'>";
  47. let arrStatus = [
  48. { id: 0, string: gLocal.gui.disable },
  49. { id: 10, string: gLocal.gui.private },
  50. { id: 30, string: gLocal.gui.public },
  51. ];
  52. for (const status of arrStatus) {
  53. if (parseInt(iterator.status) == status.id) {
  54. html += status.string;
  55. }
  56. }
  57. //render_status(iterator.status) +
  58. html += "</div>";
  59. html +=
  60. "<div style='flex:1;'><a href='../channal/my_channal_edit.php?id=" +
  61. iterator.id +
  62. "'>" +
  63. gLocal.gui.edit +
  64. "</a></div>";
  65. html += "<div style='flex:1;'>15</div>";
  66. html += "</div>";
  67. }
  68. $("#my_channal_list").html(html);
  69. } catch (e) {
  70. console.error(e);
  71. }
  72. } else {
  73. console.error("ajex error");
  74. }
  75. }
  76. );
  77. }
  78. function my_channal_edit(id) {
  79. $.get(
  80. "../channal/my_channal_get.php",
  81. {
  82. id: id,
  83. setting: "",
  84. },
  85. function (data, status) {
  86. if (status == "success") {
  87. try {
  88. let html = "";
  89. let result = JSON.parse(data);
  90. $("#article_collect").attr("a_id", result.id);
  91. html += '<div class="" style="padding:5px;">';
  92. html += '<div style="max-width:2em;flex:1;"></div>';
  93. html += "</div>";
  94. html += "<div style='display:flex;'>";
  95. html += "<div style='flex:4;'>";
  96. html += "<input type='hidden' name='id' value='" + result.id + "'/>";
  97. html +=
  98. "<input type='input' name='name' value='" +
  99. result.name +
  100. "' maxlength='32' placeholder='📝≤32'/>";
  101. html += "<textarea name='summary'>" + result.summary + "</textarea>";
  102. html += "<div>";
  103. html +=
  104. '<input id="channal_lang_select" type="input" onchange="channal_lang_change()" title="type language name/code" code="' +
  105. result.lang +
  106. '" value="' +
  107. result.lang +
  108. '" > <input id="channal_lang" type="hidden" name="lang" value="' +
  109. result.lang +
  110. '">';
  111. html += "</div>";
  112. html += '<div style="display:flex;">';
  113. html += '<div style="flex:2;">Status</div>';
  114. html += '<div style="flex:8;">';
  115. let arrStatus = [
  116. { id: 0, string: gLocal.gui.disable },
  117. { id: 10, string: gLocal.gui.private },
  118. { id: 30, string: gLocal.gui.public },
  119. ];
  120. html += "<select id = 'status' name = 'status'>";
  121. for (const iterator of arrStatus) {
  122. html += "<option ";
  123. if (parseInt(result.status) == iterator.id) {
  124. html += " selected ";
  125. }
  126. html += " value='" + iterator.id + "'>" + iterator.string + "</option>";
  127. }
  128. html += "</select>";
  129. html += "</div>";
  130. html += "</div>";
  131. html += "</div>";
  132. html += "<div id='preview_div'>";
  133. html += "<div id='preview_inner' ></div>";
  134. html += "</div>";
  135. html += "</div>";
  136. $("#channal_info").html(html);
  137. tran_lang_select_init("channal_lang_select");
  138. //$("#aritcle_status").html(render_status(result.status));
  139. $("#channal_title").html(result.name);
  140. $("#preview_inner").html();
  141. } catch (e) {
  142. console.error(e);
  143. }
  144. } else {
  145. console.error("ajex error");
  146. }
  147. }
  148. );
  149. }
  150. function channal_lang_change() {
  151. let lang = $("#channal_lang_select").val();
  152. if (lang.split("_").length == 3) {
  153. $("#channal_lang").val(lang.split("_")[2]);
  154. } else {
  155. $("#channal_lang").val(lang);
  156. }
  157. }
  158. function my_channal_save() {
  159. $.ajax({
  160. type: "POST", //方法类型
  161. dataType: "json", //预期服务器返回的数据类型
  162. url: "../channal/my_channal_post.php", //url
  163. data: $("#channal_edit").serialize(),
  164. success: function (result) {
  165. console.log(result); //打印服务端返回的数据(调试用)
  166. if (result.status == 0) {
  167. alert("保存成功");
  168. } else {
  169. alert("error:" + result.message);
  170. }
  171. },
  172. error: function (data, status) {
  173. alert("异常!" + status + data.responseText);
  174. switch (status) {
  175. case "timeout":
  176. break;
  177. case "error":
  178. break;
  179. case "notmodified":
  180. break;
  181. case "parsererror":
  182. break;
  183. default:
  184. break;
  185. }
  186. },
  187. });
  188. }