source: schedule/js/function.js@ 17648

Last change on this file since 17648 was 17557, checked in by tose, 11 years ago
Removed unnecessary functions and included comments
File size: 3.1 KB
Line 
1'use strict';
2/**
3 Created by: Jaypee Tanio
4 Date Created: Jun 16, 2013
5 Modified by: Ella Tose
6 Last Modified: Feb 14, 2014
7 */
8
9
10var currentDate;
11
12function GetDate(d,m,y)
13{
14 currentDate = y+'-'+m+'-'+d;
15};
16
17$('document').ready(function() {
18
19/*---------------------------------------------------------------------------------------------
20 Loading of previous data. Get the previous date with existing data through PreviousData.php
21 Same Shedule.ph passed to load on the controls with extra parameter 'prev' to indicate that
22 data is from previous schedule.
23 ----------------------------------------------------------------------------------------------*/
24
25$('#LoadPrev').click(function() {
26 $.ajax({
27 type:"POST",
28 cache: false,
29 url: "Transaction/PreviousData.php",
30 data: "SelectedDay="+currentDate,
31 success: function(data) {
32 var obj = $.parseJSON(data);
33 $('#Scheduling').load('Module/Scheduling.php?days='+obj+'&prev=true');
34 }
35 });
36});
37
38/*---------------------------------------------------------------------------------------------
39 Savng and updating of schedule. Data array is generated from the current table to be submitted
40 to saveSchedule.php for the execution of queries.
41 ----------------------------------------------------------------------------------------------*/
42
43$('#save').click(function(){
44 var Gdate = currentDate;
45 var data = new Array();
46 var count = 0;
47 $('.datalisting').each(function() {
48 var get_seq = 0;
49 var get_time = $(this).find(".time").val();
50 var countchild = $(this).find(".tr").length;
51 data[count] = new Array();
52 $(this).find(".tr").each(function() {
53 var get_measure = $(this).find(".measure").val();
54 var get_source = $(this).find(".source").val();
55 var get_selected = $(this).find(".selected").val();
56 if(get_source != null && get_source != null && get_selected != null) {
57 data[count][get_seq] = new Array();
58 data[count][get_seq].push(get_time);
59 data[count][get_seq].push(get_seq);
60 data[count][get_seq].push(get_selected);
61 data[count][get_seq].push(get_source);
62 data[count][get_seq].push(get_measure);
63 get_seq++;
64 }
65 });
66 if(get_time != null) {
67 count++;
68 }
69 });
70 if($('#save').val()=='SAVE')
71{
72 SaveData(data, Gdate, "save");
73 }
74else {
75 SaveData(data, Gdate, "update");
76 }
77});
78});
79
80function SaveData(data, date, trans) {
81 $.ajax({
82 type:"POST",
83 cache: false,
84 url: "Transaction/saveSchedule.php",
85 data: "Data="+JSON.stringify(data)+"&Date="+date,
86 success: function(result) {
87 if(trans == "save") {
88 alert("New schedule successfully saved.");
89 } else {
90 alert("Schedule successfully updated.");
91 }
92 }
93 });
94};
Note: See TracBrowser for help on using the repository browser.