@@ -429,8 +429,6 @@ Visibility.change(function (e, state) {
429
429
430
430
// when page ready
431
431
$ ( document ) . ready ( function ( ) {
432
- if ( ui . toolbar . edit . data ( 'blockSource' ) && ! isLogin ) { replaceUrl ( window . location . href ) }
433
-
434
432
idle . checkAway ( )
435
433
checkResponsive ( )
436
434
// if in smaller screen, we don't need advanced scrollbar
@@ -519,79 +517,80 @@ function replaceUrl (url) {
519
517
}
520
518
}
521
519
522
- //
520
+ //denied access to view or both mode if user have not permission for that
523
521
function allowVisibleSource ( isLogin , permission ) {
524
- console . log ( 'isWokr?' , isLogin , permission )
525
522
switch ( permission ) {
526
523
case 'freely' :
527
524
blockSourceView = false
528
525
break
529
526
case 'editable' :
530
527
if ( ! isLogin ) {
531
528
blockSourceView = true
532
- uiByNativeJS . toolbar . edit . setAttribute ( 'disabled' , null )
533
- uiByNativeJS . toolbar . edit . setAttribute ( 'title' , 'You have no rights to edit this note' )
534
- uiByNativeJS . toolbar . both . setAttribute ( 'disabled' , null )
535
- uiByNativeJS . toolbar . both . setAttribute ( 'title' , 'You have no rights to edit this note' )
529
+ disableControls ( )
536
530
} else {
537
531
blockSourceView = false
538
- uiByNativeJS . toolbar . edit . removeAttribute ( 'disabled' )
539
- uiByNativeJS . toolbar . edit . setAttribute ( 'title' , 'Edit (Ctrl+Alt+E)' )
540
- uiByNativeJS . toolbar . both . removeAttribute ( 'disabled' )
541
- uiByNativeJS . toolbar . both . setAttribute ( 'title' , 'Both (Ctrl+Alt+B)' )
532
+ enableControls ( )
542
533
}
543
534
break
544
535
case 'limited' :
545
536
if ( ! isLogin ) {
546
537
blockSourceView = true
547
- uiByNativeJS . toolbar . edit . setAttribute ( 'disabled' , null )
548
- uiByNativeJS . toolbar . edit . setAttribute ( 'title' , 'You have no rights to edit this note' )
549
- uiByNativeJS . toolbar . both . setAttribute ( 'disabled' , null )
550
- uiByNativeJS . toolbar . both . setAttribute ( 'title' , 'You have no rights to edit this note' )
538
+ disableControls ( )
551
539
} else {
552
540
blockSourceView = false
553
- uiByNativeJS . toolbar . edit . removeAttribute ( 'disabled' )
554
- uiByNativeJS . toolbar . edit . setAttribute ( 'title' , 'Edit (Ctrl+Alt+E)' )
555
- uiByNativeJS . toolbar . both . removeAttribute ( 'disabled' )
556
- uiByNativeJS . toolbar . both . setAttribute ( 'title' , 'Both (Ctrl+Alt+B)' )
541
+ enableControls ( )
557
542
}
558
543
break
559
544
case 'locked' :
560
545
if ( personalInfo . userid && window . owner && personalInfo . userid === window . owner ) {
561
546
blockSourceView = false
562
547
} else {
563
548
blockSourceView = true
564
- uiByNativeJS . toolbar . edit . setAttribute ( 'disabled' , null )
565
- uiByNativeJS . toolbar . edit . setAttribute ( 'title' , 'You have no rights to edit this note' )
566
- uiByNativeJS . toolbar . both . setAttribute ( 'disabled' , null )
567
- uiByNativeJS . toolbar . both . setAttribute ( 'title' , 'You have no rights to edit this note' )
549
+ disableControls ( )
568
550
}
569
551
break
570
552
case 'protected' :
571
553
if ( personalInfo . userid && window . owner && personalInfo . userid === window . owner ) {
572
554
blockSourceView = false
573
555
} else {
574
556
blockSourceView = true
575
- uiByNativeJS . toolbar . edit . setAttribute ( 'disabled' , null )
576
- uiByNativeJS . toolbar . edit . setAttribute ( 'title' , 'You have no rights to edit this note' )
577
- uiByNativeJS . toolbar . both . setAttribute ( 'disabled' , null )
578
- uiByNativeJS . toolbar . both . setAttribute ( 'title' , 'You have no rights to edit this note' )
557
+ disableControls ( )
579
558
}
580
559
break
581
560
case 'private' :
582
561
if ( personalInfo . userid && window . owner && personalInfo . userid === window . owner ) {
583
562
blockSourceView = false
584
563
} else {
585
564
blockSourceView = true
586
- uiByNativeJS . toolbar . edit . setAttribute ( 'disabled' , null )
587
- uiByNativeJS . toolbar . edit . setAttribute ( 'title' , 'You have no rights to edit this note' )
588
- uiByNativeJS . toolbar . both . setAttribute ( 'disabled' , null )
589
- uiByNativeJS . toolbar . both . setAttribute ( 'title' , 'You have no rights to edit this note' )
565
+ disableControls ( )
590
566
}
591
567
break
592
568
}
593
569
}
594
570
571
+ //set disable attr for UI
572
+ function disableControls ( ) {
573
+ ui . toolbar . edit . attr ( {
574
+ disabled : 'true' ,
575
+ title : 'You have no rights to edit this note'
576
+ } )
577
+ ui . toolbar . both . attr ( {
578
+ disabled : 'true' ,
579
+ title : 'You have no rights to edit this note'
580
+ } )
581
+ }
582
+ //remove disable attr from UI
583
+ function enableControls ( ) {
584
+ ui . toolbar . edit . removeAttr ( 'disabled' )
585
+ ui . toolbar . both . removeAttr ( 'disabled' )
586
+ ui . toolbar . edit . attr ( {
587
+ title : 'Edit (Ctrl+Alt+E)'
588
+ } )
589
+ ui . toolbar . both . attr ( {
590
+ title : 'Both (Ctrl+Alt+B)'
591
+ } )
592
+ }
593
+
595
594
//checking is user log in
596
595
function userIsLogin ( userPersonalInfo ) {
597
596
if ( userPersonalInfo . hasOwnProperty ( 'login' ) ) {
@@ -2160,6 +2159,8 @@ socket.on('refresh', function (data) {
2160
2159
updateInfo ( data )
2161
2160
updatePermission ( data . permission )
2162
2161
currentPermission = data . permission
2162
+ if ( ui . toolbar . edit . data ( 'blockSource' ) ) { allowVisibleSource ( userIsLogin ( personalInfo ) , currentPermission ) }
2163
+ if ( ui . toolbar . edit . data ( 'blockSource' ) && blockSourceView ) { replaceUrl ( window . location . href ) }
2163
2164
if ( ! window . loaded ) {
2164
2165
// auto change mode if no content detected
2165
2166
var nocontent = editor . getValue ( ) . length <= 0
@@ -2262,6 +2263,7 @@ socket.on('operation', function () {
2262
2263
} )
2263
2264
2264
2265
socket . on ( 'online users' , function ( data ) {
2266
+ console . log ( 'who faster? online users' )
2265
2267
if ( debug ) { console . debug ( data ) }
2266
2268
onlineUsers = data . users
2267
2269
updateOnlineStatus ( )
@@ -2281,14 +2283,6 @@ socket.on('online users', function (data) {
2281
2283
var user = data . users [ i ]
2282
2284
if ( user . id !== socket . id ) { buildCursor ( user ) } else { personalInfo = user }
2283
2285
}
2284
- if ( ui . toolbar . edit . data ( 'blockSource' ) ) {
2285
- setTimeout ( ( ) => {
2286
- allowVisibleSource ( userIsLogin ( personalInfo ) , currentPermission )
2287
- console . log ( 'per in timeout' , currentPermission )
2288
- } , 10000 )
2289
- //allowVisibleSource(userIsLogin(personalInfo), currentPermission)
2290
- //console.log('per', currentPermission)
2291
- }
2292
2286
} )
2293
2287
socket . on ( 'user status' , function ( data ) {
2294
2288
if ( debug ) { console . debug ( data ) }
0 commit comments