mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #138 from cmgustavo/feature/06-send-form
AngularJS directives to handle notification and form validation.
This commit is contained in:
commit
7d018389c3
|
@ -47,7 +47,7 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row" ng-if='$root.flashMessage.message'>
|
<div class="row" ng-if='$root.flashMessage.message' notification>
|
||||||
<div class="small-8 large-centered columns">
|
<div class="small-8 large-centered columns">
|
||||||
<div data-alert class="alert-box round {{$root.flashMessage.type}}">
|
<div data-alert class="alert-box round {{$root.flashMessage.type}}">
|
||||||
{{$root.flashMessage.message}}
|
{{$root.flashMessage.message}}
|
||||||
|
@ -417,10 +417,11 @@
|
||||||
<small ng-hide="!sendForm.amount.$pristine">required</small>
|
<small ng-hide="!sendForm.amount.$pristine">required</small>
|
||||||
<small class="is-valid" ng-show="!sendForm.amount.$invalid && !sendForm.amount.$pristine">valid!</small>
|
<small class="is-valid" ng-show="!sendForm.amount.$invalid && !sendForm.amount.$pristine">valid!</small>
|
||||||
<small class="has-error" ng-show="sendForm.amount.$invalid && !sendForm.amount.$pristine">
|
<small class="has-error" ng-show="sendForm.amount.$invalid && !sendForm.amount.$pristine">
|
||||||
not valid</small>
|
not valid.</small>
|
||||||
|
<small ng-show="notEnoughAmount">{{notEnoughAmount}}</small>
|
||||||
</label>
|
</label>
|
||||||
<div class="small-9 columns">
|
<div class="small-9 columns">
|
||||||
<input type="number" id="amount" name="amount" placeholder="Amount" ng-model="amount" min="0.0001" max="10000000" required>
|
<input type="number" id="amount" name="amount" placeholder="Amount" ng-model="amount" min="0.0001" max="10000000" enough-amount required>
|
||||||
</div>
|
</div>
|
||||||
<div class="small-3 columns">
|
<div class="small-3 columns">
|
||||||
<span class="postfix">BTC</span>
|
<span class="postfix">BTC</span>
|
||||||
|
|
|
@ -13,11 +13,6 @@ angular.module('copay.send').controller('SendController',
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($rootScope.availableBalance <= form.amount.$modelValue) {
|
|
||||||
$rootScope.flashMessage = { message: 'You have not enough amount to send', type: 'error'};
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var address = form.address.$modelValue;
|
var address = form.address.$modelValue;
|
||||||
var amount = (form.amount.$modelValue * 100000000).toString(); // satoshi to string
|
var amount = (form.amount.$modelValue * 100000000).toString(); // satoshi to string
|
||||||
|
|
||||||
|
|
|
@ -19,5 +19,44 @@ angular.module('copay')
|
||||||
ctrl.$formatters.unshift(validator);
|
ctrl.$formatters.unshift(validator);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}]);
|
}])
|
||||||
|
.directive('notification', ['$rootScope', function($rootScope){
|
||||||
|
return {
|
||||||
|
restrict: 'A',
|
||||||
|
link: function(scope, element, attrs, ctrl) {
|
||||||
|
setTimeout(function(){
|
||||||
|
scope.$apply(function() {
|
||||||
|
$rootScope.flashMessage = {};
|
||||||
|
});
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}])
|
||||||
|
.directive('enoughAmount', ['$rootScope', function($rootScope){
|
||||||
|
return {
|
||||||
|
require: 'ngModel',
|
||||||
|
link: function(scope, element, attrs, ctrl) {
|
||||||
|
var val = function(value) {
|
||||||
|
var vStr = new String(value);
|
||||||
|
var vNum = Number(vStr);
|
||||||
|
if (typeof vNum == "number" && vNum > 0) {
|
||||||
|
if ($rootScope.availableBalance <= vNum) {
|
||||||
|
ctrl.$setValidity('enoughAmount', false);
|
||||||
|
scope.notEnoughAmount = 'Insufficient funds!';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ctrl.$setValidity('enoughAmount', true);
|
||||||
|
scope.notEnoughAmount = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
scope.notEnoughAmount = null;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
ctrl.$parsers.unshift(val);
|
||||||
|
ctrl.$formatters.unshift(val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}])
|
||||||
|
;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue