2016-04-01 13:17:09 +00:00
|
|
|
/*
|
|
|
|
*
|
2019-01-17 13:05:03 +00:00
|
|
|
* (c) Copyright Ascensio System SIA 2010-2019
|
2016-04-01 13:17:09 +00:00
|
|
|
*
|
|
|
|
* This program is a free software product. You can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
|
|
|
* version 3 as published by the Free Software Foundation. In accordance with
|
|
|
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
|
|
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
|
|
|
* of any third-party rights.
|
|
|
|
*
|
|
|
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
|
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
|
|
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
|
|
|
*
|
2019-01-17 13:00:34 +00:00
|
|
|
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
|
|
|
* street, Riga, Latvia, EU, LV-1050.
|
2016-04-01 13:17:09 +00:00
|
|
|
*
|
|
|
|
* The interactive user interfaces in modified source and object code versions
|
|
|
|
* of the Program must display Appropriate Legal Notices, as required under
|
|
|
|
* Section 5 of the GNU AGPL version 3.
|
|
|
|
*
|
|
|
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
|
|
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
|
|
|
* grant you any rights under trademark law for use of our trademarks.
|
|
|
|
*
|
|
|
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
|
|
|
* well as technical writing content are licensed under the terms of the
|
|
|
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
|
|
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
|
|
|
*
|
|
|
|
*/
|
2016-03-11 00:48:53 +00:00
|
|
|
/**
|
|
|
|
* OpenDialog.js
|
|
|
|
*
|
|
|
|
* Select Codepage for open CSV/TXT format file.
|
|
|
|
*
|
|
|
|
* Created by Alexey.Musinov on 29/04/14
|
2018-03-01 12:16:38 +00:00
|
|
|
* Copyright (c) 2018 Ascensio System SIA. All rights reserved.
|
2016-03-11 00:48:53 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
define([
|
|
|
|
'common/main/lib/component/Window'
|
|
|
|
], function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
Common.Views.OpenDialog = Common.UI.Window.extend(_.extend({
|
|
|
|
|
|
|
|
applyFunction: undefined,
|
|
|
|
|
|
|
|
initialize : function (options) {
|
|
|
|
var t = this,
|
|
|
|
_options = {};
|
|
|
|
|
2018-07-24 12:29:53 +00:00
|
|
|
var width, height;
|
|
|
|
|
|
|
|
if (options.preview) {
|
|
|
|
width = 414;
|
|
|
|
height = 277;
|
|
|
|
} else {
|
2020-03-26 10:03:25 +00:00
|
|
|
width = (options.type !== Common.Utils.importTextType.DRM) ? 340 : (options.warning ? 420 : 262);
|
2019-04-17 09:01:20 +00:00
|
|
|
height = (options.type == Common.Utils.importTextType.CSV || options.type == Common.Utils.importTextType.Paste || options.type == Common.Utils.importTextType.Columns) ? 190 : (options.warning ? 187 : 147);
|
2018-07-24 12:29:53 +00:00
|
|
|
}
|
|
|
|
|
2016-03-11 00:48:53 +00:00
|
|
|
_.extend(_options, {
|
2019-04-17 09:01:20 +00:00
|
|
|
closable : false, // true if save settings
|
2018-02-09 14:26:34 +00:00
|
|
|
preview : options.preview,
|
2018-04-28 11:13:52 +00:00
|
|
|
warning : options.warning,
|
2019-04-17 09:01:20 +00:00
|
|
|
codepages : options.codepages,
|
2018-07-24 12:29:53 +00:00
|
|
|
width : width,
|
|
|
|
height : height,
|
2018-04-28 11:13:52 +00:00
|
|
|
header : true,
|
2016-03-11 00:48:53 +00:00
|
|
|
cls : 'open-dlg',
|
|
|
|
contentTemplate : '',
|
2018-10-31 10:44:18 +00:00
|
|
|
toolcallback : _.bind(t.onToolClose, t),
|
|
|
|
closeFile : false
|
2016-08-10 09:33:08 +00:00
|
|
|
|
2016-03-11 00:48:53 +00:00
|
|
|
}, options);
|
|
|
|
|
|
|
|
this.template = options.template || [
|
|
|
|
'<div class="box" style="height:' + (_options.height - 85) + 'px;">',
|
|
|
|
'<div class="content-panel" >',
|
2019-04-17 09:01:20 +00:00
|
|
|
'<% if (type == Common.Utils.importTextType.DRM) { %>',
|
2018-04-28 11:13:52 +00:00
|
|
|
'<% if (warning) { %>',
|
2018-04-27 11:53:36 +00:00
|
|
|
'<div>',
|
2020-06-05 13:10:48 +00:00
|
|
|
'<div class="icon img-commonctrl warn"></div>',
|
2018-04-27 11:53:36 +00:00
|
|
|
'<div style="padding-left: 50px;"><div style="font-size: 12px;">' + t.txtProtected+ '</div>',
|
|
|
|
'<label class="header" style="margin-top: 15px;">' + t.txtPassword + '</label>',
|
2020-03-26 10:03:25 +00:00
|
|
|
'<div id="id-password-txt" style="width: 290px;"></div></div>',
|
2018-04-27 11:53:36 +00:00
|
|
|
'</div>',
|
2018-04-28 11:13:52 +00:00
|
|
|
'<% } else { %>',
|
|
|
|
'<div>',
|
|
|
|
'<label class="header">' + t.txtPassword + '</label>',
|
|
|
|
'<div id="id-password-txt"></div>',
|
|
|
|
'</div>',
|
|
|
|
'<% } %>',
|
2016-08-10 09:33:08 +00:00
|
|
|
'<% } else { %>',
|
2019-04-17 09:01:20 +00:00
|
|
|
'<% 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;">',
|
2018-02-09 14:26:34 +00:00
|
|
|
'<label class="header">' + t.txtEncoding + '</label>',
|
|
|
|
'<div>',
|
2018-07-24 12:29:53 +00:00
|
|
|
'<div id="id-codepages-combo" class="input-group-nr" style="width: 100%; display: inline-block; vertical-align: middle;"></div>',
|
2018-02-09 14:26:34 +00:00
|
|
|
'</div>',
|
|
|
|
'</div>',
|
2019-04-17 09:01:20 +00:00
|
|
|
'<% } %>',
|
2020-06-26 17:44:54 +00:00
|
|
|
'<% if (type == Common.Utils.importTextType.CSV) { %>',
|
2018-02-09 14:26:34 +00:00
|
|
|
'<div style="display: inline-block; margin-bottom:15px;">',
|
|
|
|
'<label class="header">' + t.txtDelimiter + '</label>',
|
|
|
|
'<div>',
|
|
|
|
'<div id="id-delimiters-combo" class="input-group-nr" style="max-width: 100px;display: inline-block; vertical-align: middle;"></div>',
|
|
|
|
'<div id="id-delimiter-other" class="input-row" style="display: inline-block; vertical-align: middle;margin-left: 10px;"></div>',
|
|
|
|
'</div>',
|
2017-05-11 08:11:33 +00:00
|
|
|
'</div>',
|
2016-03-11 00:48:53 +00:00
|
|
|
'<% } %>',
|
2020-06-26 17:44:54 +00:00
|
|
|
'<% if (type == Common.Utils.importTextType.Paste || type == Common.Utils.importTextType.Columns) { %>',
|
|
|
|
'<div style="display: inline-block; margin-bottom:15px;width: 100%;">',
|
|
|
|
'<label class="header">' + t.txtDelimiter + '</label>',
|
|
|
|
'<div>',
|
|
|
|
'<div id="id-delimiters-combo" class="input-group-nr" style="max-width: 100px;display: inline-block; vertical-align: middle;"></div>',
|
|
|
|
'<div id="id-delimiter-other" class="input-row" style="display: inline-block; vertical-align: middle;margin-left: 10px;"></div>',
|
|
|
|
'<button type="button" class="btn btn-text-default" id="id-delimiters-advanced" style="min-width:100px; display: inline-block;float:right;">' + t.txtAdvanced + '</button>',
|
|
|
|
'</div>',
|
|
|
|
'</div>',
|
|
|
|
'<% } %>',
|
2018-02-09 14:26:34 +00:00
|
|
|
'<% if (!!preview) { %>',
|
|
|
|
'<div style="">',
|
|
|
|
'<label class="header">' + t.txtPreview + '</label>',
|
2018-02-13 07:52:48 +00:00
|
|
|
'<div style="position: relative;">',
|
|
|
|
'<div style="width: 100%;">',
|
2018-02-13 14:01:13 +00:00
|
|
|
'<div id="id-preview">',
|
2018-02-13 07:52:48 +00:00
|
|
|
'<div>',
|
2018-02-13 14:01:13 +00:00
|
|
|
'<div style="position: absolute; top: 0;"><div id="id-preview-data"></div></div>',
|
2018-02-13 07:52:48 +00:00
|
|
|
'</div>',
|
|
|
|
'</div>',
|
|
|
|
'</div>',
|
|
|
|
'</div>',
|
2018-02-09 14:26:34 +00:00
|
|
|
'</div>',
|
|
|
|
'<% } %>',
|
2016-08-10 09:33:08 +00:00
|
|
|
'<% } %>',
|
2016-03-11 00:48:53 +00:00
|
|
|
'</div>',
|
|
|
|
'</div>',
|
|
|
|
'<div class="footer center">',
|
2018-04-27 11:53:36 +00:00
|
|
|
'<button class="btn normal dlg-btn primary" result="ok">' + t.okButtonText + '</button>',
|
2018-10-31 10:44:18 +00:00
|
|
|
'<% if (closeFile) { %>',
|
|
|
|
'<button class="btn normal dlg-btn" result="cancel" style="margin-left:10px;">' + t.closeButtonText + '</button>',
|
|
|
|
'<% } %>',
|
2018-02-06 10:54:40 +00:00
|
|
|
'<% if (closable) { %>',
|
2018-10-31 10:44:18 +00:00
|
|
|
'<button class="btn normal dlg-btn" result="cancel" style="margin-left:10px;">' + t.cancelButtonText + '</button>',
|
2018-02-06 10:54:40 +00:00
|
|
|
'<% } %>',
|
2016-03-11 00:48:53 +00:00
|
|
|
'</div>'
|
|
|
|
].join('');
|
|
|
|
|
2018-02-06 10:54:40 +00:00
|
|
|
this.handler = _options.handler;
|
|
|
|
this.type = _options.type;
|
2018-02-09 14:26:34 +00:00
|
|
|
this.preview = _options.preview;
|
2019-04-18 08:39:58 +00:00
|
|
|
this.previewData = _options.previewData;
|
2018-04-28 11:13:52 +00:00
|
|
|
this.warning = _options.warning || false;
|
2018-02-06 10:54:40 +00:00
|
|
|
this.closable = _options.closable;
|
|
|
|
this.codepages = _options.codepages;
|
|
|
|
this.settings = _options.settings;
|
2018-02-09 14:26:34 +00:00
|
|
|
this.api = _options.api;
|
2018-02-06 10:54:40 +00:00
|
|
|
this.validatePwd = _options.validatePwd || false;
|
2016-03-11 00:48:53 +00:00
|
|
|
|
2017-04-21 08:10:07 +00:00
|
|
|
_options.tpl = _.template(this.template)(_options);
|
2016-03-11 00:48:53 +00:00
|
|
|
|
|
|
|
Common.UI.Window.prototype.initialize.call(this, _options);
|
|
|
|
},
|
|
|
|
render: function () {
|
|
|
|
Common.UI.Window.prototype.render.call(this);
|
|
|
|
|
|
|
|
if (this.$window) {
|
2017-09-06 13:41:53 +00:00
|
|
|
var me = this;
|
2018-02-06 10:54:40 +00:00
|
|
|
if (!this.closable)
|
|
|
|
this.$window.find('.tool').hide();
|
2016-03-11 00:48:53 +00:00
|
|
|
this.$window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this));
|
2018-02-10 12:50:29 +00:00
|
|
|
|
2018-02-13 14:01:13 +00:00
|
|
|
this.previewPanel = this.$window.find('#id-preview-data');
|
|
|
|
this.previewParent = this.previewPanel.parent();
|
|
|
|
this.previewScrolled = this.$window.find('#id-preview');
|
|
|
|
this.previewInner = this.previewScrolled.find('div:first-child');
|
2018-02-10 12:50:29 +00:00
|
|
|
|
2019-04-17 09:01:20 +00:00
|
|
|
if (this.type == Common.Utils.importTextType.DRM) {
|
2016-09-14 12:57:39 +00:00
|
|
|
this.inputPwd = new Common.UI.InputField({
|
2016-08-10 09:33:08 +00:00
|
|
|
el: $('#id-password-txt'),
|
2018-06-28 13:48:22 +00:00
|
|
|
type: 'text',
|
2017-09-06 13:41:53 +00:00
|
|
|
validateOnBlur: false,
|
|
|
|
validation : function(value) {
|
|
|
|
return me.txtIncorrectPwd;
|
|
|
|
}
|
2016-08-10 09:33:08 +00:00
|
|
|
});
|
2018-09-21 13:01:09 +00:00
|
|
|
|
2018-06-28 13:48:22 +00:00
|
|
|
this.$window.find('input').on('input', function(){
|
|
|
|
if ($(this).val() !== '') {
|
|
|
|
($(this).attr('type') !== 'password') && $(this).attr('type', 'password');
|
|
|
|
} else {
|
|
|
|
$(this).attr('type', 'text');
|
|
|
|
}
|
|
|
|
});
|
2016-09-14 12:57:39 +00:00
|
|
|
} else {
|
2016-08-10 09:33:08 +00:00
|
|
|
this.initCodePages();
|
2019-04-18 08:39:58 +00:00
|
|
|
if (this.preview) {
|
|
|
|
(this.previewData) ? this.previewCallback(this.previewData) : this.updatePreview();
|
|
|
|
}
|
2016-09-14 12:57:39 +00:00
|
|
|
}
|
2018-09-21 13:01:09 +00:00
|
|
|
this.onPrimary = function() {
|
|
|
|
me._handleInput('ok');
|
|
|
|
return false;
|
|
|
|
};
|
2016-03-11 00:48:53 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-08-10 09:33:08 +00:00
|
|
|
show: function() {
|
|
|
|
Common.UI.Window.prototype.show.apply(this, arguments);
|
|
|
|
|
2019-04-17 09:01:20 +00:00
|
|
|
if (this.type == Common.Utils.importTextType.DRM) {
|
2016-08-10 09:33:08 +00:00
|
|
|
var me = this;
|
|
|
|
setTimeout(function(){
|
|
|
|
me.inputPwd.cmpEl.find('input').focus();
|
2017-09-06 13:41:53 +00:00
|
|
|
if (me.validatePwd)
|
|
|
|
me.inputPwd.checkValidate();
|
2016-08-10 09:33:08 +00:00
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-06 10:54:40 +00:00
|
|
|
onBtnClick: function(event) {
|
|
|
|
this._handleInput(event.currentTarget.attributes['result'].value);
|
|
|
|
},
|
|
|
|
|
|
|
|
onToolClose: function() {
|
|
|
|
this._handleInput('cancel');
|
|
|
|
},
|
|
|
|
|
|
|
|
_handleInput: function(state) {
|
2016-08-10 09:33:08 +00:00
|
|
|
if (this.handler) {
|
2019-04-17 09:01:20 +00:00
|
|
|
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),
|
2018-04-19 12:33:59 +00:00
|
|
|
delimiter = this.cmbDelimiter ? this.cmbDelimiter.getValue() : null,
|
2017-05-11 08:11:33 +00:00
|
|
|
delimiterChar = (delimiter == -1) ? this.inputDelimiter.getValue() : null;
|
|
|
|
(delimiter == -1) && (delimiter = null);
|
2019-09-26 14:34:01 +00:00
|
|
|
if (!this.closable && this.type == Common.Utils.importTextType.TXT) { //save last encoding only for opening txt files
|
|
|
|
Common.localStorage.setItem("de-settings-open-encoding", encoding);
|
|
|
|
}
|
2020-06-26 17:44:54 +00:00
|
|
|
|
|
|
|
var decimal = this.separatorOptions ? this.separatorOptions.decimal : undefined,
|
|
|
|
thousands = this.separatorOptions ? this.separatorOptions.thousands : undefined;
|
|
|
|
this.handler.call(this, state, encoding, delimiter, delimiterChar, decimal, thousands);
|
2018-02-06 10:54:40 +00:00
|
|
|
}
|
2016-03-11 00:48:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.close();
|
|
|
|
},
|
|
|
|
|
|
|
|
initCodePages: function () {
|
2018-04-19 12:33:59 +00:00
|
|
|
var i, c, codepage, encodedata = [], listItems = [], length = 0, lcid_width = 0;
|
2016-03-11 00:48:53 +00:00
|
|
|
|
|
|
|
if (this.codepages) {
|
|
|
|
encodedata = [];
|
|
|
|
for (i = 0; i < this.codepages.length; ++i) {
|
|
|
|
codepage = this.codepages[i];
|
|
|
|
c = [];
|
|
|
|
c[0] = codepage.asc_getCodePage();
|
|
|
|
c[1] = codepage.asc_getCodePageName();
|
2018-04-19 12:33:59 +00:00
|
|
|
c[2] = codepage.asc_getLcid();
|
2016-03-11 00:48:53 +00:00
|
|
|
|
|
|
|
encodedata.push(c);
|
|
|
|
}
|
2018-04-19 12:33:59 +00:00
|
|
|
lcid_width = 50;
|
2016-03-11 00:48:53 +00:00
|
|
|
}
|
|
|
|
length = encodedata.length;
|
|
|
|
|
2019-04-17 09:01:20 +00:00
|
|
|
if (length) {
|
|
|
|
for (i = 0; i < length; ++i) {
|
|
|
|
listItems.push({
|
|
|
|
value: encodedata[i][0],
|
|
|
|
displayValue: Common.Utils.String.htmlEncode(encodedata[i][1]),
|
|
|
|
lcid: encodedata[i][2] || ''
|
|
|
|
});
|
|
|
|
}
|
2018-04-19 12:33:59 +00:00
|
|
|
|
2019-04-17 09:01:20 +00:00
|
|
|
var itemsTemplate =
|
|
|
|
_.template([
|
|
|
|
'<% _.each(items, function(item) { %>',
|
|
|
|
'<li id="<%= item.id %>" data-value="<%= item.value %>"><a tabindex="-1" type="menuitem">',
|
2018-07-24 12:29:53 +00:00
|
|
|
'<div style="display: inline-block;"><%= item.displayValue %></div>',
|
|
|
|
'<label style="text-align: right;width:' + lcid_width + 'px;"><%= item.lcid %></label>',
|
2019-04-17 09:01:20 +00:00
|
|
|
'</a></li>',
|
|
|
|
'<% }); %>'
|
|
|
|
].join(''));
|
|
|
|
|
|
|
|
this.cmbEncoding = new Common.UI.ComboBox({
|
|
|
|
el: $('#id-codepages-combo', this.$window),
|
|
|
|
style: 'width: 100%;',
|
|
|
|
menuStyle: 'min-width: 100%; max-height: 200px;',
|
|
|
|
cls: 'input-group-nr',
|
|
|
|
menuCls: 'scrollable-menu',
|
|
|
|
data: listItems,
|
|
|
|
editable: false,
|
|
|
|
disabled: true,
|
2019-09-26 14:34:01 +00:00
|
|
|
search: true,
|
2019-04-17 09:01:20 +00:00
|
|
|
itemsTemplate: itemsTemplate
|
|
|
|
});
|
2018-04-19 12:33:59 +00:00
|
|
|
|
|
|
|
this.cmbEncoding.setDisabled(false);
|
2019-09-26 14:34:01 +00:00
|
|
|
var encoding = (this.settings && this.settings.asc_getCodePage()) ? this.settings.asc_getCodePage() : encodedata[0][0];
|
|
|
|
if (!this.closable && this.type == Common.Utils.importTextType.TXT) { // only for opening txt files
|
|
|
|
var value = Common.localStorage.getItem("de-settings-open-encoding");
|
|
|
|
value && (encoding = parseInt(value));
|
|
|
|
}
|
|
|
|
this.cmbEncoding.setValue(encoding);
|
2018-04-19 12:33:59 +00:00
|
|
|
if (this.preview)
|
|
|
|
this.cmbEncoding.on('selected', _.bind(this.onCmbEncodingSelect, this));
|
2016-03-11 00:48:53 +00:00
|
|
|
|
2018-04-19 12:33:59 +00:00
|
|
|
var ul = this.cmbEncoding.cmpEl.find('ul'),
|
|
|
|
a = ul.find('li:nth(0) a'),
|
|
|
|
width = ul.width() - parseInt(a.css('padding-left')) - parseInt(a.css('padding-right')) - 50;
|
2018-07-24 12:29:53 +00:00
|
|
|
ul.find('li div').width(width);
|
2018-04-19 12:33:59 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 09:01:20 +00:00
|
|
|
if (this.type == Common.Utils.importTextType.CSV || this.type == Common.Utils.importTextType.Paste || this.type == Common.Utils.importTextType.Columns) {
|
2018-04-19 12:33:59 +00:00
|
|
|
this.cmbDelimiter = new Common.UI.ComboBox({
|
|
|
|
el: $('#id-delimiters-combo', this.$window),
|
|
|
|
style: 'width: 100px;',
|
|
|
|
menuStyle: 'min-width: 100px;',
|
2016-03-11 00:48:53 +00:00
|
|
|
cls: 'input-group-nr',
|
2018-04-19 12:33:59 +00:00
|
|
|
data: [
|
|
|
|
{value: 4, displayValue: this.txtComma},
|
|
|
|
{value: 2, displayValue: this.txtSemicolon},
|
|
|
|
{value: 3, displayValue: this.txtColon},
|
|
|
|
{value: 1, displayValue: this.txtTab},
|
|
|
|
{value: 5, displayValue: this.txtSpace},
|
|
|
|
{value: -1, displayValue: this.txtOther}],
|
2016-03-11 00:48:53 +00:00
|
|
|
editable: false
|
|
|
|
});
|
2018-04-19 12:33:59 +00:00
|
|
|
this.cmbDelimiter.setValue( (this.settings && this.settings.asc_getDelimiter()) ? this.settings.asc_getDelimiter() : 4);
|
|
|
|
this.cmbDelimiter.on('selected', _.bind(this.onCmbDelimiterSelect, this));
|
|
|
|
|
|
|
|
this.inputDelimiter = new Common.UI.InputField({
|
|
|
|
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);
|
2018-02-09 14:26:34 +00:00
|
|
|
if (this.preview)
|
2018-04-19 12:33:59 +00:00
|
|
|
this.inputDelimiter.on ('changing', _.bind(this.updatePreview, this));
|
2020-06-26 17:44:54 +00:00
|
|
|
|
|
|
|
if (this.type == Common.Utils.importTextType.Paste || this.type == Common.Utils.importTextType.Columns) {
|
|
|
|
this.btnAdvanced = new Common.UI.Button({
|
|
|
|
el: $('#id-delimiters-advanced')
|
|
|
|
});
|
|
|
|
this.btnAdvanced.on('click', _.bind(this.onAdvancedClick, this));
|
|
|
|
}
|
2018-02-09 14:26:34 +00:00
|
|
|
}
|
|
|
|
},
|
2017-05-11 08:11:33 +00:00
|
|
|
|
2018-02-09 14:26:34 +00:00
|
|
|
updatePreview: function() {
|
2019-04-17 09:01:20 +00:00
|
|
|
var encoding = (this.cmbEncoding && !this.cmbEncoding.isDisabled()) ? this.cmbEncoding.getValue() :
|
2018-04-19 12:33:59 +00:00
|
|
|
((this.settings && this.settings.asc_getCodePage()) ? this.settings.asc_getCodePage() : 0);
|
2019-04-17 09:01:20 +00:00
|
|
|
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:
|
2019-07-25 07:14:45 +00:00
|
|
|
this.api.asc_decodeBuffer(this.preview, new Asc.asc_CTextOptions(encoding, delimiter, delimiterChar), _.bind(this.previewCallback, this));
|
2019-04-17 09:01:20 +00:00
|
|
|
break;
|
|
|
|
case Common.Utils.importTextType.TXT:
|
2019-07-25 07:14:45 +00:00
|
|
|
this.api.asc_decodeBuffer(this.preview, new Asc.asc_CTextOptions(encoding), _.bind(this.previewCallback, this));
|
2019-04-17 09:01:20 +00:00
|
|
|
break;
|
|
|
|
case Common.Utils.importTextType.Paste:
|
|
|
|
case Common.Utils.importTextType.Columns:
|
2020-06-26 17:44:54 +00:00
|
|
|
var options = new Asc.asc_CTextOptions(encoding, delimiter, delimiterChar);
|
|
|
|
if (this.separatorOptions) {
|
|
|
|
options.asc_setNumberDecimalSeparator(this.separatorOptions.decimal);
|
|
|
|
options.asc_setNumberGroupSeparator(this.separatorOptions.thousands);
|
|
|
|
}
|
|
|
|
this.api.asc_TextImport(options, _.bind(this.previewCallback, this), this.type == Common.Utils.importTextType.Paste);
|
2019-04-17 09:01:20 +00:00
|
|
|
break;
|
2018-02-09 14:26:34 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-13 14:01:13 +00:00
|
|
|
previewCallback: function(data) {
|
2018-02-13 07:52:48 +00:00
|
|
|
if (!data || !data.length) return;
|
|
|
|
|
|
|
|
this.data = data;
|
2018-02-13 14:01:13 +00:00
|
|
|
this.previewInner.height(data.length*17);
|
2018-02-13 07:52:48 +00:00
|
|
|
|
2018-02-13 14:01:13 +00:00
|
|
|
if (!this.scrollerY)
|
|
|
|
this.scrollerY = new Common.UI.Scroller({
|
|
|
|
el: this.previewScrolled,
|
2018-02-13 07:52:48 +00:00
|
|
|
minScrollbarLength : 20,
|
|
|
|
alwaysVisibleY: true,
|
2018-05-23 10:28:33 +00:00
|
|
|
alwaysVisibleX: true,
|
2018-02-13 07:52:48 +00:00
|
|
|
onChange: _.bind(function(){
|
2018-02-13 14:01:13 +00:00
|
|
|
if (this.scrollerY) {
|
|
|
|
var startPos = this.scrollerY.getScrollTop(),
|
2018-02-13 07:52:48 +00:00
|
|
|
start = Math.floor(startPos/17+0.5),
|
|
|
|
end = start+Math.min(6, this.data.length);
|
|
|
|
if (end>this.data.length) {
|
|
|
|
end = this.data.length;
|
|
|
|
start = this.data.length-6;
|
|
|
|
startPos = start*17;
|
|
|
|
}
|
|
|
|
this.previewParent.height(108);
|
|
|
|
this.previewParent.css({top: startPos});
|
2018-02-13 14:01:13 +00:00
|
|
|
this.previewDataBlock(this.data.slice(start, end));
|
2018-02-13 07:52:48 +00:00
|
|
|
}
|
|
|
|
}, this)
|
2018-02-10 12:50:29 +00:00
|
|
|
});
|
2018-02-13 14:01:13 +00:00
|
|
|
this.scrollerY.update();
|
|
|
|
this.scrollerY.scrollTop(0);
|
2018-02-10 12:50:29 +00:00
|
|
|
},
|
|
|
|
|
2018-02-13 14:01:13 +00:00
|
|
|
previewDataBlock: function(data) {
|
|
|
|
if (!_.isUndefined(this.scrollerX)) {
|
|
|
|
this.scrollerX.destroy();
|
|
|
|
delete this.scrollerX;
|
2018-02-13 07:52:48 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 09:01:20 +00:00
|
|
|
if (this.type == Common.Utils.importTextType.CSV || this.type == Common.Utils.importTextType.Paste || this.type == Common.Utils.importTextType.Columns) {
|
2018-02-13 14:01:13 +00:00
|
|
|
var maxlength = 0;
|
|
|
|
for (var i=0; i<data.length; i++) {
|
|
|
|
if (data[i].length>maxlength)
|
|
|
|
maxlength = data[i].length;
|
2018-02-10 12:50:29 +00:00
|
|
|
}
|
2018-02-13 14:01:13 +00:00
|
|
|
var tpl = '<table>';
|
|
|
|
for (var i=0; i<data.length; i++) {
|
2019-04-17 09:01:20 +00:00
|
|
|
tpl += '<tr style="vertical-align: top;">';
|
2018-02-13 14:01:13 +00:00
|
|
|
for (var j=0; j<data[i].length; j++) {
|
|
|
|
tpl += '<td>' + Common.Utils.String.htmlEncode(data[i][j]) + '</td>';
|
|
|
|
}
|
|
|
|
for (j=data[i].length; j<maxlength; j++) {
|
|
|
|
tpl += '<td></td>';
|
|
|
|
}
|
|
|
|
tpl += '</tr>';
|
|
|
|
}
|
|
|
|
tpl += '</table>';
|
|
|
|
} else {
|
|
|
|
var tpl = '<table>';
|
|
|
|
for (var i=0; i<data.length; i++) {
|
2019-04-17 09:01:20 +00:00
|
|
|
tpl += '<tr style="vertical-align: top;"><td>' + Common.Utils.String.htmlEncode(data[i]) + '</td></tr>';
|
2018-02-10 12:50:29 +00:00
|
|
|
}
|
2018-02-13 14:01:13 +00:00
|
|
|
tpl += '</table>';
|
2016-03-11 00:48:53 +00:00
|
|
|
}
|
2018-02-13 07:52:48 +00:00
|
|
|
this.previewPanel.html(tpl);
|
|
|
|
|
2018-02-13 14:01:13 +00:00
|
|
|
this.scrollerX = new Common.UI.Scroller({
|
2018-02-13 07:52:48 +00:00
|
|
|
el: this.previewPanel,
|
|
|
|
suppressScrollY: true,
|
|
|
|
alwaysVisibleX: true,
|
|
|
|
minScrollbarLength : 20
|
|
|
|
});
|
2016-03-11 00:48:53 +00:00
|
|
|
},
|
|
|
|
|
2017-05-11 08:11:33 +00:00
|
|
|
onCmbDelimiterSelect: function(combo, record){
|
|
|
|
this.inputDelimiter.setVisible(record.value == -1);
|
2019-05-30 14:15:42 +00:00
|
|
|
(record.value == -1) && this.inputDelimiter.cmpEl.find('input').focus();
|
2018-02-09 14:26:34 +00:00
|
|
|
if (this.preview)
|
|
|
|
this.updatePreview();
|
|
|
|
},
|
|
|
|
|
|
|
|
onCmbEncodingSelect: function(combo, record){
|
|
|
|
this.updatePreview();
|
2017-05-11 08:11:33 +00:00
|
|
|
},
|
|
|
|
|
2020-06-26 17:44:54 +00:00
|
|
|
onAdvancedClick: function() {
|
|
|
|
if (!SSE) return;
|
|
|
|
|
|
|
|
var me = this,
|
|
|
|
decimal = this.api.asc_getDecimalSeparator(),
|
|
|
|
thousands = this.api.asc_getGroupSeparator();
|
|
|
|
(new SSE.Views.AdvancedSeparatorDialog({
|
|
|
|
props: {
|
|
|
|
decimal: decimal,
|
|
|
|
thousands: thousands
|
|
|
|
},
|
|
|
|
handler: function(result, value) {
|
|
|
|
if (result == 'ok') {
|
|
|
|
me.separatorOptions = {
|
|
|
|
decimal: (value.decimal.length > 0) ? value.decimal : decimal,
|
|
|
|
thousands: (value.thousands.length > 0) ? value.thousands : thousands
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})).show();
|
|
|
|
},
|
|
|
|
|
2016-03-11 00:48:53 +00:00
|
|
|
txtDelimiter : "Delimiter",
|
|
|
|
txtEncoding : "Encoding ",
|
|
|
|
txtSpace : "Space",
|
|
|
|
txtTab : "Tab",
|
2016-08-10 09:33:08 +00:00
|
|
|
txtTitle : "Choose %1 options",
|
|
|
|
txtPassword : "Password",
|
2017-05-11 08:11:33 +00:00
|
|
|
txtTitleProtected : "Protected File",
|
2017-09-06 13:41:53 +00:00
|
|
|
txtOther: 'Other',
|
2018-02-06 10:54:40 +00:00
|
|
|
txtIncorrectPwd: 'Password is incorrect.',
|
2018-02-09 14:26:34 +00:00
|
|
|
closeButtonText: 'Close File',
|
2018-04-12 11:11:00 +00:00
|
|
|
txtPreview: 'Preview',
|
|
|
|
txtComma: 'Comma',
|
|
|
|
txtColon: 'Colon',
|
2018-04-27 11:53:36 +00:00
|
|
|
txtSemicolon: 'Semicolon',
|
2020-06-26 17:44:54 +00:00
|
|
|
txtProtected: 'Once you enter the password and open the file, the current password to the file will be reset.',
|
|
|
|
txtAdvanced: 'Advanced'
|
2016-03-11 00:48:53 +00:00
|
|
|
|
|
|
|
}, Common.Views.OpenDialog || {}));
|
|
|
|
});
|