[DE][SSE] Open TXT: preview data bloks (as csv).

This commit is contained in:
Julia Radzhabova 2018-02-13 17:01:13 +03:00
parent c6e4aedae2
commit aabbc9c8fd
2 changed files with 51 additions and 62 deletions

View file

@ -92,17 +92,13 @@ define([
'<div style="">', '<div style="">',
'<label class="header">' + t.txtPreview + '</label>', '<label class="header">' + t.txtPreview + '</label>',
'<div style="position: relative;">', '<div style="position: relative;">',
'<% if (type == Asc.c_oAscAdvancedOptionsID.CSV) { %>',
'<div style="width: 100%;">', '<div style="width: 100%;">',
'<div id="id-preview-csv">', '<div id="id-preview">',
'<div>', '<div>',
'<div style="position: absolute; top: 0;"><div id="id-preview-csv-data"></div></div>', '<div style="position: absolute; top: 0;"><div id="id-preview-data"></div></div>',
'</div>', '</div>',
'</div>', '</div>',
'</div>', '</div>',
'<% } else { %>',
'<div><div id="id-preview-txt"></div></div>',
'<% } %>',
'</div>', '</div>',
'</div>', '</div>',
'<% } %>', '<% } %>',
@ -140,12 +136,10 @@ define([
this.$window.find('.tool').hide(); this.$window.find('.tool').hide();
this.$window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this)); this.$window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this));
this.previewPanel = this.$window.find((this.type == Asc.c_oAscAdvancedOptionsID.CSV) ? '#id-preview-csv-data' : '#id-preview-txt'); this.previewPanel = this.$window.find('#id-preview-data');
if (this.type == Asc.c_oAscAdvancedOptionsID.CSV) { this.previewParent = this.previewPanel.parent();
this.csvPreview = this.$window.find('#id-preview-csv'); this.previewScrolled = this.$window.find('#id-preview');
this.csvPreviewInner = this.csvPreview.find('div:first-child'); this.previewInner = this.previewScrolled.find('div:first-child');
this.previewParent = this.previewPanel.parent();
}
if (this.type == Asc.c_oAscAdvancedOptionsID.DRM) { if (this.type == Asc.c_oAscAdvancedOptionsID.DRM) {
this.inputPwd = new Common.UI.InputField({ this.inputPwd = new Common.UI.InputField({
@ -430,41 +424,26 @@ define([
var delimiter = this.cmbDelimiter ? this.cmbDelimiter.getValue() : null, var 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.api.asc_decodeBuffer(this.preview, new Asc.asc_CCSVAdvancedOptions(this.cmbEncoding.getValue(), delimiter, delimiterChar), _.bind(this.previewCsvCallback, this)); this.api.asc_decodeBuffer(this.preview, new Asc.asc_CCSVAdvancedOptions(this.cmbEncoding.getValue(), delimiter, delimiterChar), _.bind(this.previewCallback, this));
} else { } else {
if (!_.isUndefined(this.previewYScroller)) { this.api.asc_decodeBuffer(this.preview, new Asc.asc_CTXTAdvancedOptions(this.cmbEncoding.getValue()), _.bind(this.previewCallback, this));
this.previewYScroller.destroy();
delete this.previewYScroller;
}
this.api.asc_decodeBuffer(this.preview, new Asc.asc_CTXTAdvancedOptions(this.cmbEncoding.getValue()), _.bind(this.previewTxtCallback, this));
} }
}, },
previewTxtCallback: function(data) { previewCallback: function(data) {
if (!data || !data.length) return;
this.previewPanel.text(data);
this.previewYScroller = new Common.UI.Scroller({
el: this.previewPanel,
minScrollbarLength : 20,
alwaysVisibleY: true
});
},
previewCsvCallback: function(data) {
if (!data || !data.length) return; if (!data || !data.length) return;
this.data = data; this.data = data;
this.csvPreviewInner.height(data.length*17); this.previewInner.height(data.length*17);
if (!this.previewScroller) if (!this.scrollerY)
this.previewScroller = new Common.UI.Scroller({ this.scrollerY = new Common.UI.Scroller({
el: this.csvPreview, el: this.previewScrolled,
minScrollbarLength : 20, minScrollbarLength : 20,
alwaysVisibleY: true, alwaysVisibleY: true,
onChange: _.bind(function(){ onChange: _.bind(function(){
if (this.previewScroller) { if (this.scrollerY) {
var startPos = this.previewScroller.getScrollTop(), var startPos = this.scrollerY.getScrollTop(),
start = Math.floor(startPos/17+0.5), start = Math.floor(startPos/17+0.5),
end = start+Math.min(6, this.data.length); end = start+Math.min(6, this.data.length);
if (end>this.data.length) { if (end>this.data.length) {
@ -474,40 +453,48 @@ define([
} }
this.previewParent.height(108); this.previewParent.height(108);
this.previewParent.css({top: startPos}); this.previewParent.css({top: startPos});
this.previewCsvDataBlock(this.data.slice(start, end)); this.previewDataBlock(this.data.slice(start, end));
} }
}, this) }, this)
}); });
this.previewScroller.update(); this.scrollerY.update();
this.previewScroller.scrollTop(0); this.scrollerY.scrollTop(0);
}, },
previewCsvDataBlock: function(data) { previewDataBlock: function(data) {
if (!_.isUndefined(this.previewXScroller)) { if (!_.isUndefined(this.scrollerX)) {
this.previewXScroller.destroy(); this.scrollerX.destroy();
delete this.previewXScroller; delete this.scrollerX;
} }
var maxlength = 0; if (this.type == Asc.c_oAscAdvancedOptionsID.CSV) {
for (var i=0; i<data.length; i++) { var maxlength = 0;
if (data[i].length>maxlength) for (var i=0; i<data.length; i++) {
maxlength = data[i].length; if (data[i].length>maxlength)
} maxlength = data[i].length;
var tpl = '<table>';
for (var i=0; i<data.length; i++) {
tpl += '<tr>';
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++) { var tpl = '<table>';
tpl += '<td></td>'; for (var i=0; i<data.length; i++) {
tpl += '<tr>';
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 += '</tr>'; tpl += '</table>';
} else {
var tpl = '<table>';
for (var i=0; i<data.length; i++) {
tpl += '<tr><td>' + Common.Utils.String.htmlEncode(data[i]) + '</td></tr>';
}
tpl += '</table>';
} }
tpl += '</table>';
this.previewPanel.html(tpl); this.previewPanel.html(tpl);
this.previewXScroller = new Common.UI.Scroller({ this.scrollerX = new Common.UI.Scroller({
el: this.previewPanel, el: this.previewPanel,
suppressScrollY: true, suppressScrollY: true,
alwaysVisibleX: true, alwaysVisibleX: true,

View file

@ -38,17 +38,19 @@
} }
#id-preview-csv, #id-preview-txt, #id-preview-csv-data { #id-preview {
position:relative;
width: 100%; width: 100%;
height: 110px !important; height: 110px !important;
position:relative;
overflow:hidden; overflow:hidden;
border: @gray-soft solid 1px; border: @gray-soft solid 1px;
} }
#id-preview-csv-data { #id-preview-data {
border: none; width: 100%;
height: 108px !important; height: 108px !important;
position:relative;
overflow:hidden;
} }
table { table {