diff --git a/src/html/js/entries.js b/src/html/js/entries.js
index 05044b7..8beff86 100644
--- a/src/html/js/entries.js
+++ b/src/html/js/entries.js
@@ -219,16 +219,22 @@ var ListViewModel = function() {
// Function to load entries from server for a specific account and month.
self.loadEntries = function(account, month) {
+ // Clean up selected entry.
+ self.selectedItem(null);
+
// An account may not have any month (new account)
+ self.clearNewEntry()
+ var entries = [self.newEntry()];
+
if(month) {
$.get("api/entries/" + account.id() + "/" + month.year() + "/" + month.month()).success(function(data) {
- // Clean up selected entry.
- self.selectedItem(null);
-
// Update entries
- self.clearNewEntry()
- var entries = [self.newEntry()].concat(ko.utils.arrayMap($.parseJSON(data), ko.mapping.fromJS));
-
+ var dataArray = ko.utils.arrayMap($.parseJSON(data), ko.mapping.fromJS);
+
+ if(dataArray.length > 0) {
+ entries = entries.concat(dataArray);
+ }
+
self.entries(entries);
// Initialize date picker for operation date column.
@@ -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));
+ });
}
};