"; $("#reports-box").html(statusHtml); // Check if there are any parameters if ($.isEmptyObject(urlParameters)) { urlParameters = {show: "all"} } // Get the content for the new page $.get('https://maps.safecity.in/reports/fetch_reports', urlParameters, function(data) { if (data != null && data != "" && data.length > 0) { // Animation delay setTimeout(function(){ $("#reports-box").html(data); attachPagingEvents(); addReportHoverEvents(); deSelectedFilters = []; //if the map was the last thing the user was looking at: if(lastDisplyedWasMap) { switchViews($("#reports-box .report-list-toggle a.map")); } }, 400); } } ); } /** * Removes the deselected report filters from the list * of filters for fetching the reports */ function removeDeselectedReportFilter(elementId) { // Removes a parameter item from urlParameters removeParameterItem = function(key, val) { if (! $.isEmptyObject(urlParameters)) { // Get the object type objectType = Object.prototype.toString.call(urlParameters[key]); if (objectType == "[object Array]") { currentItems = urlParameters[key]; newItems = []; for (var j=0; j < currentItems.length; j++) { if (currentItems[j] != val) { newItems.push(currentItems[j]); } } if (newItems.length > 0) { urlParameters[key] = newItems; } else { delete urlParameters[key]; } } else if (objectType == "[object String]") { delete urlParameters[key]; } } } if (deSelectedFilters.length > 0) { // Check for category filter if (elementId.indexOf('filter_link_cat_') != -1){ catId = elementId.substring('filter_link_cat_'.length); removeParameterItem("c", catId); } else if (elementId.indexOf('filter_link_mode_') != -1) { modeId = elementId.substring('filter_link_mode_'.length); removeParameterItem("mode", modeId); } else if (elementId.indexOf('filter_link_media_') != -1) { mediaType = elementId.substring('filter_link_media_'.length); removeParameterItem("m", mediaType); } else if (elementId.indexOf('filter_link_verification_') != -1) { verification = elementId.substring('filter_link_verification_'.length); removeParameterItem("v", verification); } } } /** * Adds an event handler for the "Filter reports" button */ function attachFilterReportsAction() { $("#applyFilters").click(function(){ // // Get all the selected categories // var category_ids = []; $.each($(".fl-categories li a.selected"), function(i, item){ itemId = item.id.substring("filter_link_cat_".length); // Check if category 0, "All categories" has been selected category_ids.push(itemId); }); if (category_ids.length > 0) { urlParameters["c"] = category_ids; } // // Get the incident modes // var incidentModes = []; $.each($(".fl-incident-mode li a.selected"), function(i, item){ modeId = item.id.substring("filter_link_mode_".length); incidentModes.push(modeId); }); if (incidentModes.length > 0) { urlParameters["mode"] = incidentModes; } // // Get the media type // var mediaTypes = []; $.each($(".fl-media li a.selected"), function(i, item){ mediaId = item.id.substring("filter_link_media_".length); mediaTypes.push(mediaId); }); if (mediaTypes.length > 0) { urlParameters["m"] = mediaTypes; } // Get the verification status var verificationStatus = []; $.each($(".fl-verification li a.selected"), function(i, item){ statusVal = item.id.substring("filter_link_verification_".length); verificationStatus.push(statusVal); }); if (verificationStatus.length > 0) { urlParameters["v"] = verificationStatus; } // // Get the Custom Form Fields // var customFields = new Array(); var checkBoxId = null; var checkBoxArray = new Array(); $.each($("input[id^='custom_field_']"), function(i, item) { var cffId = item.id.substring("custom_field_".length); var value = $(item).val(); var type = $(item).attr("type"); if(type == "text") { if(value != "" && value != undefined && value != null) { customFields.push([cffId, value]); } } else if(type == "radio") { if($(item).attr("checked")) { customFields.push([cffId, value]); } } else if(type == "checkbox") { if($(item).attr("checked")) { checkBoxId = cffId; checkBoxArray.push(value); } } if(type != "checkbox" && checkBoxId != null) { customFields.push([checkBoxId, checkBoxArray]); checkBoxId = null; checkBoxArray = new Array(); } }); //incase the last field was a checkbox if(checkBoxId != null) { customFields.push([checkBoxId, checkBoxArray]);	} //now selects $.each($("select[id^='custom_field_']"), function(i, item) { var cffId = item.id.substring("custom_field_".length); var value = $(item).val(); if(value != "---NOT_SELECTED---") { customFields.push([cffId, value]); } }); if(customFields.length > 0) { urlParameters["cff"] = customFields; } else { delete urlParameters["cff"]; } // Fetch the reports fetchReports(); }); } /** * Makes a url string for the map stuff */ function makeUrlParamStr(str, params, arrayLevel)	{ //make sure arrayLevel is initialized var arrayLevelStr = ""; if(arrayLevel != undefined) { arrayLevelStr = arrayLevel; } var separator = ""; for(i in params) { //do we need to insert a separator? if(str.length > 0) { separator = "&"; } //get the param var param = params[i]; //is it an array or not if($.isArray(param)) { if(arrayLevelStr == "") { str = makeUrlParamStr(str, param, i); } else { str = makeUrlParamStr(str, param, arrayLevelStr + "%5B" + i + "%5D"); } } else { if(arrayLevelStr == "") { str += separator + i + "=" + param.toString(); } else { str += separator + arrayLevelStr + "%5B" + i + "%5D=" + param.toString(); } } } return str; } /** * Handles display of the incidents current incidents on the map * This method is only called when the map view is selected */ function showIncidentMap() { // URL to be used for fetching the incidents fetchURL = 'https://maps.safecity.in/json/index'; // Generate the url parameter string parameterStr = makeUrlParamStr("", urlParameters) // Add the parameters to the fetch URL fetchURL += '?' + parameterStr; // Fetch the incidents // Set the layer name var layerName = 'Reports'; // Get all current layers with the same name and remove them from the map currentLayers = map.getLayersByName(layerName); for (var i = 0; i < currentLayers.length; i++) { map.removeLayer(currentLayers[i]); } // Styling for the incidents reportStyle = new OpenLayers.Style({ pointRadius: "8", fillColor: "#30E900", fillOpacity: "0.8", strokeColor: "#197700", strokeWidth: 3, graphicZIndex: 1 }); // Apply transform to each feature before adding it to the layer preFeatureInsert = function(feature) { var point = new OpenLayers.Geometry.Point(feature.geometry.x, feature.geometry.y); OpenLayers.Projection.transform(point, proj_4326, proj_900913); }; // Create vector layer vLayer = new OpenLayers.Layer.Vector(layerName, { projection: map.displayProjection, extractAttributes: true, styleMap: new OpenLayers.StyleMap({'default' : reportStyle}), strategies: [new OpenLayers.Strategy.Fixed()], protocol: new OpenLayers.Protocol.HTTP({ url: fetchURL, format: new OpenLayers.Format.GeoJSON() }) }); // Add the vector layer to the map map.addLayer(vLayer); // Add feature selection events addFeatureSelectionEvents(map, vLayer); } /** * Clears the filter for a particular section * @param {string} parameterKey: Key of the parameter remove from the list of url parameters * @param {string} filterClass: CSS class of the section containing the filters */ function removeParameterKey(parameterKey, filterClass) { if (typeof parameterKey == 'undefined' || typeof parameterKey != 'string') return; if (typeof $("."+filterClass) == 'undefined') return; if(parameterKey == "cff") //It's Cutom Form Fields baby { $.each($("input[id^='custom_field_']"), function(i, item){ if($(item).attr("type") == "checkbox" || $(item).attr("type") == "radio") { $(item).removeAttr("checked"); } else { $(item).val(""); } });	$("select[id^='custom_field_']").val("---NOT_SELECTED---"); } else //it's just some simple removing of a class { // Deselect $.each($("." + filterClass +" li a.selected"), function(i, item){ $(item).removeClass("selected"); });	//if it's the location filter be sure to get rid of sw and ne if(parameterKey == "start_loc" || parameterKey == "radius") { delete urlParameters["sw"]; delete urlParameters["ne"]; } } // Remove the parameter key from urlParameters delete urlParameters[parameterKey]; } //]]>