Improved update last info methods, only change DOM when necessary

This commit is contained in:
Cheng-Han, Wu 2016-03-15 10:45:02 +08:00
parent 30d194bba4
commit 526f5c7e2e
3 changed files with 31 additions and 17 deletions

View file

@ -14,16 +14,20 @@ function updateLastChange() {
} }
setInterval(updateLastChange, 60000); setInterval(updateLastChange, 60000);
function updateLastChangeUser(data) { var lastchangeuser = null;
if (data.lastchangeuserprofile) { var lastchangeuserprofile = null;
var icon = lastchangeui.user.children('i'); function updateLastChangeUser() {
icon.attr('title', data.lastchangeuserprofile.name).tooltip('fixTitle'); if (lastchangeui) {
icon.attr('style', 'background-image:url(' + data.lastchangeuserprofile.photo + ')'); if (lastchangeuser && lastchangeuserprofile) {
lastchangeui.user.show(); var icon = lastchangeui.user.children('i');
lastchangeui.nouser.hide(); icon.attr('title', lastchangeuserprofile.name).tooltip('fixTitle');
} else { icon.attr('style', 'background-image:url(' + lastchangeuserprofile.photo + ')');
lastchangeui.user.hide(); lastchangeui.user.show();
lastchangeui.nouser.show(); lastchangeui.nouser.hide();
} else {
lastchangeui.user.hide();
lastchangeui.nouser.show();
}
} }
} }

View file

@ -1481,10 +1481,21 @@ socket.on('version', function (data) {
if (data != version) if (data != version)
setNeedRefresh(); setNeedRefresh();
}); });
function updateLastInfo(data) {
//console.log(data);
if (lastchangetime !== data.updatetime) {
lastchangetime = data.updatetime;
updateLastChange();
}
if (lastchangeuser !== data.lastchangeuser) {
lastchangeuser = data.lastchangeuser;
lastchangeuserprofile = data.lastchangeuserprofile;
updateLastChangeUser();
}
}
socket.on('check', function (data) { socket.on('check', function (data) {
lastchangetime = data.updatetime; //console.log(data);
updateLastChange(); updateLastInfo(data);
updateLastChangeUser(data);
}); });
socket.on('permission', function (data) { socket.on('permission', function (data) {
updatePermission(data.permission); updatePermission(data.permission);
@ -1494,14 +1505,13 @@ var otk = null;
var owner = null; var owner = null;
var permission = null; var permission = null;
socket.on('refresh', function (data) { socket.on('refresh', function (data) {
//console.log(data);
docmaxlength = data.docmaxlength; docmaxlength = data.docmaxlength;
editor.setOption("maxLength", docmaxlength); editor.setOption("maxLength", docmaxlength);
otk = data.otk; otk = data.otk;
owner = data.owner; owner = data.owner;
updatePermission(data.permission); updatePermission(data.permission);
lastchangetime = data.updatetime; updateLastInfo(data);
updateLastChange();
updateLastChangeUser(data);
if (!loaded) { if (!loaded) {
var nocontent = editor.getValue().length <= 0; var nocontent = editor.getValue().length <= 0;
if (nocontent) { if (nocontent) {

View file

@ -6,7 +6,7 @@
<div class="ui-infobar container-fluid unselectable hidden-print"> <div class="ui-infobar container-fluid unselectable hidden-print">
<small> <small>
<span> <span>
<span class="ui-lastchangeuser">&thinsp;<i class="ui-user-icon small" data-toggle="tooltip" data-placement="right"></i></span> <span class="ui-lastchangeuser" style="display: none;">&thinsp;<i class="ui-user-icon small" data-toggle="tooltip" data-placement="right"></i></span>
<span class="ui-no-lastchangeuser">&thinsp;<i class="fa fa-clock-o"></i></span> <span class="ui-no-lastchangeuser">&thinsp;<i class="fa fa-clock-o"></i></span>
&nbsp;<span class="text-uppercase">changed</span> &nbsp;<span class="text-uppercase">changed</span>
<span class="ui-lastchange text-uppercase"></span> <span class="ui-lastchange text-uppercase"></span>