channal.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. /*
  79. 编辑channel信息
  80. */
  81. function my_channal_edit(id) {
  82. $.get(
  83. "../channal/my_channal_get.php",
  84. {
  85. id: id,
  86. setting: "",
  87. },
  88. function (data, status) {
  89. if (status == "success") {
  90. try {
  91. let html = "";
  92. let result = JSON.parse(data);
  93. $("#article_collect").attr("a_id", result.id);
  94. html += '<div class="" style="padding:5px;">';
  95. html += '<div style="max-width:2em;flex:1;"></div>';
  96. html += "</div>";
  97. html += "<div style='width: 60%;padding: 1em;min-width: 25em;'>";
  98. html += '<div style="display:flex;line-height:32px;">';
  99. html += "<div style='flex:2;'>" + gLocal.gui.title + "</div>";
  100. html += "<div style='flex:8;'>";
  101. html += "<input type='hidden' name='id' value='" + result.id + "'/>";
  102. html += "</div>";
  103. html += "</div>";
  104. html += '<div style="display:flex;line-height:32px;">';
  105. html += '<div style="flex:2;">'+gLocal.gui.name+'</div>';
  106. html += '<div style="flex:8;">';
  107. html +=
  108. "<input type='input' name='name' value='" +
  109. result.name +
  110. "' maxlength='32' placeholder='channel title'/>";
  111. html += "</div>";
  112. html += "</div>";
  113. html += "<div style='display:flex;'>";
  114. html += "<div style='flex:2;'>" + gLocal.gui.introduction + "</div>";
  115. html += "<div style='flex:8;'>";
  116. html += "<textarea name='summary'>" + result.summary + "</textarea>";
  117. html += "</div>";
  118. html += "</div>";
  119. html += '<div style="display:flex;line-height:32px;">';
  120. html += '<div style="flex:2;">'+gLocal.gui.language_select+'</div>';
  121. html += '<div style="flex:8;">';
  122. html +=
  123. '<input id="channal_lang_select" type="input" onchange="channal_lang_change()"' +
  124. ' placeholder = "try type chinese or en " ' +
  125. ' title="type language name/code" code="' +
  126. result.lang +
  127. '" value="' +
  128. result.lang +
  129. '" > <input id="channal_lang" type="hidden" name="lang" value="' +
  130. result.lang +
  131. '">';
  132. html += "</div>";
  133. html += "</div>";
  134. html += '<div style="display:flex;line-height:32px;">';
  135. html += '<div style="flex:2;">'+gLocal.gui.privacy+'</div>';
  136. html += '<div style="flex:8;">';
  137. let arrStatus = [
  138. { id: 0, string: gLocal.gui.disable, note: gLocal.gui.disable_note },
  139. { id: 10, string: gLocal.gui.private, note: gLocal.gui.private_note },
  140. { id: 30, string: gLocal.gui.public, note: gLocal.gui.public_note },
  141. ];
  142. html += "<select id = 'status' name = 'status' onchange='status_change(this)'>";
  143. let status_note = "";
  144. for (const iterator of arrStatus) {
  145. html += "<option ";
  146. if (parseInt(result.status) == iterator.id) {
  147. html += " selected ";
  148. status_note = iterator.note;
  149. }
  150. html += " value='" + iterator.id + "'>" + iterator.string + "</option>";
  151. }
  152. html += "</select>";
  153. html += "<span id = 'status_help' style='margin: 0 1em;'>" + status_note + "</span><a href='#' target='_blank'>["+gLocal.gui.infomation+"]</li>";
  154. html += "</div>";
  155. html += "</div>";
  156. html += "</div>";
  157. html += "<div id='preview_div'>";
  158. html += "<div id='preview_inner' ></div>";
  159. html += "</div>";
  160. $("#channal_info").html(html);
  161. tran_lang_select_init("channal_lang_select");
  162. //$("#aritcle_status").html(render_status(result.status));
  163. $("#channal_title").html(result.name);
  164. $("#preview_inner").html();
  165. } catch (e) {
  166. console.error(e);
  167. }
  168. } else {
  169. console.error("ajex error");
  170. }
  171. }
  172. );
  173. }
  174. function status_change(obj) {
  175. let arrStatus = [
  176. { id: 0, string: gLocal.gui.disable, note: gLocal.gui.disable_note },
  177. { id: 10, string: gLocal.gui.private, note: gLocal.gui.private_note },
  178. { id: 30, string: gLocal.gui.public, note: gLocal.gui.public_note },
  179. ];
  180. let newStatus = $(obj).val();
  181. for (const iterator of arrStatus) {
  182. if (parseInt(newStatus) == iterator.id) {
  183. $("#status_help").html(iterator.note);
  184. }
  185. }
  186. }
  187. function channal_lang_change() {
  188. let lang = $("#channal_lang_select").val();
  189. if (lang.split("_").length == 3) {
  190. $("#channal_lang").val(lang.split("_")[2]);
  191. } else {
  192. $("#channal_lang").val(lang);
  193. }
  194. }
  195. function my_channal_save() {
  196. $.ajax({
  197. type: "POST", //方法类型
  198. dataType: "json", //预期服务器返回的数据类型
  199. url: "../channal/my_channal_post.php", //url
  200. data: $("#channal_edit").serialize(),
  201. success: function (result) {
  202. console.log(result); //打印服务端返回的数据(调试用)
  203. if (result.status == 0) {
  204. alert("保存成功");
  205. } else {
  206. alert("error:" + result.message);
  207. }
  208. },
  209. error: function (data, status) {
  210. alert("异常!" + status + data.responseText);
  211. switch (status) {
  212. case "timeout":
  213. break;
  214. case "error":
  215. break;
  216. case "notmodified":
  217. break;
  218. case "parsererror":
  219. break;
  220. default:
  221. break;
  222. }
  223. },
  224. });
  225. }