2
0

commit.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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.id) {
  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.id) {
  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.id) {
  64. html += "<option value='" + iterator.id + "' ";
  65. if (_commit_data.dest == iterator.id) {
  66. html += " selected ";
  67. }
  68. if (typeof _commit_data.src != "undefined" && _commit_data.src == iterator.id) {
  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. 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. /*
  161. { id: 0, string: "自动" },
  162. { id: 1, string: "全选" },
  163. { id: 2, string: "全不选" },
  164. */
  165. function commit_render_comp(mode) {
  166. let html = "";
  167. html += "<div class='commit_win_inner'>";
  168. html += commit_render_head(2);
  169. html += "<div>";
  170. html += "<button onclick='previewWin.show(commit_render_channel_select())'>返回</button>";
  171. html += "<button onclick='commit_pull()'>推送</button>";
  172. html += "<button onclick='commit_close()'>放弃</button>";
  173. html += "</div>";
  174. html += "<div class='commit_compare'>";
  175. html += "<div >";
  176. html += "<select onchange='commit_compare_mode_change(this)'>";
  177. let compareMode = [
  178. { id: 0, string: "自动" },
  179. { id: 1, string: "全选" },
  180. { id: 2, string: "全不选" },
  181. ];
  182. for (const iterator of compareMode) {
  183. html += "<option value='" + iterator.id + "' ";
  184. if (mode == iterator.id) {
  185. html += " selected ";
  186. }
  187. html += ">" + iterator.string + "</option>";
  188. }
  189. html += "</select>";
  190. html += "</div>";
  191. html += "<div class='pali'>巴利原文</div>";
  192. html += "<div class='src_text'>当前版本:" + channal_getById(_commit_data.src).name + "</div>";
  193. html += "<div class='dest_text'>推送到:" + channal_getById(_commit_data.dest).name + "</div>";
  194. html += "</div>";
  195. let textCount = 0;
  196. let sentIndex = 0;
  197. for (let iterator of sentData) {
  198. iterator.checked = false;
  199. if (iterator.translation[0].text != iterator.translation[1].text) {
  200. textCount++;
  201. if (iterator.translation[0].id != "") {
  202. html += "<div class='commit_compare'>";
  203. html += "<div >";
  204. html += "<input class='sent_checkbox' index='" + sentIndex + "' type='checkbox' ";
  205. switch (mode) {
  206. case 0:
  207. if (iterator.translation[1].id == "") {
  208. html += " checked ";
  209. iterator.checked = true;
  210. } else {
  211. if (iterator.translation[0].update_time > iterator.translation[1].update_time) {
  212. html += " checked ";
  213. iterator.checked = true;
  214. }
  215. }
  216. break;
  217. case 1:
  218. html += " checked ";
  219. iterator.checked = true;
  220. break;
  221. case 2:
  222. break;
  223. default:
  224. break;
  225. }
  226. html += " sent_id='" + iterator.pali_sent_id;
  227. html += "' onclick='commit_sent_select(this)' /></div>";
  228. html += "<div class='pali'>" + iterator.palitext + "</div>";
  229. html += "<div class='src_text'>";
  230. html += iterator.translation[0].text;
  231. html += "</div>";
  232. html += "<div ";
  233. html += "channel='" + _commit_data.dest + "'";
  234. html += "sent_id='" + iterator.pali_sent_id + "'";
  235. html += " class='dest_text'>";
  236. switch (mode) {
  237. case 0:
  238. if (iterator.translation[1].id == "") {
  239. html += "<ins>" + iterator.translation[0].text + "</ins>";
  240. } else {
  241. if (iterator.translation[0].update_time > iterator.translation[1].update_time) {
  242. html += str_diff(iterator.translation[1].text, iterator.translation[0].text);
  243. } else {
  244. html += "[新]" + iterator.translation[1].text;
  245. }
  246. }
  247. break;
  248. case 1:
  249. html += str_diff(iterator.translation[1].text, iterator.translation[0].text);
  250. break;
  251. case 2:
  252. html += iterator.translation[1].text;
  253. break;
  254. }
  255. html += "</div>";
  256. html += "</div>";
  257. }
  258. }
  259. sentIndex++;
  260. }
  261. if (textCount == 0) {
  262. html += "全部相同,无需推送。";
  263. }
  264. html += "</div>";
  265. return html;
  266. }
  267. function commit_sent_select(obj) {
  268. let sent_id = $(obj).attr("sent_id");
  269. for (let iterator of sentData) {
  270. if (iterator.pali_sent_id == sent_id) {
  271. let html = "";
  272. iterator.checked = obj.checked;
  273. if (obj.checked) {
  274. if (iterator.translation[1].id != "") {
  275. html += "<del>" + iterator.translation[1].text + "</del><br>";
  276. }
  277. html += "<ins>" + iterator.translation[0].text + "</ins>";
  278. } else {
  279. html += iterator.translation[1].text;
  280. }
  281. $(".dest_text[sent_id='" + sent_id + "']").html(html);
  282. }
  283. }
  284. }
  285. function commit_render_final(result) {
  286. let html = "";
  287. html += "<div class='commit_win_inner'>";
  288. html += commit_render_head(3);
  289. if (typeof result.update != "undefined") {
  290. html += "<div>修改:" + result.update + "</div>";
  291. }
  292. if (typeof result.insert != "undefined") {
  293. html += "<div>新增:" + result.insert + "</div>";
  294. }
  295. if (typeof result.pr != "undefined") {
  296. html += "<div>提交修改建议:" + result.pr + "</div>";
  297. }
  298. html +=
  299. "<div><a href='' onclick='window.reload()'>刷新页面</a>查看修改结果。<a onclick='previewWin.close()'>关闭</a></div>";
  300. html += "</div>";
  301. return html;
  302. }
  303. function commit_pull() {
  304. localStorage.setItem("commit_src_" + _commit_data.src, _commit_data.dest);
  305. let pullData = new Array();
  306. for (const iterator of sentData) {
  307. if (iterator.checked) {
  308. pullData.push(iterator.book + "-" + iterator.para + "-" + iterator.begin + "-" + iterator.end);
  309. }
  310. }
  311. _commit_data.sent = pullData;
  312. if (pullData.length == 0) {
  313. alert("没有数据被选择");
  314. return;
  315. }
  316. $.post(
  317. "../commit/commit.php",
  318. {
  319. data: JSON.stringify(_commit_data),
  320. },
  321. function (data, status) {
  322. if (status == "success") {
  323. let html = "";
  324. try {
  325. let result = JSON.parse(data);
  326. if (result.status == 0) {
  327. previewWin.show(commit_render_final(result));
  328. } else {
  329. alert(result.message);
  330. }
  331. } catch (e) {}
  332. }
  333. }
  334. );
  335. }
  336. function commit_close() {}
  337. function dest_change(obj) {
  338. _commit_data.dest = $(obj).val();
  339. localStorage.setItem("commit_src_" + _commit_data.src, _commit_data.dest);
  340. }
  341. function src_change(obj) {
  342. _commit_data.src = $(obj).val();
  343. localStorage.setItem("commit_last_src", _commit_data.src);
  344. }