|
| 1 | +function showloading() |
| 2 | +{ |
| 3 | +$("#hold").css("visibility","visible"); |
| 4 | +} |
| 5 | +function hideloading() |
| 6 | +{ |
| 7 | +$("#hold").css("visibility","hidden"); |
| 8 | +} |
| 9 | + |
| 10 | +function dateformat(n) |
| 11 | +{ |
| 12 | + return n<10? '0'+n:n; |
| 13 | +} |
| 14 | + |
| 15 | +function ShowLocalDate() |
| 16 | +{ |
| 17 | + const monthNames = ["January", "February", "March", "April", "May", "June", |
| 18 | + "July", "August", "September", "October", "November", "December"]; |
| 19 | +var dNow = new Date(); |
| 20 | +var localdate= dateformat(dNow.getDate())+''+monthNames[dNow.getMonth()] +''+ dNow.getHours() + ':' + dNow.getMinutes(); |
| 21 | +return localdate; |
| 22 | +} |
| 23 | + |
| 24 | + |
| 25 | +function addpr() |
| 26 | +{ |
| 27 | +/* |
| 28 | +Add a patient record |
| 29 | +Sample request: "GET /ADD?id~id243@$record~test HTTP/1.1" |
| 30 | +*/ |
| 31 | + |
| 32 | +if(($.trim($("#pr").val())!="")&($.trim($("#pid").val())!="")) |
| 33 | +{ |
| 34 | + showloading(); |
| 35 | + $.get("ADD", |
| 36 | + "id~"+$("#pid").val()+"@$record~"+encodeURIComponent($.trim($("#pr").val())), |
| 37 | + function(data) |
| 38 | + { |
| 39 | + data=$.trim(data); |
| 40 | + if(data=="success") |
| 41 | + { |
| 42 | + hideloading(); |
| 43 | + $("#status").css("display","inline-block"); |
| 44 | + setTimeout(function(){ $("#status").css("display","none"); }, 3000); |
| 45 | + } |
| 46 | + else alert("Error connecting Server"); |
| 47 | + }); |
| 48 | + |
| 49 | +} |
| 50 | +else{ |
| 51 | + alert("Please enter both patient id and record details"); |
| 52 | +} |
| 53 | + |
| 54 | +} |
| 55 | + |
| 56 | +var firstTime=true; |
| 57 | +function scrolldown() |
| 58 | +{ |
| 59 | + var div = document.getElementById("discussion"); |
| 60 | + if(firstTime) |
| 61 | + {div.scrollTop=div.scrollHeight; firstTime=false;} |
| 62 | + else |
| 63 | + { |
| 64 | + if((div.scrollHeight-div.scrollTop)<(2*div.clientHeight)){ |
| 65 | + div.scrollTop=div.scrollHeight; |
| 66 | + } |
| 67 | + else |
| 68 | + { |
| 69 | + //Show new message arrived |
| 70 | + $("#godown").css("display","inline-block"); |
| 71 | + } |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +function forcescrolldown() |
| 76 | +{ |
| 77 | + var div = document.getElementById("discussion"); |
| 78 | + div.scrollTop=div.scrollHeight; |
| 79 | + $("#godown").css("display","none"); |
| 80 | +} |
| 81 | + |
| 82 | +function showpr() |
| 83 | +{ |
| 84 | +/* |
| 85 | +Read patient record from server and show in text area |
| 86 | +Sample request: "GET /id123.pr HTTP/1.1" |
| 87 | +*/ |
| 88 | + |
| 89 | +if($.trim($("#pid").val())!="") |
| 90 | +{ |
| 91 | + showloading(); |
| 92 | + $.get($.trim($("#pid").val())+".pr","", |
| 93 | + function(data) |
| 94 | + { |
| 95 | + $("#pr").val(""); |
| 96 | + $("#pr").val(decodeURIComponent(data)); |
| 97 | + hideloading(); |
| 98 | + }); |
| 99 | + |
| 100 | +} |
| 101 | +else{ |
| 102 | + alert("Please enter patient id"); |
| 103 | +} |
| 104 | + |
| 105 | +} |
| 106 | +/************************************* |
| 107 | +Message auto sync functions |
| 108 | +**************************************/ |
| 109 | +var req_complete=true; |
| 110 | +var lastid=0; |
| 111 | + |
| 112 | +function refresh(){ |
| 113 | +if(req_complete) |
| 114 | +{ |
| 115 | + //Start the request |
| 116 | + showloading(); |
| 117 | + req_complete=false; |
| 118 | + $.get("m"+ShowLocalDate().substring(0,5)+".m","", |
| 119 | + function(data) |
| 120 | + { |
| 121 | + if(decodeURIComponent($.trim(data))=="Invalid request") |
| 122 | + { |
| 123 | + $("#discussion").html(""); |
| 124 | + hideloading(); |
| 125 | + scrolldown(); |
| 126 | + req_complete=true; |
| 127 | + } |
| 128 | + else |
| 129 | + { |
| 130 | + $("#discussion").html(""); |
| 131 | + $("#discussion").append(decodeURIComponent($.trim(data))); |
| 132 | + hideloading(); |
| 133 | + scrolldown(); |
| 134 | + req_complete=true; |
| 135 | + } |
| 136 | + }); |
| 137 | +} |
| 138 | +} |
| 139 | + |
| 140 | +function refmsg() |
| 141 | +{ |
| 142 | +/* |
| 143 | +Read patient record from server and show in text area |
| 144 | +Sample request: "GET /id123.pr HTTP/1.1" |
| 145 | +*/ |
| 146 | +if(req_complete) |
| 147 | +{ |
| 148 | + req_complete=false; |
| 149 | + //Check if there is any update on the message |
| 150 | + $.get("GETID","a~a",function(data){ |
| 151 | + data=$.trim(data); |
| 152 | + if(data=="error") |
| 153 | + { |
| 154 | + //There is an error in the server. so dont disturb |
| 155 | + } |
| 156 | + else |
| 157 | + { |
| 158 | + if(lastid!=data) |
| 159 | + { |
| 160 | + lastid=data; |
| 161 | + req_complete=true; //Important as refresh function checks if previous request is complete |
| 162 | + refresh(); |
| 163 | + } |
| 164 | + else{ |
| 165 | + //NO new message received |
| 166 | + } |
| 167 | + } |
| 168 | + req_complete=true; |
| 169 | + }); |
| 170 | +} |
| 171 | +} |
| 172 | + |
| 173 | +/************************************/ |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | +function sendmsg() |
| 178 | +{ |
| 179 | +/* |
| 180 | +Send message to server and update the chat screen |
| 181 | +Sample request: "GET /id123.pr HTTP/1.1" |
| 182 | +*/ |
| 183 | + |
| 184 | +if(($.trim($("#uid").val())!="")&($.trim($("#msg").val())!="")) |
| 185 | +{ |
| 186 | + showloading(); |
| 187 | + $.get("SEND", |
| 188 | + "id~"+$("#uid").val()+"@msg~"+encodeURIComponent($.trim($("#msg").val())), |
| 189 | + function(data) |
| 190 | + { |
| 191 | + data=$.trim(data); |
| 192 | + if(data=="success") |
| 193 | + { |
| 194 | + hideloading(); |
| 195 | + //$("#discussion").append("<div class=\"redder\"><div class=\"sender\">"+$("#uid").val()+"</div>"+$("#msg").val()+"<div class=\"time\">"+ShowLocalDate()+"</div></div>"); |
| 196 | + $("#msg").val(""); |
| 197 | + //scrolldown(); |
| 198 | + refmsg(); |
| 199 | + } |
| 200 | + else alert("Error connecting Server"); |
| 201 | + }); |
| 202 | + |
| 203 | +} |
| 204 | +else |
| 205 | +{ |
| 206 | + alert("Please enter both your id and message"); |
| 207 | +} |
| 208 | + |
| 209 | +} |
| 210 | + |
| 211 | + |
| 212 | +function assignevents() |
| 213 | +{ |
| 214 | + |
| 215 | +$("#addbtn").click( |
| 216 | +function() |
| 217 | +{ |
| 218 | +addpr(); |
| 219 | +} |
| 220 | +); |
| 221 | + |
| 222 | +$("#updatebtn").click( |
| 223 | +function() |
| 224 | +{ |
| 225 | +addpr(); |
| 226 | +} |
| 227 | +); |
| 228 | + |
| 229 | +$("#showbtn").click( |
| 230 | +function() |
| 231 | +{ |
| 232 | +showpr(); |
| 233 | +} |
| 234 | +); |
| 235 | + |
| 236 | +$("#msg").keyup(function(event) { |
| 237 | + if (event.keyCode === 13) { |
| 238 | + sendmsg(); |
| 239 | + } |
| 240 | +}); |
| 241 | + |
| 242 | +$("#uid").keyup(function(event) { |
| 243 | + if (event.keyCode === 13) { |
| 244 | + sendmsg(); |
| 245 | + } |
| 246 | +}); |
| 247 | + |
| 248 | +$("#pid").keyup(function(event) { |
| 249 | + if (event.keyCode === 13) { |
| 250 | + showpr(); |
| 251 | + } |
| 252 | +}); |
| 253 | + |
| 254 | +$("#sendbtn").click( |
| 255 | +function() |
| 256 | +{ |
| 257 | +sendmsg(); |
| 258 | +} |
| 259 | +); |
| 260 | + |
| 261 | +$("#refbtn").click( |
| 262 | +function() |
| 263 | +{ |
| 264 | +refmsg(); |
| 265 | +} |
| 266 | +); |
| 267 | + |
| 268 | +$("#godown").click( |
| 269 | +function() |
| 270 | +{ |
| 271 | +forcescrolldown(); |
| 272 | +} |
| 273 | +); |
| 274 | + |
| 275 | +} |
| 276 | + |
0 commit comments