app/soc/content/js/map-090420.js
author Mario Ferraro <fadinlight@gmail.com>
Thu, 30 Jul 2009 13:56:21 +0200
changeset 2695 9c7d31b8247c
parent 2390 723dfa4811e8
permissions -rw-r--r--
Redone the student<-> mentor map JS to reflect recent datastructure changes. Reviewed by: Lennard de Rijk (functional review)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     1
role_profile_gmap = new function(){
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     2
  // Create global variables
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     3
  var map;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     4
  var marker;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     5
  var geocoder;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     6
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     7
  // The following strings can be customized to reflect ids in the page. 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     8
  // You can also add or remove fields used for GMap Geocoding in 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     9
  // the JSON address object
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    10
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    11
  var current_lat = 0;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    12
  var current_lng = 0;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    13
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    14
  // Two different levels for zoom: Starting one and an inner that 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    15
  // is used when showing the map if lat and lon page fields are set
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    16
  var world_zoom = 0;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    17
  var country_zoom = 4;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    18
  var state_zoom = 6;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    19
  var city_zoom = 10;
1759
94b64c07f7ce Revert r2376 since it's not needed as discussed in Issue 188.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1720
diff changeset
    20
  var address_zoom = 13;
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    21
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    22
  // Do not add a starting # as this JQuery selector seems 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    23
  // incompatible with GMap API
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    24
  var map_div = "role_profile_map";
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    25
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    26
  var field_lat = "#id_latitude";
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    27
  var field_lng = "#id_longitude";
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    28
  // Need to save old values to avoid unwanted updating 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    29
  // of lat and lot if marker dragged and blur another time an address field
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    30
  var address = {
1759
94b64c07f7ce Revert r2376 since it's not needed as discussed in Issue 188.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1720
diff changeset
    31
    street: {
94b64c07f7ce Revert r2376 since it's not needed as discussed in Issue 188.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1720
diff changeset
    32
      id: "#id_res_street",
94b64c07f7ce Revert r2376 since it's not needed as discussed in Issue 188.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1720
diff changeset
    33
      old_value: ""
94b64c07f7ce Revert r2376 since it's not needed as discussed in Issue 188.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1720
diff changeset
    34
    },
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    35
    city: {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    36
      id: "#id_res_city",
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    37
      old_value: ""
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    38
    },
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    39
    state: {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    40
      id: "#id_res_state",
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    41
      old_value: ""
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    42
    },
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    43
    country: {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    44
      id: "#id_res_country",
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    45
      old_value: ""
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    46
    },
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    47
    postalcode: {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    48
      id: "#id_res_postalcode",
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    49
      old_value: ""
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    50
    }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    51
  }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    52
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    53
  // Save current address fields in the JSON Object
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    54
  function saveOldAddress() {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    55
    for (var a in address) {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    56
      address[a].old_value = $(address[a].id).val();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    57
    }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    58
  }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    59
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    60
  // Return true if the user has edited address fields
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    61
  function isNewAddress() {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    62
    for (var a in address) {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    63
      if ($(address[a].id).val() != address[a].old_value) return true;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    64
    }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    65
    return false;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    66
  }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    67
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    68
  // Write saved lat and lng values to page fields
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    69
  function setLatLngFields() {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    70
    $(field_lat).val(current_lat);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    71
    $(field_lng).val(current_lng);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    72
  }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    73
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    74
  // Read lat and lng fields and store them
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    75
  function readLatLngFields() {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    76
    current_lat = $(field_lat).val();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    77
    current_lng = $(field_lng).val();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    78
  }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    79
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    80
  // This function reads address fields, merge them and uses 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    81
  // GMap API geocoding to find the first hit
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    82
  // Using geocoding http://code.google.com/intl/it-IT/apis/maps/documentation/services.html#Geocoding
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    83
  function calculateAddress() {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    84
    // If the user has really edited address fields...
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    85
    if (isNewAddress()) {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    86
      // Merge address fields
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    87
      var address_string = "";
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    88
      for (var a in address) {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    89
        address_string+=$(address[a].id).val();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    90
        if (a!=address.length-1) {address_string+=","};
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    91
      }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    92
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    93
      // Ask GMap API for geocoding
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    94
      geocoder.getLatLng(
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    95
        address_string,
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    96
        function(point) {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    97
          // If a point is found
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    98
          if (point) {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    99
            // Save the current address in the JSON object
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   100
            saveOldAddress();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   101
            // Set the new zoom, map center and marker coords
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   102
            var zoom_set = world_zoom;
1759
94b64c07f7ce Revert r2376 since it's not needed as discussed in Issue 188.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1720
diff changeset
   103
            if ($(address.street.id).val()!="") zoom_set = address_zoom;
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   104
            else if ($(address.city.id).val()!="") zoom_set = city_zoom;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   105
            else if ($(address.state.id).val()!="") zoom_set = state_zoom;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   106
            else if ($(address.country.id).val()!="") zoom_set = country_zoom;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   107
            map.setCenter(point, zoom_set);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   108
            marker.setPoint(point);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   109
            map.clearOverlays();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   110
            map.addOverlay(marker);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   111
            // Save point coords in local variables and then update 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   112
            // the page lat/lng fields
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   113
            current_lat = point.lat();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   114
            current_lng = point.lng();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   115
            setLatLngFields();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   116
          }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   117
        }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   118
      );
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   119
    }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   120
  }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   121
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   122
  // Public function to load the map
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   123
  this.map_load = function() {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   124
    // All can happen only if there is gmap compatible browser.
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   125
    // TODO: Fallback in case the browser is not compatible
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   126
    if (GBrowserIsCompatible()) {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   127
      // Save the address fields. This is useful if the page is being edited 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   128
      // to not update blindly the lat/lng fields with GMap geocoding if 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   129
      // blurring an address field
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   130
      saveOldAddress();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   131
      var starting_point;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   132
      var zoom_selected = world_zoom;
1719
328db0964f86 Show the marker for the Google maps plug in by default.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1152
diff changeset
   133
      var show_marker = true;
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   134
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   135
      // Create the map and add small controls
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   136
      map = new GMap2(document.getElementById(map_div));
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   137
      map.addControl(new GSmallMapControl());
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   138
      map.addControl(new GMapTypeControl());
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   139
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   140
      // Instantiate a global geocoder for future use
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   141
      geocoder = new GClientGeocoder();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   142
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   143
      // If lat and lng fields are not void (the page is being edited) then 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   144
      // update the starting coords, modify the zoom level and tells following 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   145
      // code to show the marker
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   146
      if ($(field_lat).val()!="" && $(field_lng).val()!="") {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   147
        readLatLngFields();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   148
        zoom_selected = address_zoom;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   149
        show_marker = true;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   150
      }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   151
      
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   152
      // Set map center, marker coords and show it if this is an editing
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   153
      starting_point = new GLatLng(current_lat,current_lng);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   154
      map.setCenter(starting_point, zoom_selected);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   155
      marker = new GMarker(starting_point, {draggable:true});
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   156
      if (show_marker) map.addOverlay(marker);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   157
      
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   158
      // Adds a new event listener to geocode the address when an address 
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   159
      // field is blurred
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   160
      for (var a in address) {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   161
        $(address[a].id).blur(calculateAddress);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   162
      }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   163
      
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   164
      // Adds a new event listener: if the marker has been dragged around...
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   165
      GEvent.addListener(marker, "dragend", function() {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   166
        // Update internal variables with current marker coords...
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   167
        current_lat = marker.getPoint().lat();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   168
        current_lng = marker.getPoint().lng();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   169
        // ...and set page fields accordingly
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   170
        setLatLngFields();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   171
      });
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   172
    }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   173
  }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   174
};
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   175
2253
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   176
org_home_gmap = new function(){
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   177
  // Global variables
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   178
  var map;
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   179
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   180
  // HTML div tag where map needs to be inserted
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   181
  var map_div = "org_home_map";
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   182
  
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   183
  // Setup required icons
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   184
  var base_icon = new GIcon();
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   185
  base_icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   186
  base_icon.iconSize = new GSize(20, 34);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   187
  base_icon.shadowSize = new GSize(37, 34);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   188
  base_icon.iconAnchor = new GPoint(9, 34);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   189
  base_icon.infoWindowAnchor = new GPoint(9, 2);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   190
  base_icon.infoShadowAnchor = new GPoint(18, 25);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   191
  var student_icon = new GIcon(base_icon);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   192
  student_icon.image = "http://www.google.com/mapfiles/marker.png";
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   193
  var mentor_icon = new GIcon(base_icon);
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   194
  mentor_icon.image = "/soc/content/images/mentor-marker.png";
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   195
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   196
  // Map load function
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   197
  this.map_load = function(map_data) {
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   198
2253
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   199
    if (GBrowserIsCompatible()) {
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   200
      // Create the map and add small controls
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   201
      map = new GMap2(document.getElementById(map_div));
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   202
      map.addControl(new GLargeMapControl());
2390
723dfa4811e8 Partial fix for displaying mentors and students on Organization home page.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2253
diff changeset
   203
      map.addControl(new GMapTypeControl());
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   204
2253
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   205
      // Set map center and initial zoom level
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   206
      map.setCenter(new GLatLng(0, 0), 1);
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   207
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   208
      var mentors = {};
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   209
      var students = {};
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   210
      var projects = {};
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   211
      var polylines = [];
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   212
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   213
      jQuery.each(map_data.people, function(key, person) {
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   214
        if (person.type === "student") {
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   215
          students[key] = {
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   216
            "name": person.name,
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   217
            "lat": person.lat,
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   218
            "long": person.long,
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   219
            "projects": person.projects
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   220
          }
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   221
        }
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   222
        if (person.type === "mentor") {
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   223
          mentors[key] = {
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   224
            "name": person.name,
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   225
            "lat": person.lat,
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   226
            "long": person.long,
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   227
            "projects": person.projects
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   228
          };
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   229
        }
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   230
      });
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   231
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   232
      // Iterate over projects to draw polylines
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   233
      jQuery.each(map_data.projects, function (key, project) {
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   234
        var current_student = students[project.student_key];
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   235
        var current_mentor = mentors[project.mentor_key];
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   236
        if (current_student !== undefined && 
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   237
            current_mentor !== undefined &&
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   238
            current_student.lat !== null &&
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   239
            current_student.long !== null &&
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   240
            current_mentor.lat !== null &&
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   241
            current_mentor.long !== null) {
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   242
              polylines.push([[current_student.lat,current_student.long],[current_mentor.lat,current_mentor.long]]);
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   243
        }
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   244
      });
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   245
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   246
      // Iterate over students
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   247
      jQuery.each(students, function(key, person) {
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   248
        var html = "";
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   249
        var marker = null;
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   250
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   251
        if (person.lat!==null && person.long!==null) {
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   252
          point = new GLatLng(person.lat,
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   253
                              person.long);
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   254
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   255
          marker = new GMarker(point, student_icon);
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   256
          html = "<strong>" + person.name + "</strong><br />";
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   257
          html += "<span style='font-style:italic;'>Student</span><br />";
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   258
          html += "<div style='height:100px;width:300px;overflow:auto;font-size:70%'>";
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   259
          // iterate through projects
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   260
          jQuery.each(person.projects, function () {
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   261
            var current_project = map_data.projects[this];
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   262
            html += "<a href='"+ current_project.redirect + "'>" + current_project.title + "</a><br />";
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   263
            html += "Mentor: " + current_project.mentor_name + "<br />";
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   264
          });
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   265
          html+= "</div>";
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   266
          GEvent.addListener(marker, "click", function() {
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   267
            marker.openInfoWindowHtml(html);
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   268
          });
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   269
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   270
          map.addOverlay(marker);
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   271
        }
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   272
      });
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   273
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   274
      // Iterate over mentors
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   275
      jQuery.each(mentors, function(key, person) {
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   276
        var html = "";
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   277
        var marker = null;
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   278
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   279
        if (person.lat!==null && person.long!==null) {
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   280
          point = new GLatLng(person.lat,
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   281
                              person.long);
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   282
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   283
          marker = new GMarker(point, mentor_icon);
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   284
          html = "<strong>" + person.name + "</strong><br />";
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   285
          html += "<span style='font-style:italic;'>Student</span><br />";
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   286
          html += "<div style='height:100px;width:300px;overflow:auto;font-size:70%'>";
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   287
          // iterate through projects
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   288
          jQuery.each(person.projects, function () {
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   289
            var current_project = map_data.projects[this];
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   290
            html += "<a href='"+ current_project.redirect + "'>" + current_project.title + "</a><br />";
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   291
            html += "Student: " + current_project.student_name + "<br />";
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   292
          });
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   293
          html+= "</div>";
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   294
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   295
          GEvent.addListener(marker, "click", function() {
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   296
            marker.openInfoWindowHtml(html);
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   297
          });
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   298
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   299
          map.addOverlay(marker);
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   300
        }
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   301
      });
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   302
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   303
      // Draw all polylines
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   304
      jQuery.each(polylines, function() {
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   305
        var from = new GLatLng(this[0][0],this[0][1]);
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   306
        var to = new GLatLng(this[1][0],this[1][1]);
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   307
        var polyline = new GPolyline([from, to], "#ff0000", 3);
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   308
        map.addOverlay(polyline);
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   309
      });
2253
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   310
    }
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   311
  }
ab216123bee7 Added org_home_gmap function to the map JS for displaying the mentor-student map.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2251
diff changeset
   312
};