@@ -10,62 +10,64 @@ vireo.controller("OrganizationSideBarController", function ($controller, $scope,
1010
1111 var organizationCategories = OrganizationCategoryRepo . getAll ( ) ;
1212
13+ $scope . forms = { } ;
14+
1315 $scope . ready = $q . all ( [
1416 OrganizationCategoryRepo . ready ( )
1517 ] ) ;
1618
17- $scope . forms = { } ;
19+ $scope . ready . then ( function ( ) {
20+ $scope . organizationCategories = organizationCategories . filter ( function ( category ) {
21+ return ! ! category && category . name !== 'System' ;
22+ } ) ;
1823
19- $scope . organizationCategories = organizationCategories . filter ( function ( category ) {
20- return ! ! category && category . name !== 'System' ;
21- } ) ;
24+ $scope . reset = function ( ) {
25+ $scope . organizationRepo . clearValidationResults ( ) ;
26+
27+ for ( var key in $scope . forms ) {
28+ if ( $scope . forms [ key ] !== undefined && ! $scope . forms [ key ] . $pristine ) {
29+ $scope . forms [ key ] . $setPristine ( ) ;
30+ $scope . forms [ key ] . $setUntouched ( ) ;
31+ }
32+ }
2233
23- $scope . reset = function ( ) {
24- $scope . organizationRepo . clearValidationResults ( ) ;
34+ $scope . newOrganization = OrganizationRepo . resetNewOrganization ( ) ;
2535
26- for ( var key in $scope . forms ) {
27- if ( $scope . forms [ key ] !== undefined && ! $scope . forms [ key ] . $pristine ) {
28- $scope . forms [ key ] . $setPristine ( ) ;
29- $scope . forms [ key ] . $setUntouched ( ) ;
36+ if ( $scope . newOrganization . category === undefined ) {
37+ $scope . newOrganization . category = $scope . organizationCategories [ 0 ] ;
3038 }
31- }
32-
33- $scope . newOrganization = OrganizationRepo . resetNewOrganization ( ) ;
34-
35- if ( $scope . newOrganization . category === undefined ) {
36- $scope . newOrganization . category = $scope . organizationCategories [ 0 ] ;
37- }
38-
39- if ( $scope . newOrganization . parent === undefined ) {
40- $scope . newOrganization . parent = $scope . organizations [ 0 ] ;
41- }
42- } ;
43-
44- $scope . createNewOrganization = function ( hierarchical ) {
45- $scope . creatingNewOrganization = true ;
46- var parentOrganization = hierarchical === 'true' ? OrganizationRepo . newOrganization . parent : $scope . organizations [ 0 ] ;
47- OrganizationRepo . create ( {
48- "name" : OrganizationRepo . newOrganization . name ,
49- "category" : OrganizationRepo . newOrganization . category ,
50- "parentOrganization" : {
51- "id" : parentOrganization . id ,
52- "name" : parentOrganization . name ,
53- "category" : parentOrganization . category
39+
40+ if ( $scope . newOrganization . parent === undefined ) {
41+ $scope . newOrganization . parent = $scope . organizations [ 0 ] ;
42+ }
43+ } ;
44+
45+ $scope . createNewOrganization = function ( hierarchical ) {
46+ $scope . creatingNewOrganization = true ;
47+ var parentOrganization = hierarchical === 'true' ? OrganizationRepo . newOrganization . parent : $scope . organizations [ 0 ] ;
48+ OrganizationRepo . create ( {
49+ "name" : OrganizationRepo . newOrganization . name ,
50+ "category" : OrganizationRepo . newOrganization . category ,
51+ "parentOrganization" : {
52+ "id" : parentOrganization . id ,
53+ "name" : parentOrganization . name ,
54+ "category" : parentOrganization . category
55+ }
56+ } , parentOrganization ) . then ( function ( ) {
57+ $scope . creatingNewOrganization = false ;
58+ $scope . reset ( ) ;
59+ } ) ;
60+ } ;
61+
62+ OrganizationRepo . getAllSpecific ( 'tree' ) . then ( function ( orgs ) {
63+ $scope . organizations . length = 0 ;
64+
65+ if ( ! ! orgs && orgs . length > 0 ) {
66+ angular . extend ( $scope . organizations , orgs ) ;
5467 }
55- } , parentOrganization ) . then ( function ( ) {
56- $scope . creatingNewOrganization = false ;
68+
5769 $scope . reset ( ) ;
5870 } ) ;
59- } ;
60-
61- OrganizationRepo . getAllSpecific ( 'tree' ) . then ( function ( orgs ) {
62- $scope . organizations . length = 0 ;
63-
64- if ( ! ! orgs && orgs . length > 0 ) {
65- angular . extend ( $scope . organizations , orgs ) ;
66- }
67-
68- $scope . reset ( ) ;
6971 } ) ;
7072
7173} ) ;
0 commit comments