usent.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 newData = new Object();
  45. newData.id = dbId;
  46. newData.text = text;
  47. newData.time = d.getTime();
  48. user_sentence_update_buffer.push(newData);
  49. }
  50. function usent_create(blockid,id,book,paragraph,begin,end,text,tag,lang,author,editor){
  51. let newData = new Object();
  52. newData.blockid = blockid;
  53. newData.id = id;
  54. newData.book = book;
  55. newData.paragraph = paragraph;
  56. newData.begin = begin;
  57. newData.end = end;
  58. newData.text = text;
  59. newData.tag = tag;
  60. newData.lang = lang;
  61. newData.author = author;
  62. newData.editor = editor;
  63. user_sentence_create_buffer.push(newData);
  64. }
  65. function usent_commit(){
  66. if(user_sentence_create_buffer.length>0){
  67. $.post("../usent/new.php",
  68. {
  69. data:JSON.stringify(user_sentence_create_buffer)
  70. },
  71. usent_server_responce);
  72. user_sentence_create_buffer=new Array();
  73. }
  74. if(user_sentence_update_buffer.length>0){
  75. $.post("../usent/update.php",
  76. {
  77. data:JSON.stringify(user_sentence_update_buffer)
  78. },
  79. usent_server_responce);
  80. user_sentence_update_buffer=new Array();
  81. }
  82. }
  83. function usent_server_responce(data,status){
  84. try{
  85. let result= JSON.parse(data);
  86. if(result.status==0){
  87. ntf_show("user sentence"+result.message);
  88. return("user sentence"+result.message);
  89. }
  90. else{
  91. ntf_show("user sentence error"+result.message);
  92. return("user sentence error"+result.message);
  93. }
  94. }
  95. catch(e){
  96. console.error("user_sentence_update:"+e+" data:"+data);
  97. ntf_show("user sentence error");
  98. }
  99. }