services_edit.html 19.8 KB
Newer Older
1 2 3
{% extends "edumanage/welcome.html"%}
{% load i18n %}
{% load tolocale %}
4
{% load staticfiles %}
Kroustouris Stauros's avatar
Kroustouris Stauros committed
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

{% block homeactive %}{% endblock %}
{% block servicesactive %}class="active"{% endblock %}


{% block management_content %}
<h4>
	{% if edit %}
		{% tolocale form.instance LANGUAGE_CODE %} ({% trans "edit" %})
	{% else %}
		{% trans "Add Location" %}
	{% endif %}
</h4>
<hr>
<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="form-group {% if form.longitude.errors or form.latitude.errors %} error {% endif %}">
		<label for="id_map_canvas">
			<b>{% trans "Location" %}</b>
		</label>
		<div>
			<div id="map_canvas" style="width:100%; height:350px;"></div>
			<span class="help-block">{{ form.longitude.help_text }}</span>
		</div>
		<div class="col-md-6" >
			<label for="">{% trans "Search location" %}</label>: <input type="text" value="" id="searchbox" style=" width: 300px;">
		</div>
		<div class="col-md-6">

			 <div class="form-group">
			 	<label for="">Lat</label> {{ form.latitude }} <label for="">Lng</label> {{ form.longitude }}
			 				<button class="btn btn-info disabled" id="updatemap" disabled="disabled">
			 					{% trans "Update Map" %}
			 				</button>
			 				<button class="btn btn-info" id="myloc">
			 					{% trans "Current Location" %}
			 				</button>
50
			 				{% if form.longitude.errors %} <div class="alert-danger"> {{ form.longitude.errors|join:", " }} </div>
Kroustouris Stauros's avatar
Kroustouris Stauros committed
51
			 				{% endif %}
52
			 				{% if form.latitude.errors %} <div class="alert-danger"> {{ form.latitude.errors|join:", " }} </div>
Kroustouris Stauros's avatar
Kroustouris Stauros committed
53 54 55 56 57 58 59 60 61 62 63 64
			 				{% endif %} <span class="help-block">{{ form.longitude.help_text }}</span>
			 </div>
		</div>
	</div>


	<div class="col-md-6">
		<div class="form-group {% for err in services_form.errors %}{% if err|length > 0 %}error{% endif %}{% endfor %}{% if services_form.non_form_errors %}error{% endif %}">
			<label for="id_address_city">{% trans "Location Name" %}</label>
			{{services_form.management_form}}
			<div class="controls">
			{% for err in services_form.errors %}{% if err|length > 0 %}<span class="help-inline"></span>{% endif %}{% endfor %}
65
			{% if services_form.non_form_errors %} <div class="alert-danger"> {{ services_form.non_form_errors|join:", "}}</div>{% endif %}
Kroustouris Stauros's avatar
Kroustouris Stauros committed
66 67 68 69 70 71
				<table id="locsform"><thead><tr><td>{% trans "Name" %}</td><td>{% trans "Language" %}</td></tr></thead><tbody>
			{% for formset_s in services_form.forms %}
			{{ formset_s.id }}


				<tr id="{{ formset_s.prefix }}-row">
72
				<td> {% if formset_s.instance.pk %}{{ formset_s.DELETE }}{% endif %}{{ formset_s.name }}{% if formset_s.name.errors %}<br><div class="alert-danger">{{ formset_s.name.errors|join:", " }} </div>{% endif %}</td>
Kroustouris Stauros's avatar
Kroustouris Stauros committed
73 74 75 76 77 78 79 80 81 82 83 84 85
		             <td>{{formset_s.lang}}{% if formset_s.lang.errors %}<br><p class="help-inline"> {{ formset_s.lang.errors|join:", " }} </p>{% endif %}</td>

			</tr>
			{% endfor %}
			</tbody></table>
			</div>
		</div>
	</div>
	<div class="col-md-6">
		<div class="form-group {% if form.address_street.errors %} error {% endif %}">
			<label for="id_address_street">{% trans "Address Street" %}</label>
			<div class="controls">
				{{ form.address_street }}
86
				{% if form.address_street.errors %} <div class="alert-danger"> {{ form.address_street.errors|join:", " }} </div>
Kroustouris Stauros's avatar
Kroustouris Stauros committed
87 88 89 90 91 92 93 94 95
				{% endif %} <span class="help-block"> {{ form.address_street.help_text }}</span>
			</div>
		</div>
	</div>
	<div class="col-md-6">
		<div class="form-group {% if form.address_city.errors %} error {% endif %}">
			<label for="id_address_city"><b>{% trans "Address City" %}</b></label>
			<div class="controls">
				{{ form.address_city }}
96
				{% if form.address_city.errors %} <div class="alert-danger"> {{ form.address_city.errors|join:", " }} </div>
Kroustouris Stauros's avatar
Kroustouris Stauros committed
97 98 99 100 101 102 103 104 105
				{% endif %} <span class="help-block"> {{ form.address_city.help_text }}</span>
			</div>
		</div>
	</div>
	<div class="col-md-6">
		<div class="form-group {% if form.SSID.errors %} error {% endif %}">
			<label for="id_url"><b>SSID</b></label>
			<div class="controls">
				{{ form.SSID }}
106
				{% if form.SSID.errors %}<div class="alert-danger"> {{ form.SSID.errors|join:", " }} </div>
Kroustouris Stauros's avatar
Kroustouris Stauros committed
107 108 109 110 111 112 113 114 115
				{% endif %} <span class="help-block"> {{ form.SSID.help_text }}</span>
			</div>
		</div>
	</div>
	<div class="col-md-6">
		<div class="form-group {% if form.contact.errors %} error {% endif %}">
			<label for="id_contact">{% trans "Contacts" %}</label>
			<div class="controls">
				{{ form.contact }} <button class="btn btn-small btn-info" id="add_contact"><i class="icon-plus-sign icon-white"></i>Add...</button>
116
				{% if form.contact.errors %} <div class="alert-danger"> {{ form.contact.errors|join:", " }} </div>
Kroustouris Stauros's avatar
Kroustouris Stauros committed
117 118 119 120 121 122 123 124 125
				{% endif %} <span class="help-block"> {{ form.contact.help_text }}</span>
			</div>
		</div>
	</div>
	<div class="col-md-6">
		<div class="form-group {% if form.enc_level.errors %} error {% endif %}">
			<label for="id_oper_name">{% trans "Encryption Level" %}</label>
			<div class="controls">
				{{ form.enc_level }}
126
				{% if form.enc_level.errors %} <div class="alert-danger"> {{ form.enc_level.errors|join:", " }} </div>
Kroustouris Stauros's avatar
Kroustouris Stauros committed
127 128 129 130 131 132 133 134 135
				{% endif %} <span class="help-block"> {{ form.enc_level.help_text }}</span>
			</div>
		</div>
	</div>
	<div class="col-md-6">
		<div class="form-group {% if form.port_restrict.errors %} error {% endif %}">
			<label for="id_number_user">{% trans "Port Restrict" %}</label>
			<div class="controls">
				{{ form.port_restrict }}
136
				{% if form.port_restrict.errors %} <div class="alert-danger"> {{ form.port_restrict.errors|join:", " }} </div>
Kroustouris Stauros's avatar
Kroustouris Stauros committed
137 138 139 140 141 142 143 144 145
				{% endif %} <span class="help-block"> {{ form.port_restrict.help_text }}</span>
			</div>
		</div>
	</div>
	<div class="col-md-6">
		<div class="form-group {% if form.transp_proxy.errors %} error {% endif %}">
			<label for="id_number_id">{% trans "Transparent Proxy" %}</label>
			<div class="controls">
				{{ form.transp_proxy }}
146
				{% if form.transp_proxy.errors %} <div class="alert-danger"> {{ form.transp_proxy.errors|join:", " }} </div>
Kroustouris Stauros's avatar
Kroustouris Stauros committed
147 148 149 150 151 152 153 154 155
				{% endif %} <span class="help-block"> {{ form.transp_proxy.help_text }}</span>
			</div>
		</div>
	</div>
	<div class="col-md-6">
		<div class="form-group {% if form.IPv6.errors %} error {% endif %}">
			<label for="id_number_id">IPv6</label>
			<div class="controls">
				{{ form.IPv6 }}
156
				{% if form.IPv6.errors %} <div class="alert-danger"> {{ form.IPv6.errors|join:", " }} </div>
Kroustouris Stauros's avatar
Kroustouris Stauros committed
157 158 159 160 161 162 163 164 165
				{% endif %} <span class="help-block"> {{ form.IPv6.help_text }}</span>
			</div>
		</div>
	</div>
	<div class="col-md-6">
		<div class="form-group {% if form.NAT.errors %} error {% endif %}">
			<label for="id_number_id">NAT</label>
			<div class="controls">
				{{ form.NAT }}
166
				{% if form.NAT.errors %} <div class="alert-danger"> {{ form.NAT.errors|join:", " }} </div>
Kroustouris Stauros's avatar
Kroustouris Stauros committed
167 168 169 170 171 172 173 174 175
				{% endif %} <span class="help-block"> {{ form.NAT.help_text }}</span>
			</div>
		</div>
	</div>
	<div class="col-md-6">
		<div class="form-group {% if form.AP_no.errors %} error {% endif %}">
			<label for="id_number_id"><b>{% trans "AP number" %}</b></label>
			<div class="controls">
				{{ form.AP_no }}
176
				{% if form.AP_no.errors %} <div class="alert-danger"> {{ form.AP_no.errors|join:", " }} </div>
Kroustouris Stauros's avatar
Kroustouris Stauros committed
177 178 179 180 181 182 183 184 185
				{% endif %} <span class="help-block"> {{ form.AP_no.help_text }}</span>
			</div>
		</div>
	</div>
	<div class="col-md-6">
		<div class="form-group {% if form.wired.errors %} error {% endif %}">
			<label for="id_number_id">{% trans "Wired" %}</label>
			<div class="controls">
				{{ form.wired }}
186
				{% if form.wired.errors %} <div class="alert-danger"> {{ form.wired.errors|join:", " }} </div>
Kroustouris Stauros's avatar
Kroustouris Stauros committed
187 188 189 190 191 192 193 194 195
				{% endif %} <span class="help-block"> {{ form.wired.help_text }}</span>
			</div>
		</div>
	</div>
	<div class="col-md-6">
		<div class="form-group {% for err in urls_form.errors %}{% if err|length > 0 %}error{% endif %}{% endfor %}{% if urls_form.non_form_errors %}error{% endif %}">
			<label for="id_urls">{% trans "Urls" %}</label>
			{{urls_form.management_form}}
			<div class="controls">
196 197
			{% for err in urls_form.errors %}{% if err|length > 0 %}<div class="alert-danger">{{err}}</div>{% endif %}{% endfor %}
			{% if urls_form.non_form_errors %} <div class="alert-danger"> {{ urls_form.non_form_errors|join:", "}}</div>{% endif %}
Kroustouris Stauros's avatar
Kroustouris Stauros committed
198 199 200 201 202 203 204 205 206 207 208 209 210
				<table id="urlsform">
					<thead>
						<tr>
							<td>{% trans "url" %}</td>
							<td>{% trans "type" %}</td>
							<td>{% trans "language" %}</td>
						</tr>
					</thead>
					<tbody>
					{% for formset in urls_form.forms %}
						{{ formset.id }}
						<tr id="{{ formset.prefix }}-row">
							<td>
211
								{% if formset.instance.pk %}{{ formset.DELETE }}{% endif %}{{ formset.url }}{% if formset.url.errors %}<br><div class="alert-danger"> {{ formset.url.errors|join:", " }} </div>{% endif %}
Kroustouris Stauros's avatar
Kroustouris Stauros committed
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
							</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>
			</div>
		</div>
	</div>
	<div class="form-group">
		<div class="controls">
			<button type="submit" id="applybutton" value="Apply" class="btn btn-primary"/>
			{% trans "Apply" %}</button>
		</div>
	</div>
</form>

<div class="modal" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
    	<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h3 id="myModalLabel">{% trans "Add User" %}</h3>
			</div>
			<div class="modal-body" id="mymodalbody">

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

252
{% endblock %}
253

Kroustouris Stauros's avatar
Kroustouris Stauros committed
254 255

{% block extrajs %}
256
<script type="text/javascript" src="{% static 'js/jquery.formset.js' %}"></script>
257
<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?v=3.exp{% if GOOGLE_MAPS_API_KEY %}&amp;key={{ GOOGLE_MAPS_API_KEY }}{% endif %}&amp;language=en&amp;libraries=places"></script>
258
<script src="{% static 'js/jquery_csrf_protect.js' %}" type="text/javascript"></script>
259 260 261

<script type="text/javascript">
		function gettext(msgid) { return msgid; }
262

263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
		var lat = "{{MAP_CENTER.0}}";
		var lat = parseFloat(lat.replace(",","."));
		var lng = "{{MAP_CENTER.1}}";
		var lng = parseFloat(lng.replace(",","."));
 		var zoomLevel = 6;
 		{% if form.data.latitude or form.instance.latitude %}
 			var lat = "{% if form.data.latitude %}{{form.data.latitude}}{% else %}{{form.instance.latitude}}{% endif %}";
 			var lat = parseFloat(lat.replace(",","."));
 		{% endif %}
 		{% if form.data.longitude or form.instance.longitude %}
			var lng = "{% if form.data.longitude %}{{form.data.longitude}}{% else %}{{form.instance.longitude}}{% endif %}";
			var lng = parseFloat(lng.replace(",","."));
			var zoomLevel = 14;
			getOnce = true;
		{% endif %}
		var latlng = new google.maps.LatLng(lat,lng);
		var map = '';
		var marker = '';
		var getOnce = false;
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
		function setPositionValues(position) {
			$("#id_longitude").val('');
			$("#id_latitude").val('');
			$("#id_address_street").val('');
			$("#id_address_city").val('');
			pos_lng = new Number(position.lng().toPrecision(11)).toFixed(8);
			pos_lat = new Number(position.lat().toPrecision(11)).toFixed(8);
			$("#id_longitude").val(pos_lng);
			$("#id_latitude").val(pos_lat);
			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);
		}
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 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
		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);
							}
						}
					});
		}
367

368 369 370 371 372 373 374 375 376 377
		function codeLatLng(position) {
			addr = {};
			latlng = position;
			addr_num = '';
			addr_name = '';
			addr_city = '';
			addr_code = '';
			geocode(position)
		}
		function initialize() {
378
			image = new google.maps.MarkerImage('{% static '/img/edupin.png' %}',
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
					// 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" }
			                     ]}

408

409 410 411 412 413 414 415 416 417 418 419 420 421
			                   ];
			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,
			};
422 423 424



425 426
			map = new google.maps.Map(document.getElementById("map_canvas"),
					mapOptions);
427

428 429 430 431
			var input = document.getElementById('searchbox');
		    var autocomplete = new google.maps.places.Autocomplete(input);

		    autocomplete.bindTo('bounds', map);
432

433 434 435 436 437 438 439 440 441 442 443 444 445 446
			if (getOnce == false) {
				marker = new google.maps.Marker({
					position : latlng,
					draggable : true,
					'icon': image,
					animation : google.maps.Animation.DROP,

				});
				marker.setMap(map);
				{% if not form.instance.latitude %}
				setPositionValues(latlng);
				{% endif %}
			}
			google.maps.event.addListener(map, 'idle', function() {
447

448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
			{% 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());
			});
464

465 466 467 468 469 470 471 472 473 474 475
			google.maps.event.addListener(autocomplete, 'place_changed', function() {
				var place = autocomplete.getPlace();
				if (place.geometry.viewport) {
		            map.fitBounds(place.geometry.viewport);
		          } else {
		            map.setCenter(place.geometry.location);
		            map.setZoom(17);  // Why 17? Because it looks good.
		          }
				getOnce == true;
				moveMarker(place.geometry.location);
			});
476

477 478 479
		}

		$(document).ready(function() {
480

481 482 483
			initialize();

			$("div.controls > ul").addClass('unstyled');
484

485 486 487 488 489 490 491 492
			$("#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;
			});
493

494 495 496 497
			$("#myloc").click(function(){
				navigator.geolocation.getCurrentPosition(getPosition);
				return false;
			});
498

499 500 501 502 503 504 505 506
			$("#id_latitude").keypress(function(){
				$("#updatemap").removeClass('disabled');
				$("#updatemap").removeAttr('disabled');
			});
			$("#id_longitude").keypress(function(){
				$("#updatemap").removeClass('disabled');
				$("#updatemap").removeAttr('disabled');
			});
507

508
			// Initialize jquery formset
509

510 511 512 513 514
			 $('#urlsform tbody tr').formset({
                prefix: '{{urls_form.prefix}}',
                formCssClass: "dynamic-formset1",
                added: addButton,
            });
515

516 517 518 519 520
			 $('#locsform tbody tr').formset({
		            prefix: '{{services_form.prefix}}',
		            formCssClass: "dynamic-formset2",
		            added: addButton
		        });
521

522 523
			 $(".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');
524

525 526
			 $("#adduserSubmit").click(function(){
					$.ajax({
527
						url:"{% url adduser %}",
528 529 530 531 532 533 534 535
						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'){
536
										$('#mymodalbody').html(data);
537 538 539 540 541 542 543 544
									}
									else{
										$('#id_contact').append($("<option></option>").attr("value",value).text(text));
										$('#myModal').modal('hide')
									}
								}
								catch (exception) {
									$('#mymodalbody').html(data);
545
								}
546 547 548 549
							}
							});
					return false;
				});
550

551 552 553 554 555 556 557 558 559
			 $("#add_contact").click(function(){
				 $('#myModal').modal('show')
				 $.ajax({
						url:"{% url adduser %}",
						type: "GET",
						success: function(data){
							$('#mymodalbody').html(data);
							}
						});
560

561 562
				 return false;
			 });
563

564 565 566 567
		});
		function addButton(row){
			$(row).find(".delete-row").prepend('<i class="icon-remove-sign icon-white"></i> ').addClass('btn btn-small btn-warning');
		}
568 569 570



571 572 573 574
	</script>


{% endblock %}