2011-08-02 05:34:47 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 2011, Google Inc.
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are
|
|
|
|
met:
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions of source code must retain the above copyright
|
2011-08-02 05:34:47 +02:00
|
|
|
notice, this list of conditions and the following disclaimer.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions in binary form must reproduce the above
|
2011-08-02 05:34:47 +02:00
|
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
|
|
in the documentation and/or other materials provided with the
|
|
|
|
distribution.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Neither the name of Google Inc. nor the names of its
|
2011-08-02 05:34:47 +02:00
|
|
|
contributors may be used to endorse or promote products derived from
|
|
|
|
this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
*/
|
2011-08-02 05:34:47 +02:00
|
|
|
|
|
|
|
Refine.LineBasedParserUI = function(controller, jobID, job, format, config,
|
2011-08-04 22:37:14 +02:00
|
|
|
dataContainerElmt, progressContainerElmt, optionContainerElmt) {
|
2011-08-02 05:34:47 +02:00
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
this._controller = controller;
|
|
|
|
this._jobID = jobID;
|
|
|
|
this._job = job;
|
|
|
|
this._format = format;
|
|
|
|
this._config = config;
|
2011-08-02 05:34:47 +02:00
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
this._dataContainer = dataContainerElmt;
|
|
|
|
this._progressContainer = progressContainerElmt;
|
|
|
|
this._optionContainer = optionContainerElmt;
|
2011-08-02 05:34:47 +02:00
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
this._timerID = null;
|
|
|
|
this._initialize();
|
|
|
|
this._updatePreview();
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
2011-10-08 01:44:11 +02:00
|
|
|
Refine.DefaultImportingController.parserUIs.LineBasedParserUI = Refine.LineBasedParserUI;
|
2011-08-02 05:34:47 +02:00
|
|
|
|
|
|
|
Refine.LineBasedParserUI.prototype.confirmReadyToCreateProject = function() {
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
Refine.LineBasedParserUI.prototype.dispose = function() {
|
2011-10-08 01:44:11 +02:00
|
|
|
if (this._timerID !== null) {
|
2011-08-04 22:37:14 +02:00
|
|
|
window.clearTimeout(this._timerID);
|
|
|
|
this._timerID = null;
|
|
|
|
}
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Refine.LineBasedParserUI.prototype.getOptions = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var options = {
|
2011-08-22 19:55:06 +02:00
|
|
|
encoding: $.trim(this._optionContainerElmts.encodingInput[0].value),
|
|
|
|
recordPath: this._config.recordPath
|
2011-08-04 22:37:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var parseIntDefault = function(s, def) {
|
|
|
|
try {
|
2011-10-08 01:44:11 +02:00
|
|
|
var n = parseInt(s,10);
|
2011-08-04 22:37:14 +02:00
|
|
|
if (!isNaN(n)) {
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
// Ignore
|
2011-08-02 05:34:47 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
return def;
|
|
|
|
};
|
|
|
|
options.linesPerRow = parseIntDefault(this._optionContainerElmts.linesPerRowInput[0].value, 1);
|
|
|
|
|
|
|
|
if (this._optionContainerElmts.ignoreCheckbox[0].checked) {
|
|
|
|
options.ignoreLines = parseIntDefault(this._optionContainerElmts.ignoreInput[0].value, -1);
|
|
|
|
} else {
|
|
|
|
options.ignoreLines = -1;
|
|
|
|
}
|
|
|
|
if (this._optionContainerElmts.limitCheckbox[0].checked) {
|
|
|
|
options.limit = parseIntDefault(this._optionContainerElmts.limitInput[0].value, -1);
|
|
|
|
} else {
|
|
|
|
options.limit = -1;
|
|
|
|
}
|
|
|
|
if (this._optionContainerElmts.skipCheckbox[0].checked) {
|
|
|
|
options.skipDataLines = parseIntDefault(this._optionContainerElmts.skipInput[0].value, -1);
|
|
|
|
} else {
|
|
|
|
options.skipDataLines = -1;
|
|
|
|
}
|
|
|
|
options.storeBlankRows = this._optionContainerElmts.storeBlankRowsCheckbox[0].checked;
|
|
|
|
options.storeBlankCellsAsNulls = this._optionContainerElmts.storeBlankCellsAsNullsCheckbox[0].checked;
|
|
|
|
options.includeFileSources = this._optionContainerElmts.includeFileSourcesCheckbox[0].checked;
|
2020-06-15 19:56:00 +02:00
|
|
|
options.includeArchiveFileName = this._optionContainerElmts.includeArchiveFileCheckbox[0].checked;
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
return options;
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Refine.LineBasedParserUI.prototype._initialize = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this._optionContainer.unbind().empty().html(
|
|
|
|
DOM.loadHTML("core", "scripts/index/parser-interfaces/line-based-parser-ui.html"));
|
|
|
|
this._optionContainerElmts = DOM.bind(this._optionContainer);
|
|
|
|
this._optionContainerElmts.previewButton.click(function() { self._updatePreview(); });
|
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
$('#or-import-encoding').html($.i18n('core-index-import/char-encoding'));
|
|
|
|
this._optionContainerElmts.previewButton.html($.i18n('core-buttons/update-preview'));
|
|
|
|
$('#or-import-parseEvery').html($.i18n('core-index-parser/parse-every'));
|
2020-02-26 14:44:44 +01:00
|
|
|
$('#or-import-linesIntoRow').html($.i18n('core-index-parser/lines-into-row'));
|
2018-11-21 18:30:00 +01:00
|
|
|
$('#or-import-blank').text($.i18n('core-index-parser/store-blank'));
|
|
|
|
$('#or-import-null').text($.i18n('core-index-parser/store-nulls'));
|
|
|
|
$('#or-import-source').html($.i18n('core-index-parser/store-source'));
|
2020-06-15 19:56:00 +02:00
|
|
|
$('#or-import-archive').html($.i18n('core-index-parser/store-archive'));
|
2018-11-21 18:30:00 +01:00
|
|
|
$('#or-import-ignore').text($.i18n('core-index-parser/ignore-first'));
|
|
|
|
$('#or-import-lines').text($.i18n('core-index-parser/lines-beg'));
|
|
|
|
$('#or-import-parse').text($.i18n('core-index-parser/parse-next'));
|
|
|
|
$('#or-import-header').text($.i18n('core-index-parser/lines-header'));
|
|
|
|
$('#or-import-discard').text($.i18n('core-index-parser/discard-initial'));
|
|
|
|
$('#or-import-rows').text($.i18n('core-index-parser/rows-data'));
|
|
|
|
$('#or-import-load').text($.i18n('core-index-parser/load-at-most'));
|
|
|
|
$('#or-import-rows2').text($.i18n('core-index-parser/rows-data'));
|
2013-07-02 13:40:50 +02:00
|
|
|
|
2011-08-22 19:55:06 +02:00
|
|
|
this._optionContainerElmts.encodingInput
|
|
|
|
.attr('value', this._config.encoding || '')
|
|
|
|
.click(function() {
|
2011-08-29 00:43:45 +02:00
|
|
|
Encoding.selectEncoding($(this), function() {
|
2011-08-22 19:55:06 +02:00
|
|
|
self._updatePreview();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
this._optionContainerElmts.linesPerRowInput[0].value =
|
|
|
|
this._config.linesPerRow.toString();
|
|
|
|
|
|
|
|
if (this._config.ignoreLines > 0) {
|
2013-09-18 21:38:12 +02:00
|
|
|
this._optionContainerElmts.ignoreCheckbox.prop("checked", true);
|
2011-08-04 22:37:14 +02:00
|
|
|
this._optionContainerElmts.ignoreInput[0].value = this._config.ignoreLines.toString();
|
|
|
|
}
|
|
|
|
if (this._config.limit > 0) {
|
2013-09-18 21:38:12 +02:00
|
|
|
this._optionContainerElmts.limitCheckbox.prop("checked", true);
|
2011-08-04 22:37:14 +02:00
|
|
|
this._optionContainerElmts.limitInput[0].value = this._config.limit.toString();
|
|
|
|
}
|
|
|
|
if (this._config.skipDataLines > 0) {
|
2013-09-18 21:38:12 +02:00
|
|
|
this._optionContainerElmts.skipCheckbox.prop("checked", true);
|
2011-08-04 22:37:14 +02:00
|
|
|
this._optionContainerElmts.skipInput.value[0].value = this._config.skipDataLines.toString();
|
|
|
|
}
|
|
|
|
if (this._config.storeBlankRows) {
|
2013-09-18 21:38:12 +02:00
|
|
|
this._optionContainerElmts.storeBlankRowsCheckbox.prop("checked", true);
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
if (this._config.storeBlankCellsAsNulls) {
|
2013-09-18 21:38:12 +02:00
|
|
|
this._optionContainerElmts.storeBlankCellsAsNullsCheckbox.prop("checked", true);
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
if (this._config.includeFileSources) {
|
2013-09-18 21:38:12 +02:00
|
|
|
this._optionContainerElmts.includeFileSourcesCheckbox.prop("checked", true);
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
2020-06-15 19:56:00 +02:00
|
|
|
if (this._config.includeArchiveFileName) {
|
|
|
|
this._optionContainerElmts.includeArchiveFileCheckbox.prop("checked", true);
|
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
var onChange = function() {
|
|
|
|
self._scheduleUpdatePreview();
|
|
|
|
};
|
|
|
|
this._optionContainer.find("input").bind("change", onChange);
|
|
|
|
this._optionContainer.find("select").bind("change", onChange);
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Refine.LineBasedParserUI.prototype._scheduleUpdatePreview = function() {
|
2011-10-08 01:44:11 +02:00
|
|
|
if (this._timerID !== null) {
|
2011-08-04 22:37:14 +02:00
|
|
|
window.clearTimeout(this._timerID);
|
|
|
|
this._timerID = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
this._timerID = window.setTimeout(function() {
|
|
|
|
self._timerID = null;
|
|
|
|
self._updatePreview();
|
|
|
|
}, 500); // 0.5 second
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Refine.LineBasedParserUI.prototype._updatePreview = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this._progressContainer.show();
|
|
|
|
|
|
|
|
this._controller.updateFormatAndOptions(this.getOptions(), function(result) {
|
|
|
|
if (result.status == "ok") {
|
|
|
|
self._controller.getPreviewData(function(projectData) {
|
|
|
|
self._progressContainer.hide();
|
|
|
|
|
|
|
|
new Refine.PreviewTable(projectData, self._dataContainer.unbind().empty());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|