Reports | Safecity ---Not Selected---'); $("select[id^='custom_field_']").val("---NOT_SELECTED---"); $("input[id^='custom_field_']:checkbox").removeAttr("checked"); $("input[id^='custom_field_']:radio").removeAttr("checked"); $("input[id^='custom_field_']:text").val(""); // Hide textareas - should really replace with a keyword search field $("textarea[id^='custom_field_']").parent().remove(); // "Choose Date Range"" Datepicker var dates = $( "#report_date_from, #report_date_to" ).datepicker({ defaultDate: "+1w", changeMonth: true, numberOfMonths: 1, onSelect: function( selectedDate ) { var option = this.id == "report_date_from" ? "minDate" : "maxDate", instance = $( this ).data( "datepicker" ), date = $.datepicker.parseDate( instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings ); dates.not( this ).datepicker( "option", option, date ); } }); /** * Date range datepicker box functionality * Show the box when clicking the "change time" link */ $(".btn-change-time").click(function(){ $("#tooltip-box").css({ 'left': ($(this).offset().left - 80), 'top': ($(this).offset().right) }).show(); return false; }); /** * Change time period text in page header to reflect what was clicked * then hide the date range picker box */ $(".btn-date-range").click(function(){ // Change the text $(".time-period").text($(this).attr("title")); // Update the "active" state $(".btn-date-range").removeClass("active"); $(this).addClass("active"); // Date object var d = new Date(); var month = d.getMonth() + 1; if (month < 10) { month = "0" + month; } if ($(this).attr("id") == 'dateRangeAll') { // Clear the date range values $("#report_date_from").val(""); $("#report_date_to").val(""); // Clear the url parameters delete urlParameters['from']; delete urlParameters['to']; delete urlParameters['s']; delete urlParameters['e']; } else if ($(this).attr("id") == 'dateRangeToday') { // Set today's date currentDate = (d.getDate() < 10)? "0"+d.getDate() : d.getDate(); var dateString = month + '/' + currentDate + '/' + d.getFullYear(); $("#report_date_from").val(dateString); $("#report_date_to").val(dateString); } else if ($(this).attr("id") == 'dateRangeWeek') { // Get first day of the week var diff = d.getDate() - d.getDay(); var d1 = new Date(d.setDate(diff)); var d2 = new Date(d.setDate(diff + 6)); // Get the first and last days of the week firstWeekDay = (d1.getDate() < 10)? ("0" + d1.getDate()) : d1.getDate(); lastWeekDay = (d2.getDate() < 10)? ("0" + d2.getDate()) : d2.getDate(); $("#report_date_from").val(month + '/' + firstWeekDay + '/' + d1.getFullYear()); $("#report_date_to").val(month + '/' + lastWeekDay + '/' + d2.getFullYear()); } else if ($(this).attr("id") == 'dateRangeMonth') { d1 = new Date(d.setDate(32)); lastMonthDay = 32 - d1.getDay(); $("#report_date_from").val(month + '/01/' + d.getFullYear()); $("#report_date_to").val(month + '/' + lastMonthDay +'/' + d.getFullYear()); } // Update the url parameters if ($("#report_date_from").val() != '' && $("#report_date_to").val() != '') { urlParameters['from'] = $("#report_date_from").val(); urlParameters['to'] = $("#report_date_to").val(); delete urlParameters['s']; delete urlParameters['e']; } // Hide the box $("#tooltip-box").hide(); return false; }); /** * When the date filter button is clicked */ $("#tooltip-box a.filter-button").click(function(){ // Change the text $(".time-period").text($("#report_date_from").val()+" to "+$("#report_date_to").val()); // Hide the box $("#tooltip-box").hide(); report_date_from = $("#report_date_from").val(); report_date_to = $("#report_date_to").val(); if ($(this).attr("id") == "applyDateFilter" && report_date_from != '' && report_date_to != '') { // Add the parameters urlParameters["from"] = report_date_from; urlParameters["to"] = report_date_to; delete urlParameters['s']; delete urlParameters['e']; // Fetch the reports fetchReports(); } return false; }); // Initialize accordion for Report Filters $( "#accordion" ).accordion({autoHeight: false}); // Report hovering events addReportHoverEvents(); // Events for toggling the report filters addToggleReportsFilterEvents(); // Attach paging events to the paginator attachPagingEvents(); // Attach the "Filter Reports" action attachFilterReportsAction(); // When all the filters are reset $("#reset_all_filters").click(function(){ // Deselect all filters $.each($(".filter-list li a"), function(i, item){ $(item).removeClass("selected"); }); $("select[id^='custom_field_']").val("---NOT_SELECTED---"); $("input[id^='custom_field_']:checkbox").removeAttr("checked"); $("input[id^='custom_field_']:radio").removeAttr("checked"); $("input[id^='custom_field_']:text").val(""); // Reset the url parameters urlParameters = {}; // Fetch all reports fetchReports(); }); $("#accordion").accordion({change: function(event, ui){ if ($(ui.newContent).hasClass("f-location-box")) { if (typeof radiusMap == 'undefined' || radiusMap == null) { // Create the map radiusMap = createMap("divMap", latitude, longitude, defaultZoom); // Add the radius layer addRadiusLayer(radiusMap, latitude, longitude); drawCircle(radiusMap, latitude, longitude); // Detect map clicks radiusMap.events.register("click", radiusMap, function(e){ var lonlat = radiusMap.getLonLatFromViewPortPx(e.xy); var lonlat2 = radiusMap.getLonLatFromViewPortPx(e.xy); m = new OpenLayers.Marker(lonlat); markers.clearMarkers(); markers.addMarker(m); currRadius = $("#alert_radius option:selected").val(); radius = currRadius * 1000 lonlat2.transform(proj_900913, proj_4326); // Store the current latitude and longitude currLat = lonlat2.lat; currLon = lonlat2.lon; drawCircle(radiusMap, currLat, currLon, radius); // Store the radius and start locations urlParameters["radius"] = currRadius; urlParameters["start_loc"] = currLat + "," + currLon; }); // Radius selector $("select#alert_radius").change(function(e, ui) { var newRadius = $("#alert_radius").val(); // Convert to Meters radius = newRadius * 1000;	// Redraw Circle currLat = (currLat == null)? latitude : currLat; currLon = (currLon == null)? longitude : currLon; drawCircle(radiusMap, currLat, currLon, radius); // Store the radius and start locations urlParameters["radius"] = newRadius; urlParameters["start_loc"] = currLat+ "," + currLon; }); } } }}); }); /** * Registers the report hover event */ function addReportHoverEvents() { // Hover functionality for each report $(".rb_report").hover( function () { $(this).addClass("hover"); }, function () { $(this).removeClass("hover"); } ); // Category tooltip functionality var $tt = $('.r_cat_tooltip'); $("a.r_category").hover( function () { // Place the category text inside the category tooltip $tt.find('a').html($(this).find('.r_cat-desc').html()); // Display the category tooltip $tt.css({ 'left': ($(this).offset().left - 6), 'top': ($(this).offset().top - 27) }).show(); }, function () { $tt.hide(); } ); // Show/hide categories and location for a report $("a.btn-show").click(function(){ var $reportBox = $(this).attr("href"); // Hide self $(this).hide(); if ($(this).hasClass("btn-more")) { // Show categories and location $($reportBox + " .r_categories, " + $reportBox + " .r_location").slideDown(); // Show the "show less" link $($reportBox + " a.btn-less").show(); } else if ($(this).hasClass("btn-less")) { // Hide categories and location $($reportBox + " .r_categories, " + $reportBox + " .r_location").slideUp(); // Show the "show more" link $($reportBox + " a.btn-more").attr("style",""); }; return false;	}); } /** * Creates the map and sets the loaded status to 1 */ function createIncidentMap() { // Creates the map map = createMap('rb_map-view', latitude, longitude, defaultZoom); mapLoaded = 1; } function addToggleReportsFilterEvents() { // Checks if a filter exists in the list of deselected items filterExists = function(itemId) { if (deSelectedFilters.length == 0) { return false; } else { for (var i=0; i < deSelectedFilters.length; i++) { if (deSelectedFilters[i] == itemId) { return true; } } return false; } }; // toggle highlighting on the filter lists $(".filter-list li a").toggle( function(){ $(this).addClass("selected"); // Check if the element is in the list of de-selected items and remove it if (deSelectedFilters.length > 0) { var temp = []; for (var i = 0; i 0) { urlParameters["page"] = Number(pageNumber); fetchReports(); } return false; }); return false; } /** * Gets the reports using the specified parameters */ function fetchReports() { //check and see what view was last viewed: list, or map. var lastDisplyedWasMap = $("#rb_map-view").css("display") != "none"; // Reset the map loading tracker mapLoaded = 0; var loadingURL = "https://maps.safecity.in/media/img/loading_g.gif"; var statusHtml = "