Merge pull request #158 from ONLYOFFICE/feature/paste-import

Feature/paste import
This commit is contained in:
Julia Radzhabova 2019-04-18 14:30:03 +03:00 committed by GitHub
commit 925af696f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 244 additions and 101 deletions

View file

@ -106,6 +106,13 @@ Common.Utils = _.extend(new(function() {
Pivot : 10, Pivot : 10,
Cell : 11 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), 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, me = this,
checkSize = function() { checkSize = function() {
@ -203,6 +210,7 @@ Common.Utils = _.extend(new(function() {
ipStrongRe: ipStrongRe, ipStrongRe: ipStrongRe,
hostnameStrongRe: hostnameStrongRe, hostnameStrongRe: hostnameStrongRe,
documentSettingsType: documentSettingsType, documentSettingsType: documentSettingsType,
importTextType: importTextType,
zoom: function() {return me.zoom;}, zoom: function() {return me.zoom;},
innerWidth: function() {return me.innerWidth;}, innerWidth: function() {return me.innerWidth;},
innerHeight: function() {return me.innerHeight;} innerHeight: function() {return me.innerHeight;}

View file

@ -59,21 +59,20 @@ define([
width = 414; width = 414;
height = 277; height = 277;
} else { } else {
width = (options.type !== Asc.c_oAscAdvancedOptionsID.DRM) ? 340 : (options.warning ? 370 : 262); width = (options.type !== Common.Utils.importTextType.DRM) ? 340 : (options.warning ? 370 : 262);
height = (options.type == Asc.c_oAscAdvancedOptionsID.CSV) ? 190 : (options.warning ? 187 : 147); 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, { _.extend(_options, {
mode : 1, // open settings closable : false, // true if save settings
closable : (options.mode==2), // if save settings
preview : options.preview, preview : options.preview,
warning : options.warning, warning : options.warning,
codepages : options.codepages,
width : width, width : width,
height : height, height : height,
header : true, header : true,
cls : 'open-dlg', cls : 'open-dlg',
contentTemplate : '', 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), toolcallback : _.bind(t.onToolClose, t),
closeFile : false closeFile : false
@ -82,7 +81,7 @@ define([
this.template = options.template || [ this.template = options.template || [
'<div class="box" style="height:' + (_options.height - 85) + 'px;">', '<div class="box" style="height:' + (_options.height - 85) + 'px;">',
'<div class="content-panel" >', '<div class="content-panel" >',
'<% if (type == Asc.c_oAscAdvancedOptionsID.DRM) { %>', '<% if (type == Common.Utils.importTextType.DRM) { %>',
'<% if (warning) { %>', '<% if (warning) { %>',
'<div>', '<div>',
'<div class="icon img-commonctrl warn"/>', '<div class="icon img-commonctrl warn"/>',
@ -97,13 +96,15 @@ define([
'</div>', '</div>',
'<% } %>', '<% } %>',
'<% } else { %>', '<% } 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>', '<label class="header">' + t.txtEncoding + '</label>',
'<div>', '<div>',
'<div id="id-codepages-combo" class="input-group-nr" style="width: 100%; display: inline-block; vertical-align: middle;"></div>', '<div id="id-codepages-combo" class="input-group-nr" style="width: 100%; display: inline-block; vertical-align: middle;"></div>',
'</div>', '</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;">', '<div style="display: inline-block; margin-bottom:15px;">',
'<label class="header">' + t.txtDelimiter + '</label>', '<label class="header">' + t.txtDelimiter + '</label>',
'<div>', '<div>',
@ -143,6 +144,7 @@ define([
this.handler = _options.handler; this.handler = _options.handler;
this.type = _options.type; this.type = _options.type;
this.preview = _options.preview; this.preview = _options.preview;
this.previewData = _options.previewData;
this.warning = _options.warning || false; this.warning = _options.warning || false;
this.closable = _options.closable; this.closable = _options.closable;
this.codepages = _options.codepages; this.codepages = _options.codepages;
@ -168,7 +170,7 @@ define([
this.previewScrolled = this.$window.find('#id-preview'); this.previewScrolled = this.$window.find('#id-preview');
this.previewInner = this.previewScrolled.find('div:first-child'); 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({ this.inputPwd = new Common.UI.InputField({
el: $('#id-password-txt'), el: $('#id-password-txt'),
type: 'text', type: 'text',
@ -187,8 +189,9 @@ define([
}); });
} else { } else {
this.initCodePages(); this.initCodePages();
if (this.preview) if (this.preview) {
this.updatePreview(); (this.previewData) ? this.previewCallback(this.previewData) : this.updatePreview();
}
} }
this.onPrimary = function() { this.onPrimary = function() {
me._handleInput('ok'); me._handleInput('ok');
@ -200,7 +203,7 @@ define([
show: function() { show: function() {
Common.UI.Window.prototype.show.apply(this, arguments); 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; var me = this;
setTimeout(function(){ setTimeout(function(){
me.inputPwd.cmpEl.find('input').focus(); me.inputPwd.cmpEl.find('input').focus();
@ -220,15 +223,15 @@ define([
_handleInput: function(state) { _handleInput: function(state) {
if (this.handler) { if (this.handler) {
if (this.cmbEncoding) { if (this.type == Common.Utils.importTextType.DRM) {
var encoding = (!this.cmbEncoding.isDisabled()) ? this.cmbEncoding.getValue() : this.handler.call(this, state, this.inputPwd.getValue());
((this.settings && this.settings.asc_getCodePage()) ? this.settings.asc_getCodePage() : 0), } 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, delimiter = this.cmbDelimiter ? this.cmbDelimiter.getValue() : null,
delimiterChar = (delimiter == -1) ? this.inputDelimiter.getValue() : null; delimiterChar = (delimiter == -1) ? this.inputDelimiter.getValue() : null;
(delimiter == -1) && (delimiter = null); (delimiter == -1) && (delimiter = null);
this.handler.call(this, state, encoding, delimiter, delimiterChar); this.handler.call(this, state, encoding, delimiter, delimiterChar);
} else {
this.handler.call(this, state, this.inputPwd.getValue());
} }
} }
@ -253,37 +256,37 @@ define([
} }
length = encodedata.length; length = encodedata.length;
for (i = 0; i < length; ++i) { if (length) {
listItems.push({ for (i = 0; i < length; ++i) {
value: encodedata[i][0], listItems.push({
displayValue: Common.Utils.String.htmlEncode(encodedata[i][1]), value: encodedata[i][0],
lcid: encodedata[i][2] || '' displayValue: Common.Utils.String.htmlEncode(encodedata[i][1]),
}); lcid: encodedata[i][2] || ''
} });
}
var itemsTemplate = var itemsTemplate =
_.template([ _.template([
'<% _.each(items, function(item) { %>', '<% _.each(items, function(item) { %>',
'<li id="<%= item.id %>" data-value="<%= item.value %>"><a tabindex="-1" type="menuitem">', '<li id="<%= item.id %>" data-value="<%= item.value %>"><a tabindex="-1" type="menuitem">',
'<div style="display: inline-block;"><%= item.displayValue %></div>', '<div style="display: inline-block;"><%= item.displayValue %></div>',
'<label style="text-align: right;width:' + lcid_width + 'px;"><%= item.lcid %></label>', '<label style="text-align: right;width:' + lcid_width + 'px;"><%= item.lcid %></label>',
'</a></li>', '</a></li>',
'<% }); %>' '<% }); %>'
].join('')); ].join(''));
this.cmbEncoding = new Common.UI.ComboBox({ this.cmbEncoding = new Common.UI.ComboBox({
el: $('#id-codepages-combo', this.$window), el: $('#id-codepages-combo', this.$window),
style: 'width: 100%;', style: 'width: 100%;',
menuStyle: 'min-width: 100%; max-height: 200px;', menuStyle: 'min-width: 100%; max-height: 200px;',
cls: 'input-group-nr', cls: 'input-group-nr',
menuCls: 'scrollable-menu', menuCls: 'scrollable-menu',
data: listItems, data: listItems,
editable: false, editable: false,
disabled: true, disabled: true,
itemsTemplate: itemsTemplate itemsTemplate: itemsTemplate
}); });
if (length) {
this.cmbEncoding.setDisabled(false); this.cmbEncoding.setDisabled(false);
this.cmbEncoding.setValue((this.settings && this.settings.asc_getCodePage()) ? this.settings.asc_getCodePage() : encodedata[0][0]); this.cmbEncoding.setValue((this.settings && this.settings.asc_getCodePage()) ? this.settings.asc_getCodePage() : encodedata[0][0]);
if (this.preview) if (this.preview)
@ -295,7 +298,7 @@ define([
ul.find('li div').width(width); 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({ this.cmbDelimiter = new Common.UI.ComboBox({
el: $('#id-delimiters-combo', this.$window), el: $('#id-delimiters-combo', this.$window),
style: 'width: 100px;', style: 'width: 100px;',
@ -328,16 +331,23 @@ define([
}, },
updatePreview: function() { 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); ((this.settings && this.settings.asc_getCodePage()) ? this.settings.asc_getCodePage() : 0);
var delimiter = this.cmbDelimiter ? this.cmbDelimiter.getValue() : null,
delimiterChar = (delimiter == -1) ? this.inputDelimiter.getValue() : null;
(delimiter == -1) && (delimiter = null);
if (this.type == Asc.c_oAscAdvancedOptionsID.CSV) { switch (this.type) {
var delimiter = this.cmbDelimiter ? this.cmbDelimiter.getValue() : null, case Common.Utils.importTextType.CSV:
delimiterChar = (delimiter == -1) ? this.inputDelimiter.getValue() : null; this.api.asc_decodeBuffer(this.preview, new Asc.asc_CCSVAdvancedOptions(encoding, delimiter, delimiterChar), _.bind(this.previewCallback, this));
(delimiter == -1) && (delimiter = null); break;
this.api.asc_decodeBuffer(this.preview, new Asc.asc_CCSVAdvancedOptions(encoding, delimiter, delimiterChar), _.bind(this.previewCallback, this)); case Common.Utils.importTextType.TXT:
} else { this.api.asc_decodeBuffer(this.preview, new Asc.asc_CTXTAdvancedOptions(encoding), _.bind(this.previewCallback, this));
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 +389,7 @@ define([
delete this.scrollerX; 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; var maxlength = 0;
for (var i=0; i<data.length; i++) { for (var i=0; i<data.length; i++) {
if (data[i].length>maxlength) if (data[i].length>maxlength)
@ -387,7 +397,7 @@ define([
} }
var tpl = '<table>'; var tpl = '<table>';
for (var i=0; i<data.length; i++) { 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++) { for (var j=0; j<data[i].length; j++) {
tpl += '<td>' + Common.Utils.String.htmlEncode(data[i][j]) + '</td>'; tpl += '<td>' + Common.Utils.String.htmlEncode(data[i][j]) + '</td>';
} }
@ -400,7 +410,7 @@ define([
} else { } else {
var tpl = '<table>'; var tpl = '<table>';
for (var i=0; i<data.length; i++) { 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>'; tpl += '</table>';
} }

View file

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

View file

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

View file

@ -45,6 +45,7 @@ define([
'common/main/lib/util/utils', 'common/main/lib/util/utils',
'common/main/lib/util/Shortcuts', 'common/main/lib/util/Shortcuts',
'common/main/lib/view/CopyWarningDialog', 'common/main/lib/view/CopyWarningDialog',
'common/main/lib/view/OpenDialog',
'spreadsheeteditor/main/app/view/DocumentHolder', 'spreadsheeteditor/main/app/view/DocumentHolder',
'spreadsheeteditor/main/app/view/HyperlinkSettingsDialog', 'spreadsheeteditor/main/app/view/HyperlinkSettingsDialog',
'spreadsheeteditor/main/app/view/ParagraphSettingsAdvanced', 'spreadsheeteditor/main/app/view/ParagraphSettingsAdvanced',
@ -2135,23 +2136,25 @@ define([
// Prepare menu container // Prepare menu container
if (pasteContainer.length < 1) { if (pasteContainer.length < 1) {
me._arrSpecialPaste = []; me._arrSpecialPaste = [];
me._arrSpecialPaste[Asc.c_oSpecialPasteProps.paste] = me.txtPaste; me._arrSpecialPaste[Asc.c_oSpecialPasteProps.paste] = [me.txtPaste, 0];
me._arrSpecialPaste[Asc.c_oSpecialPasteProps.pasteOnlyFormula] = me.txtPasteFormulas; me._arrSpecialPaste[Asc.c_oSpecialPasteProps.pasteOnlyFormula] = [me.txtPasteFormulas, 0];
me._arrSpecialPaste[Asc.c_oSpecialPasteProps.formulaNumberFormat] = me.txtPasteFormulaNumFormat; me._arrSpecialPaste[Asc.c_oSpecialPasteProps.formulaNumberFormat] = [me.txtPasteFormulaNumFormat, 0];
me._arrSpecialPaste[Asc.c_oSpecialPasteProps.formulaAllFormatting] = me.txtPasteKeepSourceFormat; me._arrSpecialPaste[Asc.c_oSpecialPasteProps.formulaAllFormatting] = [me.txtPasteKeepSourceFormat, 0];
me._arrSpecialPaste[Asc.c_oSpecialPasteProps.formulaWithoutBorders] = me.txtPasteBorders; me._arrSpecialPaste[Asc.c_oSpecialPasteProps.formulaWithoutBorders] = [me.txtPasteBorders, 0];
me._arrSpecialPaste[Asc.c_oSpecialPasteProps.formulaColumnWidth] = me.txtPasteColWidths; me._arrSpecialPaste[Asc.c_oSpecialPasteProps.formulaColumnWidth] = [me.txtPasteColWidths, 0];
me._arrSpecialPaste[Asc.c_oSpecialPasteProps.mergeConditionalFormating] = me.txtPasteMerge; me._arrSpecialPaste[Asc.c_oSpecialPasteProps.mergeConditionalFormating] = [me.txtPasteMerge, 0];
me._arrSpecialPaste[Asc.c_oSpecialPasteProps.pasteOnlyValues] = me.txtPasteValues; me._arrSpecialPaste[Asc.c_oSpecialPasteProps.transpose] = [me.txtPasteTranspose, 0];
me._arrSpecialPaste[Asc.c_oSpecialPasteProps.valueNumberFormat] = me.txtPasteValNumFormat; me._arrSpecialPaste[Asc.c_oSpecialPasteProps.pasteOnlyValues] = [me.txtPasteValues, 1];
me._arrSpecialPaste[Asc.c_oSpecialPasteProps.valueAllFormating] = me.txtPasteValFormat; me._arrSpecialPaste[Asc.c_oSpecialPasteProps.valueNumberFormat] = [me.txtPasteValNumFormat, 1];
me._arrSpecialPaste[Asc.c_oSpecialPasteProps.pasteOnlyFormating] = me.txtPasteFormat; me._arrSpecialPaste[Asc.c_oSpecialPasteProps.valueAllFormating] = [me.txtPasteValFormat, 1];
me._arrSpecialPaste[Asc.c_oSpecialPasteProps.transpose] = me.txtPasteTranspose; me._arrSpecialPaste[Asc.c_oSpecialPasteProps.pasteOnlyFormating] = [me.txtPasteFormat, 2];
me._arrSpecialPaste[Asc.c_oSpecialPasteProps.link] = me.txtPasteLink; me._arrSpecialPaste[Asc.c_oSpecialPasteProps.link] = [me.txtPasteLink, 2];
me._arrSpecialPaste[Asc.c_oSpecialPasteProps.picture] = me.txtPastePicture; me._arrSpecialPaste[Asc.c_oSpecialPasteProps.picture] = [me.txtPastePicture, 2];
me._arrSpecialPaste[Asc.c_oSpecialPasteProps.linkedPicture] = me.txtPasteLinkPicture; me._arrSpecialPaste[Asc.c_oSpecialPasteProps.linkedPicture] = [me.txtPasteLinkPicture, 2];
me._arrSpecialPaste[Asc.c_oSpecialPasteProps.sourceformatting] = me.txtPasteSourceFormat; me._arrSpecialPaste[Asc.c_oSpecialPasteProps.sourceformatting] = [me.txtPasteSourceFormat, 2];
me._arrSpecialPaste[Asc.c_oSpecialPasteProps.destinationFormatting] = me.txtPasteDestFormat; me._arrSpecialPaste[Asc.c_oSpecialPasteProps.destinationFormatting] = [me.txtPasteDestFormat, 2];
me._arrSpecialPaste[Asc.c_oSpecialPasteProps.keepTextOnly] = [me.txtKeepTextOnly, 2];
me._arrSpecialPaste[Asc.c_oSpecialPasteProps.useTextImport] = [me.txtUseTextImport, 3];
pasteContainer = $('<div id="special-paste-container" style="position: absolute;"><div id="id-document-holder-btn-special-paste"></div></div>'); pasteContainer = $('<div id="special-paste-container" style="position: absolute;"><div id="id-document-holder-btn-special-paste"></div></div>');
documentHolderView.cmpEl.append(pasteContainer); documentHolderView.cmpEl.append(pasteContainer);
@ -2170,28 +2173,78 @@ define([
menu.removeItem(menu.items[i]); menu.removeItem(menu.items[i]);
i--; i--;
} }
var groups = [];
for (var i = 0; i < 3; i++) {
groups[i] = [];
}
var group_prev = -1; var importText;
_.each(pasteItems, function(menuItem, index) { _.each(pasteItems, function(menuItem, index) {
var group = (menuItem<7) ? 0 : (menuItem>9 ? 2 : 1); if (menuItem == Asc.c_oSpecialPasteProps.useTextImport) {
if (group_prev !== group && group_prev>=0) importText = new Common.UI.MenuItem({
menu.addItem(new Common.UI.MenuItem({ caption: '--' })); caption: me._arrSpecialPaste[menuItem][0],
group_prev = group; value: menuItem,
checkable: true,
toggleGroup : 'specialPasteGroup'
}).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(Asc.c_oSpecialPasteProps.useTextImport);
props.asc_setAdvancedOptions(new Asc.asc_CCSVAdvancedOptions(encoding, delimiter, delimiterChar));
me.api.asc_SpecialPaste(props);
}
me._state.lastSpecPasteChecked = item;
} else {
item.setChecked(false, true);
me._state.lastSpecPasteChecked && me._state.lastSpecPasteChecked.setChecked(true, true);
}
}
})).show();
setTimeout(function(){menu.hide();}, 100);
});
} else {
var mnu = new Common.UI.MenuItem({
caption: me._arrSpecialPaste[menuItem][0],
value: menuItem,
checkable: true,
toggleGroup : 'specialPasteGroup'
}).on('click', function(item, e) {
me._state.lastSpecPasteChecked = item;
var mnu = new Common.UI.MenuItem({ var props = new Asc.SpecialPasteProps();
caption: me._arrSpecialPaste[menuItem], props.asc_setProps(item.value);
value: menuItem, me.api.asc_SpecialPaste(props);
checkable: true, setTimeout(function(){menu.hide();}, 100);
toggleGroup : 'specialPasteGroup' });
}).on('click', function(item, e) { groups[me._arrSpecialPaste[menuItem][1]].push(mnu);
var props = new Asc.SpecialPasteProps(); }
props.asc_setProps(item.value);
me.api.asc_SpecialPaste(props);
setTimeout(function(){menu.hide();}, 100);
});
menu.addItem(mnu);
}); });
var newgroup = false;
for (var i = 0; i < 3; i++) {
if (newgroup && groups[i].length>0) {
menu.addItem(new Common.UI.MenuItem({ caption: '--' }));
newgroup = false;
}
_.each(groups[i], function(menuItem, index) {
menu.addItem(menuItem);
newgroup = true;
});
}
(menu.items.length>0) && menu.items[0].setChecked(true, true); (menu.items.length>0) && menu.items[0].setChecked(true, true);
me._state.lastSpecPasteChecked = (menu.items.length>0) ? menu.items[0] : null;
if (importText) {
menu.addItem(new Common.UI.MenuItem({ caption: '--' }));
menu.addItem(importText);
}
} }
if ( coord[0].asc_getX()<0 || coord[0].asc_getY()<0) { if ( coord[0].asc_getX()<0 || coord[0].asc_getY()<0) {
@ -3180,6 +3233,8 @@ define([
txtPasteLinkPicture: 'Linked Picture', txtPasteLinkPicture: 'Linked Picture',
txtPasteSourceFormat: 'Source formatting', txtPasteSourceFormat: 'Source formatting',
txtPasteDestFormat: 'Destination formatting', txtPasteDestFormat: 'Destination formatting',
txtKeepTextOnly: 'Keep text only',
txtUseTextImport: 'Use text import wizard',
txtUndoExpansion: 'Undo table autoexpansion', txtUndoExpansion: 'Undo table autoexpansion',
txtRedoExpansion: 'Redo table autoexpansion', txtRedoExpansion: 'Redo table autoexpansion',
txtAnd: 'and', txtAnd: 'and',
@ -3206,7 +3261,8 @@ define([
txtEqualsToFontColor: 'Equals to font color', txtEqualsToFontColor: 'Equals to font color',
txtAll: '(All)', txtAll: '(All)',
txtBlanks: '(Blanks)', txtBlanks: '(Blanks)',
txtColumn: 'Column' txtColumn: 'Column',
txtImportWizard: 'Text Import Wizard'
}, SSE.Controllers.DocumentHolder || {})); }, SSE.Controllers.DocumentHolder || {}));
}); });

View file

@ -1365,6 +1365,10 @@ define([
config.msg = this.errorEmailClient; config.msg = this.errorEmailClient;
break; break;
case Asc.c_oAscError.ID.NoDataToParse:
config.msg = this.errorNoDataToParse;
break;
default: default:
config.msg = (typeof id == 'string') ? id : this.errorDefaultMessage.replace('%1', id); config.msg = (typeof id == 'string') ? id : this.errorDefaultMessage.replace('%1', id);
break; break;
@ -1605,8 +1609,9 @@ define([
me = this; me = this;
if (type == Asc.c_oAscAdvancedOptionsID.CSV) { if (type == Asc.c_oAscAdvancedOptionsID.CSV) {
me._state.openDlg = new Common.Views.OpenDialog({ me._state.openDlg = new Common.Views.OpenDialog({
mode: mode, title: Common.Views.OpenDialog.prototype.txtTitle.replace('%1', 'CSV'),
type: type, closable: (mode==2), // if save settings
type: Common.Utils.importTextType.CSV,
preview: advOptions.asc_getOptions().asc_getData(), preview: advOptions.asc_getOptions().asc_getData(),
codepages: advOptions.asc_getOptions().asc_getCodePages(), codepages: advOptions.asc_getOptions().asc_getCodePages(),
settings: advOptions.asc_getOptions().asc_getRecommendedSettings(), settings: advOptions.asc_getOptions().asc_getRecommendedSettings(),
@ -1624,8 +1629,9 @@ define([
}); });
} else if (type == Asc.c_oAscAdvancedOptionsID.DRM) { } else if (type == Asc.c_oAscAdvancedOptionsID.DRM) {
me._state.openDlg = new Common.Views.OpenDialog({ me._state.openDlg = new Common.Views.OpenDialog({
title: Common.Views.OpenDialog.prototype.txtTitleProtected,
closeFile: me.appOptions.canRequestClose, closeFile: me.appOptions.canRequestClose,
type: type, type: Common.Utils.importTextType.DRM,
warning: !(me.appOptions.isDesktopApp && me.appOptions.isOffline), warning: !(me.appOptions.isDesktopApp && me.appOptions.isOffline),
validatePwd: !!me._state.isDRM, validatePwd: !!me._state.isDRM,
handler: function (result, value) { handler: function (result, value) {
@ -2493,7 +2499,8 @@ define([
errorEmailClient: 'No email client could be found', errorEmailClient: 'No email client could be found',
txtPrintArea: 'Print_Area', txtPrintArea: 'Print_Area',
txtTable: 'Table', txtTable: 'Table',
textCustomLoader: 'Please note that according to the terms of the license you are not entitled to change the loader.<br>Please contact our Sales Department to get a quote.' textCustomLoader: 'Please note that according to the terms of the license you are not entitled to change the loader.<br>Please contact our Sales Department to get a quote.',
errorNoDataToParse: 'No data was selected to parse.'
} }
})(), SSE.Controllers.Main || {})) })(), SSE.Controllers.Main || {}))
}); });

View file

@ -60,5 +60,15 @@
<div id="cell-spin-angle" style="display: inline-block;margin-left:5px;"></div> <div id="cell-spin-angle" style="display: inline-block;margin-left:5px;"></div>
</td> </td>
</tr> </tr>
<tr>
<td class="padding-small" colspan=2>
<div class="separator horizontal"></div>
</td>
</tr>
<tr>
<td class="padding-small" colspan=2>
<button type="button" class="btn btn-text-default" id="cell-btn-text-to-column" style="width:100%;"><%= scope.textTextToColumn %></button>
</td>
</tr>
<tr class="finish-cell"></tr> <tr class="finish-cell"></tr>
</table> </table>

View file

@ -46,7 +46,8 @@ define([
'common/main/lib/component/Button', 'common/main/lib/component/Button',
'common/main/lib/component/ThemeColorPalette', 'common/main/lib/component/ThemeColorPalette',
'common/main/lib/component/ColorButton', 'common/main/lib/component/ColorButton',
'common/main/lib/component/ComboBorderSize' 'common/main/lib/component/ComboBorderSize',
'common/main/lib/view/OpenDialog'
], function (menuTemplate, $, _, Backbone) { ], function (menuTemplate, $, _, Backbone) {
'use strict'; 'use strict';
@ -70,11 +71,13 @@ define([
this._state = { this._state = {
BackColor: undefined, BackColor: undefined,
DisabledControls: true, DisabledControls: true,
CellAngle: undefined CellAngle: undefined,
CSVOptions: new Asc.asc_CCSVAdvancedOptions(0, 4, '')
}; };
this.lockedControls = []; this.lockedControls = [];
this._locked = true; this._locked = true;
this.isEditCell = false; this.isEditCell = false;
this.isMultiSelect = false;
this.BorderType = 1; this.BorderType = 1;
this.render(); this.render();
@ -138,6 +141,32 @@ define([
this.api && this.api.asc_setCellAngle(field.getNumberValue()); this.api && this.api.asc_setCellAngle(field.getNumberValue());
}, },
onTextToColumn: function() {
this.api.asc_TextImport(this._state.CSVOptions, _.bind(this.onTextToColumnCallback, this), false);
},
onTextToColumnCallback: function(data) {
if (!data || !data.length) return;
var me = this;
(new Common.Views.OpenDialog({
title: me.textWizard,
closable: true,
type: Common.Utils.importTextType.Columns,
preview: true,
previewData: data,
settings: this._state.CSVOptions,
api: me.api,
handler: function (result, encoding, delimiter, delimiterChar) {
if (result == 'ok') {
if (me && me.api) {
me.api.asc_TextToColumns(new Asc.asc_CCSVAdvancedOptions(encoding, delimiter, delimiterChar));
}
}
}
})).show();
},
render: function () { render: function () {
var el = $(this.el); var el = $(this.el);
el.html(this.template({ el.html(this.template({
@ -149,6 +178,7 @@ define([
this.api = o; this.api = o;
if (o) { if (o) {
this.api.asc_registerCallback('asc_onEditCell', this.onApiEditCell.bind(this)); this.api.asc_registerCallback('asc_onEditCell', this.onApiEditCell.bind(this));
this.api.asc_registerCallback('asc_onSelectionChanged', _.bind(this.onApiSelectionChanged, this));
} }
return this; return this;
}, },
@ -236,6 +266,12 @@ define([
}); });
this.lockedControls.push(this.spnAngle); this.lockedControls.push(this.spnAngle);
this.spnAngle.on('change', _.bind(this.onAngleChange, this)); this.spnAngle.on('change', _.bind(this.onAngleChange, this));
this.btnTextToColumn = new Common.UI.Button({
el: $('#cell-btn-text-to-column')
});
this.btnTextToColumn.on('click', _.bind(this.onTextToColumn, this));
this.lockedControls.push(this.btnTextToColumn);
}, },
createDelayedElements: function() { createDelayedElements: function() {
@ -333,6 +369,10 @@ define([
this.disableControls(this._locked); this.disableControls(this._locked);
}, },
onApiSelectionChanged: function(info) {
this.isMultiSelect = info.asc_getFlags().asc_getMultiselect() || info.asc_getSelectedColsCount()>1;
},
setLocked: function (locked) { setLocked: function (locked) {
this._locked = locked; this._locked = locked;
}, },
@ -347,6 +387,7 @@ define([
item.setDisabled(disable); item.setDisabled(disable);
}); });
} }
this.btnTextToColumn.setDisabled(disable || this.isMultiSelect);
}, },
textBorders: 'Border\'s Style', textBorders: 'Border\'s Style',
@ -367,7 +408,9 @@ define([
tipDiagU: 'Set Diagonal Up Border', tipDiagU: 'Set Diagonal Up Border',
tipDiagD: 'Set Diagonal Down Border', tipDiagD: 'Set Diagonal Down Border',
textOrientation: 'Text Orientation', textOrientation: 'Text Orientation',
textAngle: 'Angle' textAngle: 'Angle',
textTextToColumn: 'Text to Columns',
textWizard: 'Text to Columns Wizard'
}, SSE.Views.CellSettings || {})); }, SSE.Views.CellSettings || {}));
}); });

View file

@ -371,6 +371,9 @@
"SSE.Controllers.DocumentHolder.txtUndoExpansion": "Undo table autoexpansion", "SSE.Controllers.DocumentHolder.txtUndoExpansion": "Undo table autoexpansion",
"SSE.Controllers.DocumentHolder.txtUseTextImport": "Use text import wizard", "SSE.Controllers.DocumentHolder.txtUseTextImport": "Use text import wizard",
"SSE.Controllers.DocumentHolder.txtWidth": "Width", "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.newDocumentTitle": "Unnamed spreadsheet",
"SSE.Controllers.LeftMenu.textByColumns": "By columns", "SSE.Controllers.LeftMenu.textByColumns": "By columns",
"SSE.Controllers.LeftMenu.textByRows": "By rows", "SSE.Controllers.LeftMenu.textByRows": "By rows",
@ -726,6 +729,7 @@
"SSE.Controllers.Main.warnNoLicense": "This version of ONLYOFFICE Editors has certain limitations for concurrent connections to the document server.<br>If you need more please consider purchasing a commercial license.", "SSE.Controllers.Main.warnNoLicense": "This version of ONLYOFFICE Editors has certain limitations for concurrent connections to the document server.<br>If you need more please consider purchasing a commercial license.",
"SSE.Controllers.Main.warnNoLicenseUsers": "This version of ONLYOFFICE Editors has certain limitations for concurrent users.<br>If you need more please consider purchasing a commercial license.", "SSE.Controllers.Main.warnNoLicenseUsers": "This version of ONLYOFFICE Editors has certain limitations for concurrent users.<br>If you need more please consider purchasing a commercial license.",
"SSE.Controllers.Main.warnProcessRightsChange": "You have been denied the right to edit the file.", "SSE.Controllers.Main.warnProcessRightsChange": "You have been denied the right to edit the file.",
"SSE.Controllers.Main.errorNoDataToParse": "No data was selected to parse.",
"SSE.Controllers.Print.strAllSheets": "All Sheets", "SSE.Controllers.Print.strAllSheets": "All Sheets",
"SSE.Controllers.Print.textWarning": "Warning", "SSE.Controllers.Print.textWarning": "Warning",
"SSE.Controllers.Print.txtCustom": "Custom", "SSE.Controllers.Print.txtCustom": "Custom",
@ -1148,6 +1152,8 @@
"SSE.Views.CellSettings.tipOuter": "Set outer border only", "SSE.Views.CellSettings.tipOuter": "Set outer border only",
"SSE.Views.CellSettings.tipRight": "Set outer right border only", "SSE.Views.CellSettings.tipRight": "Set outer right border only",
"SSE.Views.CellSettings.tipTop": "Set outer top border only", "SSE.Views.CellSettings.tipTop": "Set outer top border only",
"SSE.Views.CellSettings.textTextToColumn": "Text to Columns",
"SSE.Views.CellSettings.textWizard": "Text to Columns Wizard",
"SSE.Views.ChartSettings.strLineWeight": "Line Weight", "SSE.Views.ChartSettings.strLineWeight": "Line Weight",
"SSE.Views.ChartSettings.strSparkColor": "Color", "SSE.Views.ChartSettings.strSparkColor": "Color",
"SSE.Views.ChartSettings.strTemplate": "Template", "SSE.Views.ChartSettings.strTemplate": "Template",