2020-12-20 08:15:58 +01:00
|
|
|
'use strict';
|
|
|
|
|
2011-12-04 16:33:56 +01:00
|
|
|
/**
|
2015-12-18 04:54:04 +01:00
|
|
|
* This code is mostly from the old Etherpad. Please help us to comment this code.
|
2011-12-04 16:33:56 +01:00
|
|
|
* This helps other people to understand this code better and helps them to improve it.
|
|
|
|
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
|
|
|
|
*/
|
|
|
|
|
2011-03-26 14:10:41 +01:00
|
|
|
/**
|
|
|
|
* Copyright 2009 Google Inc.
|
2011-07-07 19:59:34 +02:00
|
|
|
*
|
2011-03-26 14:10:41 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-07-07 19:59:34 +02:00
|
|
|
*
|
2011-03-26 14:10:41 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-07-07 19:59:34 +02:00
|
|
|
*
|
2011-03-26 14:10:41 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS-IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
const padimpexp = (() => {
|
2020-11-23 19:24:19 +01:00
|
|
|
// /// import
|
|
|
|
let currentImportTimer = null;
|
2011-03-26 14:10:41 +01:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
const addImportFrames = () => {
|
2020-11-23 19:24:19 +01:00
|
|
|
$('#import .importframe').remove();
|
2020-12-20 08:15:58 +01:00
|
|
|
const iframe = $('<iframe>')
|
|
|
|
.css('display', 'none')
|
|
|
|
.attr('name', 'importiframe')
|
|
|
|
.addClass('importframe');
|
2011-07-21 21:13:58 +02:00
|
|
|
$('#import').append(iframe);
|
2020-12-20 08:15:58 +01:00
|
|
|
};
|
2011-07-07 19:59:34 +02:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
const fileInputUpdated = () => {
|
2014-11-18 19:09:29 +01:00
|
|
|
$('#importsubmitinput').addClass('throbbold');
|
2011-03-26 14:10:41 +01:00
|
|
|
$('#importformfilediv').addClass('importformenabled');
|
|
|
|
$('#importsubmitinput').removeAttr('disabled');
|
2014-11-18 19:09:29 +01:00
|
|
|
$('#importmessagefail').fadeOut('fast');
|
2020-12-20 08:15:58 +01:00
|
|
|
};
|
2011-07-07 19:59:34 +02:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
const fileInputSubmit = () => {
|
2020-11-23 19:24:19 +01:00
|
|
|
$('#importmessagefail').fadeOut('fast');
|
|
|
|
const ret = window.confirm(html10n.get('pad.impexp.confirmimport'));
|
|
|
|
if (ret) {
|
|
|
|
currentImportTimer = window.setTimeout(() => {
|
|
|
|
if (!currentImportTimer) {
|
2011-03-26 14:10:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentImportTimer = null;
|
2020-11-23 19:24:19 +01:00
|
|
|
importFailed('Request timed out.');
|
2014-01-19 20:04:09 +01:00
|
|
|
importDone();
|
2011-03-26 14:10:41 +01:00
|
|
|
}, 25000); // time out after some number of seconds
|
2011-07-07 19:59:34 +02:00
|
|
|
$('#importsubmitinput').attr(
|
2020-11-23 19:24:19 +01:00
|
|
|
{
|
|
|
|
disabled: true,
|
|
|
|
}).val(html10n.get('pad.impexp.importing'));
|
2015-12-18 04:54:04 +01:00
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
window.setTimeout(() => {
|
2011-07-07 19:59:34 +02:00
|
|
|
$('#importfileinput').attr(
|
2020-11-23 19:24:19 +01:00
|
|
|
{
|
|
|
|
disabled: true,
|
|
|
|
});
|
2011-07-07 19:59:34 +02:00
|
|
|
}, 0);
|
2011-03-26 14:10:41 +01:00
|
|
|
$('#importarrow').stop(true, true).hide();
|
|
|
|
$('#importstatusball').show();
|
|
|
|
}
|
|
|
|
return ret;
|
2020-12-20 08:15:58 +01:00
|
|
|
};
|
2011-07-07 19:59:34 +02:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
const importFailed = (msg) => {
|
2011-03-26 14:10:41 +01:00
|
|
|
importErrorMessage(msg);
|
2020-12-20 08:15:58 +01:00
|
|
|
};
|
2011-07-07 19:59:34 +02:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
const importDone = () => {
|
2020-11-23 19:24:19 +01:00
|
|
|
$('#importsubmitinput').removeAttr('disabled').val(html10n.get('pad.impexp.importbutton'));
|
|
|
|
window.setTimeout(() => {
|
2011-07-07 19:59:34 +02:00
|
|
|
$('#importfileinput').removeAttr('disabled');
|
|
|
|
}, 0);
|
2011-03-26 14:10:41 +01:00
|
|
|
$('#importstatusball').hide();
|
|
|
|
importClearTimeout();
|
2012-02-27 00:22:53 +01:00
|
|
|
addImportFrames();
|
2020-12-20 08:15:58 +01:00
|
|
|
};
|
2011-07-07 19:59:34 +02:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
const importClearTimeout = () => {
|
2020-11-23 19:24:19 +01:00
|
|
|
if (currentImportTimer) {
|
2011-03-26 14:10:41 +01:00
|
|
|
window.clearTimeout(currentImportTimer);
|
|
|
|
currentImportTimer = null;
|
|
|
|
}
|
2020-12-20 08:15:58 +01:00
|
|
|
};
|
2011-07-07 19:59:34 +02:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
const importErrorMessage = (status) => {
|
2020-11-23 19:24:19 +01:00
|
|
|
let msg = '';
|
|
|
|
|
|
|
|
if (status === 'convertFailed') {
|
|
|
|
msg = html10n.get('pad.impexp.convertFailed');
|
|
|
|
} else if (status === 'uploadFailed') {
|
|
|
|
msg = html10n.get('pad.impexp.uploadFailed');
|
|
|
|
} else if (status === 'padHasData') {
|
|
|
|
msg = html10n.get('pad.impexp.padHasData');
|
|
|
|
} else if (status === 'maxFileSize') {
|
|
|
|
msg = html10n.get('pad.impexp.maxFileSize');
|
|
|
|
} else if (status === 'permission') {
|
|
|
|
msg = html10n.get('pad.impexp.permission');
|
2012-02-27 00:22:53 +01:00
|
|
|
}
|
2015-12-18 04:54:04 +01:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
const showError = (fade) => {
|
|
|
|
$('#importmessagefail').html(
|
|
|
|
`<strong style="color: red">${html10n.get('pad.impexp.importfailed')}:</strong> ` +
|
|
|
|
`${msg || html10n.get('pad.impexp.copypaste', '')}`)[(fade ? 'fadeIn' : 'show')]();
|
|
|
|
};
|
2011-03-26 14:10:41 +01:00
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
if ($('#importexport .importmessage').is(':visible')) {
|
|
|
|
$('#importmessagesuccess').fadeOut('fast');
|
|
|
|
$('#importmessagefail').fadeOut('fast', () => {
|
2011-07-07 19:59:34 +02:00
|
|
|
showError(true);
|
|
|
|
});
|
2020-11-23 19:24:19 +01:00
|
|
|
} else {
|
2011-03-26 14:10:41 +01:00
|
|
|
showError();
|
|
|
|
}
|
2020-12-20 08:15:58 +01:00
|
|
|
};
|
2011-07-07 19:59:34 +02:00
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
// /// export
|
2011-03-26 14:10:41 +01:00
|
|
|
|
2020-11-21 19:37:57 +01:00
|
|
|
function cantExport() {
|
2020-11-23 19:24:19 +01:00
|
|
|
let type = $(this);
|
|
|
|
if (type.hasClass('exporthrefpdf')) {
|
|
|
|
type = 'PDF';
|
|
|
|
} else if (type.hasClass('exporthrefdoc')) {
|
|
|
|
type = 'Microsoft Word';
|
|
|
|
} else if (type.hasClass('exporthrefodt')) {
|
|
|
|
type = 'OpenDocument';
|
|
|
|
} else {
|
|
|
|
type = 'this file';
|
2011-03-26 14:10:41 +01:00
|
|
|
}
|
2020-11-23 19:24:19 +01:00
|
|
|
alert(html10n.get('pad.impexp.exportdisabled', {type}));
|
2011-03-26 14:10:41 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
// ///
|
2020-12-20 08:15:58 +01:00
|
|
|
let pad = undefined;
|
2020-11-23 19:24:19 +01:00
|
|
|
const self = {
|
2020-12-20 08:15:58 +01:00
|
|
|
init: (_pad) => {
|
2012-01-27 06:02:58 +01:00
|
|
|
pad = _pad;
|
2012-01-16 06:37:47 +01:00
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
// get /p/padname
|
2015-02-11 03:07:20 +01:00
|
|
|
// if /p/ isn't available due to a rewrite we use the clientVars padId
|
2020-12-20 08:15:58 +01:00
|
|
|
const padRootPath = /.*\/p\/[^/]+/.exec(document.location.pathname) || clientVars.padId;
|
2020-11-23 19:24:19 +01:00
|
|
|
// get http://example.com/p/padname without Params
|
2020-12-20 08:15:58 +01:00
|
|
|
const dl = document.location;
|
|
|
|
const padRootUrl = `${dl.protocol}//${dl.host}${dl.pathname}`;
|
2020-11-23 19:24:19 +01:00
|
|
|
|
|
|
|
// i10l buttom import
|
|
|
|
$('#importsubmitinput').val(html10n.get('pad.impexp.importbutton'));
|
|
|
|
html10n.bind('localized', () => {
|
|
|
|
$('#importsubmitinput').val(html10n.get('pad.impexp.importbutton'));
|
|
|
|
});
|
2012-12-07 05:24:40 +01:00
|
|
|
|
2011-07-22 15:07:13 +02:00
|
|
|
// build the export links
|
2020-12-20 08:15:58 +01:00
|
|
|
$('#exporthtmla').attr('href', `${padRootPath}/export/html`);
|
|
|
|
$('#exportetherpada').attr('href', `${padRootPath}/export/etherpad`);
|
|
|
|
$('#exportplaina').attr('href', `${padRootPath}/export/txt`);
|
2012-11-26 03:18:47 +01:00
|
|
|
|
|
|
|
// activate action to import in the form
|
2020-12-20 08:15:58 +01:00
|
|
|
$('#importform').attr('action', `${padRootUrl}/import`);
|
2020-11-23 19:24:19 +01:00
|
|
|
|
|
|
|
// hide stuff thats not avaible if abiword/soffice is disabled
|
2020-12-20 08:15:58 +01:00
|
|
|
if (clientVars.exportAvailable === 'no') {
|
2020-11-23 19:24:19 +01:00
|
|
|
$('#exportworda').remove();
|
|
|
|
$('#exportpdfa').remove();
|
|
|
|
$('#exportopena').remove();
|
|
|
|
|
|
|
|
$('#importmessageabiword').show();
|
2020-12-20 08:15:58 +01:00
|
|
|
} else if (clientVars.exportAvailable === 'withoutPDF') {
|
2020-11-23 19:24:19 +01:00
|
|
|
$('#exportpdfa').remove();
|
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
$('#exportworda').attr('href', `${padRootPath}/export/doc`);
|
|
|
|
$('#exportopena').attr('href', `${padRootPath}/export/odt`);
|
2020-11-23 19:24:19 +01:00
|
|
|
|
|
|
|
$('#importexport').css({height: '142px'});
|
|
|
|
$('#importexportline').css({height: '142px'});
|
|
|
|
} else {
|
2020-12-20 08:15:58 +01:00
|
|
|
$('#exportworda').attr('href', `${padRootPath}/export/doc`);
|
|
|
|
$('#exportpdfa').attr('href', `${padRootPath}/export/pdf`);
|
|
|
|
$('#exportopena').attr('href', `${padRootPath}/export/odt`);
|
2011-07-26 19:54:42 +02:00
|
|
|
}
|
2015-12-18 04:54:04 +01:00
|
|
|
|
2011-03-26 14:10:41 +01:00
|
|
|
addImportFrames();
|
2020-11-23 19:24:19 +01:00
|
|
|
$('#importfileinput').change(fileInputUpdated);
|
|
|
|
$('#importform').unbind('submit').submit(fileInputSubmit);
|
2011-03-26 14:10:41 +01:00
|
|
|
$('.disabledexport').click(cantExport);
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
handleFrameCall: (directDatabaseAccess, status) => {
|
2020-11-23 19:24:19 +01:00
|
|
|
if (directDatabaseAccess === 'undefined') directDatabaseAccess = false;
|
|
|
|
if (status !== 'ok') {
|
2012-02-27 00:22:53 +01:00
|
|
|
importFailed(status);
|
2020-11-23 19:24:19 +01:00
|
|
|
} else {
|
2020-04-21 17:03:09 +02:00
|
|
|
$('#import_export').removeClass('popup-show');
|
|
|
|
}
|
2020-04-21 17:02:58 +02:00
|
|
|
|
|
|
|
if (directDatabaseAccess) {
|
|
|
|
// Switch to the pad without redrawing the page
|
|
|
|
pad.switchToPad(clientVars.padId);
|
2020-04-21 17:03:09 +02:00
|
|
|
$('#import_export').removeClass('popup-show');
|
2020-04-21 17:02:58 +02:00
|
|
|
}
|
|
|
|
|
2012-02-27 00:22:53 +01:00
|
|
|
importDone();
|
2011-03-26 14:10:41 +01:00
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
disable: () => {
|
2020-11-23 19:24:19 +01:00
|
|
|
$('#impexp-disabled-clickcatcher').show();
|
|
|
|
$('#import').css('opacity', 0.5);
|
|
|
|
$('#impexp-export').css('opacity', 0.5);
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
enable: () => {
|
2020-11-23 19:24:19 +01:00
|
|
|
$('#impexp-disabled-clickcatcher').hide();
|
|
|
|
$('#import').css('opacity', 1);
|
|
|
|
$('#impexp-export').css('opacity', 1);
|
2011-03-26 14:10:41 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
return self;
|
2020-12-20 08:15:58 +01:00
|
|
|
})();
|
2012-01-16 02:23:48 +01:00
|
|
|
|
|
|
|
exports.padimpexp = padimpexp;
|