group.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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 class='info_block'>";
  82. html += "<h2>" + gLocal.gui.introduction + "</h2>";
  83. html += result.info.description;
  84. html += "</div>";
  85. if (result.parent) {
  86. $("#parent_group").html(
  87. " / <a href='../group/index.php?id=" +
  88. result.parent.id +
  89. "'>" +
  90. result.parent.name +
  91. "</a> "
  92. );
  93. }
  94. $("#curr_group").html("/ <a>" + result.info.name + "</a>");
  95. //子小组列表
  96. html += "<div class='info_block'>";
  97. html += "<h2>" + gLocal.gui.sub_group + "</h2>";
  98. if (result.children && result.children.length > 0) {
  99. for (const iterator of result.children) {
  100. html += '<div class="file_list_row" style="padding:5px;">';
  101. html += '<div style="max-width:2em;flex:1;"><input type="checkbox" /></div>';
  102. html += "<div style='flex:1;'>" + key++ + "</div>";
  103. html += "<div style='flex:2;'>" + iterator.name + "</div>";
  104. html += "<div style='flex:2;'>";
  105. if (iterator.power == 1) {
  106. html += "拥有者";
  107. }
  108. html += "</div>";
  109. html +=
  110. "<div style='flex:1;'><a href='../group/index.php?id=" +
  111. iterator.id +
  112. "&list=file'>进入</a></div>";
  113. html += "</div>";
  114. }
  115. } else {
  116. html += "尚未设置小组";
  117. }
  118. html += "</div>";
  119. //共享文件列表
  120. html += "<div class='info_block'>";
  121. html += "<h2>" + gLocal.gui.collaborate + "</h2>";
  122. if (result.file && result.file.length > 0) {
  123. for (const iterator of result.file) {
  124. html += '<div class="file_list_row" style="padding:5px;">';
  125. html += '<div style="max-width:2em;flex:1;"><input type="checkbox" /></div>';
  126. html += "<div style='flex:1;'>" + key++ + "</div>";
  127. html += "<div style='flex:2;'>" + iterator.title + "</div>";
  128. html += "<div style='flex:2;'>";
  129. switch (iterator.power) {
  130. case 10:
  131. html += gLocal.gui.read_only;
  132. break;
  133. case 20:
  134. break;
  135. case 30:
  136. html += gLocal.gui.write;
  137. break;
  138. default:
  139. break;
  140. }
  141. html += "</div>";
  142. html +=
  143. "<div style='flex:1;'><a href='../studio/project.php?op=open&doc_id=" +
  144. iterator.doc_id +
  145. "'>打开</a></div>";
  146. html += "</div>";
  147. }
  148. } else {
  149. html += "没有共享文档 在译经楼中添加";
  150. }
  151. html += "</div>";
  152. $("#my_group_list").html(html);
  153. } catch (e) {
  154. console.error(e);
  155. }
  156. } else {
  157. console.error("ajex error");
  158. }
  159. }
  160. );
  161. }
  162. /*
  163. 编辑channel信息
  164. */
  165. function my_channal_edit(id) {
  166. $.get(
  167. "../channal/my_channal_get.php",
  168. {
  169. id: id,
  170. setting: "",
  171. },
  172. function (data, status) {
  173. if (status == "success") {
  174. try {
  175. let html = "";
  176. let result = JSON.parse(data);
  177. $("#article_collect").attr("a_id", result.id);
  178. html += '<div class="" style="padding:5px;">';
  179. html += '<div style="max-width:2em;flex:1;"></div>';
  180. html += "</div>";
  181. html += "<div style='width: 60%;padding: 1em;min-width: 25em;'>";
  182. html += '<div style="display:flex;line-height:32px;">';
  183. html += "<input type='hidden' name='id' value='" + result.id + "'/>";
  184. html += "</div>";
  185. html += '<div style="display:flex;line-height:32px;">';
  186. html += "<div style='flex:2;'>" + gLocal.gui.title + "</div>";
  187. html += "<div style='flex:8;'>";
  188. html +=
  189. "<input type='input' name='name' value='" +
  190. result.name +
  191. "' maxlength='32' placeholder='channel title'/>";
  192. html += "</div>";
  193. html += "</div>";
  194. html += "<div style='display:flex;'>";
  195. html += "<div style='flex:2;'>" + gLocal.gui.introduction + "</div>";
  196. html += "<div style='flex:8;'>";
  197. html += "<textarea name='summary'>" + result.summary + "</textarea>";
  198. html += "</div>";
  199. html += "</div>";
  200. html += '<div style="display:flex;line-height:32px;">';
  201. html += '<div style="flex:2;">' + gLocal.gui.language_select + "</div>";
  202. html += '<div style="flex:8;">';
  203. html +=
  204. '<input id="channal_lang_select" type="input" onchange="channal_lang_change()"' +
  205. ' placeholder = "try type chinese or en " ' +
  206. ' title="type language name/code" code="' +
  207. result.lang +
  208. '" value="' +
  209. result.lang +
  210. '" > <input id="channal_lang" type="hidden" name="lang" value="' +
  211. result.lang +
  212. '">';
  213. html += "</div>";
  214. html += "</div>";
  215. html += '<div style="display:flex;line-height:32px;">';
  216. html += '<div style="flex:2;">' + gLocal.gui.privacy + "</div>";
  217. html += '<div style="flex:8;">';
  218. let arrStatus = [
  219. { id: 0, string: gLocal.gui.disable, note: gLocal.gui.disable_note },
  220. { id: 10, string: gLocal.gui.private, note: gLocal.gui.private_note },
  221. { id: 30, string: gLocal.gui.public, note: gLocal.gui.public_note },
  222. ];
  223. html += "<select id = 'status' name = 'status' onchange='status_change(this)'>";
  224. let status_note = "";
  225. for (const iterator of arrStatus) {
  226. html += "<option ";
  227. if (parseInt(result.status) == iterator.id) {
  228. html += " selected ";
  229. status_note = iterator.note;
  230. }
  231. html += " value='" + iterator.id + "'>" + iterator.string + "</option>";
  232. }
  233. html += "</select>";
  234. html +=
  235. "<span id = 'status_help' style='margin: 0 1em;'>" +
  236. status_note +
  237. "</span><a href='#' target='_blank'>[" +
  238. gLocal.gui.infomation +
  239. "]</li>";
  240. html += "</div>";
  241. html += "</div>";
  242. html += "</div>";
  243. html += "<div id='preview_div'>";
  244. html += "<div id='preview_inner' ></div>";
  245. html += "</div>";
  246. $("#channal_info").html(html);
  247. tran_lang_select_init("channal_lang_select");
  248. //$("#aritcle_status").html(render_status(result.status));
  249. $("#channal_title").html(result.name);
  250. $("#preview_inner").html();
  251. } catch (e) {
  252. console.error(e);
  253. }
  254. } else {
  255. console.error("ajex error");
  256. }
  257. }
  258. );
  259. }
  260. function status_change(obj) {
  261. let arrStatus = [
  262. { id: 0, string: gLocal.gui.disable, note: gLocal.gui.disable_note },
  263. { id: 10, string: gLocal.gui.private, note: gLocal.gui.private_note },
  264. { id: 30, string: gLocal.gui.public, note: gLocal.gui.public_note },
  265. ];
  266. let newStatus = $(obj).val();
  267. for (const iterator of arrStatus) {
  268. if (parseInt(newStatus) == iterator.id) {
  269. $("#status_help").html(iterator.note);
  270. }
  271. }
  272. }
  273. function channal_lang_change() {
  274. let lang = $("#channal_lang_select").val();
  275. if (lang.split("_").length == 3) {
  276. $("#channal_lang").val(lang.split("_")[2]);
  277. } else {
  278. $("#channal_lang").val(lang);
  279. }
  280. }
  281. function my_channal_save() {
  282. $.ajax({
  283. type: "POST", //方法类型
  284. dataType: "json", //预期服务器返回的数据类型
  285. url: "../channal/my_channal_post.php", //url
  286. data: $("#channal_edit").serialize(),
  287. success: function (result) {
  288. console.log(result); //打印服务端返回的数据(调试用)
  289. if (result.status == 0) {
  290. alert("保存成功");
  291. } else {
  292. alert("error:" + result.message);
  293. }
  294. },
  295. error: function (data, status) {
  296. alert("异常!" + status + data.responseText);
  297. switch (status) {
  298. case "timeout":
  299. break;
  300. case "error":
  301. break;
  302. case "notmodified":
  303. break;
  304. case "parsererror":
  305. break;
  306. default:
  307. break;
  308. }
  309. },
  310. });
  311. }