Fix add contribution modal categories population

This commit is contained in:
Benjamin Renard 2015-03-10 00:42:16 +01:00
parent 7ee8a555cc
commit 0085ea0d55

View file

@ -541,13 +541,7 @@ on_show_add_contribution_modal=function(e) {
$('#add_contribution_modal #add_contribution_contributor_email')[0].value=$('#view-group #contributor')[0].value;
gid=$('#add_contribution_modal').data('group-uuid');
group=groups[gid];
current_cat=$('#add_contribution_modal #add_contribution_category')[0].value;
cats="<option value=''>Non définie</option>";
for (u in group.getSortedCategories()) {
cats+="<option value='"+u+"'>"+group.categories[u]['name']+"</option>";
}
$('#add_contribution_modal #add_contribution_category').html(cats);
$('#add_contribution_modal #add_contribution_category')[0].value=current_cat;
populate_add_contribution_categories(group);
$('#add_contribution_modal #add_contribution_title').typeahead('destroy');
$('#add_contribution_modal #add_contribution_title').typeahead({
hint: true,
@ -563,9 +557,28 @@ on_show_add_contribution_modal=function(e) {
$('#add_contribution_modal #add_contribution_title').focus();
}
populate_add_contribution_categories=function(group,select) {
if (!group) {
gid=$('#add_contribution_modal').data('group-uuid');
group=groups[gid];
}
current_cat=$('#add_contribution_modal #add_contribution_category')[0].value;
cats="<option value=''>Non définie</option>";
for (u in group.getSortedCategories()) {
cats+="<option value='"+u+"'>"+group.categories[u]['name']+"</option>";
}
$('#add_contribution_modal #add_contribution_category').html(cats);
if (select) {
$('#add_contribution_modal #add_contribution_category').val(select);
}
else {
$('#add_contribution_modal #add_contribution_category').val(current_cat);
}
}
on_select_contribution_suggestion=function(event,choice,name) {
if (jQuery.type(choice['category'])=='string') {
$('#add_contribution_modal #add_contribution_category').val(choice['category']);
populate_add_contribution_categories(null,choice['category']);
}
}
@ -672,7 +685,7 @@ on_contribution_edit_btn_click=function(e) {
$('#add_contribution_modal #add_contribution_cost')[0].value=contribution.cost;
$('#add_contribution_modal #add_contribution_date')[0].value=moment(contribution.date).format('DD/MM/YYYY');
if (contribution.category) {
$('#add_contribution_modal #add_contribution_category')[0].value=contribution.category;
populate_add_contribution_categories(group,contribution.category);
}
$('#add_contribution_modal #edit_uuid')[0].value=contribution_uuid;
$('#add_contribution_modal').modal('show');