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

mobile-coautoring

parent d51719cc
/*
/*
* (c) Copyright Ascensio System SIA 2010-2016
*
* This program is a free software product. You can redistribute it and/or
......@@ -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;
this.SpellCheckUrl = '';
if (undefined == isUser) {
this.User = new AscCommon.asc_CUser();
this.User.setId("TM");
this.User.setUserName("native");
}
this.wbModel = new AscCommonExcel.Workbook(this.handlers, this);
this.initGlobalObjects(this.wbModel);
......
......@@ -42,6 +42,8 @@ window.location.host = "";
window.location.href = "";
window.location.pathname = "";
window.XMLHttpRequest = function () {};
window.NATIVE_EDITOR_ENJINE = true;
window.NATIVE_EDITOR_ENJINE_SYNC_RECALC = true;
window.IS_NATIVE_EDITOR = true;
......@@ -280,58 +282,80 @@ window["native"] = native;
var _api = null;
window.NativeSupportTimeouts = false;
window.NativeSupportTimeouts = true;
window.NativeTimeoutObject = {};
function clearTimeout(_id) {
function setTimeout(func, interval) {
if (!window.NativeSupportTimeouts)
return;
window.NativeTimeoutObject["" + _id] = undefined;
window.native["ClearTimeout"](_id);
var id = window["native"]["GenerateTimeoutId"](interval);
window.NativeTimeoutObject["" + id] = {"func": func, repeat: false};
return id;
}
function setTimeout(func, interval) {
function clearTimeout(id) {
if (!window.NativeSupportTimeouts)
return;
var _id = window.native["GenerateTimeoutId"](interval);
window.NativeTimeoutObject["" + _id] = func;
return _id;
window.NativeTimeoutObject["" + id] = undefined;
window["native"]["ClearTimeout"](id);
}
function offline_timeoutFire(_id) {
function setInterval(func, interval) {
if (!window.NativeSupportTimeouts)
return;
var _prop = "" + _id;
var _func = window.NativeTimeoutObject[_prop];
window.NativeTimeoutObject[_prop] = undefined;
// console.log("setInterval");
if (!_func)
return;
// 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;
_func.call(null);
_func = null;
return id;
}
function clearInterval(_id) {
function clearInterval(id) {
if (!window.NativeSupportTimeouts)
return;
window.NativeTimeoutObject["" + _id] = undefined;
window.native["ClearTimeout"](_id);
window.NativeTimeoutObject["" + id] = undefined;
window["native"]["ClearTimeout"](id);
}
function setInterval(func, interval) {
function offline_timeoutFire(id) {
if (!window.NativeSupportTimeouts)
return;
var _intervalFunc = function()
{
var prop = "" + id;
if (undefined === window.NativeTimeoutObject[prop]) {
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;
func.call(null);
setTimeout(func, interval);
};
var _id = window.native["GenerateTimeoutId"](interval);
window.NativeTimeoutObject["" + _id] = _intervalFunc;
return _id;
if (repeat) {
setInterval(func, interval);
}
func = null;
}
window.clearTimeout = clearTimeout;
......@@ -469,3 +493,5 @@ var global_memory_stream_menu = CreateNativeMemoryStream();
window['AscFonts'] = window['AscFonts'] || {};
window['AscFonts'].FT_Common = FT_Common;
window['SockJS'] = createSockJS();
......@@ -2702,6 +2702,7 @@ function OfflineEditor () {
this.col0 = 0;
this.row0 = 0;
this.translate = null;
this.initSettings = null;
// main
......@@ -3756,7 +3757,9 @@ function OfflineEditor () {
};
};
this.openFile = function () {
this.openFile = function(settings) {
this.initSettings = settings;
this.beforeOpen();
......@@ -3769,25 +3772,32 @@ function OfflineEditor () {
_api = new window["Asc"]["spreadsheet_api"]({});
var userInfo = new Asc.asc_CUserInfo();
userInfo.asc_putId('ios');
userInfo.asc_putFullName('ios');
userInfo.asc_getLastName('ios');
userInfo.asc_putId(this.initSettings.userId);
userInfo.asc_putFullName(this.initSettings.fullName);
userInfo.asc_putFirstName(this.initSettings.firstName);
userInfo.asc_putLastName(this.initSettings.lastName);
var docInfo = new Asc.asc_CDocInfo();
docInfo.put_Id('ios');
docInfo.put_Id(this.initSettings.documentId);
docInfo.put_UserInfo(userInfo);
_api.asc_setDocInfo(docInfo);
this.offline_beforeInit();
this.registerEventsHandlers();
_api.asc_setDocInfo(docInfo);
_api.asc_nativeOpenFile(window.native["GetFileString"]());
_api.asc_setAutoSaveGap(1);
_api.asc_nativeOpenFile(window.native["GetFileString"](), undefined, true);
_api.asc_SetFastCollaborative(true);
this.asc_WriteAllWorksheets(true);
_api.asc_SendThemeColorScheme();
_api.asc_ApplyColorScheme(false);
_api._applyFirstLoadChanges();
window["NativeSupportTimeouts"] = true;
......@@ -3805,6 +3815,14 @@ function OfflineEditor () {
// TODO: Implement Text Art Styles
this.offline_afteInit();
setInterval(function() {
//checkAUtoSave();
//console.log("autosave");
_api._autoSave();
}, 100);
};
this.registerEventsHandlers = function () {
......@@ -3893,6 +3911,25 @@ function OfflineEditor () {
asc_WriteAutoFiltersOptions(state, stream);
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 () {
var ws = _api.wb.getWorksheet();
......@@ -5228,7 +5265,7 @@ function 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_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);}
......@@ -7144,6 +7181,83 @@ function offline_apply_event(type,params) {
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:
break;
}
......
......@@ -1337,7 +1337,9 @@ function DrawingObjects() {
_this.init = function(currentSheet) {
if (!window['IS_NATIVE_EDITOR']) {
setInterval(drawTaskFunction, 5);
}
var api = window["Asc"]["editor"];
worksheet = currentSheet;
......
/*
/*
* (c) Copyright Ascensio System SIA 2010-2016
*
* This program is a free software product. You can redistribute it and/or
......@@ -515,7 +515,7 @@
}
//в обычном серверном режиме портим ссылку, потому что CoAuthoring теперь имеет встроенный адрес
//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);
}
......
......@@ -1259,9 +1259,16 @@
DocsCoApi.prototype._initSocksJs = function() {
var t = this;
if (window['IS_NATIVE_EDITOR']) {
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() {
if (t.reconnectTimeout) {
......
/*
/*
* (c) Copyright Ascensio System SIA 2010-2016
*
* This program is a free software product. You can redistribute it and/or
......@@ -268,6 +268,25 @@ function openFileCommand(binUrl, changesUrl, Signature, callback) {
};
var sFileUrl = binUrl;
sFileUrl = sFileUrl.replace(/\\/g, "/");
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,
dataType: "text",
......@@ -292,6 +311,8 @@ function openFileCommand(binUrl, changesUrl, Signature, callback) {
onEndOpen();
}
});
}
if (null != changesUrl) {
getJSZipUtils().getBinaryContent(changesUrl, function(err, data) {
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