{jq}
var mapId = {{$input.mapId|json_encode}};
function refresh_legend() {
var $form = $('#map-legend');
$.getJSON($form.attr('action'), $form.serialize())
.success(function (data) {
var ul = $form.find('ul').empty();
$.each(data, function (k, entry) {
var item = $('')
.text(entry.title)
.prepend($('').attr('src', entry.tracker_field_legendIcon))
.appendTo(ul);
if (mapId == entry.tracker_field_map) {
item.append($('')
.text(tr('Edit'))
.attr('href', $.service('tracker', 'update_item', {
trackerId: entry.tracker_id,
itemId: entry.object_id
})));
item.append($('')
.text(tr('Delete'))
.attr('href', $.service('tracker', 'remove_item', {
trackerId: entry.tracker_id,
itemId: entry.object_id
})));
item.find('a')
.click(function () {
$(this).serviceDialog({
success: refresh_legend
});
return false;
});
}
});
});
}
refresh_legend();
setInterval(refresh_legend, 120*1000);
$('#map-legend-add').submit(function () {
$(this).serviceDialog({
title: $(':submit', this).val(),
controller: 'tracker',
action: 'insert_item',
data: $(this).serialize(),
success: refresh_legend
});
return false;
});
{/jq}