Changed month selection behaviour.

This commit is contained in:
Alexis Lahouze
2013-01-08 18:50:47 +01:00
parent 7d54015970
commit 5ccddb0511
3 changed files with 33 additions and 43 deletions

View File

@ -32,8 +32,6 @@ var ListViewModel = function() {
self.entries = ko.observableArray([]);
self.years = ko.observableArray();
self.year = ko.observable();
self.months = ko.observableArray();
self.month = ko.observable();
@ -45,7 +43,7 @@ var ListViewModel = function() {
self.savedItem = ko.observable();
self.loadEntries = function() {
$.post("api/entry.php", {action: "get_entries", account: self.account().id, year: self.year(), month:self.month()}, function(data) {
$.post("api/entry.php", {action: "get_entries", account: self.account().id, year: self.month().year, month:self.month().month}, function(data) {
self.entries.removeAll();
self.selectedItem(null);
@ -165,6 +163,10 @@ var ListViewModel = function() {
}
};
self.changeMonth = function(month) {
self.month(month);
};
self.loadAccounts = function() {
$.post("api/entry.php", {action: "get_accounts"}).success(function (result) {
self.accounts(result);
@ -175,29 +177,17 @@ var ListViewModel = function() {
});
};
self.loadYears = function(account) {
$.post("api/entry.php", {action: "get_years", account: account.id}).success(function (result) {
self.years(result);
if(! self.year()){
self.year(result[0]);
}
});
};
self.loadMonths = function(year){
$.post("api/entry.php", {action: "get_months", year: year}).success(function (result) {
self.loadMonths = function(account){
$.post("api/entry.php", {action: "get_months", account: account.id}).success(function (result) {
self.months(result);
if(! self.month()) {
self.month(result[0]);
self.month(result[result.length - 1]);
}
});
};
self.account.subscribe(self.loadYears);
self.year.subscribe(self.loadMonths);
self.account.subscribe(self.loadMonths);
self.month.subscribe(self.loadEntries);