@@ -81,7 +81,6 @@ import uiElemsWithoutJquery from './lib/editor/ui-elems-without-jquery'
81
81
import { emojifyImageDir } from './lib/editor/constants'
82
82
import modeType from './lib/modeType'
83
83
import appState from './lib/appState'
84
- //import { isLogicalNot } from 'vega-lite/build/src/logical'
85
84
86
85
require ( '../vendor/showup/showup' )
87
86
@@ -259,6 +258,7 @@ const statusType = {
259
258
// global vars
260
259
window . loaded = false
261
260
let isLogin = false
261
+ let blockSourceView = false
262
262
let needRefresh = false
263
263
let isDirty = false
264
264
let editShown = false
@@ -293,6 +293,7 @@ const lastInfo = {
293
293
}
294
294
let personalInfo = { }
295
295
let onlineUsers = [ ]
296
+ let currentPermission = ''
296
297
const fileTypes = {
297
298
pl : 'perl' ,
298
299
cgi : 'perl' ,
@@ -428,9 +429,7 @@ Visibility.change(function (e, state) {
428
429
429
430
// when page ready
430
431
$ ( document ) . ready ( function ( ) {
431
- if ( ui . toolbar . edit . data ( 'blockSource' ) && isLogin === false ) { replaceUrl ( window . location . href ) }
432
-
433
- console . log ( "personal info" , onlineUsers )
432
+ if ( ui . toolbar . edit . data ( 'blockSource' ) && ! isLogin ) { replaceUrl ( window . location . href ) }
434
433
435
434
idle . checkAway ( )
436
435
checkResponsive ( )
@@ -480,14 +479,14 @@ $(document).ready(function () {
480
479
481
480
key . filter = function ( e ) { return true }
482
481
key ( 'ctrl+alt+e' , function ( e ) {
483
- if ( ui . toolbar . edit . data ( 'blockSource' ) && isLogin === false ) return
482
+ if ( blockSourceView ) return
484
483
changeMode ( modeType . edit )
485
484
} )
486
485
key ( 'ctrl+alt+v' , function ( e ) {
487
486
changeMode ( modeType . view )
488
487
} )
489
488
key ( 'ctrl+alt+b' , function ( e ) {
490
- if ( ui . toolbar . both . data ( 'blockSource' ) && isLogin === false ) return
489
+ if ( blockSourceView ) return
491
490
changeMode ( modeType . both )
492
491
} )
493
492
// toggle-dropdown
@@ -521,18 +520,79 @@ function replaceUrl (url) {
521
520
}
522
521
523
522
//
524
- function disableToolbarButtons ( isLogin , elems ) {
525
- if ( isLogin === false ) {
526
- elems . edit . setAttribute ( 'disabled' , null )
527
- elems . edit . setAttribute ( 'title' , 'You have no rights to edit this note' )
528
- elems . both . setAttribute ( 'disabled' , null )
529
- elems . both . setAttribute ( 'title' , 'You have no rights to edit this note' )
530
- } else {
531
- elems . edit . removeAttribute ( 'disabled' )
532
- elems . both . removeAttribute ( 'disabled' )
523
+ function allowVisibleSource ( isLogin , permission ) {
524
+ console . log ( 'isWokr?' , isLogin , permission )
525
+ switch ( permission ) {
526
+ case 'freely' :
527
+ blockSourceView = false
528
+ break
529
+ case 'editable' :
530
+ if ( ! isLogin ) {
531
+ 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' )
536
+ } else {
537
+ 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)' )
542
+ }
543
+ break
544
+ case 'limited' :
545
+ if ( ! isLogin ) {
546
+ 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' )
551
+ } else {
552
+ 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)' )
557
+ }
558
+ break
559
+ case 'locked' :
560
+ if ( personalInfo . userid && window . owner && personalInfo . userid === window . owner ) {
561
+ blockSourceView = false
562
+ } else {
563
+ 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' )
568
+ }
569
+ break
570
+ case 'protected' :
571
+ if ( personalInfo . userid && window . owner && personalInfo . userid === window . owner ) {
572
+ blockSourceView = false
573
+ } else {
574
+ 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' )
579
+ }
580
+ break
581
+ case 'private' :
582
+ if ( personalInfo . userid && window . owner && personalInfo . userid === window . owner ) {
583
+ blockSourceView = false
584
+ } else {
585
+ 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' )
590
+ }
591
+ break
533
592
}
534
593
}
535
594
595
+ //checking is user log in
536
596
function userIsLogin ( userPersonalInfo ) {
537
597
if ( userPersonalInfo . hasOwnProperty ( 'login' ) ) {
538
598
if ( userPersonalInfo . login === true ) {
@@ -1612,15 +1672,14 @@ function importFromUrl (url) {
1612
1672
ui . toolbar . mode . click ( function ( ) {
1613
1673
if ( personalInfo . userid && window . owner && personalInfo . userid === window . owner ) {
1614
1674
toggleMode ( )
1615
- } else if ( ui . toolbar . mode . data ( 'blockSource' ) ) return
1675
+ } else if ( blockSourceView ) return
1616
1676
toggleMode ( )
1617
1677
} )
1618
1678
// edit
1619
1679
ui . toolbar . edit . click ( function ( ) {
1620
1680
if ( personalInfo . userid && window . owner && personalInfo . userid === window . owner ) {
1621
- console . dir ( personalInfo )
1622
1681
changeMode ( modeType . edit )
1623
- } else if ( ui . toolbar . edit . data ( 'blockSource' ) ) return
1682
+ } else if ( blockSourceView ) return
1624
1683
changeMode ( modeType . edit )
1625
1684
} )
1626
1685
// view
@@ -1631,7 +1690,7 @@ ui.toolbar.view.click(function () {
1631
1690
ui . toolbar . both . click ( function ( ) {
1632
1691
if ( personalInfo . userid && window . owner && personalInfo . userid === window . owner ) {
1633
1692
changeMode ( modeType . edit )
1634
- } else if ( ui . toolbar . both . data ( 'blockSource' ) ) return
1693
+ } else if ( blockSourceView ) return
1635
1694
changeMode ( modeType . both )
1636
1695
} )
1637
1696
@@ -2100,6 +2159,7 @@ socket.on('refresh', function (data) {
2100
2159
editor . setOption ( 'maxLength' , editorInstance . config . docmaxlength )
2101
2160
updateInfo ( data )
2102
2161
updatePermission ( data . permission )
2162
+ currentPermission = data . permission
2103
2163
if ( ! window . loaded ) {
2104
2164
// auto change mode if no content detected
2105
2165
var nocontent = editor . getValue ( ) . length <= 0
@@ -2222,7 +2282,12 @@ socket.on('online users', function (data) {
2222
2282
if ( user . id !== socket . id ) { buildCursor ( user ) } else { personalInfo = user }
2223
2283
}
2224
2284
if ( ui . toolbar . edit . data ( 'blockSource' ) ) {
2225
- disableToolbarButtons ( userIsLogin ( personalInfo ) , uiByNativeJS )
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)
2226
2291
}
2227
2292
} )
2228
2293
socket . on ( 'user status' , function ( data ) {
@@ -2273,12 +2338,6 @@ socket.on('cursor blur', function (data) {
2273
2338
}
2274
2339
} )
2275
2340
2276
- //checked user is login
2277
- async function userPersonalInfo ( personalInfo ) {
2278
- let userInfo = await personalInfo
2279
- return userInfo
2280
- }
2281
-
2282
2341
var options = {
2283
2342
valueNames : [ 'id' , 'name' ] ,
2284
2343
item : '<li class="ui-user-item">' +
0 commit comments