commit.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. var _commit_data;
  2. var previewWin;
  3. function commit_init(param) {
  4. previewWin = model_win_init({ container: "model_win" });
  5. _commit_data = param;
  6. previewWin.show(commit_preview_render());
  7. }
  8. function commit_render_head(step) {
  9. let html = "";
  10. html += "<div class='commit_head step" + step + "'>";
  11. html += "<div class='commit_step commit_step_1'><div class='num'>1</div><div>选择版本</div></div>";
  12. html += "<div class='commit_step commit_step_2'><div class='num'>2</div><div>预览</div></div>";
  13. html += "<div class='commit_step commit_step_3'><div class='num'>3</div><div>完成</div></div>";
  14. html += "</div>";
  15. return html;
  16. }
  17. function commit_render_channel_select() {
  18. let html = "";
  19. html += "<div class='commit_win_inner'>";
  20. html += commit_render_head(1);
  21. html += "<div>当前:";
  22. html += "<select id='src_channel' onchange='src_change(this)'>";
  23. if (typeof _commit_data.src == "undefined") {
  24. html += "<option value='' selected>请选择当前版本</option>";
  25. }
  26. for (const iterator of _my_channal) {
  27. html += "<option value='" + iterator.id + "' ";
  28. if (_commit_data.src == iterator.id) {
  29. html += " selected ";
  30. }
  31. html += ">" + iterator.name + "</option>";
  32. }
  33. html += "</select>";
  34. html += "</div>";
  35. html += "<div>推送到:";
  36. html += "<select id='dest_channel' onchange='dest_change(this)'>";
  37. if (typeof _commit_data.dest == "undefined") {
  38. html += "<option value='' selected>请选择推送到</option>";
  39. }
  40. for (const iterator of _my_channal) {
  41. html += "<option value='" + iterator.id + "' ";
  42. if (_commit_data.dest == iterator.id) {
  43. html += " selected ";
  44. }
  45. html += ">" + iterator.name + "</option>";
  46. }
  47. html += "</select>";
  48. html += "</div>";
  49. html += "<div id='commit_preview'></div>";
  50. html += "<button onclick='previewWin.show(commit_preview_render())'>预览</button>";
  51. html += "</div>";
  52. return html;
  53. }
  54. function commit_preview_render() {
  55. let html = "";
  56. html += "<div class='commit_win_inner'>";
  57. html += commit_render_head(2);
  58. if (
  59. typeof _commit_data.src != "undefined" &&
  60. _commit_data.src != null &&
  61. _commit_data.src != "" &&
  62. typeof _commit_data.dest != "undefined" &&
  63. _commit_data.dest != null &&
  64. _commit_data.dest != ""
  65. ) {
  66. let sentList = new Array();
  67. for (const iterator of _arrData) {
  68. sentList.push(iterator.book + "-" + iterator.para + "-" + iterator.begin + "-" + iterator.end);
  69. }
  70. _commit_data.sent = sentList;
  71. let arrSentInfo = new Array();
  72. for (const iterator of _commit_data.sent) {
  73. let id = com_guid();
  74. arrSentInfo.push({ id: id, data: iterator });
  75. }
  76. if (arrSentInfo.length > 0) {
  77. let setting = new Object();
  78. setting.lang = "";
  79. setting.channal = _commit_data.src + "," + _commit_data.dest;
  80. $.post(
  81. "../term/note.php",
  82. {
  83. setting: JSON.stringify(setting),
  84. data: JSON.stringify(arrSentInfo),
  85. },
  86. function (data, status) {
  87. if (status == "success") {
  88. let sentData;
  89. let html = "";
  90. try {
  91. sentData = JSON.parse(data);
  92. } catch (e) {}
  93. html += "<div class='commit_win_inner'>";
  94. html += commit_render_head(2);
  95. html += "<div>";
  96. html += "<button onclick='previewWin.show(commit_render_channel_select())'>返回</button>";
  97. html += "<button onclick='commit_pull()'>推送</button>";
  98. html += "<button onclick='commit_close()'>放弃</button>";
  99. html += "</div>";
  100. html += "<div class='commit_compare'>";
  101. html += "<div class='pali'>巴利原文</div>";
  102. html += "<div class='src_text'>当前版本:" + channal_getById(_commit_data.src).name + "</div>";
  103. html += "<div class='dest_text'>推送到:" + channal_getById(_commit_data.dest).name + "</div>";
  104. html += "</div>";
  105. for (const iterator of sentData) {
  106. if (iterator.translation[0].id != "") {
  107. html += "<div class='commit_compare'>";
  108. html += "<div ><input type='checkbox' /></div>";
  109. html += "<div class='pali'>" + iterator.palitext + "</div>";
  110. html += "<div class='src_text'>";
  111. html += iterator.translation[0].text;
  112. html += "</div>";
  113. html += "<div class='dest_text'>";
  114. if (iterator.translation[1].id == "") {
  115. if (iterator.translation[0].id == "") {
  116. html += "无记录";
  117. } else {
  118. html += "<ins>" + iterator.translation[0].text + "</ins>";
  119. }
  120. } else {
  121. if (iterator.translation[0].update_time > iterator.translation[1].update_time) {
  122. html += "<del>" + iterator.translation[1].text + "</del><br>";
  123. html += "<ins>" + iterator.translation[0].text + "</ins>";
  124. } else {
  125. html += "[新]" + iterator.translation[1].text;
  126. }
  127. }
  128. html += "</div>";
  129. html += "</div>";
  130. }
  131. }
  132. html += "</div>";
  133. previewWin.show(html);
  134. //$("#commit_preview").html(html);
  135. }
  136. }
  137. );
  138. html += "加载中 请稍等……";
  139. html += "</div>";
  140. return html;
  141. } else {
  142. html += "没有句子被选择";
  143. html += "</div>";
  144. return html;
  145. }
  146. } else {
  147. return commit_render_channel_select();
  148. }
  149. }
  150. function commit_render_final(result) {
  151. let html = "";
  152. html += "<div class='commit_win_inner'>";
  153. html += commit_render_head(3);
  154. if (typeof result.update != "undefined") {
  155. html += "<div>修改:" + result.update + "</div>";
  156. }
  157. if (typeof result.insert != "undefined") {
  158. html += "<div>新增:" + result.insert + "</div>";
  159. }
  160. if (typeof result.pr != "undefined") {
  161. html += "<div>提交修改建议:" + result.pr + "</div>";
  162. }
  163. html +=
  164. "<div><a href='' onclick='window.reload()'>刷新页面</a>查看修改结果。<a onclick='previewWin.close()'>关闭</a></div>";
  165. html += "</div>";
  166. return html;
  167. }
  168. function commit_pull() {
  169. $.post(
  170. "../commit/commit.php",
  171. {
  172. data: JSON.stringify(_commit_data),
  173. },
  174. function (data, status) {
  175. if (status == "success") {
  176. let html = "";
  177. try {
  178. let result = JSON.parse(data);
  179. if (result.status == 0) {
  180. previewWin.show(commit_render_final(result));
  181. } else {
  182. alert(result.message);
  183. }
  184. } catch (e) {}
  185. }
  186. }
  187. );
  188. }
  189. function commit_close() {}
  190. function dest_change(obj) {
  191. _commit_data.dest = $(obj).val();
  192. }
  193. function src_change(obj) {
  194. _commit_data.src = $(obj).val();
  195. }