PageRenderTime 39ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/themes/default/views/reports/reports_js.php

https://github.com/Magaz/Ushahidi_Web
PHP | 918 lines | 595 code | 148 blank | 175 comment | 132 complexity | 65d5ef7772400ad3debca4014e4ba2f3 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-3.0, BSD-3-Clause, GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Reports listing js file.
  4. *
  5. * Handles javascript stuff related to reports list function.
  6. *
  7. * PHP version 5
  8. * LICENSE: This source file is subject to LGPL license
  9. * that is available through the world-wide-web at the following URI:
  10. * http://www.gnu.org/copyleft/lesser.html
  11. * @author Ushahidi Team <team@ushahidi.com>
  12. * @package Ushahidi - http://source.ushahididev.com
  13. * @module Reports Controller
  14. * @copyright Ushahidi - http://www.ushahidi.com
  15. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)
  16. */
  17. ?>
  18. <?php @require_once(APPPATH.'views/map_common_js.php'); ?>
  19. // Tracks the current URL parameters
  20. var urlParameters = <?php echo $url_params; ?>;
  21. var deSelectedFilters = [];
  22. // Lat/lon and zoom for the map
  23. var latitude = <?php echo $latitude; ?>;
  24. var longitude = <?php echo $longitude; ?>;
  25. var defaultZoom = <?php echo $default_zoom; ?>;
  26. // Track the current latitude and longitude on the alert radius map
  27. var currLat, currLon;
  28. // Tracks whether the map has already been loaded
  29. var mapLoaded = 0;
  30. // Map object
  31. var map = null;
  32. var radiusMap = null;
  33. if (urlParameters.length == 0)
  34. {
  35. urlParameters = {};
  36. }
  37. $(document).ready(function() {
  38. //add Not Selected values to the custom form fields that are drop downs
  39. $("select[id^='custom_field_']").prepend('<option value="---NOT_SELECTED---"><?php echo Kohana::lang("ui_main.not_selected"); ?></option>');
  40. $("select[id^='custom_field_']").val("---NOT_SELECTED---");
  41. $("input[id^='custom_field_']:checkbox").removeAttr("checked");
  42. $("input[id^='custom_field_']:radio").removeAttr("checked");
  43. $("input[id^='custom_field_']:text").val("");
  44. // Hide textareas - should really replace with a keyword search field
  45. $("textarea[id^='custom_field_']").parent().remove();
  46. // "Choose Date Range"" Datepicker
  47. var dates = $( "#report_date_from, #report_date_to" ).datepicker({
  48. defaultDate: "+1w",
  49. changeMonth: true,
  50. numberOfMonths: 1,
  51. onSelect: function( selectedDate ) {
  52. var option = this.id == "report_date_from" ? "minDate" : "maxDate",
  53. instance = $( this ).data( "datepicker" ),
  54. date = $.datepicker.parseDate(
  55. instance.settings.dateFormat ||
  56. $.datepicker._defaults.dateFormat,
  57. selectedDate, instance.settings );
  58. dates.not( this ).datepicker( "option", option, date );
  59. }
  60. });
  61. /**
  62. * Date range datepicker box functionality
  63. * Show the box when clicking the "change time" link
  64. */
  65. $(".btn-change-time").click(function(){
  66. $("#tooltip-box").css({
  67. 'left': ($(this).offset().left - 80),
  68. 'top': ($(this).offset().right)
  69. }).show();
  70. return false;
  71. });
  72. /**
  73. * Change time period text in page header to reflect what was clicked
  74. * then hide the date range picker box
  75. */
  76. $(".btn-date-range").click(function(){
  77. // Change the text
  78. $(".time-period").text($(this).attr("title"));
  79. // Update the "active" state
  80. $(".btn-date-range").removeClass("active");
  81. $(this).addClass("active");
  82. // Date object
  83. var d = new Date();
  84. var month = d.getMonth() + 1;
  85. if (month < 10)
  86. {
  87. month = "0" + month;
  88. }
  89. if ($(this).attr("id") == 'dateRangeAll')
  90. {
  91. // Clear the date range values
  92. $("#report_date_from").val("");
  93. $("#report_date_to").val("");
  94. // Clear the url parameters
  95. delete urlParameters['from'];
  96. delete urlParameters['to'];
  97. delete urlParameters['s'];
  98. delete urlParameters['e'];
  99. }
  100. else if ($(this).attr("id") == 'dateRangeToday')
  101. {
  102. // Set today's date
  103. currentDate = (d.getDate() < 10)? "0"+d.getDate() : d.getDate();
  104. var dateString = month + '/' + currentDate + '/' + d.getFullYear();
  105. $("#report_date_from").val(dateString);
  106. $("#report_date_to").val(dateString);
  107. }
  108. else if ($(this).attr("id") == 'dateRangeWeek')
  109. {
  110. // Get first day of the week
  111. var diff = d.getDate() - d.getDay();
  112. var d1 = new Date(d.setDate(diff));
  113. var d2 = new Date(d.setDate(diff + 6));
  114. // Get the first and last days of the week
  115. firstWeekDay = (d1.getDate() < 10)? ("0" + d1.getDate()) : d1.getDate();
  116. lastWeekDay = (d2.getDate() < 10)? ("0" + d2.getDate()) : d2.getDate();
  117. $("#report_date_from").val(month + '/' + firstWeekDay + '/' + d1.getFullYear());
  118. $("#report_date_to").val(month + '/' + lastWeekDay + '/' + d2.getFullYear());
  119. }
  120. else if ($(this).attr("id") == 'dateRangeMonth')
  121. {
  122. d1 = new Date(d.setDate(32));
  123. lastMonthDay = 32 - d1.getDay();
  124. $("#report_date_from").val(month + '/01/' + d.getFullYear());
  125. $("#report_date_to").val(month + '/' + lastMonthDay +'/' + d.getFullYear());
  126. }
  127. // Update the url parameters
  128. if ($("#report_date_from").val() != '' && $("#report_date_to").val() != '')
  129. {
  130. urlParameters['from'] = $("#report_date_from").val();
  131. urlParameters['to'] = $("#report_date_to").val();
  132. delete urlParameters['s'];
  133. delete urlParameters['e'];
  134. }
  135. // Hide the box
  136. $("#tooltip-box").hide();
  137. return false;
  138. });
  139. /**
  140. * When the date filter button is clicked
  141. */
  142. $("#tooltip-box a.filter-button").click(function(){
  143. // Change the text
  144. $(".time-period").text($("#report_date_from").val()+" to "+$("#report_date_to").val());
  145. // Hide the box
  146. $("#tooltip-box").hide();
  147. report_date_from = $("#report_date_from").val();
  148. report_date_to = $("#report_date_to").val();
  149. if ($(this).attr("id") == "applyDateFilter" && report_date_from != '' && report_date_to != '')
  150. {
  151. // Add the parameters
  152. urlParameters["from"] = report_date_from;
  153. urlParameters["to"] = report_date_to;
  154. delete urlParameters['s'];
  155. delete urlParameters['e'];
  156. // Fetch the reports
  157. fetchReports();
  158. }
  159. return false;
  160. });
  161. // Initialize accordion for Report Filters
  162. $( "#accordion" ).accordion({autoHeight: false});
  163. // Report hovering events
  164. addReportHoverEvents();
  165. // Events for toggling the report filters
  166. addToggleReportsFilterEvents();
  167. // Attach paging events to the paginator
  168. attachPagingEvents();
  169. // Attach the "Filter Reports" action
  170. attachFilterReportsAction();
  171. // When all the filters are reset
  172. $("#reset_all_filters").click(function(){
  173. // Deselect all filters
  174. $.each($(".filter-list li a"), function(i, item){
  175. $(item).removeClass("selected");
  176. });
  177. $("select[id^='custom_field_']").val("---NOT_SELECTED---");
  178. $("input[id^='custom_field_']:checkbox").removeAttr("checked");
  179. $("input[id^='custom_field_']:radio").removeAttr("checked");
  180. $("input[id^='custom_field_']:text").val("");
  181. // Reset the url parameters
  182. urlParameters = {};
  183. // Fetch all reports
  184. fetchReports();
  185. });
  186. $("#accordion").accordion({change: function(event, ui){
  187. if ($(ui.newContent).hasClass("f-location-box"))
  188. {
  189. if (typeof radiusMap == 'undefined' || radiusMap == null)
  190. {
  191. // Create the map
  192. radiusMap = createMap("divMap", latitude, longitude, defaultZoom);
  193. // Add the radius layer
  194. addRadiusLayer(radiusMap, latitude, longitude);
  195. drawCircle(radiusMap, latitude, longitude);
  196. // Detect map clicks
  197. radiusMap.events.register("click", radiusMap, function(e){
  198. var lonlat = radiusMap.getLonLatFromViewPortPx(e.xy);
  199. var lonlat2 = radiusMap.getLonLatFromViewPortPx(e.xy);
  200. m = new OpenLayers.Marker(lonlat);
  201. markers.clearMarkers();
  202. markers.addMarker(m);
  203. currRadius = $("#alert_radius option:selected").val();
  204. radius = currRadius * 1000
  205. lonlat2.transform(proj_900913, proj_4326);
  206. // Store the current latitude and longitude
  207. currLat = lonlat2.lat;
  208. currLon = lonlat2.lon;
  209. drawCircle(radiusMap, currLat, currLon, radius);
  210. // Store the radius and start locations
  211. urlParameters["radius"] = currRadius;
  212. urlParameters["start_loc"] = currLat + "," + currLon;
  213. });
  214. // Radius selector
  215. $("select#alert_radius").change(function(e, ui) {
  216. var newRadius = $("#alert_radius").val();
  217. // Convert to Meters
  218. radius = newRadius * 1000;
  219. // Redraw Circle
  220. currLat = (currLat == null)? latitude : currLat;
  221. currLon = (currLon == null)? longitude : currLon;
  222. drawCircle(radiusMap, currLat, currLon, radius);
  223. // Store the radius and start locations
  224. urlParameters["radius"] = newRadius;
  225. urlParameters["start_loc"] = currLat+ "," + currLon;
  226. });
  227. }
  228. }
  229. }});
  230. });
  231. /**
  232. * Registers the report hover event
  233. */
  234. function addReportHoverEvents()
  235. {
  236. // Hover functionality for each report
  237. $(".rb_report").hover(
  238. function () {
  239. $(this).addClass("hover");
  240. },
  241. function () {
  242. $(this).removeClass("hover");
  243. }
  244. );
  245. // Category tooltip functionality
  246. var $tt = $('.r_cat_tooltip');
  247. $("a.r_category").hover(
  248. function () {
  249. // Place the category text inside the category tooltip
  250. $tt.find('a').html($(this).find('.r_cat-desc').html());
  251. // Display the category tooltip
  252. $tt.css({
  253. 'left': ($(this).offset().left - 6),
  254. 'top': ($(this).offset().top - 27)
  255. }).show();
  256. },
  257. function () {
  258. $tt.hide();
  259. }
  260. );
  261. // Show/hide categories and location for a report
  262. $("a.btn-show").click(function(){
  263. var $reportBox = $(this).attr("href");
  264. // Hide self
  265. $(this).hide();
  266. if ($(this).hasClass("btn-more"))
  267. {
  268. // Show categories and location
  269. $($reportBox + " .r_categories, " + $reportBox + " .r_location").slideDown();
  270. // Show the "show less" link
  271. $($reportBox + " a.btn-less").show();
  272. }
  273. else if ($(this).hasClass("btn-less"))
  274. {
  275. // Hide categories and location
  276. $($reportBox + " .r_categories, " + $reportBox + " .r_location").slideUp();
  277. // Show the "show more" link
  278. $($reportBox + " a.btn-more").attr("style","");
  279. };
  280. return false;
  281. });
  282. }
  283. /**
  284. * Creates the map and sets the loaded status to 1
  285. */
  286. function createIncidentMap()
  287. {
  288. // Creates the map
  289. map = createMap('rb_map-view', latitude, longitude, defaultZoom);
  290. mapLoaded = 1;
  291. }
  292. function addToggleReportsFilterEvents()
  293. {
  294. // Checks if a filter exists in the list of deselected items
  295. filterExists = function(itemId) {
  296. if (deSelectedFilters.length == 0)
  297. {
  298. return false;
  299. }
  300. else
  301. {
  302. for (var i=0; i < deSelectedFilters.length; i++)
  303. {
  304. if (deSelectedFilters[i] == itemId)
  305. {
  306. return true;
  307. }
  308. }
  309. return false;
  310. }
  311. };
  312. // toggle highlighting on the filter lists
  313. $(".filter-list li a").toggle(
  314. function(){
  315. $(this).addClass("selected");
  316. // Check if the element is in the list of de-selected items and remove it
  317. if (deSelectedFilters.length > 0)
  318. {
  319. var temp = [];
  320. for (var i = 0; i<deSelectedFilters.length; i++)
  321. {
  322. if (deSelectedFilters[i] != $(this).attr("id"))
  323. {
  324. temp.push(deSelectedFilters[i]);
  325. }
  326. }
  327. deSelectedFilters = temp;
  328. }
  329. },
  330. function(){
  331. if ($(this).hasClass("selected"))
  332. {
  333. elementId = $(this).attr("id");
  334. // Add the id of the deselected filter
  335. if ( ! filterExists(elementId))
  336. {
  337. deSelectedFilters.push(elementId);
  338. }
  339. // Update the parameter value for the deselected filter
  340. removeDeselectedReportFilter(elementId);
  341. }
  342. $(this).removeClass("selected");
  343. }
  344. );
  345. }
  346. /**
  347. * Switch Views map, or list
  348. */
  349. function switchViews(view)
  350. {
  351. // Hide both divs
  352. $("#rb_list-view, #rb_map-view").hide();
  353. // Show the appropriate div
  354. $($(view).attr("href")).show();
  355. // Remove the class "selected" from all parent li's
  356. $("#reports-box .report-list-toggle a").parent().removeClass("active");
  357. // Add class "selected" to both instances of the clicked link toggle
  358. $("."+$(view).attr("class")).parent().addClass("active");
  359. // Check if the map view is active
  360. if ($("#rb_map-view").css("display") == "block")
  361. {
  362. // Check if the map has already been created
  363. if (mapLoaded == 0)
  364. {
  365. createIncidentMap();
  366. }
  367. // Set the current page
  368. urlParameters["page"] = $(".pager li a.active").html();
  369. // Load the map
  370. setTimeout(function(){ showIncidentMap() }, 400);
  371. }
  372. return false;
  373. }
  374. /**
  375. * List/map view toggle
  376. */
  377. function addReportViewOptionsEvents()
  378. {
  379. $("#reports-box .report-list-toggle a").click(function(){
  380. return switchViews($(this));
  381. });
  382. }
  383. /**
  384. * Attaches paging events to the paginator
  385. */
  386. function attachPagingEvents()
  387. {
  388. // Add event handler that allows switching between list view and map view
  389. addReportViewOptionsEvents();
  390. // Remove page links for the metadata pager
  391. $("ul.pager a").attr("href", "#");
  392. $("ul.pager a").click(function() {
  393. // Add the clicked page to the url parameters
  394. urlParameters["page"] = $(this).html();
  395. // Fetch the reports
  396. fetchReports();
  397. return false;
  398. });
  399. $("td.last li a").click(function(){
  400. pageNumber = $(this).attr("id").substr("page_".length);
  401. if (Number(pageNumber) > 0)
  402. {
  403. urlParameters["page"] = Number(pageNumber);
  404. fetchReports();
  405. }
  406. return false;
  407. });
  408. return false;
  409. }
  410. /**
  411. * Gets the reports using the specified parameters
  412. */
  413. function fetchReports()
  414. {
  415. //check and see what view was last viewed: list, or map.
  416. var lastDisplyedWasMap = $("#rb_map-view").css("display") != "none";
  417. // Reset the map loading tracker
  418. mapLoaded = 0;
  419. var loadingURL = "<?php echo url::file_loc('img').'media/img/loading_g.gif'; ?>";
  420. var statusHtml = "<div style=\"width: 100%; margin-top: 100px;\" align=\"center\">" +
  421. "<div><img src=\""+loadingURL+"\" border=\"0\"></div>" +
  422. "<p style=\"padding: 10px 2px;\"><h3><?php echo Kohana::lang('ui_main.loading_reports'); ?>...</h3></p>" +
  423. "</div>";
  424. $("#reports-box").html(statusHtml);
  425. // Check if there are any parameters
  426. if ($.isEmptyObject(urlParameters))
  427. {
  428. urlParameters = {show: "all"}
  429. }
  430. // Get the content for the new page
  431. $.get('<?php echo url::site().'reports/fetch_reports'?>',
  432. urlParameters,
  433. function(data) {
  434. if (data != null && data != "" && data.length > 0) {
  435. // Animation delay
  436. setTimeout(function(){
  437. $("#reports-box").html(data);
  438. attachPagingEvents();
  439. addReportHoverEvents();
  440. deSelectedFilters = [];
  441. //if the map was the last thing the user was looking at:
  442. if(lastDisplyedWasMap)
  443. {
  444. switchViews($("#reports-box .report-list-toggle a.map"));
  445. }
  446. }, 400);
  447. }
  448. }
  449. );
  450. }
  451. /**
  452. * Removes the deselected report filters from the list
  453. * of filters for fetching the reports
  454. */
  455. function removeDeselectedReportFilter(elementId)
  456. {
  457. // Removes a parameter item from urlParameters
  458. removeParameterItem = function(key, val) {
  459. if (! $.isEmptyObject(urlParameters))
  460. {
  461. // Get the object type
  462. objectType = Object.prototype.toString.call(urlParameters[key]);
  463. if (objectType == "[object Array]")
  464. {
  465. currentItems = urlParameters[key];
  466. newItems = [];
  467. for (var j=0; j < currentItems.length; j++)
  468. {
  469. if (currentItems[j] != val)
  470. {
  471. newItems.push(currentItems[j]);
  472. }
  473. }
  474. if (newItems.length > 0)
  475. {
  476. urlParameters[key] = newItems;
  477. }
  478. else
  479. {
  480. delete urlParameters[key];
  481. }
  482. }
  483. else if (objectType == "[object String]")
  484. {
  485. delete urlParameters[key];
  486. }
  487. }
  488. }
  489. if (deSelectedFilters.length > 0)
  490. {
  491. // Check for category filter
  492. if (elementId.indexOf('filter_link_cat_') != -1){
  493. catId = elementId.substring('filter_link_cat_'.length);
  494. removeParameterItem("c", catId);
  495. }
  496. else if (elementId.indexOf('filter_link_mode_') != -1)
  497. {
  498. modeId = elementId.substring('filter_link_mode_'.length);
  499. removeParameterItem("mode", modeId);
  500. }
  501. else if (elementId.indexOf('filter_link_media_') != -1)
  502. {
  503. mediaType = elementId.substring('filter_link_media_'.length);
  504. removeParameterItem("m", mediaType);
  505. }
  506. else if (elementId.indexOf('filter_link_verification_') != -1)
  507. {
  508. verification = elementId.substring('filter_link_verification_'.length);
  509. removeParameterItem("v", verification);
  510. }
  511. }
  512. }
  513. /**
  514. * Adds an event handler for the "Filter reports" button
  515. */
  516. function attachFilterReportsAction()
  517. {
  518. $("#applyFilters").click(function(){
  519. //
  520. // Get all the selected categories
  521. //
  522. var category_ids = [];
  523. $.each($(".fl-categories li a.selected"), function(i, item){
  524. itemId = item.id.substring("filter_link_cat_".length);
  525. // Check if category 0, "All categories" has been selected
  526. category_ids.push(itemId);
  527. });
  528. if (category_ids.length > 0)
  529. {
  530. urlParameters["c"] = category_ids;
  531. }
  532. //
  533. // Get the incident modes
  534. //
  535. var incidentModes = [];
  536. $.each($(".fl-incident-mode li a.selected"), function(i, item){
  537. modeId = item.id.substring("filter_link_mode_".length);
  538. incidentModes.push(modeId);
  539. });
  540. if (incidentModes.length > 0)
  541. {
  542. urlParameters["mode"] = incidentModes;
  543. }
  544. //
  545. // Get the media type
  546. //
  547. var mediaTypes = [];
  548. $.each($(".fl-media li a.selected"), function(i, item){
  549. mediaId = item.id.substring("filter_link_media_".length);
  550. mediaTypes.push(mediaId);
  551. });
  552. if (mediaTypes.length > 0)
  553. {
  554. urlParameters["m"] = mediaTypes;
  555. }
  556. // Get the verification status
  557. var verificationStatus = [];
  558. $.each($(".fl-verification li a.selected"), function(i, item){
  559. statusVal = item.id.substring("filter_link_verification_".length);
  560. verificationStatus.push(statusVal);
  561. });
  562. if (verificationStatus.length > 0)
  563. {
  564. urlParameters["v"] = verificationStatus;
  565. }
  566. //
  567. // Get the Custom Form Fields
  568. //
  569. var customFields = new Array();
  570. var checkBoxId = null;
  571. var checkBoxArray = new Array();
  572. $.each($("input[id^='custom_field_']"), function(i, item) {
  573. var cffId = item.id.substring("custom_field_".length);
  574. var value = $(item).val();
  575. var type = $(item).attr("type");
  576. if(type == "text")
  577. {
  578. if(value != "" && value != undefined && value != null)
  579. {
  580. customFields.push([cffId, value]);
  581. }
  582. }
  583. else if(type == "radio")
  584. {
  585. if($(item).attr("checked"))
  586. {
  587. customFields.push([cffId, value]);
  588. }
  589. }
  590. else if(type == "checkbox")
  591. {
  592. if($(item).attr("checked"))
  593. {
  594. checkBoxId = cffId;
  595. checkBoxArray.push(value);
  596. }
  597. }
  598. if(type != "checkbox" && checkBoxId != null)
  599. {
  600. customFields.push([checkBoxId, checkBoxArray]);
  601. checkBoxId = null;
  602. checkBoxArray = new Array();
  603. }
  604. });
  605. //incase the last field was a checkbox
  606. if(checkBoxId != null)
  607. {
  608. customFields.push([checkBoxId, checkBoxArray]);
  609. }
  610. //now selects
  611. $.each($("select[id^='custom_field_']"), function(i, item) {
  612. var cffId = item.id.substring("custom_field_".length);
  613. var value = $(item).val();
  614. if(value != "---NOT_SELECTED---")
  615. {
  616. customFields.push([cffId, value]);
  617. }
  618. });
  619. if(customFields.length > 0)
  620. {
  621. urlParameters["cff"] = customFields;
  622. }
  623. else
  624. {
  625. delete urlParameters["cff"];
  626. }
  627. // Fetch the reports
  628. fetchReports();
  629. });
  630. }
  631. /**
  632. * Makes a url string for the map stuff
  633. */
  634. function makeUrlParamStr(str, params, arrayLevel)
  635. {
  636. //make sure arrayLevel is initialized
  637. var arrayLevelStr = "";
  638. if(arrayLevel != undefined)
  639. {
  640. arrayLevelStr = arrayLevel;
  641. }
  642. var separator = "";
  643. for(i in params)
  644. {
  645. //do we need to insert a separator?
  646. if(str.length > 0)
  647. {
  648. separator = "&";
  649. }
  650. //get the param
  651. var param = params[i];
  652. //is it an array or not
  653. if($.isArray(param))
  654. {
  655. if(arrayLevelStr == "")
  656. {
  657. str = makeUrlParamStr(str, param, i);
  658. }
  659. else
  660. {
  661. str = makeUrlParamStr(str, param, arrayLevelStr + "%5B" + i + "%5D");
  662. }
  663. }
  664. else
  665. {
  666. if(arrayLevelStr == "")
  667. {
  668. str += separator + i + "=" + param.toString();
  669. }
  670. else
  671. {
  672. str += separator + arrayLevelStr + "%5B" + i + "%5D=" + param.toString();
  673. }
  674. }
  675. }
  676. return str;
  677. }
  678. /**
  679. * Handles display of the incidents current incidents on the map
  680. * This method is only called when the map view is selected
  681. */
  682. function showIncidentMap()
  683. {
  684. // URL to be used for fetching the incidents
  685. fetchURL = '<?php echo url::site().'json/index' ;?>';
  686. // Generate the url parameter string
  687. parameterStr = makeUrlParamStr("", urlParameters)
  688. // Add the parameters to the fetch URL
  689. fetchURL += '?' + parameterStr;
  690. // Fetch the incidents
  691. // Set the layer name
  692. var layerName = '<?php echo Kohana::lang('ui_main.reports')?>';
  693. // Get all current layers with the same name and remove them from the map
  694. currentLayers = map.getLayersByName(layerName);
  695. for (var i = 0; i < currentLayers.length; i++)
  696. {
  697. map.removeLayer(currentLayers[i]);
  698. }
  699. // Styling for the incidents
  700. reportStyle = new OpenLayers.Style({
  701. pointRadius: "8",
  702. fillColor: "#30E900",
  703. fillOpacity: "0.8",
  704. strokeColor: "#197700",
  705. strokeWidth: 3,
  706. graphicZIndex: 1
  707. });
  708. // Apply transform to each feature before adding it to the layer
  709. preFeatureInsert = function(feature)
  710. {
  711. var point = new OpenLayers.Geometry.Point(feature.geometry.x, feature.geometry.y);
  712. OpenLayers.Projection.transform(point, proj_4326, proj_900913);
  713. };
  714. // Create vector layer
  715. vLayer = new OpenLayers.Layer.Vector(layerName, {
  716. projection: map.displayProjection,
  717. extractAttributes: true,
  718. styleMap: new OpenLayers.StyleMap({'default' : reportStyle}),
  719. strategies: [new OpenLayers.Strategy.Fixed()],
  720. protocol: new OpenLayers.Protocol.HTTP({
  721. url: fetchURL,
  722. format: new OpenLayers.Format.GeoJSON()
  723. })
  724. });
  725. // Add the vector layer to the map
  726. map.addLayer(vLayer);
  727. // Add feature selection events
  728. addFeatureSelectionEvents(map, vLayer);
  729. }
  730. /**
  731. * Clears the filter for a particular section
  732. * @param {string} parameterKey: Key of the parameter remove from the list of url parameters
  733. * @param {string} filterClass: CSS class of the section containing the filters
  734. */
  735. function removeParameterKey(parameterKey, filterClass)
  736. {
  737. if (typeof parameterKey == 'undefined' || typeof parameterKey != 'string')
  738. return;
  739. if (typeof $("."+filterClass) == 'undefined')
  740. return;
  741. if(parameterKey == "cff") //It's Cutom Form Fields baby
  742. {
  743. $.each($("input[id^='custom_field_']"), function(i, item){
  744. if($(item).attr("type") == "checkbox" || $(item).attr("type") == "radio")
  745. {
  746. $(item).removeAttr("checked");
  747. }
  748. else
  749. {
  750. $(item).val("");
  751. }
  752. });
  753. $("select[id^='custom_field_']").val("---NOT_SELECTED---");
  754. }
  755. else //it's just some simple removing of a class
  756. {
  757. // Deselect
  758. $.each($("." + filterClass +" li a.selected"), function(i, item){
  759. $(item).removeClass("selected");
  760. });
  761. //if it's the location filter be sure to get rid of sw and ne
  762. if(parameterKey == "start_loc" || parameterKey == "radius")
  763. {
  764. delete urlParameters["sw"];
  765. delete urlParameters["ne"];
  766. }
  767. }
  768. // Remove the parameter key from urlParameters
  769. delete urlParameters[parameterKey];
  770. }