Commit f3c97069 authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

Правка с пользователями (теперь они у нас в классе хранятся), также мы генерируем для них цвета.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@55586 954022d7-b5bf-4e40-9824-e11837661b57
parent f41d0b69
...@@ -801,6 +801,12 @@ ...@@ -801,6 +801,12 @@
prot["asc_getY"] = prot.asc_getY; prot["asc_getY"] = prot.asc_getY;
prot["asc_getWidth"] = prot.asc_getWidth; prot["asc_getWidth"] = prot.asc_getWidth;
prot["asc_getHeight"] = prot.asc_getHeight; prot["asc_getHeight"] = prot.asc_getHeight;
function generateColor() {
return '#' + ('000000' + Math.floor(Math.random()*0xFFFFFF).toString(16)).substr(-6);
}
window["Asc"].generateColor = generateColor;
} }
)(window); )(window);
......
...@@ -11,8 +11,7 @@ ...@@ -11,8 +11,7 @@
this._CoAuthoringApi = new DocsCoApi(); this._CoAuthoringApi = new DocsCoApi();
this._onlineWork = false; this._onlineWork = false;
if (options) if (options) {
{
this.onAuthParticipantsChanged = options.onAuthParticipantsChanged; this.onAuthParticipantsChanged = options.onAuthParticipantsChanged;
this.onParticipantsChanged = options.onParticipantsChanged; this.onParticipantsChanged = options.onParticipantsChanged;
this.onMessage = options.onMessage; this.onMessage = options.onMessage;
...@@ -31,8 +30,8 @@ ...@@ -31,8 +30,8 @@
CDocsCoApi.prototype.init = function (user, docid, token, serverHost, serverPath, callback, editorType, documentFormatSave) { CDocsCoApi.prototype.init = function (user, docid, token, serverHost, serverPath, callback, editorType, documentFormatSave) {
if (this._CoAuthoringApi && this._CoAuthoringApi.isRightURL()) { if (this._CoAuthoringApi && this._CoAuthoringApi.isRightURL()) {
var t = this; var t = this;
this._CoAuthoringApi.onAuthParticipantsChanged = function (e) {t.callback_OnAuthParticipantsChanged(e);}; this._CoAuthoringApi.onAuthParticipantsChanged = function (e, count) {t.callback_OnAuthParticipantsChanged(e, count);};
this._CoAuthoringApi.onParticipantsChanged = function (e, Count) {t.callback_OnParticipantsChanged(e, Count);}; this._CoAuthoringApi.onParticipantsChanged = function (e, count) {t.callback_OnParticipantsChanged(e, count);};
this._CoAuthoringApi.onMessage = function (e) {t.callback_OnMessage(e);}; this._CoAuthoringApi.onMessage = function (e) {t.callback_OnMessage(e);};
this._CoAuthoringApi.onLocksAcquired = function (e) {t.callback_OnLocksAcquired(e);}; this._CoAuthoringApi.onLocksAcquired = function (e) {t.callback_OnLocksAcquired(e);};
this._CoAuthoringApi.onLocksReleased = function (e, bChanges) {t.callback_OnLocksReleased(e, bChanges);}; this._CoAuthoringApi.onLocksReleased = function (e, bChanges) {t.callback_OnLocksReleased(e, bChanges);};
...@@ -145,34 +144,34 @@ ...@@ -145,34 +144,34 @@
} }
}; };
CDocsCoApi.prototype.callback_OnAuthParticipantsChanged = function (e) { CDocsCoApi.prototype.callback_OnAuthParticipantsChanged = function (e, count) {
if (this.onAuthParticipantsChanged) if (this.onAuthParticipantsChanged)
return this.onAuthParticipantsChanged(e); this.onAuthParticipantsChanged(e, count);
}; };
CDocsCoApi.prototype.callback_OnParticipantsChanged = function (e, Count) { CDocsCoApi.prototype.callback_OnParticipantsChanged = function (e, count) {
if (this.onParticipantsChanged) if (this.onParticipantsChanged)
return this.onParticipantsChanged (e, Count); this.onParticipantsChanged (e, count);
}; };
CDocsCoApi.prototype.callback_OnMessage = function (e) { CDocsCoApi.prototype.callback_OnMessage = function (e) {
if (this.onMessage) if (this.onMessage)
return this.onMessage (e); this.onMessage (e);
}; };
CDocsCoApi.prototype.callback_OnLocksAcquired = function (e) { CDocsCoApi.prototype.callback_OnLocksAcquired = function (e) {
if (this.onLocksAcquired) if (this.onLocksAcquired)
return this.onLocksAcquired (e); this.onLocksAcquired (e);
}; };
CDocsCoApi.prototype.callback_OnLocksReleased = function (e, bChanges) { CDocsCoApi.prototype.callback_OnLocksReleased = function (e, bChanges) {
if (this.onLocksReleased) if (this.onLocksReleased)
return this.onLocksReleased (e, bChanges); this.onLocksReleased (e, bChanges);
}; };
CDocsCoApi.prototype.callback_OnLocksReleasedEnd = function () { CDocsCoApi.prototype.callback_OnLocksReleasedEnd = function () {
if (this.onLocksReleasedEnd) if (this.onLocksReleasedEnd)
return this.onLocksReleasedEnd (); this.onLocksReleasedEnd ();
}; };
/** /**
...@@ -183,31 +182,31 @@ ...@@ -183,31 +182,31 @@
*/ */
CDocsCoApi.prototype.callback_OnDisconnect = function (e, isDisconnectAtAll, isCloseCoAuthoring) { CDocsCoApi.prototype.callback_OnDisconnect = function (e, isDisconnectAtAll, isCloseCoAuthoring) {
if (this.onDisconnect) if (this.onDisconnect)
return this.onDisconnect (e, isDisconnectAtAll, isCloseCoAuthoring); this.onDisconnect (e, isDisconnectAtAll, isCloseCoAuthoring);
}; };
CDocsCoApi.prototype.callback_OnFirstLoadChanges = function (e) { CDocsCoApi.prototype.callback_OnFirstLoadChanges = function (e) {
if (this.onFirstLoadChanges) if (this.onFirstLoadChanges)
return this.onFirstLoadChanges (e); this.onFirstLoadChanges (e);
}; };
CDocsCoApi.prototype.callback_OnConnectionStateChanged = function (e) { CDocsCoApi.prototype.callback_OnConnectionStateChanged = function (e) {
if (this.onConnectionStateChanged) if (this.onConnectionStateChanged)
return this.onConnectionStateChanged (e); this.onConnectionStateChanged (e);
}; };
CDocsCoApi.prototype.callback_OnSetIndexUser = function (e) { CDocsCoApi.prototype.callback_OnSetIndexUser = function (e) {
if (this.onSetIndexUser) if (this.onSetIndexUser)
return this.onSetIndexUser (e); this.onSetIndexUser (e);
}; };
CDocsCoApi.prototype.callback_OnSaveChanges = function (e) { CDocsCoApi.prototype.callback_OnSaveChanges = function (e) {
if (this.onSaveChanges) if (this.onSaveChanges)
return this.onSaveChanges (e); this.onSaveChanges (e);
}; };
CDocsCoApi.prototype.callback_OnStartCoAuthoring = function (e) { CDocsCoApi.prototype.callback_OnStartCoAuthoring = function (e) {
if (this.onStartCoAuthoring) if (this.onStartCoAuthoring)
return this.onStartCoAuthoring (e); this.onStartCoAuthoring (e);
}; };
/** States /** States
...@@ -218,8 +217,7 @@ ...@@ -218,8 +217,7 @@
* 3 - closed * 3 - closed
*/ */
var DocsCoApi = function (options) { var DocsCoApi = function (options) {
if (options) if (options) {
{
this.onAuthParticipantsChanged = options.onAuthParticipantsChanged; this.onAuthParticipantsChanged = options.onAuthParticipantsChanged;
this.onParticipantsChanged = options.onParticipantsChanged; this.onParticipantsChanged = options.onParticipantsChanged;
this.onMessage = options.onMessage; this.onMessage = options.onMessage;
...@@ -233,7 +231,10 @@ ...@@ -233,7 +231,10 @@
this.onConnectionStateChanged = options.onConnectionStateChanged; this.onConnectionStateChanged = options.onConnectionStateChanged;
} }
this._state = 0; this._state = 0;
this._participants = []; // Online-пользователи в документе
this._participants = {};
this._countEditUsers = 0;
this._user = "Anonymous"; this._user = "Anonymous";
this._locks = {}; this._locks = {};
this._msgBuffer = []; this._msgBuffer = [];
...@@ -277,10 +278,6 @@ ...@@ -277,10 +278,6 @@
DocsCoApi.prototype.getSessionId = function () { DocsCoApi.prototype.getSessionId = function () {
return this._id; return this._id;
}; };
// ToDo убрать getParticipants
DocsCoApi.prototype.getParticipants = function () {
return this._participants;
};
DocsCoApi.prototype.getUser = function () { DocsCoApi.prototype.getUser = function () {
return this._user; return this._user;
...@@ -412,7 +409,9 @@ ...@@ -412,7 +409,9 @@
}; };
DocsCoApi.prototype.getUsers = function () { DocsCoApi.prototype.getUsers = function () {
this._send({"type": "getusers"}); // Специально для возможности получения после прохождения авторизации (Стоит переделать)
if (this.onAuthParticipantsChanged)
this.onAuthParticipantsChanged(this._participants, this._countEditUsers);
}; };
DocsCoApi.prototype.disconnect = function () { DocsCoApi.prototype.disconnect = function () {
...@@ -635,29 +634,25 @@ ...@@ -635,29 +634,25 @@
} }
}; };
DocsCoApi.prototype._onParticipantsChanged = function (participants, isStartEvent) { DocsCoApi.prototype._onAuthParticipantsChanged = function (participants) {
this._participants = []; this._participants = {};
this._countEditUsers = 0;
if (participants) { if (participants) {
var tmpUser, countEditUsers = 0; var tmpUser;
for (var i = 0; i < participants.length; ++i) { for (var i = 0; i < participants.length; ++i) {
tmpUser = new asc_user(participants[i]); tmpUser = new asc_user(participants[i]);
this._participants.push(tmpUser); this._participants[tmpUser.asc_getId()] = tmpUser;
// Считаем число всех пользователей (и тех кто просматривает тоже) // Считаем число всех пользователей (и тех кто просматривает тоже)
++countEditUsers; ++this._countEditUsers;
} }
if (isStartEvent) {
if (this.onAuthParticipantsChanged) if (this.onAuthParticipantsChanged)
this.onAuthParticipantsChanged (this._participants); this.onAuthParticipantsChanged(this._participants, this._countEditUsers);
} else {
if (this.onParticipantsChanged)
this.onParticipantsChanged (this._participants, countEditUsers);
}
// Посылаем эвент о совместном редактировании // Посылаем эвент о совместном редактировании
if (1 < countEditUsers) { if (1 < this._countEditUsers)
this._onStartCoAuthoring(isStartEvent); this._onStartCoAuthoring(/*isStartEvent*/true);
}
} }
}; };
...@@ -665,6 +660,20 @@ ...@@ -665,6 +660,20 @@
var userStateChanged = null; var userStateChanged = null;
if (undefined !== data["state"] && this.onConnectionStateChanged) { if (undefined !== data["state"] && this.onConnectionStateChanged) {
userStateChanged = new asc_user(data); userStateChanged = new asc_user(data);
if (userStateChanged.asc_getState()) {
this._participants[userStateChanged.asc_getId()] = userStateChanged;
++this._countEditUsers;
// Посылаем эвент о совместном редактировании
if (1 < this._countEditUsers)
this._onStartCoAuthoring(/*isStartEvent*/false);
} else {
delete this._participants[userStateChanged.asc_getId()];
--this._countEditUsers;
}
this.onParticipantsChanged(this._participants, this._countEditUsers);
this.onConnectionStateChanged(userStateChanged); this.onConnectionStateChanged(userStateChanged);
} }
}; };
...@@ -683,8 +692,7 @@ ...@@ -683,8 +692,7 @@
if (docsCoApi.onConnect) { if (docsCoApi.onConnect) {
docsCoApi.onConnect(); docsCoApi.onConnect();
} }
if (docsCoApi._locks) if (docsCoApi._locks) {
{
docsCoApi.ownedLockBlocks = []; docsCoApi.ownedLockBlocks = [];
//If we already have locks //If we already have locks
for (var block in docsCoApi._locks) { for (var block in docsCoApi._locks) {
...@@ -703,8 +711,11 @@ ...@@ -703,8 +711,11 @@
"type":"auth", "type":"auth",
"docid":docsCoApi._docid, "docid":docsCoApi._docid,
"token":docsCoApi._token, "token":docsCoApi._token,
"user":docsCoApi._user.asc_getId(), "user": {
"username":docsCoApi._user.asc_getUserName(), "id":docsCoApi._user.asc_getId(),
"name":docsCoApi._user.asc_getUserName(),
"color":docsCoApi._user.asc_getColor()
},
"locks":docsCoApi.ownedLockBlocks, "locks":docsCoApi.ownedLockBlocks,
"sessionId":docsCoApi._id, "sessionId":docsCoApi._id,
"serverHost": docsCoApi._serverHost, "serverHost": docsCoApi._serverHost,
...@@ -788,7 +799,7 @@ ...@@ -788,7 +799,7 @@
docsCoApi._state = 2; // Authorized docsCoApi._state = 2; // Authorized
docsCoApi._id = data["sessionId"]; docsCoApi._id = data["sessionId"];
docsCoApi._onParticipantsChanged(data["participants"], /*isStartEvent*/ true); docsCoApi._onAuthParticipantsChanged(data["participants"]);
if (data["indexuser"]) { if (data["indexuser"]) {
docsCoApi._indexuser = data["indexuser"]; docsCoApi._indexuser = data["indexuser"];
...@@ -814,14 +825,6 @@ ...@@ -814,14 +825,6 @@
if (docsCoApi._initCallback) { if (docsCoApi._initCallback) {
docsCoApi._initCallback({result:data["result"]}); docsCoApi._initCallback({result:data["result"]});
} }
},
"getusers":function (data) {
// Специально для возможности получения после прохождения авторизации
docsCoApi._onParticipantsChanged(data["participants"], /*isStartEvent*/ true);
},
"participants":function (data) {
//Pushed participants list from server
docsCoApi._onParticipantsChanged(data["participants"], /*isStartEvent*/ false);
}, },
"message":function (data) { "message":function (data) {
docsCoApi._onMessages(data); docsCoApi._onMessages(data);
...@@ -850,12 +853,4 @@ ...@@ -850,12 +853,4 @@
}; };
}; };
global["CDocsCoApi"] = CDocsCoApi; global["CDocsCoApi"] = CDocsCoApi;
//Helpers
/*Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};*/
})(window); })(window);
\ 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) { if ( !(this instanceof asc_CUser) ) { return new asc_CUser(val); } this.id = null; // уникальный id - пользователя this.userName = null; // имя пользователя this.state = undefined; // состояние (true - подключен, false - отключился) this.color = null; // цвет пользователя this._setUser(val); return this; } asc_CUser.prototype = { constructor: asc_CUser, _setUser: function (val) { if (val) { this.id = val["id"]; this.userName = val["username"]; this.color = val["color"]; this.state = val["state"]; } }, asc_getId: function () { return this.id; }, asc_getUserName: function () { return this.userName; }, asc_getState: function () { return this.state; }, asc_getColor: function () { return this.color; }, asc_setId: function (val) { this.id = val; }, asc_setUserName: function (val) { this.userName = val; }, asc_setState: function (val) { this.state = val; }, 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_setUserName"] = prot.asc_setUserName; prot["asc_setState"] = prot.asc_setState; prot["asc_setColor"] = prot.asc_setColor; } )(window); "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) { if ( !(this instanceof asc_CUser) ) { return new asc_CUser(val); } this.id = null; // уникальный id - пользователя this.userName = null; // имя пользователя this.state = undefined; // состояние (true - подключен, false - отключился) this.color = null; // цвет пользователя this._setUser(val); return this; } asc_CUser.prototype = { constructor: asc_CUser, _setUser: function (val) { if (val) { this.id = val["id"]; this.userName = val["username"]; this.color = val["color"]; this.state = val["state"]; } else { this.color = asc.generateColor(); } }, asc_getId: function () { return this.id; }, asc_getUserName: function () { return this.userName; }, asc_getState: function () { return this.state; }, asc_getColor: function () { return this.color; }, asc_setId: function (val) { this.id = val; }, asc_setUserName: function (val) { this.userName = val; }, asc_setState: function (val) { this.state = val; }, 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_setUserName"] = prot.asc_setUserName; prot["asc_setState"] = prot.asc_setState; prot["asc_setColor"] = prot.asc_setColor; } )(window);
\ No newline at end of file \ No newline at end of file
......
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