|
|
@ -56,6 +56,7 @@ define([
|
|
|
|
var CHECKPOINT_INTERVAL = 50;
|
|
|
|
var CHECKPOINT_INTERVAL = 50;
|
|
|
|
var DISPLAY_RESTORE_BUTTON = false;
|
|
|
|
var DISPLAY_RESTORE_BUTTON = false;
|
|
|
|
var NEW_VERSION = 2;
|
|
|
|
var NEW_VERSION = 2;
|
|
|
|
|
|
|
|
var PENDING_TIMEOUT = 30000;
|
|
|
|
|
|
|
|
|
|
|
|
var debug = function (x) {
|
|
|
|
var debug = function (x) {
|
|
|
|
if (!window.CP_DEV_MODE) { return; }
|
|
|
|
if (!window.CP_DEV_MODE) { return; }
|
|
|
@ -76,6 +77,7 @@ define([
|
|
|
|
var privateData = metadataMgr.getPrivateData();
|
|
|
|
var privateData = metadataMgr.getPrivateData();
|
|
|
|
var readOnly = false;
|
|
|
|
var readOnly = false;
|
|
|
|
var offline = false;
|
|
|
|
var offline = false;
|
|
|
|
|
|
|
|
var pendingChanges = {};
|
|
|
|
var config = {};
|
|
|
|
var config = {};
|
|
|
|
var content = {
|
|
|
|
var content = {
|
|
|
|
hashes: {},
|
|
|
|
hashes: {},
|
|
|
@ -102,6 +104,18 @@ define([
|
|
|
|
return metadataMgr.getNetfluxId() + '-' + privateData.clientId;
|
|
|
|
return metadataMgr.getNetfluxId() + '-' + privateData.clientId;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var setEditable = function (state) {
|
|
|
|
|
|
|
|
$('#cp-app-oo-editor').find('#cp-app-oo-offline').remove();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
window.frames[0].editor.asc_setViewMode(!state);
|
|
|
|
|
|
|
|
//window.frames[0].editor.setViewModeDisconnect(true);
|
|
|
|
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
if (!state) {
|
|
|
|
|
|
|
|
$('#cp-app-oo-editor').append(h('div#cp-app-oo-offline'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
debug(state);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var deleteOffline = function () {
|
|
|
|
var deleteOffline = function () {
|
|
|
|
var ids = content.ids;
|
|
|
|
var ids = content.ids;
|
|
|
|
var users = Object.keys(metadataMgr.getMetadata().users);
|
|
|
|
var users = Object.keys(metadataMgr.getMetadata().users);
|
|
|
@ -600,7 +614,30 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var handleChanges = function (obj, send) {
|
|
|
|
var handleChanges = function (obj, send) {
|
|
|
|
|
|
|
|
// Add a new entry to the pendingChanges object.
|
|
|
|
|
|
|
|
// If we can't send the patch within 30s, force a page reload
|
|
|
|
|
|
|
|
var uid = Util.uid();
|
|
|
|
|
|
|
|
pendingChanges[uid] = setTimeout(function () {
|
|
|
|
|
|
|
|
// If we're offline, force a reload on reconnect
|
|
|
|
|
|
|
|
if (offline) {
|
|
|
|
|
|
|
|
pendingChanges.force = true;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// We're online: force a reload now
|
|
|
|
|
|
|
|
setEditable(false);
|
|
|
|
|
|
|
|
UI.alert(Messages.realtime_unrecoverableError, function () {
|
|
|
|
|
|
|
|
common.gotoURL();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, PENDING_TIMEOUT);
|
|
|
|
|
|
|
|
if (offline) {
|
|
|
|
|
|
|
|
pendingChanges.force = true;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Send the changes
|
|
|
|
// Send the changes
|
|
|
|
rtChannel.sendMsg({
|
|
|
|
rtChannel.sendMsg({
|
|
|
|
type: "saveChanges",
|
|
|
|
type: "saveChanges",
|
|
|
@ -609,7 +646,13 @@ define([
|
|
|
|
locks: [content.locks[getId()]],
|
|
|
|
locks: [content.locks[getId()]],
|
|
|
|
excelAdditionalInfo: null
|
|
|
|
excelAdditionalInfo: null
|
|
|
|
}, null, function (err, hash) {
|
|
|
|
}, null, function (err, hash) {
|
|
|
|
if (err) { return void console.error(err); }
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
return void console.error(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pendingChanges[uid]) {
|
|
|
|
|
|
|
|
clearTimeout(pendingChanges[uid]);
|
|
|
|
|
|
|
|
delete pendingChanges[uid];
|
|
|
|
|
|
|
|
}
|
|
|
|
// Call unSaveLock to tell onlyoffice that the patch was sent.
|
|
|
|
// Call unSaveLock to tell onlyoffice that the patch was sent.
|
|
|
|
// It will allow you to make changes to another cell.
|
|
|
|
// It will allow you to make changes to another cell.
|
|
|
|
// If there is an error and unSaveLock is not called, onlyoffice
|
|
|
|
// If there is an error and unSaveLock is not called, onlyoffice
|
|
|
@ -662,10 +705,12 @@ define([
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "isSaveLock":
|
|
|
|
case "isSaveLock":
|
|
|
|
// TODO ping the server to check if we're online first?
|
|
|
|
// TODO ping the server to check if we're online first?
|
|
|
|
|
|
|
|
if (!offline) {
|
|
|
|
send({
|
|
|
|
send({
|
|
|
|
type: "saveLock",
|
|
|
|
type: "saveLock",
|
|
|
|
saveLock: false
|
|
|
|
saveLock: false
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "getLock":
|
|
|
|
case "getLock":
|
|
|
|
handleLock(obj, send);
|
|
|
|
handleLock(obj, send);
|
|
|
@ -1305,18 +1350,6 @@ define([
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var setEditable = function (state) {
|
|
|
|
|
|
|
|
$('#cp-app-oo-editor').find('#cp-app-oo-offline').remove();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
window.frames[0].editor.asc_setViewMode(!state);
|
|
|
|
|
|
|
|
//window.frames[0].editor.setViewModeDisconnect(true);
|
|
|
|
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
if (!state) {
|
|
|
|
|
|
|
|
$('#cp-app-oo-editor').append(h('div#cp-app-oo-offline'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
debug(state);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var stringifyInner = function () {
|
|
|
|
var stringifyInner = function () {
|
|
|
|
var obj = {
|
|
|
|
var obj = {
|
|
|
|
content: content,
|
|
|
|
content: content,
|
|
|
@ -1574,16 +1607,19 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
config.onConnectionChange = function (info) {
|
|
|
|
config.onConnectionChange = function (info) {
|
|
|
|
setEditable(info.state);
|
|
|
|
|
|
|
|
if (info.state) {
|
|
|
|
if (info.state) {
|
|
|
|
|
|
|
|
// If we tried to send changes while we were offline, force a page reload
|
|
|
|
UI.findOKButton().click();
|
|
|
|
UI.findOKButton().click();
|
|
|
|
offline = false;
|
|
|
|
if (Object.keys(pendingChanges).length) {
|
|
|
|
// XXX allow reconnect or not?
|
|
|
|
return void UI.confirm(Messages.oo_reconnect, function (yes) {
|
|
|
|
/*UI.confirm(Messages.oo_reconnect, function (yes) {
|
|
|
|
|
|
|
|
if (!yes) { return; }
|
|
|
|
if (!yes) { return; }
|
|
|
|
common.gotoURL();
|
|
|
|
common.gotoURL();
|
|
|
|
});*/
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setEditable(true);
|
|
|
|
|
|
|
|
offline = false;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
setEditable(false);
|
|
|
|
offline = true;
|
|
|
|
offline = true;
|
|
|
|
UI.findOKButton().click();
|
|
|
|
UI.findOKButton().click();
|
|
|
|
UI.alert(Messages.common_connectionLost, undefined, true);
|
|
|
|
UI.alert(Messages.common_connectionLost, undefined, true);
|
|
|
|