Improve import/export office documents

pull/1/head
yflory 5 years ago
parent 5a26be5531
commit a7ffc038d9

@ -55,6 +55,10 @@ define([
return $('button.ok').last(); return $('button.ok').last();
}; };
UI.removeModals = function () {
$('div.alertify').remove();
};
var listenForKeys = UI.listenForKeys = function (yes, no, el) { var listenForKeys = UI.listenForKeys = function (yes, no, el) {
var handler = function (e) { var handler = function (e) {
e.stopPropagation(); e.stopPropagation();
@ -375,6 +379,7 @@ define([
dialog.getButtons = function (buttons, onClose) { dialog.getButtons = function (buttons, onClose) {
if (!Array.isArray(buttons)) { return void console.error('Not an array'); } if (!Array.isArray(buttons)) { return void console.error('Not an array'); }
if (!buttons.length) { return; }
var navs = []; var navs = [];
buttons.forEach(function (b) { buttons.forEach(function (b) {
if (!b.name || !b.onClick) { return; } if (!b.name || !b.onClick) { return; }

@ -27,6 +27,16 @@ body.cp-app-sheet, body.cp-app-oodoc, body.cp-app-ooslide {
); );
} }
.cp-oo-x2tXls {
display: flex;
align-items: center;
justify-content: center;
.fa {
font-size: 30px;
margin-right: 10px;
}
}
#cp-fileupload { #cp-fileupload {
display: none !important; display: none !important;
} }

@ -8,6 +8,7 @@ define([
'/common/common-hash.js', '/common/common-hash.js',
'/common/common-util.js', '/common/common-util.js',
'/common/common-ui-elements.js', '/common/common-ui-elements.js',
'/common/hyperscript.js',
'/api/config', '/api/config',
'/customize/messages.js', '/customize/messages.js',
'/customize/application_config.js', '/customize/application_config.js',
@ -33,6 +34,7 @@ define([
Hash, Hash,
Util, Util,
UIElements, UIElements,
h,
ApiConfig, ApiConfig,
Messages, Messages,
AppConfig, AppConfig,
@ -65,6 +67,7 @@ define([
var toolbar; var toolbar;
var andThen = function (common) { var andThen = function (common) {
var Title; var Title;
var sframeChan = common.getSframeChannel(); var sframeChan = common.getSframeChannel();
@ -898,6 +901,8 @@ define([
result = x2t.FS.readFile('/working/' + fileName + "." + outputFormat); result = x2t.FS.readFile('/working/' + fileName + "." + outputFormat);
} catch (e) { } catch (e) {
debug("Failed reading converted file"); debug("Failed reading converted file");
UI.removeModals();
UI.warn(Messages.error);
return ""; return "";
} }
return result; return result;
@ -919,6 +924,7 @@ define([
xlsData = x2tConvertDataInternal(x2t, data, filename, extension); xlsData = x2tConvertDataInternal(x2t, data, filename, extension);
if (xlsData) { if (xlsData) {
var blob = new Blob([xlsData], {type: "application/bin;charset=utf-8"}); var blob = new Blob([xlsData], {type: "application/bin;charset=utf-8"});
UI.removeModals();
saveAs(blob, finalFilename); saveAs(blob, finalFilename);
} }
}; };
@ -957,7 +963,7 @@ define([
if (typeof(Atomics) === "undefined") { if (typeof(Atomics) === "undefined") {
ext = ['.bin']; ext = ['.bin'];
warning = 'Use chrome'; // XXX tell the user they can export as Office format with Chrome? warning = '<div class="alert alert-info">'+Messages.oo_exportChrome+'</div>';
} }
var types = ext.map(function (val) { var types = ext.map(function (val) {
@ -980,8 +986,7 @@ define([
}; };
var $select = UIElements.createDropdown(dropdownConfig); var $select = UIElements.createDropdown(dropdownConfig);
var warningText = warning ? ('<br>' + warning) : ''; UI.prompt(Messages.exportPrompt+warning, Util.fixFileName(suggestion), function (filename) {
UI.prompt(Messages.exportPrompt+warningText, Util.fixFileName(suggestion), function (filename) {
// $select.getValue() // $select.getValue()
if (!(typeof(filename) === 'string' && filename)) { return; } if (!(typeof(filename) === 'string' && filename)) { return; }
var ext = ($select.getValue() || '').slice(1); var ext = ($select.getValue() || '').slice(1);
@ -991,7 +996,15 @@ define([
return; return;
} }
var content = h('div.cp-oo-x2tXls', [
h('span.fa.fa-spin.fa-spinner'),
h('span', Messages.oo_exportInProgress)
]);
var modal = UI.openCustomModal(UI.dialog.customModal(content, {buttons: []}));
setTimeout(function () {
x2tSaveAndConvertData(text, "filename.bin", ext, filename+'.'+ext); x2tSaveAndConvertData(text, "filename.bin", ext, filename+'.'+ext);
}, 100);
}, { }, {
typeInput: $select[0] typeInput: $select[0]
}, true); }, true);
@ -1092,15 +1105,18 @@ define([
return nId.length === 32; return nId.length === 32;
}); });
if (m.length > 1) { if (m.length > 1) {
UI.removeModals();
return void UI.alert(Messages.oo_cantUpload); return void UI.alert(Messages.oo_cantUpload);
} }
if (!content) { if (!content) {
return void UI.alert(Messages.error); // XXX? UI.removeModals();
return void UI.alert(Messages.oo_invalidFormat);
   }    }
var blob = new Blob([content], {type: 'plain/text'}); var blob = new Blob([content], {type: 'plain/text'});
var file = getFileType(); var file = getFileType();
blob.name = (metadataMgr.getMetadataLazy().title || file.doc) + '.' + file.type; blob.name = (metadataMgr.getMetadataLazy().title || file.doc) + '.' + file.type;
var uploadedCallback = function() { var uploadedCallback = function() {
UI.removeModals();
UI.confirm(Messages.oo_uploaded, function (yes) { UI.confirm(Messages.oo_uploaded, function (yes) {
try { try {
window.frames[0].editor.setViewModeDisconnect(); window.frames[0].editor.setViewModeDisconnect();
@ -1124,6 +1140,12 @@ define([
if (ext === "bin") { if (ext === "bin") {
return void importFile(content); return void importFile(content);
} }
var div = h('div.cp-oo-x2tXls', [
h('span.fa.fa-spin.fa-spinner'),
h('span', Messages.oo_importInProgress)
]);
var modal = UI.openCustomModal(UI.dialog.customModal(div, {buttons: []}));
setTimeout(function () {
require(['/common/onlyoffice/x2t/x2t.js'], function() { require(['/common/onlyoffice/x2t/x2t.js'], function() {
var x2t = window.Module; var x2t = window.Module;
x2t.run(); x2t.run();
@ -1143,6 +1165,7 @@ define([
}); });
}; };
}); });
}, 100);
}; };
var loadLastDocument = function () { var loadLastDocument = function () {

@ -5067,7 +5067,7 @@ function _emscripten_asm_const_iii(code, sigPtr, argbuf) {
node.stream_ops = stream_ops; node.stream_ops = stream_ops;
return node; return node;
},createPreloadedFile:function(parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn, preFinish) { },createPreloadedFile:function(parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn, preFinish) {
Browser.init(); // XXX perhaps this method should move onto Browser? Browser.init(); // perhaps this method should move onto Browser?
// TODO we should allow people to just pass in a complete filename instead // TODO we should allow people to just pass in a complete filename instead
// of parent and name being that we just join them anyways // of parent and name being that we just join them anyways
var fullname = name ? PATH_FS.resolve(PATH.join2(parent, name)) : parent; var fullname = name ? PATH_FS.resolve(PATH.join2(parent, name)) : parent;

Loading…
Cancel
Save