Fixed bug: not displaying "add new entry" line when account is empty.

This commit is contained in:
Alexis Lahouze 2013-01-30 00:32:06 +01:00
parent 65d1b00127
commit 43c4e1f61d

View File

@ -219,15 +219,21 @@ var ListViewModel = function() {
// Function to load entries from server for a specific account and month.
self.loadEntries = function(account, month) {
// An account may not have any month (new account)
if(month) {
$.get("api/entries/" + account.id() + "/" + month.year() + "/" + month.month()).success(function(data) {
// Clean up selected entry.
self.selectedItem(null);
// Update entries
// An account may not have any month (new account)
self.clearNewEntry()
var entries = [self.newEntry()].concat(ko.utils.arrayMap($.parseJSON(data), ko.mapping.fromJS));
var entries = [self.newEntry()];
if(month) {
$.get("api/entries/" + account.id() + "/" + month.year() + "/" + month.month()).success(function(data) {
// Update entries
var dataArray = ko.utils.arrayMap($.parseJSON(data), ko.mapping.fromJS);
if(dataArray.length > 0) {
entries = entries.concat(dataArray);
}
self.entries(entries);
@ -237,8 +243,12 @@ var ListViewModel = function() {
});
});
} else {
// If no month, just remove all entries.
self.entries.removeAll();
self.entries(entries);
// 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));
});
}
};