feat(invitations): add directive of vipFlag to show user`s VIP flag

This commit is contained in:
OldHawk
2017-09-14 14:42:56 +08:00
parent 09c1a31ac5
commit 74b8334d4c

View File

@@ -0,0 +1,37 @@
(function () {
'use strict';
angular.module('users')
.directive('vipFlag', vipFlag);
vipFlag.$inject = ['$compile', '$translate'];
function vipFlag($compile, $translate) {
var directive = {
restrict: 'A',
link: link
};
return directive;
function link(scope, element, attrs) {
scope.$watch(attrs.vipFlag, function (s) {
if (s) {
var user = s;
var title = $translate.instant('USER_IS_VIP', {name: user.displayName});
var cls = attrs.vipClass;
var e = angular.element('<span class="vip-flag" ng-click="$event.stopPropagation();" ng-if="user.isVip"><kbd>VIP</kbd></span>');
if (e) {
e.addClass(cls ? cls : '');
e.attr('title', title);
element.html(e);
$compile(element.contents())(scope);
}
}
});
}
}
}());