annotate media/js/membermap.js @ 133:c515b7401078

Use the new common way to apply markItUp to textareas and to get the smiley and markdown help dialogs for all the remaining apps except for forums and comments.
author Brian Neal <bgneal@gmail.com>
date Fri, 27 Nov 2009 00:21:47 +0000
parents dbd703f7d63a
children b43e1288ff80
rev   line source
gremmie@1 1 var mmap = {
gremmie@1 2 map: null,
gremmie@1 3 geocoder: null,
gremmie@1 4 users: Object,
gremmie@1 5 userOnMap: false,
gremmie@1 6 userClick: function() {
gremmie@1 7 var name = $('option:selected', this).text();
gremmie@1 8 if (name != mmap.selectText)
gremmie@1 9 {
gremmie@1 10 mmap.clickUser(name);
gremmie@1 11 }
gremmie@1 12 },
gremmie@1 13 clickUser: function(name) {
gremmie@1 14 pt = new GLatLng(mmap.users[name].lat, mmap.users[name].lon);
gremmie@1 15 mmap.map.setCenter(pt);
gremmie@1 16 mmap.users[name].marker.openInfoWindowHtml(mmap.users[name].message);
gremmie@1 17 },
gremmie@1 18 clear: function() {
gremmie@1 19 mmap.users.length = 0;
gremmie@1 20 },
gremmie@1 21 resizeUserList: function() {
gremmie@1 22 var sel = $('#member_map_members');
gremmie@1 23 sel[0].size = Math.min(29, sel[0].length);
gremmie@1 24 $('#member_map_count').html(sel[0].length);
gremmie@1 25 },
gremmie@1 26 selectText: "(select)",
gremmie@1 27 onMapDir: 'You have previously added yourself to the member map. Your information appears below. You may change ' +
gremmie@1 28 'the information if you wish. To delete yourself from the map, click the Delete button.',
gremmie@1 29 offMapDir: 'Your location is not on the map. If you would like to appear on the map, please fill out the form below ' +
gremmie@1 30 'and click the Submit button.'
gremmie@1 31 };
gremmie@1 32 $(document).ready(function() {
gremmie@1 33 if (GBrowserIsCompatible())
gremmie@1 34 {
gremmie@1 35 $(window).unload(GUnload);
gremmie@1 36 mmap.map = new GMap2($('#member_map_map')[0]);
gremmie@1 37 mmap.map.setCenter(new GLatLng(15.0, -30.0), 2);
gremmie@1 38 mmap.map.enableScrollWheelZoom();
gremmie@1 39 mmap.map.addControl(new GLargeMapControl());
gremmie@1 40 mmap.map.addControl(new GMapTypeControl());
gremmie@1 41 mmap.geocoder = new GClientGeocoder();
gremmie@1 42
gremmie@1 43 if (mmapUser.userName)
gremmie@1 44 {
gremmie@1 45 $.getJSON('/member_map/query/',
gremmie@1 46 function(data) {
gremmie@1 47 mmap.map.clearOverlays();
gremmie@1 48 var sel = $('#member_map_members');
gremmie@1 49 sel[0].length = 0;
gremmie@1 50 mmap.clear();
gremmie@1 51 $.each(data.users, function(i, item) {
gremmie@1 52 sel.append($('<option />').html(item.name));
gremmie@1 53 var marker = new GMarker(new GLatLng(item.lat, item.lon));
gremmie@1 54 marker.bindInfoWindowHtml(item.message);
gremmie@1 55 mmap.map.addOverlay(marker);
gremmie@1 56 mmap.users[item.name] = item;
gremmie@1 57 mmap.users[item.name].marker = marker;
gremmie@1 58 if (mmapUser.userName == item.name)
gremmie@1 59 {
gremmie@1 60 mmap.userOnMap = true;
gremmie@1 61 }
gremmie@1 62 });
gremmie@1 63 sel[0].size = Math.min(29, data.users.length);
gremmie@1 64 $('#member_map_count').html(data.users.length);
gremmie@1 65
gremmie@1 66 sel = $('#member_map_recent');
gremmie@1 67 sel[0].length = 0;
gremmie@1 68 sel.append($('<option />').html(mmap.selectText));
gremmie@1 69 $.each(data.recent, function(i, item) {
gremmie@1 70 sel.append($('<option />').html(item));
gremmie@1 71 });
gremmie@1 72 var submitButton = $('#member_map_submit');
gremmie@1 73 var deleteButton = $('#member_map_delete');
gremmie@1 74
gremmie@1 75 submitButton.click(function() {
gremmie@1 76 if (mmap.geocoder)
gremmie@1 77 {
gremmie@1 78 $(this).attr('disabled', 'disabled').val('Updating Map...');
gremmie@1 79 var address = $('#id_location').val();
gremmie@1 80 mmap.geocoder.getLatLng(address,
gremmie@1 81 function(point) {
gremmie@1 82 if (!point)
gremmie@1 83 {
gremmie@1 84 alert(address + ' could not be found on Google Maps.');
gremmie@1 85 return;
gremmie@1 86 }
gremmie@1 87 $.post('/member_map/add/', {
gremmie@1 88 loc : address,
gremmie@1 89 lat : point.lat(),
gremmie@1 90 lon : point.lng(),
gremmie@1 91 msg : $('#id_message').val()
gremmie@1 92 },
gremmie@1 93 function(data, textStatus) {
gremmie@1 94 var wasOnMap = mmap.userOnMap;
gremmie@1 95 if (mmap.userOnMap)
gremmie@1 96 {
gremmie@1 97 mmap.map.removeOverlay(mmap.users[mmapUser.userName].marker);
gremmie@1 98 }
gremmie@1 99 else
gremmie@1 100 {
gremmie@1 101 $('#member_map_members').append($('<option />').html(data.name));
gremmie@1 102 mmap.userOnMap = true;
gremmie@1 103 deleteButton.removeAttr('disabled').val('Delete');
gremmie@1 104 }
gremmie@1 105 var marker = new GMarker(new GLatLng(data.lat, data.lon));
gremmie@1 106 marker.bindInfoWindowHtml(data.message);
gremmie@1 107 mmap.map.addOverlay(marker);
gremmie@1 108 mmap.users[mmapUser.userName] = data;
gremmie@1 109 mmap.users[mmapUser.userName].marker = marker;
gremmie@1 110 mmap.clickUser(mmapUser.userName);
gremmie@1 111 submitButton.removeAttr('disabled').val('Update');
gremmie@1 112 $('#member_map_directions').html(mmap.onMapDir);
gremmie@1 113 mmap.resizeUserList();
gremmie@1 114 alert(wasOnMap ? "Your location has been updated!" :
gremmie@1 115 "You've been added to the map!");
gremmie@1 116 },
gremmie@1 117 'json');
gremmie@1 118 });
gremmie@1 119 }
gremmie@1 120 return false;
gremmie@1 121 });
gremmie@1 122
gremmie@1 123 deleteButton.click(function() {
gremmie@1 124 deleteButton.attr('disabled', 'disabled').val('Deleting...');
gremmie@1 125 $.post('/member_map/delete/', function(data, textStatus) {
gremmie@1 126 $('#id_location').val('');
gremmie@1 127 $('#id_message').val('');
gremmie@1 128 $("#member_map_members option[value='" + mmapUser.userName + "']").remove();
gremmie@1 129 $("#member_map_recent option[value='" + mmapUser.userName + "']").remove();
gremmie@1 130 mmap.map.removeOverlay(mmap.users[mmapUser.userName].marker);
gremmie@1 131 mmap.users[mmapUser.userName].marker = null;
gremmie@1 132 mmap.users[mmapUser.userName] = null;
gremmie@1 133 mmap.userOnMap = false;
gremmie@1 134 deleteButton.val('Delete');
gremmie@1 135 submitButton.removeAttr('disabled').val('Add');
gremmie@1 136 $('#member_map_directions').html(mmap.offMapDir);
gremmie@1 137 mmap.resizeUserList();
gremmie@1 138 alert("You've been removed from the map.");
gremmie@1 139 },
gremmie@1 140 'text');
gremmie@1 141 return false;
gremmie@1 142 });
gremmie@1 143
gremmie@1 144 if (mmap.userOnMap)
gremmie@1 145 {
gremmie@1 146 submitButton.val('Update');
gremmie@1 147 $('#member_map_directions').html(mmap.onMapDir);
gremmie@1 148 }
gremmie@1 149 else
gremmie@1 150 {
gremmie@1 151 submitButton.val('Add');
gremmie@1 152 deleteButton.attr('disabled', 'disabled');
gremmie@1 153 $('#member_map_directions').html(mmap.offMapDir);
gremmie@1 154 }
gremmie@1 155 });
gremmie@1 156 $('#member_map_members').change(mmap.userClick);
gremmie@1 157 $('#member_map_recent').change(mmap.userClick);
gremmie@1 158 }
gremmie@1 159 }
gremmie@1 160 });