PageRenderTime 59ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/application/views/reports_js.php

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