bheng8200

sublimeIndentation

Mar 30th, 2021 (edited)
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 25.67 KB | None | 0 0
  1.     <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  2.     <script type="text/javascript" src="https://momentjs.com/downloads/moment.js"></script>
  3.     <script src="https://js.pusher.com/4.1/pusher.min.js"></script>
  4.     <script>
  5.  
  6.     // Enable pusher logging - don't include this in production
  7.     Pusher.logToConsole = true;
  8.  
  9.     var pusher = new Pusher('***', {
  10.         cluster: 'us2'
  11.     });
  12.  
  13.     var channel = pusher.subscribe('logEventChannel');
  14.     channel.bind('logEvent', function(response) {
  15.  
  16.  
  17.  
  18.         var log       = response.data['json'];
  19.         var method    = response.data['method'];
  20.  
  21.        
  22.         console.log('\x1b[41m%s\x1b[0m',">>>>>>>>>>>>>>>>>>>>>>>>>DBEUG<<<<<<<<<<<<<<<<<<<<<<<<<");
  23.         console.log('\x1b[41m%s\x1b[0m','method');
  24.         console.log(method);
  25.         console.log('\x1b[41m%s\x1b[0m',">>>>>>>>>>>>>>>>>>>>>>>>>DBEUG<<<<<<<<<<<<<<<<<<<<<<<<<");
  26.        
  27.        
  28.         console.log("SENT FROM BE", method , log);
  29.  
  30.         //====================================
  31.         //              POST
  32.         //====================================
  33.  
  34.         if(method == 'POST'){
  35.  
  36.             var type      = log.type;
  37.             var id        = log.id;
  38.             var babyId    = log.babyId;
  39.             var updatedAt = log.updated_at;
  40.             var timeAgo   = moment(updatedAt).fromNow();
  41.             var time      = moment(updatedAt).format('hh:mm a');
  42.  
  43.            
  44.             getLogMessages(type);
  45.             getCount(type);
  46.             shake('.badge-'+type,1);
  47.  
  48.  
  49.             if(type == 'feed'){
  50.  
  51.                
  52.                 logAudit(babyId);
  53.  
  54.                 blink(".timeLeft");
  55.                 blink(".nextFeed");
  56.  
  57.             }
  58.  
  59.  
  60.  
  61.             var row = `<tr id="tr-${id}" data-type="${type}"> <td > <a class="btn btn-${type}" > <img class="logIconSmall" src="/assets/be/img/baby/${type}.png"/> </a> </td> <td> <a onclick="showModal('${time}','${type}','${id}')" class="btn btn-link"> ${time} </a> </td> <td></td> </tr>`;
  62.  
  63.             $('.tbody-log').prepend(row);
  64.             blink("#tr-"+id);
  65.  
  66.         }
  67.  
  68.         //====================================
  69.         //              PUT
  70.         //====================================
  71.  
  72.         if(method == 'PUT'){
  73.  
  74.  
  75.             var type      = log.type;
  76.             var id        = log.id;
  77.             var babyId    = log.babyId;
  78.             var updatedAt = log.updated_at;
  79.             var timeAgo   = moment(updatedAt).fromNow();
  80.             var time      = moment(updatedAt).format('hh:mm a');
  81.  
  82.             getLogMessages(type);
  83.             getCount(type);
  84.             shake('.badge-'+type,1);
  85.  
  86.  
  87.             if(type == 'feed'){
  88.                
  89.                 logAudit(babyId);
  90.                 blink(".timeLeft");
  91.                 blink(".nextFeed");
  92.             }
  93.  
  94.             $("#tr-"+id).remove(); 
  95.  
  96.             var row = `<tr id="tr-${id}" data-type="${type}"> <td > <a class="btn btn-${type}" > <img class="logIconSmall" src="/assets/be/img/baby/${type}.png"/> </a> </td> <td> <a onclick="showModal('${time}','${type}','${id}')" class="btn btn-link"> ${time} </a> </td> <td></td> </tr>`;
  97.  
  98.  
  99.  
  100.             $('.tbody-log').prepend(row);
  101.             blink("#tr-"+id);
  102.  
  103.  
  104.         }
  105.  
  106.         //====================================
  107.         //              DELETE
  108.         //====================================
  109.  
  110.         if(method == 'DELETE'){
  111.  
  112.             var id     = log.logId;
  113.             var type   = log.type;
  114.             var babyId = log.babyId;
  115.  
  116.  
  117.             if(type == 'feed'){
  118.                
  119.                 logAudit(babyId);
  120.                 blink(".timeLeft");
  121.                 blink(".nextFeed");
  122.             }
  123.  
  124.             getLogMessages(type);
  125.             getCount(type);
  126.             shake('.badge-'+type,1);
  127.             blink("#tr-"+id);
  128.  
  129.             $("#tr-"+id)
  130.             .animate({ backgroundColor: "#ef004810" }, 500 )
  131.             .animate({ backgroundColor: "black"}, 500 )
  132.             .fadeOut(100);
  133.         }
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.         audit(babyId, id, type, method);
  141.         getNextFeed(babyId);
  142.  
  143.     });
  144.  
  145. </script>
  146.  
  147.  
  148.  
  149.  
  150. {{-- Mobile Vs. Desktop --}}
  151. @if($is_mobile)
  152. @include('layouts.be.baby.scripts.swipe')
  153. @else
  154. <script src="/assets/be/js/snowflakeCursor.js"></script>
  155. @endif
  156.  
  157.  
  158. {{-- Audio --}}
  159. <audio id="audio-poop" src="http://www.soundjay.com/button/beep-07.wav" autostart="false" ></audio>
  160. <audio id="audio-pee" src="http://www.soundjay.com/button/beep-02.wav" autostart="false" ></audio>
  161. <audio id="audio-feed" src="http://www.soundjay.com/button/beep-03.wav" autostart="false" ></audio>
  162. <audio id="audio-medicine" src="http://www.soundjay.com/button/beep-04.wav" autostart="false" ></audio>
  163. <audio id="audio-cry" src="http://www.soundjay.com/button/beep-05.wav" autostart="false" ></audio>
  164.  
  165. <script type="text/javascript">
  166.  
  167.  
  168.     function playSound(sound) {
  169.         var sound = document.getElementById("audio-"+sound);
  170.         sound.play();
  171.     }
  172.  
  173.  
  174. </script>
  175.  
  176.  
  177. <script type="text/javascript">
  178.  
  179.  
  180.     function shake(select, seconds) {
  181.         // $(select).effect('shake', {
  182.         //  times: 4
  183.         // }, seconds*1000);
  184.  
  185.         $(select).effect( "shake", { direction: "up", times: 4, distance: 10}, seconds*1000);
  186.     }
  187.  
  188.  
  189.     function blink(select, seconds) {
  190.         $(select).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);
  191.     }
  192.  
  193.     function checkTime(i) {
  194.         if (i < 10) {i = "0" + i};  
  195.         return i;
  196.     }
  197.  
  198.     function timeDiffCalc(dateFuture, dateNow) {
  199.         let diffInMilliSeconds = Math.abs(dateFuture - dateNow) / 1000;
  200.  
  201.         // console.log(dateFuture,dateNow);
  202.  
  203.         const days = Math.floor(diffInMilliSeconds / 86400);
  204.         diffInMilliSeconds -= days * 86400;
  205.         // console.log('calculated days', days);
  206.  
  207.         const hours = Math.floor(diffInMilliSeconds / 3600) % 24;
  208.         diffInMilliSeconds -= hours * 3600;
  209.         // console.log('calculated hours', hours);
  210.  
  211.         const minutes = Math.floor(diffInMilliSeconds / 60) % 60;
  212.         diffInMilliSeconds -= minutes * 60;
  213.         // console.log('minutes', minutes);
  214.  
  215.         let difference = '';
  216.         if (days > 0) {
  217.             difference += (days === 1) ? `${days} day, ` : `${days} days, `;
  218.         }
  219.  
  220.         difference += (hours === 0 || hours === 1) ? `${hours}h ` : `${hours}h `;
  221.         difference += (minutes === 0 || hours === 1) ? `${minutes}m` : `${minutes}m`;
  222.  
  223.         return difference;
  224.     }
  225.  
  226.  
  227.     function refreshThePage(seconds) {
  228.         window.setTimeout(function () {
  229.             window.location.reload();
  230.         }, 1000 * seconds);
  231.     }
  232.  
  233.  
  234.     var url_string = window.location.href;
  235.     var url        = new URL(url_string);
  236.     var dateParam  = url.searchParams.get("date");
  237.     var codeParam  = url.searchParams.get("code");
  238.  
  239.     /*================================
  240.     =            TimeLeft            =
  241.     ================================*/
  242.  
  243.     var nextFeedString = '{{ $nextFeed }}';
  244.     nextFeedString     = nextFeedString.replace(' ', 'T');
  245.     var timeLeft       = timeDiffCalc(new Date(nextFeedString), new Date());
  246.     var date           = moment().format('YYYY-MM-DD');
  247.  
  248.  
  249.  
  250.  
  251.     // CLOCK Vs. NO CLOCK
  252.     if(dateParam == null || dateParam == date) {
  253.  
  254.         //setInterval($('#clock').html(moment().format('ddd M/d/y H:mm:ss')), 1000);
  255.  
  256.         window.setInterval(function () {
  257.             $('#clock').html(moment().format('ddd MM/DD/y H:mm:ss'))
  258.         }, 1000);
  259.  
  260.  
  261.         timeLeftRender(nextFeedString);
  262.  
  263.     } else {
  264.  
  265.  
  266.         //NO CLOCK
  267.         var date = dateParam;
  268.         $('#clock').text(moment(date).format('ddd MM/DD/y'));
  269.  
  270.         $("#profileIcon").css("border", "4px solid #fff");
  271.         $("#clock").css("color", "#fff");
  272.         $("pre").css("border", "2px solid #fff");
  273.        
  274.     }
  275.  
  276.  
  277.     //====================================
  278.     //              Profile + Age
  279.     //====================================
  280.  
  281.     $("#norden, #age").click(function() {
  282.  
  283.         console.log("norden clicked");
  284.  
  285.         var win = window.open('https://www.youtube.com/watch?v=jYHdPf_IZqc&ab_channel=Lan_LanSubs', '_blank');
  286.         if (win) {
  287.             win.focus();
  288.         } else {
  289.  
  290.             alert('Please allow popups for this website');
  291.         }
  292.  
  293.     });
  294.  
  295.  
  296.  
  297.     //====================================
  298.     //              Desktop
  299.     //====================================
  300.  
  301.     if ($(window).width() > 600) {
  302.  
  303.  
  304.  
  305.         //====================================
  306.         //              displayMode
  307.         //====================================
  308.  
  309.         if(`{{$baby->displayMode}}` < 4){
  310.  
  311.             $('.rightSection, #profileIcon, #norden, #age, #logNote, .slidingText, #babyNameDesktop').remove();
  312.             $('.leftSection').toggleClass('col-md-9');
  313.             $('.leftSection').css('background-image',"url()");
  314.             $(".nextFeed").css("font-size", "270px");
  315.             $(".timeLeft").css("border-bottom", "none");
  316.             $(".badge").css("font-size", "40px");
  317.  
  318.  
  319.  
  320.             if(`{{$baby->displayMode}}` == 3){
  321.  
  322.                 $("#profileIcon, #norden").mouseenter(function() {             
  323.                     $("#profileIcon").css("cursor", "url(https://i.imgur.com/T2QWx7Z.png), auto ");
  324.                 });
  325.  
  326.                 $('.leftSection').css('background-image',"url({{$baby->babyBgPath}})");
  327.  
  328.             }
  329.  
  330.  
  331.         } else {
  332.  
  333.             $("#profileIcon, #norden").mouseenter(function() {             
  334.                 $("#profileIcon").css("cursor", "url(https://i.imgur.com/T2QWx7Z.png), auto ");
  335.             });
  336.  
  337.             $('.leftSection').css('background-image',"url({{$baby->babyBgPath}})");
  338.  
  339.         }
  340.  
  341.        
  342.         $('.leftSection').css('height', $(window).height());
  343.         $('.rightSection').css('height', $(window).height());
  344.         $("body").css("overflow", "hidden");
  345.  
  346.  
  347.         $(".adminLink, .readOnlyLink").show();
  348.  
  349.         // refreshThePage(30);
  350.  
  351.        
  352.         //snowFlare
  353.         new snowflakeCursor({ element: document.querySelector(".leftSection") });
  354.  
  355.  
  356.     } else {
  357.  
  358.  
  359.         //====================================
  360.         //              Mobile
  361.         //====================================
  362.  
  363.  
  364.         $(".adminLink, .readOnlyLink").hide();     
  365.     }
  366.  
  367.  
  368.  
  369.     //====================================
  370.     //              Note
  371.     //====================================
  372.  
  373.     $("#toggleNoteModal").hide();
  374.     $("#logNote").click(function() {
  375.         $("#toggleNoteModal").click();
  376.  
  377.     });
  378.  
  379.  
  380.         //====================================
  381.         //              Interval
  382.         //====================================
  383.  
  384.         $(".previous").click(function() {
  385.  
  386.            
  387.             var selectedDay = moment(date).subtract(Math.abs(1), 'days').format('YYYY-MM-DD');
  388.  
  389.             console.log("previous");
  390.             console.log('selectedDay', selectedDay);
  391.             console.log('date',date);
  392.  
  393.             document.location = window.location.origin + window.location.pathname + '?code={{$baby->readOnlyCode}}&date=' + selectedDay;
  394.  
  395.         });
  396.  
  397.  
  398.         $(".next").click(function() {
  399.  
  400.  
  401.             if(date != moment().format('YYYY-MM-DD')) {
  402.                 var selectedDay = moment(date).add(1, 'days').format('YYYY-MM-DD');
  403.  
  404.                 console.log("next");
  405.                 console.log('selectedDay', selectedDay);
  406.                 console.log('date',date);
  407.  
  408.                 document.location = window.location.origin + window.location.pathname + '?code={{$baby->readOnlyCode}}&date=' + selectedDay;
  409.             } else {
  410.                 console.log("future");
  411.             }
  412.         });
  413.  
  414.  
  415.         //====================================
  416.         //              ReadOnly
  417.         //====================================
  418.  
  419.        
  420.         if(codeParam == '{{ $baby->readOnlyCode }}' ) {
  421.             $("a.btn, .btn-link, #logNote").click(function() {
  422.                 return false;
  423.             });
  424.         }
  425.  
  426.         $(document).on('show.bs.modal', '#note', function (e) {
  427.             console.log('works');
  428.             $("body, html").css("overflow", "hidden");
  429.  
  430.             window.onbeforeunload = function() {
  431.                 return false;
  432.             }
  433.  
  434.  
  435.  
  436.         });
  437.  
  438.  
  439.  
  440.         //====================================
  441.         //              TR Hover
  442.         //====================================
  443.  
  444.  
  445.         $("tr").mouseenter(function() {
  446.  
  447.             var row = $(this).attr("data-type");
  448.  
  449.             //RESET
  450.             $('tr').css("border-top", "0");
  451.             $('tr').css("border-bottom", "0");
  452.             $('tr').css("box-shadow", "none");
  453.  
  454.             //SET
  455.             if(row == 'pee'){
  456.  
  457.                 $(this).css("border-top", "2px solid #46b8da");
  458.                 $(this).css("border-bottom", "2px solid #46b8da");
  459.                 $(this).css("box-shadow", "0px 0px 200px 2px #46b8da");
  460.                 $(this).css("-moz-box-shadow", "0px 0px 200px 2px #46b8da");
  461.                 $(this).css("-webkit-box-shadow", "0px 0px 200px 2px #46b8da");
  462.             }
  463.  
  464.             if(row == 'poop'){
  465.                 $(this).css("border-top", "2px solid #ffb54c");
  466.                 $(this).css("border-bottom", "2px solid #ffb54c");
  467.                 $(this).css("box-shadow", "0px 0px 200px 2px #ffb54c");
  468.                 $(this).css("-moz-box-shadow", "0px 0px 200px 2px #ffb54c");
  469.                 $(this).css("-webkit-box-shadow", "0px 0px 200px 2px #ffb54c");
  470.  
  471.             }
  472.  
  473.             if(row == 'feed'){
  474.                 $(this).css("border-top", "2px solid #fff");
  475.                 $(this).css("border-bottom", "2px solid #fff");
  476.                 $(this).css("box-shadow", "0px 0px 200px 2px #fff");
  477.                 $(this).css("-moz-box-shadow", "0px 0px 200px 2px #fff");
  478.                 $(this).css("-webkit-box-shadow", "0px 0px 200px 2px #fff");
  479.  
  480.             }
  481.  
  482.             if(row == 'medicine'){
  483.                 $(this).css("border-top", "2px solid #e6ff00");
  484.                 $(this).css("border-bottom", "2px solid #e6ff00");
  485.                 $(this).css("box-shadow", "0px 0px 200px 2px #e6ff00");
  486.                 $(this).css("-moz-box-shadow", "0px 0px 200px 2px #e6ff00");
  487.                 $(this).css("-webkit-box-shadow", "0px 0px 200px 2px #e6ff00");
  488.  
  489.             }
  490.  
  491.         });
  492.  
  493.  
  494.         //====================================
  495.         //              countType
  496.         //====================================
  497.  
  498.  
  499.         function getCount(type) {
  500.  
  501.             var data    = {};
  502.             data.babyId = '{{ $baby->id }}';
  503.             data.type   = type;
  504.             data.date   = date;
  505.  
  506.  
  507.  
  508.             $.ajax({
  509.                 method: 'POST',
  510.                 url: '/baby/countType',
  511.                 crossDomain: true,
  512.                 contentType: false,
  513.                 headers: {
  514.                     'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('value'),
  515.                     "Accept": "application/json",
  516.                     "Content-Type": "application/x-www-form-urlencoded",
  517.                     "Cache-Control": "no-cache"
  518.                 },
  519.                 data: data,
  520.                 success: function(response){
  521.                     // console.log(response);
  522.  
  523.                     $('.count-'+data.type).text(response);
  524.                 },
  525.                 error: function(jqXHR, textStatus, errorThrown) {
  526.                     console.log(JSON.stringify(jqXHR));
  527.                     console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
  528.                 }
  529.             });
  530.  
  531.         }
  532.  
  533.  
  534.         getCount('poop');
  535.         getCount('pee');
  536.         getCount('medicine');
  537.         getCount('feed');
  538.  
  539.  
  540.  
  541.  
  542.         //====================================
  543.         //              Log Create
  544.         //====================================
  545.  
  546.         $('.logButtons a').on('click', function (e){
  547.  
  548.             e.preventDefault();
  549.            
  550.             var data    = {};
  551.             data.method = 'POST';
  552.             data.babyId = '{{ $baby->id }}';
  553.             data.type   = $(this).attr("data-type");
  554.             data.date   = date;
  555.            
  556.  
  557.  
  558.             console.log('SENT from FE',data);
  559.  
  560.             // return false;
  561.  
  562.  
  563.             $.ajax({
  564.                 method: 'POST',
  565.                 url: '/baby/log',
  566.                 crossDomain: true,
  567.                 contentType: false,
  568.                 headers: {
  569.                     'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('value'),
  570.                     "Accept": "application/json",
  571.                     "Content-Type": "application/x-www-form-urlencoded",
  572.                     "Cache-Control": "no-cache"
  573.                 },
  574.                 data: data,
  575.                 success: function(response){
  576.                     getCount(data.type);
  577.                 },
  578.                 error: function(jqXHR, textStatus, errorThrown) {
  579.                     console.log(JSON.stringify(jqXHR));
  580.                     console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
  581.                 }
  582.             });
  583.  
  584.  
  585.         });
  586.  
  587.  
  588.  
  589.         //====================================
  590.         //              Log Create
  591.         //====================================
  592.  
  593.         function updateLog(logId) {
  594.  
  595.            
  596.             var data       = {};
  597.             data.method    = 'PUT';
  598.             data.babyId    = '{{ $baby->id }}';
  599.             data.logId     = logId;
  600.             data.date      = date;
  601.             data.updatedAt = $("input[name=updatedAt]").val();
  602.  
  603.             console.log('SENT from FE',data);
  604.  
  605.             $.ajax({
  606.                 method: 'PUT',
  607.                 url: '/baby/log',
  608.                 crossDomain: true,
  609.                 contentType: false,
  610.                 headers: {
  611.                     'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('value'),
  612.                     "Accept": "application/json",
  613.                     "Content-Type": "application/x-www-form-urlencoded",
  614.                     "Cache-Control": "no-cache"
  615.                 },
  616.                 data: data,
  617.                 success: function(response){
  618.                     $('.modal').modal('hide');
  619.                 },
  620.                 error: function(jqXHR, textStatus, errorThrown) {
  621.                     console.log(JSON.stringify(jqXHR));
  622.                     console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
  623.                 }
  624.             });
  625.  
  626.  
  627.         };
  628.  
  629.  
  630.  
  631.  
  632.         //====================================
  633.         //              Log Delete
  634.         //====================================
  635.  
  636.         function deleteLog(logId, type) {
  637.  
  638.  
  639.             var data    = {};
  640.             data.method = 'DELETE';
  641.             data.babyId = '{{ $baby->id }}';
  642.             data.logId  = logId;
  643.             data.date   = date;
  644.             data.type   = type;
  645.  
  646.             console.log('SENT from FE',data);
  647.  
  648.  
  649.             $.ajax({
  650.                 method: 'DELETE',
  651.                 url: '/baby/log',
  652.                 crossDomain: true,
  653.                 contentType: false,
  654.                 headers: {
  655.                     'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('value'),
  656.                     "Accept": "application/json",
  657.                     "Content-Type": "application/x-www-form-urlencoded",
  658.                     "Cache-Control": "no-cache"
  659.                 },
  660.                 data: data,
  661.                 success: function(response){
  662.                     $('.modal').modal('hide');
  663.                 },
  664.                 error: function(jqXHR, textStatus, errorThrown) {
  665.                     console.log(JSON.stringify(jqXHR));
  666.                     console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
  667.                 }
  668.             });
  669.  
  670.  
  671.  
  672.         }
  673.  
  674.  
  675.  
  676.         //====================================
  677.         //              logDetail
  678.         //====================================
  679.  
  680.  
  681.         function getLogMessages(type) {
  682.  
  683.  
  684.             var data    = {};
  685.             data.babyId = '{{ $baby->id }}';
  686.             data.type   = type;
  687.             data.date   = date;
  688.  
  689.  
  690.             $.ajax({
  691.                 method: 'POST',
  692.                 url: '/baby/logDetail',
  693.                 crossDomain: true,
  694.                 contentType: false,
  695.                 headers: {
  696.                     'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('value'),
  697.                     "Accept": "application/json",
  698.                     "Content-Type": "application/x-www-form-urlencoded",
  699.                     "Cache-Control": "no-cache"
  700.                 },
  701.                 data: data,
  702.                 success: function(response){
  703.                     // console.log(response);
  704.  
  705.                     // console.log("data.type",data.type);
  706.  
  707.                     var lastFeedMessage = '';
  708.                     var lastFeedColor = '';
  709.  
  710.  
  711.                     for (i = 0; i < response.length; i++) {
  712.                         // console.log(response[i].id);
  713.  
  714.                         if(data.type == 'feed'){
  715.                             if(response[i].msg.includes("+")){
  716.                                 var color = '#00ff5c';
  717.                             } else {
  718.                                 var color = '#ef0048';
  719.                             }
  720.  
  721.                             lastFeedMessage = response[0].msg;
  722.                             if(lastFeedMessage.includes("+")){
  723.                                 var lastFeedColor = '#00ff5c';
  724.                             } else {
  725.                                 var lastFeedColor = '#ef0048';
  726.                             }
  727.  
  728.                         } else {
  729.                             var color = '#ccc';
  730.                         }
  731.  
  732.                         $('#td-'+response[i].id).html('');
  733.                         var td = `<span style="font-weight: bold; color:${color};">${response[i].msg}</span>`;
  734.                         $('#td-'+response[i].id).prepend(td);
  735.                     }
  736.  
  737.  
  738.  
  739.                     if(`{{$baby->displayMode}}` == 1){
  740.                         if ($(window).width() > 600) {
  741.                             $('.timeLeft').append(`<br><span style="font-weight: bold; font-size:100px; margin-left:10px; color:${lastFeedColor};">${lastFeedMessage}</span>`);
  742.                         }
  743.                     }
  744.  
  745.  
  746.                 },
  747.                 error: function(jqXHR, textStatus, errorThrown) {
  748.                     console.log(JSON.stringify(jqXHR));
  749.                     console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
  750.                 }
  751.             });
  752.  
  753.         }
  754.  
  755.  
  756.         getLogMessages('feed');
  757.         getLogMessages('poop');
  758.         getLogMessages('pee');
  759.         getLogMessages('medicine');
  760.  
  761.  
  762.  
  763.  
  764.         //====================================
  765.         //              datePicker
  766.         //====================================
  767.  
  768.  
  769.         $("#clock").click(function() {
  770.  
  771.  
  772.             $("#expiryDate").datepicker({
  773.                 dateFormat: 'yy-mm-dd',
  774.                 maxDate: 0,
  775.                 onSelect: function() {
  776.                     var dateSelected = $(this).datepicker('getDate');
  777.                     dateSelected = moment(dateSelected).format('YYYY-MM-DD');
  778.  
  779.  
  780.  
  781.                     if(dateParam == null) {
  782.                         var url = document.location.href+"&date="+dateSelected;
  783.                     }else {
  784.                         var url = document.location.href;
  785.                         url = url.replace(dateParam,dateSelected);
  786.  
  787.                     }
  788.  
  789.                     document.location = url;
  790.                 }
  791.             });
  792.             $('#expiryDate').datepicker('show');
  793.         });
  794.  
  795.  
  796.  
  797.  
  798.         //====================================
  799.         //              showForm
  800.         //====================================
  801.  
  802.  
  803.         function showModal(val, type, logId ) {
  804.  
  805.             console.log("val, type, logId",val, type, logId);
  806.  
  807.             var popupTemplate = `
  808.             <div class="modal fade" data-backdrop="static">
  809.             <div class="model-content" style="margin-top: 200px;">
  810.             <div class="col-sm-offset-4 col-sm-2 col-md-offset-5 col-md-2 text-center">
  811.             <img width="80" src="/assets/be/img/baby/${type}.png"><br><br><br>
  812.             <input type="time" value="${val}" name="updatedAt" width="100%" height="80">
  813.             <br><br>
  814.             <button onclick="updateLog('${logId}')" class="btn btn-success btn-block">Done</button>
  815.             <br>
  816.             <button onclick="deleteLog('${logId}', '${type}')" class="btn btn-danger btn-block">Delete</button>
  817.             </div>
  818.             </div>
  819.             </div>
  820.             `;
  821.  
  822.  
  823.             $(popupTemplate).modal();
  824.  
  825.         }
  826.  
  827.  
  828.         //====================================
  829.         //              getLog
  830.         //====================================
  831.  
  832.         function getLog(logId) {
  833.  
  834.  
  835.             var data    = {};
  836.             console.log('SENT from FE',data);
  837.  
  838.  
  839.             $.ajax({
  840.                 method: 'POST',
  841.                 url: '/baby/log/'+logId,
  842.                 crossDomain: true,
  843.                 contentType: false,
  844.                 headers: {
  845.                     'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('value'),
  846.                     "Accept": "application/json",
  847.                     "Content-Type": "application/x-www-form-urlencoded",
  848.                     "Cache-Control": "no-cache"
  849.                 },
  850.                 data: data,
  851.                 success: function(response){
  852.                    
  853.                     getCount(data.type);
  854.                    
  855.  
  856.                     var log       = response.data['json'];
  857.                     var type      = log.type;
  858.                     var id        = log.id;
  859.                     var updatedAt = log.updated_at;
  860.                     var timeAgo   = moment(updatedAt).fromNow();
  861.                     var time      = moment(updatedAt).format('hh:mm a');
  862.  
  863.                     var row = `<tr data-type="${type}"> <td > <a class="btn btn-${type}" > <img class="logIconSmall" src="/assets/be/img/baby/${type}.png"/> </a> </td> <td>
  864.  
  865.                     <a onclick="showModal('${time}','${type}','${id}')" class="btn btn-link">
  866.                     ${time}
  867.                     </a>
  868.  
  869.  
  870.                     </td>
  871.                     <td></td>
  872.  
  873.                     </tr>`;
  874.                     $('.tbody-log').prepend(row);
  875.  
  876.  
  877.                 },
  878.                 error: function(jqXHR, textStatus, errorThrown) {
  879.                     console.log(JSON.stringify(jqXHR));
  880.                     console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
  881.                 }
  882.             });
  883.  
  884.  
  885.  
  886.         }
  887.  
  888.  
  889.  
  890.  
  891.         //====================================
  892.         //              getNextFeed
  893.         //====================================
  894.  
  895.         function getNextFeed(babyId) {
  896.  
  897.  
  898.             var data    = {};
  899.             data.babyId = babyId;
  900.             data.date   = date;
  901.  
  902.  
  903.             console.log('SENT from FE',data);
  904.  
  905.  
  906.             $.ajax({
  907.                 method: 'POST',
  908.                 url: '/baby/log/nextFeed',
  909.                 crossDomain: true,
  910.                 contentType: false,
  911.                 headers: {
  912.                     'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('value'),
  913.                     "Accept": "application/json",
  914.                     "Content-Type": "application/x-www-form-urlencoded",
  915.                     "Cache-Control": "no-cache"
  916.                 },
  917.                 data: data,
  918.                 success: function(response){
  919.  
  920.  
  921.                     console.log('SUCCESS response',response);
  922.                     timeLeftRender(response);
  923.                 },
  924.                 error: function(jqXHR, textStatus, errorThrown) {
  925.                     console.log(JSON.stringify(jqXHR));
  926.                     console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
  927.                 }
  928.             });
  929.  
  930.  
  931.  
  932.         }
  933.  
  934.  
  935.  
  936.         window.setInterval(function () {
  937.             getNextFeed('{{ $baby->id }}');
  938.         }, 5000);
  939.  
  940.  
  941.         //====================================
  942.         //              timeLeft
  943.         //====================================
  944.  
  945.  
  946.         function timeLeftRender(nextFeedString) {
  947.  
  948.  
  949.             nextFeedString     = nextFeedString.replace(' ', 'T');
  950.             var timeLeft       = timeDiffCalc(new Date(nextFeedString), new Date());
  951.  
  952.             $('.timeLeft').text('');
  953.             $('.timeLeft').text(timeLeft);
  954.  
  955.  
  956.             $('.nextFeed').text('');
  957.             $('.nextFeed').html(moment(nextFeedString).format('h:mm a'));
  958.  
  959.  
  960.  
  961.             if(timeLeft.includes("0h")){
  962.  
  963.                 $(".timeLeft").css("color", "#ffc51b");
  964.                 timeLeft = timeLeft.replace('0h', '');
  965.                 $('.timeLeft').text(timeLeft);
  966.  
  967.                 if ($(window).width() > 600) {
  968.                     $(".timeLeft").css("font-size", "234px");
  969.                 } else {
  970.                     $(".timeLeft").css("font-size", "25px");
  971.                 }
  972.  
  973.  
  974.                 $("#profileIcon").css("border", "4px solid #ffc51b");
  975.                 $("#clock").css("color", "#ffc51b");
  976.                 $("pre").css("border", "2px solid #ffc51b");
  977.  
  978.  
  979.  
  980.             }else {
  981.  
  982.  
  983.                 $(".timeLeft").css("color", "#00ff5c");
  984.                 $("#profileIcon").css("border", "4px solid #00ff5c");
  985.                 $("#clock").css("color", "#00ff5c");
  986.                 $("pre").css("border", "2px solid #00ff5c");
  987.  
  988.  
  989.             }
  990.  
  991.  
  992.  
  993.             if(new Date(nextFeedString) < new Date()){
  994.  
  995.                 $(".timeLeft").css("color", "#c12222");
  996.                 timeLeft = timeLeft.replace('0h', '');
  997.                 $("#profileIcon").css("border", "4px solid #c12222");
  998.                 $("#clock").css("color", "#c12222");
  999.                 $("pre").css("border", "2px solid #c12222");
  1000.  
  1001.  
  1002.                 $('.timeLeft').text(timeLeft);
  1003.  
  1004.             }else{
  1005.  
  1006.                 $('.timeLeft').text(timeLeft);
  1007.  
  1008.             }
  1009.  
  1010.         }
  1011.  
  1012.         //====================================
  1013.         //              Audit
  1014.         //====================================
  1015.  
  1016.         function logAudit(babyId) {
  1017.  
  1018.             var data    = {};
  1019.             data.babyId = babyId;
  1020.             data.date   = date;
  1021.  
  1022.             console.log('SENT from FE',data);
  1023.  
  1024.             $.ajax({
  1025.                 method: 'POST',
  1026.                 url: '/baby/log/audit',
  1027.                 crossDomain: true,
  1028.                 contentType: false,
  1029.                 headers: {
  1030.                     'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('value'),
  1031.                     "Accept": "application/json",
  1032.                     "Content-Type": "application/x-www-form-urlencoded",
  1033.                     "Cache-Control": "no-cache"
  1034.                 },
  1035.                 data: data,
  1036.                 success: function(response){
  1037.                     console.log('SUCCESS response',response);
  1038.                 },
  1039.                 error: function(jqXHR, textStatus, errorThrown) {
  1040.                     console.log(JSON.stringify(jqXHR));
  1041.                     console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
  1042.                 }
  1043.             });
  1044.  
  1045.         }
  1046.  
  1047.  
  1048.         //====================================
  1049.         //              audit
  1050.         //====================================
  1051.  
  1052.  
  1053.         function audit(babyId, logId, type, method) {
  1054.  
  1055.             var data    = {};
  1056.             data.babyId = babyId;
  1057.             data.logId  = logId;
  1058.             data.type   = type;
  1059.             data.method = method;
  1060.            
  1061.             console.log('SENT from FE',data);
  1062.  
  1063.             $.ajax({
  1064.                 method: 'POST',
  1065.                 url: '/baby/audit',
  1066.                 crossDomain: true,
  1067.                 contentType: false,
  1068.                 headers: {
  1069.                     'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('value'),
  1070.                     "Accept": "application/json",
  1071.                     "Content-Type": "application/x-www-form-urlencoded",
  1072.                     "Cache-Control": "no-cache"
  1073.                 },
  1074.                 data: data,
  1075.                 success: function(response){
  1076.                     console.log('SUCCESS response',response);
  1077.                 },
  1078.                 error: function(jqXHR, textStatus, errorThrown) {
  1079.                     console.log(JSON.stringify(jqXHR));
  1080.                     console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
  1081.                 }
  1082.             });
  1083.  
  1084.         }
  1085.  
  1086.  
  1087.  
  1088.  
  1089.     </script>
  1090.  
  1091.  
  1092.  
Add Comment
Please, Sign In to add comment