@@ -96,8 +96,7 @@ export default class extends Controller.extend(EmberTableControllerMixin) {
9696        extraValuePaths  : [ 'isLocked' ] , 
9797        cellComponent    : 'ui-table/cell/events/view/sessions/cell-lock-session' , 
9898        actions          : { 
99-           unlockSession  : this . unlockSession . bind ( this ) , 
100-           lockSession    : this . lockSession . bind ( this ) 
99+           lockSession : this . lockSession . bind ( this ) 
101100        } 
102101      } 
103102    ] ; 
@@ -137,51 +136,29 @@ export default class extends Controller.extend(EmberTableControllerMixin) {
137136  } 
138137
139138  @action 
140-   lockSession ( session_id )  { 
141-     let  session  =   this . store . peekRecord ( 'session' ,  session_id ,  {  backgroundReload : false  } ) ; 
142-     session . set ( 'isLocked' ,  true ) ; 
143-     this . set ( 'isLoading' ,  true ) ; 
144-     session . save ( ) 
145-       . then ( ( )  =>  { 
146-         this . notify . success ( this . l10n . t ( 'Session has been locked successfully.' ) , 
147-           { 
148-             id : 'session_locked' 
149-           } ) ; 
150-         this . refreshModel . bind ( this ) ( ) ; 
151-       } ) 
152-       . catch ( ( )  =>  { 
153-         this . notify . error ( this . l10n . t ( 'An unexpected error has occurred.' ) , 
154-           { 
155-             id : 'session_lock_error' 
156-           } ) ; 
157-       } ) 
158-       . finally ( ( )  =>  { 
159-         this . set ( 'isLoading' ,  false ) ; 
160-       } ) ; 
161-   } 
162- 
163-   @action 
164-   unlockSession ( session_id )  { 
165-     let  session  =   this . store . peekRecord ( 'session' ,  session_id ,  {  backgroundReload : false  } ) ; 
166-     session . set ( 'isLocked' ,  false ) ; 
139+   async  lockSession ( session_id ,  lock )  { 
140+     const  session  =   this . store . peekRecord ( 'session' ,  session_id ,  {  backgroundReload : false  } ) ; 
141+     const  {  isLocked }  =  session ; 
142+     session . set ( 'isLocked' ,  lock ) ; 
167143    this . set ( 'isLoading' ,  true ) ; 
168-     session . save ( ) 
169-       . then ( ( )  =>  { 
170-         this . notify . success ( this . l10n . t ( 'Session has been unlocked successfully.' ) , 
171-           { 
172-             id : 'session_unlock' 
173-           } ) ; 
174-         this . refreshModel . bind ( this ) ( ) ; 
175-       } ) 
176-       . catch ( ( )  =>  { 
177-         this . notify . error ( this . l10n . t ( 'An unexpected error has occurred.' ) , 
178-           { 
179-             id : 'session_unexpected_unlock' 
180-           } ) ; 
181-       } ) 
182-       . finally ( ( )  =>  { 
183-         this . set ( 'isLoading' ,  false ) ; 
184-       } ) ; 
144+     const  lockMessage  =  lock  ? 'locked'  : 'unlocked' ; 
145+     try  { 
146+       await  session . save ( ) ; 
147+       this . notify . success ( this . l10n . t ( `Session has been ${  lockMessage  }   successfully.` ) , 
148+         { 
149+           id : 'session_lock' 
150+         } ) ; 
151+       this . refreshModel . bind ( this ) ( ) ; 
152+     }  catch  ( e )  { 
153+       session . set ( 'isLocked' ,  isLocked ) ; 
154+       console . error ( 'Error while changing session lock in organizer session list' ,  e ) ; 
155+       this . notify . error ( this . l10n . t ( 'An unexpected error has occurred.' ) , 
156+         { 
157+           id : 'session_unexpected_lock' 
158+         } ) ; 
159+     }  finally  { 
160+       this . set ( 'isLoading' ,  false ) ; 
161+     } 
185162  } 
186163
187164  @action 
0 commit comments