'use strict'; /** Created by: Jaypee Tanio Date Created: Jun 16, 2013 Modified by: Ella Tose Last Modified: Feb 14, 2014 */ var currentDate; function GetDate(d,m,y) { currentDate = y+'-'+m+'-'+d; }; $('document').ready(function() { /*--------------------------------------------------------------------------------------------- Loading of previous data. Get the previous date with existing data through PreviousData.php Same Shedule.ph passed to load on the controls with extra parameter 'prev' to indicate that data is from previous schedule. ----------------------------------------------------------------------------------------------*/ $('#LoadPrev').click(function() { $.ajax({ type:"POST", cache: false, url: "Transaction/PreviousData.php", data: "SelectedDay="+currentDate, success: function(data) { var obj = $.parseJSON(data); $('#Scheduling').load('Module/Scheduling.php?days='+obj+'&prev=true'); } }); }); /*--------------------------------------------------------------------------------------------- Savng and updating of schedule. Data array is generated from the current table to be submitted to saveSchedule.php for the execution of queries. ----------------------------------------------------------------------------------------------*/ $('#save').click(function(){ var Gdate = currentDate; var data = new Array(); var count = 0; $('.datalisting').each(function() { var get_seq = 0; var get_time = $(this).find(".time").val(); var countchild = $(this).find(".tr").length; data[count] = new Array(); $(this).find(".tr").each(function() { var get_measure = $(this).find(".measure").val(); var get_source = $(this).find(".source").val(); var get_selected = $(this).find(".selected").val(); if(get_source != null && get_source != null && get_selected != null) { data[count][get_seq] = new Array(); data[count][get_seq].push(get_time); data[count][get_seq].push(get_seq); data[count][get_seq].push(get_selected); data[count][get_seq].push(get_source); data[count][get_seq].push(get_measure); get_seq++; } }); if(get_time != null) { count++; } }); if($('#save').val()=='SAVE') { SaveData(data, Gdate, "save"); } else { SaveData(data, Gdate, "update"); } }); }); function SaveData(data, date, trans) { $.ajax({ type:"POST", cache: false, url: "Transaction/saveSchedule.php", data: "Data="+JSON.stringify(data)+"&Date="+date, success: function(result) { if(trans == "save") { alert("New schedule successfully saved."); } else { alert("Schedule successfully updated."); } } }); };