diff --git a/accountant-ui/index.html b/accountant-ui/index.html
index 0c36c2b..e4bc302 100644
--- a/accountant-ui/index.html
+++ b/accountant-ui/index.html
@@ -66,6 +66,7 @@
+
diff --git a/accountant-ui/js/accounts.js b/accountant-ui/js/accounts.js
index 3a622a8..8ecc3cd 100644
--- a/accountant-ui/js/accounts.js
+++ b/accountant-ui/js/accounts.js
@@ -19,8 +19,8 @@
angular.module('accountant.accounts', [
'ngResource',
+ 'ngMessages',
'ui-notification',
- 'xeditable',
'ngBootbox'
])
@@ -160,7 +160,7 @@ angular.module('accountant.accounts', [
}])
.directive(
- 'accountFormDialog', function($ngBootbox) {
+ 'accountFormDialog', function($ngBootbox, Notification) {
return {
restrict: 'A',
scope: {
@@ -175,8 +175,48 @@ angular.module('accountant.accounts', [
scope.form = {};
+ scope.submitForm = function() {
+ // check to make sure the form is completely valid
+ if (!scope.form.$valid) {
+ return false;
+ }
+
+ // Authorized overdraft is a positive integer but data is a negative integer.
+ scope.data.authorized_overdraft = -scope.data.authorized_overdraft
+
+ angular.copy(scope.data, scope.account);
+
+ // Save account
+ console.log(scope.account);
+ return scope.account.$save().then(
+ function(data) {
+ Notification.success('Account #' + data.id + ' saved.');
+
+ scope.account.getSolds();
+
+ return data;
+ }, function(data) {
+ Notification.error('Error while saving account #' + data.id);
+ scope.account.getSolds();
+ console.log(data);
+ return false;
+ }
+ );
+ };
+
element.on('click', function() {
- //angular.copy(scope.account, scope.form);
+ // Create new account if not passed in ng-model.
+ if(!scope.account) {
+ scope.account = new Account({
+ authorized_overdraft: 0
+ });
+ }
+
+ scope.data = {};
+ angular.copy(scope.account, scope.data);
+
+ // Authorized overdraft must be positive in form.
+ scope.data.authorized_overdraft = -scope.data.authorized_overdraft
// Open dialog with form.
$ngBootbox.customDialog({
@@ -188,15 +228,7 @@ angular.module('accountant.accounts', [
save: {
label: 'Save',
className: 'btn-success',
- callback: function() {
- // Validate form
- console.log(scope.form);
-
- // Save account
- console.log(scope.account);
-
- return false;
- }
+ callback: scope.submitForm
},
cancel: {
label: 'Cancel',
diff --git a/accountant-ui/js/operations.js b/accountant-ui/js/operations.js
index 5e2722d..66304ed 100644
--- a/accountant-ui/js/operations.js
+++ b/accountant-ui/js/operations.js
@@ -482,7 +482,8 @@ angular.module('accountant.operations', [
scope.form = {};
element.on('click', function() {
- //angular.copy(scope.operation, scope.form);
+ scope.data = {};
+ angular.copy(scope.operation, scope.data);
// Open dialog with form.
$ngBootbox.customDialog({
diff --git a/accountant-ui/js/scheduler.js b/accountant-ui/js/scheduler.js
index 510dd92..75aed46 100644
--- a/accountant-ui/js/scheduler.js
+++ b/accountant-ui/js/scheduler.js
@@ -21,6 +21,7 @@ angular.module('accountant.scheduler', [
'ngRoute',
'ngBootbox',
'ui-notification',
+ 'xeditable',
'mgcrea.ngStrap'
])
diff --git a/accountant-ui/views/account.form.tmpl.html b/accountant-ui/views/account.form.tmpl.html
index c3e0ec6..7a33eea 100644
--- a/accountant-ui/views/account.form.tmpl.html
+++ b/accountant-ui/views/account.form.tmpl.html
@@ -15,24 +15,39 @@
along with Accountant. If not, see