PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/application/views/admin/reports/reports_js.php

https://github.com/lucaspottersky/Ushahidi_Web
PHP | 211 lines | 135 code | 36 blank | 40 comment | 14 complexity | 5e79397247b3c9be5ef80768e70ef2c6 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-2.0, AGPL-1.0, LGPL-3.0
  1. /**
  2. * Main reports js file.
  3. *
  4. * Handles javascript stuff related to reports function.
  5. *
  6. * PHP version 5
  7. * LICENSE: This source file is subject to LGPL license
  8. * that is available through the world-wide-web at the following URI:
  9. * http://www.gnu.org/copyleft/lesser.html
  10. * @author Ushahidi Team <team@ushahidi.com>
  11. * @package Ushahidi - http://source.ushahididev.com
  12. * @module API Controller
  13. * @copyright Ushahidi - http://www.ushahidi.com
  14. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)
  15. */
  16. <?php require SYSPATH.'../application/views/admin/utils_js.php' ?>
  17. // Ajax Submission
  18. function reportAction ( action, confirmAction, incident_id )
  19. {
  20. var statusMessage;
  21. if( !isChecked( "incident" ) && incident_id=='' )
  22. {
  23. alert('Please select at least one report.');
  24. } else {
  25. var answer = confirm('<?php echo Kohana::lang('ui_admin.are_you_sure_you_want_to'); ?> ' + confirmAction + '?')
  26. if (answer){
  27. // Set Submit Type
  28. $("#action").attr("value", action);
  29. var $incident_single = $(document.getElementById("incident_single"))
  30. var $mainform = $(document.getElementById("reportMain"));
  31. if (incident_id != '')
  32. {
  33. // Submit Form For Single Item
  34. $incident_single.attr("value", incident_id);
  35. //prevent checked reports from receiving actoin if action is triggered from a single report
  36. $mainform.find("input:checkbox").attr("checked", false);
  37. }
  38. else
  39. {
  40. // Set Hidden form item to 000 so that it doesn't return server side error for blank value
  41. $incident_single.attr("value", "000");
  42. }
  43. $mainform.submit();
  44. }
  45. }
  46. return false;
  47. }
  48. function showLog(id)
  49. {
  50. $('#' + id).toggle(400);
  51. }
  52. $(function () {
  53. // Handle sort/order fields
  54. $("select#order").change(function() { $('.sort-form').submit(); });
  55. $(".sort-ASC").click(function() {
  56. $('.sort-field').val('DESC');
  57. $('.sort-form').submit();
  58. return false;
  59. });
  60. $(".sort-DESC").click(function() {
  61. $('.sort-field').val('ASC');
  62. $('.sort-form').submit();
  63. return false;
  64. });
  65. // Handle search tab
  66. $(".tabset .search").click(function() {
  67. if ($('.search-tab').hasClass('active'))
  68. {
  69. $(".search-tab").removeClass('active').slideUp(300, function() { $(".action-tab").slideDown().addClass('active'); });
  70. $(".tabset .search").removeClass('active');
  71. }
  72. else
  73. {
  74. $(".action-tab").removeClass('active').slideUp(300, function() {
  75. $(".search-tab").slideDown().addClass('active');
  76. // Check if the map has already been created
  77. if (mapLoaded == false)
  78. {
  79. initMap();
  80. }
  81. });
  82. $(".tabset .search").addClass('active');
  83. }
  84. return false;
  85. });
  86. // Category treeview
  87. $(".category-column").treeview({
  88. persist: "location",
  89. collapsed: true,
  90. unique: false
  91. });
  92. });
  93. // Map reference
  94. var map = null;
  95. var latitude = <?php echo isset($_GET['start_loc'][0]) ? floatval($_GET['start_loc'][0]) : Kohana::config('settings.default_lat') ?>;
  96. var longitude = <?php echo isset($_GET['start_loc'][1]) ? floatval($_GET['start_loc'][1]) : Kohana::config('settings.default_lon'); ?>;
  97. var zoom = 8;
  98. var mapLoaded = false;
  99. var initMap = function(){
  100. // OpenLayers uses IE's VML for vector graphics
  101. // We need to wait for IE's engine to finish loading all namespaces (document.namespaces) for VML.
  102. // jQuery.ready is executing too soon for IE to complete it's loading process.
  103. <?php echo map::layers_js(FALSE); ?>
  104. var mapConfig = {
  105. // Map center
  106. center: {
  107. latitude: latitude,
  108. longitude: longitude
  109. },
  110. // Zoom level
  111. zoom: zoom,
  112. // Base layers
  113. baseLayers: <?php echo map::layers_array(FALSE); ?>
  114. };
  115. map = new Ushahidi.Map('divMap', mapConfig);
  116. map.addRadiusLayer({
  117. latitude: latitude,
  118. longitude: longitude
  119. });
  120. // Subscribe to makerpositionchanged event
  121. map.register("markerpositionchanged", function(coords){
  122. $(".search_lat").val(coords.latitude);
  123. $(".search_lon").val(coords.longitude);
  124. });
  125. // Alerts Slider
  126. $("select#alert_radius").change(
  127. function(e, ui) {
  128. var newRadius = $("#alert_radius").val();
  129. // Convert to Meters
  130. radius = newRadius * 1000;
  131. // Redraw Circle
  132. map.updateRadius({radius: radius});
  133. }
  134. );
  135. mapLoaded = true;
  136. };
  137. $(function () {
  138. $('.btn_find').on('click', function () {
  139. geoCode();
  140. });
  141. $('#location_find').bind('keypress', function(e) {
  142. var code = (e.keyCode ? e.keyCode : e.which);
  143. if(code == 13) { //Enter keycode
  144. geoCode();
  145. return false;
  146. }
  147. });
  148. });
  149. /**
  150. * Google GeoCoder
  151. */
  152. function geoCode() {
  153. $('#find_loading').html('<img src="<?php echo url::file_loc('img')."media/img/loading_g.gif"; ?>">');
  154. address = $("#location_find").val();
  155. $.post("<?php echo url::site(); ?>reports/geocode/", { address: address },
  156. function(data){
  157. if (data.status == 'success') {
  158. map.updateRadius({
  159. longitude: data.longitude,
  160. latitude: data.latitude
  161. });
  162. // Update form values
  163. $("#alert_lat").val(data.latitude);
  164. $("#alert_lon").val(data.longitude);
  165. } else {
  166. // Alert message to be displayed
  167. var alertMessage = address + " not found!\n\n***************************\n" +
  168. "Enter more details like city, town, country\nor find a city or town " +
  169. "close by and zoom in\nto find your precise location";
  170. alert(alertMessage)
  171. }
  172. $('#find_loading').html('');
  173. }, "json");
  174. return false;
  175. }