Commit e44ccb4a authored by Ilya.Kirillov's avatar Ilya.Kirillov Committed by Alexander.Trofimov

Доработана новая схема с цветами пользователей: в пару к обычному цвету...

Доработана новая схема с цветами пользователей: в пару к обычному цвету добавлен темный цвет, исправлен баг с запросом цвета по UserName, сделано чтобы можно было получить как числовое значение так и сразу объект CColor.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@66668 954022d7-b5bf-4e40-9824-e11837661b57
parent 8009b0b4
"use strict"; /* docscoapicommon.js * * Author: Alexander.Trofimov * Date: 09.11.12 */( /** * @param {Window} window * @param {undefined} undefined */ function (window, undefined) { /* * Import * ----------------------------------------------------------------------------- */ var asc = window["Asc"] ? window["Asc"] : (window["Asc"] = {}); var prot; /** * Класс user для совместного редактирования/просмотра документа * ----------------------------------------------------------------------------- * * @constructor * @memberOf Asc */ function asc_CUser (val) { this.id = null; // уникальный id - пользователя this.userName = null; // имя пользователя this.state = undefined; // состояние (true - подключен, false - отключился) this.indexUser = -1; // Индекс пользователя (фактически равно числу заходов в документ на сервере) this.color = null; // цвет пользователя this.view = false; // просмотр(true), редактор(false) this._setUser(val); return this; } asc_CUser.prototype._setUser = function (val) { if (val) { this.id = val['id']; this.userName = val['username']; this.indexUser = val['indexUser']; this.color = getUserColorById(this.id, this.userName); this.state = val['state']; this.view = val['view']; } }; asc_CUser.prototype.asc_getId = function () { return this.id; }; asc_CUser.prototype.asc_getUserName = function () { return this.userName; }; asc_CUser.prototype.asc_getState = function () { return this.state; }; asc_CUser.prototype.asc_getColor = function () { return '#' + ('000000' + this.color.toString(16)).substr(-6); }; asc_CUser.prototype.asc_getColorValue = function () { return this.color; }; asc_CUser.prototype.asc_getView = function () { return this.view; }; asc_CUser.prototype.asc_setId = function (val) { this.id = val; }; asc_CUser.prototype.asc_setUserName = function (val) { this.userName = val; }; asc_CUser.prototype.asc_setState = function (val) { this.state = val; }; asc_CUser.prototype.asc_setColor = function (val) { this.color = val; }; /* * Export * ----------------------------------------------------------------------------- */ window["Asc"]["asc_CUser"] = window["Asc"].asc_CUser = asc_CUser; prot = asc_CUser.prototype; prot["asc_getId"] = prot.asc_getId; prot["asc_getUserName"] = prot.asc_getUserName; prot["asc_getState"] = prot.asc_getState; prot["asc_setId"] = prot.asc_setId; prot["asc_getColor"] = prot.asc_getColor; prot["asc_getColorValue"] = prot.asc_getColorValue; prot["asc_getView"] = prot.asc_getView; prot["asc_setUserName"] = prot.asc_setUserName; prot["asc_setState"] = prot.asc_setState; prot["asc_setColor"] = prot.asc_setColor; } )(window); var ConnectionState = { Reconnect: -1, // reconnect state None: 0, // not initialized WaitAuth: 1, // waiting session id Authorized: 2, // authorized ClosedCoAuth: 3, // closed coauthoring ClosedAll: 4, // closed all SaveChanges: 10 // save };
\ No newline at end of file
"use strict"; /* docscoapicommon.js * * Author: Alexander.Trofimov * Date: 09.11.12 */( /** * @param {Window} window * @param {undefined} undefined */ function (window, undefined) { /* * Import * ----------------------------------------------------------------------------- */ var asc = window["Asc"] ? window["Asc"] : (window["Asc"] = {}); var prot; /** * Класс user для совместного редактирования/просмотра документа * ----------------------------------------------------------------------------- * * @constructor * @memberOf Asc */ function asc_CUser (val) { this.id = null; // уникальный id - пользователя this.userName = null; // имя пользователя this.state = undefined; // состояние (true - подключен, false - отключился) this.indexUser = -1; // Индекс пользователя (фактически равно числу заходов в документ на сервере) this.color = null; // цвет пользователя this.view = false; // просмотр(true), редактор(false) this._setUser(val); return this; } asc_CUser.prototype._setUser = function (val) { if (val) { this.id = val['id']; this.userName = val['username']; this.indexUser = val['indexUser']; this.color = getUserColorById(this.id, this.userName, false, true); this.state = val['state']; this.view = val['view']; } }; asc_CUser.prototype.asc_getId = function () { return this.id; }; asc_CUser.prototype.asc_getUserName = function () { return this.userName; }; asc_CUser.prototype.asc_getState = function () { return this.state; }; asc_CUser.prototype.asc_getColor = function () { return '#' + ('000000' + this.color.toString(16)).substr(-6); }; asc_CUser.prototype.asc_getColorValue = function () { return this.color; }; asc_CUser.prototype.asc_getView = function () { return this.view; }; asc_CUser.prototype.asc_setId = function (val) { this.id = val; }; asc_CUser.prototype.asc_setUserName = function (val) { this.userName = val; }; asc_CUser.prototype.asc_setState = function (val) { this.state = val; }; asc_CUser.prototype.asc_setColor = function (val) { this.color = val; }; /* * Export * ----------------------------------------------------------------------------- */ window["Asc"]["asc_CUser"] = window["Asc"].asc_CUser = asc_CUser; prot = asc_CUser.prototype; prot["asc_getId"] = prot.asc_getId; prot["asc_getUserName"] = prot.asc_getUserName; prot["asc_getState"] = prot.asc_getState; prot["asc_setId"] = prot.asc_setId; prot["asc_getColor"] = prot.asc_getColor; prot["asc_getColorValue"] = prot.asc_getColorValue; prot["asc_getView"] = prot.asc_getView; prot["asc_setUserName"] = prot.asc_setUserName; prot["asc_setState"] = prot.asc_setState; prot["asc_setColor"] = prot.asc_setColor; } )(window); var ConnectionState = { Reconnect: -1, // reconnect state None: 0, // not initialized WaitAuth: 1, // waiting session id Authorized: 2, // authorized ClosedCoAuth: 3, // closed coauthoring ClosedAll: 4, // closed all SaveChanges: 10 // save };
\ No newline at end of file
......
......@@ -2156,17 +2156,57 @@ CContentChangesElement.prototype.Make_ArrayOfSimpleActions = function(Type, Pos,
return Positions;
};
var g_oUserColorById = {}, g_oUserNextColorIndex = 0;
function getUserColorById(userId, userName) {
var res;
if (g_oUserColorById.hasOwnProperty(userId)) {
res = g_oUserColorById[userId];
} else if (g_oUserColorById.hasOwnProperty(userName)) {
res = g_oUserColorById[userName];
} else {
res = g_oUserColorById[userId] = c_oAscArrUserColors[g_oUserNextColorIndex % c_oAscArrUserColors.length];
++g_oUserNextColorIndex;
}
return res;
function getUserColorById(userId, userName, isDark, isNumericValue)
{
var res;
if (g_oUserColorById.hasOwnProperty(userId))
{
res = g_oUserColorById[userId];
}
else if (g_oUserColorById.hasOwnProperty(userName))
{
res = g_oUserColorById[userName];
}
else
{
var nColor = c_oAscArrUserColors[g_oUserNextColorIndex % c_oAscArrUserColors.length];
++g_oUserNextColorIndex;
if (userId)
{
res = g_oUserColorById[userId] = new CUserCacheColor(nColor);
}
else
{
res = g_oUserColorById[userName] = new CUserCacheColor(nColor);
}
}
if (!res)
return new CColor(0, 0, 0, 255);
var oColor = true === isDark ? res.Dark : res.Light;
return true === isNumericValue ? ((oColor.r << 16) & 0xFF0000) | ((oColor.g << 8) & 0xFF00) | (oColor.b & 0xFF) : oColor;
}
function CUserCacheColor(nColor)
{
var r = (nColor >> 16) & 0xFF;
var g = (nColor >> 8) & 0xFF;
var b = nColor & 0xFF;
var Y = Math.max(0, Math.min(255, 0.299 * r + 0.587 * g + 0.114 * b));
var Cb = Math.max(0, Math.min(255, 128 - 0.168736 * r - 0.331264 * g + 0.5 * b));
var Cr = Math.max(0, Math.min(255, 128 + 0.5 * r - 0.418688 * g - 0.081312 * b));
if (Y > 63)
Y = 63;
var R = Math.max(0, Math.min(255, Y + 1.402 * (Cr - 128))) | 0;
var G = Math.max(0, Math.min(255, Y - 0.34414 * (Cb - 128) - 0.71414 * (Cr - 128))) | 0;
var B = Math.max(0, Math.min(255, Y + 1.772 * (Cb - 128) )) | 0;
this.Light = new CColor(r, g, b, 255);
this.Dark = new CColor(R, G, B, 255);
}
var g_oIdCounter = new CIdCounter();
......
......@@ -978,10 +978,7 @@ function CDrawingCollaborativeTarget()
this.Size = 0;
this.Page = -1;
this.Color = null;
this.Color = null;
this.Transform = null;
this.HtmlElement = null;
......@@ -1004,23 +1001,8 @@ CDrawingCollaborativeTarget.prototype =
this.HtmlElement.width = 1;
this.HtmlElement.height = 1;
var nColor = getUserColorById(this.Id);
var oColor = new CDocumentColor( (nColor >> 16) & 0xFF, (nColor >> 8) & 0xFF, nColor & 0xFF );
var Y = Math.max(0, Math.min(255, 0.299 * oColor.r + 0.587 * oColor.g + 0.114 * oColor.b));
var Cb = Math.max(0, Math.min(255, 128 - 0.168736 * oColor.r - 0.331264 * oColor.g + 0.5 * oColor.b));
var Cr = Math.max(0, Math.min(255, 128 + 0.5 * oColor.r - 0.418688 * oColor.g - 0.081312 * oColor.b));
if (Y > 63)
Y = 63;
var R = Math.max(0, Math.min(255, Y + 1.402 * (Cr - 128))) | 0;
var G = Math.max(0, Math.min(255, Y - 0.34414 * (Cb - 128) - 0.71414 * (Cr - 128))) | 0;
var B = Math.max(0, Math.min(255, Y + 1.772 * (Cb - 128) )) | 0;
this.Color = new CDocumentColor(R, G, B);
this.Style ="rgb(" + R + "," + G + "," + B + ")";
this.Color = getUserColorById(this.Id, null, true);
this.Style ="rgb(" + this.Color.r + "," + this.Color.g + "," + this.Color.b + ")";
}
// 2) определяем размер
......@@ -3496,18 +3478,6 @@ function CDrawingDocument()
}
}
};
this.Collaborative_GetTargetColor = function(UserId)
{
for (var i = 0; i < this.CollaborativeTargets.length; i++)
{
if (UserId == this.CollaborativeTargets[i].Id)
return this.CollaborativeTargets[i].Color;
}
return null;
};
this.Collaborative_GetTargetPosition = function(UserId)
{
for (var i = 0; i < this.CollaborativeTargets.length; i++)
......
......@@ -568,7 +568,7 @@ CCollaborativeEditing.prototype.Show_ForeignCursorLabel = function(UserId)
Api.sync_HideForeignCursorLabel(UserId);
}, FOREIGN_CURSOR_LABEL_HIDETIME);
var Color = DrawingDocument.Collaborative_GetTargetColor(UserId);
var Color = getUserColorById(UserId, null, true);
var Coords = DrawingDocument.Collaborative_GetTargetPosition(UserId);
if (!Color || !Coords)
return;
......
......@@ -2061,6 +2061,7 @@ function CDrawingCollaborativeTarget()
this.Size = 0;
this.Page = -1;
this.Color = null;
this.Transform = null;
this.HtmlElement = null;
......@@ -2085,23 +2086,8 @@ CDrawingCollaborativeTarget.prototype =
this.HtmlElement.width = 1;
this.HtmlElement.height = 1;
var nColor = getUserColorById(this.Id);
var oColor = new CDocumentColor( (nColor >> 16) & 0xFF, (nColor >> 8) & 0xFF, nColor & 0xFF );
var Y = Math.max(0, Math.min(255, 0.299 * oColor.r + 0.587 * oColor.g + 0.114 * oColor.b));
var Cb = Math.max(0, Math.min(255, 128 - 0.168736 * oColor.r - 0.331264 * oColor.g + 0.5 * oColor.b));
var Cr = Math.max(0, Math.min(255, 128 + 0.5 * oColor.r - 0.418688 * oColor.g - 0.081312 * oColor.b));
if (Y > 63)
Y = 63;
var R = Math.max(0, Math.min(255, Y + 1.402 * (Cr - 128))) | 0;
var G = Math.max(0, Math.min(255, Y - 0.34414 * (Cb - 128) - 0.71414 * (Cr - 128))) | 0;
var B = Math.max(0, Math.min(255, Y + 1.772 * (Cb - 128) )) | 0;
this.Color = new CDocumentColor(R, G, B);
this.Style ="rgb(" + R + "," + G + "," + B + ")";
this.Color = getUserColorById(this.Id, null, true);
this.Style ="rgb(" + this.Color.r + "," + this.Color.g + "," + this.Color.b + ")";
}
// 2) определяем размер
......@@ -6951,18 +6937,6 @@ function CDrawingDocument()
}
}
};
this.Collaborative_GetTargetColor = function(UserId)
{
for (var i = 0; i < this.CollaborativeTargets.length; i++)
{
if (UserId == this.CollaborativeTargets[i].Id)
return this.CollaborativeTargets[i].Color;
}
return null;
};
this.Collaborative_GetTargetPosition = function(UserId)
{
for (var i = 0; i < this.CollaborativeTargets.length; i++)
......
......@@ -447,7 +447,7 @@ CWordCollaborativeEditing.prototype.Show_ForeignCursorLabel = function(UserId)
Api.sync_HideForeignCursorLabel(UserId);
}, FOREIGN_CURSOR_LABEL_HIDETIME);
var Color = DrawingDocument.Collaborative_GetTargetColor(UserId);
var Color = getUserColorById(UserId, null, true);
var Coords = DrawingDocument.Collaborative_GetTargetPosition(UserId);
if (!Color || !Coords)
return;
......
......@@ -968,9 +968,8 @@ asc_docs_api.prototype._coAuthoringInitEnd = function() {
bUseColor = false;
}
var nColor = getUserColorById(userId);
var oColor = false === bUseColor ? null : new CDocumentColor((nColor >> 16) & 0xFF, (nColor >> 8) & 0xFF, nColor & 0xFF);
var oCommonColor = getUserColorById(userId, null, false, false);
var oColor = false === bUseColor ? null : new CDocumentColor(oCommonColor.r, oCommonColor.g, oCommonColor.b);
t._coAuthoringSetChange(e, oColor);
// т.е. если bSendEvent не задан, то посылаем сообщение + когда загрузился документ
if (!bFirstLoad && t.bInit_word_control) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment