Subversion Repository Public Repository

gpstest

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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<%@ 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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<%
	String email = session.getAttribute("email").toString();
	String password = session.getAttribute("password").toString();
%>
<title>Nrusingh GPS</title>
<link href="css/main.css" rel="stylesheet" />
<link href="css/topmenu.css" rel="stylesheet" />
<link href="css/tablestyle.css" rel="stylesheet" />
<link href="css/mymodal.css" rel="stylesheet" />

<script src="js/jquery.min.js"></script>
<script type="text/javascript">
	$(function(){
		var flag = 0;
		var curr_geofence_id = '';
		$('#div_loader').show();
		var email = '<%= email%>';
		var password = '<%= password%>';
		list_all_geofence();
		
		//$('#screen, #modal button').click(function(){
		$('#modal button').click(function(){
			flag = 0;
			curr_geofence_id = '';
			$('#screen, #modal').hide('slow');
		});
		
		$(document).on("click", "#btn_submit", function(event) {
			//alert('flag: '+flag);
			
			// flag = 1 : create user, flag = 2 : update user
			if(flag == 1){
				create_geofence();
				$('#screen, #modal').hide('slow');
				list_all_geofence();				
			}else if(flag == 2){
				alert(curr_geofence_id)
				update_geofence(curr_geofence_id);	
				$('#screen, #modal').hide('slow');
				list_all_geofence();
			}
		});
		
		$(document).on("click", "#btn_create_geofence", function(event) {
			flag = 1;
			$('#txt_geofence_name').val('');
			$('#txt_geofence_desc').val('');
			$('#txt_geofence_area').val('');
			$('#screen, #modal').show('slow');
		});
		
		$(document).on("click", ".btn_update_geofence", function(event) {
			flag = 2;
			var btn_id = $(this).attr('id');
			var id = btn_id.replace('btn_update_geofence','');
			curr_geofence_id = id;
			
			$('#txt_geofence_name').val('');
			$('#txt_geofence_desc').val('');
			$('#txt_geofence_area').val('');
			$('#screen, #modal').show('slow');
		});
		
		$(document).on("click", ".btn_delete_geofence", function(event) {
			if (confirm("Are you sure, delete this geofence?")) {
				$('#div_user_list').hide();
				$('#div_loader').show();
				var btn_id = $(this).attr('id');
				var id = btn_id.replace('btn_delete_geofence','');
				delete_geofence(id);				
			}else{
				
			}	
		});
		
		function create_geofence(){
			url = "http://23.92.61.79:8082/api/geofences/";
			var geofence_name= $('#txt_geofence_name').val();
			var geofence_desc = $('#txt_geofence_desc').val();
			var geofence_area = $('#txt_geofence_area').val();
			if(
					geofence_name== undefined  || geofence_name.trim().length<= 0 ||  
					geofence_desc == undefined || geofence_desc.trim().length <= 0 ||  
					geofence_area == undefined || geofence_area.trim().length <= 0
			){
				$('#div_response').html("");
				$('#div_response').html("Invalid inputs");
			}else{
				$.ajax({
					async:false,
					cache:false,
					dataType:"json",
					type: "post",  
					url: url,
					headers: {
						"Accept": "application/json",         
						"Content-Type": "application/json",
						"Authorization": "Basic " + btoa(email + ":" + password)
					},
					data:JSON.stringify({name: geofence_name,description:geofence_desc,area:geofence_area}),
					success: function (response) {
						console.log('Success: '+JSON.stringify(response));
						$('#div_response').html("");
						$('#div_response').html("Geofence created successfully...");
					},
					error: function (response) {
						console.log('Error: '+JSON.stringify(response));
						$('#div_response').html("");
						$('#div_response').html("There has been an error.");
					}
				});
			}
		}
		
		function list_all_geofence(){
			var url = "http://23.92.61.79:8082/api/geofences/";
			$.ajax({
				async:false,
				cache:false,
				dataType:"json",
				type: 'get',
				url: url,
				headers: {
					"Accept": "application/json",         
					"Content-Type": "application/json",
					"Authorization": "Basic " + btoa(email + ":" + password)
				},			
				success: function (response) {
					console.log('Success: '+JSON.stringify(response));
					var usertable = '<table id="mytable">';
					usertable += '<tr>';
					usertable += '<th>Name</th>';
					usertable += '<th>Description</th>';
					usertable += '<th>Area</th>';
					usertable += '<th>Attributes</th>';
					usertable += '<th>Action</th>';
					usertable += '</tr>';
					$.each(response, function(k,v){
						var id = v.id;
						var name = v.name;
						var description = v.description;
						var area = v.area;
						var attributes = v.attributes;
						
						usertable += '<tr>';
						usertable += '<td>'+id+'</td>';
						usertable += '<td>'+name+'</td>';
						usertable += '<td>'+description+'</td>';
						usertable += '<td>'+area+'</td>';
						usertable += '<td><input type="button" id="btn_update_geofence'+id+'" class="btn_update_geofence" value="Update" /><input type="button" id="btn_delete_geofence'+id+'" class="btn_delete_geofence" value="Delete" style="margin-left: 20px;" /></td>';
						usertable += '</tr>';
					});
					usertable += '</table>';
					$('#div_loader').hide();
					$('#div_user_list').html('');
					$('#div_user_list').html(usertable);
				},
				error: function (response) {
					$('#div_loader').hide();
					console.log('Error: '+JSON.stringify(response));
				}
			});
		}
		
		function delete_geofence(id){
			var url = "http://23.92.61.79:8082/api/geofences/"+parseInt(id);
			$.ajax({
				async:false,
				cache:false,
				dataType:"json",
				type: 'delete',
				url: url,
				headers: {
					"Accept": "application/json",         
					"Content-Type": "application/json",
					"Authorization": "Basic " + btoa(email + ":" + password)
				},			
				success: function (response) {
					console.log('Success: '+JSON.stringify(response));
					list_all_geofence();
					$('#div_user_list').show();
					$('#div_loader').hide();
				},
				error: function (response) {
					console.log('Error: '+JSON.stringify(response));
					list_all_geofence();
					$('#div_user_list').show();
					$('#div_loader').hide();
				}
			});
		}
		
		function update_geofence(id){
			var url = "http://23.92.61.79:8082/api/geofences/"+id;
			var geofence_name= $('#txt_geofence_name').val();
			var geofence_desc = $('#txt_geofence_desc').val();
			var geofence_area = $('#txt_geofence_area').val();
			if(
					geofence_name== undefined  || geofence_name.trim().length <= 0 ||  
					geofence_desc == undefined || geofence_desc.trim().length <= 0 ||  
					geofence_area == undefined || geofence_area.trim().length <= 0
			){
				$('#div_response').html("");
				$('#div_response').html("Invalid inputs");
			}else{
				$.ajax({
					async:false,
					cache:false,
					dataType:"json",
					type: 'put',
					url: url,
					headers: {
						"Accept": "application/json",         
						"Content-Type": "application/json",
						"Authorization": "Basic " + btoa(email + ":" + password)
					},		
					data:JSON.stringify({id:id,name: geofence_name,description:geofence_desc,area:geofence_area}),
					success: function (response) {
						console.log('Success: '+JSON.stringify(response));
						$('#div_loader').hide();
						list_all_geofence();
					},
					error: function (response) {
						console.log('Error: '+JSON.stringify(response));
						$('#div_loader').hide();
						list_all_geofence();
					}
				});
			}
		}
	});
</script>

</head>
<body>
	<div id="screen"></div>
	<div class="container">
		<!-- top panel -->
		<header>
		<div>
			<img src="images/logo1.png" style="width: 100px;">
		</div>
		<div style="margin-top: -95px; margin-left: 180px;">
			<h1>
				<a href="login" style="text-decoration: none; color: white;">NRUSiNGH
					GPS TRACKER</a>
			</h1>
		</div>

		<div style="float: right; margin-top: -40px;">
			<span style="font-weight: 900; text-transform: uppercase; vertical-align: 7px;"><%=session.getAttribute("email")%></span>
			<a href="logout"><img src="images/logout.png" alt="logout" style="width: 22px; margin-right: 15px;"/></a>
		</div>
		<jsp:include page="menu.jsp" /> </header>
		<br>
		<!-- top panel ends -->

		<!-- left panel -->
		<nav> </nav>
		<!-- left panel ends -->

		<!-- right panel -->
		<article> <!-- <p><a href="map.jsp">Map</a></p> --> 
		<!-- <div id="div_map">
			<div id="loader_map" style="disply: none;">
				<img id="loader_img_map" alt="Loding ..." src="images/loader.gif" />
			</div>
		</div> -->
			<div>
				<div id="div_loader" style="disply: none;">
					<img id="img_loader" alt="Loding ..." src="images/loader.gif" />
				</div>
				<div><input type="button" id="btn_create_geofence" value="Create Geofence" /></div>
				<div id="div_user_list" style="height: 400px; overflow: auto;"></div>
				
				 
			</div> 
		</article>
		<!-- right panel ends -->

		<!-- buttom panel -->
		<footer>
		<div style="text-align: center">Copyright &copy; Nrusingha nath
			Nayak</div>
		</footer>
		<!-- buttom panel ends -->
	</div>
	
				<!-- modal -->
				 <div id="modal">
				 	<button style="float: right;margin-top: -10px;margin-right: -20px; background-color: #e26666; color: white; border: none; padding: 2px 10px 5px;">x</button>
					<table>
						<tr>
							<td>Name</td>
							<td><div><input type="text" id="txt_geofence_name" name="txt_geofence_name" placeholder="Geofence Name" class="txt" /></div></td>
						</tr>
						<tr>
							<td>Desc.</td>
							<td><div><input type="text" id="txt_geofence_desc" name="txt_geofence_desc" placeholder="Geofence Desc" class="txt" /></div></td>
						</tr>
						<tr>
							<td>Area</td>
							<td><div><input type="text" id="txt_geofence_area" name="txt_geofence_area" placeholder="Geofence Area" class="txt" /></div></td>
						</tr>
						<tr>
							<td>Attributes</td>
							<td><div><input type="text" id="txt_geofence_attr" name="txt_geofence_attr" placeholder="Geofence Attr" class="txt" /></div></td>
						</tr>
						<tr>
							<td></td>
							<td><div class="box-btn"><input type="button" id="btn_submit" name="btn_submit" value="Submit" class="btn" style="float: right;" /></div></td>
						</tr>
					</table>
				 </div>
				 <!-- modal ends -->
</body>
</html>

Commits for gpstest/WebContent/_geofence.jsp

Diff revisions: vs.
Revision Author Commited Message
1 lingaraj picture lingaraj Sat 24 Nov, 2018 13:04:59 +0000