diff options
author | Wu Cheng-Han | 2015-09-25 14:02:34 +0800 |
---|---|---|
committer | Wu Cheng-Han | 2015-09-25 14:02:34 +0800 |
commit | e64249453f98c65b632b504e9c71a1c616e875b9 (patch) | |
tree | ff23c7c66162869c1e4b1948c4b0481dd6555092 | |
parent | ab6deb8e2ec7d99001ec22e8491a373495667852 (diff) |
Fixed permission might not update and emit properly
Diffstat (limited to '')
-rw-r--r-- | public/js/index.js | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/public/js/index.js b/public/js/index.js index d470776f..07082401 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -891,24 +891,28 @@ ui.toolbar.both.click(function () { //permission //freely ui.infobar.permission.freely.click(function () { - updatePermission("freely"); + emitPermission("freely"); }); //editable ui.infobar.permission.editable.click(function () { - updatePermission("editable"); + emitPermission("editable"); }); //locked ui.infobar.permission.locked.click(function () { - updatePermission("locked"); + emitPermission("locked"); }); -function updatePermission(_permission) { +function emitPermission(_permission) { if (_permission != permission) { socket.emit('permission', _permission); } } -function checkPermission() { +function updatePermission(newPermission) { + if (permission != newPermission) { + permission = newPermission; + refreshView(); + } var label = null; var title = null; switch (permission) { @@ -934,6 +938,30 @@ function checkPermission() { ui.infobar.permission.label.html(label).attr('title', title); } +function havePermission() { + var bool = false; + switch (permission) { + case "freely": + bool = true; + break; + case "editable": + if (!personalInfo.login) { + bool = false; + } else { + bool = true; + } + break; + case "locked": + if (personalInfo.userid != owner) { + bool = false; + } else { + bool = true; + } + break; + } + return bool; +} + //socket.io actions var socket = io.connect(); //overwrite original event for checking login state @@ -981,8 +1009,7 @@ socket.on('check', function (data) { updateLastChange(); }); socket.on('permission', function (data) { - permission = data.permission; - checkPermission(); + updatePermission(data.permission); }); var docmaxlength = null; var otk = null; @@ -993,11 +1020,10 @@ socket.on('refresh', function (data) { editor.setOption("maxLength", docmaxlength); otk = data.otk; owner = data.owner; - permission = data.permission; + updatePermission(data.permission); lastchangetime = data.updatetime; lastchangeui = ui.infobar.lastchange; updateLastChange(); - checkPermission(); if (!loaded) { changeMode(currentMode); loaded = true; |