Fix add contribution modal categories population
This commit is contained in:
parent
7ee8a555cc
commit
0085ea0d55
1 changed files with 22 additions and 9 deletions
31
inc/myco.js
31
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;
|
$('#add_contribution_modal #add_contribution_contributor_email')[0].value=$('#view-group #contributor')[0].value;
|
||||||
gid=$('#add_contribution_modal').data('group-uuid');
|
gid=$('#add_contribution_modal').data('group-uuid');
|
||||||
group=groups[gid];
|
group=groups[gid];
|
||||||
current_cat=$('#add_contribution_modal #add_contribution_category')[0].value;
|
populate_add_contribution_categories(group);
|
||||||
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;
|
|
||||||
$('#add_contribution_modal #add_contribution_title').typeahead('destroy');
|
$('#add_contribution_modal #add_contribution_title').typeahead('destroy');
|
||||||
$('#add_contribution_modal #add_contribution_title').typeahead({
|
$('#add_contribution_modal #add_contribution_title').typeahead({
|
||||||
hint: true,
|
hint: true,
|
||||||
|
@ -563,9 +557,28 @@ on_show_add_contribution_modal=function(e) {
|
||||||
$('#add_contribution_modal #add_contribution_title').focus();
|
$('#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) {
|
on_select_contribution_suggestion=function(event,choice,name) {
|
||||||
if (jQuery.type(choice['category'])=='string') {
|
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_cost')[0].value=contribution.cost;
|
||||||
$('#add_contribution_modal #add_contribution_date')[0].value=moment(contribution.date).format('DD/MM/YYYY');
|
$('#add_contribution_modal #add_contribution_date')[0].value=moment(contribution.date).format('DD/MM/YYYY');
|
||||||
if (contribution.category) {
|
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 #edit_uuid')[0].value=contribution_uuid;
|
||||||
$('#add_contribution_modal').modal('show');
|
$('#add_contribution_modal').modal('show');
|
||||||
|
|
Loading…
Reference in a new issue