commit.js 9.6 KB

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