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