Fixed permission might not update and emit properly

This commit is contained in:
Wu Cheng-Han 2015-09-25 14:02:34 +08:00
parent ab6deb8e2e
commit e64249453f
1 changed files with 35 additions and 9 deletions

View File

@ -891,24 +891,28 @@ ui.toolbar.both.click(function () {
//permission //permission
//freely //freely
ui.infobar.permission.freely.click(function () { ui.infobar.permission.freely.click(function () {
updatePermission("freely"); emitPermission("freely");
}); });
//editable //editable
ui.infobar.permission.editable.click(function () { ui.infobar.permission.editable.click(function () {
updatePermission("editable"); emitPermission("editable");
}); });
//locked //locked
ui.infobar.permission.locked.click(function () { ui.infobar.permission.locked.click(function () {
updatePermission("locked"); emitPermission("locked");
}); });
function updatePermission(_permission) { function emitPermission(_permission) {
if (_permission != permission) { if (_permission != permission) {
socket.emit('permission', _permission); socket.emit('permission', _permission);
} }
} }
function checkPermission() { function updatePermission(newPermission) {
if (permission != newPermission) {
permission = newPermission;
refreshView();
}
var label = null; var label = null;
var title = null; var title = null;
switch (permission) { switch (permission) {
@ -934,6 +938,30 @@ function checkPermission() {
ui.infobar.permission.label.html(label).attr('title', title); 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 //socket.io actions
var socket = io.connect(); var socket = io.connect();
//overwrite original event for checking login state //overwrite original event for checking login state
@ -981,8 +1009,7 @@ socket.on('check', function (data) {
updateLastChange(); updateLastChange();
}); });
socket.on('permission', function (data) { socket.on('permission', function (data) {
permission = data.permission; updatePermission(data.permission);
checkPermission();
}); });
var docmaxlength = null; var docmaxlength = null;
var otk = null; var otk = null;
@ -993,11 +1020,10 @@ socket.on('refresh', function (data) {
editor.setOption("maxLength", docmaxlength); editor.setOption("maxLength", docmaxlength);
otk = data.otk; otk = data.otk;
owner = data.owner; owner = data.owner;
permission = data.permission; updatePermission(data.permission);
lastchangetime = data.updatetime; lastchangetime = data.updatetime;
lastchangeui = ui.infobar.lastchange; lastchangeui = ui.infobar.lastchange;
updateLastChange(); updateLastChange();
checkPermission();
if (!loaded) { if (!loaded) {
changeMode(currentMode); changeMode(currentMode);
loaded = true; loaded = true;