Change layout for Open Dialog.

[SSE] Add import wizard for special paste
This commit is contained in:
Julia Radzhabova 2019-04-17 12:01:20 +03:00
parent da22437f35
commit 60004afb1d
7 changed files with 103 additions and 64 deletions

View file

@ -106,6 +106,13 @@ Common.Utils = _.extend(new(function() {
Pivot : 10,
Cell : 11
},
importTextType = {
DRM: 0,
CSV: 1,
TXT: 2,
Paste: 3,
Columns: 4
},
isMobile = /android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent || navigator.vendor || window.opera),
me = this,
checkSize = function() {
@ -203,6 +210,7 @@ Common.Utils = _.extend(new(function() {
ipStrongRe: ipStrongRe,
hostnameStrongRe: hostnameStrongRe,
documentSettingsType: documentSettingsType,
importTextType: importTextType,
zoom: function() {return me.zoom;},
innerWidth: function() {return me.innerWidth;},
innerHeight: function() {return me.innerHeight;}

View file

@ -59,21 +59,20 @@ define([
width = 414;
height = 277;
} else {
width = (options.type !== Asc.c_oAscAdvancedOptionsID.DRM) ? 340 : (options.warning ? 370 : 262);
height = (options.type == Asc.c_oAscAdvancedOptionsID.CSV) ? 190 : (options.warning ? 187 : 147);
width = (options.type !== Common.Utils.importTextType.DRM) ? 340 : (options.warning ? 370 : 262);
height = (options.type == Common.Utils.importTextType.CSV || options.type == Common.Utils.importTextType.Paste || options.type == Common.Utils.importTextType.Columns) ? 190 : (options.warning ? 187 : 147);
}
_.extend(_options, {
mode : 1, // open settings
closable : (options.mode==2), // if save settings
closable : false, // true if save settings
preview : options.preview,
warning : options.warning,
codepages : options.codepages,
width : width,
height : height,
header : true,
cls : 'open-dlg',
contentTemplate : '',
title : (options.type == Asc.c_oAscAdvancedOptionsID.DRM) ? t.txtTitleProtected : t.txtTitle.replace('%1', (options.type == Asc.c_oAscAdvancedOptionsID.CSV) ? 'CSV' : 'TXT'),
toolcallback : _.bind(t.onToolClose, t),
closeFile : false
@ -82,7 +81,7 @@ define([
this.template = options.template || [
'<div class="box" style="height:' + (_options.height - 85) + 'px;">',
'<div class="content-panel" >',
'<% if (type == Asc.c_oAscAdvancedOptionsID.DRM) { %>',
'<% if (type == Common.Utils.importTextType.DRM) { %>',
'<% if (warning) { %>',
'<div>',
'<div class="icon img-commonctrl warn"/>',
@ -97,13 +96,15 @@ define([
'</div>',
'<% } %>',
'<% } else { %>',
'<div style="<% if (!!preview && type == Asc.c_oAscAdvancedOptionsID.CSV) { %>width: 230px;margin-right: 10px;display: inline-block;<% } else { %>width: 100%;<% } %>margin-bottom:15px;">',
'<% if (codepages && codepages.length>0) { %>',
'<div style="<% if (!!preview && (type == Common.Utils.importTextType.CSV || type == Common.Utils.importTextType.Paste || type == Common.Utils.importTextType.Columns)) { %>width: 230px;margin-right: 10px;display: inline-block;<% } else { %>width: 100%;<% } %>margin-bottom:15px;">',
'<label class="header">' + t.txtEncoding + '</label>',
'<div>',
'<div id="id-codepages-combo" class="input-group-nr" style="width: 100%; display: inline-block; vertical-align: middle;"></div>',
'</div>',
'</div>',
'<% if (type == Asc.c_oAscAdvancedOptionsID.CSV) { %>',
'<% } %>',
'<% if (type == Common.Utils.importTextType.CSV || type == Common.Utils.importTextType.Paste || type == Common.Utils.importTextType.Columns) { %>',
'<div style="display: inline-block; margin-bottom:15px;">',
'<label class="header">' + t.txtDelimiter + '</label>',
'<div>',
@ -168,7 +169,7 @@ define([
this.previewScrolled = this.$window.find('#id-preview');
this.previewInner = this.previewScrolled.find('div:first-child');
if (this.type == Asc.c_oAscAdvancedOptionsID.DRM) {
if (this.type == Common.Utils.importTextType.DRM) {
this.inputPwd = new Common.UI.InputField({
el: $('#id-password-txt'),
type: 'text',
@ -200,7 +201,7 @@ define([
show: function() {
Common.UI.Window.prototype.show.apply(this, arguments);
if (this.type == Asc.c_oAscAdvancedOptionsID.DRM) {
if (this.type == Common.Utils.importTextType.DRM) {
var me = this;
setTimeout(function(){
me.inputPwd.cmpEl.find('input').focus();
@ -220,15 +221,15 @@ define([
_handleInput: function(state) {
if (this.handler) {
if (this.cmbEncoding) {
var encoding = (!this.cmbEncoding.isDisabled()) ? this.cmbEncoding.getValue() :
if (this.type == Common.Utils.importTextType.DRM) {
this.handler.call(this, state, this.inputPwd.getValue());
} else {
var encoding = (this.cmbEncoding && !this.cmbEncoding.isDisabled()) ? this.cmbEncoding.getValue() :
((this.settings && this.settings.asc_getCodePage()) ? this.settings.asc_getCodePage() : 0),
delimiter = this.cmbDelimiter ? this.cmbDelimiter.getValue() : null,
delimiterChar = (delimiter == -1) ? this.inputDelimiter.getValue() : null;
(delimiter == -1) && (delimiter = null);
this.handler.call(this, state, encoding, delimiter, delimiterChar);
} else {
this.handler.call(this, state, this.inputPwd.getValue());
}
}
@ -253,6 +254,7 @@ define([
}
length = encodedata.length;
if (length) {
for (i = 0; i < length; ++i) {
listItems.push({
value: encodedata[i][0],
@ -283,7 +285,6 @@ define([
itemsTemplate: itemsTemplate
});
if (length) {
this.cmbEncoding.setDisabled(false);
this.cmbEncoding.setValue((this.settings && this.settings.asc_getCodePage()) ? this.settings.asc_getCodePage() : encodedata[0][0]);
if (this.preview)
@ -295,7 +296,7 @@ define([
ul.find('li div').width(width);
}
if (this.type == Asc.c_oAscAdvancedOptionsID.CSV) {
if (this.type == Common.Utils.importTextType.CSV || this.type == Common.Utils.importTextType.Paste || this.type == Common.Utils.importTextType.Columns) {
this.cmbDelimiter = new Common.UI.ComboBox({
el: $('#id-delimiters-combo', this.$window),
style: 'width: 100px;',
@ -328,16 +329,23 @@ define([
},
updatePreview: function() {
var encoding = (!this.cmbEncoding.isDisabled()) ? this.cmbEncoding.getValue() :
var encoding = (this.cmbEncoding && !this.cmbEncoding.isDisabled()) ? this.cmbEncoding.getValue() :
((this.settings && this.settings.asc_getCodePage()) ? this.settings.asc_getCodePage() : 0);
if (this.type == Asc.c_oAscAdvancedOptionsID.CSV) {
var delimiter = this.cmbDelimiter ? this.cmbDelimiter.getValue() : null,
delimiterChar = (delimiter == -1) ? this.inputDelimiter.getValue() : null;
(delimiter == -1) && (delimiter = null);
switch (this.type) {
case Common.Utils.importTextType.CSV:
this.api.asc_decodeBuffer(this.preview, new Asc.asc_CCSVAdvancedOptions(encoding, delimiter, delimiterChar), _.bind(this.previewCallback, this));
} else {
break;
case Common.Utils.importTextType.TXT:
this.api.asc_decodeBuffer(this.preview, new Asc.asc_CTXTAdvancedOptions(encoding), _.bind(this.previewCallback, this));
break;
case Common.Utils.importTextType.Paste:
case Common.Utils.importTextType.Columns:
this.api.asc_TextImport(new Asc.asc_CCSVAdvancedOptions(encoding, delimiter, delimiterChar), _.bind(this.previewCallback, this), this.type == Common.Utils.importTextType.Paste);
break;
}
},
@ -379,7 +387,7 @@ define([
delete this.scrollerX;
}
if (this.type == Asc.c_oAscAdvancedOptionsID.CSV) {
if (this.type == Common.Utils.importTextType.CSV || this.type == Common.Utils.importTextType.Paste || this.type == Common.Utils.importTextType.Columns) {
var maxlength = 0;
for (var i=0; i<data.length; i++) {
if (data[i].length>maxlength)
@ -387,7 +395,7 @@ define([
}
var tpl = '<table>';
for (var i=0; i<data.length; i++) {
tpl += '<tr>';
tpl += '<tr style="vertical-align: top;">';
for (var j=0; j<data[i].length; j++) {
tpl += '<td>' + Common.Utils.String.htmlEncode(data[i][j]) + '</td>';
}
@ -400,7 +408,7 @@ define([
} else {
var tpl = '<table>';
for (var i=0; i<data.length; i++) {
tpl += '<tr><td>' + Common.Utils.String.htmlEncode(data[i]) + '</td></tr>';
tpl += '<tr style="vertical-align: top;"><td>' + Common.Utils.String.htmlEncode(data[i]) + '</td></tr>';
}
tpl += '</table>';
}

View file

@ -1947,8 +1947,9 @@ define([
me = this;
if (type == Asc.c_oAscAdvancedOptionsID.TXT) {
me._state.openDlg = new Common.Views.OpenDialog({
mode: mode,
type: type,
title: Common.Views.OpenDialog.prototype.txtTitle.replace('%1', 'TXT'),
closable: (mode==2), // if save settings
type: Common.Utils.importTextType.TXT,
preview: advOptions.asc_getOptions().asc_getData(),
codepages: advOptions.asc_getOptions().asc_getCodePages(),
settings: advOptions.asc_getOptions().asc_getRecommendedSettings(),
@ -1966,8 +1967,9 @@ define([
});
} else if (type == Asc.c_oAscAdvancedOptionsID.DRM) {
me._state.openDlg = new Common.Views.OpenDialog({
title: Common.Views.OpenDialog.prototype.txtTitleProtected,
closeFile: me.appOptions.canRequestClose,
type: type,
type: Common.Utils.importTextType.DRM,
warning: !(me.appOptions.isDesktopApp && me.appOptions.isOffline),
validatePwd: !!me._state.isDRM,
handler: function (result, value) {

View file

@ -1788,8 +1788,9 @@ define([
me = this;
if (type == Asc.c_oAscAdvancedOptionsID.DRM) {
me._state.openDlg = new Common.Views.OpenDialog({
title: Common.Views.OpenDialog.prototype.txtTitleProtected,
closeFile: me.appOptions.canRequestClose,
type: type,
type: Common.Utils.importTextType.DRM,
warning: !(me.appOptions.isDesktopApp && me.appOptions.isOffline),
validatePwd: !!me._state.isDRM,
handler: function (result, value) {

View file

@ -2184,9 +2184,23 @@ define([
caption: me._arrSpecialPaste[menuItem][0],
value: menuItem
}).on('click', function(item, e) {
(new Common.Views.OpenDialog({
title: me.txtImportWizard,
closable: true,
type: Common.Utils.importTextType.Paste,
preview: true,
api: me.api,
handler: function (result, encoding, delimiter, delimiterChar) {
if (result == 'ok') {
if (me && me.api) {
var props = new Asc.SpecialPasteProps();
props.asc_setProps(item.value);
props.asc_setProps(Asc.c_oSpecialPasteProps.useTextImport);
props.asc_setAdvancedOptions(new Asc.asc_CCSVAdvancedOptions(encoding, delimiter, delimiterChar));
me.api.asc_SpecialPaste(props);
}
}
}
})).show();
setTimeout(function(){menu.hide();}, 100);
});
} else {
@ -3237,7 +3251,8 @@ define([
txtEqualsToFontColor: 'Equals to font color',
txtAll: '(All)',
txtBlanks: '(Blanks)',
txtColumn: 'Column'
txtColumn: 'Column',
txtImportWizard: 'Text Import Wizard'
}, SSE.Controllers.DocumentHolder || {}));
});

View file

@ -1605,8 +1605,9 @@ define([
me = this;
if (type == Asc.c_oAscAdvancedOptionsID.CSV) {
me._state.openDlg = new Common.Views.OpenDialog({
mode: mode,
type: type,
title: Common.Views.OpenDialog.prototype.txtTitle.replace('%1', 'CSV'),
closable: (mode==2), // if save settings
type: Common.Utils.importTextType.CSV,
preview: advOptions.asc_getOptions().asc_getData(),
codepages: advOptions.asc_getOptions().asc_getCodePages(),
settings: advOptions.asc_getOptions().asc_getRecommendedSettings(),
@ -1624,8 +1625,9 @@ define([
});
} else if (type == Asc.c_oAscAdvancedOptionsID.DRM) {
me._state.openDlg = new Common.Views.OpenDialog({
title: Common.Views.OpenDialog.prototype.txtTitleProtected,
closeFile: me.appOptions.canRequestClose,
type: type,
type: Common.Utils.importTextType.DRM,
warning: !(me.appOptions.isDesktopApp && me.appOptions.isOffline),
validatePwd: !!me._state.isDRM,
handler: function (result, value) {

View file

@ -368,6 +368,9 @@
"SSE.Controllers.DocumentHolder.txtUnderbar": "Bar under text",
"SSE.Controllers.DocumentHolder.txtUndoExpansion": "Undo table autoexpansion",
"SSE.Controllers.DocumentHolder.txtWidth": "Width",
"SSE.Controllers.DocumentHolder.txtKeepTextOnly": "Keep text only",
"SSE.Controllers.DocumentHolder.txtUseTextImport": "Use text import wizard",
"SSE.Controllers.DocumentHolder.txtImportWizard": "Text Import Wizard",
"SSE.Controllers.LeftMenu.newDocumentTitle": "Unnamed spreadsheet",
"SSE.Controllers.LeftMenu.textByColumns": "By columns",
"SSE.Controllers.LeftMenu.textByRows": "By rows",