-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtaskDetails.jsp
executable file
·177 lines (169 loc) · 4.89 KB
/
taskDetails.jsp
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
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="user" class="com.olam.blsheet.beans.User" scope="session" />
<%
System.out.println(user);
try {
if (!user.isAuthenticated()) {
response.sendRedirect(request.getContextPath());
}
} catch (IllegalArgumentException e) {
response.sendRedirect(request.getContextPath());
}
%>
<html>
<head>
<title>Simple jQuery and JSP example</title>
<link rel="stylesheet" href="resources/jQuery/theme/default/jquery-ui.css" />
<script src="resources/jQuery/jquery.js" type="text/javascript"></script>
<script src="resources/jQuery/jquery-ui.js" type="text/javascript"></script>
</head>
<script type="text/javascript">
$(document).ready(function() {
console.log("userId : ");
var userId = <%=user.getId()%>;
$("p").text(userId);
console.log(userId);
//alert(userId);
$.ajax({
type: "post",
url: "DetailServlet",
data: {userId: userId},
dataType: "json",
success: function(data) {
console.log("data.id");
console.log(data);
$('#name').val(data.name);
var userList = data.userList;
for(var i=0;i<userList.length;i++){
var user = userList[i];
console.log(user.name);
console.log(user.userId);
var $ctrl = $('<input/>').attr({ type: 'checkbox', name:'chk',value:user.userId}).addClass("chk")
$("#otherUsers").append($ctrl);
$("#otherUsers").append(user.name);
$("#otherUsers").append(" ");
//$('#checkboxes').append('<input type="checkbox" />)
}
}
}),
$(function() {
$("#datepicker").datepicker();
});
$('#submit').click(function() {
var name = $('#name').val();
if(name==null || name==""){
alert("Name is Empty.")
return false;
}
var date = $('#datepicker').val();
if(date==null || date==""){
alert("Date is Empty.")
return false;
}
var amount = $('#amount').val();
if(amount==null || amount==""){
alert("Amount cannot be Empty.")
return false;
}else{
console.log("----------"+amount);
console.log(isNaN(amount));
if(isNaN(amount)){
alert("Please provide some integer value(s).");
return false;
}
}
var description = $('#description').val();
if(description==null || description==""){
alert("Description is Empty.")
return false;
}
var selectedIds ="";
if($('input[name=chk]').is(':checked')){
var chkBox = document.getElementsByName("chk");
for(var i = 0;i<chkBox.length;i++){
if(chkBox[i].checked == true){
selectedIds = selectedIds+chkBox[i].value+",";
}
}
console.log(selectedIds);
}else{
alert("Please select atleast one member.");
return false;
}
console.log(name);
console.log(date);
console.log(amount);
console.log(description);
console.log(userId);
//alert(number);
$.ajax({
type: "post",
url: "DataServlet",
data: {userId : userId, name : name,amount : amount,description : description,date : date,selectedUsers : selectedIds},
dataType: "json",
success: function(data) {
if(data!=null){
alert("Your transaction successfully Completed....");
}
console.log("data");
console.log(data);
$('#datepicker').val("");
selectedIds = "";
$('#description').val("");
$('#amount').val("");
$('input:checkbox').removeAttr('checked');
}
});
});
$('#link').click(function(){
window.location.replace("<%=request.getContextPath()%>/viewStatus.jsp");
});
$('#signOut').click(function(){
window.location.replace("<%=request.getContextPath()%>");
});
});
</script>
<body>
<dir>
<table width="95%">
<tr>
<td align="left"></td>
<td align="right"><a href="#" style="text-decoration: none;"
id="link">Summary </a><a href="#"
style="text-decoration: none;" id="signOut">Sign Out</td>
</tr>
</table>
</dir>
<dir>
<h3 style="font-family: fantasy; color: red;">Enter the Details
of Purchase</h3>
<table>
<tr>
<td>User Name</td>
<td><input type="text" id="name" readonly="true" /></td>
</tr>
<tr>
<td>Purchase Date</td>
<td><input type="text" id="datepicker" /></td>
</tr>
<tr>
<td>Amount Spend</td>
<td><input type="text" id="amount" /></td>
</tr>
<tr>
<td>Description</td>
<td><textarea id="description" rows="4" cols="24"> </textarea></td>
</tr>
</table>
<div id=otherUsers>
<h4 style="color: blue;">Select Atleast One member</h4>
</div>
<div>
<input id="submit" type="button" value=" SUBMIT "
name="submit" />
</div>
</dir>
</body>
</html>