-
Notifications
You must be signed in to change notification settings - Fork 0
/
fl.meteor.js
62 lines (53 loc) · 1.97 KB
/
fl.meteor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
angular.module('fl.meteor', ['angular-meteor', 'fl.common'])
.factory('MeteorHelper', ['$q', '$meteorUtils', '$rootScope', '$meteor', function($q, $meteorUtils, $rootScope) {
return {
excludeAngularKey: excludeAngularKey,
checkPermission: checkPermission
};
function checkPermission(stateName) {
var deferred = $q.defer();
$meteorUtils.autorun($rootScope, function() {
if(!Meteor.loggingIn() && Roles.subscription.ready() && Permissions.subscription.ready()) {
if(Permissions.stateHasPermissionByUser(stateName, Meteor.user())) {
deferred.resolve(true);
} else {
deferred.reject(Permissions.getReplaceStateName(stateName) || "UNAUTHORIZED");
}
}
});
return deferred.promise;
}
function excludeAngularKey(source) {
return angular.fromJson(angular.toJson(source));
}
}])
.filter('findByValue', [function() {
return function(matchValue, targetList, returnKey, findKey) {
return NUTIL.finder(matchValue, targetList).returnKey(returnKey || "label").findKey(findKey || "value").find();
}
}])
.filter('findById', [function() {
return function(matchValue, targetList, returnKey) {
return NUTIL.finder(matchValue, targetList).returnKey(returnKey).findKey("_id").find();
}
}])
.run(run);
run.$inject = ['$rootScope', '$meteor'];
function run($rootScope, $meteor) {
$rootScope.logout = logout;
$rootScope.loginWithFacebook = loginWithFacebook;
$rootScope.loginWithTwitter = loginWithTwitter;
$rootScope.isAdmin = isAdmin;
function logout() {
return $meteor.logout();
}
function loginWithTwitter() {
return $meteor.loginWithTwitter(Meteor.isCordova ? {loginStyle: "redirect"} : {});
}
function loginWithFacebook() {
return $meteor.loginWithFacebook(Meteor.isCordova ? {loginStyle: "redirect"} : {});
}
function isAdmin() {
return Roles.userIsInRole($rootScope.currentUser, [ROLES.ADMIN, ROLES.MANAGER]);
}
}