2
0

usent.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. var user_sentence_create_buffer = new Array();
  2. var user_sentence_update_buffer = new Array();
  3. var user_sentence_block_create_buffer = new Array();
  4. var user_sentence_block_update_buffer = new Array();
  5. function usent_block_create(blockid, book, paragraph, lang, author, editor, tag) {
  6. var d = new Date();
  7. let newBlock = new Object();
  8. newBlock.id = blockid;
  9. newBlock.book = book;
  10. newBlock.paragraph = paragraph;
  11. newBlock.tag = tag;
  12. newBlock.lang = lang;
  13. newBlock.author = author;
  14. newBlock.editor = editor;
  15. newBlock.time = d.getTime();
  16. user_sentence_block_create_buffer.push(newBlock);
  17. }
  18. function usent_block_commit() {
  19. if (user_sentence_block_create_buffer.length > 0) {
  20. $.post("../usent/new_block.php",
  21. {
  22. data: JSON.stringify(user_sentence_block_create_buffer)
  23. },
  24. usent_server_responce);
  25. user_sentence_block_create_buffer = new Array();
  26. }
  27. if (user_sentence_block_update_buffer.length > 0) {
  28. $.post("../usent/updata.php",
  29. {
  30. data: JSON.stringify(user_sentence_block_update_buffer)
  31. },
  32. usent_server_responce);
  33. user_sentence_block_update_buffer = new Array();
  34. }
  35. }
  36. function usent_block_fork(blockid, newBlockId) {
  37. }
  38. function usent_change(blockid, begin, end, text) {
  39. }
  40. function usent_update(blockid, begin, end, text) {
  41. var d = new Date();
  42. let mBlock = doc_tran("#" + blockid);
  43. let dbId = mBlock.text(begin, end, "id");
  44. let sent_status = mBlock.text(begin, end, "status");
  45. let newData = new Object();
  46. newData.id = dbId;
  47. newData.text = text;
  48. newData.status = sent_status;
  49. newData.time = d.getTime();
  50. user_sentence_update_buffer.push(newData);
  51. }
  52. function usent_create(blockid, id, book, paragraph, begin, end, text, tag, lang, author, editor) {
  53. let newData = new Object();
  54. newData.blockid = blockid;
  55. newData.id = id;
  56. newData.book = book;
  57. newData.paragraph = paragraph;
  58. newData.begin = begin;
  59. newData.end = end;
  60. newData.text = text;
  61. newData.tag = tag;
  62. newData.lang = lang;
  63. newData.author = author;
  64. newData.editor = editor;
  65. user_sentence_create_buffer.push(newData);
  66. }
  67. function usent_commit() {
  68. if (user_sentence_create_buffer.length > 0) {
  69. $.post("../usent/new.php",
  70. {
  71. data: JSON.stringify(user_sentence_create_buffer)
  72. },
  73. usent_server_responce);
  74. user_sentence_create_buffer = new Array();
  75. }
  76. if (user_sentence_update_buffer.length > 0) {
  77. $.post("../usent/update.php",
  78. {
  79. data: JSON.stringify(user_sentence_update_buffer)
  80. },
  81. usent_server_responce);
  82. user_sentence_update_buffer = new Array();
  83. }
  84. }
  85. function usent_server_responce(data, status) {
  86. try {
  87. let result = JSON.parse(data);
  88. if (result.status == 0) {
  89. ntf_show("user sentence" + result.message);
  90. return ("user sentence" + result.message);
  91. }
  92. else {
  93. ntf_show("user sentence error" + result.message);
  94. return ("user sentence error" + result.message);
  95. }
  96. }
  97. catch (e) {
  98. console.error("user_sentence_update:" + e + " data:" + data);
  99. ntf_show("user sentence error");
  100. }
  101. }