Statistics
| Branch: | Tag: | Revision:

root / templates / edumanage / services_edit.html @ 138dad8b

History | View | Annotate | Download (18.5 kB)

1
{% extends "edumanage/welcome.html"%}
2
{% load i18n %}
3
{% load tolocale %}
4
{% block crumbs %}
5
        <li><a href="{% url manage %}">{% trans "Home" %}</a><span class="divider">/</span></li>
6
        <li><a href="{% url services %}">{% trans "Services" %}</a><span class="divider">/</span></li>
7
        <li class="active">{% if edit %}{% tolocale form.instance LANGUAGE_CODE %} ({% trans "edit" %}){% else %}{% trans "Add Service" %}{% endif %}</li>
8
{% endblock %}
9
{% block extrahead %}
10
<script type="text/javascript" src="/static/js/jquery.formset.js"></script>
11
 <script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=false"></script>
12
      <script src="/static/js/jquery_csrf_protect.js" type="text/javascript"></script>
13

    
14
<script type="text/javascript">
15
                function gettext(msgid) { return msgid; }
16
                
17
                 var lat = 36.97;
18
                 var lng = 23.71;
19
                 var zoomLevel = 6;
20
                 {% if form.data.latitude or form.instance.latitude %}
21
                         var lat = "{% if form.data.latitude %}{{form.data.latitude}}{% else %}{{form.instance.latitude}}{% endif %}";
22
                         var lat = parseFloat(lat.replace(",","."));
23
                 {% endif %}
24
                 {% if form.data.longitude or form.instance.longitude %}
25
                        var lng = "{% if form.data.longitude %}{{form.data.longitude}}{% else %}{{form.instance.longitude}}{% endif %}";
26
                        var lng = parseFloat(lng.replace(",","."));
27
                        var zoomLevel = 14;
28
                        getOnce = true;
29
                {% endif %}
30
                var latlng = new google.maps.LatLng(lat,lng);
31
                var map = '';
32
                var marker = '';
33
                var getOnce = false;
34

35
                function setPositionValues(position) {
36
                        $("#id_longitude").val('');
37
                        $("#id_latitude").val('');
38
                        $("#id_address_street").val('');
39
                        $("#id_address_city").val('');
40

41
                        $("#id_longitude").val(position.lng().toPrecision(8));
42
                        $("#id_latitude").val(position.lat().toPrecision(8));
43
                        codeLatLng(position);
44
                }
45

46
                function getPosition(position) {
47
                        latlng = new google.maps.LatLng(position.coords.latitude,
48
                                        position.coords.longitude);
49
                        getOnce = true;
50
                        map.setCenter(latlng);
51
                        map.setZoom(15);
52
                        marker.setPosition(latlng);
53
                        setPositionValues(latlng);
54
                }
55

56
                function moveMarker(position) {
57
                        marker.setPosition(position);
58
                        setPositionValues(position);
59
                }
60
                
61
                function geocode(position){
62
                        geocoder
63
                        .geocode(
64
                                        {
65
                                                'latLng' : position
66
                                        },
67
                                        function(results, status) {
68
                                                if (status == google.maps.GeocoderStatus.OK) {
69
                                                        if (results.length >= 1) {
70
                                                                for ( var ii = 0; ii < results[0].address_components.length; ii++) {
71
                                                                        var street_number = route = street = city = state = zipcode = country = formatted_address = '';
72
                                                                        var types = results[0].address_components[ii].types
73
                                                                                        .join(",");
74
                                                                        if (types == "street_number") {
75
                                                                                addr.street_number = results[0].address_components[ii].long_name;
76
                                                                        }
77
                                                                        if (types == "route"
78
                                                                                        || types == "point_of_interest,establishment") {
79
                                                                                addr.route = results[0].address_components[ii].long_name;
80
                                                                        }
81
                                                                        if (types == "sublocality,political"
82
                                                                                        || types == "locality,political"
83
                                                                                        || types == "neighborhood,political"
84
                                                                                        || types == "political") {
85
                                                                                addr.city = (city == '' || types == "locality,political") ? results[0].address_components[ii].long_name
86
                                                                                                : city;
87
                                                                        }
88
                                                                        if (types == "administrative_area_level_1,political") {
89
                                                                                addr.state = results[0].address_components[ii].short_name;
90
                                                                        }
91
                                                                        if (types == "postal_code"
92
                                                                                        || types == "postal_code_prefix,postal_code") {
93
                                                                                addr.zipcode = results[0].address_components[ii].long_name;
94
                                                                        }
95
                                                                        if (types == "country,political") {
96
                                                                                addr.country = results[0].address_components[ii].long_name;
97
                                                                        }
98
                                                                }
99
                                                        }
100

101
                                                        if (addr.route && addr.city) {
102
                                                                addr_field = addr.route;
103
                                                                if (addr.street_number) {
104
                                                                        addr_field = addr.route + " "
105
                                                                                        + addr.street_number;
106
                                                                }
107
                                                                $("#id_address_street").val(addr_field);
108
                                                                city_field = addr.city;
109
                                                                if (addr.zipcode) {
110
                                                                        city_field = addr.city + ", "
111
                                                                                        + addr.zipcode;
112
                                                                }
113
                                                                $("#id_address_city").val(city_field);
114
                                                        }
115
                                                }
116
                                        });
117
                }
118
                
119
                function codeLatLng(position) {
120
                        addr = {};
121
                        latlng = position;
122
                        addr_num = '';
123
                        addr_name = '';
124
                        addr_city = '';
125
                        addr_code = '';
126
                        geocode(position)
127
                }
128
                function initialize() {
129
                        image = new google.maps.MarkerImage('/static/img/edupin.png',
130
                                        // This marker is 29 pixels wide by 40 pixels tall.
131
                                        new google.maps.Size(29, 40),
132
                                        // The origin for this image is 0,0.
133
                                        new google.maps.Point(0,0),
134
                                        // The anchor for this image is the base of the flagpole at 18,42.
135
                                        new google.maps.Point(14, 40)
136
                                );
137
                        var styleArray = [
138
                                           {
139
                                               featureType: "all",
140
                                               stylers: [
141
                                                 { saturation: -60 },
142
                                                 {gamma: 1.00 }
143
                                               ]
144
                                             },{
145
                                               featureType: "poi.business",
146
                                               elementType: "labels",
147
                                               stylers: [
148
                                                 { visibility: "off" }
149
                                               ]
150
                                             },
151
                                             { "featureType": "transit.line", "elementType": "geometry", "stylers": [ { "visibility": "off" } ] },
152
                                             { "featureType": "poi", "elementType": "all", "stylers": [ { "visibility": "off" } ] },
153
                                             {'featureType': "administrative.country",
154
                                             'elementType': "labels",
155
                                             'stylers': [
156
                                                 { 'visibility': "off" }
157
                                             ]}
158

159
                                             
160
                                           ];
161
                        geocoder = new google.maps.Geocoder();
162
                        var mapOptions = {
163
                                center : latlng,
164
                                zoom : zoomLevel,
165
                                styles: styleArray,
166
                                 mapTypeId: google.maps.MapTypeId.ROADMAP,
167
                                    mapTypeControlOptions: {
168
                                              style: google.maps.MapTypeControlStyle.DEFAULT
169
                                            },
170
                                        navigationControl: true,
171
                                        mapTypeControl: false,
172
                        };
173
                        map = new google.maps.Map(document.getElementById("map_canvas"),
174
                                        mapOptions);
175
                        if (getOnce == false) {
176
                                marker = new google.maps.Marker({
177
                                        position : latlng,
178
                                        draggable : true,
179
                                        'icon': image,
180
                                        animation : google.maps.Animation.DROP,
181

182
                                });
183
                                marker.setMap(map);
184
                                setPositionValues(latlng);
185
                        }
186
                        google.maps.event.addListener(map, 'idle', function() {
187
                                
188
                        {% if not form.data.latitude  %}
189
                                {% if not form.instance.latitude  %}
190
                                        if (navigator.geolocation && getOnce == false) {
191
                                                navigator.geolocation.getCurrentPosition(getPosition);
192
                                        }
193
                                {% endif %}
194
                        {% endif %}
195

196
                        });
197

198
                        google.maps.event.addListener(map, 'click', function(event) {
199
                                moveMarker(event.latLng);
200
                        });
201
                        google.maps.event.addListener(marker, 'dragend', function(event) {
202
                                setPositionValues(marker.getPosition());
203
                        });
204

205
                }
206

207
                $(document).ready(function() {
208
                        
209
                        initialize();
210
                        
211
                        $("div.controls > ul").addClass('unstyled');
212
                        
213
                        $("#updatemap").click(function(){
214
                                latlng = new google.maps.LatLng($("#id_latitude").val(), $("#id_longitude").val());
215
                                moveMarker(latlng);
216
                                map.setCenter(latlng);
217
                                $("#updatemap").addClass('disabled');
218
                                $("#updatemap").attr('disabled', 'disabled');
219
                                return false;
220
                        });
221
                        
222
                        $("#myloc").click(function(){
223
                                navigator.geolocation.getCurrentPosition(getPosition);
224
                                return false;
225
                        });
226
                        
227
                        $("#id_latitude").keypress(function(){
228
                                $("#updatemap").removeClass('disabled');
229
                                $("#updatemap").removeAttr('disabled');
230
                        });
231
                        $("#id_longitude").keypress(function(){
232
                                $("#updatemap").removeClass('disabled');
233
                                $("#updatemap").removeAttr('disabled');
234
                        });
235
                        
236
                        // Initialize jquery formset
237
                        
238
                         $('#urlsform tbody tr').formset({
239
                prefix: '{{urls_form.prefix}}',
240
                formCssClass: "dynamic-formset1",
241
                added: addButton,
242
            });
243
                        
244
                         $('#locsform tbody tr').formset({
245
                            prefix: '{{services_form.prefix}}',
246
                            formCssClass: "dynamic-formset2",
247
                            added: addButton
248
                        });
249
                         
250
                         $(".delete-row").prepend('<i class="icon-remove-sign icon-white"></i> ').addClass('btn btn-small btn-warning');
251
                         $(".add-row").prepend('<i class="icon-plus-sign icon-white"></i> ').addClass('btn btn-small btn-info');
252
                         
253
                         $("#adduserSubmit").click(function(){
254
                                        $.ajax({
255
                                                url:"{% url adduser %}", 
256
                                                data:$("#add_user_form").serialize(),
257
                                                type: "POST",
258
                                                cache: false,
259
                                                success:function(data){
260
                                                                try {
261
                                                                        value = data.value;
262
                                                                        text = data.text;
263
                                                                        if (typeof value === 'undefined' && typeof text === 'undefined'){
264
                                                                                $('#mymodalbody').html(data);        
265
                                                                        }
266
                                                                        else{
267
                                                                                $('#id_contact').append($("<option></option>").attr("value",value).text(text));
268
                                                                                $('#myModal').modal('hide')
269
                                                                        }
270
                                                                }
271
                                                                catch (exception) {
272
                                                                        $('#mymodalbody').html(data);
273
                                                                }                                        
274
                                                        }
275
                                                        });
276
                                        return false;
277
                                });
278
                         
279
                         $("#add_contact").click(function(){
280
                                 $('#myModal').modal('show')
281
                                 $.ajax({
282
                                                url:"{% url adduser %}",
283
                                                type: "GET",
284
                                                success: function(data){
285
                                                        $('#mymodalbody').html(data);
286
                                                        }
287
                                                });
288
                        
289
                                 return false;
290
                         });
291
                         
292
                });
293
                function addButton(row){
294
                        $(row).find(".delete-row").prepend('<i class="icon-remove-sign icon-white"></i> ').addClass('btn btn-small btn-warning');
295
                }
296
                
297
                
298
                
299
        </script>
300

    
301

    
302
{% endblock %}
303
                        
304
{% block homeactive %}{% endblock %}
305
{% block servicesactive %}class="active"{% endblock %}
306
{% block subcontent %}
307

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

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

    
478
<div class="modal hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
479
<div class="modal-header">
480
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
481
<h3 id="myModalLabel">{% trans "Add User" %}</h3>
482
</div>
483
<div class="modal-body" id="mymodalbody">
484

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

    
492
{% endblock %}