[DE][SSE] Open CSV/TXT: preview data bloks.

This commit is contained in:
Julia Radzhabova 2018-02-13 10:52:48 +03:00
parent 995fda53eb
commit c6e4aedae2
2 changed files with 101 additions and 75 deletions

View file

@ -91,11 +91,19 @@ define([
'<% if (!!preview) { %>', '<% if (!!preview) { %>',
'<div style="">', '<div style="">',
'<label class="header">' + t.txtPreview + '</label>', '<label class="header">' + t.txtPreview + '</label>',
'<% if (type == Asc.c_oAscAdvancedOptionsID.CSV) { %>', '<div style="position: relative;">',
'<div><div id="id-preview-csv"></div></div>', '<% if (type == Asc.c_oAscAdvancedOptionsID.CSV) { %>',
'<% } else { %>', '<div style="width: 100%;">',
'<div><div id="id-preview-txt"></div></div>', '<div id="id-preview-csv">',
'<% } %>', '<div>',
'<div style="position: absolute; top: 0;"><div id="id-preview-csv-data"></div></div>',
'</div>',
'</div>',
'</div>',
'<% } else { %>',
'<div><div id="id-preview-txt"></div></div>',
'<% } %>',
'</div>',
'</div>', '</div>',
'<% } %>', '<% } %>',
'<% } %>', '<% } %>',
@ -132,7 +140,12 @@ 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' : '#id-preview-txt'); this.previewPanel = this.$window.find((this.type == Asc.c_oAscAdvancedOptionsID.CSV) ? '#id-preview-csv-data' : '#id-preview-txt');
if (this.type == Asc.c_oAscAdvancedOptionsID.CSV) {
this.csvPreview = this.$window.find('#id-preview-csv');
this.csvPreviewInner = this.csvPreview.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({
@ -413,90 +426,93 @@ define([
}, },
updatePreview: function() { updatePreview: function() {
if (!_.isUndefined(this.previewScroller)) {
this.previewScroller.destroy();
delete this.previewScroller;
}
if (this.type == Asc.c_oAscAdvancedOptionsID.CSV) { if (this.type == Asc.c_oAscAdvancedOptionsID.CSV) {
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.previewCallback, this)); this.api.asc_decodeBuffer(this.preview, new Asc.asc_CCSVAdvancedOptions(this.cmbEncoding.getValue(), delimiter, delimiterChar), _.bind(this.previewCsvCallback, this));
} else { } else {
this.api.asc_decodeBuffer(this.preview, new Asc.asc_CTXTAdvancedOptions(this.cmbEncoding.getValue()), _.bind(this.previewCallback, this)); if (!_.isUndefined(this.previewYScroller)) {
this.previewYScroller.destroy();
delete this.previewYScroller;
}
this.api.asc_decodeBuffer(this.preview, new Asc.asc_CTXTAdvancedOptions(this.cmbEncoding.getValue()), _.bind(this.previewTxtCallback, this));
} }
}, },
previewCallback: function(data) { previewTxtCallback: function(data) {
if (!data || !data.length) return; if (!data || !data.length) return;
if (this.type == Asc.c_oAscAdvancedOptionsID.CSV) { this.previewPanel.text(data);
var maxlength = 0; this.previewYScroller = new Common.UI.Scroller({
for (var i=0; i<data.length; i++) {
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++) {
tpl += '<td></td>';
}
tpl += '</tr>';
}
tpl += '</table>';
this.previewPanel.html(tpl);
} else {
this.previewPanel.text(data);
}
this.previewScroller = new Common.UI.Scroller({
el: this.previewPanel, el: this.previewPanel,
minScrollbarLength : 10 minScrollbarLength : 20,
alwaysVisibleY: true
}); });
}, },
startLoadData: function() { previewCsvCallback: function(data) {
if (this.type == Asc.c_oAscAdvancedOptionsID.CSV) { if (!data || !data.length) return;
this.previewPanel.html('<table></table>');
this.previewInner = this.previewPanel.find('table');
} else {
this.previewPanel.html('');
}
this.previewScroller = new Common.UI.Scroller({
el: this.previewPanel,
minScrollbarLength : 10
});
},
previewDataBlock: function(data) { this.data = data;
if (this.type == Asc.c_oAscAdvancedOptionsID.CSV) { this.csvPreviewInner.height(data.length*17);
var maxlength = 0;
for (var i=0; i<data.length; i++) { if (!this.previewScroller)
if (data[i].length>maxlength) this.previewScroller = new Common.UI.Scroller({
maxlength = data[i].length; el: this.csvPreview,
} minScrollbarLength : 20,
var tpl = ''; alwaysVisibleY: true,
for (var i=0; i<data.length; i++) { onChange: _.bind(function(){
tpl += '<tr>'; if (this.previewScroller) {
for (var j=0; j<data[i].length; j++) { var startPos = this.previewScroller.getScrollTop(),
tpl += '<td>' + Common.Utils.String.htmlEncode(data[i][j]) + '</td>'; 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});
this.previewCsvDataBlock(this.data.slice(start, end));
} }
for (j=data[i].length; j<maxlength; j++) { }, this)
tpl += '<td></td>'; });
}
tpl += '</tr>';
}
this.previewInner.append($(tpl));
} else {
var span = $('<span/>');
span.text(data);
this.previewPanel.append(span);
}
this.previewScroller.update(); this.previewScroller.update();
this.previewScroller.scrollTop(0);
},
previewCsvDataBlock: function(data) {
if (!_.isUndefined(this.previewXScroller)) {
this.previewXScroller.destroy();
delete this.previewXScroller;
}
var maxlength = 0;
for (var i=0; i<data.length; i++) {
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++) {
tpl += '<td></td>';
}
tpl += '</tr>';
}
tpl += '</table>';
this.previewPanel.html(tpl);
this.previewXScroller = new Common.UI.Scroller({
el: this.previewPanel,
suppressScrollY: true,
alwaysVisibleX: true,
minScrollbarLength : 20
});
}, },
onCmbDelimiterSelect: function(combo, record){ onCmbDelimiterSelect: function(combo, record){

View file

@ -38,18 +38,28 @@
} }
#id-preview-csv, #id-preview-txt { #id-preview-csv, #id-preview-txt, #id-preview-csv-data {
position:relative; position:relative;
width: 100%; width: 100%;
height: 106px; height: 110px !important;
overflow:hidden; overflow:hidden;
border: @gray-soft solid 1px; border: @gray-soft solid 1px;
} }
#id-preview-csv-data {
border: none;
height: 108px !important;
}
table {
min-height: 108px;
}
td { td {
padding: 1px 8px 1px 0; padding: 1px 8px 1px 0;
border-right: @gray-soft solid 1px; border-right: @gray-soft solid 1px;
min-width: 30px; min-width: 30px;
height: 17px;
white-space: nowrap; white-space: nowrap;
} }