Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@terwey
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terwey/cdfd063d09d5c5ab8981 to your computer and use it in GitHub Desktop.
Save terwey/cdfd063d09d5c5ab8981 to your computer and use it in GitHub Desktop.
/*
This method sets the Description of a Location
@todo add fail callbock method and throw exception as notification
*/
$(document).ready(function() {
$("a[data-role=updateLocationDescription]").click(function() {
var reference = $(this);
var form = $('form#update-location-description-form');
var anchorData = jQuery.parseJSON($(this).attr('data-json'));
var description = $('p.location-description');
var currentInput = form.find('textarea');
var route = Routing.generate('anchorventures_location_update_description', { id: anchorData.locationId } );
$(this).hide();
currentInput.css('display', 'inline-block');
currentInput.focus();
currentInput.blur(function () {
$(currentInput).hide();
$(reference).show();
/* only fire ajax update event if the input changed */
if($(this).val() && $(this).val() !== description.text().trim()) {
$.ajax({
url: route,
type: 'POST',
cache: false,
data: $(form).serialize(),
dataType: 'html',
beforeSend: function(data){
$("div.overlay-preloader, div.av-preloader").fadeIn();
}
})
.always(function() {
$("div.overlay-preloader, div.av-preloader").fadeOut();
})
.done(function(data) {
$(description).html(jQuery.parseJSON(data.replace(/\\r\\n/g, "<br />")));
});
} else {
/* if input is empty set old value */
$(this).val(description.text().trim()).html();
};
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment