group.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. var _my_channal = null;
  2. var get_channel_list_callback = null;
  3. channal_list();
  4. function group_list_init() {
  5. if (typeof gGroupId == "undefined") {
  6. my_group_list();
  7. group_add_dlg_init("group_add_div");
  8. } else {
  9. group_list(gGroupId, gList);
  10. team_add_dlg_init("group_add_div");
  11. }
  12. }
  13. function channal_list() {
  14. $.post("../channal/get.php", {}, function (data) {
  15. try {
  16. _my_channal = JSON.parse(data);
  17. if (get_channel_list_callback) {
  18. get_channel_list_callback();
  19. }
  20. } catch (e) {
  21. console.error(e);
  22. }
  23. });
  24. }
  25. function channal_getById(id) {
  26. for (const iterator of _my_channal) {
  27. if (iterator.id == id) {
  28. return iterator;
  29. }
  30. }
  31. return false;
  32. }
  33. function my_group_list() {
  34. $.get("../group/list.php", {}, function (data, status) {
  35. if (status == "success") {
  36. try {
  37. let html = "";
  38. let result = JSON.parse(data);
  39. let key = 1;
  40. if (result.length > 0) {
  41. for (const iterator of result) {
  42. html += '<div class="file_list_row" style="padding:5px;">';
  43. html += "<div style='flex:1;'>" + key++ + "</div>";
  44. html += "<div style='flex:2;'>" + iterator.group_name + "</div>";
  45. html += "<div style='flex:2;'>";
  46. if (iterator.power == 1) {
  47. html += "拥有者";
  48. }
  49. html += "</div>";
  50. html +=
  51. "<div style='flex:1;'><a href='../group/index.php?id=" +
  52. iterator.group_id +
  53. "'>进入</a></div>";
  54. html += "</div>";
  55. }
  56. } else {
  57. html += "你没有加入任何工作组 现在 创建 你的工作组。";
  58. }
  59. $("#my_group_list").html(html);
  60. } catch (e) {
  61. console.error(e);
  62. }
  63. } else {
  64. console.error("ajex error");
  65. }
  66. });
  67. }
  68. function group_list(id, list) {
  69. $.get(
  70. "../group/get.php",
  71. {
  72. id: id,
  73. list: list,
  74. },
  75. function (data, status) {
  76. if (status == "success") {
  77. try {
  78. let html = "";
  79. let result = JSON.parse(data);
  80. let key = 1;
  81. html += "<div>";
  82. html += result.info.description;
  83. html += "</div>";
  84. if (result.parent) {
  85. $("#parent_group").html(
  86. " / <a href='../group/index.php?id=" +
  87. result.parent.id +
  88. "'>" +
  89. result.parent.name +
  90. "</a> "
  91. );
  92. }
  93. $("#curr_group").html("/ <a>" + result.info.name + "</a>");
  94. //子小组列表
  95. if (result.children && result.children.length > 0) {
  96. html += "<div><a href='../group/index.php?id=" + id + "&list=file'>列出公共文件</a></div>";
  97. for (const iterator of result.children) {
  98. html += '<div class="file_list_row" style="padding:5px;">';
  99. html += '<div style="max-width:2em;flex:1;"><input type="checkbox" /></div>';
  100. html += "<div style='flex:1;'>" + key++ + "</div>";
  101. html += "<div style='flex:2;'>" + iterator.name + "</div>";
  102. html += "<div style='flex:2;'>";
  103. if (iterator.power == 1) {
  104. html += "拥有者";
  105. }
  106. html += "</div>";
  107. html +=
  108. "<div style='flex:1;'><a href='../group/index.php?id=" +
  109. iterator.id +
  110. "&list=file'>进入</a></div>";
  111. html += "</div>";
  112. }
  113. }
  114. //文件列表
  115. if (result.file && result.file.length > 0) {
  116. for (const iterator of result.file) {
  117. html += '<div class="file_list_row" style="padding:5px;">';
  118. html += '<div style="max-width:2em;flex:1;"><input type="checkbox" /></div>';
  119. html += "<div style='flex:1;'>" + key++ + "</div>";
  120. html += "<div style='flex:2;'>" + iterator.title + "</div>";
  121. html += "<div style='flex:2;'>";
  122. if (iterator.power == 1) {
  123. html += "拥有者";
  124. }
  125. html += "</div>";
  126. html +=
  127. "<div style='flex:1;'><a href='../studio/project.php?op=open&doc_id=" +
  128. iterator.doc_id +
  129. "'>打开</a></div>";
  130. html += "</div>";
  131. }
  132. }
  133. $("#my_group_list").html(html);
  134. } catch (e) {
  135. console.error(e);
  136. }
  137. } else {
  138. console.error("ajex error");
  139. }
  140. }
  141. );
  142. }
  143. /*
  144. 编辑channel信息
  145. */
  146. function my_channal_edit(id) {
  147. $.get(
  148. "../channal/my_channal_get.php",
  149. {
  150. id: id,
  151. setting: "",
  152. },
  153. function (data, status) {
  154. if (status == "success") {
  155. try {
  156. let html = "";
  157. let result = JSON.parse(data);
  158. $("#article_collect").attr("a_id", result.id);
  159. html += '<div class="" style="padding:5px;">';
  160. html += '<div style="max-width:2em;flex:1;"></div>';
  161. html += "</div>";
  162. html += "<div style='width: 60%;padding: 1em;min-width: 25em;'>";
  163. html += '<div style="display:flex;line-height:32px;">';
  164. html += "<input type='hidden' name='id' value='" + result.id + "'/>";
  165. html += "</div>";
  166. html += '<div style="display:flex;line-height:32px;">';
  167. html += "<div style='flex:2;'>" + gLocal.gui.title + "</div>";
  168. html += "<div style='flex:8;'>";
  169. html +=
  170. "<input type='input' name='name' value='" +
  171. result.name +
  172. "' maxlength='32' placeholder='channel title'/>";
  173. html += "</div>";
  174. html += "</div>";
  175. html += "<div style='display:flex;'>";
  176. html += "<div style='flex:2;'>" + gLocal.gui.introduction + "</div>";
  177. html += "<div style='flex:8;'>";
  178. html += "<textarea name='summary'>" + result.summary + "</textarea>";
  179. html += "</div>";
  180. html += "</div>";
  181. html += '<div style="display:flex;line-height:32px;">';
  182. html += '<div style="flex:2;">' + gLocal.gui.language_select + "</div>";
  183. html += '<div style="flex:8;">';
  184. html +=
  185. '<input id="channal_lang_select" type="input" onchange="channal_lang_change()"' +
  186. ' placeholder = "try type chinese or en " ' +
  187. ' title="type language name/code" code="' +
  188. result.lang +
  189. '" value="' +
  190. result.lang +
  191. '" > <input id="channal_lang" type="hidden" name="lang" value="' +
  192. result.lang +
  193. '">';
  194. html += "</div>";
  195. html += "</div>";
  196. html += '<div style="display:flex;line-height:32px;">';
  197. html += '<div style="flex:2;">' + gLocal.gui.privacy + "</div>";
  198. html += '<div style="flex:8;">';
  199. let arrStatus = [
  200. { id: 0, string: gLocal.gui.disable, note: gLocal.gui.disable_note },
  201. { id: 10, string: gLocal.gui.private, note: gLocal.gui.private_note },
  202. { id: 30, string: gLocal.gui.public, note: gLocal.gui.public_note },
  203. ];
  204. html += "<select id = 'status' name = 'status' onchange='status_change(this)'>";
  205. let status_note = "";
  206. for (const iterator of arrStatus) {
  207. html += "<option ";
  208. if (parseInt(result.status) == iterator.id) {
  209. html += " selected ";
  210. status_note = iterator.note;
  211. }
  212. html += " value='" + iterator.id + "'>" + iterator.string + "</option>";
  213. }
  214. html += "</select>";
  215. html +=
  216. "<span id = 'status_help' style='margin: 0 1em;'>" +
  217. status_note +
  218. "</span><a href='#' target='_blank'>[" +
  219. gLocal.gui.infomation +
  220. "]</li>";
  221. html += "</div>";
  222. html += "</div>";
  223. html += "</div>";
  224. html += "<div id='preview_div'>";
  225. html += "<div id='preview_inner' ></div>";
  226. html += "</div>";
  227. $("#channal_info").html(html);
  228. tran_lang_select_init("channal_lang_select");
  229. //$("#aritcle_status").html(render_status(result.status));
  230. $("#channal_title").html(result.name);
  231. $("#preview_inner").html();
  232. } catch (e) {
  233. console.error(e);
  234. }
  235. } else {
  236. console.error("ajex error");
  237. }
  238. }
  239. );
  240. }
  241. function status_change(obj) {
  242. let arrStatus = [
  243. { id: 0, string: gLocal.gui.disable, note: gLocal.gui.disable_note },
  244. { id: 10, string: gLocal.gui.private, note: gLocal.gui.private_note },
  245. { id: 30, string: gLocal.gui.public, note: gLocal.gui.public_note },
  246. ];
  247. let newStatus = $(obj).val();
  248. for (const iterator of arrStatus) {
  249. if (parseInt(newStatus) == iterator.id) {
  250. $("#status_help").html(iterator.note);
  251. }
  252. }
  253. }
  254. function channal_lang_change() {
  255. let lang = $("#channal_lang_select").val();
  256. if (lang.split("_").length == 3) {
  257. $("#channal_lang").val(lang.split("_")[2]);
  258. } else {
  259. $("#channal_lang").val(lang);
  260. }
  261. }
  262. function my_channal_save() {
  263. $.ajax({
  264. type: "POST", //方法类型
  265. dataType: "json", //预期服务器返回的数据类型
  266. url: "../channal/my_channal_post.php", //url
  267. data: $("#channal_edit").serialize(),
  268. success: function (result) {
  269. console.log(result); //打印服务端返回的数据(调试用)
  270. if (result.status == 0) {
  271. alert("保存成功");
  272. } else {
  273. alert("error:" + result.message);
  274. }
  275. },
  276. error: function (data, status) {
  277. alert("异常!" + status + data.responseText);
  278. switch (status) {
  279. case "timeout":
  280. break;
  281. case "error":
  282. break;
  283. case "notmodified":
  284. break;
  285. case "parsererror":
  286. break;
  287. default:
  288. break;
  289. }
  290. },
  291. });
  292. }