-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopen_canteen.js
executable file
·197 lines (162 loc) · 5.39 KB
/
open_canteen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
$(document).ready( function() {
// Expand upload form
$('#upload-link').click( function() {
$('#upload').toggle('slow');
$('#upload_description').toggle('slow');
return false;
});
// Expand detail information area
$('#display-link').click( function() {
$('#display').toggle('slow');
return false;
});
// $("table tr").click(function() {
// $("table tr").css("background", "#fff"); //reset to original color
// $(this).css("background", "#fo0"); //apply the new color
// });
});
// Check if inputs have been selected/entered properly
function validateForm()
{
var food_type = document.getElementsByName("food_type");
var ingredient = document.getElementsByName("ingredient");
var canteen = document.getElementsByName("canteen");
var err_flag1 = true;
var err_flag2 = true;
var err_flag3 = true;
for (var i=0; i<food_type.length; i++) {
if(food_type[i].checked == true) err_flag1 = false;
}
for (var i=0; i<ingredient.length; i++) {
if(ingredient[i].checked == true) err_flag2 = false;
}
for (var i=0; i<canteen.length; i++) {
if(canteen[i].checked == true) err_flag3 = false;
}
if (err_flag1 || err_flag2 || err_flag3) {
alert("Food type, Main Ingredient and Canteen must be selected");
return false;
}
}
function validateUpload()
{
var food_name = document.getElementsByName("food_name_");
if (food_name[0].value == "") {
alert("Food name is missing");
return false;
}
}
function validatePicUpload()
{
var pic_addr = document.getElementById("pic_upload");
if (pic_addr.value == "") {
alert("No picture uploaded");
return false;
}
}
// check if metadata text file has been loaded succesfully
function do_alert(err_flag)
{
if (err_flag == 1) {
alert("Error has occured. Going back to the front page");
window.history.back();
}
}
function show_detail(id, index)
{
//alert(document.getElementById('detail_info').value + " / " +id);
document.getElementById('detail_info').value = id;
document.getElementById('selected_row').value = index;
document.forms["display"].submit();
return true;
}
function check_redirect(flag) {
if(flag==true) {
document.getElementById('upload').setAttribute("display", "block");
document.getElementById('upload_description').setAttribute("display", "none");
}
else {
document.getElementById('upload').setAttribute("display", "hidden");
document.getElementById('upload_description').setAttribute("display", "block");
}
}
function add_comment(){
var form = document.getElementById('add_comment_form');
var reviewer_name = document.getElementById('_reviewer_name').value;
var comment = document.getElementById('_comment').value;
var rating_radio = document.getElementsByName('_rating');
var recommend_radio = document.getElementsByName('_recommend');
var dishname = document.getElementsByName('food_name')[0].value;
if (!comment){
alert("Please enter a comment");
return false;
}
if (!reviewer_name){
var anon = confirm("Leave review anonymously?");
if (anon) {
// reviewer_name = "Anonymous";
document.getElementById('_reviewer_name').value = "Anonymous";
}
else return false;
}
var rating = 0;
for (var i=0; i < rating_radio.length; i++){
if (rating_radio[i].checked)
{
rating = rating_radio[i].value;
}
}
var recommendation = "";
for (var i=0; i < recommend_radio.length; i++){
if (recommend_radio[i].checked)
{
recommendation = recommend_radio[i].value;
}
}
var confirmation_string = "Thanks " + reviewer_name + "!\nYou are about to leave the following review for " + dishname + ":\n\nRating: " + rating + "/5 \nBottom Line: " + recommendation +"\nComments: " + comment + "\n\nAdd review?";
var add_comment = confirm(confirmation_string);
return add_comment;
}
// function to use for debugging
function do_print(msg)
{
alert("print: " + msg);
}
function commentSubmit()
{
//document.getElementById("_comment").value = "";
//document.forms["add_comment_form"].submit();
//document.forms["add_comment_form"].reset();
if(add_comment()) {
//document.forms["add_comment_form"].submit();
//document.forms["add_comment_form"].reset();
document.getElementById("add_comment_form").submit();
//document.getElementById("add_comment_form").reset();
//document.getElementById("_comment").value = "";
//document.getElementById("_reviewer_name").value = "";
}
else {
//alert("Comment has not been submitted");
}
}
function clearForm()
{
document.getElementById("_comment").value = "";
document.getElementById("_reviewer_name").value = "";
}
function chg_row_color(index)
{
// reset row color
var table = document.getElementById("metadata_table");
var rows = table.getElementsByTagName("tr");
//if(index != null) {
for(var i = 0; i < rows.length; i++) {
if(i==(index+1)) {
rows[i].className = "selected_row";
}
else {
rows[i].className = "plain_row";
}
}
//}
}