Skip to content

Commit c464555

Browse files
authored
Merge pull request #686 from Henry-Hao/issue-669
Issue 669
2 parents afb92cd + 0535f3e commit c464555

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

app/public/js/location_report.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
location_report.js is used in the report on a single location,
33
pages/location_report/collapsed.blade.php.
44
*/
5+
var suggestion_counter = 0;
56
function initMap() {
67
var map = new google.maps.Map(document.getElementById('map'), {
78
zoom: 15,
@@ -114,6 +115,14 @@ function setSuggestionMessage(msg, is_warning) {
114115
}
115116
}
116117

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+
117126
function suggestionSubmitted(r) {
118127
setSuggestionMessage("Suggestion has been created.", false);
119128

@@ -164,12 +173,44 @@ function suggestionButtonClicked() {
164173
'url': url
165174
},
166175
'url': '/api/add-suggestion',
176+
'beforeSend': function(jqXHR,settings) {
177+
$('button').prop('disabled',true);
178+
},
167179
'success': suggestionSubmitted,
168-
'error': suggestionFailed
180+
'error': suggestionFailed,
181+
'complete': function(jqXHR,textStatus) {
182+
$('button').prop('disabled',false);
183+
resetHighlight();
184+
}
169185
});
170186
}
171187

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+
172209
function setupSuggestionFeature() {
210+
highlightDiffField("location-name");
211+
highlightDiffField("phone-number");
212+
highlightDiffField("address");
213+
highlightDiffField("url");
173214
$("#suggestionFormConfirm").click(suggestionButtonClicked);
174215
}
175216

app/resources/assets/sass/_location_map_report.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ This is where to put SCSS for the location report that shows a map.
3737
}
3838
}
3939

40+
.highlight {
41+
background-color: rgba(77, 121, 255,0.3) !important;
42+
}
43+
4044
.suggestion-form {
4145
label {
4246
margin-top: 7px;

app/resources/views/pages/location_report/collapsed.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
<button type="button" class="btn btn-default"
152152
data-dismiss="modal">Close
153153
</button>
154-
<button type="button" class="btn btn-primary" id="suggestionFormConfirm">
154+
<button type="button" class="btn btn-primary" id="suggestionFormConfirm" disabled>
155155
Confirm
156156
</button>
157157
</div>

app/resources/views/pages/location_report/suggestion_form.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@
88
<div class="col-sm-6 col-xs-12">
99
<div class="input-group">
1010
<label for="location-name">Location name:</label>
11-
<input type="text" class="form-control" name="location-name" id="location-name" value="{{ $location->name }}" required>
11+
<input type="text" class="form-control" name="location-name" id="location-name" data-value="{{ $location->name }}" value="{{ $location->name }}" required>
1212
</div>
1313
</div>
1414
<div class="col-sm-6 col-xs-12">
1515
<div class="input-group">
1616
<label for="phone-number">Phone number:</label>
17-
<input type="tel" class="form-control" name="phone-number" id="phone-number" value="{{ $location->phone_number }}">
17+
<input type="tel" class="form-control" name="phone-number" id="phone-number" data-value="{{ $location->phone_number }}" value="{{ $location->phone_number }}">
1818
</div>
1919
</div>
2020
<div class="col-xs-12">
2121
<div class="input-group">
2222
<label for="address">Address:</label>
23-
<input type="text" class="form-control" name="address" id="address" value="{{ $location->address }}" required>
23+
<input type="text" class="form-control" name="address" id="address" data-value="{{ $location->address }}" value="{{ $location->address }}" required>
2424
</div>
2525
</div>
2626
<div class="col-xs-12">
2727
<div class="input-group">
2828
<label for="url">External website:</label>
29-
<input type="url" class="form-control" name="url" id="url" value="{{ $location->external_web_url }}">
29+
<input type="url" class="form-control" name="url" id="url" data-value="{{ $location->external_web_url }}" value="{{ $location->external_web_url }}">
3030
</div>
3131
</div>
3232
</div>

0 commit comments

Comments
 (0)