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();
};
UI.removeModals = function () {
$('div.alertify').remove();
};
var listenForKeys = UI.listenForKeys = function (yes, no, el) {
var handler = function (e) {
e.stopPropagation();
@ -375,6 +379,7 @@ define([
dialog.getButtons = function (buttons, onClose) {
if (!Array.isArray(buttons)) { return void console.error('Not an array'); }
if (!buttons.length) { return; }
var navs = [];
buttons.forEach(function (b) {
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 {
display: none !important;
}

@ -8,6 +8,7 @@ define([
'/common/common-hash.js',
'/common/common-util.js',
'/common/common-ui-elements.js',
'/common/hyperscript.js',
'/api/config',
'/customize/messages.js',
'/customize/application_config.js',
@ -33,6 +34,7 @@ define([
Hash,
Util,
UIElements,
h,
ApiConfig,
Messages,
AppConfig,
@ -65,6 +67,7 @@ define([
var toolbar;
var andThen = function (common) {
var Title;
var sframeChan = common.getSframeChannel();
@ -898,6 +901,8 @@ define([
result = x2t.FS.readFile('/working/' + fileName + "." + outputFormat);
} catch (e) {
debug("Failed reading converted file");
UI.removeModals();
UI.warn(Messages.error);
return "";
}
return result;
@ -919,6 +924,7 @@ define([
xlsData = x2tConvertDataInternal(x2t, data, filename, extension);
if (xlsData) {
var blob = new Blob([xlsData], {type: "application/bin;charset=utf-8"});
UI.removeModals();
saveAs(blob, finalFilename);
}
};
@ -957,7 +963,7 @@ define([
if (typeof(Atomics) === "undefined") {
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) {
@ -980,8 +986,7 @@ define([
};
var $select = UIElements.createDropdown(dropdownConfig);
var warningText = warning ? ('<br>' + warning) : '';
UI.prompt(Messages.exportPrompt+warningText, Util.fixFileName(suggestion), function (filename) {
UI.prompt(Messages.exportPrompt+warning, Util.fixFileName(suggestion), function (filename) {
// $select.getValue()
if (!(typeof(filename) === 'string' && filename)) { return; }
var ext = ($select.getValue() || '').slice(1);
@ -991,7 +996,15 @@ define([
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);
}, 100);
}, {
typeInput: $select[0]
}, true);
@ -1092,15 +1105,18 @@ define([
return nId.length === 32;
});
if (m.length > 1) {
UI.removeModals();
return void UI.alert(Messages.oo_cantUpload);
}
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 file = getFileType();
blob.name = (metadataMgr.getMetadataLazy().title || file.doc) + '.' + file.type;
var uploadedCallback = function() {
UI.removeModals();
UI.confirm(Messages.oo_uploaded, function (yes) {
try {
window.frames[0].editor.setViewModeDisconnect();
@ -1124,6 +1140,12 @@ define([
if (ext === "bin") {
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() {
var x2t = window.Module;
x2t.run();
@ -1143,6 +1165,7 @@ define([
});
};
});
}, 100);
};
var loadLastDocument = function () {

@ -5067,7 +5067,7 @@ function _emscripten_asm_const_iii(code, sigPtr, argbuf) {
node.stream_ops = stream_ops;
return node;
},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
// of parent and name being that we just join them anyways
var fullname = name ? PATH_FS.resolve(PATH.join2(parent, name)) : parent;

Loading…
Cancel
Save