services_edit.html 17.9 KB
Newer Older
1
{% extends "edumanage/welcome.html"%}
2
3
4
5
6
7

{% block crumbs %}
	<li><a href="{% url manage %}">Home</a><span class="divider">/</span></li>
	<li><a href="{% url services %}">Services</a><span class="divider">/</span></li>
	<li class="active">Add-Edit</li>
{% endblock %}
8
{% block extrahead %}
9
<script type="text/javascript" src="/static/js/jquery.formset.js"></script>
10
11
 <script type="text/javascript"
      src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
12
13
14
15
16
      <script src="/static/js/jquery_csrf_protect.js" type="text/javascript"></script>

<script type="text/javascript">
		function gettext(msgid) { return msgid; }
		
17
18
19
20
 		var lat = 36.97;
 		var lng = 23.71;
 		var zoomLevel = 6;
 		{% if form.data.latitude or form.instance.latitude %}
21
22
 			var lat = "{% if form.data.latitude %}{{form.data.latitude}}{% else %}{{form.instance.latitude}}{% endif %}";
 			var lat = parseFloat(lat.replace(",","."));
23
24
 		{% endif %}
 		{% if form.data.longitude or form.instance.longitude %}
25
26
			var lng = "{% if form.data.longitude %}{{form.data.longitude}}{% else %}{{form.instance.longitude}}{% endif %}";
			var lng = parseFloat(lng.replace(",","."));
27
28
29
30
31
32
33
			var zoomLevel = 14;
			getOnce = true;
		{% endif %}
		var latlng = new google.maps.LatLng(lat,lng);
		var map = '';
		var marker = '';
		var getOnce = false;
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
		function setPositionValues(position) {
			$("#id_longitude").val('');
			$("#id_latitude").val('');
			$("#id_address_street").val('');
			$("#id_address_city").val('');

			$("#id_longitude").val(position.lng().toPrecision(8));
			$("#id_latitude").val(position.lat().toPrecision(8));
			codeLatLng(position);
		}

		function getPosition(position) {
			latlng = new google.maps.LatLng(position.coords.latitude,
					position.coords.longitude);
			getOnce = true;
			map.setCenter(latlng);
			map.setZoom(15);
			marker.setPosition(latlng);
			setPositionValues(latlng);
		}

		function moveMarker(position) {
			marker.setPosition(position);
			setPositionValues(position);
		}
		
		function geocode(position){
			geocoder
			.geocode(
					{
						'latLng' : position
					},
					function(results, status) {
						if (status == google.maps.GeocoderStatus.OK) {
							if (results.length >= 1) {
								for ( var ii = 0; ii < results[0].address_components.length; ii++) {
									var street_number = route = street = city = state = zipcode = country = formatted_address = '';
									var types = results[0].address_components[ii].types
											.join(",");
									if (types == "street_number") {
										addr.street_number = results[0].address_components[ii].long_name;
									}
									if (types == "route"
											|| types == "point_of_interest,establishment") {
										addr.route = results[0].address_components[ii].long_name;
									}
									if (types == "sublocality,political"
											|| types == "locality,political"
											|| types == "neighborhood,political"
											|| types == "political") {
										addr.city = (city == '' || types == "locality,political") ? results[0].address_components[ii].long_name
												: city;
									}
									if (types == "administrative_area_level_1,political") {
										addr.state = results[0].address_components[ii].short_name;
									}
									if (types == "postal_code"
											|| types == "postal_code_prefix,postal_code") {
										addr.zipcode = results[0].address_components[ii].long_name;
									}
									if (types == "country,political") {
										addr.country = results[0].address_components[ii].long_name;
									}
								}
							}

							if (addr.route && addr.city) {
								addr_field = addr.route;
								if (addr.street_number) {
									addr_field = addr.route + " "
											+ addr.street_number;
								}
								$("#id_address_street").val(addr_field);
								city_field = addr.city;
								if (addr.zipcode) {
									city_field = addr.city + ", "
											+ addr.zipcode;
								}
								$("#id_address_city").val(city_field);
							}
						}
					});
		}
		
		function codeLatLng(position) {
			addr = {};
			latlng = position;
			addr_num = '';
			addr_name = '';
			addr_city = '';
			addr_code = '';
			geocode(position)
		}
		function initialize() {
			image = new google.maps.MarkerImage('/static/img/edupin.png',
					// This marker is 29 pixels wide by 40 pixels tall.
					new google.maps.Size(29, 40),
					// The origin for this image is 0,0.
					new google.maps.Point(0,0),
					// The anchor for this image is the base of the flagpole at 18,42.
					new google.maps.Point(14, 40)
				);
			var styleArray = [
			                   {
			                       featureType: "all",
			                       stylers: [
			                         { saturation: -60 },
			                         {gamma: 1.00 }
			                       ]
			                     },{
			                       featureType: "poi.business",
			                       elementType: "labels",
			                       stylers: [
			                         { visibility: "off" }
			                       ]
			                     },
			                     { "featureType": "transit.line", "elementType": "geometry", "stylers": [ { "visibility": "off" } ] },
			                     { "featureType": "poi", "elementType": "all", "stylers": [ { "visibility": "off" } ] },
			                     {'featureType': "administrative.country",
			                     'elementType': "labels",
			                     'stylers': [
			                         { 'visibility': "off" }
			                     ]}

			                     
			                   ];
			geocoder = new google.maps.Geocoder();
			var mapOptions = {
				center : latlng,
				zoom : zoomLevel,
				styles: styleArray,
				 mapTypeId: google.maps.MapTypeId.ROADMAP,
				    mapTypeControlOptions: {
					      style: google.maps.MapTypeControlStyle.DEFAULT
					    },
					navigationControl: true,
					mapTypeControl: false,
			};
			map = new google.maps.Map(document.getElementById("map_canvas"),
					mapOptions);
			if (getOnce == false) {
				marker = new google.maps.Marker({
					position : latlng,
					draggable : true,
					'icon': image,
					animation : google.maps.Animation.DROP,

				});
				marker.setMap(map);
				setPositionValues(latlng);
			}
			google.maps.event.addListener(map, 'idle', function() {
				
			{% if not form.data.latitude  %}
				{% if not form.instance.latitude  %}
					if (navigator.geolocation && getOnce == false) {
						navigator.geolocation.getCurrentPosition(getPosition);
					}
				{% endif %}
			{% endif %}

			});

			google.maps.event.addListener(map, 'click', function(event) {
				moveMarker(event.latLng);
			});
			google.maps.event.addListener(marker, 'dragend', function(event) {
				setPositionValues(marker.getPosition());
			});

		}

		$(document).ready(function() {
			
			initialize();
			$("#updatemap").click(function(){
				latlng = new google.maps.LatLng($("#id_latitude").val(), $("#id_longitude").val());
				moveMarker(latlng);
				map.setCenter(latlng);
				$("#updatemap").addClass('disabled');
				$("#updatemap").attr('disabled', 'disabled');
				return false;
			});
			
			$("#myloc").click(function(){
				navigator.geolocation.getCurrentPosition(getPosition);
				return false;
			});
			
			$("#id_latitude").keypress(function(){
				$("#updatemap").removeClass('disabled');
				$("#updatemap").removeAttr('disabled');
			});
			$("#id_longitude").keypress(function(){
				$("#updatemap").removeClass('disabled');
				$("#updatemap").removeAttr('disabled');
			});
			
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
			// Initialize jquery formset
			
			 $('#urlsform tbody tr').formset({
            prefix: '{{urls_form.prefix}}',
            formCssClass: "dynamic-formset1",
            added: addButton,
        });
			
			 $('#locsform tbody tr').formset({
		            prefix: '{{services_form.prefix}}',
		            formCssClass: "dynamic-formset2",
		            added: addButton
		        });
			 
			 $(".delete-row").prepend('<i class="icon-remove-sign icon-white"></i> ').addClass('btn btn-small btn-warning');
			 $(".add-row").prepend('<i class="icon-plus-sign icon-white"></i> ').addClass('btn btn-small btn-info');
			 
			 $("#adduserSubmit").click(function(){
					$.ajax({
						url:"{% url adduser %}", 
						data:$("#add_user_form").serialize(),
						type: "POST",
						cache: false,
						success:function(data){
								try {
									value = data.value;
									text = data.text;
									if (typeof value === 'undefined' && typeof text === 'undefined'){
										$('#mymodalbody').html(data);	
									}
									else{
										$('#id_contact').append($("<option></option>").attr("value",value).text(text));
										$('#myModal').modal('hide')
									}
								}
								catch (exception) {
									$('#mymodalbody').html(data);
								}					
							}
							});
					return false;
				});
			 
			 $("#add_contact").click(function(){
				 $('#myModal').modal('show')
				 $.ajax({
						url:"{% url adduser %}",
						type: "GET",
						success: function(data){
							$('#mymodalbody').html(data);
							}
						});
			
				 return false;
			 });
			 
289
		});
290
291
292
293
294
295
		function addButton(row){
			$(row).find(".delete-row").prepend('<i class="icon-remove-sign icon-white"></i> ').addClass('btn btn-small btn-warning');
		}
		
		
		
296
297
298
299
	</script>


{% endblock %}
300
301
302
303
			
{% block homeactive %}{% endblock %}
{% block servicesactive %}class="active"{% endblock %}
{% block subcontent %}
304

305
306
<h4>Services Add/Edit</h4>
<hr>
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<form method="POST" class="form-horizontal">
	{% csrf_token %}
	{% if form.non_field_errors %}
	<p class="error">
		{{ form.non_field_errors}}
	</p>
	{% endif %}
	<div style="display: none">
		{{form.institutionid}}
	</div>
	<div class="control-group {% if form.longitude.errors or form.latitude.errors %} error {% endif %}">
		<label class="control-label" for="id_map_canvas"><b>Location</b></label>
		<div class="controls">
			<div id="map_canvas" style="width:100%; height:350px;"></div>
			<span class="help-block">{{ form.longitude.help_text }}</span>
		</div>
		<div class="controls">
			Lng:{{ form.longitude }} Lat:{{ form.latitude }}
			<button class="btn btn-info disabled" id="updatemap" disabled="disabled">
				Update Map
			</button>
			<button class="btn btn-info" id="myloc">
				Current Location
			</button>
			{% if form.longitude.errors %} <span class="help-inline"> {{ form.longitude.errors|join:", " }} </span>
			{% endif %}
			{% if form.latitude.errors %} <span class="help-inline"> {{ form.latitude.errors|join:", " }} </span>
			{% endif %} <span class="help-block">{{ form.longitude.help_text }}</span>
		</div>
	</div>
337
338

	<div class="control-group {% for err in services_form.errors %}{% if err|length > 0 %}error{% endif %}{% endfor %}{% if services_form.non_form_errors %}error{% endif %}">
339
340
341
		<label class="control-label" for="id_address_city"><b>loc_name</b></label>
		{{services_form.management_form}}
		<div class="controls">
342
343
344
345
346
347
348
349
350
351
352
353
		{% for err in services_form.errors %}{% if err|length > 0 %}<span class="help-inline"></span>{% endif %}{% endfor %}
		{% if services_form.non_form_errors %} <span class="help-inline"> {{ services_form.non_form_errors|join:", "}}</span>{% endif %}
			<table id="locsform"><thead><tr><td>Name</td><td>language</td></tr></thead><tbody>
		{% for formset_s in services_form.forms %}
		{{ formset_s.id }}
		
		
			<tr id="{{ formset_s.prefix }}-row">
			<td> {% if formset_s.instance.pk %}{{ formset_s.DELETE }}{% endif %}{{ formset_s.name }}{% if formset_s.name.errors %}<br><div class="help-inline"> {{ formset_s.name.errors|join:", " }} </div>{% endif %}</td> 
             <td>{{formset_s.lang}}{% if formset_s.lang.errors %}<br><p class="help-inline"> {{ formset_s.lang.errors|join:", " }} </p>{% endif %}</td>
             
		</tr>
354
		{% endfor %}
355
356
		</tbody></table>
		</div>
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
	</div>
	<div class="control-group {% if form.address_street.errors %} error {% endif %}">
		<label class="control-label" for="id_address_street"><b>Address Street</b></label>
		<div class="controls">
			{{ form.address_street }}
			{% if form.address_street.errors %} <span class="help-inline"> {{ form.address_street.errors|join:", " }} </span>
			{% endif %} <span class="help-block"> {{ form.address_street.help_text }}</span>
		</div>
	</div>
	<div class="control-group {% if form.address_city.errors %} error {% endif %}">
		<label class="control-label" for="id_address_city"><b>Address City</b></label>
		<div class="controls">
			{{ form.address_city }}
			{% if form.address_city.errors %} <span class="help-inline"> {{ form.address_city.errors|join:", " }} </span>
			{% endif %} <span class="help-block"> {{ form.address_city.help_text }}</span>
		</div>
	</div>
	<div class="control-group {% if form.SSID.errors %} error {% endif %}">
		<label class="control-label" for="id_url"><b>SSID</b></label>
		<div class="controls">
			{{ form.SSID }}
			{% if form.SSID.errors %} <span class="help-inline"> {{ form.SSID.errors|join:", " }} </span>
			{% endif %} <span class="help-block"> {{ form.SSID.help_text }}</span>
		</div>
	</div>
	<div class="control-group {% if form.contact.errors %} error {% endif %}">
383
		<label class="control-label" for="id_contact"><b>Contact</b></label>
384
		<div class="controls">
385
			{{ form.contact }} <button class="btn btn-small btn-info" id="add_contact"><i class="icon-plus-sign icon-white"></i>Add...</button>
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
			{% if form.contact.errors %} <span class="help-inline"> {{ form.contact.errors|join:", " }} </span>
			{% endif %} <span class="help-block"> {{ form.contact.help_text }}</span>
		</div>
	</div>
	<div class="control-group {% if form.enc_level.errors %} error {% endif %}">
		<label class="control-label" for="id_oper_name"><b>enc_level</b></label>
		<div class="controls">
			{{ form.enc_level }}
			{% if form.enc_level.errors %} <span class="help-inline"> {{ form.enc_level.errors|join:", " }} </span>
			{% endif %} <span class="help-block"> {{ form.enc_level.help_text }}</span>
		</div>
	</div>
	<div class="control-group {% if form.port_restrict.errors %} error {% endif %}">
		<label class="control-label" for="id_number_user">port_restrict</label>
		<div class="controls">
			{{ form.port_restrict }}
			{% if form.port_restrict.errors %} <span class="help-inline"> {{ form.port_restrict.errors|join:", " }} </span>
			{% endif %} <span class="help-block"> {{ form.port_restrict.help_text }}</span>
		</div>
	</div>
	<div class="control-group {% if form.transp_proxy.errors %} error {% endif %}">
		<label class="control-label" for="id_number_id">transp_proxy</label>
		<div class="controls">
			{{ form.transp_proxy }}
			{% if form.transp_proxy.errors %} <span class="help-inline"> {{ form.transp_proxy.errors|join:", " }} </span>
			{% endif %} <span class="help-block"> {{ form.transp_proxy.help_text }}</span>
		</div>
	</div>
	<div class="control-group {% if form.IPv6.errors %} error {% endif %}">
		<label class="control-label" for="id_number_id">IPv6</label>
		<div class="controls">
			{{ form.IPv6 }}
			{% if form.IPv6.errors %} <span class="help-inline"> {{ form.IPv6.errors|join:", " }} </span>
			{% endif %} <span class="help-block"> {{ form.IPv6.help_text }}</span>
		</div>
	</div>
	<div class="control-group {% if form.NAT.errors %} error {% endif %}">
		<label class="control-label" for="id_number_id">NAT</label>
		<div class="controls">
			{{ form.NAT }}
			{% if form.NAT.errors %} <span class="help-inline"> {{ form.NAT.errors|join:", " }} </span>
			{% endif %} <span class="help-block"> {{ form.NAT.help_text }}</span>
		</div>
	</div>
	<div class="control-group {% if form.AP_no.errors %} error {% endif %}">
		<label class="control-label" for="id_number_id"><b>AP_no</b></label>
		<div class="controls">
			{{ form.AP_no }}
			{% if form.AP_no.errors %} <span class="help-inline"> {{ form.AP_no.errors|join:", " }} </span>
			{% endif %} <span class="help-block"> {{ form.AP_no.help_text }}</span>
		</div>
	</div>
	<div class="control-group {% if form.wired.errors %} error {% endif %}">
		<label class="control-label" for="id_number_id">wired</label>
		<div class="controls">
			{{ form.wired }}
			{% if form.wired.errors %} <span class="help-inline"> {{ form.wired.errors|join:", " }} </span>
			{% endif %} <span class="help-block"> {{ form.wired.help_text }}</span>
		</div>
	</div>
446
447
448
	<div class="control-group {% for err in urls_form.errors %}{% if err|length > 0 %}error{% endif %}{% endfor %}{% if urls_form.non_form_errors %}error{% endif %}">
		<label class="control-label" for="id_urls">Urls</label>
		{{urls_form.management_form}}
449
		<div class="controls">
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
		{% for err in urls_form.errors %}{% if err|length > 0 %}<span class="help-inline">{{err}}</span>{% endif %}{% endfor %}
		{% if urls_form.non_form_errors %} <span class="help-inline"> {{ urls_form.non_form_errors|join:", "}}</span>{% endif %}
			<table id="urlsform"><thead><tr><td>url</td><td>type</td><td>language</td></tr></thead><tbody>
		{% for formset in urls_form.forms %}
		{{ formset.id }}
		
		
			<tr id="{{ formset.prefix }}-row">
			<td> {% if formset.instance.pk %}{{ formset.DELETE }}{% endif %}{{ formset.url }}{% if formset.url.errors %}<br><div class="help-inline"> {{ formset.url.errors|join:", " }} </div>{% endif %}</td> 
             <td>{{formset.urltype}}{% if formset.urltype.errors %}<br><p class="help-inline"> {{ formset.urltype.errors|join:", " }} </p>{% endif %}</td>
             <td>{{formset.lang}}{% if formset.lang.errors %}<br><p class="help-inline"> {{ formset.lang.errors|join:", " }} </p>{% endif %}</td>
             
		</tr>
		{% endfor %}
		</tbody></table>
465
466
467
468
469
470
471
472
473
		</div>
	</div>
	<div class="control-group">
		<div class="controls">
			<button type="submit" id="applybutton" value="Apply" class="btn btn-large btn-primary"/>
			Apply</button>
		</div>
	</div>
</form>
474

475
476
477
478
479
480
481
482
483
484
485
486
487
488
<div class="modal hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Add User</h3>
</div>
<div class="modal-body" id="mymodalbody">

</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<a class="btn btn-primary" id="adduserSubmit" href="#">Save changes</a>
</div>
</div>

489
{% endblock %}