From 0f2e985634e8a2be7e1ae633551a300ca14bdb43 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 9 Feb 2018 17:26:34 +0300 Subject: [PATCH] Fix Bug 36742. --- apps/common/main/lib/view/OpenDialog.js | 99 ++++++++++++++++--- .../main/resources/less/opendialog.less | 13 +++ .../main/app/controller/Main.js | 2 + apps/documenteditor/main/locale/en.json | 1 + .../main/app/controller/Main.js | 2 + apps/spreadsheeteditor/main/locale/en.json | 1 + 6 files changed, 104 insertions(+), 14 deletions(-) diff --git a/apps/common/main/lib/view/OpenDialog.js b/apps/common/main/lib/view/OpenDialog.js index 462f7f0289..934cfce300 100644 --- a/apps/common/main/lib/view/OpenDialog.js +++ b/apps/common/main/lib/view/OpenDialog.js @@ -55,10 +55,10 @@ define([ _.extend(_options, { closable : false, - width : 250, - height : (options.type == Asc.c_oAscAdvancedOptionsID.CSV) ? 205 : 155, - contentWidth : 390, + width : (options.preview) ? 414 : 262, + height : (options.preview) ? 291 : ((options.type == Asc.c_oAscAdvancedOptionsID.CSV) ? 205 : 155), header : true, + preview : options.preview, 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'), @@ -73,14 +73,30 @@ define([ '', '
', '<% } else { %>', - '', - '
', - '<% if (type == Asc.c_oAscAdvancedOptionsID.CSV) { %>', - '', - '
', - '
', - '
', + '
', + '', + '
', + '
', + '
', '
', + '<% if (type == Asc.c_oAscAdvancedOptionsID.CSV) { %>', + '
', + '', + '
', + '
', + '
', + '
', + '
', + '<% } %>', + '<% if (!!preview) { %>', + '
', + '', + '<% if (type == Asc.c_oAscAdvancedOptionsID.CSV) { %>', + '
', + '<% } else { %>', + '
', + '<% } %>', + '
', '<% } %>', '<% } %>', '
', @@ -96,9 +112,11 @@ define([ this.handler = _options.handler; this.type = _options.type; + this.preview = _options.preview; this.closable = _options.closable; this.codepages = _options.codepages; this.settings = _options.settings; + this.api = _options.api; this.validatePwd = _options.validatePwd || false; _options.tpl = _.template(this.template)(_options); @@ -125,6 +143,7 @@ define([ this.$window.find('input').on('keypress', _.bind(this.onKeyPress, this)); } else { this.initCodePages(); + this.updatePreview(); } this.onPrimary = function() { me._handleInput('ok'); @@ -346,18 +365,22 @@ define([ this.cmbEncoding = new Common.UI.ComboBox({ el: $('#id-codepages-combo', this.$window), - menuStyle: 'min-width: 218px; max-height: 200px;', + style: 'width: 230px;', + menuStyle: 'min-width: 230px; max-height: 200px;', cls: 'input-group-nr', menuCls: 'scrollable-menu', data: listItems, editable: false }); this.cmbEncoding.setValue( (this.settings && this.settings.asc_getCodePage()) ? this.settings.asc_getCodePage() : encodedata[0][0]); + if (this.preview) + this.cmbEncoding.on('selected', _.bind(this.onCmbEncodingSelect, this)); if (this.type == Asc.c_oAscAdvancedOptionsID.CSV) { this.cmbDelimiter = new Common.UI.ComboBox({ el: $('#id-delimiters-combo', this.$window), - menuStyle: 'min-width: 110px;', + style: 'width: 100px;', + menuStyle: 'min-width: 100px;', cls: 'input-group-nr', data: [ {value: 4, displayValue: ','}, @@ -375,16 +398,63 @@ define([ el : $('#id-delimiter-other'), style : 'width: 30px;', maxLength: 1, + validateOnChange: true, + validateOnBlur: false, value: (this.settings && this.settings.asc_getDelimiterChar()) ? this.settings.asc_getDelimiterChar() : '' }); this.inputDelimiter.setVisible(false); - + if (this.preview) + this.inputDelimiter.on ('changing', _.bind(this.updatePreview, this)); } } }, + updatePreview: function() { + 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); + this.api.asc_decodeBuffer(this.preview, new Asc.asc_CCSVAdvancedOptions(this.cmbEncoding.getValue(), delimiter, delimiterChar), _.bind(this.previewCallback, this)); + } else { + this.api.asc_decodeBuffer(this.preview, new Asc.asc_CTXTAdvancedOptions(this.cmbEncoding.getValue()), _.bind(this.previewCallback, this)); + } + }, + + previewCallback: function(data) { + if (!data || !data.length) return; + + if (this.type == Asc.c_oAscAdvancedOptionsID.CSV) { + var maxlength = 0; + for (var i=0; imaxlength) + maxlength = data[i].length; + } + var tpl = ''; + for (var i=0; i'; + } + for (j=data[i].length; j