Last active
August 29, 2015 14:13
-
-
Save terwey/cdfd063d09d5c5ab8981 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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