-
-
Notifications
You must be signed in to change notification settings - Fork 2
Code snippets
gfr edited this page Dec 2, 2020
·
1 revision
Collection of code snippets to enhance generated modules.
function postEditForm(featureId, submitAction, success_callback, error_callback){
var formData = new FormData();
if(true == submitAction){
//Only set form data when we submit the form - otherwise an csrf-token error will occur
formData = new FormData(jQuery('#editForm')[0]);
formData.append('modulename_objectType[updateapproved]', '1');
}
jQuery.ajax({
url : Routing.generate('modulename_objectType_edit', {id: featureId}),
type: 'POST',
headers: {
'X-Some-Additiona-Header': true
},
data : formData,
cache: false,
contentType: false,
processData: false,
success: function(html) {
success_callback(html);
if(true == submitAction){
console.log("submit done);
}else{
jQuery('#editContainer').html(jQuery(html).find('#editForm'));
jQuery('#editForm').submit(function(submitEvent){
submitEvent.preventDefault();
});
jQuery('#editForm').find('button').each(function(index, value){
var button = jQuery(this);
switch(button.attr('id')){
case 'modulename_objectType_updateapproved':
button.click(function(buttonClickEvent){
buttonClickEvent.preventDefault();
postEditForm(featureId, true, function(html) {
console.log("update success");
}, function(xhr, textStatus, errorThrown){
console.log("updateError");
});
});
break;
case 'modulename_objectType_cancel':
button.click(function(buttonClickEvent){
buttonClickEvent.preventDefault();
console.log("update canceled");
});
break;
default:
button.remove();
break;
}
});
}
},
error: function(xhr, textStatus, errorThrown){
error_callback(xhr, textStatus, errorThrown)
}
});
}
postEditForm(featureEventParams.clickedFeature.properties.id, false, function(html) {
console.log("loaded form");
}, function(xhr, textStatus, errorThrown){
console.log("load form error");
});