@@ -198,27 +198,7 @@ require('../../css/piklor.css');
198198 cache : false ,
199199 } ,
200200 } ) ;
201- $ . ajax ( OC . generateUrl ( '/apps/timetracker/ajax/tags' ) , {
202- dataType : "json"
203- } ) . done ( function ( data ) {
204- var arr = $ ( '#locked-select-tags' ) . val ( ) . map ( function ( x ) {
205- return parseInt ( x ) ;
206- } ) ;
207- $ . each ( data . Tags , function ( index , value ) {
208- if ( arr . includes ( value . id ) ) {
209- $ ( '#locked-select-tags' ) . append (
210- '<option selected="selected" value="' + value . id + '">' + value . name + '</option>'
211- ) ;
212- } else {
213- $ ( '#locked-select-tags' ) . append (
214- '<option value="' + value . id + '">' + value . name + '</option>'
215- ) ;
216201
217- }
218- }
219- ) ;
220- $ ( '#locked-select-tags' ) . trigger ( "change" ) ;
221- } ) ;
222202
223203
224204
@@ -227,6 +207,10 @@ require('../../css/piklor.css');
227207 width : '200px' ,
228208 placeholder : "Select users..." ,
229209 allowClear : true ,
210+ results : function ( data ) {
211+ lastResults = data . results ;
212+ return { results : data } ;
213+ } ,
230214 ajax : {
231215 headers : {
232216 "requesttoken" : oc_requesttoken ,
@@ -417,30 +401,69 @@ require('../../css/piklor.css');
417401 clientName : row . getData ( ) . client ,
418402 } ;
419403
420- // var tagSelectData = [{
421- // allowedTags: row.getData().allowedTags,
422-
423- // }];
424-
425- //form.find("#client-select-popup").select2("val",JSON.stringify(clientSelectData));
426- $ ( "#client-select-popup" ) . val ( clientSelectData . clientId ) . change ( ) ;
427- // $('#client-select-popup').append(
428- // '<option selected="selected" value="' + clientSelectData.clientId + '">' + clientSelectData.clientName + '</option>'
429- // );
404+ if ( clientSelectData . clientId != null ) {
405+ $ ( '#client-select-popup' ) . append (
406+ '<option selected="selected" value="' + clientSelectData . clientId + '">' + clientSelectData . clientName + '</option>'
407+ ) ;
408+ $ ( "#client-select-popup" ) . trigger ( 'change' ) ;
409+ }
430410
431411 form . find ( "#archived" ) . prop ( 'checked' , row . getData ( ) . archived ) ;
432412 if ( isAdmin ( ) ) {
433413 var tags = row . getData ( ) . origAllowedTags . map ( function ( e ) { return e . id ; } ) ;
434414 var users = row . getData ( ) . allowedUsers ;
435415
436-
437- //form.find("#locked-select-tags").select2("val",tags);
438- // $('#locked-select-tags').append(tags.each( function(tag){
439- // '<option selected="selected" value="' + tag + '">' + tag + '</option>'
440- // }).join()
441- // );
442- $ ( "#locked-select-tags" ) . val ( tags ) . change ( ) ;
443- $ ( "#locked-select-users" ) . val ( users ) . change ( ) ;
416+ $ . ajax ( OC . generateUrl ( '/apps/timetracker/ajax/tags' ) , {
417+ dataType : "json"
418+ } ) . done ( function ( data ) {
419+ $ ( '#locked-select-tags' ) . html ( '' ) ;
420+ $ . each ( data . Tags , function ( index , value ) {
421+ if ( tags . includes ( value . id ) ) {
422+ var option = new Option ( value . name , value . id , true , true ) ;
423+ $ ( '#locked-select-tags' ) . append ( option ) . trigger ( 'change' ) ;
424+
425+ }
426+ }
427+ ) ;
428+ $ ( '#locked-select-tags' ) . trigger ( {
429+ type : 'select2:select' ,
430+ params : {
431+ data : data
432+ }
433+ } ) ;
434+
435+ } ) ;
436+
437+ $ . ajax ( '/ocs/v2.php/cloud/users/details?offset=0&search=' , {
438+ dataType : "json" ,
439+ headers : {
440+ "requesttoken" : oc_requesttoken ,
441+
442+ } ,
443+ } ) . done ( function ( data ) {
444+
445+ var userMap = $ . map ( data . ocs . data . users , function ( val , i ) {
446+ return { id : i , text :val . displayname } ;
447+ } ) ;
448+
449+ $ ( '#locked-select-users' ) . val ( null ) . trigger ( 'change' ) ;
450+ $ ( '#locked-select-users' ) . html ( '' ) ;
451+ $ . each ( userMap , function ( index , value ) {
452+ if ( users . includes ( value . text ) ) {
453+ var option = new Option ( value . text , value . id , true , true ) ;
454+ $ ( '#locked-select-users' ) . append ( option ) . trigger ( 'change' ) ;
455+
456+ }
457+ }
458+ ) ;
459+ $ ( '#locked-select-users' ) . trigger ( {
460+ type : 'select2:select' ,
461+ params : {
462+ data : data
463+ }
464+ } ) ;
465+ } ) ;
466+
444467 form . find ( "#locked" ) . prop ( 'checked' , row . getData ( ) . locked ) ;
445468 if ( $ ( '#locked' ) . is ( ':checked' ) ) {
446469 $ ( "#locked-options" ) . removeClass ( 'hidden' ) ;
0 commit comments