Endy Muhardin avatar Endy Muhardin committed a25025c

implement add/remove menu dari role

Comments (0)

Files changed (2)

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

         
         $scope.saveSelectedMenu = function(){
             console.log($scope.selectedMenu);
+            for ( var i = 0; i < $scope.selectedMenu.length; i++) {
+                var p = {id: $scope.selectedMenu[i]};
+                $scope.currentRole.menuSet.push(p);
+            }
+            RoleService.save($scope.currentRole)
+            .success(function(){
+                RoleService.unselectedMenu($scope.currentRole)
+                .success(function(data){
+                    $scope.unselectedMenu = data;
+                    $scope.currentRole = RoleService.get({
+                        id: $scope.currentRole.id
+                    });
+                });
+            });
             $scope.showMenuDialog = false;
         }
         
             console.log($scope.selectedMenu);
             $scope.showMenuDialog = false;
         }
+
+        $scope.removeSelectedMenu = function(x){
+            if(x.id == null){
+                return;
+            }
+            var ixMenu = -1;
+            for(var i = 0; i < $scope.currentRole.menuSet.length; i++){
+                if(x.id === $scope.currentRole.menuSet[i].id){
+                    ixMenu = i;
+                    break;
+                }
+            }
+            if(ixMenu >= 0){
+                $scope.currentRole.menuSet.splice(ixMenu, 1);
+                RoleService.save($scope.currentRole)
+                .success(function(){
+                    RoleService.unselectedMenu($scope.currentRole)
+                    .success(function(data){
+                        $scope.unselectedMenu = data;
+                        $scope.currentRole = RoleService.get({
+                            id: $scope.currentRole.id
+                        });
+                    });
+                });
+            }
+        }
     }])
     .controller('UserController', ['$scope', 'UserService', 'RoleService', function($scope, UserService, RoleService){
         $scope.users = UserService.query();

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

                     <td>{{m.label}}</td>
                     <td>{{m.action}}</td>
                     <td>
-                        <a removeSelectedMenu(p)><i class="icon-remove"></i></a>
+                        <a ng-click="removeSelectedMenu(m)"><i class="icon-remove"></i></a>
                     </td>
                 </tr>
             </tbody>
                                ng-click="updateSelectedMenu($event, p.id)">
                     </td>
                     <td>{{p.label}}</td>
-                    <td>{{p.value}}</td>
+                    <td>{{p.action}}</td>
                 </tr>
             </tbody>
         </table>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.