-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
202 lines (149 loc) · 5.65 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery Mobile: Demos and Documentation</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<link rel="stylesheet" href="jqm-docs.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="jqm-docs.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyAIBdEo66QYkdkD0Pgbob70Jxelq2scm88&sensor=false"> </script>
<script src="libs/jquery.ui.map.full.min.js" type="text/javascript"></script>
<script type="text/javascript">
var gm = null;
var latitude = 0;
var longitude = 0;
$(document).bind('pageinit', function() {
initiate_geolocation();
$('#askForHosting').submit(function() {
// Get the vars
var name = $("input#askName").val();
var email = $("input#askEmail").val();
var tel = $("input#askTel").val();
// POST the data to server
$.ajax({
type: "POST",
url: "/hosting/people",
data: { name: name, email: email, cellNumber: tel, latitude: latitude, longitude: longitude}
}).done(function( msg ) {
alert( "Data Saved: " + msg );
// Hide loading
$.mobile.hidePageLoadingMsg();
}).fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus );
// Hide loading
$.mobile.hidePageLoadingMsg();
});
// Show loading
$.mobile.showPageLoadingMsg();
// Close the popup
$( "#popupAskHosting" ).popup( "close" );
// Don't submit the form, we already submited it
return false;
});
$('#offerHosting').click(function() {
addMarkers();
});
});
function initiate_geolocation() {
navigator.geolocation.getCurrentPosition(initializeMap);
}
function initializeMap(position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
var myCenter = new google.maps.LatLng(latitude, longitude);
var myMarker = new google.maps.Marker({
position:myCenter,
bounds: true,
animation:google.maps.Animation.BOUNCE
});
var mapProp = {
center: myCenter,
zoom:8,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
gm = $('#gmap');
gm.gmap(mapProp);
gm.gmap('addMarker', myMarker);
// addMarkers();
}
function addMarkers() {
// Check if map loaded
if (gm === null) {
return;
}
$.getJSON( '/rest/hosting/people', function(data) {
$.each( data, function(i, m) {
gm.gmap('addMarker', { position: new google.maps.LatLng(m.latitude, m.longitude), bounds:true } )
.click(function() {
gm.gmap('openInfoWindow', { 'content': getPersonInfoHtml(m)}, this);
});
});
});
}
function getPersonInfoHtml(person) {
return '<h3>'+person.name+'</h3>Phone: <a href="tel:'+person.cellNumber+'">'+person.cellNumber+'</a><br><button onclick="offerHostingTo(\''+person.id+'\')">Offer hosting</button>';
}
function offerHostingTo(personId) {
// DELETE the data to server
$.ajax({
type: "DELETE",
url: "/hosting/people",
data: { id: personId}
}).done(function( msg ) {
alert( "Offered hosting: " + msg );
// Hide loading
$.mobile.hidePageLoadingMsg();
}).fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus );
// Hide loading
$.mobile.hidePageLoadingMsg();
});
// Show loading
$.mobile.showPageLoadingMsg();
}
</script>
</head>
<body>
<div data-role="page" class="type-home">
<div data-role="popup" id="popupAskHosting" data-overlay-theme="a" data-theme="c" style="max-width:400px;" class="ui-corner-all">
<form id="askForHosting">
<div style="padding:10px 20px;">
<h3>Please provide a name, email or/and your telephone number</h3>
<label for="name" class="ui-hidden-accessible">Name:</label>
<input type="text" name="name" id="askName" value="" placeholder="your name" data-theme="a" />
<label for="email" class="ui-hidden-accessible">Email:</label>
<input type="email" name="email" id="askEmail" value="" placeholder="your email" data-theme="a" />
<label for="pw" class="ui-hidden-accessible">Phone number:</label>
<input type="tel" name="tel" id="askTel" value="" placeholder="your phone number" data-theme="a" />
<button type="submit" data-theme="b">Find a place</button>
<button type="cancel" data-theme="c">Cancel</button>
</div>
</form>
</div>
<div data-role="content">
<div class="content-secondary">
<div id="jqm-homeheader">
<h1 id="jqm-logo"><img src="images/logo.png" alt="jQuery Mobile Framework" /></h1>
<p>Helping people in case of emergencies.</p>
</div>
<p class="intro"><strong>Welcome.</strong> In case of emergency remember to stay calm. If you need or can provide help please select the appropriate action.</p>
<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="f">
<li data-role="list-divider">In case of emergency</li>
<li><a href="#popupAskHosting" data-rel="popup">I need a place to stay</a></li>
<!-- <li><a href="docs/about/intro.html">I need a place to stay</a></li> -->
<li><a href="#" id="offerHosting">I can host</a></li>
</ul>
</div><!--/content-primary-->
<div class="content-primary">
<div id="gmap" style="width:500px;height:380px;"></div>
</div>
</div>
<div data-role="footer" class="footer-docs" data-theme="c">
<p>© ogeo team. Codemotion 2012</p>
</div>
</div>
</body>
</html>