Guest User

Untitled

a guest
Feb 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. undefined
  2. test
  3.  
  4. manual test
  5. test
  6.  
  7. undefined
  8. manual test
  9. test
  10.  
  11. function getFreshComments(tabIDToUpdate){
  12.  
  13. var tabInnerComments = $("#" + tabIDToUpdate + " .theNote");
  14. var output;
  15.  
  16. $.getJSON("/notesapi/" + tabIDToUpdate, showCommentsGotten);
  17.  
  18. function showCommentsGotten(dataFedIn){ //dataFedIn is passed in from the $.getJson function above
  19.  
  20. $.each(dataFedIn.todoMessages, (key, item)=>{
  21. output += item + "<br>";
  22. });
  23.  
  24. var normalComments = output;
  25. var newComments = normalComments.split(",").join("<br>");
  26.  
  27. tabInnerComments.html(newComments);
  28. }
  29.  
  30.  
  31. }
  32.  
  33.  
  34. $('body').on("submit", ".additionalCommentsForTodo", function(evt){
  35.  
  36. evt.preventDefault();
  37.  
  38. var tabIDToUpdate = $(this).parent().parent().attr("id");
  39. var commentToInsert = $(".todoCommentBox", this).val();
  40.  
  41.  
  42. console.log(commentToInsert);
  43.  
  44.  
  45. if(commentToInsert !=""){
  46. // var commentToInsert = $(".todoCommentBox", this);
  47.  
  48. console.log("//~~~~~~~FRONTEND NOTE: the ID number for the update is[" + tabIDToUpdate + "] and the message is: " + commentToInsert);
  49.  
  50. $.ajax({
  51. type : "PUT",
  52. url : "/notesapi/" + tabIDToUpdate,
  53. contentType : "application/json; charset=utf-8",
  54. data : JSON.stringify({
  55. todoMessages : commentToInsert
  56. }),
  57. success : function(){
  58. setTimeout(function(){
  59. getFreshComments(tabIDToUpdate);
  60. }, 2000)
  61. },
  62. error : function(XMLHttpRequest, textStatus, errorThrown) {
  63. if (XMLHttpRequest.readyState == 4) {
  64. console.log("HTTP error (can be checked by XMLHttpRequest.status and XMLHttpRequest.statusText");
  65. }
  66. else if (XMLHttpRequest.readyState == 0) {
  67. console.log("Network error (i.e. connection refused, access denied due to CORS, etc.");
  68. }
  69. else {
  70. console.log("something weird is happening");
  71. }
  72. }
  73. }); //ajax end
  74. }
  75.  
  76.  
  77. });
  78.  
  79. app.put("/notesapi/:tabID", (request, response) => {
  80.  
  81. //mongoose.connect(databaseLoc);
  82.  
  83. var idNum = request.params.tabID;
  84. var newIdNumber = idNum.trim();
  85.  
  86. //~~~~~~~~These are the default params for findOneAndUpdate commented out below
  87. //Model.findOneAndUpdate([conditions], [update], [options], [callback])
  88.  
  89. NotesModel.update({_id:newIdNumber},{$push : { todoMessages : request.body.todoMessages } }, (error,data)=>{
  90. if(error){
  91. console.log("error in deleting yo!");
  92. throw error;
  93. } else {
  94. console.log("//~~~~~~~BACKEND NOTE: data has been UPDATED ~~~//");
  95. //mongoose.connection.close();
  96. //response.status(204);
  97. response.json(data);
  98. console.log("//~~~~~~~BACKEND NOTE(2): the ID number for the update is[ --> " + newIdNumber + " <-- ]");
  99. console.log("//~~~~~~~BACKEND NOTE(3): the message to upload is[" + request.body.todoMessages +"]");
  100. }
  101. });
  102.  
  103. });
Add Comment
Please, Sign In to add comment