|
2 | 2 | location_report.js is used in the report on a single location, |
3 | 3 | pages/location_report/collapsed.blade.php. |
4 | 4 | */ |
| 5 | +var suggestion_counter = 0; |
5 | 6 | function initMap() { |
6 | 7 | var map = new google.maps.Map(document.getElementById('map'), { |
7 | 8 | zoom: 15, |
@@ -114,6 +115,14 @@ function setSuggestionMessage(msg, is_warning) { |
114 | 115 | } |
115 | 116 | } |
116 | 117 |
|
| 118 | +function resetHighlight(){ |
| 119 | + $('#location-name').val($('#location-name').data('value')); |
| 120 | + $('#address').val($('#address').data('value')); |
| 121 | + $('#phone-number').val($('#phone-number').data('value')); |
| 122 | + $('#url').val($('#url').data('value')); |
| 123 | + $('.highlight').removeClass('highlight'); |
| 124 | +} |
| 125 | + |
117 | 126 | function suggestionSubmitted(r) { |
118 | 127 | setSuggestionMessage("Suggestion has been created.", false); |
119 | 128 |
|
@@ -164,12 +173,44 @@ function suggestionButtonClicked() { |
164 | 173 | 'url': url |
165 | 174 | }, |
166 | 175 | 'url': '/api/add-suggestion', |
| 176 | + 'beforeSend': function(jqXHR,settings) { |
| 177 | + $('button').prop('disabled',true); |
| 178 | + }, |
167 | 179 | 'success': suggestionSubmitted, |
168 | | - 'error': suggestionFailed |
| 180 | + 'error': suggestionFailed, |
| 181 | + 'complete': function(jqXHR,textStatus) { |
| 182 | + $('button').prop('disabled',false); |
| 183 | + resetHighlight(); |
| 184 | + } |
169 | 185 | }); |
170 | 186 | } |
171 | 187 |
|
| 188 | +function highlightDiffField(id) { |
| 189 | + $('#' + id).bind('input', function(event){ |
| 190 | + //highlight modified suggestion fields |
| 191 | + if($(this).data('value') != $(this).val()){ |
| 192 | + if(!$(this).hasClass('highlight')) |
| 193 | + suggestion_counter += 1; |
| 194 | + $(this).addClass('highlight'); |
| 195 | + } else { |
| 196 | + if($(this).hasClass('highlight')) |
| 197 | + suggestion_counter -= 1; |
| 198 | + $(this).removeClass('highlight'); |
| 199 | + } |
| 200 | + // disable submit button when there is no difference in the fields |
| 201 | + if(suggestion_counter > 0) |
| 202 | + $("#suggestionFormConfirm").prop("disabled",false); |
| 203 | + else |
| 204 | + $("#suggestionFormConfirm").prop("disabled",true); |
| 205 | + |
| 206 | + }) |
| 207 | +} |
| 208 | + |
172 | 209 | function setupSuggestionFeature() { |
| 210 | + highlightDiffField("location-name"); |
| 211 | + highlightDiffField("phone-number"); |
| 212 | + highlightDiffField("address"); |
| 213 | + highlightDiffField("url"); |
173 | 214 | $("#suggestionFormConfirm").click(suggestionButtonClicked); |
174 | 215 | } |
175 | 216 |
|
|
0 commit comments