channal.js 6.6 KB

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