Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.25 KB | None | 0 0
  1. <style type="text/css" media="screen">
  2. .datePicker{
  3. position:relative;
  4. float:right;
  5. left:-210px;
  6. z-index:3;
  7. top: 83px;
  8. }
  9.  
  10. #loading{
  11. position:relative;
  12. left:380px;
  13. top:-100px;
  14. }
  15.  
  16. </style>
  17. <script>
  18. var myObj = {};
  19. var oTable;
  20. var jsonReturn;
  21.  
  22. $(document).ready(function() {
  23.  
  24. $.ajaxSetup({
  25. type: "POST",
  26. dataType: "json",
  27. //async:false,
  28.  
  29. complete: function() {},
  30. success: function() {},
  31. error: function() {
  32. console.log("OH SHIT, SOMETHING BAD HAPPENED!!!!");
  33. },
  34. });
  35.  
  36. // Ajax loaders
  37. $("#loading").ajaxStart(function(){
  38. $(this).show();
  39. });
  40.  
  41. $("#loading").ajaxStop(function(){
  42. $(this).hide();
  43. });
  44.  
  45. function drawTable(date){
  46.  
  47.  
  48. oTable = $('#example').dataTable( {
  49. "bProcessing": true,
  50. "bRetrieve":false,
  51.  
  52. //"bServerSide": true,
  53. "sPaginationType": "full_numbers",
  54. "bDestroy":true,
  55. "aoColumns": [
  56. { "sClass": "center", "bSortable": false },
  57. null,
  58. null,
  59. null,
  60. null,
  61. { "sClass": "center" },
  62. { "sClass": "center" },
  63. { "sClass": "center" }
  64. ],
  65. "aoColumnDefs": [
  66. { "bVisible": false, "bSearchable": false,"aTargets": [ 5 ] }
  67.  
  68. //{ "bSearchable": false, "bVisible": false, "aTargets": [ 2 ] },
  69. //{ "bVisible": false, "aTargets": [ 3 ] }
  70. ],
  71. //"sAjaxSource": "/calendar.json",
  72. "fnInitComplete": function(){
  73. //Complete
  74. },
  75. "fnServerData": function ( sSource, aoData, fnCallback ) {
  76. /* Add some extra data to the sender */
  77. if(date!=null)
  78. aoData.push( { "name": "date", "value": date } );
  79. $.getJSON( sSource, aoData, function (json) {
  80. jsonReturn = json
  81. fnCallback(json);
  82. });
  83. }
  84. });
  85.  
  86. }
  87.  
  88. /* Draw the initial table, passing in null to get today date */
  89. drawTable(null);
  90.  
  91. function getChargesViaAjax(data){
  92. var htmlOut;
  93. $.ajax({
  94. url: "/calendar/show",
  95. data: data,
  96. async:false,
  97. complete: function(data,textStatus,xhr) {
  98. selectedDate = $('#tableDate').html();
  99. //called when complete
  100. myObj = JSON.parse(data["responseText"]);
  101. htmlOut = '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">';
  102. htmlOut+='<caption>FIN: '+myObj.patient_fin+' Date: '+selectedDate+'</caption>';
  103. htmlOut+='<th>Name</th><th>Type</th><th>Location</th><th>Doctor</th><th>Recorded</th>';
  104. $.each(myObj.aaData,function(index,value) {
  105. htmlOut+="<tr>";
  106. htmlOut += '<td>'+value.procedure_name+'</td>';
  107. htmlOut += '<td>'+replaceNull(value.procedure_type)+'</td>';
  108. htmlOut += '<td>'+replaceNull(value.locality)+'</td>';
  109. htmlOut += '<td>'+value.charging_doctor+'</td>';
  110. if(!value.been_recorded){
  111. htmlOut += '<td>'
  112. htmlOut += '<div id=\'div_'+value.id+'\'>'
  113. <% if current_user.is_admin? %>
  114. htmlOut += '<input class="recordCharge" id=\'charge_'+value.id+'\' type=\'button\' class=\'record_charge_button\' onClick=\'recordThisCharge('+value.id+');\' value=\'record\'/>';
  115. <% else %>
  116. htmlOut+='<font size="3em" color="yellow">No</font>';
  117.  
  118. <% end -%>
  119.  
  120.  
  121. htmlOut +='</div>';
  122. htmlOut +='</td>';
  123. }else{
  124. htmlOut+='<td><font color="green">Yes</font></td>';
  125. }
  126. htmlOut+='</tr>';
  127. });
  128. }
  129. });
  130. return htmlOut;
  131. }
  132.  
  133. /* Add event listener for opening and closing details
  134. * Note that the indicator for showing which row is open is not controlled by DataTables,
  135. * rather it is done here
  136. */
  137. $('#example tbody td img').live('click', function () {
  138. var nTr = this.parentNode.parentNode;
  139. if ( this.src.match('details_close')){
  140. /* This row is already open - close it */
  141. this.src = "../images/examples_support/details_open.png";
  142. oTable.fnClose( nTr );
  143. } else {
  144. /* Open this row */
  145. myObj = {}
  146. myObj.patientID = oTable.fnGetData( nTr )[5];
  147. myObj.selectedDate = jsonReturn['date'];
  148. //getChargeViaAjax(myObj);
  149.  
  150. this.src = "../images/examples_support/details_close.png";
  151. oTable.fnOpen( nTr, fnFormatDetails(oTable, nTr,myObj), 'details' );
  152. }
  153. });
  154.  
  155. $( "#datepicker" ).datepicker({
  156. onClose: function(dateText, inst){
  157. drawTable(dateText);
  158. $('#tableDate').html(dateText);
  159. }
  160. });
  161.  
  162. /* Formating function for row details */
  163. function fnFormatDetails ( oTable, nTr, myObj ){
  164. var aData = oTable.fnGetData( nTr );
  165. var sOut = getChargesViaAjax(myObj);
  166. return sOut;
  167. }
  168.  
  169. function replaceNull(value){
  170. if(value==null){ return ""; }
  171. else{ return value; }
  172. }
  173.  
  174. });
  175.  
  176. function recordThisCharge(id){
  177. console.log("===> " +id);
  178. response={}
  179. charge={}
  180. response.id=id
  181. charge.recorded=true
  182. response.charge=charge
  183. $(function(){
  184. $.ajax({
  185. dataType: "json",
  186. url: "/charges/update",
  187. data: response,
  188. success: function(msg){
  189. $('#charge_'+id).parent().html('<font color="green">Yes</font>')
  190. },
  191. error: function(XMLHttpRequest, textStatus, errorThrown){
  192. $('#charge_'+id).parent().html('<font color="red">Error</font>');
  193. }
  194. });
  195. });
  196. }
  197.  
  198.  
  199.  
  200. </script>
  201. </head>
  202. <body id="dt_example">
  203. <div id="container">
  204. <div class="datePicker">
  205. <p>Date: <input type="text" id="datepicker"></p>
  206. </div>
  207.  
  208. <div class="full_width big">
  209. <i>Patient</i> Charges
  210. </div>
  211. <h1 id="tableDate">Today</h1>
  212. <div id="dynamic">
  213. <table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
  214. <thead>
  215. <tr>
  216. <th width="4%"></th>
  217. <th width="20%">Name:</th>
  218. <th width="20%">Admitted:</th>
  219. <th width="20%">Doctor:</th>
  220. <th width="12%">Facility:</th>
  221. <th width="10%">ID</th>
  222. <th width="12%">Charges:</th>
  223. <th width="12%">Unbilled:</th>
  224.  
  225. </tr>
  226. </thead>
  227. <tbody>
  228.  
  229. <!--
  230. DataTables puts data here
  231. -->
  232.  
  233. </tbody>
  234. <tfoot>
  235. <tr>
  236. <th></th>
  237. <th>Name</th>
  238. <th>Admitted</th>
  239. <th>Doctor</th>
  240. <th>Facility</th>
  241. <th>ID</th>
  242. <th>Charges</th>
  243. <th>Unbilled</th>
  244.  
  245. </tr>
  246. </tfoot>
  247. </table>
  248. </div>
  249. <div class="spacer"></div>
  250.  
  251. <!-- Hidden div for ajax loader -->
  252. <div id="loading" style="display:none">
  253. <img src="../images/ajaxLoader.gif"/>
  254. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement