';
$('#locations_list').html(list);
});
});
}
}
function init_admin() {
if (GBrowserIsCompatible()) {
if(festivalEdition==="unsound-festival-new-york-2012") {
map.setCenter(new GLatLng(40.732787,-73.928119), 12);
//map.setCenter(new GLatLng(50.0616847483284, 19.9373960494995), 15);
}
else {
map.setCenter(new GLatLng(50.0616847483284, 19.9373960494995), 15);
//map.setCenter(new GLatLng(40.732787,-73.928119), 12);
}
/* map.setCenter(new GLatLng(50.0616847483284, 19.9373960494995), 15); */
map.setMapType(G_NORMAL_MAP);
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
load_data();
GEvent.addListener(map, "click", function(marker, point) {
if (point) {
cnt++;
marker = new GMarker(point, {draggable:false});
var latlng = marker.getLatLng();
var lat = latlng.lat();
var lng = latlng.lng();
var mark = {};
mark.lat = lat;
mark.lng = lng;
mark.marker = marker;
lastLoc[cnt] = mark;
var content = "
";
map.addOverlay(marker);
marker.openInfoWindow(content);
$('#closeWindow').click(function() { marker.closeInfoWindow(); map.removeOverlay(marker); return false; });
if(cnt > 1) { pokaz(cnt); }
}
});
}
}
function load_data() {
var list = $('#locations_list').html();
list = '';
map.clearOverlays();
$.ajax({
type: "GET",
url: "http://unsound.pl/en/festival/localisations_ajax_get/2010",
dataType: "json",
success: function(data){
$.each(data, function(i,item){
var point = new GPoint(item.lat, item.lng);
var marker = new GMarker(point, {draggable:false});
map.addOverlay(marker);
GEvent.addListener(marker, "click", function(point) {
var latlng = marker.getLatLng();
var www_ready = anchorize(item.www);
var html = '
Name: ' + item.name + '
';
html += '
Address: ' + item.address + '
';
html += '
Town: ' + item.town + '
';
html += '
Website: ' + www_ready + '
';
html += '
EDIT REMOVE
';
marker.openInfoWindow(html);
});
var localisation = {};
localisation.id = item.id;
localisation.lat = item.lng;
localisation.lng = item.lat;
localisation.name = item.name;
localisation.address = item.address;
localisation.town = item.town;
localisation.www = item.www;
localisation.marker = marker;
locs[localisation.id] = localisation;
list += '
';
});
$('#locations_list').html(list);
}
});
}
function load_data2(data) {
var list = $('#locations_list').html();
list = '';
map.clearOverlays();
$.each(data, function(i,item){
var point = new GPoint(item.lat, item.lng);
var marker = new GMarker(point, {draggable:false});
map.addOverlay(marker);
GEvent.addListener(marker, "click", function(point) {
var latlng = marker.getLatLng();
var www_ready = anchorize(item.www);
var html = '
Name: ' + item.name + '
';
html += '
Address: ' + item.address + '
';
html += '
Town: ' + item.town + '
';
html += '
Website: ' + www_ready + '
';
html += '
EDIT REMOVE
';
marker.openInfoWindow(html);
});
var localisation = {};
localisation.id = item.id;
localisation.lat = item.lng;
localisation.lng = item.lat;
localisation.name = item.name;
localisation.address = item.address;
localisation.town = item.town;
localisation.www = item.www;
localisation.marker = marker;
locs[localisation.id] = localisation;
list += '
';
});
$('#locations_list').html(list);
}
function addPlace() {
form = $('#marker-form');
if( !form.validate() ) { return; }
var sdata = {};
$('*[name]', form).each(function() {
var t = $(this);
var val = t.val();
sdata[t.attr('name')] = val;
});
$.ajax({
type: "POST",
url: "http://unsound.pl/en/festival/localisations_ajax_set/2010",
data: sdata,
dataType: "json",
success: function(data){
if(data.msg=='ok') {
load_data2(data.result);
}
}
});
}
function removePlace(itemId) {
var sdata = {};
sdata.id = itemId;
$.ajax({
type: "POST",
url: "http://unsound.pl/en/festival/localisations_ajax_remove/2010",
data: sdata,
dataType: "json",
success: function(data){
if(data.msg=='ok') {
load_data2(data.result);
}
if(data.msg=='This location belongs to a few events.') {
alert(data.msg);
}
}
});
}
function editPlace(itemId) {
//map.panTo(new GLatLng(locs[itemId].lat, locs[itemId].lng));
var my_marker = locs[itemId].marker;
var name = locs[itemId].name;
var address = locs[itemId].address;
var town = locs[itemId].town;
var www = locs[itemId].www;
var lat = locs[itemId].lat;
var lng = locs[itemId].lng;
var content = "
";
content +="Name
";
content +="Address "+address+"
";
content +="Town
";
content +="Website
";
content +=" ";
content +=" ";
content +="";
my_marker.openInfoWindow(content);
$('#closeWindow').click(function() { my_marker.closeInfoWindow(); return false; });
}
function updatePlace(itemId) {
form = $('#marker-form');
if( !form.validate() ) { return; }
var sdata = {};
$('*[name]', form).each(function() {
var t = $(this);
var val = t.val();
sdata[t.attr('name')] = val;
});
sdata.id = itemId;
$.ajax({
type: "POST",
url: "http://unsound.pl/en/festival/localisations_ajax_update/2010",
data: sdata,
dataType: "json",
success: function(data){
if(data.msg=='ok') {
load_data2(data.result);
}
}
});
}
function pokaz(item) {
var marker = lastLoc[item-1].marker;
map.removeOverlay(marker);
}
function moveTo(itemId) {
//map.panTo(new GLatLng(locs[itemId].lat, locs[itemId].lng));
var my_marker = locs[itemId].marker;
var name = locs[itemId].name;
var address = locs[itemId].address;
var town = locs[itemId].town;
var www = locs[itemId].www;
var www_ready = anchorize(www);
var html = 'Name: ' + name + '
';
html += 'Address: ' + address + '
';
html += 'Town: ' + town + '
';
html += 'Website: ' + www_ready + '
';
my_marker.openInfoWindow(html);
}
function adminMoveTo(itemId) {
//map.panTo(new GLatLng(locs[itemId].lat, locs[itemId].lng));
var my_marker = locs[itemId].marker;
var name = locs[itemId].name;
var address = locs[itemId].address;
var town = locs[itemId].town;
var www = locs[itemId].www;
var www_ready = anchorize(www);
var html = 'Name: ' + name + '
';
html += 'Address: ' + address + '
';
html += 'Town: ' + town + '
';
html += 'Website: ' + www_ready + '
';
html += 'EDIT REMOVE
';
my_marker.openInfoWindow(html);
}
validators = {
required:function (param) {
var val = $(this).val();
return !(!val || val.lengthparam);
},
email:function() {
var val = $(this).val();
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
return emailPattern.test(val);
},
float:function() {
var val = $(this).val();
var pattern = /^[-+]?([0-9]*\.[0-9]+|[0-9]+)$/;
return pattern.test(val);
},
onFalse:function(params) {
}
}
$.fn.validate = function(callback) {
if(!callback) callback = function(passed,method,param) {
if(!passed) {
$(this).addClass("error");
errorous = true;
} else {
$(this).removeClass("error");
}
}
var pass = true;
this.each(function() {
$('*[name]', this).each(function() {
var data = $(this).metadata();
for(var fn in data) {
var passed = validators[fn].call(this,data[fn]);
callback.call(this,passed,fn,data);
if(!passed) pass=false;
}
});
});
return pass;
}