66OC . Settings = OC . Settings || { } ;
77OC . Settings = _ . extend ( OC . Settings , {
88
9- _cachedGroups : null ,
9+ _cachedGroups : null ,
1010
11- /**
11+ /**
1212 * Setup selection box for group selection.
1313 *
1414 * Values need to be separated by a pipe "|" character.
@@ -20,77 +20,81 @@ OC.Settings = _.extend(OC.Settings, {
2020 * @param {Array } [options] extra options
2121 * @param {Array } [options.excludeAdmins=false] flag whether to exclude admin groups
2222 */
23- setupGroupsSelect : function ( $elements , extraOptions , options ) {
24- var self = this ;
25- options = options || { } ;
26- if ( $elements . length > 0 ) {
27- // Let's load the data and THEN init our select
28- $ . ajax ( {
29- url : OC . linkToOCS ( 'cloud/groups' , 2 ) + 'details' ,
30- dataType : 'json' ,
31- success : function ( data ) {
32- var results = [ ] ;
23+ setupGroupsSelect : function ( $elements , extraOptions , options ) {
24+ var self = this ;
25+ options = options || { } ;
26+ if ( $elements . length > 0 ) {
27+ // Let's load the data and THEN init our select
28+ $ . ajax ( {
29+ url : OC . linkToOCS ( 'cloud/groups' , 2 ) + 'details' ,
30+ dataType : 'json' ,
31+ success : function ( data ) {
32+ var results = [ ] ;
3333
34- if ( data . ocs . data . groups && data . ocs . data . groups . length > 0 ) {
34+ if ( data . ocs . data . groups && data . ocs . data . groups . length > 0 ) {
3535
36- data . ocs . data . groups . forEach ( function ( group ) {
37- if ( ! options . excludeAdmins || group . id !== 'admin' ) {
38- results . push ( { id : group . id , displayname : group . displayname } ) ;
39- }
40- } )
36+ data . ocs . data . groups . forEach ( function ( group ) {
37+ if ( ! options . excludeAdmins || group . id !== 'admin' ) {
38+ results . push ( { id : group . id , displayname : group . displayname } ) ;
39+ }
40+ } )
4141
42- // note: settings are saved through a "change" event registered
43- // on all input fields
44- $elements . select2 ( _ . extend ( {
45- placeholder : t ( 'core' , 'Groups' ) ,
46- allowClear : true ,
47- multiple : true ,
48- toggleSelect : true ,
49- separator : '|' ,
50- data : { results : results , text : 'displayname' } ,
51- initSelection : function ( element , callback ) {
52- var groups = $ ( element ) . val ( ) ;
53- var selection ;
54- if ( groups && results . length > 0 ) {
55- selection = _ . map ( ( groups || [ ] ) . split ( '|' ) . sort ( ) , function ( groupId ) {
56- return {
57- id : groupId ,
58- displayname : results . find ( function ( group ) {
59- return group . id === groupId ;
60- } ) . displayname
61- } ;
62- } ) ;
63- } else if ( groups ) {
64- selection = _ . map ( ( groups || [ ] ) . split ( '|' ) . sort ( ) , function ( groupId ) {
65- return {
66- id : groupId ,
67- displayname : groupId
68- } ;
69- } ) ;
70- }
71- callback ( selection ) ;
72- } ,
73- formatResult : function ( element ) {
74- return escapeHTML ( element . displayname ) ;
75- } ,
76- formatSelection : function ( element ) {
77- return escapeHTML ( element . displayname ) ;
78- } ,
79- escapeMarkup : function ( m ) {
80- // prevent double markup escape
81- return m ;
82- }
83- } , extraOptions || { } ) ) ;
84- } else {
85- OC . Notification . show ( t ( 'settings' , 'Group list is empty' ) , { type : 'error' } ) ;
86- console . log ( data ) ;
87- }
88- } ,
89- error : function ( data ) {
90- OC . Notification . show ( t ( 'settings' , 'Unable to retrieve the group list' ) , { type : 'error' } ) ;
91- console . log ( data ) ;
92- }
93- } ) ;
94- }
95- }
96- } ) ;
42+ // note: settings are saved through a "change" event registered
43+ // on all input fields
44+ $elements . select2 ( _ . extend ( {
45+ placeholder : t ( 'core' , 'Groups' ) ,
46+ allowClear : true ,
47+ multiple : true ,
48+ toggleSelect : true ,
49+ separator : '|' ,
50+ data : { results : results , text : 'displayname' } ,
51+ initSelection : function ( element , callback ) {
52+ var groups = $ ( element ) . val ( ) ;
53+ var selection ;
54+ if ( groups && results . length > 0 ) {
55+ selection = _ . map ( _ . filter ( ( groups || [ ] ) . split ( '|' ) . sort ( ) , function ( groupId ) {
56+ return results . find ( function ( group ) {
57+ return group . id === groupId
58+ } ) !== undefined
59+ } ) , function ( groupId ) {
60+ return {
61+ id : groupId ,
62+ displayname : results . find ( function ( group ) {
63+ return group . id === groupId
64+ } ) . displayname
65+ }
66+ } )
67+ } else if ( groups ) {
68+ selection = _ . map ( ( groups || [ ] ) . split ( '|' ) . sort ( ) , function ( groupId ) {
69+ return {
70+ id : groupId ,
71+ displayname : groupId
72+ } ;
73+ } ) ;
74+ }
75+ callback ( selection ) ;
76+ } ,
77+ formatResult : function ( element ) {
78+ return escapeHTML ( element . displayname ) ;
79+ } ,
80+ formatSelection : function ( element ) {
81+ return escapeHTML ( element . displayname ) ;
82+ } ,
83+ escapeMarkup : function ( m ) {
84+ // prevent double markup escape
85+ return m ;
86+ }
87+ } , extraOptions || { } ) ) ;
88+ } else {
89+ OC . Notification . show ( t ( 'settings' , 'Group list is empty' ) , { type : 'error' } ) ;
90+ console . log ( data ) ;
91+ }
92+ } ,
93+ error : function ( data ) {
94+ OC . Notification . show ( t ( 'settings' , 'Unable to retrieve the group list' ) , { type : 'error' } ) ;
95+ console . log ( data ) ;
96+ }
97+ } ) ;
98+ }
99+ }
100+ } ) ;
0 commit comments