33 * This file is licensed under the Affero General Public License version 3 or later.
44 * See the COPYING-README file.
55 */
6- OC . Settings = OC . Settings || { } ;
6+ OC . 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,38 +20,38 @@ 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+ const 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+ const 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 ) {
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+ const groups = $ ( element ) . val ( )
53+ let selection
54+ if ( groups && results . length > 0 ) {
5555 selection = _ . map ( _ . filter ( ( groups || [ ] ) . split ( '|' ) . sort ( ) , function ( groupId ) {
5656 return results . find ( function ( group ) {
5757 return group . id === groupId
@@ -61,40 +61,40 @@ OC.Settings = _.extend(OC.Settings, {
6161 id : groupId ,
6262 displayname : results . find ( function ( group ) {
6363 return group . id === groupId
64- } ) . displayname
64+ } ) . displayname ,
6565 }
6666 } )
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- } ) ;
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