commit.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. var _commit_data;
  2. var previewWin;
  3. var sentData;
  4. function commit_init(param) {
  5. previewWin = model_win_init({ container: "model_win" });
  6. _commit_data = param;
  7. previewWin.show(commit_preview_render());
  8. }
  9. function commit_render_head(step) {
  10. let html = "";
  11. html += "<div class='commit_head step" + step + "'>";
  12. html += "<div class='commit_step commit_step_1'><div class='num'>1</div><div>选择版本</div></div>";
  13. html += "<div class='commit_step commit_step_2'><div class='num'>2</div><div>文本比对</div></div>";
  14. html += "<div class='commit_step commit_step_3'><div class='num'>3</div><div>完成</div></div>";
  15. html += "</div>";
  16. return html;
  17. }
  18. function commit_render_channel_select() {
  19. let html = "";
  20. html += "<div class='commit_win_inner' >";
  21. html += commit_render_head(1);
  22. html += "<div style='display:flex;'>";
  23. if (typeof _commit_data.src != "undefined") {
  24. html += "<div>译文来源:";
  25. let isFound = false;
  26. for (const iterator of _my_channal) {
  27. if (_commit_data.src == iterator.id) {
  28. html += iterator.name;
  29. isFound = true;
  30. break;
  31. }
  32. }
  33. if (!isFound) {
  34. for (const iterator of _channalData) {
  35. if (_commit_data.src == iterator.id) {
  36. html += iterator.name;
  37. isFound = true;
  38. break;
  39. }
  40. }
  41. }
  42. if (!isFound) {
  43. html += "无法找到Channel";
  44. }
  45. html += "</div>";
  46. } else {
  47. html += "<div>请选择译文来源";
  48. html += "</div>";
  49. }
  50. html += "<div>➡目标译文:</div>";
  51. html += "<div>";
  52. html += "<select id='dest_channel' onchange='dest_change(this)'>";
  53. if (typeof _commit_data.dest == "undefined") {
  54. let lastDest = localStorage.getItem("commit_src_" + _commit_data.src);
  55. if (typeof lastDest == "undefined") {
  56. html += "<option value='' selected>请选择目标版本</option>";
  57. } else {
  58. _commit_data.dest = lastDest;
  59. }
  60. }
  61. for (const iterator of _my_channal) {
  62. if (iterator.status > 0 && _commit_data.src != iterator.id) {
  63. html += "<option value='" + iterator.id + "' ";
  64. if (_commit_data.dest == iterator.id) {
  65. html += " selected ";
  66. }
  67. if (typeof _commit_data.src != "undefined" && _commit_data.src == iterator.id) {
  68. html += "style:'display:none;' ";
  69. }
  70. html += " >" + iterator.name + "-";
  71. if (iterator.power >= 30) {
  72. html += gLocal.gui.your;
  73. } else if (iterator.power >= 20) {
  74. html += "可编辑";
  75. } else if (iterator.power >= 10) {
  76. html += "只读";
  77. } else {
  78. html += "停用";
  79. }
  80. html += "</option>";
  81. }
  82. }
  83. html += "</select>";
  84. html += "</div>";
  85. html += "<div id='commit_preview'>";
  86. if (typeof _commit_data.express != "undefined" && _commit_data.express == true) {
  87. if (typeof _commit_data.sent != "undefined" && _commit_data.sent.length != 0) {
  88. html += "<button onclick='commit_pull()'>✔</button>";
  89. } else {
  90. html += "没有句子数据";
  91. }
  92. } else {
  93. html += "<button onclick='previewWin.show(commit_preview_render())'>文本比对</button>";
  94. }
  95. html += "</div>";
  96. html += "</div>";
  97. html += "</div>";
  98. return html;
  99. }
  100. function commit_preview_render() {
  101. let html = "";
  102. html += "<div class='commit_win_inner'>";
  103. html += commit_render_head(2);
  104. if (
  105. typeof _commit_data.src != "undefined" &&
  106. _commit_data.src != null &&
  107. _commit_data.src != "" &&
  108. typeof _commit_data.dest != "undefined" &&
  109. _commit_data.dest != null &&
  110. _commit_data.dest != ""
  111. ) {
  112. if (typeof _commit_data.sent == "undefined" || _commit_data.sent.length == 0) {
  113. let sentList = new Array();
  114. for (const iterator of _arrData) {
  115. sentList.push(iterator.book + "-" + iterator.para + "-" + iterator.begin + "-" + iterator.end);
  116. }
  117. _commit_data.sent = sentList;
  118. }
  119. let arrSentInfo = new Array();
  120. for (const iterator of _commit_data.sent) {
  121. let id = com_guid();
  122. arrSentInfo.push({ id: id, data: iterator });
  123. }
  124. if (arrSentInfo.length > 0) {
  125. let setting = new Object();
  126. setting.lang = "";
  127. setting.channal = _commit_data.src + "," + _commit_data.dest;
  128. $.post(
  129. "../term/note.php",
  130. {
  131. setting: JSON.stringify(setting),
  132. data: JSON.stringify(arrSentInfo),
  133. },
  134. function (data, status) {
  135. if (status == "success") {
  136. try {
  137. sentData = JSON.parse(data);
  138. } catch (e) {}
  139. previewWin.show(commit_render_comp(0));
  140. }
  141. }
  142. );
  143. html += "加载中 请稍等……";
  144. html += "</div>";
  145. return html;
  146. } else {
  147. html += "没有句子被选择";
  148. html += "</div>";
  149. return html;
  150. }
  151. } else {
  152. return commit_render_channel_select();
  153. }
  154. }
  155. function commit_compare_mode_change(obj) {
  156. previewWin.show(commit_render_comp(parseInt($(obj).val())));
  157. }
  158. function commit_render_comp(mode) {
  159. let html = "";
  160. html += "<div class='commit_win_inner'>";
  161. html += commit_render_head(2);
  162. html += "<div>";
  163. html += "<button onclick='previewWin.show(commit_render_channel_select())'>返回</button>";
  164. html += "<button onclick='commit_pull()'>推送</button>";
  165. html += "<button onclick='commit_close()'>放弃</button>";
  166. html += "</div>";
  167. html += "<div class='commit_compare'>";
  168. html += "<div >";
  169. html += "<select onchange='commit_compare_mode_change(this)'>";
  170. let compareMode = [
  171. { id: 0, string: "自动" },
  172. { id: 1, string: "全选" },
  173. { id: 2, string: "全不选" },
  174. ];
  175. for (const iterator of compareMode) {
  176. html += "<option value='" + iterator.id + "' ";
  177. if (mode == iterator.id) {
  178. html += " selected ";
  179. }
  180. html += ">" + iterator.string + "</option>";
  181. }
  182. html += "</select>";
  183. html += "</div>";
  184. html += "<div class='pali'>巴利原文</div>";
  185. html += "<div class='src_text'>当前版本:" + channal_getById(_commit_data.src).name + "</div>";
  186. html += "<div class='dest_text'>推送到:" + channal_getById(_commit_data.dest).name + "</div>";
  187. html += "</div>";
  188. let textCount = 0;
  189. let sentIndex = 0;
  190. for (let iterator of sentData) {
  191. iterator.checked = false;
  192. if (iterator.translation[0].text != iterator.translation[1].text) {
  193. textCount++;
  194. if (iterator.translation[0].id != "") {
  195. html += "<div class='commit_compare'>";
  196. html += "<div >";
  197. html += "<input class='sent_checkbox' index='" + sentIndex + "' type='checkbox' ";
  198. switch (mode) {
  199. case 0:
  200. if (iterator.translation[1].id == "") {
  201. html += " checked ";
  202. iterator.checked = true;
  203. } else {
  204. if (iterator.translation[0].update_time > iterator.translation[1].update_time) {
  205. html += " checked ";
  206. iterator.checked = true;
  207. }
  208. }
  209. break;
  210. case 1:
  211. html += " checked ";
  212. iterator.checked = true;
  213. break;
  214. case 2:
  215. break;
  216. default:
  217. break;
  218. }
  219. html += " sent_id='" + iterator.pali_sent_id;
  220. html += "' onclick='commit_sent_select(this)' /></div>";
  221. html += "<div class='pali'>" + iterator.palitext + "</div>";
  222. html += "<div class='src_text'>";
  223. html += iterator.translation[0].text;
  224. html += "</div>";
  225. html += "<div ";
  226. html += "channel='" + _commit_data.dest + "'";
  227. html += "sent_id='" + iterator.pali_sent_id + "'";
  228. html += " class='dest_text'>";
  229. switch (mode) {
  230. case 0:
  231. if (iterator.translation[1].id == "") {
  232. html += "<ins>" + iterator.translation[0].text + "</ins>";
  233. } else {
  234. if (iterator.translation[0].update_time > iterator.translation[1].update_time) {
  235. html += "<del>" + iterator.translation[1].text + "</del><br>";
  236. html += "<ins>" + iterator.translation[0].text + "</ins>";
  237. } else {
  238. html += "[新]" + iterator.translation[1].text;
  239. }
  240. }
  241. break;
  242. case 1:
  243. html += "<del>" + iterator.translation[1].text + "</del><br>";
  244. html += "<ins>" + iterator.translation[0].text + "</ins>";
  245. break;
  246. case 2:
  247. html += iterator.translation[1].text;
  248. break;
  249. }
  250. html += "</div>";
  251. html += "</div>";
  252. }
  253. }
  254. sentIndex++;
  255. }
  256. if (textCount == 0) {
  257. html += "译文全部相同,无需推送。";
  258. }
  259. html += "</div>";
  260. return html;
  261. }
  262. function commit_sent_select(obj) {
  263. let sent_id = $(obj).attr("sent_id");
  264. for (let iterator of sentData) {
  265. if (iterator.pali_sent_id == sent_id) {
  266. let html = "";
  267. iterator.checked = obj.checked;
  268. if (obj.checked) {
  269. if (iterator.translation[1].id != "") {
  270. html += "<del>" + iterator.translation[1].text + "</del><br>";
  271. }
  272. html += "<ins>" + iterator.translation[0].text + "</ins>";
  273. } else {
  274. html += iterator.translation[1].text;
  275. }
  276. $(".dest_text[sent_id='" + sent_id + "']").html(html);
  277. }
  278. }
  279. }
  280. function commit_render_final(result) {
  281. let html = "";
  282. html += "<div class='commit_win_inner'>";
  283. html += commit_render_head(3);
  284. if (typeof result.update != "undefined") {
  285. html += "<div>修改:" + result.update + "</div>";
  286. }
  287. if (typeof result.insert != "undefined") {
  288. html += "<div>新增:" + result.insert + "</div>";
  289. }
  290. if (typeof result.pr != "undefined") {
  291. html += "<div>提交修改建议:" + result.pr + "</div>";
  292. }
  293. html +=
  294. "<div><a href='' onclick='window.reload()'>刷新页面</a>查看修改结果。<a onclick='previewWin.close()'>关闭</a></div>";
  295. html += "</div>";
  296. return html;
  297. }
  298. function commit_pull() {
  299. localStorage.setItem("commit_src_" + _commit_data.src, _commit_data.dest);
  300. let pullData = new Array();
  301. for (const iterator of sentData) {
  302. if (iterator.checked) {
  303. for (const iterator of _arrData) {
  304. pullData.push(iterator.book + "-" + iterator.para + "-" + iterator.begin + "-" + iterator.end);
  305. }
  306. _commit_data.sent = pullData;
  307. }
  308. }
  309. if (pullData.length == 0) {
  310. alert("没有数据被选择");
  311. return;
  312. }
  313. $.post(
  314. "../commit/commit.php",
  315. {
  316. data: JSON.stringify(_commit_data),
  317. },
  318. function (data, status) {
  319. if (status == "success") {
  320. let html = "";
  321. try {
  322. let result = JSON.parse(data);
  323. if (result.status == 0) {
  324. previewWin.show(commit_render_final(result));
  325. } else {
  326. alert(result.message);
  327. }
  328. } catch (e) {}
  329. }
  330. }
  331. );
  332. }
  333. function commit_close() {}
  334. function dest_change(obj) {
  335. _commit_data.dest = $(obj).val();
  336. localStorage.setItem("commit_src_" + _commit_data.src, _commit_data.dest);
  337. }
  338. function src_change(obj) {
  339. _commit_data.src = $(obj).val();
  340. localStorage.setItem("commit_last_src", _commit_data.src);
  341. }