Fixed bug: not displaying "add new entry" line when account is empty.
This commit is contained in:
parent
65d1b00127
commit
43c4e1f61d
@ -219,16 +219,22 @@ var ListViewModel = function() {
|
|||||||
|
|
||||||
// Function to load entries from server for a specific account and month.
|
// Function to load entries from server for a specific account and month.
|
||||||
self.loadEntries = function(account, month) {
|
self.loadEntries = function(account, month) {
|
||||||
|
// Clean up selected entry.
|
||||||
|
self.selectedItem(null);
|
||||||
|
|
||||||
// An account may not have any month (new account)
|
// An account may not have any month (new account)
|
||||||
|
self.clearNewEntry()
|
||||||
|
var entries = [self.newEntry()];
|
||||||
|
|
||||||
if(month) {
|
if(month) {
|
||||||
$.get("api/entries/" + account.id() + "/" + month.year() + "/" + month.month()).success(function(data) {
|
$.get("api/entries/" + account.id() + "/" + month.year() + "/" + month.month()).success(function(data) {
|
||||||
// Clean up selected entry.
|
|
||||||
self.selectedItem(null);
|
|
||||||
|
|
||||||
// Update entries
|
// Update entries
|
||||||
self.clearNewEntry()
|
var dataArray = ko.utils.arrayMap($.parseJSON(data), ko.mapping.fromJS);
|
||||||
var entries = [self.newEntry()].concat(ko.utils.arrayMap($.parseJSON(data), ko.mapping.fromJS));
|
|
||||||
|
if(dataArray.length > 0) {
|
||||||
|
entries = entries.concat(dataArray);
|
||||||
|
}
|
||||||
|
|
||||||
self.entries(entries);
|
self.entries(entries);
|
||||||
|
|
||||||
// Initialize date picker for operation date column.
|
// Initialize date picker for operation date column.
|
||||||
@ -237,8 +243,12 @@ var ListViewModel = function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// If no month, just remove all entries.
|
self.entries(entries);
|
||||||
self.entries.removeAll();
|
|
||||||
|
// Initialize date picker for operation date column.
|
||||||
|
$("#new_operation_date").datepicker().on('changeDate', function(ev){
|
||||||
|
self.newEntry().operation_date(ev.date.format(ev.currentTarget.dataset.dateFormat));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user