Simple Groups Git Source Tree
Root/
| Source at commit 150ded5d78219cb1216994158d38ec17b66c25ac created 1 year 3 months ago. By jetherton, starting to add different roles within simple groups. Now the fun startsgit status | |
|---|---|
| 1 | <?php |
| 2 | /** |
| 3 | * Edit reports js file. |
| 4 | * |
| 5 | * Handles javascript stuff related to edit report 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 API 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 | // jQuery Textbox Hints Plugin |
| 19 | // Will move to separate file later or attach to forms plugin |
| 20 | jQuery.fn.hint = function (blurClass) { |
| 21 | if (!blurClass) { |
| 22 | blurClass = 'texthint'; |
| 23 | } |
| 24 | |
| 25 | return this.each(function () { |
| 26 | // get jQuery version of 'this' |
| 27 | var $input = jQuery(this), |
| 28 | |
| 29 | // capture the rest of the variable to allow for reuse |
| 30 | title = $input.attr('title'), |
| 31 | $form = jQuery(this.form), |
| 32 | $win = jQuery(window); |
| 33 | |
| 34 | function remove() { |
| 35 | if ($input.val() === title && $input.hasClass(blurClass)) { |
| 36 | $input.val('').removeClass(blurClass); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | // only apply logic if the element has the attribute |
| 41 | if (title) { |
| 42 | // on blur, set value to title attr if text is blank |
| 43 | $input.blur(function () { |
| 44 | if (this.value === '') { |
| 45 | $input.val(title).addClass(blurClass); |
| 46 | } |
| 47 | }).focus(remove).blur(); // now change all inputs to title |
| 48 | |
| 49 | // clear the pre-defined text when form is submitted |
| 50 | $form.submit(remove); |
| 51 | $win.unload(remove); // handles Firefox's autocomplete |
| 52 | $(".btn_find").click(remove); |
| 53 | } |
| 54 | }); |
| 55 | }; |
| 56 | |
| 57 | /* Dynamic categories */ |
| 58 | $(document).ready(function() { |
| 59 | $('#category_add').hide(); |
| 60 | $('#add_new_category').click(function() { |
| 61 | var category_name = $("input#category_name").val(); |
| 62 | var category_description = $("input#category_description").val(); |
| 63 | var category_color = $("input#category_color").val(); |
| 64 | |
| 65 | //trim the form fields |
| 66 | //Removed ".toUpperCase()" from name and desc for Ticket #38 |
| 67 | category_name = category_name.replace(/^\s+|\s+$/g, ''); |
| 68 | category_description = category_description.replace(/^\s+|\s+$/g,''); |
| 69 | category_color = category_color.replace(/^\s+|\s+$/g, '').toUpperCase(); |
| 70 | |
| 71 | if (!category_name || !category_description || !category_color) { |
| 72 | alert("Please fill in all the fields"); |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | //category_color = category_color.toUpperCase(); |
| 77 | |
| 78 | re = new RegExp("[^ABCDEF0123456789]"); //Color values are in hex |
| 79 | if (re.test(category_color) || category_color.length != 6) { |
| 80 | alert("Please use the Color picker to help you choose a color"); |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | $.post("<?php echo url::base() . 'admin/reports/save_category/' ?>", { category_title: category_name, category_description: category_description, category_color: category_color }, |
| 85 | function(data){ |
| 86 | if ( data.status == 'saved') |
| 87 | { |
| 88 | // alert(category_name+" "+category_description+" "+category_color); |
| 89 | $('#user_categories').append("<li><label><input type=\"checkbox\"name=\"incident_category[]\" value=\""+data.id+"\" class=\"check-box\" checked />"+category_name+"</label></li>"); |
| 90 | $('#category_add').hide(); |
| 91 | } |
| 92 | else |
| 93 | { |
| 94 | alert("Your submission had errors!!"); |
| 95 | } |
| 96 | }, "json"); |
| 97 | return false; |
| 98 | }); |
| 99 | |
| 100 | // Category treeview |
| 101 | $("#category-column-1,#category-column-2").treeview({ |
| 102 | persist: "location", |
| 103 | collapsed: true, |
| 104 | unique: false |
| 105 | }); |
| 106 | |
| 107 | }); |
| 108 | |
| 109 | |
| 110 | // Date Picker JS |
| 111 | $(document).ready(function() { |
| 112 | $("#incident_date").datepicker({ |
| 113 | showOn: "both", |
| 114 | buttonImage: "<?php echo url::base() ?>media/img/icon-calendar.gif", |
| 115 | buttonImageOnly: true |
| 116 | }); |
| 117 | }); |
| 118 | |
| 119 | function addFormField(div, field, hidden_id, field_type) { |
| 120 | var id = document.getElementById(hidden_id).value; |
| 121 | $("#" + div).append("<div class=\"row link-row second\" id=\"" + field + "_" + id + "\"><input type=\"" + field_type + "\" name=\"" + field + "[]\" class=\"" + field_type + " long\" /><a href=\"#\" class=\"add\" onClick=\"addFormField('" + div + "','" + field + "','" + hidden_id + "','" + field_type + "'); return false;\">add</a><a href=\"#\" class=\"rem\" onClick='removeFormField(\"#" + field + "_" + id + "\"); return false;'>remove</a></div>"); |
| 122 | |
| 123 | $("#" + field + "_" + id).effect("highlight", {}, 800); |
| 124 | |
| 125 | id = (id - 1) + 2; |
| 126 | document.getElementById(hidden_id).value = id; |
| 127 | } |
| 128 | |
| 129 | function removeFormField(id) { |
| 130 | var answer = confirm("Are You Sure You Want To Delete This Item?"); |
| 131 | if (answer){ |
| 132 | $(id).remove(); |
| 133 | } |
| 134 | else{ |
| 135 | return false; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | function deletePhoto (id, div) |
| 140 | { |
| 141 | var answer = confirm("Are You Sure You Want To Delete This Photo?"); |
| 142 | if (answer){ |
| 143 | $("#" + div).effect("highlight", {}, 800); |
| 144 | $.get("<?php echo url::base() . 'admin/simplegroups/reports/deletePhoto/' ?>" + id); |
| 145 | $("#" + div).remove(); |
| 146 | } |
| 147 | else{ |
| 148 | return false; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Google GeoCoder |
| 154 | */ |
| 155 | function geoCode() |
| 156 | { |
| 157 | $('#find_loading').html('<img src="<?php echo url::base() . "media/img/loading_g.gif"; ?>">'); |
| 158 | address = $("#location_find").val(); |
| 159 | $.get("<?php echo url::site() . 'findlocation/geocode/' ?>", { address: address }, |
| 160 | function(data){ |
| 161 | |
| 162 | $('#find_location_results').html(data); |
| 163 | $('#find_loading').html(''); |
| 164 | |
| 165 | }); |
| 166 | return false; |
| 167 | } |
| 168 | |
| 169 | /*************************************** |
| 170 | *Put things on the map based on a geolocation |
| 171 | ****************************************/ |
| 172 | function placeLocation(lat, lon, name) |
| 173 | { |
| 174 | |
| 175 | var lonlat = new OpenLayers.LonLat(lon, lat); |
| 176 | |
| 177 | lonlat.transform(proj_4326,proj_900913); |
| 178 | |
| 179 | m = new OpenLayers.Marker(lonlat); |
| 180 | markers.clearMarkers(); |
| 181 | markers.addMarker(m); |
| 182 | map.setCenter(lonlat, <?php echo $default_zoom; ?>); |
| 183 | |
| 184 | // Update form values |
| 185 | $("#latitude").attr("value", lat); |
| 186 | $("#longitude").attr("value", lon); |
| 187 | $("#location_name").attr("value", name); |
| 188 | |
| 189 | return false; |
| 190 | } |
| 191 | |
| 192 | var map; |
| 193 | var thisLayer; |
| 194 | var proj_4326 = new OpenLayers.Projection('EPSG:4326'); |
| 195 | var proj_900913 = new OpenLayers.Projection('EPSG:900913'); |
| 196 | var markers; |
| 197 | $(document).ready(function() { |
| 198 | // Now initialise the map |
| 199 | var options = { |
| 200 | units: "m" |
| 201 | , numZoomLevels: 20 |
| 202 | , controls:[], |
| 203 | projection: proj_900913, |
| 204 | 'displayProjection': proj_4326 |
| 205 | }; |
| 206 | map = new OpenLayers.Map('divMap', options); |
| 207 | |
| 208 | <?php echo map::layers_js(FALSE); ?> |
| 209 | map.addLayers(<?php echo map::layers_array(FALSE); ?>); |
| 210 | |
| 211 | map.addControl(new OpenLayers.Control.Navigation()); |
| 212 | map.addControl(new OpenLayers.Control.PanZoomBar()); |
| 213 | map.addControl(new OpenLayers.Control.MousePosition()); |
| 214 | map.addControl(new OpenLayers.Control.LayerSwitcher()); |
| 215 | |
| 216 | // Create the markers layer |
| 217 | markers = new OpenLayers.Layer.Markers("Markers"); |
| 218 | map.addLayer(markers); |
| 219 | |
| 220 | // create a lat/lon object |
| 221 | var myPoint = new OpenLayers.LonLat(<?php echo $longitude; ?>, <?php echo $latitude; ?>); |
| 222 | myPoint.transform(proj_4326, map.getProjectionObject()); |
| 223 | |
| 224 | // create a marker positioned at a lon/lat |
| 225 | var marker = new OpenLayers.Marker(myPoint); |
| 226 | markers.addMarker(marker); |
| 227 | |
| 228 | // display the map centered on a latitude and longitude (Google zoom levels) |
| 229 | map.setCenter(myPoint, <?php echo $default_zoom; ?>); |
| 230 | |
| 231 | // Detect Map Clicks |
| 232 | map.events.register("click", map, function(e){ |
| 233 | var lonlat = map.getLonLatFromViewPortPx(e.xy); |
| 234 | var lonlat2 = map.getLonLatFromViewPortPx(e.xy); |
| 235 | m = new OpenLayers.Marker(lonlat); |
| 236 | markers.clearMarkers(); |
| 237 | markers.addMarker(m); |
| 238 | |
| 239 | lonlat2.transform(proj_900913,proj_4326); |
| 240 | // Update form values (jQuery) |
| 241 | $("#latitude").attr("value", lonlat2.lat); |
| 242 | $("#longitude").attr("value", lonlat2.lon); |
| 243 | }); |
| 244 | |
| 245 | // GeoCode |
| 246 | $('.btn_find').live('click', function () { |
| 247 | geoCode(); |
| 248 | }); |
| 249 | $('#location_find').bind('keypress', function(e) { |
| 250 | var code = (e.keyCode ? e.keyCode : e.which); |
| 251 | if(code == 13) { //Enter keycode |
| 252 | geoCode(); |
| 253 | return false; |
| 254 | } |
| 255 | }); |
| 256 | |
| 257 | // Event on Latitude/Longitude Typing Change |
| 258 | $('#latitude, #longitude').bind("change keyup", function() { |
| 259 | var newlat = $("#latitude").val(); |
| 260 | var newlon = $("#longitude").val(); |
| 261 | if (!isNaN(newlat) && !isNaN(newlon)) |
| 262 | { |
| 263 | var lonlat = new OpenLayers.LonLat(newlon, newlat); |
| 264 | lonlat.transform(proj_4326,proj_900913); |
| 265 | m = new OpenLayers.Marker(lonlat); |
| 266 | markers.clearMarkers(); |
| 267 | markers.addMarker(m); |
| 268 | map.setCenter(lonlat, <?php echo $default_zoom; ?>); |
| 269 | } |
| 270 | else |
| 271 | { |
| 272 | alert('Invalid value!') |
| 273 | } |
| 274 | }); |
| 275 | |
| 276 | |
| 277 | /* Form Actions */ |
| 278 | // Action on Save Only |
| 279 | $('.btn_save').live('click', function () { |
| 280 | $("#save").attr("value", "1"); |
| 281 | $(this).parents("form").submit(); |
| 282 | return false; |
| 283 | }); |
| 284 | |
| 285 | $('.btn_save_close').live('click', function () { |
| 286 | $(this).parents("form").submit(); |
| 287 | return false; |
| 288 | }); |
| 289 | |
| 290 | // Delete Action |
| 291 | $('.btn_delete').live('click', function () { |
| 292 | var agree=confirm("Are You Sure You Want To DELETE item?"); |
| 293 | if (agree){ |
| 294 | $('#reportMain').submit(); |
| 295 | } |
| 296 | return false; |
| 297 | }); |
| 298 | |
| 299 | // Toggle Date Editor |
| 300 | $('a#date_toggle').click(function() { |
| 301 | $('#datetime_edit').show(400); |
| 302 | $('#datetime_default').hide(); |
| 303 | return false; |
| 304 | }); |
| 305 | |
| 306 | // Show Messages Box |
| 307 | $('a#messages_toggle').click(function() { |
| 308 | $('#show_messages').toggle(400); |
| 309 | return false; |
| 310 | }); |
| 311 | |
| 312 | // Textbox Hints |
| 313 | $("#location_find").hint(); |
| 314 | }); |
| 315 | |
| 316 | function formSwitch(form_id, incident_id) |
| 317 | { |
| 318 | var answer = confirm('Are You Sure You Want To SWITCH Forms?'); |
| 319 | if (answer){ |
| 320 | $('#form_loader').html('<img src="<?php echo url::base() . "media/img/loading_g.gif"; ?>">'); |
| 321 | $.post("<?php echo url::base() . 'admin/simplegroups/reports/switch_form' ?>", { form_id: form_id, incident_id: incident_id }, |
| 322 | function(data){ |
| 323 | if (data.status == 'success'){ |
| 324 | $('#custom_forms').html(''); |
| 325 | $('#custom_forms').html(unescape(data.response)); |
| 326 | $('#form_loader').html(''); |
| 327 | } |
| 328 | }, "json"); |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | // Initialize tinyMCE Wysiwyg Editor |
| 333 | tinyMCE.init({ |
| 334 | convert_urls : false, |
| 335 | relative_urls : false, |
| 336 | mode : "exact", |
| 337 | elements : "incident_description", |
| 338 | theme : "advanced", |
| 339 | plugins : "pagebreak,advhr,advimage,advlink,iespell,inlinepopups,contextmenu,paste,directionality,noneditable,advlist", |
| 340 | // Theme options |
| 341 | theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,fontselect,fontsizeselect", |
| 342 | theme_advanced_buttons2 : "outdent,indent,blockquote,|,undo,redo,|,link,unlink,image,code,|,forecolor,backcolor", |
| 343 | theme_advanced_buttons3 : "cut,copy,paste,pastetext,pasteword,|,hr,removeformat,visualaid,|,sub,sup,|,advhr,|,ltr,rtl", |
| 344 | theme_advanced_toolbar_location : "top", |
| 345 | theme_advanced_toolbar_align : "left" |
| 346 | }); |
Branches:
master
