app/soc/content/js/map-090917.js
author Lennard de Rijk <ljvderijk@gmail.com>
Wed, 30 Sep 2009 21:10:36 +0200
changeset 2994 24db4afbc82e
parent 2939 415a7c2866fd
child 3093 d1be59b6b627
permissions -rw-r--r--
Removed order property in the getBatchOfData. This ordering is not possible since you want to go over the entities in order oftheir key and ordering them would prohibit this from happening properly.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
     1
(function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
     2
  var role_profile_gmap = window.role_profile_gmap = function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
     3
  };
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
     4
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     5
  // Create global variables
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     6
  var map;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     7
  var marker;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     8
  var geocoder;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
     9
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    10
  // The following strings can be customized to reflect ids in the page.
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    11
  // 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
    12
  // the JSON address object
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
  var current_lat = 0;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    15
  var current_lng = 0;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    16
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    17
  // 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
    18
  // 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
    19
  var world_zoom = 0;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    20
  var country_zoom = 4;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    21
  var state_zoom = 6;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    22
  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
    23
  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
    24
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    25
  // 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
    26
  // incompatible with GMap API
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    27
  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
    28
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    29
  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
    30
  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
    31
  // 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
    32
  // 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
    33
  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
    34
    street: {
94b64c07f7ce Revert r2376 since it's not needed as discussed in Issue 188.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1720
diff changeset
    35
      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
    36
      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
    37
    },
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    38
    city: {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    39
      id: "#id_res_city",
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    40
      old_value: ""
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    41
    },
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    42
    state: {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    43
      id: "#id_res_state",
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    44
      old_value: ""
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    45
    },
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    46
    country: {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    47
      id: "#id_res_country",
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    48
      old_value: ""
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    49
    },
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    50
    postalcode: {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    51
      id: "#id_res_postalcode",
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    52
      old_value: ""
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    53
    }
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    54
  };
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    55
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    56
  // 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
    57
  function saveOldAddress() {
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    58
    jQuery.each(address, function (level, level_details) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    59
      level_details.old_value = jQuery(level_details.id).val();
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    60
    });
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    61
  }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    62
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    63
  // 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
    64
  function isNewAddress() {
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    65
    var is_new = false;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    66
    jQuery.each(address, function (level, level_details) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    67
      if (jQuery(level_details.id).val() !== level_details.old_value) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    68
        is_new = true;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    69
        return false;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    70
      }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    71
    });
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    72
    return is_new;
1152
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
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    75
  // 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
    76
  function setLatLngFields() {
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    77
    jQuery(field_lat).val(current_lat);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    78
    jQuery(field_lng).val(current_lng);
1152
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
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    81
  // 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
    82
  function readLatLngFields() {
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    83
    current_lat = jQuery(field_lat).val();
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    84
    current_lng = jQuery(field_lng).val();
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    85
  }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    86
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    87
  // This function reads address fields, merge them and uses
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    88
  // GMap API geocoding to find the first hit
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    89
  // Using geocoding
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    90
  // http://code.google.com/intl/it-IT/apis/maps/documentation/
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    91
  // services.html#Geocoding
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    92
  function calculateAddress() {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    93
    // 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
    94
    if (isNewAddress()) {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    95
      // Merge address fields
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
    96
      var address_string = "";
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    97
      jQuery.each(address, function (level, level_details) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    98
        address_string += jQuery(level_details.id).val() + ",";
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
    99
      });
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   100
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   101
      // 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
   102
      geocoder.getLatLng(
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   103
        address_string,
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   104
        function (point) {
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   105
          // 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
   106
          if (point) {
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   107
            // 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
   108
            saveOldAddress();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   109
            // 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
   110
            var zoom_set = world_zoom;
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   111
            if (jQuery(address.street.id).val() !== "") {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   112
              zoom_set = address_zoom;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   113
            }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   114
            else if (jQuery(address.city.id).val() !== "") {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   115
              zoom_set = city_zoom;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   116
            }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   117
            else if (jQuery(address.state.id).val() !== "") {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   118
              zoom_set = state_zoom;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   119
            }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   120
            else if (jQuery(address.country.id).val() !== "") {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   121
              zoom_set = country_zoom;
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   122
            }
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   123
            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
   124
            marker.setPoint(point);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   125
            map.clearOverlays();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   126
            map.addOverlay(marker);
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   127
            // 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
   128
            // 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
   129
            current_lat = point.lat();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   130
            current_lng = point.lng();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   131
            setLatLngFields();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   132
          }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   133
        }
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
    }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   136
  }
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   137
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   138
  // Public function to load the map
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   139
  role_profile_gmap.map_load = function () {
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   140
    // 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
   141
    // TODO: Fallback in case the browser is not compatible
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   142
    if (window.GBrowserIsCompatible()) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   143
      // Save the address fields. This is useful if the page is being edited
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   144
      // to not update blindly the lat/lng fields with GMap geocoding if
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   145
      // blurring an address field
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   146
      saveOldAddress();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   147
      var starting_point;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   148
      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
   149
      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
   150
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   151
      // Create the map and add small controls
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   152
      map = new window.GMap2(document.getElementById(map_div));
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   153
      map.addControl(new window.GSmallMapControl());
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   154
      map.addControl(new window.GMapTypeControl());
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   155
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   156
      // Instantiate a global geocoder for future use
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   157
      geocoder = new window.GClientGeocoder();
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   158
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   159
      // If lat and lng fields are not void (the page is being edited) then
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   160
      // update the starting coords, modify the zoom level and tells following
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   161
      // code to show the marker
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   162
      if (jQuery(field_lat).val() !== "" && jQuery(field_lng).val() !== "") {
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   163
        readLatLngFields();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   164
        zoom_selected = address_zoom;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   165
        show_marker = true;
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   166
      }
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   167
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   168
      // Set map center, marker coords and show it if this is an editing
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   169
      starting_point = new window.GLatLng(current_lat, current_lng);
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   170
      map.setCenter(starting_point, zoom_selected);
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   171
      marker = new window.GMarker(starting_point, {draggable: true});
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   172
      if (show_marker) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   173
        map.addOverlay(marker);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   174
      }
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   175
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   176
      // 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
   177
      // field is blurred
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   178
      jQuery.each(address, function (level, level_details) {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   179
        jQuery(level_details.id).blur(calculateAddress);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   180
      });
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   181
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   182
      // Adds a new event listener: if the marker has been dragged around...
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   183
      window.GEvent.addListener(marker, "dragend", function () {
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   184
        // 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
   185
        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
   186
        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
   187
        // ...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
   188
        setLatLngFields();
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   189
      });
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   190
    }
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   191
  };
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   192
}());
1152
b82caf7bb17c Add Google Maps integration for Role profiles create/edit views.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
   193
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   194
(function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   195
  var org_home_gmap = window.org_home_gmap = function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   196
  };
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
   197
  // 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
   198
  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
   199
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
  // 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
   201
  var map_div = "org_home_map";
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   202
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
   203
  // Setup required icons
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   204
  var base_icon = new window.GIcon();
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
  base_icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   206
  base_icon.iconSize = new window.GSize(20, 34);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   207
  base_icon.shadowSize = new window.GSize(37, 34);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   208
  base_icon.iconAnchor = new window.GPoint(9, 34);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   209
  base_icon.infoWindowAnchor = new window.GPoint(9, 2);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   210
  base_icon.infoShadowAnchor = new window.GPoint(18, 25);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   211
  var student_icon = new window.GIcon(base_icon);
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
   212
  student_icon.image = "http://www.google.com/mapfiles/marker.png";
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   213
  var mentor_icon = new window.GIcon(base_icon);
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
   214
  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
   215
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
   216
  // Map load function
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   217
  org_home_gmap.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
   218
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   219
    if (window.GBrowserIsCompatible()) {
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
   220
      // Create the map and add small controls
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   221
      map = new window.GMap2(document.getElementById(map_div));
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   222
      map.addControl(new window.GLargeMapControl());
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   223
      map.addControl(new window.GMapTypeControl());
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   224
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
   225
      // Set map center and initial zoom level
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   226
      map.setCenter(new window.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
   227
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   228
      var mentors = {};
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   229
      var students = {};
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   230
      var projects = {};
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   231
      var polylines = [];
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   232
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   233
      jQuery.each(map_data.people, function (key, person) {
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   234
        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
   235
          students[key] = {
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   236
            "name": person.name,
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   237
            "lat": person.lat,
2938
062d5ddb15b7 Shrinksafe complains during compression of map JS fixed.
Mario Ferraro <fadinlight@gmail.com>
parents: 2801
diff changeset
   238
            "lon": person.lon,
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   239
            "projects": person.projects
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   240
          };
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   241
        }
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   242
        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
   243
          mentors[key] = {
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   244
            "name": person.name,
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   245
            "lat": person.lat,
2938
062d5ddb15b7 Shrinksafe complains during compression of map JS fixed.
Mario Ferraro <fadinlight@gmail.com>
parents: 2801
diff changeset
   246
            "lon": person.lon,
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   247
            "projects": person.projects
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   248
          };
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   249
        }
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
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   252
      // 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
   253
      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
   254
        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
   255
        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
   256
        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
   257
            current_mentor !== undefined &&
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   258
            current_student.lat !== null &&
2938
062d5ddb15b7 Shrinksafe complains during compression of map JS fixed.
Mario Ferraro <fadinlight@gmail.com>
parents: 2801
diff changeset
   259
            current_student.lon !== null &&
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   260
            current_mentor.lat !== null &&
2938
062d5ddb15b7 Shrinksafe complains during compression of map JS fixed.
Mario Ferraro <fadinlight@gmail.com>
parents: 2801
diff changeset
   261
            current_mentor.lon !== null) {
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   262
              /*jslint white: false */
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   263
              polylines.push([
2938
062d5ddb15b7 Shrinksafe complains during compression of map JS fixed.
Mario Ferraro <fadinlight@gmail.com>
parents: 2801
diff changeset
   264
                [current_student.lat, current_student.lon],
062d5ddb15b7 Shrinksafe complains during compression of map JS fixed.
Mario Ferraro <fadinlight@gmail.com>
parents: 2801
diff changeset
   265
                [current_mentor.lat, current_mentor.lon]
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   266
              ]);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   267
              /*jslint white: true */
2695
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
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   271
      // Iterate over students
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   272
      jQuery.each(students, function (key, person) {
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   273
        var html = "";
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   274
        var marker = null;
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   275
2938
062d5ddb15b7 Shrinksafe complains during compression of map JS fixed.
Mario Ferraro <fadinlight@gmail.com>
parents: 2801
diff changeset
   276
        if (person.lat !== null && person.lon !== null) {
062d5ddb15b7 Shrinksafe complains during compression of map JS fixed.
Mario Ferraro <fadinlight@gmail.com>
parents: 2801
diff changeset
   277
          var point = new window.GLatLng(person.lat, person.lon);
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   278
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   279
          marker = new window.GMarker(point, student_icon);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   280
          html = [
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   281
            "<strong>", person.name, "</strong><br />",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   282
            "<span style='font-style:italic;'>Student</span><br />",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   283
            "<div style='height:100px;width:300px;",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   284
            "overflow:auto;font-size:70%'>"
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   285
          ].join("");
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   286
          // iterate through projects
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   287
          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
   288
            var current_project = map_data.projects[this];
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   289
            html += [
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   290
              "<a href='", current_project.redirect, "'>",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   291
              current_project.title, "</a><br />",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   292
              "Mentor: ", current_project.mentor_name, "<br />"
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   293
            ].join("");
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   294
          });
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   295
          html += "</div>";
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   296
          window.GEvent.addListener(marker, "click", function () {
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   297
            marker.openInfoWindowHtml(html);
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
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   300
          map.addOverlay(marker);
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
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   304
      // Iterate over mentors
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   305
      jQuery.each(mentors, function (key, person) {
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   306
        var html = "";
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   307
        var marker = null;
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   308
2938
062d5ddb15b7 Shrinksafe complains during compression of map JS fixed.
Mario Ferraro <fadinlight@gmail.com>
parents: 2801
diff changeset
   309
        if (person.lat !== null && person.lon !== null) {
062d5ddb15b7 Shrinksafe complains during compression of map JS fixed.
Mario Ferraro <fadinlight@gmail.com>
parents: 2801
diff changeset
   310
          var point = new window.GLatLng(person.lat, person.lon);
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   311
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   312
          marker = new window.GMarker(point, mentor_icon);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   313
          html = [
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   314
            "<strong>", person.name, "</strong><br />",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   315
            "<span style='font-style:italic;'>Mentor</span><br />",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   316
            "<div style='height:100px;width:300px;",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   317
            "overflow:auto;font-size:70%'>"
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   318
          ].join("");
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   319
          // iterate through projects
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   320
          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
   321
            var current_project = map_data.projects[this];
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   322
            html += [
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   323
              "<a href='", current_project.redirect, "'>",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   324
              current_project.title, "</a><br />",
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   325
              "Student: ", current_project.student_name, "<br />"
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   326
            ].join("");
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   327
          });
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   328
          html += "</div>";
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   329
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   330
          window.GEvent.addListener(marker, "click", function () {
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   331
            marker.openInfoWindowHtml(html);
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   332
          });
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   333
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   334
          map.addOverlay(marker);
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   335
        }
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   336
      });
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   337
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   338
      // Draw all polylines
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   339
      jQuery.each(polylines, function () {
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   340
        var from = new window.GLatLng(this[0][0], this[0][1]);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   341
        var to = new window.GLatLng(this[1][0], this[1][1]);
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   342
        var polyline = new window.GPolyline([from, to], "#ff0000", 3);
2695
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   343
        map.addOverlay(polyline);
9c7d31b8247c Redone the student<-> mentor map JS to reflect recent datastructure changes.
Mario Ferraro <fadinlight@gmail.com>
parents: 2390
diff changeset
   344
      });
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
   345
    }
2800
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   346
  };
cd9eed2b787e Made all JS code JSLint compliant.
Mario Ferraro <fadinlight@gmail.com>
parents: 2700
diff changeset
   347
}());