Browse Source

settings get/add/edit/del

develop
Robin Thoni 8 years ago
parent
commit
3178e32fce

+ 6
- 0
app.js View File

@@ -46,6 +46,12 @@ luticate.config(['$stateProvider', '$urlRouterProvider', '$httpProvider',
46 46
             controller:'PermissionsController'
47 47
         });
48 48
 
49
+        $stateProvider.state('settings',{
50
+            url:'/settings',
51
+            templateUrl:'views/settings.html',
52
+            controller:'SettingsController'
53
+        });
54
+
49 55
         $stateProvider.state('test',{
50 56
             url:'/test',
51 57
             templateUrl:'views/test.html',

+ 86
- 0
controllers/modals/settingedit.controller.js View File

@@ -0,0 +1,86 @@
1
+/**
2
+ * Created by robin on 11/4/15.
3
+ */
4
+
5
+angular.module('luticate')
6
+    .controller('SettingEditController', ['$scope', 'luticateAuthSettings', 'data', 'luticateAuthCache', '$q',
7
+        function($scope, luticateAuthSettings, data, luticateAuthCache, $q) {
8
+            if (data != null) {
9
+                $scope.setting = data;
10
+                $scope.setting.IsNew = false;
11
+                $scope.neededPermission = "LU_SETTING_EDIT";
12
+            }
13
+            else {
14
+                $scope.setting = {
15
+                    "Name": "",
16
+                    "Type": "string",
17
+                    "Value": "",
18
+                    "IsBlocked": true,
19
+                    "IsAdmin": true,
20
+                    "IsNew": true
21
+                };
22
+                $scope.neededPermission = "LU_SETTING_ADD";
23
+            }
24
+
25
+            $scope.types = [
26
+                "string",
27
+                "int",
28
+                "float",
29
+                "bool",
30
+                "object"
31
+            ];
32
+
33
+            $scope.setType = function(type)
34
+            {
35
+                if ($scope.setting.Type == type)
36
+                {
37
+                    return;
38
+                }
39
+                $scope.setting.Type = type;
40
+                if (type == 'int' || type == 'float')
41
+                {
42
+                    $scope.setting.Value = 0;
43
+                }
44
+                else if (type == 'string')
45
+                {
46
+                    $scope.setting.Value = "";
47
+                }
48
+                else if (type == 'bool')
49
+                {
50
+                    $scope.setting.Value = true;
51
+                }
52
+                else if (type == 'object')
53
+                {
54
+                    $scope.setting.Value = {};
55
+                }
56
+            };
57
+
58
+            $scope.submitForm = function()
59
+            {
60
+                $scope.setting.Name = $scope.setting.Name.toUpperCase();
61
+                if (!$scope.setting.IsNew) {
62
+                    if (luticateAuthCache.hasEffectivePermission("LU_SETTING_EDIT")) {
63
+                        var promiseEditSetting = {
64
+                            id: "promiseEditSetting",
65
+                            loaderGroups: ["modal"]
66
+                        };
67
+                        return luticateAuthSettings.edit({
68
+                            setting_name: $scope.setting.Name,
69
+                            setting: $scope.setting
70
+                        }, promiseEditSetting);
71
+                    }
72
+                    else {
73
+                        var defer = $q.defer();
74
+                        defer.resolve();
75
+                        return defer.promise;
76
+                    }
77
+                }
78
+                else {
79
+                    var promiseAddSetting = {
80
+                        id: "promiseAddSetting",
81
+                        loaderGroups: ["modal"]
82
+                    };
83
+                    return luticateAuthSettings.add($scope.setting, promiseAddSetting);
84
+                }
85
+            }
86
+        }]);

+ 65
- 0
controllers/settings.controller.js View File

@@ -0,0 +1,65 @@
1
+angular.module('luticate')
2
+    .controller('SettingsController', ['$scope', 'luticateAuthSettings',
3
+        function($scope, luticateAuthSettings) {
4
+
5
+            $scope.luTable = {
6
+                columns: [
7
+                    {
8
+                        name: "Name",
9
+                        width: 3,
10
+                        getValue: function (item) {
11
+                            return item.Name;
12
+                        }
13
+                    }, {
14
+                        name: "Type",
15
+                        width: 1,
16
+                        getValue: function (item) {
17
+                            return item.Type;
18
+                        }
19
+                    }, {
20
+                        name: "Blocked",
21
+                        width: 1,
22
+                        getValue: function (item) {
23
+                            return item.IsBlocked ? "Yes" : "No";
24
+                        }
25
+                    }, {
26
+                        name: "Admin",
27
+                        width: 1,
28
+                        getValue: function (item) {
29
+                            return item.IsAdmin ? "Yes" : "No";
30
+                        }
31
+                    }, {
32
+                        name: "Value",
33
+                        width: 6,
34
+                        getValue: function (item) {
35
+                            return item.Value;
36
+                        }
37
+                    }
38
+                ],
39
+
40
+                canAdd: 'LU_SETTING_ADD',
41
+
42
+                canDel: 'LU_SETTING_DEL',
43
+
44
+                canEdit: function()
45
+                {
46
+                    return true;
47
+                },
48
+
49
+                getLoadPagePromise: function (page, perPage, query, promise) {
50
+                    return luticateAuthSettings.getAll({page: page, perPage: perPage, query: query}, promise);
51
+                },
52
+
53
+                getDelPromise: function (id, promise) {
54
+                    return luticateAuthSettings.del({setting_name: id}, promise);
55
+                },
56
+
57
+                getEditController: function () {
58
+                    return "SettingEdit";
59
+                },
60
+
61
+                getItemId: function (item) {
62
+                    return item.Name;
63
+                }
64
+            }
65
+    }]);

+ 8
- 0
css/app.less View File

@@ -2,6 +2,14 @@ body {
2 2
   padding-top: 70px;
3 3
 }
4 4
 
5
+/**
6
+========================================================
7
+**/
8
+
9
+.navbar-brand {
10
+  padding-right: 42px;
11
+}
12
+
5 13
 .caption {
6 14
   height: 100%;
7 15
   overflow: hidden;

+ 2
- 0
index.html View File

@@ -49,6 +49,7 @@
49 49
     <script src="controllers/users.controller.js"></script>
50 50
     <script src="controllers/groups.controller.js"></script>
51 51
     <script src="controllers/permissions.controller.js"></script>
52
+    <script src="controllers/settings.controller.js"></script>
52 53
     <script src="controllers/test.controller.js"></script>
53 54
 
54 55
     <!-- Modal Controller -->
@@ -60,6 +61,7 @@
60 61
     <script src="controllers/modals/groupusersadd.controller.js"></script>
61 62
     <script src="controllers/modals/grouppermissions.controller.js"></script>
62 63
     <script src="controllers/modals/groupusers.controller.js"></script>
64
+    <script src="controllers/modals/settingedit.controller.js"></script>
63 65
 
64 66
     <!-- SDK -->
65 67
     <script src="sdk/cache.js"></script>

+ 1
- 1
views/groups.html View File

@@ -1,5 +1,5 @@
1 1
 <!-- Page Content -->
2 2
 <div class="container">
3
-    <lu-edit-table options="luTable" class="row col-sm-8 col-sm-offset-2" ></lu-edit-table>
3
+    <lu-edit-table options="luTable" class="row col-sm-12" ></lu-edit-table>
4 4
 </div>
5 5
 

+ 73
- 0
views/modals/settingedit.html View File

@@ -0,0 +1,73 @@
1
+<dialog-ok-cancel title="{{ setting.IsNew ? 'Add' : 'Edit'}} setting {{ setting.Name }}">
2
+    <div class="form-group">
3
+        <label for="name" class="col-sm-2 control-label">Name</label>
4
+        <div class="col-sm-9">
5
+            <input autofocus id="name" class="form-control input-permission-name" ng-model="setting.Name" required ng-disabled="!setting.IsNew"/>
6
+        </div>
7
+    </div>
8
+    <div class="form-group">
9
+        <label class="col-sm-2 control-label">Blocked</label>
10
+        <div class="col-sm-9">
11
+            <div class="btn-group">
12
+                <button type="button" class="btn btn-primary dropdown-toggle btn-select" data-toggle="dropdown" href="" lu-enable-permission="{{ neededPermission }}">
13
+                    {{ setting.IsBlocked ? 'Yes' : 'No' }} <span class="caret"></span>
14
+                </button>
15
+                <ul class="dropdown-menu">
16
+                    <li><a href="" ng-click="setting.IsBlocked = false">No</a></li>
17
+                    <li><a href="" ng-click="setting.IsBlocked = true">Yes</a></li>
18
+                </ul>
19
+            </div>
20
+        </div>
21
+    </div>
22
+    <div class="form-group">
23
+        <label class="col-sm-2 control-label">Admin</label>
24
+        <div class="col-sm-9">
25
+            <div class="btn-group">
26
+                <button type="button" class="btn btn-primary dropdown-toggle btn-select" data-toggle="dropdown" href="" lu-enable-permission="{{ neededPermission }}">
27
+                    {{ setting.IsAdmin ? 'Yes' : 'No' }} <span class="caret"></span>
28
+                </button>
29
+                <ul class="dropdown-menu">
30
+                    <li><a href="" ng-click="setting.IsAdmin = false">No</a></li>
31
+                    <li><a href="" ng-click="setting.IsAdmin = true">Yes</a></li>
32
+                </ul>
33
+            </div>
34
+        </div>
35
+    </div>
36
+    <div class="form-group">
37
+        <label class="col-sm-2 control-label">Type</label>
38
+        <div class="col-sm-9">
39
+            <div class="btn-group">
40
+                <button type="button" class="btn btn-primary dropdown-toggle btn-select" data-toggle="dropdown"
41
+                        href="" lu-enable-permission="{{ neededPermission }}" ng-disabled="!setting.IsNew">
42
+                    {{ setting.Type }} <span class="caret"></span>
43
+                </button>
44
+                <ul class="dropdown-menu">
45
+                    <li ng-repeat="type in types"><a href="" ng-click="setType(type)">{{ type }}</a></li>
46
+                </ul>
47
+            </div>
48
+        </div>
49
+    </div>
50
+    <div class="form-group">
51
+        <label class="col-sm-2 control-label" for="Value">Value</label>
52
+        <div class="col-sm-9">
53
+            <textarea id="Value" ng-model="setting.Value" ng-if="setting.Type == 'string'"
54
+                      class="form-control" lu-enable-permission="{{ neededPermission }}"></textarea>
55
+
56
+            <input id="Value" ng-model="setting.Value" ng-if="setting.Type == 'int' || setting.Type == 'float'"
57
+                   class="form-control" type="number" required lu-enable-permission="{{ neededPermission }}" />
58
+
59
+            <div class="col-sm-9" ng-if="setting.Type == 'object'">{{ setting.Value }}</div>
60
+
61
+            <div class="btn-group" ng-if="setting.Type == 'bool'">
62
+                <button type="button" class="btn btn-primary dropdown-toggle btn-select" data-toggle="dropdown"
63
+                        href="" lu-enable-permission="{{ neededPermission }}">
64
+                    {{ setting.Value ? 'Yes' : 'No' }} <span class="caret"></span>
65
+                </button>
66
+                <ul class="dropdown-menu">
67
+                    <li><a href="" ng-click="setting.Value = false">No</a></li>
68
+                    <li><a href="" ng-click="setting.Value = true">Yes</a></li>
69
+                </ul>
70
+            </div>
71
+        </div>
72
+    </div>
73
+</dialog-ok-cancel>

+ 1
- 0
views/navbar.html View File

@@ -18,6 +18,7 @@
18 18
                 <li ui-sref-active="active"><a ui-sref="users" lu-show-permission="LU_USER_GET">Users</a></li>
19 19
                 <li ui-sref-active="active"><a ui-sref="groups" lu-show-permission="LU_GROUP_GET">Groups</a></li>
20 20
                 <li ui-sref-active="active"><a ui-sref="permissions" lu-show-permission="LU_PERM_GET">Permissions</a></li>
21
+                <li ui-sref-active="active"><a ui-sref="settings" lu-show-permission="LU_SETTING_GET">Settings</a></li>
21 22
                 <!--<li><a ui-sref="test" >Test</a></li>-->
22 23
             </ul>
23 24
             <ul class="nav navbar-nav navbar-right">

+ 1
- 1
views/permissions.html View File

@@ -1,4 +1,4 @@
1 1
 <!-- Page Content -->
2 2
 <div class="container">
3
-    <lu-edit-table options="luTable" class="row col-sm-8 col-sm-offset-2" ></lu-edit-table>
3
+    <lu-edit-table options="luTable" class="row col-sm-12" ></lu-edit-table>
4 4
 </div>

+ 4
- 0
views/settings.html View File

@@ -0,0 +1,4 @@
1
+<!-- Page Content -->
2
+<div class="container">
3
+    <lu-edit-table options="luTable" class="row col-sm-12" ></lu-edit-table>
4
+</div>

+ 1
- 1
views/users.html View File

@@ -1,4 +1,4 @@
1 1
 <!-- Page Content -->
2 2
 <div class="container">
3
-    <lu-edit-table options="luTable" class="row col-sm-8 col-sm-offset-2"></lu-edit-table>
3
+    <lu-edit-table options="luTable" class="row col-sm-12"></lu-edit-table>
4 4
 </div>

Loading…
Cancel
Save