@@ -2,14 +2,10 @@ import {
22 Component ,
33 OnDestroy ,
44 OnInit ,
5+ Injector ,
56 ChangeDetectionStrategy
67} from '@angular/core' ;
7- import {
8- FormBuilder ,
9- FormGroup ,
10- Validators
11- } from "@angular/forms" ;
12- import { AccessRoleSandbox } from '../../role.sandbox' ;
8+ import { RoleFormContainer } from '../form/role.form' ;
139import RoleForm from '../../models/role-form.model' ;
1410
1511@Component ( {
@@ -18,69 +14,28 @@ import RoleForm from '../../models/role-form.model';
1814 styleUrls : [ './create-role.container.scss' ] ,
1915 changeDetection : ChangeDetectionStrategy . OnPush
2016} )
21- export class CreateRoleContainer implements OnInit {
22-
23- /**
24- * Form Group
25- *
26- * @type {FormGroup }
27- * @memberof CreateRoleContainer
28- */
29- public form : FormGroup ;
30-
31- itemList = [ ] ;
32- selectedItems = [ ] ;
33- settings = { } ;
34-
17+ export class CreateRoleContainer extends RoleFormContainer implements OnInit {
18+
3519 /**
36- * Creates an instance of CreateRoleContainer .
20+ * Creates an instance of UpdateRoleContainer .
3721 *
38- * @param {AccessRoleSandbox } accessRoleSandbox
39- * @param {FormBuilder } formBuilder
40- * @memberof CreateRoleContainer
22+ * @param {Injector } injector
23+ * @memberof UpdateRoleContainer
4124 */
4225 constructor (
43- public accessRoleSandbox : AccessRoleSandbox ,
44- private formBuilder : FormBuilder
45- ) { }
26+ injector : Injector
27+ ) {
28+ super ( injector ) ;
29+ }
4630
4731 /**
4832 * On Init container
4933 *
5034 * @memberof CreateRoleContainer
5135 */
5236 ngOnInit ( ) {
53- this . form = this . formBuilder . group ( {
54- name : [ "" , Validators . required ] ,
55- sort : [ "" , Validators . required ] ,
56- status : [ "" , Validators . required ] ,
57- permissions : [ [ ] , Validators . required ]
58- } ) ;
59-
60- this . itemList = [
61- { "id" : 1 , "itemName" : "Angular" } ,
62- { "id" : 2 , "itemName" : "JavaScript" } ,
63- { "id" : 3 , "itemName" : "HTML" } ,
64- { "id" : 4 , "itemName" : "CSS" } ,
65- { "id" : 5 , "itemName" : "ReactJS" } ,
66- { "id" : 6 , "itemName" : "HTML5" } ,
67- { "id" : 1 , "itemName" : "Angular" } ,
68- { "id" : 2 , "itemName" : "JavaScript" } ,
69- { "id" : 3 , "itemName" : "HTML" } ,
70- { "id" : 4 , "itemName" : "CSS" } ,
71- { "id" : 5 , "itemName" : "ReactJS" } ,
72- { "id" : 6 , "itemName" : "HTML5" }
73- ] ;
74- this . selectedItems = [ { "id" : 2 , "itemName" : "JavaScript" } ] ;
75- this . settings = {
76- text : "Select Permissions" ,
77- selectAllText : 'Select All' ,
78- unSelectAllText : 'UnSelect All' ,
79- classes : "custom-multiselect-checkbox-dp" ,
80- enableSearchFilter : true ,
81- searchPlaceholderText : 'Search Permissions...' ,
82- badgeShowLimit : 5
83- } ;
37+ this . registerSubscriptions ( ) ;
38+ this . accessPermissionSandbox . getPermissions ( ) ;
8439 }
8540
8641 /**
@@ -91,9 +46,15 @@ export class CreateRoleContainer implements OnInit {
9146 * @memberof CreateRoleContainer
9247 */
9348 public onSubmit ( event : Event , form : any ) {
94- const roleForm = new RoleForm ( form ) ;
95-
96- this . accessRoleSandbox . createRole ( roleForm ) ;
49+ const formData = {
50+ name : form . name ,
51+ sort : form . sort ,
52+ status : form . status ,
53+ permissions : this . getFormPermissions ( ) ,
54+ associated_permissions : this . getFormPermissions ( )
55+ }
56+
57+ this . accessRoleSandbox . createRole ( new RoleForm ( formData ) ) ;
9758 }
9859
9960 /**
@@ -102,24 +63,8 @@ export class CreateRoleContainer implements OnInit {
10263 * @memberof CreateRoleContainer
10364 */
10465 public onNgDestroy ( ) {
66+ this . routerSubscription . unsubscribe ( ) ;
10567 this . accessRoleSandbox . unregisterEvents ( ) ;
106- }
107-
108- public onItemSelect ( item : any ) {
109- console . log ( item ) ;
110- console . log ( this . selectedItems ) ;
111- }
112-
113- public OnItemDeSelect ( item : any ) {
114- console . log ( item ) ;
115- console . log ( this . selectedItems ) ;
116- }
117-
118- public onSelectAll ( items : any ) {
119- console . log ( items ) ;
120- }
121-
122- public onDeSelectAll ( items : any ) {
123- console . log ( items ) ;
68+ this . accessPermissionSandbox . unregisterEvents ( ) ;
12469 }
12570}
0 commit comments