Some fixes. Cleaned up entry instanciation and ajax call.

This commit is contained in:
Alexis Lahouze 2013-01-12 23:02:31 +01:00
parent d6e9d0b4cd
commit 2cada51f02
3 changed files with 20 additions and 27 deletions

View File

@ -38,7 +38,7 @@ class EntryAPI extends RestAPI {
if($entry['id'] != null) {
$statement=$connection->prepare("update entry set value_date=:value_date, operation_date=:operation_date, label=:label, value=:value, account_id=:account, category=:category where id=:id");
} else {
$statement=$connection->prepare("insert into entry (value_date, operation_date, label, value, account_id) values (:value_date, :operation_date, :label, :value, :account, :category)");
$statement=$connection->prepare("insert into entry (value_date, operation_date, label, value, account_id, category) values (:value_date, :operation_date, :label, :value, :account, :category)");
}
$statement->bindParam("value_date", $entry['value_date']);

View File

@ -41,7 +41,7 @@
</div>
<div class="span4">
<div id="categories-chart-placeholder" data-bind="pieChart: $root.categoriesChart"></div>
<div id="expense-categories-chart-placeholder" data-bind="pieChart: $root.expenseCategoriesChart"></div>
</div>
</div>

View File

@ -1,23 +1,13 @@
function entry(data){
var id = ko.utils.unwrapObservable(data.id);
var value_date = ko.utils.unwrapObservable(data.value_date);
var operation_date = ko.utils.unwrapObservable(data.operation_date);
var label = ko.utils.unwrapObservable(data.label);
var value = ko.utils.unwrapObservable(data.value);
var account = ko.utils.unwrapObservable(data.account);
var sold = ko.utils.unwrapObservable(data.sold);
var pointedSold = ko.utils.unwrapObservable(data.pointedSold);
var category = ko.utils.unwrapObservable(data.category);
this.id=ko.observable(id ? id : null);
this.value_date=ko.observable(value_date ? value_date : null);
this.operation_date=ko.observable(operation_date ? operation_date : null);
this.label=ko.observable(label ? label : null);
this.value=ko.observable(value ? value : null);
this.account=ko.observable(account ? account : null);
this.sold=ko.observable(sold ? sold : null);
this.pointedSold=ko.observable(pointedSold ? pointedSold : null);
this.category=ko.observable(category ? category : null);
this.id=ko.observable(ko.utils.unwrapObservable(data.id));
this.value_date=ko.observable(ko.utils.unwrapObservable(data.value_date));
this.operation_date=ko.observable(ko.utils.unwrapObservable(data.operation_date));
this.label=ko.observable(ko.utils.unwrapObservable(data.label));
this.value=ko.observable(ko.utils.unwrapObservable(data.value));
this.account=ko.observable(ko.utils.unwrapObservable(data.account));
this.sold=ko.observable(ko.utils.unwrapObservable(data.sold));
this.pointedSold=ko.observable(ko.utils.unwrapObservable(data.pointedSold));
this.category=ko.observable(ko.utils.unwrapObservable(data.category));
}
function message(alertType, title, message) {
@ -41,7 +31,7 @@ var ListViewModel = function() {
self.itemToRemove = ko.observable();
self.chart = null;
self.categoriesChart = ko.computed(function() {
self.expenseCategoriesChart = ko.computed(function() {
var entries=ko.utils.unwrapObservable(self.entries);
var chartValues = [];
@ -258,13 +248,14 @@ var ListViewModel = function() {
};
self.save = function() {
var item = new entry(self.selectedItem());
var item = ko.toJS(self.selectedItem());
if(item.value_date()) {
item.value_date(dateToString(item.value_date()));
if(item.value_date) {
item.value_date = dateToString(item.value_date);
}
if(item.operation_date()) {
item.operation_date(dateToString(item.operation_date()));
if(item.operation_date) {
item.operation_date = dateToString(item.operation_date);
}
$.post("api/entry.php", {action: "save_entry", entry:item}).success(function(data) {
@ -403,6 +394,7 @@ drawChart = function(entries, element) {
// plot chart
window.chart = $.jqplot(element.id, chartValues, {
title: "&Eacute;volution du solde",
axes:{
xaxis:{
renderer:$.jqplot.DateAxisRenderer,
@ -446,6 +438,7 @@ drawPieChart = function(entries, element) {
// plot chart
window.pieChart = $.jqplot(element.id, chartValues, {
title: "D&eacute;penses",
seriesDefaults: {
renderer: $.jqplot.PieRenderer,
rendererOptions: {