Changed the way we point entries. Closes #4.

This commit is contained in:
Alexis Lahouze
2013-01-26 01:15:07 +01:00
parent e4e74eea9f
commit 3cd9304689
8 changed files with 53 additions and 45 deletions

View File

@ -84,7 +84,7 @@
<thead>
<tr>
<th style="width: 100px">Date de valeur</th>
<th style="width: 100px">Date de l'op.</th>
<!--<th style="width: 100px">Date de l'op.</th>-->
<th>Libell&eacute; de l'op&eacute;ration</th>
<th style="width: 50px">Montant</th>
<th style="width: 50px">Solde</th>
@ -179,8 +179,6 @@
<!-- Displayed item template -->
<script id="itemsTmpl" type="text/html">
<tr data-bind="css: { 'warning': sold() < 0 && sold() >= $root.account().authorized_overdraft(), 'error': sold() < $root.account().authorized_overdraft() }">
<td data-bind="text: value_date"></td>
<td data-bind="text: operation_date"></td>
<td data-bind="text: label"></td>
@ -189,7 +187,7 @@
<td data-bind="text: sold, css: {'text-warning': sold() < 0 && sold() >= $root.account().authorized_overdraft(), 'text-error': sold() < $root.account().authorized_overdraft() }"></td>
<td data-bind="text: operation_date() ? pointedsold : '', css: {'text-warning': pointedsold() < 0 && pointedsold() >= $root.account().authorized_overdraft(), 'text-error': pointedsold() < $root.account().authorized_overdraft() }"></td>
<td data-bind="text: pointed() ? pointedsold : '', css: {'text-warning': pointedsold() < 0 && pointedsold() >= $root.account().authorized_overdraft(), 'text-error': pointedsold() < $root.account().authorized_overdraft() }"></td>
<td data-bind="text: category"></td>
@ -197,6 +195,7 @@
<div class="btn-group">
<a class="btn btn-mini" data-bind="click: $root.edit" href="#" title="edit"><i class="icon-edit"></i></a>
<a class="btn btn-mini" data-bind="click: $root.remove" href="#" title="remove"><i class="icon-trash"></i></a>
<a class="btn btn-mini" data-bind="css: {'active': pointed}, click: $root.pointEntry" href="#" title="point"><i class="icon-pencil"></i></a>
</div>
</td>
</tr>
@ -205,8 +204,6 @@
<!-- New item template -->
<script id="newTmpl" type="text/html">
<tr class="form-inline">
<td><input type="date" class="input-small" data-bind="value: value_date" data-date-format="yyyy-mm-dd" id="new_value_date" /></td>
<td><input type="date" class="input-small" data-bind="value: operation_date" data-date-format="yyyy-mm-dd" id="new_operation_date" /></td>
<td><input type="text" class="input-xxlarge" data-bind="value: label"/></td>
@ -223,6 +220,7 @@
<div class="btn-group">
<a class="btn btn-mini btn-success" data-bind="click: $root.save" href="#" title="Add"><i class="icon-plus"></i></a>
<a class="btn btn-mini" data-bind="click: $root.cancel" href="#" title="Clear"><i class="icon-remove"></i></a>
<a class="btn btn-mini" data-bind="css: {'active': pointed}, click: $root.pointEntry" href="#" title="point"><i class="icon-pencil"></i></a>
</div>
</td>
</tr>
@ -231,8 +229,6 @@
<!-- Edit item template -->
<script id="editTmpl" type="text/html">
<tr class="form-inline" data-bind="css: { 'warning': sold() < 0 && sold() >= $root.account().authorized_overdraft(), 'error': sold() < $root.account().authorized_overdraft() }">
<td><input type="date" class="input-small" data-bind="value: value_date" data-date-format="yyyy-mm-dd" id="value_date" /></td>
<td><input type="date" class="input-small" data-bind="value: operation_date" data-date-format="yyyy-mm-dd" id="operation_date" /></td>
<td><input type="text" class="input-xxlarge" data-bind="value: label"/></td>
@ -245,10 +241,11 @@
<td><input type="text" class="input-small" data-bind="value: category, typeahead: {source: $root.categories }" /></td>
<td class="btn-group">
<td>
<div class="btn-group">
<a class="btn btn-mini btn-success" data-bind="click: $root.save" href="#" title="Save"><i class="icon-ok"></i></a>
<a class="btn btn-mini" data-bind="click: $root.cancel" href="#" title="Cancel"><i class="icon-ban-circle"></i></a>
<a class="btn btn-mini" data-bind="css: {'active': pointed}, click: $root.pointEntry" href="#" title="point"><i class="icon-pencil"></i></a>
</div>
</td>
</tr>

Binary file not shown.

View File

@ -1,7 +1,7 @@
// Entry object
function entry(){
this.id=ko.observable();
this.value_date=ko.observable();
this.pointed=ko.observable();
this.operation_date=ko.observable();
this.label=ko.observable();
this.value=ko.observable();
@ -54,7 +54,7 @@ var ListViewModel = function() {
self.selectedItem = ko.observable();
self.newEntry = ko.observable(ko.mapping.fromJS({
id: null,
value_date: null,
pointed: false,
operation_date: null,
label: null,
value: null,
@ -209,8 +209,8 @@ var ListViewModel = function() {
// Transform to an array readable by jqplot Line renderer.
var chartValues = [];
$.each(entries, function(index, entry) {
if(unwrap(entry.value_date) && unwrap(entry.sold)) {
chartValues.push([unwrap(entry.value_date), Number(unwrap(entry.sold))]);
if(unwrap(entry.operation_date) && unwrap(entry.sold)) {
chartValues.push([unwrap(entry.operation_date), Number(unwrap(entry.sold))]);
}
});
@ -231,11 +231,6 @@ var ListViewModel = function() {
self.entries(entries);
// Initialize date picker for value date column.
$("#new_value_date").datepicker().on('changeDate', function(ev){
self.newEntry().value_date(ev.date.format(ev.currentTarget.dataset.dateFormat));
});
// 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));
@ -333,11 +328,6 @@ var ListViewModel = function() {
self.savedItem=ko.toJS(item);
self.selectedItem(item);
// Initialize date picker for value date column.
$("#value_date").datepicker().on('changeDate', function(ev){
self.selectedItem().value_date(ev.date.format(ev.currentTarget.dataset.dateFormat));
});
// Initialize date picker for operation date column.
$("#operation_date").datepicker().on('changeDate', function(ev){
self.selectedItem().operation_date(ev.date.format(ev.currentTarget.dataset.dateFormat));
@ -346,8 +336,8 @@ var ListViewModel = function() {
self.clearNewEntry = function() {
self.newEntry().id(null); // id should not change, but just in case...
self.newEntry().pointed(false)
self.newEntry().operation_date(null);
self.newEntry().value_date(null);
self.newEntry().label(null);
self.newEntry().value(null);
self.newEntry().account_id(self.account().id()); // account_id should not change, but just in case...
@ -359,8 +349,8 @@ var ListViewModel = function() {
// Reset selected item fields to saved item ones.
if(item === self.selectedItem() && self.savedItem) {
self.selectedItem().id(self.savedItem.id); // id should not change, but just in case...
self.selectedItem().pointed(self.savedItem.pointed);
self.selectedItem().operation_date(self.savedItem.operation_date);
self.selectedItem().value_date(self.savedItem.value_date);
self.selectedItem().label(self.savedItem.label);
self.selectedItem().value(self.savedItem.value);
self.selectedItem().account_id(self.savedItem.account_id); // account_id should not change, but just in case...
@ -377,6 +367,18 @@ var ListViewModel = function() {
self.selectedItem(null);
};
self.pointEntry = function(entry) {
if(entry.pointed()) {
entry.pointed(false);
} else {
entry.pointed(true);
}
if(entry != self.newEntry()) {
self.save(entry);
}
};
// Function to save the current selected entry.
self.save = function(item) {
//var item = self.selectedItem();