Skip to content

Commit

Permalink
fix editing customer data related to issue #2
Browse files Browse the repository at this point in the history
  • Loading branch information
meisyal committed Sep 20, 2015
1 parent 3fbc3d2 commit d4d4b63
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions www/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ MIM.controller('CustomerController', function($scope, $ionicPlatform, $cordovaSQ
};

$scope.editCustomer = function(customersData) {
var query = 'UPDATE Customers SET name = ?, address = ?, telephone_number = ? WHERE id = ?';
var query = 'UPDATE Customers SET name = ?, address = ?, telephone_number = ?, ' +
'updated_at = DATETIME(\'now\') WHERE id = ?';
$cordovaSQLite.execute(db, query, [customersData.name, customersData.address, customersData.phone, customersData.id]).then(function(res) {
console.log('Item ' + customersData.id + ' is updated.');
customersData.newItem = ' ';
Expand Down Expand Up @@ -353,13 +354,14 @@ MIM.controller('CustomerController', function($scope, $ionicPlatform, $cordovaSQ
if (index == 1) {
$scope.addModal.show();
} else {
var query = 'SELECT name, address, telephone_number FROM Customers WHERE id = ?';
$scope.customersData = {};
var query = 'SELECT id, name, address, telephone_number FROM Customers WHERE id = ?';
$cordovaSQLite.execute(db, query, [customer.id]).then(function(res) {
if (res.rows.length) {
$scope.customer_id = res.rows.item(0).id;
$scope.customer_name = res.rows.item(0).name;
$scope.customer_address = res.rows.item(0).address;
$scope.customer_phone = res.rows.item(0).telephone_number;
$scope.customersData.id = res.rows.item(0).id;
$scope.customersData.name = res.rows.item(0).name;
$scope.customersData.address = res.rows.item(0).address;
$scope.customersData.phone = res.rows.item(0).telephone_number;
}
}, function(error) {
console.error(error);
Expand Down
2 changes: 1 addition & 1 deletion www/templates/customers.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ion-view title="Customers">
<ion-view cache-view="false" title="Customers">
<ion-nav-buttons side="right">
<button class="right button button-icon icon ion-android-add" ng-click="openCustomerModal(1)"></button>
</ion-nav-buttons>
Expand Down

0 comments on commit d4d4b63

Please sign in to comment.