Changed reload behaviour after save or delete.
This commit is contained in:
parent
a41cf30723
commit
41618f3096
@ -42,8 +42,8 @@ var ListViewModel = function() {
|
||||
self.selectedItem = ko.observable();
|
||||
self.savedItem = ko.observable();
|
||||
|
||||
self.loadEntries = function() {
|
||||
$.post("api/entry.php", {action: "get_entries", account: self.account().id, year: self.month().year, month:self.month().month}, function(data) {
|
||||
self.loadEntries = function(account, month) {
|
||||
$.post("api/entry.php", {action: "get_entries", account: account.id, year: month.year, month: month.month}, function(data) {
|
||||
self.entries.removeAll();
|
||||
self.selectedItem(null);
|
||||
|
||||
@ -69,6 +69,8 @@ var ListViewModel = function() {
|
||||
if(!self.account()){
|
||||
self.account(result[0]);
|
||||
}
|
||||
|
||||
self.loadMonths(self.account());
|
||||
});
|
||||
};
|
||||
|
||||
@ -76,7 +78,11 @@ var ListViewModel = function() {
|
||||
$.post("api/entry.php", {action: "get_months", account: account.id}).success(function (result) {
|
||||
self.months(result);
|
||||
|
||||
if(!self.month()) {
|
||||
self.month(result[result.length - 1]);
|
||||
}
|
||||
|
||||
self.loadEntries(self.account(), self.month());
|
||||
});
|
||||
};
|
||||
|
||||
@ -158,7 +164,7 @@ var ListViewModel = function() {
|
||||
message("success", "Save", data.message);
|
||||
|
||||
self.selectedItem(null);
|
||||
self.loadEntries();
|
||||
self.loadAccounts();
|
||||
}).error(function() {
|
||||
message("error", "Error.", "Unexpected error.");
|
||||
});
|
||||
@ -178,17 +184,19 @@ var ListViewModel = function() {
|
||||
};
|
||||
|
||||
self.selectMonth = function(month) {
|
||||
if(month) {
|
||||
self.month(month);
|
||||
self.loadEntries(self.account(), month);
|
||||
}
|
||||
};
|
||||
|
||||
self.selectAccount = function(account) {
|
||||
if(account) {
|
||||
self.account(account);
|
||||
self.loadMonths(account);
|
||||
}
|
||||
};
|
||||
|
||||
self.account.subscribe(self.loadMonths);
|
||||
|
||||
self.month.subscribe(self.loadEntries);
|
||||
|
||||
$(document).ready(self.loadAccounts);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user