1
- 'use strict'
1
+ ( function ( angular , _ ) {
2
+ 'use strict' ;
3
+
4
+ angular . module ( "umbraco" ) . controller ( "RJP.MultiUrlPickerController" , function ( $scope , dialogService , iconHelper , entityResource ) {
5
+ var documentIds = [ ] ;
6
+ var mediaIds = [ ] ;
7
+
8
+ $scope . renderModel = [ ] ;
9
+ $scope . cfg = { maxNumberOfItems : 0 , minNumberOfItems : 0 } ;
10
+ $scope . sortableOptions = { handle : '.handle' } ;
11
+
12
+ if ( $scope . model . value ) {
13
+ _ . each ( $scope . model . value , function ( item , i ) {
14
+ $scope . renderModel . push ( new Link ( item ) ) ;
15
+ if ( item . id ) {
16
+ ( item . isMedia ? mediaIds : documentIds ) . push ( item . id ) ;
17
+ }
18
+ } ) ;
19
+ }
2
20
3
- angular . module ( "umbraco" ) . controller ( "RJP.MultiUrlPickerController" , function ( $scope , dialogService , iconHelper , entityResource ) {
4
- var documentIds = [ ]
5
- , mediaIds = [ ]
21
+ var setIcon = function ( nodes ) {
22
+ if ( _ . isArray ( nodes ) ) {
23
+ _ . each ( nodes , setIcon ) ;
24
+ } else {
25
+ var item = _ . find ( $scope . renderModel , function ( item ) {
26
+ return + item . id === nodes . id ;
27
+ } ) ;
28
+ item . icon = iconHelper . convertFromLegacyIcon ( nodes . icon ) ;
29
+ }
30
+ } ;
6
31
7
- $scope . renderModel = [ ]
8
- $scope . cfg = { maxNumberOfItems : 0 , minNumberOfItems : 0 }
9
- $scope . sortableOptions = { handle : '.handle' }
32
+ entityResource . getByIds ( documentIds , 'Document' ) . then ( setIcon ) ;
33
+ entityResource . getByIds ( mediaIds , 'Media' ) . then ( setIcon ) ;
10
34
11
- if ( $scope . model . value ) {
12
- _ . each ( $scope . model . value , function ( item , i ) {
13
- $scope . renderModel . push ( new Link ( item ) )
14
- if ( item . id ) {
15
- ( item . isMedia ? mediaIds : documentIds ) . push ( item . id )
16
- }
17
- } )
18
- }
19
-
20
- var setIcon = function ( nodes ) {
21
- if ( _ . isArray ( nodes ) ) {
22
- _ . each ( nodes , setIcon )
23
- } else {
24
- var item = _ . find ( $scope . renderModel , function ( item ) {
25
- return + item . id === nodes . id
26
- } )
27
- item . icon = iconHelper . convertFromLegacyIcon ( nodes . icon ) ;
35
+ if ( $scope . model . config ) {
36
+ $scope . cfg = angular . extend ( $scope . cfg , $scope . model . config ) ;
28
37
}
29
- }
30
-
31
- entityResource . getByIds ( documentIds , 'Document' ) . then ( setIcon )
32
- entityResource . getByIds ( mediaIds , 'Media' ) . then ( setIcon )
33
-
34
- if ( $scope . model . config ) {
35
- $scope . cfg = angular . extend ( $scope . cfg , $scope . model . config )
36
- }
37
-
38
- if ( $scope . cfg . maxNumberOfItems <= 0 ) {
39
- delete $scope . cfg . maxNumberOfItems
40
- }
41
- if ( $scope . cfg . minNumberOfItems <= 0 ) {
42
- $scope . cfg . minNumberOfItems = 0
43
- }
44
-
45
- $scope . openLinkPicker = function ( ) {
46
- dialogService . linkPicker ( { callback : $scope . onContentSelected } )
47
- }
48
-
49
- $scope . edit = function ( index ) {
50
- var link = $scope . renderModel [ index ]
51
- dialogService . linkPicker ( {
38
+
39
+ if ( $scope . cfg . maxNumberOfItems <= 0 ) {
40
+ delete $scope . cfg . maxNumberOfItems ;
41
+ }
42
+ if ( $scope . cfg . minNumberOfItems <= 0 ) {
43
+ $scope . cfg . minNumberOfItems = 0 ;
44
+ }
45
+
46
+ $scope . openLinkPicker = function ( ) {
47
+ dialogService . linkPicker ( { callback : $scope . onContentSelected } ) ;
48
+ } ;
49
+
50
+ $scope . edit = function ( index ) {
51
+ var link = $scope . renderModel [ index ] ;
52
+ dialogService . linkPicker ( {
52
53
currentTarget : {
53
- id : link . isMedia ? null : link . id // the linkPicker breaks if it get an id for media
54
- , index : index
55
- , name : link . name
56
- , url : link . url
57
- , target : link . target
58
- , isMedia : link . isMedia
59
- }
60
- , callback : $scope . onContentSelected
61
- } )
62
- }
63
-
64
- $scope . remove = function ( index ) {
65
- $scope . renderModel . splice ( index , 1 )
66
- $scope . model . value = $scope . renderModel
67
- }
68
-
69
- $scope . $watch (
54
+ id : link . isMedia ? null : link . id , // the linkPicker breaks if it get an id for media
55
+ index : index ,
56
+ name : link . name ,
57
+ url : link . url ,
58
+ target : link . target ,
59
+ isMedia : link . isMedia ,
60
+ } ,
61
+ callback : $scope . onContentSelected
62
+ } ) ;
63
+ } ;
64
+
65
+ $scope . remove = function ( index ) {
66
+ $scope . renderModel . splice ( index , 1 ) ;
67
+ $scope . model . value = $scope . renderModel ;
68
+ } ;
69
+
70
+ $scope . $watch (
70
71
function ( ) {
71
- return $scope . renderModel . length
72
- }
73
- , function ( newVal ) {
72
+ return $scope . renderModel . length ;
73
+ } ,
74
+ function ( newVal ) {
74
75
if ( $scope . renderModel . length ) {
75
- $scope . model . value = $scope . renderModel
76
+ $scope . model . value = $scope . renderModel ;
76
77
} else {
77
- $scope . model . value = null
78
+ $scope . model . value = null ;
78
79
}
79
80
80
81
if ( $scope . cfg . minNumberOfItems && + $scope . cfg . minNumberOfItems > $scope . renderModel . length ) {
81
- $scope . multiUrlPickerForm . minCount . $setValidity ( 'minCount' , false )
82
+ $scope . multiUrlPickerForm . minCount . $setValidity ( 'minCount' , false ) ;
82
83
} else {
83
- $scope . multiUrlPickerForm . minCount . $setValidity ( 'minCount' , true )
84
+ $scope . multiUrlPickerForm . minCount . $setValidity ( 'minCount' , true ) ;
84
85
}
85
86
if ( $scope . cfg . maxNumberOfItems && + $scope . cfg . maxNumberOfItems < $scope . renderModel . length ) {
86
- $scope . multiUrlPickerForm . maxCount . $setValidity ( 'maxCount' , false )
87
+ $scope . multiUrlPickerForm . maxCount . $setValidity ( 'maxCount' , false ) ;
87
88
} else {
88
- $scope . multiUrlPickerForm . maxCount . $setValidity ( 'maxCount' , true )
89
+ $scope . multiUrlPickerForm . maxCount . $setValidity ( 'maxCount' , true ) ;
89
90
}
90
91
}
91
- )
92
+ ) ;
92
93
93
- $scope . $on ( "formSubmitting" , function ( ev , args ) {
94
- if ( $scope . renderModel . length ) {
95
- $scope . model . value = $scope . renderModel
96
- } else {
97
- $scope . model . value = null
98
- }
99
- } )
94
+ $scope . $on ( "formSubmitting" , function ( ev , args ) {
95
+ if ( $scope . renderModel . length ) {
96
+ $scope . model . value = $scope . renderModel ;
97
+ } else {
98
+ $scope . model . value = null ;
99
+ }
100
+ } ) ;
100
101
101
102
102
- $scope . onContentSelected = function ( e ) {
103
- var link = new Link ( e ) ;
103
+ $scope . onContentSelected = function ( e ) {
104
+ var link = new Link ( e ) ;
104
105
105
- if ( e . index != null ) {
106
- $scope . renderModel [ e . index ] = link
107
- } else {
108
- $scope . renderModel . push ( link )
109
- }
106
+ if ( e . index != = null ) {
107
+ $scope . renderModel [ e . index ] = link ;
108
+ } else {
109
+ $scope . renderModel . push ( link ) ;
110
+ }
110
111
111
- if ( e . id && e . id > 0 ) {
112
- entityResource . getById ( e . id , e . isMedia ? 'Media' : 'Document' ) . then ( setIcon )
113
- }
112
+ if ( e . id && e . id > 0 ) {
113
+ entityResource . getById ( e . id , e . isMedia ? 'Media' : 'Document' ) . then ( setIcon ) ;
114
+ }
114
115
115
- $scope . model . value = $scope . renderModel
116
- dialogService . close ( )
117
- }
118
-
119
- function Link ( link ) {
120
- this . id = link . id ;
121
- this . name = link . name || link . url ;
122
- this . url = link . url ;
123
- this . target = link . target ;
124
- this . isMedia = link . isMedia ;
125
- this . icon = link . icon || 'icon-link' ;
126
- }
127
- } )
116
+ $scope . model . value = $scope . renderModel ;
117
+ dialogService . close ( ) ;
118
+ } ;
119
+
120
+ function Link ( link ) {
121
+ this . id = link . id ;
122
+ this . name = link . name || link . url ;
123
+ this . url = link . url ;
124
+ this . target = link . target ;
125
+ this . isMedia = link . isMedia ;
126
+ this . icon = link . icon || 'icon-link' ;
127
+ }
128
+ } ) ;
129
+ } ) ( window . angular , window . _ ) ;
0 commit comments