2014-03-14 13:38:27 -07:00
|
|
|
'use strict';
|
2014-04-22 12:07:14 -07:00
|
|
|
|
2014-06-03 12:39:06 -07:00
|
|
|
angular.module('copayApp.directives')
|
2014-05-07 15:04:36 -07:00
|
|
|
.directive('validAddress', [
|
2014-04-22 12:07:14 -07:00
|
|
|
|
2014-05-07 15:04:36 -07:00
|
|
|
function() {
|
2014-04-22 12:07:14 -07:00
|
|
|
|
2014-05-07 15:04:36 -07:00
|
|
|
var bitcore = require('bitcore');
|
|
|
|
var Address = bitcore.Address;
|
2014-04-22 12:07:14 -07:00
|
|
|
|
2014-05-07 15:04:36 -07:00
|
|
|
return {
|
|
|
|
require: 'ngModel',
|
|
|
|
link: function(scope, elem, attrs, ctrl) {
|
|
|
|
var validator = function(value) {
|
|
|
|
var a = new Address(value);
|
|
|
|
ctrl.$setValidity('validAddress', a.isValid());
|
|
|
|
return value;
|
|
|
|
};
|
|
|
|
|
|
|
|
ctrl.$parsers.unshift(validator);
|
|
|
|
ctrl.$formatters.unshift(validator);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
])
|
2014-05-16 14:33:06 -07:00
|
|
|
.directive('notification', ['$rootScope',
|
2014-05-07 15:04:36 -07:00
|
|
|
function($rootScope) {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
link: function(scope, element, attrs, ctrl) {
|
|
|
|
setTimeout(function() {
|
|
|
|
scope.$apply(function() {
|
2014-05-20 08:30:20 -07:00
|
|
|
$rootScope.$flashMessage = {};
|
2014-05-07 15:04:36 -07:00
|
|
|
});
|
|
|
|
}, 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 {
|
2014-04-23 10:41:27 -07:00
|
|
|
scope.notEnoughAmount = null;
|
2014-04-23 09:16:20 -07:00
|
|
|
}
|
2014-05-07 15:04:36 -07:00
|
|
|
return value;
|
2014-04-23 09:16:20 -07:00
|
|
|
}
|
2014-05-07 15:04:36 -07:00
|
|
|
ctrl.$parsers.unshift(val);
|
|
|
|
ctrl.$formatters.unshift(val);
|
2014-04-23 09:16:20 -07:00
|
|
|
}
|
2014-05-07 15:04:36 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
])
|
2014-05-14 14:24:24 -07:00
|
|
|
.directive('walletSecret', ['walletFactory',
|
|
|
|
function(walletFactory) {
|
|
|
|
return {
|
|
|
|
require: 'ngModel',
|
|
|
|
link: function(scope, elem, attrs, ctrl) {
|
|
|
|
var validator = function(value) {
|
|
|
|
ctrl.$setValidity('walletSecret', Boolean(walletFactory.decodeSecret(value)));
|
|
|
|
return value;
|
|
|
|
};
|
|
|
|
|
|
|
|
ctrl.$parsers.unshift(validator);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
])
|
2014-05-07 15:04:36 -07:00
|
|
|
.directive('loading', function() {
|
2014-04-24 18:43:19 -07:00
|
|
|
return {
|
|
|
|
restrict: 'A',
|
2014-05-16 14:33:06 -07:00
|
|
|
link: function($scope, element, attr) {
|
2014-04-24 18:43:19 -07:00
|
|
|
var a = element.html();
|
|
|
|
var text = attr.loading;
|
2014-05-16 14:33:06 -07:00
|
|
|
element.on('click', function() {
|
2014-05-08 08:25:35 -07:00
|
|
|
element.html('<i class="size-21 fi-bitcoin-circle icon-rotate spinner"></i> ' + text + '...');
|
2014-05-16 14:33:06 -07:00
|
|
|
});
|
|
|
|
$scope.$watch('loading', function(val) {
|
|
|
|
if (!val) {
|
2014-04-24 18:43:19 -07:00
|
|
|
element.html(a);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2014-05-07 15:04:36 -07:00
|
|
|
.directive('ngFileSelect', function() {
|
2014-04-25 15:11:56 -07:00
|
|
|
return {
|
|
|
|
link: function($scope, el) {
|
|
|
|
el.bind('change', function(e) {
|
|
|
|
$scope.file = (e.srcElement || e.target).files[0];
|
|
|
|
$scope.getFile();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2014-05-26 11:03:39 -07:00
|
|
|
})
|
|
|
|
.directive('avatar', function($rootScope, controllerUtils) {
|
2014-05-07 15:04:36 -07:00
|
|
|
return {
|
|
|
|
link: function(scope, element, attrs) {
|
2014-05-08 11:48:00 -07:00
|
|
|
var peer = JSON.parse(attrs.peer)
|
|
|
|
var peerId = peer.peerId;
|
|
|
|
var nick = peer.nick;
|
|
|
|
element.addClass('video-small');
|
2014-05-16 14:33:06 -07:00
|
|
|
var muted = controllerUtils.getVideoMutedStatus(peerId);
|
2014-05-07 15:04:36 -07:00
|
|
|
if (muted) {
|
|
|
|
element.attr("muted", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-26 11:03:39 -07:00
|
|
|
})
|
|
|
|
.directive('checkStrength', function() {
|
|
|
|
return {
|
|
|
|
replace: false,
|
|
|
|
restrict: 'EACM',
|
2014-06-02 10:39:12 -07:00
|
|
|
require: 'ngModel',
|
2014-05-26 11:03:39 -07:00
|
|
|
link: function(scope, element, attrs) {
|
|
|
|
var _grep = function(elems, callback, invert) {
|
|
|
|
var callbackInverse,
|
|
|
|
matches = [],
|
|
|
|
i = 0,
|
|
|
|
length = elems.length,
|
|
|
|
callbackExpect = !invert;
|
|
|
|
|
|
|
|
// Go through the array, only saving the items
|
|
|
|
// that pass the validator function
|
|
|
|
for (; i < length; i++) {
|
|
|
|
callbackInverse = !callback(elems[i], i);
|
|
|
|
if (callbackInverse !== callbackExpect) {
|
|
|
|
matches.push(elems[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return matches;
|
|
|
|
};
|
|
|
|
|
|
|
|
var strength = {
|
2014-06-02 10:39:12 -07:00
|
|
|
messages: ['too weak', 'weak', 'weak', 'medium', 'strong'],
|
2014-05-26 11:03:39 -07:00
|
|
|
colors: ['#c0392b', '#e74c3c', '#d35400', '#f39c12', '#27ae60'],
|
|
|
|
mesureStrength: function (p) {
|
|
|
|
var _force = 0;
|
|
|
|
var _regex = /[$-/:-?{-~!"^_`\[\]]/g;
|
|
|
|
var _lowerLetters = /[a-z]+/.test(p);
|
|
|
|
var _upperLetters = /[A-Z]+/.test(p);
|
|
|
|
var _numbers = /[0-9]+/.test(p);
|
|
|
|
var _symbols = _regex.test(p);
|
|
|
|
var _flags = [_lowerLetters, _upperLetters, _numbers, _symbols];
|
|
|
|
var _passedMatches = _grep(_flags, function (el) { return el === true; }).length;
|
|
|
|
|
|
|
|
_force += 2 * p.length + ((p.length >= 10) ? 1 : 0);
|
|
|
|
_force += _passedMatches * 10;
|
|
|
|
|
|
|
|
// penality (short password)
|
|
|
|
_force = (p.length <= 6) ? Math.min(_force, 10) : _force;
|
|
|
|
|
|
|
|
// penality (poor variety of characters)
|
|
|
|
_force = (_passedMatches == 1) ? Math.min(_force, 10) : _force;
|
|
|
|
_force = (_passedMatches == 2) ? Math.min(_force, 20) : _force;
|
|
|
|
_force = (_passedMatches == 3) ? Math.min(_force, 40) : _force;
|
|
|
|
return _force;
|
|
|
|
},
|
|
|
|
getColor: function (s) {
|
|
|
|
var idx = 0;
|
|
|
|
|
|
|
|
if (s <= 10) { idx = 0; }
|
|
|
|
else if (s <= 20) { idx = 1; }
|
|
|
|
else if (s <= 30) { idx = 2; }
|
|
|
|
else if (s <= 40) { idx = 3; }
|
|
|
|
else { idx = 4; }
|
|
|
|
|
2014-06-02 10:39:12 -07:00
|
|
|
return { idx: idx + 1, col: this.colors[idx], message: this.messages[idx] };
|
2014-05-26 11:03:39 -07:00
|
|
|
}
|
|
|
|
};
|
2014-06-02 10:39:12 -07:00
|
|
|
|
|
|
|
scope.$watch(attrs.ngModel, function (newValue, oldValue) {
|
2014-05-26 11:03:39 -07:00
|
|
|
if (newValue && newValue !== '') {
|
|
|
|
var c = strength.getColor(strength.mesureStrength(newValue));
|
2014-06-02 10:39:12 -07:00
|
|
|
element.css({ 'border-color': c.col });
|
|
|
|
scope[attrs.checkStrength] = c.message;
|
2014-05-26 11:03:39 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2014-04-25 15:11:56 -07:00
|
|
|
});
|