From 43c4e1f61dc1747215556994d0d7cb9e296789d2 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Wed, 30 Jan 2013 00:32:06 +0100 Subject: [PATCH] Fixed bug: not displaying "add new entry" line when account is empty. --- src/html/js/entries.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) 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)); + }); } };