Переглянути джерело

permissions edit directive

tags/0.1.0
Robin Thoni 9 роки тому
джерело
коміт
b2a5d910dd
1 змінених файлів з 144 додано та 0 видалено
  1. 144
    0
      src/lupermissionsedit.js

+ 144
- 0
src/lupermissionsedit.js Переглянути файл

@@ -0,0 +1,144 @@
1
+/**
2
+ * Created by robin on 11/4/15.
3
+ */
4
+
5
+angular.module('luticateUtils')
6
+    .directive('luPermissionEdit', ['dialogs', 'luticateDialogErrorHelper', 'luticateAuthPermissions',
7
+        function(dialogs, luticateDialogErrorHelper, luticateAuthPermissions) {
8
+            return {
9
+                restrict: 'E',
10
+                scope: {
11
+                    luModel: '&'
12
+                },
13
+                templateUrl: "/luticate/lupermissionedit.html",
14
+                link: function ($scope, element, attrs) {
15
+
16
+                    $scope.permissions = [];
17
+                    $scope.allPermissions = [];
18
+                    $scope.tmpPermission = {
19
+                        Name: "",
20
+                        Value: true
21
+                    };
22
+                    var luModel = $scope.luModel();
23
+
24
+                    $scope.editPermission = function(permission, value)
25
+                    {
26
+                        var promiseEditPermission = {
27
+                            id: "promiseEditPermission_" + permission.Name + "_" + $scope.$id,
28
+                            loaderGroups: ['permission_' + permission.Name]
29
+                        };
30
+                        luModel.getEditPermissionPromise(permission.Name, value, promiseEditPermission)
31
+                            .then(function(data)
32
+                            {
33
+                                permission.Value = value;
34
+                            }, luticateDialogErrorHelper.errorDialog);
35
+                    };
36
+
37
+                    $scope.delPermission = function(permission)
38
+                    {
39
+                        var promiseDelPermission = {
40
+                            id: "promiseDelPermission_" + permission.Name + "_" + $scope.$id,
41
+                            loaderGroups: ['permission_' + permission.Name]
42
+                        };
43
+                        luModel.getDelPermissionPromise(permission.Name, promiseDelPermission)
44
+                            .then(function(data)
45
+                            {
46
+                                $scope.loadPermissions();
47
+                            }, luticateDialogErrorHelper.errorDialog);
48
+                    };
49
+
50
+                    $scope.addPermission = function(permission)
51
+                    {
52
+                        var promiseAddPermission = {
53
+                            id: "promiseAddPermission_" + permission.Name + "_" + $scope.$id,
54
+                            loaderGroups: ['permission_add']
55
+                        };
56
+                        luModel.getAddPermissionPromise(permission.Name, permission.Value, promiseAddPermission)
57
+                            .then(function(data)
58
+                            {
59
+                                $scope.loadPermissions();
60
+                            }, luticateDialogErrorHelper.errorDialog);
61
+                    };
62
+
63
+                    $scope.loadPermissions = function() {
64
+
65
+                        var promiseLoadPermissions = {
66
+                            id: "promiseLoadPermissions_" + $scope.$id,
67
+                            groups: ['permissionList']
68
+                        };
69
+                        luModel.getGetAllPromise(null, null, promiseLoadPermissions)
70
+                            .then(function (permissions) {
71
+                                $scope.permissions = permissions.Data;
72
+                            }, luticateDialogErrorHelper.errorDialog);
73
+                    };
74
+
75
+                    $scope.loadAllPermissions = function() {
76
+
77
+                        var promiseLoadAllPermissions = {
78
+                            id: "promiseLoadAllPermissions_" + $scope.$id,
79
+                            groups: ['permission_add']
80
+                        };
81
+                        luticateAuthPermissions.getAll(null, promiseLoadAllPermissions)
82
+                            .then(function (permissions) {
83
+                                $scope.allPermissions = permissions.Data;
84
+                                $scope.tmpPermission.Name = $scope.allPermissions[0].Name;
85
+                            }, luticateDialogErrorHelper.errorDialog);
86
+                    };
87
+
88
+                    $scope.loadPermissions();
89
+                    $scope.loadAllPermissions();
90
+                }
91
+            };
92
+        }]);
93
+
94
+angular.module('luticateUtils').run(['$templateCache', function($templateCache)
95
+{
96
+    $templateCache.put('/luticate/lupermissionedit.html', '<div class="col-sm-12">' +
97
+'        <div class="form-group col-sm-12"  lu-busy="permissionList">' +
98
+'    <div class="col-sm-6" ng-repeat="permission in permissions" lu-busy="{group: \'permission_\' + permission.Name}">' +
99
+'    <label class="col-sm-6 control-label">{{ permission.Name }}</label>' +
100
+'<div class="col-sm-6">' +
101
+'    <div class="btn-group">' +
102
+'    <a class="btn btn-default dropdown-toggle btn-select" data-toggle="dropdown" href="">' +
103
+'    {{ permission.Value ? \'Allow\' : \'Disallow\' }} <span class="caret"></span>' +
104
+'    </a>' +
105
+'    <ul class="dropdown-menu">' +
106
+'    <li><a href="" ng-click="editPermission(permission, false)">Disallow</a></li>' +
107
+'<li><a href="" ng-click="editPermission(permission, true)">Allow</a></li>' +
108
+'</ul>' +
109
+'</div>' +
110
+'<div class="btn-group">' +
111
+'    <button type="button" class="btn btn-default" ng-click="delPermission(permission)">' +
112
+'    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>' +
113
+'    </button>' +
114
+'    </div>' +
115
+'    </div>' +
116
+'    </div>' +
117
+'    </div>' +
118
+'    <div class="clearfix"></div>' +
119
+'    <div class="col-sm-12" lu-busy="permission_add">' +
120
+'    <div class="btn-group">' +
121
+'    <a class="btn btn-default dropdown-toggle btn-select" data-toggle="dropdown" href="">' +
122
+'    {{ tmpPermission.Name }} <span class="caret"></span>' +
123
+'    </a>' +
124
+'    <ul class="dropdown-menu">' +
125
+'    <li ng-repeat="permission in allPermissions">' +
126
+'    <a href="" ng-click="tmpPermission.Name = permission.Name">{{ permission.Name}}</a>' +
127
+'</li>' +
128
+'</ul>' +
129
+'</div>' +
130
+'<div class="btn-group">' +
131
+'    <a class="btn btn-default dropdown-toggle btn-select" data-toggle="dropdown" href="">' +
132
+'    {{ tmpPermission.Value ? \'Allow\' : \'Disallow\' }} <span class="caret"></span>' +
133
+'    </a>' +
134
+'    <ul class="dropdown-menu">' +
135
+'    <li><a href="" ng-click="tmpPermission.Value = false">Disallow</a></li>' +
136
+'<li><a href="" ng-click="tmpPermission.Value = true">Allow</a></li>' +
137
+'</ul>' +
138
+'</div>' +
139
+'<button type="button" class="btn btn-default" ng-click="addPermission(tmpPermission)">' +
140
+'    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add' +
141
+'    </button>' +
142
+'    </div>' +
143
+'    </div>');
144
+}]);

Завантаження…
Відмінити
Зберегти