Commit 5397fc2b authored by alexey.musinov's avatar alexey.musinov

mobile-coautoring

parent d51719cc
/* /*
* (c) Copyright Ascensio System SIA 2010-2016 * (c) Copyright Ascensio System SIA 2010-2016
* *
* This program is a free software product. You can redistribute it and/or * This program is a free software product. You can redistribute it and/or
...@@ -3086,14 +3086,16 @@ var editor; ...@@ -3086,14 +3086,16 @@ var editor;
} }
}; };
spreadsheet_api.prototype.asc_nativeOpenFile = function(base64File, version) { spreadsheet_api.prototype.asc_nativeOpenFile = function(base64File, version, isUser) {
asc["editor"] = this; asc["editor"] = this;
this.SpellCheckUrl = ''; this.SpellCheckUrl = '';
this.User = new AscCommon.asc_CUser(); if (undefined == isUser) {
this.User.setId("TM"); this.User = new AscCommon.asc_CUser();
this.User.setUserName("native"); this.User.setId("TM");
this.User.setUserName("native");
}
this.wbModel = new AscCommonExcel.Workbook(this.handlers, this); this.wbModel = new AscCommonExcel.Workbook(this.handlers, this);
this.initGlobalObjects(this.wbModel); this.initGlobalObjects(this.wbModel);
......
...@@ -42,6 +42,8 @@ window.location.host = ""; ...@@ -42,6 +42,8 @@ window.location.host = "";
window.location.href = ""; window.location.href = "";
window.location.pathname = ""; window.location.pathname = "";
window.XMLHttpRequest = function () {};
window.NATIVE_EDITOR_ENJINE = true; window.NATIVE_EDITOR_ENJINE = true;
window.NATIVE_EDITOR_ENJINE_SYNC_RECALC = true; window.NATIVE_EDITOR_ENJINE_SYNC_RECALC = true;
window.IS_NATIVE_EDITOR = true; window.IS_NATIVE_EDITOR = true;
...@@ -280,58 +282,80 @@ window["native"] = native; ...@@ -280,58 +282,80 @@ window["native"] = native;
var _api = null; var _api = null;
window.NativeSupportTimeouts = false; window.NativeSupportTimeouts = true;
window.NativeTimeoutObject = {}; window.NativeTimeoutObject = {};
function clearTimeout(_id) {
if (!window.NativeSupportTimeouts)
return;
window.NativeTimeoutObject["" + _id] = undefined;
window.native["ClearTimeout"](_id);
}
function setTimeout(func, interval) { function setTimeout(func, interval) {
if (!window.NativeSupportTimeouts) if (!window.NativeSupportTimeouts)
return; return;
var _id = window.native["GenerateTimeoutId"](interval); var id = window["native"]["GenerateTimeoutId"](interval);
window.NativeTimeoutObject["" + _id] = func; window.NativeTimeoutObject["" + id] = {"func": func, repeat: false};
return _id;
return id;
} }
function offline_timeoutFire(_id) {
function clearTimeout(id) {
if (!window.NativeSupportTimeouts) if (!window.NativeSupportTimeouts)
return; return;
var _prop = "" + _id; window.NativeTimeoutObject["" + id] = undefined;
var _func = window.NativeTimeoutObject[_prop]; window["native"]["ClearTimeout"](id);
window.NativeTimeoutObject[_prop] = undefined; }
if (!_func) function setInterval(func, interval) {
if (!window.NativeSupportTimeouts)
return; return;
_func.call(null); // console.log("setInterval");
_func = null;
// var intervalFunc = function() {
//
// console.log("intervalFunc");
//
// func.call(null);
// setInterval(func, interval);
// }
var id = window["native"]["GenerateTimeoutId"](interval);
window.NativeTimeoutObject["" + id] = {func: func, repeat: true, interval: interval}; // intervalFunc;
return id;
} }
function clearInterval(_id) { function clearInterval(id) {
if (!window.NativeSupportTimeouts) if (!window.NativeSupportTimeouts)
return; return;
window.NativeTimeoutObject["" + _id] = undefined; window.NativeTimeoutObject["" + id] = undefined;
window.native["ClearTimeout"](_id); window["native"]["ClearTimeout"](id);
} }
function setInterval(func, interval) {
function offline_timeoutFire(id) {
if (!window.NativeSupportTimeouts) if (!window.NativeSupportTimeouts)
return; return;
var _intervalFunc = function() var prop = "" + id;
{
func.call(null); if (undefined === window.NativeTimeoutObject[prop]) {
setTimeout(func, interval); return;
}; }
var func = window.NativeTimeoutObject[prop].func;
var repeat = window.NativeTimeoutObject[prop].repeat;
var interval = window.NativeTimeoutObject[prop].interval;
window.NativeTimeoutObject[prop] = undefined;
if (!func)
return;
var _id = window.native["GenerateTimeoutId"](interval); func.call(null);
window.NativeTimeoutObject["" + _id] = _intervalFunc;
return _id; if (repeat) {
setInterval(func, interval);
}
func = null;
} }
window.clearTimeout = clearTimeout; window.clearTimeout = clearTimeout;
...@@ -468,4 +492,6 @@ var FT_Common = new _FT_Common(); ...@@ -468,4 +492,6 @@ var FT_Common = new _FT_Common();
var global_memory_stream_menu = CreateNativeMemoryStream(); var global_memory_stream_menu = CreateNativeMemoryStream();
window['AscFonts'] = window['AscFonts'] || {}; window['AscFonts'] = window['AscFonts'] || {};
window['AscFonts'].FT_Common = FT_Common; window['AscFonts'].FT_Common = FT_Common;
\ No newline at end of file
window['SockJS'] = createSockJS();
...@@ -2702,10 +2702,11 @@ function OfflineEditor () { ...@@ -2702,10 +2702,11 @@ function OfflineEditor () {
this.col0 = 0; this.col0 = 0;
this.row0 = 0; this.row0 = 0;
this.translate = null; this.translate = null;
this.initSettings = null;
// main // main
this.beforeOpen = function() { this.beforeOpen = function() {
var offlineEditor = this; var offlineEditor = this;
...@@ -3756,8 +3757,10 @@ function OfflineEditor () { ...@@ -3756,8 +3757,10 @@ function OfflineEditor () {
}; };
}; };
this.openFile = function () { this.openFile = function(settings) {
this.initSettings = settings;
this.beforeOpen(); this.beforeOpen();
window["CreateMainTextMeasurerWrapper"](); window["CreateMainTextMeasurerWrapper"]();
...@@ -3769,25 +3772,32 @@ function OfflineEditor () { ...@@ -3769,25 +3772,32 @@ function OfflineEditor () {
_api = new window["Asc"]["spreadsheet_api"]({}); _api = new window["Asc"]["spreadsheet_api"]({});
var userInfo = new Asc.asc_CUserInfo(); var userInfo = new Asc.asc_CUserInfo();
userInfo.asc_putId('ios'); userInfo.asc_putId(this.initSettings.userId);
userInfo.asc_putFullName('ios'); userInfo.asc_putFullName(this.initSettings.fullName);
userInfo.asc_getLastName('ios'); userInfo.asc_putFirstName(this.initSettings.firstName);
userInfo.asc_putLastName(this.initSettings.lastName);
var docInfo = new Asc.asc_CDocInfo(); var docInfo = new Asc.asc_CDocInfo();
docInfo.put_Id('ios'); docInfo.put_Id(this.initSettings.documentId);
docInfo.put_UserInfo(userInfo); docInfo.put_UserInfo(userInfo);
_api.asc_setDocInfo(docInfo);
this.offline_beforeInit(); this.offline_beforeInit();
this.registerEventsHandlers(); this.registerEventsHandlers();
_api.asc_setAutoSaveGap(1);
_api.asc_nativeOpenFile(window.native["GetFileString"](), undefined, true);
_api.asc_setDocInfo(docInfo); _api.asc_SetFastCollaborative(true);
_api.asc_nativeOpenFile(window.native["GetFileString"]());
this.asc_WriteAllWorksheets(true); this.asc_WriteAllWorksheets(true);
_api.asc_SendThemeColorScheme(); _api.asc_SendThemeColorScheme();
_api.asc_ApplyColorScheme(false); _api.asc_ApplyColorScheme(false);
_api._applyFirstLoadChanges();
window["NativeSupportTimeouts"] = true; window["NativeSupportTimeouts"] = true;
...@@ -3805,6 +3815,14 @@ function OfflineEditor () { ...@@ -3805,6 +3815,14 @@ function OfflineEditor () {
// TODO: Implement Text Art Styles // TODO: Implement Text Art Styles
this.offline_afteInit(); this.offline_afteInit();
setInterval(function() {
//checkAUtoSave();
//console.log("autosave");
_api._autoSave();
}, 100);
}; };
this.registerEventsHandlers = function () { this.registerEventsHandlers = function () {
...@@ -3893,6 +3911,25 @@ function OfflineEditor () { ...@@ -3893,6 +3911,25 @@ function OfflineEditor () {
asc_WriteAutoFiltersOptions(state, stream); asc_WriteAutoFiltersOptions(state, stream);
window["native"]["OnCallMenuEvent"](3060, stream); // ASC_SPREADSHEETS_EVENT_TYPE_FILTER_DIALOG window["native"]["OnCallMenuEvent"](3060, stream); // ASC_SPREADSHEETS_EVENT_TYPE_FILTER_DIALOG
}); });
_api.asc_registerCallback('asc_onGetEditorPermissions', function(state) {
//console.log("asc_onGetEditorPermissions");
var rData = {
"c" : 'open',
"id" : t.initSettings.documentId,
"userid" : t.initSettings.userId,
"format" : "xlsx",
"vkey" : undefined,
"url" : this.documentUrl,
"title" : this.documentTitle,
"embeddedfonts" : false,
"viewmode" : false// this.getViewMode()
};
_api.CoAuthoringApi.auth(false, // this.getViewMode()
rData);
});
}; };
this.updateFrozen = function () { this.updateFrozen = function () {
var ws = _api.wb.getWorksheet(); var ws = _api.wb.getWorksheet();
...@@ -5228,7 +5265,7 @@ function OfflineEditor () { ...@@ -5228,7 +5265,7 @@ function OfflineEditor () {
} }
var _s = new OfflineEditor(); var _s = new OfflineEditor();
function offline_of() {_s.openFile();} function offline_of(arg) {_s.openFile(arg);}
function offline_stz(v) {_s.zoom = v; _api.asc_setZoom(v);} function offline_stz(v) {_s.zoom = v; _api.asc_setZoom(v);}
function offline_ds(x, y, width, height, ratio, istoplayer) {_s.drawSheet(x, y, width, height, ratio, istoplayer);} function offline_ds(x, y, width, height, ratio, istoplayer) {_s.drawSheet(x, y, width, height, ratio, istoplayer);}
function offline_dh(x, y, width, height, type, ratio) {_s.drawHeader(x, y, width, height, type, ratio);} function offline_dh(x, y, width, height, type, ratio) {_s.drawHeader(x, y, width, height, type, ratio);}
...@@ -7143,7 +7180,84 @@ function offline_apply_event(type,params) { ...@@ -7143,7 +7180,84 @@ function offline_apply_event(type,params) {
ws.changeRowHeight(toRow, height, 0); ws.changeRowHeight(toRow, height, 0);
break; break;
} }
case 10000: // ASC_SOCKET_EVENT_TYPE_OPEN
{
var t = _api.CoAuthoringApi._CoAuthoringApi;
t._state = AscCommon.ConnectionState.WaitAuth;
t.onFirstConnect();
break;
}
case 10010: // ASC_SOCKET_EVENT_TYPE_CLOSE
{
break;
}
case 10020: // ASC_SOCKET_EVENT_TYPE_MESSAGE
{
var t = _api.CoAuthoringApi._CoAuthoringApi;
var dataObject = JSON.parse(params);
// console.log(params + " : " + dataObject['type']);
switch (dataObject['type']) {
case 'auth' :
t._onAuth(dataObject);
break;
case 'message' :
t._onMessages(dataObject, false);
break;
case 'cursor' :
t._onCursor(dataObject);
break;
case 'getLock' :
t._onGetLock(dataObject);
break;
case 'releaseLock' :
t._onReleaseLock(dataObject);
break;
case 'connectState' :
t._onConnectionStateChanged(dataObject);
break;
case 'saveChanges' :
t._onSaveChanges(dataObject);
break;
case 'saveLock' :
t._onSaveLock(dataObject);
break;
case 'unSaveLock' :
t._onUnSaveLock(dataObject);
break;
case 'savePartChanges' :
t._onSavePartChanges(dataObject);
break;
case 'drop' :
t._onDrop(dataObject);
break;
case 'waitAuth' : /*Ждем, когда придет auth, документ залочен*/
break;
case 'error' : /*Старая версия sdk*/
t._onDrop(dataObject);
break;
case 'documentOpen' :
t._documentOpen(dataObject);
break;
case 'warning':
t._onWarning(dataObject);
break;
case 'license':
t._onLicense(dataObject);
break;
}
break;
}
default: default:
break; break;
} }
......
...@@ -1336,8 +1336,10 @@ function DrawingObjects() { ...@@ -1336,8 +1336,10 @@ function DrawingObjects() {
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
_this.init = function(currentSheet) { _this.init = function(currentSheet) {
setInterval(drawTaskFunction, 5); if (!window['IS_NATIVE_EDITOR']) {
setInterval(drawTaskFunction, 5);
}
var api = window["Asc"]["editor"]; var api = window["Asc"]["editor"];
worksheet = currentSheet; worksheet = currentSheet;
......
/* /*
* (c) Copyright Ascensio System SIA 2010-2016 * (c) Copyright Ascensio System SIA 2010-2016
* *
* This program is a free software product. You can redistribute it and/or * This program is a free software product. You can redistribute it and/or
...@@ -515,7 +515,7 @@ ...@@ -515,7 +515,7 @@
} }
//в обычном серверном режиме портим ссылку, потому что CoAuthoring теперь имеет встроенный адрес //в обычном серверном режиме портим ссылку, потому что CoAuthoring теперь имеет встроенный адрес
//todo надо использовать проверку get_OfflineApp //todo надо использовать проверку get_OfflineApp
if (!(window['NATIVE_EDITOR_ENJINE'] || offlineMode === this.documentUrl)) if (!(window['NATIVE_EDITOR_ENJINE'] || offlineMode === this.documentUrl) || window['IS_NATIVE_EDITOR'])
{ {
this.CoAuthoringApi.set_url(null); this.CoAuthoringApi.set_url(null);
} }
......
...@@ -1259,9 +1259,16 @@ ...@@ -1259,9 +1259,16 @@
DocsCoApi.prototype._initSocksJs = function() { DocsCoApi.prototype._initSocksJs = function() {
var t = this; var t = this;
//ограничиваем transports WebSocket и XHR / JSONP polling, как и engine.io https://github.com/socketio/engine.io
//при переборе streaming transports у клиента с wirewall происходило зацикливание(не повторялось в версии sock.js 0.3.4) if (window['IS_NATIVE_EDITOR']) {
var sockjs = this.sockjs = new (this._getSockJs())(this.sockjs_url, null, {transports: ['websocket', 'xdr-polling', 'xhr-polling', 'iframe-xhr-polling', 'jsonp-polling']}); var sockjs = this.sockjs = window['SockJS'];
sockjs.open();
return sockjs;
} else {
//ограничиваем transports WebSocket и XHR / JSONP polling, как и engine.io https://github.com/socketio/engine.io
//при переборе streaming transports у клиента с wirewall происходило зацикливание(не повторялось в версии sock.js 0.3.4)
var sockjs = this.sockjs = new (this._getSockJs())(this.sockjs_url, null, {transports: ['websocket', 'xdr-polling', 'xhr-polling', 'iframe-xhr-polling', 'jsonp-polling']});
}
sockjs.onopen = function() { sockjs.onopen = function() {
if (t.reconnectTimeout) { if (t.reconnectTimeout) {
......
/* /*
* (c) Copyright Ascensio System SIA 2010-2016 * (c) Copyright Ascensio System SIA 2010-2016
* *
* This program is a free software product. You can redistribute it and/or * This program is a free software product. You can redistribute it and/or
...@@ -268,7 +268,26 @@ function openFileCommand(binUrl, changesUrl, Signature, callback) { ...@@ -268,7 +268,26 @@ function openFileCommand(binUrl, changesUrl, Signature, callback) {
}; };
var sFileUrl = binUrl; var sFileUrl = binUrl;
sFileUrl = sFileUrl.replace(/\\/g, "/"); sFileUrl = sFileUrl.replace(/\\/g, "/");
asc_ajax({
if (window['IS_NATIVE_EDITOR']) {
result = window["native"]["openFileCommand"](sFileUrl, changesUrl, Signature);
var url;
var nIndex = sFileUrl.lastIndexOf("/");
url = (-1 !== nIndex) ? sFileUrl.substring(0, nIndex + 1) : sFileUrl;
if (0 < result.length) {
oResult.bSerFormat = Signature === result.substring(0, Signature.length);
oResult.data = result;
oResult.url = url;
} else {
bError = true;
}
bEndLoadFile = true;
onEndOpen();
} else {
asc_ajax({
url: sFileUrl, url: sFileUrl,
dataType: "text", dataType: "text",
success: function(result) { success: function(result) {
...@@ -292,6 +311,8 @@ function openFileCommand(binUrl, changesUrl, Signature, callback) { ...@@ -292,6 +311,8 @@ function openFileCommand(binUrl, changesUrl, Signature, callback) {
onEndOpen(); onEndOpen();
} }
}); });
}
if (null != changesUrl) { if (null != changesUrl) {
getJSZipUtils().getBinaryContent(changesUrl, function(err, data) { getJSZipUtils().getBinaryContent(changesUrl, function(err, data) {
bEndLoadChanges = true; bEndLoadChanges = true;
......
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