Commits

Endy Muhardin committed 133599a

implement remove permission dari role

Comments (0)

Files changed (2)

belajar-restful-web/src/main/webapp/js/aplikasi-controller.js

             }
             $scope.currentRole = RoleService.get({
                 id: x.id
-                });
+            });
             RoleService.unselectedPermission(x).success(function(data){
                 $scope.unselectedPermission = data;
             });
             }
             RoleService.save($scope.currentRole)
             .success(function(){
-                $scope.currentRole = RoleService.get({
-                    id: $scope.currentRole.id
-                });;
+                RoleService.unselectedPermission($scope.currentRole)
+                .success(function(data){
+                    $scope.unselectedPermission = data;
+                    $scope.currentRole = RoleService.get({
+                        id: $scope.currentRole.id
+                    });
+                });
             });
             $scope.showPermissionDialog = false;
         }
             console.log($scope.selectedPermission);
             $scope.showPermissionDialog = false;
         }
+
+        $scope.removeSelectedPermission = function(x){
+            if(x.id == null){
+                return;
+            }
+            var ixPermission = -1;
+            for(var i = 0; i < $scope.currentRole.permissionSet.length; i++){
+                if(x.id === $scope.currentRole.permissionSet[i].id){
+                    ixPermission = i;
+                    break;
+                }
+            }
+            if(ixPermission >= 0){
+                $scope.currentRole.permissionSet.splice(ixPermission, 1);
+                RoleService.save($scope.currentRole)
+                .success(function(){
+                    RoleService.unselectedPermission($scope.currentRole)
+                    .success(function(data){
+                        $scope.unselectedPermission = data;
+                        $scope.currentRole = RoleService.get({
+                            id: $scope.currentRole.id
+                        });
+                    });
+                });
+            }
+        }
         
         $scope.selectAllMenu = function($event){
             if($event.target.checked){

belajar-restful-web/src/main/webapp/pages/system/role.html

                     <td>{{m.label}}</td>
                     <td>{{m.action}}</td>
                     <td>
-                        <a><i class="icon-remove"></i></a>
+                        <a removeSelectedMenu(p)><i class="icon-remove"></i></a>
                     </td>
                 </tr>
             </tbody>
                     <td>{{p.label}}</td>
                     <td>{{p.value}}</td>
                     <td>
-                        <a><i class="icon-remove"></i></a>
+                        <a ng-click="removeSelectedPermission(p)"><i class="icon-remove"></i></a>
                     </td>
                 </tr>
             </tbody>