diff --git a/inc/myco.js b/inc/myco.js
index af7f01c..2579afb 100644
--- a/inc/myco.js
+++ b/inc/myco.js
@@ -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="";
- for (u in group.getSortedCategories()) {
- cats+="";
- }
- $('#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="";
+ for (u in group.getSortedCategories()) {
+ cats+="";
+ }
+ $('#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');